comparison Source/TouchKeys/Osc.h @ 49:90ce403d0dc5

Added OSC control over all main application functions. OSC messages can be sent to do most of the tasks available from the GUI.
author Andrew McPherson <andrewm@eecs.qmul.ac.uk>
date Mon, 13 Apr 2015 19:30:27 -0700
parents 48e3f67b5fe0
children
comparison
equal deleted inserted replaced
48:2a9e5576905e 49:90ce403d0dc5
169 169
170 // State variables 170 // State variables
171 string globalPrefix_; // Prefix for all OSC paths 171 string globalPrefix_; // Prefix for all OSC paths
172 }; 172 };
173 173
174 // Simple class to hold a message alongw ith a path and a type
175 class OscMessage
176 {
177 public:
178 OscMessage(const char *path, const char *type, lo_message& message)
179 : path_(path), type_(type), message_(message) {}
180
181 ~OscMessage() {
182 lo_message_free(message_);
183 }
184
185 const char *path() { return path_.c_str(); }
186 const char *type() { return type_.c_str(); }
187 lo_message message() { return message_; }
188
189 // Add a prefix to the message path
190 void prependPath(const char *prefix) {
191 path_.insert(0, prefix); // TODO: check that this is right
192 }
193
194 private:
195 std::string path_;
196 std::string type_;
197 lo_message message_;
198 };
199
200
174 class OscTransmitter 201 class OscTransmitter
175 { 202 {
176 public: 203 public:
177 OscTransmitter() : enabled_(true), debugMessages_(false) {} 204 OscTransmitter() : enabled_(true), debugMessages_(false) {}
178 205
191 void sendByteArray(const char * path, const unsigned char * data, int length); 218 void sendByteArray(const char * path, const unsigned char * data, int length);
192 219
193 void setDebugMessages(bool debug) { debugMessages_ = debug; } 220 void setDebugMessages(bool debug) { debugMessages_ = debug; }
194 221
195 ~OscTransmitter(); 222 ~OscTransmitter();
223
224 // Static methods
225 static OscMessage* createMessage(const char * path, const char * type, ...);
226 static OscMessage* createSuccessMessage() { return createMessage("/result", "i", 0, LO_ARGS_END); }
227 static OscMessage* createFailureMessage() { return createMessage("/result", "i", 1, LO_ARGS_END); }
196 228
197 private: 229 private:
198 vector<lo_address> addresses_; 230 vector<lo_address> addresses_;
199 bool enabled_; 231 bool enabled_;
200 bool debugMessages_; 232 bool debugMessages_;