feat!: add exceptions and support type safe getting OscArgument values

This commit is contained in:
Cassandra de la Cruz-Munoz 2023-10-21 09:15:37 -04:00
parent 9201215b06
commit 87d903619e
31 changed files with 517 additions and 1126 deletions

View File

@ -0,0 +1,17 @@
using System;
using godotOscSharp;
namespace godotVmcSharp
{
public class DataOutOfRangeException : ArgumentOutOfRangeException
{
public DataOutOfRangeException(String address, int index, String name, String expected, object actual): base($"{address}[{index}] {name}", actual, expected)
{}
public DataOutOfRangeException(String address, int index, String name, String expected, object actual, Exception inner): base($"{address}[{index}] {name} has data out of range. Received '{actual}', expected within range '{expected}'.", inner)
{}
public DataOutOfRangeException(OscAddress address, int index, String name, String expected, object actual): base($"{address.ToString()}[{index}] {name}", actual, expected)
{}
public DataOutOfRangeException(OscAddress address, int index, String name, String expected, object actual, Exception inner): base($"{address.ToString()}[{index}] {name} has data out of range. Received '{actual}', expected within range '{expected}'.", inner)
{}
}
}

View File

@ -0,0 +1,16 @@
using System;
using godotOscSharp;
namespace godotVmcSharp
{
public class MissingArgumentsException : ArgumentNullException
{
public MissingArgumentsException() : base("Missing parameters.") {}
public MissingArgumentsException(String message): base(message) {}
public MissingArgumentsException(String message, Exception inner): base(message, inner) {}
public MissingArgumentsException(String address, String expected, int actual) : base($"{address}", "Missing parameters: expecting {expected}, received {actual}.") {}
public MissingArgumentsException(String address, String expected, int actual, Exception inner) : base($"Missing parameters for {address}: expecting {expected}, received {actual}.", inner) {}
public MissingArgumentsException(OscAddress address, String expected, int actual) : base($"{address.ToString()}", "Missing parameters: expecting {expected}, received {actual}.") {}
public MissingArgumentsException(OscAddress address, String expected, int actual, Exception inner) : base($"Missing parameters for {address.ToString()}: expecting {expected}, received {actual}.", inner) {}
}
}

View File

