int OscReceiver::handler(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *data) { bool matched = false; string pathString(path); if(useThru_) { // Rebroadcast any matching messages if(!pathString.compare(0, thruPrefix_.length(), thruPrefix_)) lo_send_message(thruAddress_, path, msg); } // Check if the incoming message matches the global prefix for this program. If not, discard it. if(pathString.compare(0, globalPrefix_.length(), globalPrefix_)) { cout << "OSC message '" << path << "' received\n"; return 1; } // Lock the mutex so the list of listeners doesn't change midway through pthread_mutex_lock(&oscListenerMutex_); // Now remove the global prefix and compare the rest of the message to the registered handlers. multimap<string, OscHandler*>::iterator it; pair<multimap<string, OscHandler*>::iterator,multimap<string, OscHandler*>::iterator> ret; string truncatedPath = pathString.substr(globalPrefix_.length(), pathString.length() - globalPrefix_.length()); ret = noteListeners_.equal_range(truncatedPath); it = ret.first; while(it != ret.second) { OscHandler *object = (*it++).second; #ifdef DEBUG_MESSAGES cout << "Matched OSC path '" << path << "' to handler " << object << endl; #endif object->oscHandlerMethod(truncatedPath.c_str(), types, argc, argv, data); matched = true; } pthread_mutex_unlock(&oscListenerMutex_); if(matched) // This message has been handled return 0; printf("Unhandled OSC path: <%s>\n", path); #ifdef DEBUG_MESSAGES for (int i=0; i<argc; i++) { printf("arg %d '%c' ", i, types[i]); lo_arg_pp((lo_type)types[i], argv[i]); printf("\n"); } #endif return 1; }
int OscController::handler(const char *path, const char *types, lo_arg **argv, int argc, lo_message msg, void *data) { bool matched = false; #ifdef DEBUG_MESSAGES_EXTRA cout << "Received OSC message " << path << " [" << types << "]\n"; #endif if(useOscMidi_) // OSC MIDI emulation. Also the most time-sensitive & frequent message so do this first. { if(!strcmp(path, "/mrp/midi") && argc >= 1) { if(types[0] == 'm') return handleMidi(argv[0]->m[1], argv[0]->m[2], argv[0]->m[3]); if(argc >= 3) if(types[0] == 'i' && types[1] == 'i' && types[2] == 'i') return handleMidi((unsigned char)argv[0]->i, (unsigned char)argv[1]->i, (unsigned char)argv[2]->i); } if(!strcmp(path, "/mrp/quality/brightness") && argc >= 3) { if(types[0] == 'i' && types[1] == 'i' && types[2] == 'f') return handleRtBrightness(argv); } if(!strcmp(path, "/mrp/quality/intensity") && argc >= 3) { if(types[0] == 'i' && types[1] == 'i' && types[2] == 'f') return handleRtIntensity(argv); } if(!strcmp(path, "/mrp/quality/pitch") && argc >= 3) { if(types[0] == 'i' && types[1] == 'i' && types[2] == 'f') return handleRtPitch(argv); } if(!strcmp(path, "/mrp/quality/pitch/vibrato") && argc >= 3) { if(types[0] == 'i' && types[1] == 'i' && types[2] == 'f') return handleRtPitchVibrato(argv); } if(!strcmp(path, "/mrp/quality/harmonic") && argc >= 3) { if(types[0] == 'i' && types[1] == 'i' && types[2] == 'f') return handleRtHarmonic(argv); } if(!strcmp(path, "/mrp/quality/harmonics/raw") && argc >= 3) { if(types[0] == 'i' && types[1] == 'i' && types[2] == 'f') return handleRtHarmonicsRaw(argc, types, argv); } if(!strcmp(path, "/mrp/volume") && argc >= 1) { if(types[0] == 'f') { cout << "setting volume to " << argv[0]->f << endl; midiController_->render_->setGlobalAmplitude(argv[0]->f); return 0; } } if(!strcmp(path, "/mrp/global/harmonics") && argc == 2) { if(types[0] == 'i' || types[1] == 'f') midiController_->oscHandleGlobalParameters(path, types, 2, argv, data); } if(!strcmp(path, "/mrp/allnotesoff")) { allNotesOff(); } } string pathString(path); if(useThru_) { // Rebroadcast any matching messages if(!pathString.compare(0, thruPrefix_.length(), thruPrefix_)) lo_send_message(thruAddress_, path, msg); } // Check if the incoming message matches the global prefix for this program. If not, discard it. if(pathString.compare(0, globalPrefix_.length(), globalPrefix_)) { cout << "OSC message '" << path << "' received\n"; return 1; } // Lock the mutex so the list of listeners doesn't change midway through pthread_mutex_lock(&oscListenerMutex_); // Now remove the global prefix and compare the rest of the message to the registered handlers. multimap<string, OscHandler*>::iterator it; pair<multimap<string, OscHandler*>::iterator,multimap<string, OscHandler*>::iterator> ret; string truncatedPath = pathString.substr(globalPrefix_.length(), pathString.length() - globalPrefix_.length()); ret = noteListeners_.equal_range(truncatedPath); it = ret.first; while(it != ret.second) { OscHandler *object = (*it++).second; #ifdef DEBUG_MESSAGES_EXTRA cout << "Matched OSC path '" << path << "' to handler " << object << endl; #endif object->oscHandlerMethod(truncatedPath.c_str(), types, argc, argv, data); matched = true; } pthread_mutex_unlock(&oscListenerMutex_); if(matched) // This message has been handled return 0; printf("Unhandled OSC path: <%s>\n", path); /*#ifdef DEBUG_MESSAGES for (i=0; i<argc; i++) { printf("arg %d '%c' ", i, types[i]); lo_arg_pp((lo_type)types[i], argv[i]); printf("\n"); } #endif*/ return 1; }