11 #ifndef hifi_OscPlugin_h
12 #define hifi_OscPlugin_h
14 #include <controllers/InputDevice.h>
15 #include <controllers/StandardControls.h>
16 #include <plugins/InputPlugin.h>
21 class OscPlugin :
public InputPlugin {
26 virtual void init()
override;
27 virtual bool isSupported()
const override;
28 virtual const QString getName()
const override {
return NAME; }
29 const QString getID()
const override {
return OSC_ID_STRING; }
31 virtual bool activate()
override;
32 virtual void deactivate()
override;
34 virtual void pluginFocusOutEvent()
override { _inputDevice->focusOutEvent(); }
35 virtual void pluginUpdate(
float deltaTime,
const controller::InputCalibrationData& inputCalibrationData)
override;
37 virtual void saveSettings()
const override;
38 virtual void loadSettings()
override;
46 class InputDevice :
public controller::InputDevice {
48 friend class OscPlugin;
50 InputDevice() : controller::InputDevice(
"OSC") {}
53 virtual controller::Input::NamedVector getAvailableInputs()
const override;
54 virtual QString getDefaultMappingConfig()
const override;
55 virtual void update(
float deltaTime,
const controller::InputCalibrationData& inputCalibrationData)
override;
56 virtual void focusOutEvent()
override {};
59 void setContainer(OscPlugin* container) { _container = container; }
61 OscPlugin* _container {
nullptr };
64 std::shared_ptr<InputDevice> _inputDevice;
66 static const char* NAME;
67 static const char* OSC_ID_STRING;
69 bool _enabled {
false };
70 mutable bool _initialized {
false };
72 lo_server_thread _oscServerThread {
nullptr };
75 bool _debug {
false };
76 enum Constants { DEFAULT_OSC_SERVER_PORT = 7700 };
77 int _serverPort { DEFAULT_OSC_SERVER_PORT };
78 controller::InputCalibrationData _lastInputCalibrationData;
80 std::vector<float> _blendshapeValues;
81 std::vector<bool> _blendshapeValidFlags;
83 bool _headRotValid {
false };
84 glm::vec3 _headTransTarget;
85 glm::vec3 _headTransSmoothed;
86 bool _headTransValid {
false };
87 glm::quat _eyeLeftRot;
88 bool _eyeLeftRotValid {
false };
89 glm::quat _eyeRightRot;
90 bool _eyeRightRotValid {
false };
91 std::mutex _dataMutex;