@ -1,32 +0,0 @@
/*
godotVmcSharp
Copyright (C) 2023 Cassandra de la Cruz-Munoz
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace godotVmcSharp
{
public class InvalidArgumentType
{
public static string GetErrorString(string address, string name, char expected, char actual)
{
return $"Invalid argument type for argument \"{name}\" of \"{address}\". Expected {expected}, received {actual}.";
}
public static string GetErrorString(godotOscSharp.OscAddress address, string name, char expected, char actual)
{
return GetErrorString(address.ToString(), name, expected, actual);
}
}
}

View File

@ -20,12 +20,14 @@ using System.Net;
using godotOscSharp; using godotOscSharp;
using Godot; using Godot;
#nullable enable
namespace godotVmcSharp namespace godotVmcSharp
{ {
public class Marionette public class Marionette
{ {
private OscReceiver receiver; private OscReceiver receiver;
private OscSender sender; private OscSender? sender;
private CameraReceiver cam; private CameraReceiver cam;
private DeviceReceiver devices; private DeviceReceiver devices;
private DirectionalLightReceiver lights; private DirectionalLightReceiver lights;
@ -55,40 +57,40 @@ namespace godotVmcSharp
switch (m.Address.ToString()) switch (m.Address.ToString())
{ {
case "/VMC/Ext/OK": case "/VMC/Ext/OK":
new VmcExtOk(m); VmcExtOk.CreateFromMessage(m);
break; break;
case "/VMC/Ext/T": case "/VMC/Ext/T":
new VmcExtT(m); VmcExtT.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Root/Pos": case "/VMC/Ext/Root/Pos":
new VmcExtRootPos(m); VmcExtRootPos.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Bone/Pos": case "/VMC/Ext/Bone/Pos":
new VmcExtBonePos(m); VmcExtBonePos.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Blend/Val": case "/VMC/Ext/Blend/Val":
new VmcExtBlendVal(m); VmcExtBlendVal.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Blend/Apply": case "/VMC/Ext/Blend/Apply":
new VmcMessage(m.Address); new VmcMessage(m.Address);
break; break;
case "/VMC/Ext/Cam": case "/VMC/Ext/Cam":
this.cam.ProcessMessage(new VmcExtCam(m)); this.cam.ProcessMessage(VmcExtCam.CreateFromMessage(m));
break; break;
case "/VMC/Ext/Con": case "/VMC/Ext/Con":
new VmcExtCon(m); VmcExtCon.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Key": case "/VMC/Ext/Key":
new VmcExtKey(m); VmcExtKey.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Midi/Note": case "/VMC/Ext/Midi/Note":
new VmcExtMidiNote(m); VmcExtMidiNote.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Midi/CC/Val": case "/VMC/Ext/Midi/CC/Val":
new VmcExtMidiCcVal(m); VmcExtMidiCcVal.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Midi/CC/Bit": case "/VMC/Ext/Midi/CC/Bit":
new VmcExtMidiCcBit(m); VmcExtMidiCcBit.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Hmd/Pos": case "/VMC/Ext/Hmd/Pos":
case "/VMC/Ext/Con/Pos": case "/VMC/Ext/Con/Pos":
@ -96,31 +98,31 @@ namespace godotVmcSharp
case "/VMC/Ext/Hmd/Pos/Local": case "/VMC/Ext/Hmd/Pos/Local":
case "/VMC/Ext/Con/Pos/Local": case "/VMC/Ext/Con/Pos/Local":
case "/VMC/Ext/Tra/Pos/Local": case "/VMC/Ext/Tra/Pos/Local":
this.devices.ProcessMessage(new VmcExtDevicePos(m)); this.devices.ProcessMessage(VmcExtDevicePos.CreateFromMessage(m));
break; break;
case "/VMC/Ext/Rcv": case "/VMC/Ext/Rcv":
new VmcExtRcv(m); VmcExtRcv.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Light": case "/VMC/Ext/Light":
this.lights.ProcessMessage(new VmcExtLight(m)); this.lights.ProcessMessage(VmcExtLight.CreateFromMessage(m));
break; break;
case "/VMC/Ext/VRM": case "/VMC/Ext/VRM":
new VmcExtVrm(m); VmcExtVrm.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Remote": case "/VMC/Ext/Remote":
new VmcExtRemote(m); VmcExtRemote.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Opt": case "/VMC/Ext/Opt":
new VmcExtOpt(m); VmcExtOpt.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Setting/Color": case "/VMC/Ext/Setting/Color":
new VmcExtSettingColor(m); VmcExtSettingColor.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Setting/Win": case "/VMC/Ext/Setting/Win":
new VmcExtSettingWin(m); VmcExtSettingWin.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Config": case "/VMC/Ext/Config":
new VmcExtConfig(m); VmcExtConfig.CreateFromMessage(m);
break; break;
} }
} }

View File

@ -55,46 +55,46 @@ namespace godotVmcSharp
case "/VMC/Ext/Hmd/Pos": case "/VMC/Ext/Hmd/Pos":
case "/VMC/Ext/Con/Pos": case "/VMC/Ext/Con/Pos":
case "/VMC/Ext/Tra/Pos": case "/VMC/Ext/Tra/Pos":
this.devices.ProcessMessage(new VmcExtDevicePos(m)); this.devices.ProcessMessage(VmcExtDevicePos.CreateFromMessage(m));
break; break;
case "/VMC/Ext/Set/Period": case "/VMC/Ext/Set/Period":
new VmcExtSetPeriod(m); VmcExtSetPeriod.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Midi/CC/Val": case "/VMC/Ext/Midi/CC/Val":
new VmcExtMidiCcVal(m); VmcExtMidiCcVal.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Cam": case "/VMC/Ext/Cam":
this.cam.ProcessMessage(new VmcExtCam(m)); this.cam.ProcessMessage(VmcExtCam.CreateFromMessage(m));
break; break;
case "/VMC/Ext/Blend/Val": case "/VMC/Ext/Blend/Val":
new VmcExtBlendVal(m); VmcExtBlendVal.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Blend/Apply": case "/VMC/Ext/Blend/Apply":
new VmcMessage(m.Address); new VmcMessage(m.Address);
break; break;
case "/VMC/Ext/Set/Eye": case "/VMC/Ext/Set/Eye":
new VmcExtSetEye(m); VmcExtSetEye.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Set/Req": case "/VMC/Ext/Set/Req":
new VmcMessage(m.Address); new VmcMessage(m.Address);
break; break;
case "/VMC/Ext/Set/Res": case "/VMC/Ext/Set/Res":
new VmcExtSetRes(m); VmcExtSetRes.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Set/Calib/Ready": case "/VMC/Ext/Set/Calib/Ready":
new VmcMessage(m.Address); new VmcMessage(m.Address);
break; break;
case "/VMC/Ext/Set/Calib/Exec": case "/VMC/Ext/Set/Calib/Exec":
new VmcExtSetCalibExec(m); VmcExtSetCalibExec.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Set/Config": case "/VMC/Ext/Set/Config":
new VmcExtSetConfig(m); VmcExtSetConfig.CreateFromMessage(m);
break; break;
case "/VMC/Ext/Light": case "/VMC/Ext/Light":
this.lights.ProcessMessage(new VmcExtLight(m)); this.lights.ProcessMessage(VmcExtLight.CreateFromMessage(m));
break; break;
case "/VMC/Ext/Set/Shortcut": case "/VMC/Ext/Set/Shortcut":
new VmcExtSetShortcut(m); VmcExtSetShortcut.CreateFromMessage(m);
break; break;
} }
} }

View File

@ -16,92 +16,83 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using godotOscSharp; using godotOscSharp;
using System;
#nullable enable
namespace godotVmcSharp namespace godotVmcSharp
{ {
public class VmcExtBlendVal : VmcMessage public class VmcExtBlendVal : VmcMessage
{ {
public readonly string Name; public readonly string? Name;
public readonly float Value; public readonly float Value;
public VmcExtBlendVal(OscMessage m) : base(m.Address) public static VmcExtBlendVal CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 2) if (m.Data.Count <= 2)
{ {
GD.Print($"Invalid number of arguments for /VMC/Ext/Blend/Val. Expected 2, received {m.Data.Count}."); throw new MissingArgumentsException(m.Address, "2", m.Data.Count);
return;
} }
if (m.Data[0].Type != 's') var blendShape = m.Data[0].GetAsString();
{ var value = m.Data[1].GetAsFloat();
GD.Print(InvalidArgumentType.GetErrorString(Addr, "name", 's', m.Data[0].Type)); if (value < 0 || value > 1) {
return; throw new DataOutOfRangeException(m.Address, 1, "value", "0 <= value <= 1", value);
} }
if (m.Data[1].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "value", 'f', m.Data[1].Type));
return;
}
var blendShape = (string)m.Data[0].Value;
if (IsVrm0BlendShape(blendShape)) if (IsVrm0BlendShape(blendShape))
{ {
Name = blendShape; return new VmcExtBlendVal(blendShape, value);
Value = (float)m.Data[1].Value;
return;
} }
if (IsVrm1Expression(blendShape)) if (IsVrm1Expression(blendShape))
{ {
Name = blendShape; return new VmcExtBlendVal(blendShape, value);
Value = (float)m.Data[1].Value;
return;
} }
if (IsArkitBlendShape(blendShape)) if (IsArkitBlendShape(blendShape))
{ {
Name = blendShape; return new VmcExtBlendVal(blendShape, value);
Value = (float)m.Data[1].Value;
return;
} }
GD.Print($"Invalid argument for {Addr}. BlendShape \"{blendShape}\" not in list."); throw new DataOutOfRangeException(m.Address, 0, "name", "name in valid blendshape names", blendShape);
} }
public VmcExtBlendVal(string name, float value) : base(new OscAddress("VMC/Ext/Blend/Val")) public static VmcExtBlendVal CreateFromParams(string name, float value)
{ {
if (value < 0 || value > 1) {
throw new DataOutOfRangeException("VMC/Ext/Blend/Val", 1, "value", "0 <= value <= 1", value);
}
if (IsVrm0BlendShape(name)) if (IsVrm0BlendShape(name))
{ {
Name = name; return new VmcExtBlendVal(name, value);
Value = value;
return;
} }
if (IsVrm1Expression(name)) if (IsVrm1Expression(name))
{ {
Name = name; return new VmcExtBlendVal(name, value);
Value = value;
return;
} }
if (IsArkitBlendShape(name)) if (IsArkitBlendShape(name))
{ {
Name = name; return new VmcExtBlendVal(name, value);
Value = value;
return;
} }
GD.Print($"Invalid argument for {Addr}. BlendShape \"{name}\" not in list."); throw new DataOutOfRangeException("VMC/Ext/Blend/Val", 0, "name", "name in valid blendshape names", name);
} }
private bool IsVrm0BlendShape(string name) private VmcExtBlendVal(String name, float value): base(new OscAddress("VMC/Ext/Blend/Val")) {
Name = name;
Value = value;
}
private static bool IsVrm0BlendShape(string name)
{ {
return name == "Joy" || name == "Angry" || name == "Sorrow" || name == "Fun" || return name == "Joy" || name == "Angry" || name == "Sorrow" || name == "Fun" ||
name == "A" || name == "I" || name == "U" || name == "E" || name == "O" || name == "A" || name == "I" || name == "U" || name == "E" || name == "O" ||
name == "Blink_L" || name == "Blink_R"; name == "Blink_L" || name == "Blink_R";
} }
private bool IsVrm1Expression(string name) private static bool IsVrm1Expression(string name)
{ {
return name == "happy" || name == "angry" || name == "sad" || name == "relaxed" || return name == "happy" || name == "angry" || name == "sad" || name == "relaxed" ||
name == "aa" || name == "ih" || name == "ou" || name == "ee" || name == "oh" || name == "aa" || name == "ih" || name == "ou" || name == "ee" || name == "oh" ||
name == "blinkLeft" || name == "blinkRight"; name == "blinkLeft" || name == "blinkRight";
} }
private bool IsArkitBlendShape(string name) private static bool IsArkitBlendShape(string name)
{ {
return name == "browInnerUp" || return name == "browInnerUp" ||
name == "browDownLeft" || name == "browDownRight" || name == "browDownLeft" || name == "browDownRight" ||
@ -135,8 +126,8 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument> { return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument> {
new OscArgument(Name, 's'), OscArgument.CreateFromParams(Name, 's')!,
new OscArgument(Value, 'f') OscArgument.CreateFromParams(Value, 'f')!
}); });
} }
} }

View File

@ -26,55 +26,13 @@ namespace godotVmcSharp
public readonly string Name; public readonly string Name;
public readonly Transform3D Transform; public readonly Transform3D Transform;
public VmcExtBonePos(OscMessage m) : base(m.Address) public static VmcExtBonePos CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 8) if (m.Data.Count < 8)
{ {
GD.Print($"Invalid number of arguments for {Addr}. Expected 8, received {m.Data.Count}."); throw new MissingArgumentsException(m.Address, "8", m.Data.Count);
return;
} }
if (m.Data[0].Type != 's') return new VmcExtBonePos((string)m.Data[0].GetAsString(), new Transform3D(new Basis(new Quaternion(m.Data[4].GetAsFloat(), m.Data[5].GetAsFloat(), m.Data[6].GetAsFloat(), m.Data[7].GetAsFloat())), new Vector3(m.Data[1].GetAsFloat(), m.Data[2].GetAsFloat(), m.Data[3].GetAsFloat())));
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "name", 's', m.Data[0].Type));
return;
}
if (m.Data[1].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.x", 'f', m.Data[1].Type));
return;
}
if (m.Data[2].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.y", 'f', m.Data[2].Type));
return;
}
if (m.Data[3].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.z", 'f', m.Data[3].Type));
return;
}
if (m.Data[4].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.x", 'f', m.Data[4].Type));
return;
}
if (m.Data[5].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.y", 'f', m.Data[5].Type));
return;
}
if (m.Data[6].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.z", 'f', m.Data[6].Type));
return;
}
if (m.Data[7].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.w", 'f', m.Data[7].Type));
return;
}
Name = (string)m.Data[0].Value;
Transform = new Transform3D(new Basis(new Quaternion((float)m.Data[4].Value, (float)m.Data[5].Value, (float)m.Data[6].Value, (float)m.Data[7].Value)), new Vector3((float)m.Data[1].Value, (float)m.Data[2].Value, (float)m.Data[3].Value));
} }
public VmcExtBonePos(string name, Transform3D transform) : base(new OscAddress("/VMC/Ext/Bone/Pos")) public VmcExtBonePos(string name, Transform3D transform) : base(new OscAddress("/VMC/Ext/Bone/Pos"))
@ -87,14 +45,14 @@ namespace godotVmcSharp
{ {
var quat = Transform.Basis.GetRotationQuaternion(); var quat = Transform.Basis.GetRotationQuaternion();
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{ return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{
new OscArgument(Name, 's'), OscArgument.CreateFromParams(Name, 's')!,
new OscArgument(Transform.Origin.X, 'f'), OscArgument.CreateFromParams(Transform.Origin.X, 'f')!,
new OscArgument(Transform.Origin.Y, 'f'), OscArgument.CreateFromParams(Transform.Origin.Y, 'f')!,
new OscArgument(Transform.Origin.Z, 'f'), OscArgument.CreateFromParams(Transform.Origin.Z, 'f')!,
new OscArgument(quat.X, 'f'), OscArgument.CreateFromParams(quat.X, 'f')!,
new OscArgument(quat.Y, 'f'), OscArgument.CreateFromParams(quat.Y, 'f')!,
new OscArgument(quat.Z, 'f'), OscArgument.CreateFromParams(quat.Z, 'f')!,
new OscArgument(quat.W, 'f'), OscArgument.CreateFromParams(quat.W, 'f')!,
}); });
} }
} }

View File

@ -28,61 +28,13 @@ namespace godotVmcSharp
public readonly Transform3D Transform; public readonly Transform3D Transform;
public readonly float Fov; public readonly float Fov;
public VmcExtCam(OscMessage m) : base(m.Address) public static VmcExtCam CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 9) if (m.Data.Count < 9)
{ {
GD.Print($"Invalid number of arguments for /VMC/Ext/Cam. Expected 9, received {m.Data.Count}."); throw new MissingArgumentsException(m.Address, "9", m.Data.Count);
return;
} }
if (m.Data[0].Type != 's') return new VmcExtCam(m.Data[0].GetAsString(), new Transform3D(new Basis(new Quaternion(m.Data[4].GetAsFloat(), m.Data[5].GetAsFloat(), m.Data[6].GetAsFloat(), m.Data[7].GetAsFloat())), new Vector3(m.Data[1].GetAsFloat(), m.Data[2].GetAsFloat(), m.Data[3].GetAsFloat())), m.Data[8].GetAsFloat());
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "name", 's', m.Data[0].Type));
return;
}
if (m.Data[1].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.x", 'f', m.Data[1].Type));
return;
}
if (m.Data[2].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.y", 'f', m.Data[2].Type));
return;
}
if (m.Data[3].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.z", 'f', m.Data[3].Type));
return;
}
if (m.Data[4].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.x", 'f', m.Data[4].Type));
return;
}
if (m.Data[5].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.y", 'f', m.Data[5].Type));
return;
}
if (m.Data[6].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.z", 'f', m.Data[6].Type));
return;
}
if (m.Data[7].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.w", 'f', m.Data[7].Type));
return;
}
if (m.Data[8].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString("VMC/Ext/Cam", "fov", 'f', m.Data[8].Type));
return;
}
Name = (string)m.Data[0].Value;
Transform = new Transform3D(new Basis(new Quaternion((float)m.Data[4].Value, (float)m.Data[5].Value, (float)m.Data[6].Value, (float)m.Data[7].Value)), new Vector3((float)m.Data[1].Value, (float)m.Data[2].Value, (float)m.Data[3].Value));
Fov = (float)m.Data[8].Value;
} }
public VmcExtCam(string name, Transform3D transform, float fov) : base(new OscAddress("/VMC/Ext/Cam")) public VmcExtCam(string name, Transform3D transform, float fov) : base(new OscAddress("/VMC/Ext/Cam"))
@ -96,15 +48,15 @@ namespace godotVmcSharp
{ {
var quat = Transform.Basis.GetRotationQuaternion(); var quat = Transform.Basis.GetRotationQuaternion();
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{ return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{
new OscArgument(Name, 's'), OscArgument.CreateFromParams(Name, 's')!,
new OscArgument(Transform.Origin.X, 'f'), OscArgument.CreateFromParams(Transform.Origin.X, 'f')!,
new OscArgument(Transform.Origin.Y, 'f'), OscArgument.CreateFromParams(Transform.Origin.Y, 'f')!,
new OscArgument(Transform.Origin.Z, 'f'), OscArgument.CreateFromParams(Transform.Origin.Z, 'f')!,
new OscArgument(quat.X, 'f'), OscArgument.CreateFromParams(quat.X, 'f')!,
new OscArgument(quat.Y, 'f'), OscArgument.CreateFromParams(quat.Y, 'f')!,
new OscArgument(quat.Z, 'f'), OscArgument.CreateFromParams(quat.Z, 'f')!,
new OscArgument(quat.W, 'f'), OscArgument.CreateFromParams(quat.W, 'f')!,
new OscArgument(Fov, 'f') OscArgument.CreateFromParams(Fov, 'f')!
}); });
} }
} }

View File

@ -30,67 +30,31 @@ namespace godotVmcSharp
public readonly int IsAxis; public readonly int IsAxis;
public readonly Vector3 Axis; public readonly Vector3 Axis;
public VmcExtCon(OscMessage m) : base(m.Address) public static VmcExtCon CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 8) if (m.Data.Count < 8)
{ {
GD.Print($"Invalid number of arguments for /VMC/Ext/Con. Expected 8, received {m.Data.Count}."); throw new MissingArgumentsException(m.Address, "8", m.Data.Count);
return;
} }
if (m.Data[0].Type != 'i') var active = m.Data[0].GetAsInt32();
if (active < 0 || active > 2)
{ {
GD.Print(InvalidArgumentType.GetErrorString(Addr, "active", 'i', m.Data[0].Type)); throw new DataOutOfRangeException(m.Address, 0, "active", "{0, 1, 2}", active);
return;
} }
if (m.Data[1].Type != 's') return new VmcExtCon(active, m.Data[1].GetAsString(), m.Data[2].GetAsInt32(), m.Data[3].GetAsInt32(), m.Data[4].GetAsInt32(), new Vector3(m.Data[5].GetAsFloat(), m.Data[6].GetAsFloat(), m.Data[7].GetAsFloat()));
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "name", 's', m.Data[1].Type));
return;
}
if (m.Data[2].Type != 'i')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "IsLeft", 'i', m.Data[2].Type));
}
if (m.Data[3].Type != 'i')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "IsTouch", 'i', m.Data[3].Type));
}
if (m.Data[4].Type != 'i')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "IsAxis", 'i', m.Data[4].Type));
}
if (m.Data[5].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "Axis.x", 'f', m.Data[5].Type));
}
if (m.Data[6].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "Axis.y", 'f', m.Data[6].Type));
}
if (m.Data[7].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "Axis.z", 'f', m.Data[7].Type));
}
if ((int)m.Data[0].Value < 0 || (int)m.Data[0].Value > 2)
{
GD.Print($"Invalid value for \"active\" 'i' argument of /VMC/Ext/Con. Expected 0-2, received {(int)m.Data[0].Value}");
return;
}
Active = (int)m.Data[0].Value;
Name = (string)m.Data[1].Value;
IsLeft = (int)m.Data[2].Value;
IsTouch = (int)m.Data[3].Value;
IsAxis = (int)m.Data[4].Value;
Axis = new Vector3((float)m.Data[5].Value, (float)m.Data[6].Value, (float)m.Data[7].Value);
} }
public VmcExtCon(int active, string name, int isLeft, int isTouch, int isAxis, Vector3 axis) : base(new OscAddress("/VMC/Ext/Con")) public static VmcExtCon CreateFromParams(int active, string name, int isLeft, int isTouch, int isAxis, Vector3 axis)
{ {
if (active < 0 || active > 2) if (active < 0 || active > 2)
{ {
GD.Print($"Invalid value for \"active\" 'i' argument of {Addr}. Expected 0-2, received {active}"); throw new DataOutOfRangeException("/VMC/Ext/Con", 0, "active", "{0, 1, 2}", active);
return;
} }
return new VmcExtCon(active, name, isLeft, isTouch, isAxis, axis);
}
private VmcExtCon(int active, string name, int isLeft, int isTouch, int isAxis, Vector3 axis) : base(new OscAddress("/VMC/Ext/Con"))
{
Active = active; Active = active;
Name = name; Name = name;
IsLeft = isLeft; IsLeft = isLeft;
@ -99,17 +63,18 @@ namespace godotVmcSharp
Axis = axis; Axis = axis;
} }
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{ return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{
new OscArgument(Active, 'i'), OscArgument.CreateFromParams(Active, 'i')!,
new OscArgument(Name, 's'), OscArgument.CreateFromParams(Name, 's')!,
new OscArgument(IsLeft, 'i'), OscArgument.CreateFromParams(IsLeft, 'i')!,
new OscArgument(IsTouch, 'i'), OscArgument.CreateFromParams(IsTouch, 'i')!,
new OscArgument(IsAxis, 'i'), OscArgument.CreateFromParams(IsAxis, 'i')!,
new OscArgument(Axis.X, 'i'), OscArgument.CreateFromParams(Axis.X, 'i')!,
new OscArgument(Axis.Y, 'i'), OscArgument.CreateFromParams(Axis.Y, 'i')!,
new OscArgument(Axis.Z, 'i'), OscArgument.CreateFromParams(Axis.Z, 'i')!,
}); });
} }
} }

View File

@ -16,7 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using godotOscSharp; using godotOscSharp;
namespace godotVmcSharp namespace godotVmcSharp
@ -25,19 +24,13 @@ namespace godotVmcSharp
{ {
public readonly string Path; public readonly string Path;
public VmcExtConfig(OscMessage m) : base(m.Address) public static VmcExtConfig CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 1) if (m.Data.Count < 1)
{ {
GD.Print($"Invalid number of arguments for {Addr}. Expecting 1, received {m.Data.Count}"); throw new MissingArgumentsException(m.Address, "1", m.Data.Count);
return;
} }
if (m.Data[0].Type != 's') return new VmcExtConfig(m.Data[0].GetAsString());
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "path", 's', m.Data[0].Type));
return;
}
Path = (string)m.Data[0].Value;
} }
public VmcExtConfig(string path) : base(new OscAddress("/VMC/Ext/Config")) public VmcExtConfig(string path) : base(new OscAddress("/VMC/Ext/Config"))
@ -47,7 +40,7 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument> { new OscArgument(Path, 's') }); return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument> { OscArgument.CreateFromParams(Path, 's') });
} }
} }
} }

View File

@ -26,55 +26,13 @@ namespace godotVmcSharp
public readonly string Serial; public readonly string Serial;
public readonly Transform3D Transform; public readonly Transform3D Transform;
public VmcExtDevicePos(OscMessage m) : base(m.Address) public static VmcExtDevicePos CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 8) if (m.Data.Count < 8)
{ {
GD.Print($"Invalid number of arguments for {base.Addr}. Expected 8, received {m.Data.Count}."); throw new MissingArgumentsException(m.Address, "{8}", m.Data.Count);
return;
} }
if (m.Data[0].Type != 's') return new VmcExtDevicePos(m.Address, m.Data[0].GetAsString(), new Transform3D(new Basis(new Quaternion(m.Data[4].GetAsFloat(), m.Data[5].GetAsFloat(), m.Data[6].GetAsFloat(), m.Data[7].GetAsFloat())), new Vector3(m.Data[1].GetAsFloat(), m.Data[2].GetAsFloat(), m.Data[3].GetAsFloat())));
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "serial", 's', m.Data[0].Type));
return;
}
if (m.Data[1].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.x", 'f', m.Data[1].Type));
return;
}
if (m.Data[2].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.y", 'f', m.Data[2].Type));
return;
}
if (m.Data[3].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.z", 'f', m.Data[3].Type));
return;
}
if (m.Data[4].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.x", 'f', m.Data[4].Type));
return;
}
if (m.Data[5].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.y", 'f', m.Data[5].Type));
return;
}
if (m.Data[6].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.z", 'f', m.Data[6].Type));
return;
}
if (m.Data[7].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.w", 'f', m.Data[7].Type));
return;
}
Serial = (string)m.Data[0].Value;
Transform = new Transform3D(new Basis(new Quaternion((float)m.Data[4].Value, (float)m.Data[5].Value, (float)m.Data[6].Value, (float)m.Data[7].Value)), new Vector3((float)m.Data[1].Value, (float)m.Data[2].Value, (float)m.Data[3].Value));
} }
public VmcExtDevicePos(OscAddress Addr, string serial, Transform3D transform) : base(Addr) public VmcExtDevicePos(OscAddress Addr, string serial, Transform3D transform) : base(Addr)
@ -87,14 +45,14 @@ namespace godotVmcSharp
{ {
var quat = Transform.Basis.GetRotationQuaternion(); var quat = Transform.Basis.GetRotationQuaternion();
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{ return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{
new OscArgument(Serial, 's'), OscArgument.CreateFromParams(Serial, 's')!,
new OscArgument(Transform.Origin.X, 'f'), OscArgument.CreateFromParams(Transform.Origin.X, 'f')!,
new OscArgument(Transform.Origin.Y, 'f'), OscArgument.CreateFromParams(Transform.Origin.Y, 'f')!,
new OscArgument(Transform.Origin.Z, 'f'), OscArgument.CreateFromParams(Transform.Origin.Z, 'f')!,
new OscArgument(quat.X, 'f'), OscArgument.CreateFromParams(quat.X, 'f')!,
new OscArgument(quat.Y, 'f'), OscArgument.CreateFromParams(quat.Y, 'f')!,
new OscArgument(quat.Z, 'f'), OscArgument.CreateFromParams(quat.Z, 'f')!,
new OscArgument(quat.W, 'f') OscArgument.CreateFromParams(quat.W, 'f')!
}); });
} }
} }

View File

@ -16,7 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using godotOscSharp; using godotOscSharp;
namespace godotVmcSharp namespace godotVmcSharp
@ -26,40 +25,27 @@ namespace godotVmcSharp
public readonly int Active; public readonly int Active;
public readonly string Name; public readonly string Name;
public readonly int Keycode; public readonly int Keycode;
public VmcExtKey(OscMessage m) : base(m.Address) public static VmcExtKey CreateFromMessage(OscMessage m)
{ {
if (m.Data[0].Type != 'i') var active = m.Data[0].GetAsInt32();
if (active < 0 || active > 1)
{ {
GD.Print(InvalidArgumentType.GetErrorString(Addr, "active", 'i', m.Data[0].Type)); throw new DataOutOfRangeException(m.Address, 0, "active", "{0, 1}", active);
return;
} }
if (m.Data[1].Type != 's') return new VmcExtKey(active, m.Data[1].GetAsString(), m.Data[2].GetAsInt32());
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "name", 's', m.Data[1].Type));
return;
}
if (m.Data[2].Type != 'i')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "keycode", 'i', m.Data[2].Type));
return;
}
if ((int)m.Data[0].Value < 0 || (int)m.Data[0].Value > 1)
{
GD.Print($"Invalid value for \"active\" 'i' argument of {Addr}. Expected 0 or 1, received {(int)m.Data[0].Value}");
return;
}
Active = (int)m.Data[0].Value;
Name = (string)m.Data[1].Value;
Keycode = (int)m.Data[2].Value;
} }
public VmcExtKey(int active, string name, int keycode) : base(new OscAddress("/VMC/Ext/Key")) public static VmcExtKey CreateFromParams(int active, string name, int keycode)
{ {
if (active < 0 || active > 1) if (active < 0 || active > 1)
{ {
GD.Print($"Invalid value for \"active\" 'i' argument of {Addr}. Expected 0 or 1, received {active}"); throw new DataOutOfRangeException("/VMC/Ext/Key", 0, "active", "{0, 1}", active);
return;
} }
return new VmcExtKey(active, name, keycode);
}
private VmcExtKey(int active, string name, int keycode) : base(new OscAddress("/VMC/Ext/Key"))
{
Active = active; Active = active;
Name = name; Name = name;
Keycode = keycode; Keycode = keycode;
@ -68,9 +54,9 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{ return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{
new OscArgument(Active, 'i'), OscArgument.CreateFromParams(Active, 'i')!,
new OscArgument(Name, 's'), OscArgument.CreateFromParams(Name, 's')!,
new OscArgument(Keycode, 'i') OscArgument.CreateFromParams(Keycode, 'i')!
}); });
} }
} }

View File

@ -18,7 +18,6 @@
using Godot; using Godot;
using godotOscSharp; using godotOscSharp;
using System.Collections.Generic;
namespace godotVmcSharp namespace godotVmcSharp
{ {
@ -28,76 +27,13 @@ namespace godotVmcSharp
public readonly Transform3D Transform; public readonly Transform3D Transform;
public readonly Color Color; public readonly Color Color;
public VmcExtLight(OscMessage m) : base(m.Address) public static VmcExtLight CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 12) if (m.Data.Count < 12)
{ {
GD.Print($"Invalid number of arguments for {base.Addr}. Expected 12, received {m.Data.Count}."); throw new MissingArgumentsException(m.Address, "12", m.Data.Count);
return;
} }
if (m.Data[0].Type != 's') return new VmcExtLight(m.Data[0].GetAsString(), new Transform3D(new Basis(new Quaternion(m.Data[4].GetAsFloat(), m.Data[5].GetAsFloat(), m.Data[6].GetAsFloat(), m.Data[7].GetAsFloat())), new Vector3(m.Data[1].GetAsFloat(), m.Data[2].GetAsFloat(), m.Data[3].GetAsFloat())), new Color(m.Data[8].GetAsFloat(), m.Data[9].GetAsFloat(), m.Data[10].GetAsFloat(), m.Data[11].GetAsFloat()));
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "name", 's', m.Data[0].Type));
return;
}
if (m.Data[1].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.x", 'f', m.Data[1].Type));
return;
}
if (m.Data[2].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.y", 'f', m.Data[2].Type));
return;
}
if (m.Data[3].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.z", 'f', m.Data[3].Type));
return;
}
if (m.Data[4].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.x", 'f', m.Data[4].Type));
return;
}
if (m.Data[5].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.y", 'f', m.Data[5].Type));
return;
}
if (m.Data[6].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.z", 'f', m.Data[6].Type));
return;
}
if (m.Data[7].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.w", 'f', m.Data[7].Type));
return;
}
if (m.Data[8].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "color.red", 'f', m.Data[8].Type));
return;
}
if (m.Data[9].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "color.blue", 'f', m.Data[9].Type));
return;
}
if (m.Data[10].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "color.green", 'f', m.Data[10].Type));
return;
}
if (m.Data[11].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "color.alpha", 'f', m.Data[11].Type));
return;
}
Name = (string)m.Data[0].Value;
Transform = new Transform3D(new Basis(new Quaternion((float)m.Data[4].Value, (float)m.Data[5].Value, (float)m.Data[6].Value, (float)m.Data[7].Value)), new Vector3((float)m.Data[1].Value, (float)m.Data[2].Value, (float)m.Data[3].Value));
Color = new Color((float)m.Data[8].Value, (float)m.Data[9].Value, (float)m.Data[10].Value, (float)m.Data[11].Value);
} }
public VmcExtLight(string name, Transform3D transform, Color color) : base(new OscAddress("/VMC/Ext/Light")) public VmcExtLight(string name, Transform3D transform, Color color) : base(new OscAddress("/VMC/Ext/Light"))
@ -110,19 +46,19 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
var quat = Transform.Basis.GetRotationQuaternion(); var quat = Transform.Basis.GetRotationQuaternion();
return new OscMessage(Addr, new List<OscArgument>{ return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{
new OscArgument(Name, 's'), OscArgument.CreateFromParams(Name, 's')!,
new OscArgument(Transform.Origin.X, 'f'), OscArgument.CreateFromParams(Transform.Origin.X, 'f')!,
new OscArgument(Transform.Origin.Y, 'f'), OscArgument.CreateFromParams(Transform.Origin.Y, 'f')!,
new OscArgument(Transform.Origin.Z, 'f'), OscArgument.CreateFromParams(Transform.Origin.Z, 'f')!,
new OscArgument(quat.X, 'f'), OscArgument.CreateFromParams(quat.X, 'f')!,
new OscArgument(quat.Y, 'f'), OscArgument.CreateFromParams(quat.Y, 'f')!,
new OscArgument(quat.Z, 'f'), OscArgument.CreateFromParams(quat.Z, 'f')!,
new OscArgument(quat.W, 'f'), OscArgument.CreateFromParams(quat.W, 'f')!,
new OscArgument(Color.R, 'f'), OscArgument.CreateFromParams(Color.R, 'f')!,
new OscArgument(Color.G, 'f'), OscArgument.CreateFromParams(Color.G, 'f')!,
new OscArgument(Color.B, 'f'), OscArgument.CreateFromParams(Color.B, 'f')!,
new OscArgument(Color.A, 'f') OscArgument.CreateFromParams(Color.A, 'f')!
}); });
} }
} }

View File

@ -16,7 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using godotOscSharp; using godotOscSharp;
namespace godotVmcSharp namespace godotVmcSharp
@ -25,34 +24,27 @@ namespace godotVmcSharp
{ {
public readonly int Knob; public readonly int Knob;
public readonly int Active; public readonly int Active;
public VmcExtMidiCcBit(OscMessage m) : base(m.Address) public static VmcExtMidiCcBit CreateFromMessage(OscMessage m)
{ {
if (m.Data[0].Type != 'i') var active = m.Data[1].GetAsInt32();
if (active < 0 || active > 1)
{ {
GD.Print(InvalidArgumentType.GetErrorString(Addr, "knob", 'i', m.Data[0].Type)); throw new DataOutOfRangeException(m.Address, 1, "active", "{0, 1}", active);
return;
} }
if (m.Data[1].Type != 'i') return new VmcExtMidiCcBit(m.Data[0].GetAsInt32(), active);
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "active", 'i', m.Data[1].Type));
return;
}
if ((int)m.Data[1].Value < 0 || (int)m.Data[1].Value > 1)
{
GD.Print($"Invalid value for \"active\" argument of {Addr}. Expected 0 or 1, received {(int)m.Data[1].Value}.");
return;
}
Knob = (int)m.Data[0].Value;
Active = (int)m.Data[1].Value;
} }
public VmcExtMidiCcBit(int knob, int active) : base(new OscAddress("/VMC/Ext/Midi/CC/Bit")) public static VmcExtMidiCcBit CreateFromParams(int knob, int active)
{ {
if (active < 0 || active > 1) if (active < 0 || active > 1)
{ {
GD.Print($"Invalid value for \"active\" argument of {Addr}. Expected 0 or 1, received {active}."); throw new DataOutOfRangeException("/VMC/Ext/Midi/CC/Bit", 1, "active", "{0, 1}", active);
return;
} }
return new VmcExtMidiCcBit(knob, active);
}
private VmcExtMidiCcBit(int knob, int active) : base(new OscAddress("/VMC/Ext/Midi/CC/Bit"))
{
Knob = knob; Knob = knob;
Active = active; Active = active;
} }
@ -60,8 +52,8 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{ return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{
new OscArgument(Knob, 'i'), OscArgument.CreateFromParams(Knob, 'i')!,
new OscArgument(Active, 'i') OscArgument.CreateFromParams(Active, 'i')!
}); });
} }
} }

View File

@ -16,7 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using godotOscSharp; using godotOscSharp;
namespace godotVmcSharp namespace godotVmcSharp
@ -25,20 +24,13 @@ namespace godotVmcSharp
{ {
public readonly int Knob; public readonly int Knob;
public readonly float Value; public readonly float Value;
public VmcExtMidiCcVal(OscMessage m) : base(m.Address) public static VmcExtMidiCcVal CreateFromMessage(OscMessage m)
{ {
if (m.Data[0].Type != 'i') if (m.Data.Count < 2)
{ {
GD.Print(InvalidArgumentType.GetErrorString(Addr, "knob", 'i', m.Data[0].Type)); throw new MissingArgumentsException(m.Address, "{2}", m.Data.Count);
return;
} }
if (m.Data[1].Type != 'f') return new VmcExtMidiCcVal(m.Data[0].GetAsInt32(), m.Data[1].GetAsFloat());
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "value", 'f', m.Data[1].Type));
return;
}
Knob = (int)m.Data[0].Value;
Value = (int)m.Data[1].Value;
} }
public VmcExtMidiCcVal(int knob, float value) : base(new OscAddress("/VMC/Ext/Midi/CC/Val")) public VmcExtMidiCcVal(int knob, float value) : base(new OscAddress("/VMC/Ext/Midi/CC/Val"))
@ -50,8 +42,8 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{ return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{
new OscArgument(Knob, 'i'), OscArgument.CreateFromParams(Knob, 'i')!,
new OscArgument(Value, 'f') OscArgument.CreateFromParams(Value, 'f')!
}); });
} }
} }

View File

@ -16,7 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using godotOscSharp; using godotOscSharp;
namespace godotVmcSharp namespace godotVmcSharp
@ -28,46 +27,31 @@ namespace godotVmcSharp
public readonly int Note; public readonly int Note;
public readonly float Velocity; public readonly float Velocity;
public VmcExtMidiNote(OscMessage m) : base(m.Address) public static VmcExtMidiNote CreateFromMessage(OscMessage m)
{ {
if (m.Data[0].Type != 'i') if (m.Data.Count < 4)
{ {
GD.Print(InvalidArgumentType.GetErrorString(Addr, "active", 'i', m.Data[0].Type)); throw new MissingArgumentsException(m.Address, "{4}", m.Data.Count);
return;
} }
if (m.Data[1].Type != 'i') var active = m.Data[0].GetAsInt32();
if (active < 0 || active > 1)
{ {
GD.Print(InvalidArgumentType.GetErrorString(Addr, "channel", 'i', m.Data[1].Type)); throw new DataOutOfRangeException(m.Address, 0, "active", "{0, 1}", active);
return;
} }
if (m.Data[2].Type != 'i') return new VmcExtMidiNote(active, m.Data[1].GetAsInt32(), m.Data[2].GetAsInt32(), m.Data[3].GetAsFloat());
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "note", 'i', m.Data[2].Type));
return;
}
if (m.Data[3].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "velocity", 'f', m.Data[4].Type));
return;
}
if ((int)m.Data[0].Value < 0 || (int)m.Data[0].Value > 1)
{
GD.Print($"Invalid value for \"active\" 'i' argument of {Addr}. Expected 0 or 1, received {(int)m.Data[0].Value}");
return;
}
Active = (int)m.Data[0].Value;
Channel = (int)m.Data[1].Value;
Note = (int)m.Data[2].Value;
Velocity = (int)m.Data[3].Value;
} }
public VmcExtMidiNote(int active, int channel, int note, float velocity) : base(new OscAddress("/VMC/Ext/Midi/Note")) public static VmcExtMidiNote CreateFromParams(int active, int channel, int note, float velocity)
{ {
if (active < 0 || active > 1) if (active < 0 || active > 1)
{ {
GD.Print($"Invalid value for \"active\" 'i' argument of {Addr}. Expected 0 or 1, received {Active}."); throw new DataOutOfRangeException("/VMC/Ext/Midi/Note", 0, "active", "{0, 1}", active);
return;
} }
return new VmcExtMidiNote(active, channel, note, velocity);
}
private VmcExtMidiNote(int active, int channel, int note, float velocity) : base(new OscAddress("/VMC/Ext/Midi/Note"))
{
Active = active; Active = active;
Channel = channel; Channel = channel;
Note = note; Note = note;
@ -77,10 +61,10 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{ return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{
new OscArgument(Active, 'i'), OscArgument.CreateFromParams(Active, 'i')!,
new OscArgument(Channel, 'i'), OscArgument.CreateFromParams(Channel, 'i')!,
new OscArgument(Note, 'i'), OscArgument.CreateFromParams(Note, 'i')!,
new OscArgument(Velocity, 'f') OscArgument.CreateFromParams(Velocity, 'f')!
}); });
} }
} }

View File

@ -17,7 +17,6 @@
*/ */
using godotOscSharp; using godotOscSharp;
using Godot;
using System.Collections.Generic; using System.Collections.Generic;
namespace godotVmcSharp namespace godotVmcSharp
@ -29,163 +28,120 @@ namespace godotVmcSharp
public readonly int? CalibrationMode; public readonly int? CalibrationMode;
public readonly int? TrackingStatus; public readonly int? TrackingStatus;
public VmcExtOk(int loaded) : base(new OscAddress("/VMC/Ext/OK")) public static VmcExtOk CreateFromParams(int loaded)
{ {
if (loaded < 0 || loaded > 1) if (loaded < 0 || loaded > 1)
{ {
GD.Print($"Invalid value for loaded status. Expected 0 or 1, received {loaded}."); throw new DataOutOfRangeException("/VMC/Ext/OK", 0, "loaded", "{0, 1}", loaded);
return;
} }
return new VmcExtOk(loaded);
}
private VmcExtOk(int loaded): base(new OscAddress("/VMC/Ext/OK"))
{
Loaded = loaded; Loaded = loaded;
} }
public VmcExtOk(int loaded, int calibrationState, int calibrationMode) : base(new OscAddress("/VMC/Ext/OK")) public static VmcExtOk CreateFromParams(int loaded, int calibrationState, int calibrationMode)
{ {
if (loaded < 0 || loaded > 1) if (loaded < 0 || loaded > 1)
{ {
GD.Print($"Invalid value for loaded status. Expected 0 or 1, received {loaded}."); throw new DataOutOfRangeException("/VMC/Ext/OK", 0, "loaded", "{0, 1}", loaded);
return;
} }
if (calibrationState < 0 || calibrationState > 3) if (calibrationState < 0 || calibrationState > 3)
{ {
GD.Print($"Invalid value for calibration state. Expected 0-3, received {calibrationState}"); throw new DataOutOfRangeException("/VMC/Ext/OK", 1, "calibrationState", "{0..3}", calibrationState);
return;
} }
if (calibrationMode < 0 || calibrationMode > 2) if (calibrationMode < 0 || calibrationMode > 2)
{ {
GD.Print($"Invalid value for calibration mode. Expected 0-2, received {calibrationMode}"); throw new DataOutOfRangeException("/VMC/Ext/OK", 2, "calibrationMode", "{0..2}", calibrationMode);
return;
} }
return new VmcExtOk(loaded, calibrationState, calibrationMode);
}
private VmcExtOk(int loaded, int calibrationState, int calibrationMode) : base(new OscAddress("/VMC/Ext/OK"))
{
Loaded = loaded; Loaded = loaded;
CalibrationState = calibrationState; CalibrationState = calibrationState;
CalibrationMode = calibrationMode; CalibrationMode = calibrationMode;
} }
public VmcExtOk(int loaded, int calibrationState, int calibrationMode, int trackingStatus) : base(new OscAddress("/VMC/Ext/OK")) public static VmcExtOk CreateFromParams(int loaded, int calibrationState, int calibrationMode, int trackingStatus)
{ {
if (loaded < 0 || loaded > 1) if (loaded < 0 || loaded > 1)
{ {
GD.Print($"Invalid value for loaded status. Expected 0 or 1, received {loaded}."); throw new DataOutOfRangeException("/VMC/Ext/OK", 0, "loaded", "{0, 1}", loaded);
return;
} }
if (calibrationState < 0 || calibrationState > 3) if (calibrationState < 0 || calibrationState > 3)
{ {
GD.Print($"Invalid value for calibration state. Expected 0-3, received {calibrationState}"); throw new DataOutOfRangeException("/VMC/Ext/OK", 1, "calibrationState", "{0..3}", calibrationState);
return;
} }
if (calibrationMode < 0 || calibrationMode > 2) if (calibrationMode < 0 || calibrationMode > 2)
{ {
GD.Print($"Invalid value for calibration mode. Expected 0-2, received {calibrationMode}"); throw new DataOutOfRangeException("/VMC/Ext/OK", 2, "calibrationMode", "{0..2}", calibrationMode);
return;
} }
if (trackingStatus < 0 || trackingStatus > 1) if (trackingStatus < 0 || trackingStatus > 1)
{ {
GD.Print($"Invalid value for tracking status. Expected 0-1, received {trackingStatus}"); throw new DataOutOfRangeException("/VMC/Ext/OK", 3, "trackingStatus", "{0, 1}", trackingStatus);
return;
} }
return new VmcExtOk(loaded, calibrationState, calibrationMode, trackingStatus);
}
private VmcExtOk(int loaded, int calibrationState, int calibrationMode, int trackingStatus) : base(new OscAddress("/VMC/Ext/OK"))
{
Loaded = loaded; Loaded = loaded;
CalibrationState = calibrationState; CalibrationState = calibrationState;
CalibrationMode = calibrationMode; CalibrationMode = calibrationMode;
TrackingStatus = trackingStatus; TrackingStatus = trackingStatus;
} }
public VmcExtOk(OscMessage m) : base(m.Address) public static VmcExtOk CreateFromMessage(OscMessage m)
{ {
switch (m.Data.Count) switch (m.Data.Count)
{ {
case 1: case 1:
if (!OkParam0(m.Data[0])) return new VmcExtOk(getLoaded(m));
{
return;
}
Loaded = (int)m.Data[0].Value;
break;
case 3: case 3:
if (!OkParam1And2(m.Data[0], m.Data[1], m.Data[2])) return new VmcExtOk(getLoaded(m), getCalibrationState(m), getCalibrationMode(m));
{
return;
}
Loaded = (int)m.Data[0].Value;
CalibrationState = (int)m.Data[1].Value;
CalibrationMode = (int)m.Data[2].Value;
break;
case 4: case 4:
if (!OkParam3(m.Data[0], m.Data[1], m.Data[2], m.Data[3])) var trackingStatus = m.Data[3].GetAsInt32();
if (trackingStatus < 0 || trackingStatus > 1)
{ {
return; throw new DataOutOfRangeException("/VMC/Ext/OK", 3, "trackingStatus", "{0, 1}", trackingStatus);
} }
Loaded = (int)m.Data[0].Value; return new VmcExtOk(getLoaded(m), getCalibrationState(m), getCalibrationMode(m), trackingStatus);
CalibrationState = (int)m.Data[1].Value;
CalibrationMode = (int)m.Data[2].Value;
TrackingStatus = (int)m.Data[3].Value;
break;
default: default:
GD.Print($"Invalid number of arguments for /VMC/Ext/OK message. Expected 1, 3, or 4 but received {m.Data.Count}"); throw new MissingArgumentsException(m.Address, "{1, 3, 4}", m.Data.Count);
return;
} }
} }
private bool OkParam0(OscArgument arg) private static int getLoaded(OscMessage m)
{ {
if (arg.Type != 'i') var loaded = m.Data[0].GetAsInt32();
if (loaded < 0 || loaded > 1)
{ {
GD.Print($"Invalid argument type for /VMC/Ext/OK message. Expected int in argument 0, received {arg.Type}"); throw new DataOutOfRangeException("/VMC/Ext/OK", 0, "loaded", "{0, 1}", loaded);
return false;
} }
if ((int)arg.Value < 0 && (int)arg.Value > 1) return loaded;
{
GD.Print($"Invalid value for loaded status. Expected 0-1, received {(int)arg.Value}");
return false;
}
return true;
} }
private bool OkParam1And2(OscArgument arg0, OscArgument arg1, OscArgument arg2) private static int getCalibrationState(OscMessage m)
{ {
if (!OkParam0(arg0)) var calibrationState = m.Data[1].GetAsInt32();
if (calibrationState < 0 || calibrationState > 3)
{ {
return false; throw new DataOutOfRangeException("/VMC/Ext/OK", 1, "calibrationState", "{0..3}", calibrationState);
} }
if (arg1.Type != 'i') return calibrationState;
{
GD.Print($"Invalid argument type for /VMC/Ext/OK message. Expected int in argument 1, received {arg1.Type}");
return false;
}
if (arg2.Type != 'i')
{
GD.Print($"Invalid argument type for /VMC/Ext/OK message. Expected int in argument 2, received {arg2.Type}");
return false;
}
if ((int)arg1.Value < 0 && (int)arg1.Value > 3)
{
GD.Print($"Invalid value for calibration state. Expected 0-3, received {(int)arg1.Value}");
return false;
}
if ((int)arg2.Value < 0 && (int)arg2.Value > 2)
{
GD.Print($"Invalid value for calibration mode. Expected 0-2, received {(int)arg2.Value}");
return false;
}
return true;
} }
private bool OkParam3(OscArgument arg0, OscArgument arg1, OscArgument arg2, OscArgument arg) private static int getCalibrationMode(OscMessage m)
{ {
if (!OkParam1And2(arg0, arg1, arg2)) var calibrationMode = m.Data[2].GetAsInt32();
if (calibrationMode < 0 || calibrationMode > 2)
{ {
return false; throw new DataOutOfRangeException("/VMC/Ext/OK", 2, "calibrationMode", "{0..2}", calibrationMode);
} }
if (arg.Type != 'i') return calibrationMode;
{
GD.Print($"Invalid argument type for /VMC/Ext/OK message. Expected int in argument 3, received {arg.Type}");
return false;
}
if ((int)arg.Value < 0 && (int)arg.Value > 1)
{
GD.Print($"Invalid value for tracking status. Expected 0-1, received {(int)arg.Value}");
return false;
}
return true;
} }
public new OscMessage ToMessage() public new OscMessage ToMessage()
@ -193,22 +149,22 @@ namespace godotVmcSharp
if (CalibrationState == null) if (CalibrationState == null)
{ {
return new OscMessage(Addr, new List<OscArgument>{ return new OscMessage(Addr, new List<OscArgument>{
new OscArgument(Loaded, 'i') OscArgument.CreateFromParams(Loaded, 'i')!
}); });
} }
if (TrackingStatus == null) if (TrackingStatus == null)
{ {
return new OscMessage(Addr, new List<OscArgument>{ return new OscMessage(Addr, new List<OscArgument>{
new OscArgument(Loaded, 'i'), OscArgument.CreateFromParams(Loaded, 'i')!,
new OscArgument(CalibrationState, 'i'), OscArgument.CreateFromParams(CalibrationState, 'i')!,
new OscArgument(CalibrationMode, 'i') OscArgument.CreateFromParams(CalibrationMode, 'i')!
}); });
} }
return new OscMessage(Addr, new List<OscArgument>{ return new OscMessage(Addr, new List<OscArgument>{
new OscArgument(Loaded, 'i'), OscArgument.CreateFromParams(Loaded, 'i')!,
new OscArgument(CalibrationState, 'i'), OscArgument.CreateFromParams(CalibrationState, 'i')!,
new OscArgument(CalibrationMode, 'i'), OscArgument.CreateFromParams(CalibrationMode, 'i')!,
new OscArgument(TrackingStatus, 'i') OscArgument.CreateFromParams(TrackingStatus, 'i')!
}); });
} }
} }

