Lumiverse  2.5
A framework for creating lighting control applications
OscPatch.h
Go to the documentation of this file.
1 
5 #pragma once
6 
7 #include "LumiverseCoreConfig.h"
8 
9 #ifdef USE_OSC
10 
11 #include "Patch.h"
12 #include "lib/oscpack/osc/OscOutboundPacketStream.h"
13 #include "lib/oscpack/osc/OscPacketListener.h"
14 #include "lib/oscpack/osc/OscReceivedElements.h"
15 #include "lib/oscpack/ip/UdpSocket.h"
16 
17 namespace Lumiverse {
18 
19 enum OscFormat {
20  PREFIXED_ADDR = 0,
21  PER_DEVICE_ADDR = 1,
22  ETC_EOS = 2
23 };
24 
25 class OscPatch : public Patch, public osc::OscPacketListener {
26 
27 public:
28  OscPatch(string address, int port, OscFormat mode = PREFIXED_ADDR, string pattern = "lumiverse");
29  OscPatch(JSONNode data);
30  ~OscPatch();
31 
32  virtual void init() override;
33 
34  virtual void update(set<Device *> devices) override;
35 
36  virtual void close() override;
37 
38  virtual JSONNode toJSON() override;
39 
40  virtual void deleteDevice(string id) override;
41 
42  virtual string getType() { return "osc"; }
43 
44  void changeAddress(string address, int port);
45  void changeInPort(int port);
46  string getAddress();
47  int getPort();
48  int getInPort();
49  bool isRunning();
50 
57  bool sync(const set<Device *> devices);
58 
62  set<int> getEosSelection();
63 
70  OscFormat _mode;
71 
73  string _pattern;
74 
75 protected:
76  virtual void ProcessMessage(const osc::ReceivedMessage& m, const IpEndpointName& remote);
77 
78 private:
79  string _address;
80  int _port;
81  int _inPort;
82  bool _running;
83 
84  UdpTransmitSocket* _t;
85 
89  void deviceToOsc(osc::OutboundPacketStream& p, Device* d);
90 
97  void deviceToEos(Device* d);
98 
102  void newEosCmd();
103 
107  void loadJSON(JSONNode data);
108 
112  void processSelection(string chans);
113 
114  Device* _syncDevice;
115  bool _syncReady;
116  set<string> _syncParams;
117  set<int> _syncChan;
118 };
119 
120 }
121 
122 #endif
Definition: OscPatch.h:25
virtual JSONNode toJSON() override
Returns a JSON node representing the patch.
Definition: OscPatch.cpp:71
OscFormat _mode
Determines how the OSC messages are sent Under PREFIXED_ADDR the OSC packet will be arranged as follo...
Definition: OscPatch.h:70
void newEosCmd()
Resets the Eos command line.
Definition: OscPatch.cpp:462
virtual void update(set< Device * > devices) override
Grabs values from list of Devices, translates them to proper format for the given network...
Definition: OscPatch.cpp:40
set< int > getEosSelection()
Returns the selected device channels from Eos.
Definition: OscPatch.cpp:230
A Patch maps devices to output channels and handles the output of data to the network.
Definition: Patch.h:24
void deviceToEos(Device *d)
Outputs a series of ETC Eos commands to update the state.
Definition: OscPatch.cpp:405
bool sync(const set< Device * > devices)
Only active in ETC_EOS mode. Synchronizes device values with what's in EOS.
Definition: OscPatch.cpp:128
virtual void deleteDevice(string id) override
Called when a device is deleted from the Rig.
Definition: OscPatch.cpp:85
virtual string getType()
Gets the type of the patch as a string.
Definition: OscPatch.h:42
void deviceToOsc(osc::OutboundPacketStream &p, Device *d)
Converts a device to OSC and places the conversion in the outbound packet stream. ...
Definition: OscPatch.cpp:358
virtual void close() override
Prepares for patch shutdown.
Definition: OscPatch.cpp:60
Contains all core Lumiverse functions and variables.
Definition: Device.cpp:2
void loadJSON(JSONNode data)
Loads a patch from JSON data.
Definition: OscPatch.cpp:470
virtual void init() override
Initializes settings for the patch.
Definition: OscPatch.cpp:23
void processSelection(string chans)
Processes an Eos selection string.
Definition: OscPatch.cpp:503
A Device in Lumiverse maintains information about a lighting device.
Definition: Device.h:55
string _pattern
In fixed mode, the pattern to which messages are sent.
Definition: OscPatch.h:73
The Patch translates Lumiverse Data to Network Data.