l@270
|
1 /***** OSCClient.cpp *****/
|
l@270
|
2 #include <OSCClient.h>
|
l@270
|
3
|
l@270
|
4 OSCClient::OSCClient(){}
|
l@270
|
5
|
l@270
|
6 void OSCClient::sendQueue(void* ptr){
|
l@270
|
7 OSCClient *instance = (OSCClient*)ptr;
|
l@270
|
8 instance->queueSend();
|
l@270
|
9 }
|
l@270
|
10
|
l@270
|
11 void OSCClient::setup(int _port, const char* _address, bool scheduleTask){
|
l@270
|
12 address = _address;
|
l@270
|
13 port = _port;
|
l@270
|
14
|
l@270
|
15 socket.setServer(address);
|
l@270
|
16 socket.setPort(port);
|
l@270
|
17
|
l@270
|
18 if (scheduleTask)
|
l@270
|
19 createAuxTasks();
|
l@270
|
20 }
|
l@270
|
21
|
l@270
|
22 void OSCClient::createAuxTasks(){
|
l@270
|
23 char name [30];
|
l@270
|
24 sprintf (name, "OSCSendTask %i", port);
|
andrewm@303
|
25 OSCSendTask = Bela_createAuxiliaryTask(sendQueue, BELA_AUDIO_PRIORITY-5, name, this, true);
|
l@270
|
26 }
|
l@270
|
27
|
l@270
|
28 void OSCClient::queueMessage(oscpkt::Message msg){
|
l@270
|
29 outQueue.push(msg);
|
l@270
|
30 }
|
l@270
|
31
|
l@270
|
32 void OSCClient::queueSend(){
|
l@270
|
33 if (!outQueue.empty()){
|
l@270
|
34 pw.init().startBundle();
|
l@270
|
35 while(!outQueue.empty()){
|
l@270
|
36 pw.addMessage(outQueue.front());
|
l@270
|
37 outQueue.pop();
|
l@270
|
38 }
|
l@270
|
39 pw.endBundle();
|
l@270
|
40 outBuffer = pw.packetData();
|
l@270
|
41 socket.send(outBuffer, pw.packetSize());
|
l@270
|
42 }
|
l@270
|
43 }
|
l@270
|
44
|
l@270
|
45 void OSCClient::sendMessageNow(oscpkt::Message msg){
|
l@270
|
46 pw.init().addMessage(msg);
|
l@270
|
47 outBuffer = pw.packetData();
|
l@270
|
48 socket.send(outBuffer, pw.packetSize());
|
l@270
|
49 }
|
l@270
|
50
|
l@270
|
51 // OSCMessageFactory
|
l@270
|
52 OSCMessageFactory& OSCMessageFactory::to(std::string addr){
|
l@270
|
53 msg.init(addr);
|
l@270
|
54 return *this;
|
l@270
|
55 }
|
l@270
|
56
|
l@270
|
57 OSCMessageFactory& OSCMessageFactory::add(std::string in){
|
l@270
|
58 msg.pushStr(in);
|
l@270
|
59 return *this;
|
l@270
|
60 }
|
l@270
|
61 OSCMessageFactory& OSCMessageFactory::add(int in){
|
l@270
|
62 msg.pushInt32(in);
|
l@270
|
63 return *this;
|
l@270
|
64 }
|
l@270
|
65 OSCMessageFactory& OSCMessageFactory::add(float in){
|
l@270
|
66 msg.pushFloat(in);
|
l@270
|
67 return *this;
|
l@270
|
68 }
|
l@270
|
69 OSCMessageFactory& OSCMessageFactory::add(bool in){
|
l@270
|
70 msg.pushBool(in);
|
l@270
|
71 return *this;
|
l@270
|
72 }
|
l@270
|
73 OSCMessageFactory& OSCMessageFactory::add(void *ptr, int size){
|
l@270
|
74 msg.pushBlob(ptr, size);
|
l@270
|
75 return *this;
|
l@270
|
76 }
|
l@270
|
77 oscpkt::Message OSCMessageFactory::end(){
|
l@270
|
78 return msg;
|
giuliomoro@301
|
79 }
|