View File

@ -16,7 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using godotOscSharp; using godotOscSharp;
namespace godotVmcSharp namespace godotVmcSharp
@ -25,19 +24,13 @@ namespace godotVmcSharp
{ {
public readonly string option; public readonly string option;
public VmcExtOpt(OscMessage m) : base(m.Address) public static VmcExtOpt CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 1) if (m.Data.Count < 1)
{ {
GD.Print($"Invalid number of arguments for {Addr}. Expecting 1, received {m.Data.Count}"); throw new MissingArgumentsException(m.Address, "1", m.Data.Count);
return;
} }
if (m.Data[0].Type != 's') return new VmcExtOpt(m.Data[0].GetAsString());
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "option", 's', m.Data[0].Type));
return;
}
option = (string)m.Data[0].Value;
} }
public VmcExtOpt(string _option) : base(new OscAddress("/VMC/Ext/Opt")) public VmcExtOpt(string _option) : base(new OscAddress("/VMC/Ext/Opt"))
@ -47,7 +40,7 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{new OscArgument(option, 's')}); return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{OscArgument.CreateFromParams(option, 's')!});
} }
} }
} }

View File

@ -16,88 +16,82 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using godotOscSharp; using godotOscSharp;
using System.Collections.Generic; using System.Collections.Generic;
#nullable enable
namespace godotVmcSharp namespace godotVmcSharp
{ {
public class VmcExtRcv : VmcMessage public class VmcExtRcv : VmcMessage
{ {
public readonly int Enable; public readonly int Enable;
public readonly int Port; public readonly int Port;
public readonly string IpAddress; public readonly string? IpAddress;
public VmcExtRcv(OscMessage m) : base(m.Address) public static VmcExtRcv CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count > 3 || m.Data.Count < 2) if (m.Data.Count < 2)
{ {
GD.Print($"Invalid number of arguments for {Addr}. Expecting 2 or 3, received {m.Data.Count}"); throw new MissingArgumentsException(m.Address, "{2, 3}", m.Data.Count);
return;
} }
if (m.Data[0].Type != 'i') var enable = m.Data[0].GetAsInt32();
if (enable < 0 || enable > 1)
{ {
GD.Print(InvalidArgumentType.GetErrorString(Addr, "enable", 'i', m.Data[0].Type)); throw new DataOutOfRangeException(m.Address, 0, "enable", "{0, 1}", enable);
return;
} }
if (m.Data[1].Type != 'i') var port = m.Data[1].GetAsInt32();
if (port < 0 || port > 65535)
{ {
GD.Print(InvalidArgumentType.GetErrorString(Addr, "port", 'i', m.Data[0].Type)); throw new DataOutOfRangeException(m.Address, 1, "port", "{0..65535}", port);
return;
} }
if ((int)m.Data[0].Value < 0 || (int)m.Data[0].Value > 1) if (m.Data.Count >= 2) {
{ return new VmcExtRcv(enable, port);
GD.Print($"Invalid value for \"enable\" argument of {Addr}. Expected 0 or 1, received {(int)m.Data[0].Value}.");
return;
} }
if ((int)m.Data[1].Value < 0 || (int)m.Data[1].Value > 65535) return new VmcExtRcv(enable, port, m.Data[2].GetAsString());
{
GD.Print($"Invalid value for \"port\" argument of {Addr}. Expected 0-65535, received {(int)m.Data[1].Value}.");
return;
}
Enable = (int)m.Data[0].Value;
Port = (int)m.Data[1].Value;
if (m.Data.Count != 3)
{
IpAddress = "";
return;
}
if (m.Data[2].Type != 's')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "IpAddress", 's', m.Data[2].Type));
return;
}
IpAddress = (string)m.Data[2].Value;
} }
public VmcExtRcv(int enable, int port) : base(new OscAddress("/VMC/Ext/Rcv")) public static VmcExtRcv CreateFromParams(int enable, int port)
{ {
if (enable < 0 || enable > 1) if (enable < 0 || enable > 1)
{ {
GD.Print($"Invalid value for \"enable\" argument of {Addr}. Expected 0 or 1, received {enable}."); throw new DataOutOfRangeException("/VMC/Ext/Rcv", 0, "enable", "{0, 1}", enable);
return;
} }
if (port < 0 || port > 65535) if (port < 0 || port > 65535)
{ {
GD.Print($"Invalid value for \"port\" argument of {Addr}. Expected 0-65535, received {port}."); throw new DataOutOfRangeException("/VMC/Ext/Rcv", 1, "port", "{0..65535}", port);
return;
} }
return new VmcExtRcv(enable, port);
}
private VmcExtRcv(int enable, int port) : base(new OscAddress("/VMC/Ext/Rcv"))
{
Enable = enable; Enable = enable;
Port = port; Port = port;
IpAddress = "";
} }
public VmcExtRcv(int enable, int port, string ipAddress) : base(new OscAddress("/VMC/Ext/Rcv")) public static VmcExtRcv CreateFromMessage(int enable, int port, string ipAddress)
{ {
if (enable < 0 || enable > 1) if (enable < 0 || enable > 1)
{ {
GD.Print($"Invalid value for \"enable\" argument of {Addr}. Expected 0 or 1, received {enable}."); throw new DataOutOfRangeException("/VMC/Ext/Rcv", 0, "enable", "{0, 1}", enable);
return;
} }
if (port < 0 || port > 65535) if (port < 0 || port > 65535)
{ {
GD.Print($"Invalid value for \"port\" argument of {Addr}. Expected 0-65535, received {port}."); throw new DataOutOfRangeException("/VMC/Ext/Rcv", 1, "port", "{0..65535}", port);
return; }
return new VmcExtRcv(enable, port, ipAddress);
}
private VmcExtRcv(int enable, int port, string ipAddress) : base(new OscAddress("/VMC/Ext/Rcv"))
{
if (enable < 0 || enable > 1)
{
throw new DataOutOfRangeException("/VMC/Ext/Rcv", 0, "enable", "{0, 1}", enable);
}
if (port < 0 || port > 65535)
{
throw new DataOutOfRangeException("/VMC/Ext/Rcv", 1, "port", "{0..65535}", port);
} }
Enable = enable; Enable = enable;
Port = port; Port = port;
@ -106,17 +100,17 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
if (IpAddress == "") if (IpAddress == null)
{ {
return new OscMessage(Addr, new List<OscArgument>{ return new OscMessage(Addr, new List<OscArgument>{
new OscArgument(Enable, 'i'), OscArgument.CreateFromParams(Enable, 'i')!,
new OscArgument(Port, 'i'), OscArgument.CreateFromParams(Port, 'i')!,
}); });
} }
return new OscMessage(Addr, new List<OscArgument>{ return new OscMessage(Addr, new List<OscArgument>{
new OscArgument(Enable, 'i'), OscArgument.CreateFromParams(Enable, 'i')!,
new OscArgument(Port, 'i'), OscArgument.CreateFromParams(Port, 'i')!,
new OscArgument(IpAddress, 's'), OscArgument.CreateFromParams(IpAddress, 's')!,
}); });
} }
} }

