godotVmcSharp/Performer.cs

103 lines
3.8 KiB
C#
Raw Permalink Normal View History

2023-08-16 19:47:14 +02:00
/*
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/>.
*/
using System.Net;
using Godot;
using godotOscSharp;
namespace godotVmcSharp
{
public class Performer
{
private OscReceiver receiver;
private OscSender sender;
private CameraReceiver cam;
private DeviceReceiver devices;
private DirectionalLightReceiver lights;
private Node3D node;
public Performer(IPAddress host, int port, Node3D node)
2023-08-16 19:47:14 +02:00
{
this.node = node;
receiver = new OscReceiver(port);
sender = new OscSender(host, port);
2023-08-16 19:47:14 +02:00
receiver.MessageReceived += (sender, e) =>
{
GD.Print($"Received a message from {e.IPAddress}:{e.Port}");
ProcessMessage(e.Message);
};
receiver.ErrorReceived += (sender, e) =>
{
GD.Print($"Error: {e.ErrorMessage}");
};
devices = new DeviceReceiver();
lights = new DirectionalLightReceiver();
cam = new CameraReceiver(node.GetViewport().GetCamera3D());
2023-08-16 19:47:14 +02:00
}
private void ProcessMessage(OscMessage m)
2023-08-16 19:47:14 +02:00
{
switch (m.Address.ToString())
{
case "/VMC/Ext/Hmd/Pos":
case "/VMC/Ext/Con/Pos":
case "/VMC/Ext/Tra/Pos":
this.devices.ProcessMessage(VmcExtDevicePos.CreateFromMessage(m));
break;
case "/VMC/Ext/Set/Period":
VmcExtSetPeriod.CreateFromMessage(m);
break;
case "/VMC/Ext/Midi/CC/Val":
VmcExtMidiCcVal.CreateFromMessage(m);
break;
case "/VMC/Ext/Cam":
this.cam.ProcessMessage(VmcExtCam.CreateFromMessage(m));
break;
2023-08-16 19:47:14 +02:00
case "/VMC/Ext/Blend/Val":
VmcExtBlendVal.CreateFromMessage(m);
2023-08-16 19:47:14 +02:00
break;
case "/VMC/Ext/Blend/Apply":
new VmcMessage(m.Address);
break;
2023-08-17 00:43:51 +02:00
case "/VMC/Ext/Set/Eye":
VmcExtSetEye.CreateFromMessage(m);
2023-08-17 00:43:51 +02:00
break;
case "/VMC/Ext/Set/Req":
new VmcMessage(m.Address);
break;
case "/VMC/Ext/Set/Res":
VmcExtSetRes.CreateFromMessage(m);
break;
case "/VMC/Ext/Set/Calib/Ready":
new VmcMessage(m.Address);
break;
case "/VMC/Ext/Set/Calib/Exec":
VmcExtSetCalibExec.CreateFromMessage(m);
break;
case "/VMC/Ext/Set/Config":
VmcExtSetConfig.CreateFromMessage(m);
break;
2023-08-16 20:35:37 +02:00
case "/VMC/Ext/Light":
this.lights.ProcessMessage(VmcExtLight.CreateFromMessage(m));
2023-08-16 20:35:37 +02:00
break;
case "/VMC/Ext/Set/Shortcut":
VmcExtSetShortcut.CreateFromMessage(m);
break;
2023-08-16 19:47:14 +02:00
}
}
}
}