l@270: /***** OSCClient.cpp *****/ l@270: #include l@270: l@270: OSCClient::OSCClient(){} l@270: l@270: void OSCClient::sendQueue(void* ptr){ l@270: OSCClient *instance = (OSCClient*)ptr; l@270: instance->queueSend(); l@270: } l@270: l@270: void OSCClient::setup(int _port, const char* _address, bool scheduleTask){ l@270: address = _address; l@270: port = _port; l@270: l@270: socket.setServer(address); l@270: socket.setPort(port); l@270: l@270: if (scheduleTask) l@270: createAuxTasks(); l@270: } l@270: l@270: void OSCClient::createAuxTasks(){ l@270: char name [30]; l@270: sprintf (name, "OSCSendTask %i", port); andrewm@303: OSCSendTask = Bela_createAuxiliaryTask(sendQueue, BELA_AUDIO_PRIORITY-5, name, this, true); l@270: } l@270: l@270: void OSCClient::queueMessage(oscpkt::Message msg){ l@270: outQueue.push(msg); l@270: } l@270: l@270: void OSCClient::queueSend(){ l@270: if (!outQueue.empty()){ l@270: pw.init().startBundle(); l@270: while(!outQueue.empty()){ l@270: pw.addMessage(outQueue.front()); l@270: outQueue.pop(); l@270: } l@270: pw.endBundle(); l@270: outBuffer = pw.packetData(); l@270: socket.send(outBuffer, pw.packetSize()); l@270: } l@270: } l@270: l@270: void OSCClient::sendMessageNow(oscpkt::Message msg){ l@270: pw.init().addMessage(msg); l@270: outBuffer = pw.packetData(); l@270: socket.send(outBuffer, pw.packetSize()); l@270: } l@270: l@270: // OSCMessageFactory l@270: OSCMessageFactory& OSCMessageFactory::to(std::string addr){ l@270: msg.init(addr); l@270: return *this; l@270: } l@270: l@270: OSCMessageFactory& OSCMessageFactory::add(std::string in){ l@270: msg.pushStr(in); l@270: return *this; l@270: } l@270: OSCMessageFactory& OSCMessageFactory::add(int in){ l@270: msg.pushInt32(in); l@270: return *this; l@270: } l@270: OSCMessageFactory& OSCMessageFactory::add(float in){ l@270: msg.pushFloat(in); l@270: return *this; l@270: } l@270: OSCMessageFactory& OSCMessageFactory::add(bool in){ l@270: msg.pushBool(in); l@270: return *this; l@270: } l@270: OSCMessageFactory& OSCMessageFactory::add(void *ptr, int size){ l@270: msg.pushBlob(ptr, size); l@270: return *this; l@270: } l@270: oscpkt::Message OSCMessageFactory::end(){ l@270: return msg; giuliomoro@301: }