View File

@ -16,7 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using godotOscSharp; using godotOscSharp;
namespace godotVmcSharp namespace godotVmcSharp
@ -26,25 +25,13 @@ namespace godotVmcSharp
public readonly string Service; public readonly string Service;
public readonly string Json; public readonly string Json;
public VmcExtRemote(OscMessage m) : base(m.Address) public static VmcExtRemote CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 2) if (m.Data.Count < 2)
{ {
GD.Print($"Invalid number of arguments for {Addr} message. Expected 2 but received {m.Data.Count}"); throw new MissingArgumentsException(m.Address, "2", m.Data.Count);
return;
} }
if (m.Data[0].Type != 's') return new VmcExtRemote(m.Data[0].GetAsString(), m.Data[1].GetAsString());
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "service", 's', m.Data[0].Type));
return;
}
if (m.Data[1].Type != 's')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "json", 's', m.Data[1].Type));
return;
}
Service = (string)m.Data[0].Value;
Json = (string)m.Data[1].Value;
} }
public VmcExtRemote(string service, string json) : base(new OscAddress("/VMC/Ext/Remote")) public VmcExtRemote(string service, string json) : base(new OscAddress("/VMC/Ext/Remote"))
@ -56,8 +43,8 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{ return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{
new OscArgument(Service, 's'), OscArgument.CreateFromParams(Service, 's')!,
new OscArgument(Json, 's') OscArgument.CreateFromParams(Json, 's')!
}); });
} }
} }

