static int osc_message_handler(const char *path, const char *types, lo_arg **argv, int argc, lo_message, void *user_data) { AudioPluginOSCGUIManager *manager = (AudioPluginOSCGUIManager *)user_data; InstrumentId instrument; int position; QString method; if (!manager->parseOSCPath(path, instrument, position, method)) { return 1; } OSCMessage *message = new OSCMessage(); message->setTarget(instrument); message->setTargetData(position); message->setMethod(qstrtostr(method)); int arg = 0; while (types && arg < argc && types[arg]) { message->addArg(types[arg], argv[arg]); ++arg; } manager->postMessage(message); return 0; }
int OSCServer::aviableCheck(void) { if( udpserver.available() == 0 ) { return -1; } OSCMessage rcvMes; //get max receive data udpserver.read(_rcvData, kMaxRecieveData); //get client ip udpserver.getip(rcvMes._ip); //get client port rcvMes.setPortNumber(udpserver.getport()); //clear input buffer udpserver.flush(); //decode message if( _decoder.decode(&rcvMes, _rcvData) < 0 ) { return -1; } _adrMatch.paternComp(&rcvMes); return 1; }
void OSCQueue::postMessage(OSCMessage message) { int count = 0, max = 5; while (m_buffer.getWriteSpace() == 0) { if (count == max) { std::cerr << "ERROR: OSCQueue::postMessage: OSC message queue is full and not clearing -- abandoning incoming message" << std::endl; return; } std::cerr << "WARNING: OSCQueue::postMessage: OSC message queue (capacity " << m_buffer.getSize() << " is full!" << std::endl; std::cerr << "Waiting for something to be processed" << std::endl; #ifdef _WIN32 Sleep(1); #else sleep(1); #endif count++; } OSCMessage *mp = new OSCMessage(message); m_buffer.write(&mp, 1); std::cerr << "OSCQueue::postMessage: Posted OSC message: target " << message.getTarget() << ", target data " << message.getTargetData() << ", method " << message.getMethod().toStdString() << std::endl; emit messagesAvailable(); }
void SmSnDevice::handleOSCBundleInternal(class OSCBundle &bundle) { if (bundle.hasError()) { errorCue(); playTone(400,100); osc.sendOSCBundleError(bundle); } else if (!(handleOSCBundle(bundle) // TODO: copying addresses into buffers on the fly (via address()), one by one, is inefficient || bundle.dispatch(address(OSC_ERROR), handleErrorMessage) || bundle.dispatch(address(OSC_INFO), handleInfoMessage) //|| bundle.dispatch(address(OSC_MORSE), handleMorseMessage) || bundle.dispatch(address(OSC_OK), handleOkMessage) || bundle.dispatch(address(OSC_PING), handlePingMessage) || bundle.dispatch(address(OSC_READY), handleReadyMessage) #ifdef BOUNTIFUL_RAM || bundle.dispatch(address(OSC_CONTEXT_SET), handleContextSetMessage) || bundle.dispatch(address(OSC_PING_REPLY), handlePingReplyMessage) || bundle.dispatch(address(OSC_RGB_SET), handleRGBSetMessage) || bundle.dispatch(address(OSC_TONE), handleToneMessage) || bundle.dispatch(address(OSC_VIBRO), handleVibroMessage) #endif // BOUNTIFUL_RAM || bundle.dispatch(address(OSC_WARNING), handleWarningMessage) )) { if (!bundle.size()) { osc.sendError(ERR_EMPTY_OSC_BUNDLE); } else { for (int i = 0; i < bundle.size(); i++) { OSCMessage *m = bundle.getOSCMessage(i); char address[64]; m->getAddress(address); osc.sendError(ERR_NO_HANDLER, address); } } errorCue(); } }
void OSCBundle::send(Print &p){ //don't send a bundle with errors if (hasError()){ return; } //write the bundle header static uint8_t header[] = {'#', 'b', 'u', 'n', 'd', 'l', 'e', 0}; p.write(header, 8); //write the timetag { osctime_t time = timetag; uint32_t d = BigEndian(time.seconds); uint8_t * ptr = (uint8_t *) &d; p.write(ptr, 4); d = BigEndian(time.fractionofseconds); ptr = (uint8_t *) &d; p.write(ptr, 4); } //send the messages for (int i = 0; i < numMessages; i++){ OSCMessage * msg = getOSCMessage(i); int msgSize = msg->bytes(); //turn the message size into a pointer uint32_t s32 = BigEndian((uint32_t) msgSize); uint8_t * sptr = (uint8_t *) &s32; //write the messsage size p.write(sptr, 4); msg->send(p); } }
//returns the first fullMatch. OSCMessage * OSCBundle::getOSCMessage( char * addr){ for (int i = 0; i < numMessages; i++){ OSCMessage * msg = getOSCMessage(i); if (msg->fullMatch(addr)){ return msg; } } }
bool OSCBundle::route(const char * pattern, void (*callback)(OSCMessage&, int), int initial_offset){ bool called = false; for (int i = 0; i < numMessages; i++){ OSCMessage msg = getOSCMessage(i); called = msg.route(pattern, callback, initial_offset) || called; } return called; }
bool OSCBundle::hasError(){ bool retError = error != OSC_OK; //test each of the data for (int i = 0; i < numMessages; i++){ OSCMessage * msg = getOSCMessage(i); retError |= msg->hasError(); } return retError; }
void encoderButton(OSCMessage &msg){ if (msg.isInt(0)){ if (msg.getInt(0) == 1) { ui.encoderPress(); } if (msg.getInt(0) == 0) { ui.encoderRelease(); } } }
/* helpers */ void setScreenLine(OledScreen &screen, int lineNum, OSCMessage &msg){ char str[256]; char screenLine[256]; int i = 0; screenLine[0] = 0; // since there are no strings in pd, the line message will be made of different types // cat the line together, then throw it up on the patch screen while (msg.isString(i) || msg.isFloat(i) || msg.isInt(i)){ if (msg.isString(i)){ msg.getString(i, str, 256); strcat(screenLine, str); strcat(screenLine, " "); } if (msg.isFloat(i)){ sprintf(str, "%g ", msg.getFloat(i)); strcat(screenLine, str); } if (msg.isInt(i)){ sprintf(str, "%d ", msg.getInt(i)); strcat(screenLine, str); } i++; } screen.setLine(lineNum, screenLine); // printf("%s\n", screenLine); }
void Ambix_encoderAudioProcessor::sendOSC() // send osc data { if (osc_out) { OSCMessage mymsg = OSCMessage("/ambi_enc"); mymsg.addInt32(m_id); // source id mymsg.addString("test"); // name... currently unused mymsg.addFloat32(2.0f); // distance... currently unused mymsg.addFloat32(360.f*(azimuth_param-0.5f)); // azimuth -180....180° mymsg.addFloat32(360.f*(elevation_param-0.5f)); // elevation -180....180° mymsg.addFloat32(size_param); // size param 0.0 ... 1.0 mymsg.addFloat32(dpk); // digital peak value linear 0.0 ... 1.0 (=0dBFS) mymsg.addFloat32(rms); // rms value linear 0.0 ... 1.0 (=0dBFS) if(osc_in) { mymsg.addInt32(osc_in_port.getIntValue()); // osc receiver udp port } for (int i = 0; i < oscSenders.size(); i++) { oscSenders.getUnchecked(i)->send(mymsg); } _azimuth_param = azimuth_param; // change buffers _elevation_param = elevation_param; _size_param = size_param; _rms = rms; _dpk = dpk; } }
void OSCServer::oscMessageReceived (const OSCMessage& message){ // we're realtime here, defer if needed if(createClientIfNeeded(message)) return; if(OSCAddressPattern("/All/*").matches(message.getAddressPattern().toString())){ StringArray res; res.addTokens(message.getAddressPattern().toString(),"/",""); res.removeRange(1, 1); String current = res.joinIntoString("/"); for(auto &c:clients){ for(auto & b:c->boundedParams){ StringArray res2; res2.addTokens(b->address.toString(),"/",""); // currently /Tracks/i/i/... res2.removeRange(1, 3); String curS = res2.joinIntoString("/"); if(curS == current){ float val; if(getValueFromMessage(message, val)){ b->setValue(val); } } } } } else{ for(auto &c:clients){ for(auto & b:c->boundedParams){ if(message.getAddressPattern() == b->address){ float val; if(getValueFromMessage(message, val)){ b->setValue(val); } else{ DBG("message format not supported : "+String( message[0].getType())); } } } } } }
void vuMeter(OSCMessage &msg){ static int count; char line[1024]; int len, i, outR, outL, inR, inL; if (msg.isInt(0)) inR = msg.getInt(0); if (msg.isInt(1)) inL = msg.getInt(1); if (msg.isInt(2)) outR = msg.getInt(2); if (msg.isInt(3)) outL = msg.getInt(3); ui.patchScreen.drawInfoBar(inR, inL, outR, outL); }
OSCMessage & OSCBundle::add(OSCMessage & _msg){ OSCMessage * msg = new OSCMessage(_msg); if (!msg->hasError()){ //realloc the array to fit the message OSCMessage ** messageMem = (OSCMessage **) realloc(messages, sizeof(OSCMessage *) * (numMessages + 1)); if (messageMem != NULL){ messages = messageMem; messages[numMessages] = msg; numMessages++; } else { error = ALLOCFAILED; } } return *msg; }
void OSCBundle::decodeMessage(uint8_t incomingByte){ //get the current message if (numMessages > 0){ OSCMessage * lastMessage = messages[numMessages - 1]; //put the bytes in there lastMessage->fill(incomingByte); //if it's all done if (incomingBufferSize == incomingMessageSize){ //move onto the next message decodeState = MESSAGE_SIZE; clearIncomingBuffer(); } else if (incomingBufferSize > incomingMessageSize){ error = INVALID_OSC; } } }
void do_slider3(){ float data = recMes.getArgFloat(0); dmx_wert[2 + shift]= data * 255; }
// this is called if an OSC message is received void Ambix_encoderAudioProcessor::oscMessageReceived (const OSCMessage& message) { // /ambi_enc_set <id> <distance> <azimuth> <elevation> <size> // parse the message for int and float float val[5]; for (int i=0; i < jmin(5,message.size()); i++) { val[i] = 0.5f; // get the value wheter it is a int or float value if (message[i].getType() == OSCTypes::float32) { val[i] = (float)message[i].getFloat32(); } else if (message[i].getType() == OSCTypes::int32) { val[i] = (float)message[i].getInt32(); } } setParameterNotifyingHost(Ambix_encoderAudioProcessor::AzimuthParam, jlimit(0.f, 1.f, (val[2]+180.f)/360.f) ); setParameterNotifyingHost(Ambix_encoderAudioProcessor::ElevationParam, jlimit(0.f, 1.f, (val[3]+180.f)/360.f) ); setParameterNotifyingHost(Ambix_encoderAudioProcessor::SizeParam, jlimit(0.f, 1.f, val[4])); }
void do_button3(){ long data = recMes.getArgInt(0); for (i = 0; i <= 11; i++) { dmx_wert[i]=255; } }
bool OSCServer::createClientIfNeeded(const OSCMessage &m){ // m. // TODO what clever protocol should we implement if(m.getAddressPattern().matches(OSCAddress("/Hi"))){ String host = m[0].getString(); if(host == "localhost"){ host = "127.0.0.1"; } int port = m[1].getInt32(); for(auto & c:clients){ if(c->host==host && c->port == port) return false; } OSCClient * cli = new OSCClient(host,port,true); for(auto & t:owner->tracks){ for(auto & p :t.get()->getParameters()){ cli->bindParameter(t, p, "/Tracks/"+String(*t->groupID) + "/" +String(*t->trackNum) + "/" + p->getName(50) ); } } clients.add(cli); return true; } else if(m.getAddressPattern().matches(OSCAddress("/Bye"))){ String host = m[0].getString(); if(host == "localhost"){ host = "127.0.0.1"; } int port = m[1].getInt32(); for(auto & c:clients){ if(c->host==host && c->port == port){ clients.removeObject(c); break; } } } return false; }
void do_ypos(){ float data = recMes.getArgFloat(0); Serial.print( "ypos: " ); Serial.println( data ); }
/** * Convert the byte array a simple message. Assumes that the byte array is a message. * @return a message containing the data specified in the byte stream */ OSCMessage& OSCByteArrayToMsgConverter::convertMessage() { OSCMessage* message = new OSCMessage(); QString addrStr = readString(); message->setAddress(addrStr); QByteArray types = readTypes(); if(types.isNull()) return *message; moveToFourByteBoundry(); for(int i = 0; i < types.length(); i++) { if('[' == types.at(i)) { // we're looking at an array -- read it in message->addArgument(readArray(types, ++i)); // then increment i to the end of the array while(']' != types.at(i)) i++; }else message->addArgument(readArgument(types.at(i))); } return *message; }
int OSCQueue::oscMessageHandler(const char *path, const char *types, lo_arg **argv, int argc, lo_message, void *user_data) { OSCQueue *queue = static_cast<OSCQueue *>(user_data); int target; int targetData; QString method; if (!queue->parseOSCPath(path, target, targetData, method)) { return 1; } OSCMessage message; message.setTarget(target); message.setTargetData(targetData); message.setMethod(method); int i = 0; while (types && i < argc && types[i]) { char type = types[i]; lo_arg *arg = argv[i]; switch (type) { case 'i': message.addArg(arg->i); break; // This conversion fails to compile in 64-bit environments // at present, and we don't use the h type anyway so we // can safely omit it // case 'h': message.addArg(arg->h); break; case 'f': message.addArg(arg->f); break; case 'd': message.addArg(arg->d); break; case 'c': message.addArg(arg->c); break; case 't': message.addArg(arg->i); break; case 's': message.addArg(&arg->s); break; default: std::cerr << "WARNING: OSCQueue::oscMessageHandler: " << "Unsupported OSC type '" << type << "'" << std::endl; break; } ++i; } queue->postMessage(message); return 0; }
void CApplicationMonitor::Dump(OSCMessage &msg, bool bOnlyIfPresent) const { CApplicationMonitorHeader Header; CCrashReport Report; uint8_t uReport; uint32_t uAddress; LoadHeader(Header); if (!bOnlyIfPresent || Header.m_uSavedReports != 0) { for (uReport = 0; uReport < Header.m_uSavedReports; ++uReport) { LoadReport(uReport, Report); uAddress = 0; memcpy(&uAddress, Report.m_auAddress, PROGRAM_COUNTER_SIZE); msg.add((int)uAddress); msg.add((int)Report.m_uData); } } }
void do_xpos(){ float data = recMes.getArgFloat(0); Serial.print( "xpos: " ); Serial.println( (data) ); }
void OSCPacketDispatcher::dispatchMessage(OSCMessage& message, QHostAddress& address, QDateTime& time) { QList<QString> mkeys = iAddressToClassTable->keys(); for(int i=0; i < mkeys.length(); i++) { const QString& addresskey = mkeys.at(i); if(addresskey==message.getAddress()) { OSCListener* olistener = iAddressToClassTable->value(addresskey); olistener->acceptMessage(address,time,message); } } }
void setup() { //for message logging Serial.begin(9600); Ethernet.begin(serverMac ,serverIp); // Ethernet.begin(serverMac ,serverIp ,gateway ,subnet); //setting osc recieve server osc.begin(serverPort); sendMes.setIp( destIp ); sendMes.setPort( destPort ); sendMes.setTopAddress( topAddress ); pinMode(SW_PIN, INPUT); pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, HIGH); //LED OFF ledFlag=false; swFlag=false; analogReference(DEFAULT); oldPotValue=(long)analogRead(POT_PIN); //osc message buffer clear osc.flush(); long value = 1; sendMes.setSubAddress( subAddress[1] ); // "/ard/switch" sendMes.setArgs( "i", &value ); osc.sendOsc( &sendMes ); }
bool OSCServer::getValueFromMessage(const OSCMessage& message,float & val){ // allow empty messages for boolean actions if(message.size() == 0){ val = 1; return true; } if(message[0].isInt32()){ val = message[0].getInt32(); return true; } else if(message[0].isFloat32()){ val = message[0].getFloat32(); return true; } else if(message[0].isBlob()){ //not supported jassert(false); } return false; }
void TuioClient::oscMessageReceived (const OSCMessage& message) { if( message.getAddressPattern() == "/tuio/2Dcur" ) { String cmd; cmd = message[0].getString(); if (cmd == "set") { int32 s_id; float xpos, ypos, xspeed, yspeed, maccel; s_id=message[1].getInt32(); xpos=message[2].getFloat32(); ypos=message[3].getFloat32(); xspeed =message[4].getFloat32(); yspeed=message[5].getFloat32(); maccel=message[6].getFloat32(); std::list<TuioCursor*>::iterator tcur; for (tcur=cursorList.begin(); tcur!= cursorList.end(); tcur++) if((*tcur)->getSessionID()==(long)s_id) break; if (tcur==cursorList.end()) { TuioCursor *addCursor = new TuioCursor((long)s_id,-1,xpos,ypos); frameCursors.push_back(addCursor); } else if ( ((*tcur)->getX()!=xpos) || ((*tcur)->getY()!=ypos) || ((*tcur)->getXSpeed()!=xspeed) || ((*tcur)->getYSpeed()!=yspeed) || ((*tcur)->getMotionAccel()!=maccel) ) { int id = (*tcur)->getCursorID(); TuioCursor *updateCursor = new TuioCursor((long)s_id,id,xpos,ypos); updateCursor->update(xpos,ypos,xspeed,yspeed,maccel); frameCursors.push_back(updateCursor); } } else if (cmd=="alive") { aliveCursorList.clear(); for(int i = 1; i < message.size() ; i++) { aliveCursorList.push_back(message[i].getInt32()); } } else if( cmd== "fseq" ){ int32 fseq; fseq = message[1].getInt32(); bool lateFrame = false; if (fseq>0) { if (fseq>currentFrame) currentTime = TuioTime::getSessionTime(); if ((fseq>=currentFrame) || ((currentFrame-fseq)>100)) currentFrame = fseq; else lateFrame = true; } else if ((TuioTime::getSessionTime().getTotalMilliseconds()-currentTime.getTotalMilliseconds())>100) { currentTime = TuioTime::getSessionTime(); } if (!lateFrame) { // lockCursorList(); // find the removed cursors first for (std::list<TuioCursor*>::iterator tcur=cursorList.begin(); tcur != cursorList.end(); tcur++) { std::list<long>::iterator iter = find(aliveCursorList.begin(), aliveCursorList.end(), (*tcur)->getSessionID()); if (iter == aliveCursorList.end()) { (*tcur)->remove(currentTime); frameCursors.push_back(*tcur); } } // unlockCursorList(); for (std::list<TuioCursor*>::iterator iter=frameCursors.begin(); iter != frameCursors.end(); iter++) { TuioCursor *tcur = (*iter); int c_id = -1; TuioCursor *frameCursor = NULL; switch (tcur->getTuioState()) { case TUIO_REMOVED: frameCursor = tcur; frameCursor->remove(currentTime); for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++) (*listener)->removeTuioCursor(frameCursor); // lockCursorList(); for (std::list<TuioCursor*>::iterator delcur=cursorList.begin(); delcur!=cursorList.end(); delcur++) { if((*delcur)->getSessionID()==frameCursor->getSessionID()) { cursorList.erase(delcur); break; } } if (frameCursor->getCursorID()==maxCursorID) { maxCursorID = -1; delete frameCursor; if (cursorList.size()>0) { std::list<TuioCursor*>::iterator clist; for (clist=cursorList.begin(); clist != cursorList.end(); clist++) { c_id = (*clist)->getCursorID(); if (c_id>maxCursorID) maxCursorID=c_id; } freeCursorBuffer.clear(); for (std::list<TuioCursor*>::iterator flist=freeCursorList.begin(); flist != freeCursorList.end(); flist++) { TuioCursor *freeCursor = (*flist); if (freeCursor->getCursorID()>maxCursorID) delete freeCursor; else freeCursorBuffer.push_back(freeCursor); } freeCursorList = freeCursorBuffer; } else { for (std::list<TuioCursor*>::iterator flist=freeCursorList.begin(); flist != freeCursorList.end(); flist++) { TuioCursor *freeCursor = (*flist); delete freeCursor; } freeCursorList.clear(); } } else if (frameCursor->getCursorID()<maxCursorID) { freeCursorList.push_back(frameCursor); } // unlockCursorList(); break; case TUIO_ADDED: // lockCursorList(); c_id = (int)cursorList.size(); if (((int)(cursorList.size())<=maxCursorID) && ((int)(freeCursorList.size())>0)) { std::list<TuioCursor*>::iterator closestCursor = freeCursorList.begin(); for(std::list<TuioCursor*>::iterator iter = freeCursorList.begin();iter!= freeCursorList.end(); iter++) { if((*iter)->getDistance(tcur)<(*closestCursor)->getDistance(tcur)) closestCursor = iter; } TuioCursor *freeCursor = (*closestCursor); c_id = freeCursor->getCursorID(); freeCursorList.erase(closestCursor); delete freeCursor; } else maxCursorID = c_id; frameCursor = new TuioCursor(currentTime,tcur->getSessionID(),c_id,tcur->getX(),tcur->getY()); cursorList.push_back(frameCursor); delete tcur; // unlockCursorList(); for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++){ (*listener)->addTuioCursor(frameCursor); } break; default: // lockCursorList(); std::list<TuioCursor*>::iterator iter; for (iter=cursorList.begin(); iter != cursorList.end(); iter++) { if((*iter)->getSessionID()==tcur->getSessionID()) { frameCursor = (*iter); break; } } if ( (tcur->getX()!=frameCursor->getX() && tcur->getXSpeed()==0) || (tcur->getY()!=frameCursor->getY() && tcur->getYSpeed()==0) ) frameCursor->update(currentTime,tcur->getX(),tcur->getY()); else frameCursor->update(currentTime,tcur->getX(),tcur->getY(),tcur->getXSpeed(),tcur->getYSpeed(),tcur->getMotionAccel()); delete tcur; // unlockCursorList(); for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++) (*listener)->updateTuioCursor(frameCursor); } } for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++) (*listener)->refresh(currentTime); } else { for (std::list<TuioCursor*>::iterator iter=frameCursors.begin(); iter != frameCursors.end(); iter++) { TuioCursor *tcur = (*iter); delete tcur; } } frameCursors.clear(); } } else if( message.getAddressPattern()== "/tuio/2Dobj" ){ // String cmd = message[0].getString(); // // if (cmd=="set") { // // int32 s_id, c_id; // float xpos, ypos, angle, xspeed, yspeed, rspeed, maccel, raccel; // s_id=message[1].getInt32(); // c_id=message[2].getInt32(); // xpos=message[3].getFloat32(); // ypos=message[4].getFloat32(); // angle=message[5].getFloat32(); // xspeed =message[6].getFloat32(); // yspeed=message[7].getFloat32(); // rspeed=message[8].getFloat32(); // maccel=message[9].getFloat32(); // raccel=message[10].getFloat32(); // // lockObjectList(); // std::list<TuioObject*>::iterator tobj; // for (tobj=objectList.begin(); tobj!= objectList.end(); tobj++) // if((*tobj)->getSessionID()==(long)s_id) break; // // if (tobj == objectList.end()) { // // TuioObject *addObject = new TuioObject((long)s_id,(int)c_id,xpos,ypos,angle); // frameObjects.push_back(addObject); // // } else if ( ((*tobj)->getX()!=xpos) || ((*tobj)->getY()!=ypos) || ((*tobj)->getAngle()!=angle) || ((*tobj)->getXSpeed()!=xspeed) || ((*tobj)->getYSpeed()!=yspeed) || ((*tobj)->getRotationSpeed()!=rspeed) || ((*tobj)->getMotionAccel()!=maccel) || ((*tobj)->getRotationAccel()!=raccel) ) { // // TuioObject *updateObject = new TuioObject((long)s_id,(*tobj)->getSymbolID(),xpos,ypos,angle); // updateObject->update(xpos,ypos,angle,xspeed,yspeed,rspeed,maccel,raccel); // frameObjects.push_back(updateObject); // // } // unlockObjectList(); // // } // else if (cmd=="alive") { // // aliveObjectList.clear(); // for(int i = 1 ; i < message.size() ; i++){ // aliveObjectList.push_back(message[i].getInt32()); // } // // } else if (cmd == "fseq") { // // int32 fseq; // fseq = message[1].getInt32(); // bool lateFrame = false; // if (fseq>0) { // if (fseq>currentFrame) currentTime = TuioTime::getSessionTime(); // if ((fseq>=currentFrame) || ((currentFrame-fseq)>100)) currentFrame = fseq; // else lateFrame = true; // } else if ((TuioTime::getSessionTime().getTotalMilliseconds()-currentTime.getTotalMilliseconds())>100) { // currentTime = TuioTime::getSessionTime(); // } // // if (!lateFrame) { // // lockObjectList(); // //find the removed objects first // for (std::list<TuioObject*>::iterator tobj=objectList.begin(); tobj != objectList.end(); tobj++) { // std::list<long>::iterator iter = find(aliveObjectList.begin(), aliveObjectList.end(), (*tobj)->getSessionID()); // if (iter == aliveObjectList.end()) { // (*tobj)->remove(currentTime); // frameObjects.push_back(*tobj); // } // } // unlockObjectList(); // // for (std::list<TuioObject*>::iterator iter=frameObjects.begin(); iter != frameObjects.end(); iter++) { // TuioObject *tobj = (*iter); // // TuioObject *frameObject = NULL; // switch (tobj->getTuioState()) { // case TUIO_REMOVED: // frameObject = tobj; // frameObject->remove(currentTime); // // for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++) // (*listener)->removeTuioObject(frameObject); // // lockObjectList(); // for (std::list<TuioObject*>::iterator delobj=objectList.begin(); delobj!=objectList.end(); delobj++) { // if((*delobj)->getSessionID()==frameObject->getSessionID()) { // objectList.erase(delobj); // break; // } // } // unlockObjectList(); // break; // case TUIO_ADDED: // // lockObjectList(); // frameObject = new TuioObject(currentTime,tobj->getSessionID(),tobj->getSymbolID(),tobj->getX(),tobj->getY(),tobj->getAngle()); // objectList.push_back(frameObject); // unlockObjectList(); // // for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++) // (*listener)->addTuioObject(frameObject); // // break; // default: // // lockObjectList(); // std::list<TuioObject*>::iterator iter; // for (iter=objectList.begin(); iter != objectList.end(); iter++) { // if((*iter)->getSessionID()==tobj->getSessionID()) { // frameObject = (*iter); // break; // } // } // if(iter==objectList.end()) break; // // if ( (tobj->getX()!=frameObject->getX() && tobj->getXSpeed()==0) || (tobj->getY()!=frameObject->getY() && tobj->getYSpeed()==0) ) // frameObject->update(currentTime,tobj->getX(),tobj->getY(),tobj->getAngle()); // else // frameObject->update(currentTime,tobj->getX(),tobj->getY(),tobj->getAngle(),tobj->getXSpeed(),tobj->getYSpeed(),tobj->getRotationSpeed(),tobj->getMotionAccel(),tobj->getRotationAccel()); // unlockObjectList(); // // for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++) // (*listener)->updateTuioObject(frameObject); // // } // delete tobj; // } // // for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++) // (*listener)->refresh(currentTime); // // } else { // for (std::list<TuioObject*>::iterator iter=frameObjects.begin(); iter != frameObjects.end(); iter++) { // TuioObject *tobj = (*iter); // delete tobj; // } // } // // frameObjects.clear(); // } } }
int main(int argc, char* argv[]) { uint32_t seconds = 0; char udpPacketIn[256]; //uint8_t osc_packet_in[256]; uint8_t i = 0; int len = 0; int page = 0; Timer screenFpsTimer, screenLineTimer, knobPollTimer, pingTimer, upTime; screenFpsTimer.reset(); knobPollTimer.reset(); screenLineTimer.reset(); pingTimer.reset(); upTime.reset(); // set locale so sorting happens in right order //std::setlocale(LC_ALL, "en_US.UTF-8"); // for setting real time scheduling /*struct sched_param par; par.sched_priority = 10; printf("settin priority to: %d\n", 10); if (sched_setscheduler(0,SCHED_FIFO,&par) < 0){ printf("failed to set rt scheduling\n"); }*/ udpSock.setDestination(4000, "localhost"); OSCMessage msgIn; ui.buildMenu(); ui.drawPatchList(); // send ready to wake up MCU // MCU is ignoring stuff over serial port until this message comes through // don't empty the message because it gets sent out periodically incase MCU resets OSCMessage rdyMsg("/ready"); rdyMsg.add(1); rdyMsg.send(dump); // send it a few times just in case for(i = 0; i<4; i++) { slip.sendMessage(dump.buffer, dump.length, serial); usleep(20000); // wait 20 ms } //playFirst(); quit = 0; // full udp -> serial -> serial -> udp for (;;){ // receive udp, send to serial len = udpSock.readBuffer(udpPacketIn, 256, 0); if (len > 0){ msgIn.empty(); for (i = 0; i < len; i++){ msgIn.fill(udpPacketIn[i]); } if(!msgIn.hasError()){ msgIn.dispatch("/oled/vumeter", vuMeter, 0); msgIn.dispatch("/oled/line/1", setPatchScreenLine1, 0); msgIn.dispatch("/oled/line/2", setPatchScreenLine2, 0); msgIn.dispatch("/oled/line/3", setPatchScreenLine3, 0); msgIn.dispatch("/oled/line/4", setPatchScreenLine4, 0); msgIn.dispatch("/oled/line/5", setPatchScreenLine5, 0); msgIn.dispatch("/oled/aux/line/1", setAuxScreenLine1, 0); msgIn.dispatch("/oled/aux/line/2", setAuxScreenLine2, 0); msgIn.dispatch("/oled/aux/line/3", setAuxScreenLine3, 0); msgIn.dispatch("/oled/aux/line/4", setAuxScreenLine4, 0); msgIn.dispatch("/oled/aux/line/5", setAuxScreenLine5, 0); msgIn.dispatch("/oled/aux/clear", auxScreenClear, 0); msgIn.dispatch("/ready", sendReady, 0); msgIn.dispatch("/shutdown", sendShutdown, 0); msgIn.dispatch("/led", setLED, 0); msgIn.dispatch("/oled/setscreen", setScreen, 0); msgIn.dispatch("/reload", reload, 0); msgIn.dispatch("/quitmother", quitMother, 0); msgIn.dispatch("/screenshot", screenShot, 0); msgIn.dispatch("/pgmchg", programChange, 0); msgIn.dispatch("/getPatchName", getPatchName, 0); } else { printf("bad message\n"); } msgIn.empty(); } // receive serial, send udp if(slip.recvMessage(serial)) { udpSock.writeBuffer(slip.decodedBuf, slip.decodedLength); // check if we need to do something with this message msgIn.empty(); msgIn.fill(slip.decodedBuf, slip.decodedLength); msgIn.dispatch("/enc", encoderInput, 0); msgIn.dispatch("/encbut", encoderButton, 0); msgIn.empty(); } // sleep for .5ms usleep(750); if (ui.currentScreen == AUX) { // we can do a whole screen, but not faster than 20fps if (screenFpsTimer.getElapsed() > 50.f){ screenFpsTimer.reset(); if (ui.newScreen){ ui.newScreen = 0; updateScreenPage(0, ui.auxScreen);//menuScreen); updateScreenPage(1, ui.auxScreen); updateScreenPage(2, ui.auxScreen); updateScreenPage(3, ui.auxScreen); updateScreenPage(4, ui.auxScreen); updateScreenPage(5, ui.auxScreen); updateScreenPage(6, ui.auxScreen); updateScreenPage(7, ui.auxScreen); } } } else if (ui.currentScreen == MENU) { // we can do a whole screen, but not faster than 20fps if (screenFpsTimer.getElapsed() > 50.f){ screenFpsTimer.reset(); if (ui.newScreen){ ui.newScreen = 0; updateScreenPage(0, ui.menuScreen);//menuScreen); updateScreenPage(1, ui.menuScreen); updateScreenPage(2, ui.menuScreen); updateScreenPage(3, ui.menuScreen); updateScreenPage(4, ui.menuScreen); updateScreenPage(5, ui.menuScreen); updateScreenPage(6, ui.menuScreen); updateScreenPage(7, ui.menuScreen); } // if there is a patch running while on menu screen, switch back to patch screen after the timeout if (ui.menuScreenTimeout > 0) ui.menuScreenTimeout -= 50; else ui.currentScreen = PATCH; } } else if (ui.currentScreen == PATCH) { if (ui.patchIsRunning) { // every 16 ms send a new screen page if (screenLineTimer.getElapsed() > 15.f){ screenLineTimer.reset(); updateScreenPage(page, ui.patchScreen); page++; page %= 8; } } } // every 1 second send a ping in case MCU resets if (pingTimer.getElapsed() > 1000.f){ // printf("pinged the MCU at %f ms.\n", upTime.getElapsed()); pingTimer.reset(); rdyMsg.send(dump); slip.sendMessage(dump.buffer, dump.length, serial); } // poll for knobs if (knobPollTimer.getElapsed() > 40.f){ knobPollTimer.reset(); sendGetKnobs(); } // check exit flag if (quit) { printf("quitting\n"); return 0; } } // for;; }
/* OSC messages received from MCU (we only use ecncoder input, the key and knob messages get passed righ to PD or other program */ void encoderInput(OSCMessage &msg){ if (msg.isInt(0)){ if (msg.getInt(0) == 1) ui.encoderUp(); if (msg.getInt(0) == 0) ui.encoderDown(); } }