View File

@ -30,31 +30,16 @@ namespace godotVmcSharp
public readonly Vector3? Scale; public readonly Vector3? Scale;
public readonly Vector3? Offset; public readonly Vector3? Offset;
public VmcExtRootPos(OscMessage m) : base(m.Address) public static VmcExtRootPos CreateFromMessage(OscMessage m)
{ {
switch (m.Data.Count) switch (m.Data.Count)
{ {
case 8: case 8:
if (!Transform8(m.Data)) return new VmcExtRootPos(m.Data[0].GetAsString(), new Transform3D(new Basis(new Quaternion(m.Data[4].GetAsFloat(), m.Data[5].GetAsFloat(), m.Data[6].GetAsFloat(), m.Data[7].GetAsFloat())), new Vector3(m.Data[1].GetAsFloat(), m.Data[2].GetAsFloat(), m.Data[3].GetAsFloat())));
{
return;
}
Name = (string)m.Data[0].Value;
Transform = new Transform3D(new Basis(new Quaternion((float)m.Data[4].Value, (float)m.Data[5].Value, (float)m.Data[6].Value, (float)m.Data[7].Value)), new Vector3((float)m.Data[1].Value, (float)m.Data[2].Value, (float)m.Data[3].Value));
break;
case 14: case 14:
if (!Transform14(m.Data)) return new VmcExtRootPos(m.Data[0].GetAsString(), new Transform3D(new Basis(new Quaternion(m.Data[4].GetAsFloat(), m.Data[5].GetAsFloat(), m.Data[6].GetAsFloat(), m.Data[7].GetAsFloat())), new Vector3(m.Data[1].GetAsFloat(), m.Data[2].GetAsFloat(), m.Data[3].GetAsFloat())), new Vector3(m.Data[8].GetAsFloat(), m.Data[9].GetAsFloat(), m.Data[10].GetAsFloat()), new Vector3(m.Data[11].GetAsFloat(), m.Data[12].GetAsFloat(), m.Data[13].GetAsFloat()));
{
return;
}
Name = (string)m.Data[0].Value;
Transform = new Transform3D(new Basis(new Quaternion((float)m.Data[4].Value, (float)m.Data[5].Value, (float)m.Data[6].Value, (float)m.Data[7].Value)), new Vector3((float)m.Data[1].Value, (float)m.Data[2].Value, (float)m.Data[3].Value));
Scale = new Vector3((float)m.Data[8].Value, (float)m.Data[9].Value, (float)m.Data[10].Value);
Offset = new Vector3((float)m.Data[11].Value, (float)m.Data[12].Value, (float)m.Data[13].Value);
break;
default: default:
GD.Print($"Invalid number of arguments for {Addr}. Expected 8 or 14, received {m.Data.Count}."); throw new MissingArgumentsException(m.Address, "{8, 14}", m.Data.Count);
return;
} }
} }
@ -72,121 +57,37 @@ namespace godotVmcSharp
Offset = offset; Offset = offset;
} }
private bool Transform8(List<OscArgument> data)
{
if (data[0].Type != 's')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "name", 's', data[0].Type));
return false;
}
if (data[1].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.x", 'f', data[1].Type));
return false;
}
if (data[2].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.y", 'f', data[2].Type));
return false;
}
if (data[3].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.z", 'f', data[3].Type));
return false;
}
if (data[4].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.x", 'f', data[4].Type));
return false;
}
if (data[5].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.y", 'f', data[5].Type));
return false;
}
if (data[6].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.z", 'f', data[6].Type));
return false;
}
if (data[7].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "q.w", 'f', data[7].Type));
return false;
}
return true;
}
private bool Transform14(List<OscArgument> data)
{
if (!Transform8(data))
{
return false;
}
if (data[8].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "s.x", 'f', data[8].Type));
return false;
}
if (data[9].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "s.y", 'f', data[9].Type));
return false;
}
if (data[10].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "s.z", 'f', data[10].Type));
return false;
}
if (data[11].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "o.x", 'f', data[11].Type));
return false;
}
if (data[12].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "o.y", 'f', data[12].Type));
return false;
}
if (data[13].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "o.z", 'f', data[13].Type));
return false;
}
return true;
}
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
var quat = Transform.Basis.GetRotationQuaternion(); var quat = Transform.Basis.GetRotationQuaternion();
if (!Scale.HasValue) if (!Scale.HasValue)
{ {
return new OscMessage(Addr, new List<OscArgument>{ return new OscMessage(Addr, new List<OscArgument>{
new OscArgument(Name, 's'), OscArgument.CreateFromParams(Name, 's')!,
new OscArgument(Transform.Origin.X, 'f'), OscArgument.CreateFromParams(Transform.Origin.X, 'f')!,
new OscArgument(Transform.Origin.Y, 'f'), OscArgument.CreateFromParams(Transform.Origin.Y, 'f')!,
new OscArgument(Transform.Origin.Z, 'f'), OscArgument.CreateFromParams(Transform.Origin.Z, 'f')!,
new OscArgument(quat.X, 'f'), OscArgument.CreateFromParams(quat.X, 'f')!,
new OscArgument(quat.Y, 'f'), OscArgument.CreateFromParams(quat.Y, 'f')!,
new OscArgument(quat.Z, 'f'), OscArgument.CreateFromParams(quat.Z, 'f')!,
new OscArgument(quat.W, 'f'), OscArgument.CreateFromParams(quat.W, 'f')!,
}); });
} }
return new OscMessage(Addr, new List<OscArgument>{ return new OscMessage(Addr, new List<OscArgument>{
new OscArgument(Name, 's'), OscArgument.CreateFromParams(Name, 's')!,
new OscArgument(Transform.Origin.X, 'f'), OscArgument.CreateFromParams(Transform.Origin.X, 'f')!,
new OscArgument(Transform.Origin.Y, 'f'), OscArgument.CreateFromParams(Transform.Origin.Y, 'f')!,
new OscArgument(Transform.Origin.Z, 'f'), OscArgument.CreateFromParams(Transform.Origin.Z, 'f')!,
new OscArgument(quat.X, 'f'), OscArgument.CreateFromParams(quat.X, 'f')!,
new OscArgument(quat.Y, 'f'), OscArgument.CreateFromParams(quat.Y, 'f')!,
new OscArgument(quat.Z, 'f'), OscArgument.CreateFromParams(quat.Z, 'f')!,
new OscArgument(quat.W, 'f'), OscArgument.CreateFromParams(quat.W, 'f')!,
new OscArgument(Scale.Value.X, 'f'), OscArgument.CreateFromParams(Scale!.Value.X, 'f')!,
new OscArgument(Scale.Value.Y, 'f'), OscArgument.CreateFromParams(Scale!.Value.Y, 'f')!,
new OscArgument(Scale.Value.Z, 'f'), OscArgument.CreateFromParams(Scale!.Value.Z, 'f')!,
new OscArgument(Offset.Value.X, 'f'), OscArgument.CreateFromParams(Offset!.Value.X, 'f')!,
new OscArgument(Offset.Value.Y, 'f'), OscArgument.CreateFromParams(Offset!.Value.Y, 'f')!,
new OscArgument(Offset.Value.Z, 'f'), OscArgument.CreateFromParams(Offset!.Value.Z, 'f')!,
}); });
} }
} }

View File

@ -16,7 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using godotOscSharp; using godotOscSharp;
namespace godotVmcSharp namespace godotVmcSharp
@ -25,39 +24,37 @@ namespace godotVmcSharp
{ {
public readonly int Mode; public readonly int Mode;
public VmcExtSetCalibExec(OscMessage m) : base(m.Address) public static VmcExtSetCalibExec CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 1) if (m.Data.Count < 1)
{ {
GD.Print($"Invalid number of arguments for {Addr}. Expecting 1, received {m.Data.Count}"); throw new MissingArgumentsException(m.Address, "{1}", m.Data.Count);
return;
} }
if (m.Data[0].Type != 'i') var mode = m.Data[0].GetAsInt32();
if (mode < 0 || mode > 2)
{ {
GD.Print(InvalidArgumentType.GetErrorString(Addr, "mode", 'i', m.Data[0].Type)); throw new DataOutOfRangeException(m.Address, 0, "mode", "{0..2}", mode);
return;
} }
if ((int)m.Data[0].Value < 0 || (int)m.Data[0].Value > 2) return new VmcExtSetCalibExec(mode);
{
GD.Print($"Invalid value for argument \"mode\" of \"/VMC/Ext/Set/Calib/Exec\". Expected in range 0-2, received {(int)m.Data[0].Value}");
return;
}
Mode = (int)m.Data[0].Value;
} }
public VmcExtSetCalibExec(int mode) : base(new OscAddress("/VMC/Ext/Set/Calib/Exec")) public static VmcExtSetCalibExec CreateFromParams(int mode)
{ {
if (mode < 0 || mode > 2) if (mode < 0 || mode > 2)
{ {
GD.Print($"Invalid value for argument \"mode\" of \"/VMC/Ext/Set/Calib/Exec\". Expected in range 0-2, received {mode}"); throw new DataOutOfRangeException("/VMC/Ext/Set/Calib/Exec", 0, "mode", "{0..2}", mode);
return;
} }
return new VmcExtSetCalibExec(mode);
}
private VmcExtSetCalibExec(int mode) : base(new OscAddress("/VMC/Ext/Set/Calib/Exec"))
{
Mode = mode; Mode = mode;
} }
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{new OscArgument(Mode, 'i')}); return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{OscArgument.CreateFromParams(Mode, 'i')!});
} }
} }
} }

View File

@ -16,7 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using godotOscSharp; using godotOscSharp;
namespace godotVmcSharp namespace godotVmcSharp
@ -25,19 +24,13 @@ namespace godotVmcSharp
{ {
public readonly string Path; public readonly string Path;
public VmcExtSetConfig(OscMessage m) : base(m.Address) public static VmcExtSetConfig CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 1) if (m.Data.Count < 1)
{ {
GD.Print($"Invalid number of arguments for {Addr}. Expecting 1, received {m.Data.Count}"); throw new MissingArgumentsException(m.Address, "{1}", m.Data.Count);
return;
} }
if (m.Data[0].Type != 's') return new VmcExtSetConfig(m.Data[0].GetAsString());
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "path", 's', m.Data[0].Type));
return;
}
Path = (string)m.Data[0].Value;
} }
public VmcExtSetConfig(string path) : base(new OscAddress("/VMC/Ext/Set/Config")) public VmcExtSetConfig(string path) : base(new OscAddress("/VMC/Ext/Set/Config"))
@ -47,7 +40,7 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{new OscArgument(Path, 's')}); return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{OscArgument.CreateFromParams(Path, 's')!});
} }
} }
} }

View File

@ -26,35 +26,29 @@ namespace godotVmcSharp
public readonly int Enable; public readonly int Enable;
public readonly Vector3 Position; public readonly Vector3 Position;
public VmcExtSetEye(OscMessage m) : base(m.Address) public static VmcExtSetEye CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 4) if (m.Data.Count < 4)
{ {
GD.Print($"Invalid number of arguments for {Addr}. Expecting 4, received {m.Data.Count}"); throw new MissingArgumentsException(m.Address, "{4}", m.Data.Count);
return;
} }
if (m.Data[0].Type != 'i') if (m.Data[0].Type != 'i')
{ {
GD.Print(InvalidArgumentType.GetErrorString(Addr, "enable", 'i', m.Data[0].Type)); throw new InvalidDataTypeException(m.Address, 0, "enable", 'i', m.Data[0].Type);
return;
} }
if (m.Data[1].Type != 'f') if (m.Data[1].Type != 'f')
{ {
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.x", 'f', m.Data[1].Type)); throw new InvalidDataTypeException(m.Address, 1, "p.x", 'f', m.Data[1].Type);
return;
} }
if (m.Data[2].Type != 'f') if (m.Data[2].Type != 'f')
{ {
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.y", 'f', m.Data[2].Type)); throw new InvalidDataTypeException(m.Address, 2, "p.y", 'f', m.Data[2].Type);
return;
} }
if (m.Data[3].Type != 'f') if (m.Data[3].Type != 'f')
{ {
GD.Print(InvalidArgumentType.GetErrorString(Addr, "p.z", 'f', m.Data[3].Type)); throw new InvalidDataTypeException(m.Address, 3, "p.z", 'f', m.Data[3].Type);
return;
} }
Enable = (int)m.Data[0].Value; return new VmcExtSetEye(m.Data[0].GetAsInt32(), new Vector3(m.Data[1].GetAsFloat(), m.Data[2].GetAsFloat(), m.Data[3].GetAsFloat()));
Position = new Vector3((float)m.Data[1].Value, (float)m.Data[2].Value, (float)m.Data[3].Value);
} }
public VmcExtSetEye(int enable, Vector3 position) : base(new OscAddress("/VMC/Ext/Set/Eye")) public VmcExtSetEye(int enable, Vector3 position) : base(new OscAddress("/VMC/Ext/Set/Eye"))
@ -66,10 +60,10 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{ return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{
new OscArgument(Enable, 'i'), OscArgument.CreateFromParams(Enable, 'i')!,
new OscArgument(Position.X, 'f'), OscArgument.CreateFromParams(Position.X, 'f')!,
new OscArgument(Position.Y, 'f'), OscArgument.CreateFromParams(Position.Y, 'f')!,
new OscArgument(Position.Z, 'f'), OscArgument.CreateFromParams(Position.Z, 'f')!,
}); });
} }
} }

View File

@ -16,7 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using godotOscSharp; using godotOscSharp;
namespace godotVmcSharp namespace godotVmcSharp
@ -30,49 +29,13 @@ namespace godotVmcSharp
public readonly int Camera; public readonly int Camera;
public readonly int Devices; public readonly int Devices;
public VmcExtSetPeriod(OscMessage m) : base(m.Address) public static VmcExtSetPeriod CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 6) if (m.Data.Count < 6)
{ {
GD.Print($"Invalid number of arguments for {Addr}. Expecting 6, received {m.Data.Count}"); throw new MissingArgumentsException(m.Address, "{6}", m.Data.Count);
return;
} }
if (m.Data[0].Type != 'i') return new VmcExtSetPeriod(m.Data[0].GetAsInt32(), m.Data[1].GetAsInt32(), m.Data[2].GetAsInt32(), m.Data[3].GetAsInt32(), m.Data[4].GetAsInt32(), m.Data[5].GetAsInt32());
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "status", 'i', m.Data[0].Type));
return;
}
if (m.Data[1].Type != 'i')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "root", 'i', m.Data[1].Type));
return;
}
if (m.Data[2].Type != 'i')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "bone", 'i', m.Data[2].Type));
return;
}
if (m.Data[3].Type != 'i')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "blendShape", 'i', m.Data[3].Type));
return;
}
if (m.Data[4].Type != 'i')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "camera", 'i', m.Data[4].Type));
return;
}
if (m.Data[5].Type != 'i')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "devices", 'i', m.Data[5].Type));
return;
}
Status = (int)m.Data[0].Value;
Root = (int)m.Data[1].Value;
Bone = (int)m.Data[2].Value;
BlendShape = (int)m.Data[3].Value;
Camera = (int)m.Data[4].Value;
Devices = (int)m.Data[5].Value;
} }
public VmcExtSetPeriod(int status, int root, int bone, int blendShape, int camera, int devices) : base(new OscAddress("/VMC/Ext/Set/Period")) public VmcExtSetPeriod(int status, int root, int bone, int blendShape, int camera, int devices) : base(new OscAddress("/VMC/Ext/Set/Period"))
@ -88,12 +51,12 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{ return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{
new OscArgument(Status, 'i'), OscArgument.CreateFromParams(Status, 'i')!,
new OscArgument(Root, 'i'), OscArgument.CreateFromParams(Root, 'i')!,
new OscArgument(Bone, 'i'), OscArgument.CreateFromParams(Bone, 'i')!,
new OscArgument(BlendShape, 'i'), OscArgument.CreateFromParams(BlendShape, 'i')!,
new OscArgument(Camera, 'i'), OscArgument.CreateFromParams(Camera, 'i')!,
new OscArgument(Devices, 'i'), OscArgument.CreateFromParams(Devices, 'i')!,
}); });
} }
} }

View File

@ -16,7 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using godotOscSharp; using godotOscSharp;
@ -26,19 +25,13 @@ namespace godotVmcSharp
{ {
public readonly string Response; public readonly string Response;
public VmcExtSetRes(OscMessage m) : base(m.Address) public static VmcExtSetRes CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 1) if (m.Data.Count < 1)
{ {
GD.Print($"Invalid number of arguments for {Addr}. Expecting 1, received {m.Data.Count}"); throw new MissingArgumentsException(m.Address, "{1}", m.Data.Count);
return;
} }
if (m.Data[0].Type != 's') return new VmcExtSetRes(m.Data[0].GetAsString());
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "response", 's', m.Data[0].Type));
return;
}
Response = (string)m.Data[0].Value;
} }
public VmcExtSetRes(string response) : base(new OscAddress("/VMC/Ext/Set/Res")) public VmcExtSetRes(string response) : base(new OscAddress("/VMC/Ext/Set/Res"))
@ -48,7 +41,7 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{new OscArgument(Response, 's')}); return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{OscArgument.CreateFromParams(Response, 's')!});
} }
} }
} }

View File

@ -16,7 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using godotOscSharp; using godotOscSharp;
namespace godotVmcSharp namespace godotVmcSharp
@ -25,19 +24,13 @@ namespace godotVmcSharp
{ {
public readonly string Shortcut; public readonly string Shortcut;
public VmcExtSetShortcut(OscMessage m) : base(m.Address) public static VmcExtSetShortcut CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 1) if (m.Data.Count < 1)
{ {
GD.Print($"Invalid number of arguments for {Addr}. Expecting 1, received {m.Data.Count}"); throw new MissingArgumentsException(m.Address, "{1}", m.Data.Count);
return;
} }
if (m.Data[0].Type != 's') return new VmcExtSetShortcut(m.Data[0].GetAsString());
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "shortcut", 's', m.Data[0].Type));
return;
}
Shortcut = (string)m.Data[0].Value;
} }
public VmcExtSetShortcut(string shortcut) : base(new OscAddress("/VMC/Ext/Set/Shortcut")) public VmcExtSetShortcut(string shortcut) : base(new OscAddress("/VMC/Ext/Set/Shortcut"))
@ -47,7 +40,7 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{new OscArgument(Shortcut, 's')}); return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{OscArgument.CreateFromParams(Shortcut, 's')!});
} }
} }
} }

View File

@ -25,34 +25,13 @@ namespace godotVmcSharp
{ {
public readonly Color Color; public readonly Color Color;
public VmcExtSettingColor(OscMessage m) : base(m.Address) public static VmcExtSettingColor CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 4) if (m.Data.Count < 4)
{ {
GD.Print($"Invalid number of arguments for {Addr}. Expecting 4, received {m.Data.Count}"); throw new MissingArgumentsException(m.Address, "{4}", m.Data.Count);
return;
} }
if (m.Data[0].Type != 'f') return new VmcExtSettingColor(new Godot.Color(m.Data[0].GetAsFloat(), m.Data[1].GetAsFloat(), m.Data[2].GetAsFloat(), m.Data[3].GetAsFloat()));
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "r", 'f', m.Data[0].Type));
return;
}
if (m.Data[1].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "g", 'f', m.Data[1].Type));
return;
}
if (m.Data[2].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "b", 'f', m.Data[2].Type));
return;
}
if (m.Data[3].Type != 'f')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "a", 'f', m.Data[3].Type));
return;
}
Color = new Godot.Color((float)m.Data[0].Value, (float)m.Data[1].Value, (float)m.Data[2].Value, (float)m.Data[3].Value);
} }
public VmcExtSettingColor(Color color) : base(new OscAddress("/VMC/Ext/Setting/Color")) public VmcExtSettingColor(Color color) : base(new OscAddress("/VMC/Ext/Setting/Color"))
@ -63,10 +42,10 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{ return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{
new OscArgument(Color.R, 'f'), OscArgument.CreateFromParams(Color.R, 'f')!,
new OscArgument(Color.G, 'f'), OscArgument.CreateFromParams(Color.G, 'f')!,
new OscArgument(Color.B, 'f'), OscArgument.CreateFromParams(Color.B, 'f')!,
new OscArgument(Color.A, 'f') OscArgument.CreateFromParams(Color.A, 'f')!
}); });
} }
} }

View File

@ -16,7 +16,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using godotOscSharp; using godotOscSharp;
namespace godotVmcSharp namespace godotVmcSharp
@ -28,81 +27,58 @@ namespace godotVmcSharp
public readonly int WindowClickThrough; public readonly int WindowClickThrough;
public readonly int HideBorder; public readonly int HideBorder;
public VmcExtSettingWin(OscMessage m) : base(m.Address) public static VmcExtSettingWin CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 4) if (m.Data.Count < 4)
{ {
GD.Print($"Invalid number of arguments for {Addr}. Expecting 4, received {m.Data.Count}"); throw new MissingArgumentsException(m.Address, "4", m.Data.Count);
return;
} }
if (m.Data[0].Type != 'i') var isTopMost = m.Data[0].GetAsInt32();
{ var isTransparent = m.Data[1].GetAsInt32();
GD.Print(InvalidArgumentType.GetErrorString(Addr, "isTopMost", 'i', m.Data[0].Type)); var windowClickThrough = m.Data[2].GetAsInt32();
return; var hideBorder = m.Data[3].GetAsInt32();
}
if (m.Data[1].Type != 'i')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "isTransparent", 'i', m.Data[1].Type));
return;
}
if (m.Data[2].Type != 'i')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "windowClickThrough", 'i', m.Data[2].Type));
return;
}
if (m.Data[3].Type != 'i')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "hideBorder", 'i', m.Data[3].Type));
return;
}
if ((int)m.Data[0].Value < 0 || (int)m.Data[0].Value > 1)
{
GD.Print($"Invalid value for \"isTopMost\" 'i' argument of {Addr}. Expected 0 or 1, received {(int)m.Data[0].Value}");
return;
}
if ((int)m.Data[1].Value < 0 || (int)m.Data[1].Value > 1)
{
GD.Print($"Invalid value for \"isTransparent\" 'i' argument of {Addr}. Expected 0 or 1, received {(int)m.Data[1].Value}");
return;
}
if ((int)m.Data[2].Value < 0 || (int)m.Data[2].Value > 1)
{
GD.Print($"Invalid value for \"windowClickThrough\" 'i' argument of {Addr}. Expected 0 or 1, received {(int)m.Data[2].Value}");
return;
}
if ((int)m.Data[3].Value < 0 || (int)m.Data[3].Value > 1)
{
GD.Print($"Invalid value for \"hideBorder\" 'i' argument of {Addr}. Expected 0 or 1, received {(int)m.Data[3].Value}");
return;
}
IsTopMost = (int)m.Data[0].Value;
IsTransparent = (int)m.Data[1].Value;
WindowClickThrough = (int)m.Data[2].Value;
HideBorder = (int)m.Data[3].Value;
}
public VmcExtSettingWin(int isTopMost, int isTransparent, int windowClickThrough, int hideBorder) : base(new OscAddress("/VMC/Ext/Setting/Win"))
{
if (isTopMost < 0 || isTopMost > 1) if (isTopMost < 0 || isTopMost > 1)
{ {
GD.Print($"Invalid value for \"isTopMost\" 'i' argument of {Addr}. Expected 0 or 1, received {isTopMost}"); throw new DataOutOfRangeException(m.Address, 0, "isTopMost", "{0, 1}", isTopMost);
return;
} }
if (isTransparent < 0 || isTransparent > 1) if (isTransparent < 0 || isTransparent > 1)
{ {
GD.Print($"Invalid value for \"isTransparent\" 'i' argument of {Addr}. Expected 0 or 1, received {isTransparent}"); throw new DataOutOfRangeException(m.Address, 1, "isTransparent", "{0, 1}", isTransparent);
return;
} }
if (windowClickThrough < 0 || windowClickThrough > 1) if (windowClickThrough < 0 || windowClickThrough > 1)
{ {
GD.Print($"Invalid value for \"windowClickThrough\" 'i' argument of {Addr}. Expected 0 or 1, received {windowClickThrough}"); throw new DataOutOfRangeException(m.Address, 2, "windowClickThrough", "{0, 1}", windowClickThrough);
return;
} }
if (hideBorder < 0 || hideBorder > 1) if (hideBorder < 0 || hideBorder > 1)
{ {
GD.Print($"Invalid value for \"hideBorder\" 'i' argument of {Addr}. Expected 0 or 1, received {hideBorder}"); throw new DataOutOfRangeException(m.Address, 3, "hideBorder", "{0, 1}", hideBorder);
return;
} }
return new VmcExtSettingWin(isTopMost, isTransparent, windowClickThrough, hideBorder);
}
public static VmcExtSettingWin CreateFromParams(int isTopMost, int isTransparent, int windowClickThrough, int hideBorder)
{
if (isTopMost < 0 || isTopMost > 1)
{
throw new DataOutOfRangeException("/VMC/Ext/Setting/Win", 0, "isTopMost", "{0, 1}", isTopMost);
}
if (isTransparent < 0 || isTransparent > 1)
{
throw new DataOutOfRangeException("/VMC/Ext/Setting/Win", 1, "isTransparent", "{0, 1}", isTransparent);
}
if (windowClickThrough < 0 || windowClickThrough > 1)
{
throw new DataOutOfRangeException("/VMC/Ext/Setting/Win", 2, "windowClickThrough", "{0, 1}", windowClickThrough);
}
if (hideBorder < 0 || hideBorder > 1)
{
throw new DataOutOfRangeException("/VMC/Ext/Setting/Win", 3, "hideBorder", "{0, 1}", hideBorder);
}
return new VmcExtSettingWin(isTopMost, isTransparent, windowClickThrough, hideBorder);
}
private VmcExtSettingWin(int isTopMost, int isTransparent, int windowClickThrough, int hideBorder) : base(new OscAddress("/VMC/Ext/Setting/Win"))
{
IsTopMost = isTopMost; IsTopMost = isTopMost;
IsTransparent = isTransparent; IsTransparent = isTransparent;
WindowClickThrough = windowClickThrough; WindowClickThrough = windowClickThrough;
@ -112,10 +88,10 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{ return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{
new OscArgument(IsTopMost, 'i'), OscArgument.CreateFromParams(IsTopMost, 'i')!,
new OscArgument(IsTransparent, 'i'), OscArgument.CreateFromParams(IsTransparent, 'i')!,
new OscArgument(WindowClickThrough, 'i'), OscArgument.CreateFromParams(WindowClickThrough, 'i')!,
new OscArgument(HideBorder, 'i') OscArgument.CreateFromParams(HideBorder, 'i')!
}); });
} }
} }

View File

@ -17,26 +17,19 @@
*/ */
using godotOscSharp; using godotOscSharp;
using Godot;
namespace godotVmcSharp namespace godotVmcSharp
{ {
public class VmcExtT : VmcMessage public class VmcExtT : VmcMessage
{ {
public readonly float Time; public readonly float Time;
public VmcExtT(OscMessage m) : base(m.Address) public static VmcExtT CreateFromMessage(OscMessage m)
{ {
if (m.Data.Count != 1) if (m.Data.Count < 1)
{ {
GD.Print($"Invalid number of arguments for /VMC/Ext/T message. Expected 1 but received {m.Data.Count}"); throw new MissingArgumentsException(m.Address, "1", m.Data.Count);
return;
} }
if (m.Data[0].Type != 'f') return new VmcExtT(m.Data[0].GetAsFloat());
{
InvalidArgumentType.GetErrorString(m.Address.ToString(), "time", 'f', m.Data[0].Type);
return;
}
Time = (float)m.Data[0].Value;
} }
public VmcExtT(float time) : base(new OscAddress("/VMC/Ext/T")) public VmcExtT(float time) : base(new OscAddress("/VMC/Ext/T"))
@ -47,7 +40,7 @@ namespace godotVmcSharp
public new OscMessage ToMessage() public new OscMessage ToMessage()
{ {
return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{ return new OscMessage(Addr, new System.Collections.Generic.List<OscArgument>{
new OscArgument(Time, 'f') OscArgument.CreateFromParams(Time, 'f')!
}); });
} }
} }

View File

@ -16,60 +16,30 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using godotOscSharp; using godotOscSharp;
using System.Collections.Generic; using System.Collections.Generic;
#nullable enable
namespace godotVmcSharp namespace godotVmcSharp
{ {
public class VmcExtVrm : VmcMessage public class VmcExtVrm : VmcMessage
{ {
public readonly string Path; public readonly string Path;
public readonly string Title; public readonly string Title;
public readonly string Hash; public readonly string? Hash;
public VmcExtVrm(OscMessage m) : base(m.Address) public static VmcExtVrm? CreateFromMessage(OscMessage m)
{ {
switch (m.Data.Count) switch (m.Data.Count)
{ {
case 2: case 2:
if (m.Data[0].Type != 's') return new VmcExtVrm(m.Data[0].GetAsString(), m.Data[1].GetAsString());
{ case 1:
GD.Print(InvalidArgumentType.GetErrorString(Addr, "path", 's', m.Data[0].Type)); case 0:
return; throw new MissingArgumentsException(m.Address, "2 <= count <= 3", m.Data.Count);
}
if (m.Data[1].Type != 's')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "title", 's', m.Data[1].Type));
return;
}
Path = (string)m.Data[0].Value;
Title = (string)m.Data[1].Value;
Hash = "";
break;
case 3:
if (m.Data[0].Type != 's')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "path", 's', m.Data[0].Type));
return;
}
if (m.Data[1].Type != 's')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "title", 's', m.Data[1].Type));
return;
}
if (m.Data[2].Type != 's')
{
GD.Print(InvalidArgumentType.GetErrorString(Addr, "hash", 's', m.Data[1].Type));
return;
}
Path = (string)m.Data[0].Value;
Title = (string)m.Data[1].Value;
Hash = (string)m.Data[2].Value;
break;
default: default:
GD.Print($"Invalid number of arguments for {Addr} message. Expected 2 or 3 but received {m.Data.Count}"); return new VmcExtVrm(m.Data[0].GetAsString(), m.Data[1].GetAsString(), m.Data[2].GetAsString());
return;
} }
} }
@ -77,7 +47,6 @@ namespace godotVmcSharp
{ {
Path = path; Path = path;
Title = title; Title = title;
Hash = "";
} }
public VmcExtVrm(string path, string title, string hash) : base(new OscAddress("/VMC/Ext/VRM")) public VmcExtVrm(string path, string title, string hash) : base(new OscAddress("/VMC/Ext/VRM"))
@ -92,14 +61,14 @@ namespace godotVmcSharp
if (Hash == null) if (Hash == null)
{ {
return new OscMessage(Addr, new List<OscArgument>{ return new OscMessage(Addr, new List<OscArgument>{
new OscArgument(Path, 's'), OscArgument.CreateFromParams(Path, 's')!,
new OscArgument(Title, 's') OscArgument.CreateFromParams(Title, 's')!
}); });
} }
return new OscMessage(Addr, new List<OscArgument>{ return new OscMessage(Addr, new List<OscArgument>{
new OscArgument(Path, 's'), OscArgument.CreateFromParams(Path, 's')!,
new OscArgument(Title, 's'), OscArgument.CreateFromParams(Title, 's')!,
new OscArgument(Hash, 's') OscArgument.CreateFromParams(Hash, 's')!
}); });
} }
} }