//-------------------------------------------------------------- void AppCore::update() { ofBackground(0, 0, 0); // update scope array from pd pd.readArray("scope", scopeArray); // udpate pd from gui pd << StartMessage() << "transpose" << transposeSlider.getValue() << FinishList("TO_PD"); pd << StartMessage() << "mix" << mixSlider.getValue() << FinishList("TO_PD"); pd << StartMessage() << "inGain" << inGainSlider.getValue() << FinishList("TO_PD"); pd << StartMessage() << "outGain" << outGainSlider.getValue() << FinishList("TO_PD"); }
void ErrorHandler::operator() (const char* fmt, const char* msg, int n) { if (StartMessage()) { sprintf(addBuff, fmt, msg, n); Add(addBuff); EndMessage(); } }
void ErrorHandler::operator() (const char* fmt, int n1, int n2) { if (StartMessage()) { sprintf(addBuff, fmt, n1, n2); Add(addBuff); EndMessage(); } }
void RangeCheck(int lower, int value, int upper, char *errormessage) { if ((value < lower) | (value > upper)) { StartMessage(); printf("RangeCheck fails: %d <= %d <= %d: ",lower,value,upper); EndMessage(); oops(errormessage); } }
NS_IMETHODIMP nsFolderCompactState::OnStartRequest(nsIRequest *request, nsISupports *ctxt) { return StartMessage(); }
//-------------------------------------------------------------- void AppCore::playTone(int pitch) { pd << StartMessage() << "pitch" << pitch << FinishList("tone") << Bang("tone"); }
//-------------------------------------------------------------- void AppCore::setup(const int numOutChannels, const int numInChannels, const int sampleRate, const int ticksPerBuffer) { ofSetFrameRate(60); ofSetVerticalSync(true); //ofSetLogLevel(OF_LOG_VERBOSE); // double check where we are ... cout << ofFilePath::getCurrentWorkingDirectory() << endl; if(!pd.init(numOutChannels, numInChannels, sampleRate, ticksPerBuffer)) { ofLog(OF_LOG_ERROR, "Could not init pd"); OF_EXIT_APP(1); } midiChan = 1; // midi channels are 1-16 // subscribe to receive source names pd.subscribe("toOF"); pd.subscribe("env"); // add message receiver, disables polling (see processEvents) pd.addReceiver(*this); // automatically receives from all subscribed sources pd.ignore(*this, "env"); // don't receive from "env" //pd.ignore(*this); // ignore all sources //pd.receive(*this, "toOF"); // receive only from "toOF" // add midi receiver pd.addMidiReceiver(*this); // automatically receives from all channels //pd.ignoreMidi(*this, 1); // ignore midi channel 1 //pd.ignoreMidi(*this); // ignore all channels //pd.receiveMidi(*this, 1); // receive only from channel 1 // add the data/pd folder to the search path pd.addToSearchPath("pd"); // audio processing on pd.start(); cout << endl << "BEGIN Patch Test" << endl; // open patch Patch patch = pd.openPatch("test.pd"); cout << patch << endl; // close patch pd.closePatch(patch); cout << patch << endl; // open patch patch = pd.openPatch("test.pd"); cout << patch << endl; cout << "FINISH Patch Test" << endl; cout << endl << "BEGIN Message Test" << endl; // test basic atoms pd.sendBang("fromOF"); pd.sendFloat("fromOF", 100); pd.sendSymbol("fromOF", "test string"); // stream interface pd << Bang("fromOF") << Float("fromOF", 100) << Symbol("fromOF", "test string"); // send a list pd.startMessage(); pd.addFloat(1.23); pd.addSymbol("a symbol"); pd.finishList("fromOF"); // send a message to the $0 receiver ie $0-toOF pd.startMessage(); pd.addFloat(1.23); pd.addSymbol("a symbol"); pd.finishList(patch.dollarZeroStr()+"-fromOF"); // send a list using the List object List testList; testList.addFloat(1.23); testList.addSymbol("sent from a List object"); pd.sendList("fromOF", testList); pd.sendMessage("fromOF", "msg", testList); // stream interface for list pd << StartMessage() << 1.23 << "sent from a streamed list" << FinishList("fromOF"); cout << "FINISH Message Test" << endl; cout << endl << "BEGIN MIDI Test" << endl; // send functions pd.sendNoteOn(midiChan, 60); pd.sendControlChange(midiChan, 0, 64); pd.sendProgramChange(midiChan, 100); // note: pgm num range is 1 - 128 pd.sendPitchBend(midiChan, 2000); // note: ofxPd uses -8192 - 8192 while [bendin] returns 0 - 16383, // so sending a val of 2000 gives 10192 in pd pd.sendAftertouch(midiChan, 100); pd.sendPolyAftertouch(midiChan, 64, 100); pd.sendMidiByte(0, 239); // note: pd adds +2 to the port number from [midiin], [sysexin], & [realtimein] pd.sendSysex(0, 239); // so sending to port 0 gives port 2 in pd pd.sendSysRealTime(0, 239); // stream pd << NoteOn(midiChan, 60) << ControlChange(midiChan, 100, 64) << ProgramChange(midiChan, 100) << PitchBend(midiChan, 2000) << Aftertouch(midiChan, 100) << PolyAftertouch(midiChan, 64, 100) << StartMidi(0) << 239 << Finish() << StartSysex(0) << 239 << Finish() << StartSysRealTime(0) << 239 << Finish(); cout << "FINISH MIDI Test" << endl; cout << endl << "BEGIN Array Test" << endl; // array check length cout << "array1 len: " << pd.arraySize("array1") << endl; // read array std::vector<float> array1; pd.readArray("array1", array1); // sets array to correct size cout << "array1 "; for(int i = 0; i < array1.size(); ++i) cout << array1[i] << " "; cout << endl; // write array for(int i = 0; i < array1.size(); ++i) array1[i] = i; pd.writeArray("array1", array1); // ready array pd.readArray("array1", array1); cout << "array1 "; for(int i = 0; i < array1.size(); ++i) cout << array1[i] << " "; cout << endl; // clear array pd.clearArray("array1", 10); // ready array pd.readArray("array1", array1); cout << "array1 "; for(int i = 0; i < array1.size(); ++i) cout << array1[i] << " "; cout << endl; cout << "FINISH Array Test" << endl; cout << endl << "BEGIN PD Test" << endl; pd.sendSymbol("fromOF", "test"); cout << "FINISH PD Test" << endl << endl; cout << endl << "BEGIN Event Polling Test" << endl; // clear receivers, enable polling pd.clearReceivers(); pd.clearMidiReceivers(); pd.sendSymbol("fromOF", "test"); processEvents(); // <-- manually poll for events // re-add receivers, disable polling pd.addReceiver(*this); pd.addMidiReceiver(*this); pd.ignore(*this, "env"); cout << "FINISH Event Polling Test" << endl << endl; // play a tone by sending a list // [list tone pitch 72 ( pd.startMessage(); pd.addSymbol("pitch"); pd.addFloat(72); pd.finishList("tone"); pd.sendBang("tone"); }
//-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetVerticalSync(true); //ofSetLogLevel("Pd", OF_LOG_VERBOSE); // see verbose info inside // the number of libpd ticks per buffer, // used to compute the audio buffer len: tpb * blocksize (always 64) #ifdef TARGET_LINUX_ARM // longer latency for Raspberry PI int ticksPerBuffer = 32; // 32 * 64 = buffer len of 2048 int numInputs = 0; // no built in mic #else int ticksPerBuffer = 8; // 8 * 64 = buffer len of 512 int numInputs = 1; #endif int numOutputs = 2; // setup OF sound stream ofSoundStreamSetup(numOutputs, numInputs, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 4); // allocate pd instance handles instanceMutex.lock(); pdinstance1 = pdinstance_new(); pdinstance2 = pdinstance_new(); instanceMutex.unlock(); // set a "current" instance before pd.init() or else Pd will make // an unnecessary third "default" instance instanceMutex.lock(); pd_setinstance(pdinstance1); instanceMutex.unlock(); // setup Pd // // set 4th arg to true for queued message passing using an internal ringbuffer, // this is useful if you need to control where and when the message callbacks // happen (ie. within a GUI thread) // // note: you won't see any message prints until update() is called since // the queued messages are processed there, this is normal // // ... here we'd sure like to be able to have number of channels be // per-instance. The sample rate is still global within Pd but we might // also consider relaxing that restrction. // if(!pd.init(numOutputs, numInputs, 44100, ticksPerBuffer, false)) { ofExit(1); } pd.setReceiver(this); // allocate instance output buffers outputBufferSize = numOutputs*ticksPerBuffer*ofxPd::blockSize(); outputBuffer1 = new float[outputBufferSize]; outputBuffer2 = new float[outputBufferSize]; memset(outputBuffer1, 0, outputBufferSize); memset(outputBuffer2, 0, outputBufferSize); instanceMutex.lock(); pd_setinstance(pdinstance1); // talk to first pd instance instanceMutex.unlock(); // audio processing on pd.start(); // open patch pd.openPatch("test.pd"); instanceMutex.lock(); pd_setinstance(pdinstance2); // talk to the second pd instance instanceMutex.unlock(); // audio processing on pd.start(); // open patch pd.openPatch("test.pd"); // The following two messages can be sent without setting the pd instance // and anyhow the symbols are global so they may affect multiple instances. // However, if the messages change anything in the pd instance structure // (DSP state; current time; list of all canvases n our instance) those // changes will apply to the current Pd nstance, so the earlier messages, // for instance, were sensitive to which was the current one. // // Note also that I'm using the fact that $0 is set to 1003, 1004, ... // as patches are opened, it would be better to open the patches with // settable $1, etc parameters to openPatch(). // [; pd frequency 220 ( pd << StartMessage() << 440.0f << FinishMessage("1003-frequency", "float"); // [; pd frequency 440 ( pd << StartMessage() << 880.0f << FinishMessage("1004-frequency", "float"); }
void ErrorHandler::operator() (const char* msg) { if (StartMessage()) { Add(msg); EndMessage(); } }
//-------------------------------------------------------------- void ofApp::setup() { ofSetFrameRate(60); ofSetVerticalSync(true); //ofSetLogLevel("Pd", OF_LOG_VERBOSE); // see verbose info inside // double check where we are ... cout << ofFilePath::getCurrentWorkingDirectory() << endl; // the number of libpd ticks per buffer, // used to compute the audio buffer len: tpb * blocksize (always 64) #ifdef TARGET_LINUX_ARM // longer latency for Raspberry PI int ticksPerBuffer = 32; // 32 * 64 = buffer len of 2048 int numInputs = 0; // no built in mic #else int ticksPerBuffer = 8; // 8 * 64 = buffer len of 512 int numInputs = 1; #endif // setup OF sound stream ofSoundStreamSetup(2, numInputs, this, 44100, ofxPd::blockSize()*ticksPerBuffer, 3); // setup Pd // // set 4th arg to true for queued message passing using an internal ringbuffer, // this is useful if you need to control where and when the message callbacks // happen (ie. within a GUI thread) // // note: you won't see any message prints until update() is called since // the queued messages are processed there, this is normal // if(!pd.init(2, numInputs, 44100, ticksPerBuffer, false)) { OF_EXIT_APP(1); } midiChan = 1; // midi channels are 1-16 // subscribe to receive source names pd.subscribe("toOF"); pd.subscribe("env"); // add message receiver, required if you want to recieve messages pd.addReceiver(*this); // automatically receives from all subscribed sources pd.ignoreSource(*this, "env"); // don't receive from "env" //pd.ignoreSource(*this); // ignore all sources //pd.receiveSource(*this, "toOF"); // receive only from "toOF" // add midi receiver, required if you want to recieve midi messages pd.addMidiReceiver(*this); // automatically receives from all channels //pd.ignoreMidiChannel(*this, 1); // ignore midi channel 1 //pd.ignoreMidiChannel(*this); // ignore all channels //pd.receiveMidiChannel(*this, 1); // receive only from channel 1 // add the data/pd folder to the search path pd.addToSearchPath("pd/abs"); // audio processing on pd.start(); // ----------------------------------------------------- cout << endl << "BEGIN Patch Test" << endl; // open patch Patch patch = pd.openPatch("pd/test.pd"); cout << patch << endl; // close patch pd.closePatch(patch); cout << patch << endl; // open patch again patch = pd.openPatch(patch); cout << patch << endl; cout << "FINISH Patch Test" << endl; // ----------------------------------------------------- cout << endl << "BEGIN Message Test" << endl; // test basic atoms pd.sendBang("fromOF"); pd.sendFloat("fromOF", 100); pd.sendSymbol("fromOF", "test string"); // stream interface pd << Bang("fromOF") << Float("fromOF", 100) << Symbol("fromOF", "test string"); // send a list pd.startMessage(); pd.addFloat(1.23); pd.addSymbol("a symbol"); pd.finishList("fromOF"); // send a message to the $0 receiver ie $0-fromOF pd.startMessage(); pd.addFloat(1.23); pd.addSymbol("a symbol"); pd.finishList(patch.dollarZeroStr()+"-fromOF"); // send a list using the List object List testList; testList.addFloat(1.23); testList.addSymbol("sent from a List object"); pd.sendList("fromOF", testList); pd.sendMessage("fromOF", "msg", testList); // stream interface for list pd << StartMessage() << 1.23 << "sent from a streamed list" << FinishList("fromOF"); cout << "FINISH Message Test" << endl; // ----------------------------------------------------- cout << endl << "BEGIN MIDI Test" << endl; // send functions pd.sendNoteOn(midiChan, 60); pd.sendControlChange(midiChan, 0, 64); pd.sendProgramChange(midiChan, 100); // note: pgm num range is 1 - 128 pd.sendPitchBend(midiChan, 2000); // note: ofxPd uses -8192 - 8192 while [bendin] returns 0 - 16383, // so sending a val of 2000 gives 10192 in pd pd.sendAftertouch(midiChan, 100); pd.sendPolyAftertouch(midiChan, 64, 100); pd.sendMidiByte(0, 239); // note: pd adds +2 to the port number from [midiin], [sysexin], & [realtimein] pd.sendSysex(0, 239); // so sending to port 0 gives port 2 in pd pd.sendSysRealTime(0, 239); // stream pd << NoteOn(midiChan, 60) << ControlChange(midiChan, 100, 64) << ProgramChange(midiChan, 100) << PitchBend(midiChan, 2000) << Aftertouch(midiChan, 100) << PolyAftertouch(midiChan, 64, 100) << StartMidi(0) << 239 << Finish() << StartSysex(0) << 239 << Finish() << StartSysRealTime(0) << 239 << Finish(); cout << "FINISH MIDI Test" << endl; // ----------------------------------------------------- cout << endl << "BEGIN Array Test" << endl; // array check length cout << "array1 len: " << pd.arraySize("array1") << endl; // read array std::vector<float> array1; pd.readArray("array1", array1); // sets array to correct size cout << "array1 "; for(int i = 0; i < array1.size(); ++i) cout << array1[i] << " "; cout << endl; // write array for(int i = 0; i < array1.size(); ++i) array1[i] = i; pd.writeArray("array1", array1); // ready array pd.readArray("array1", array1); cout << "array1 "; for(int i = 0; i < array1.size(); ++i) cout << array1[i] << " "; cout << endl; // clear array pd.clearArray("array1", 10); // ready array pd.readArray("array1", array1); cout << "array1 "; for(int i = 0; i < array1.size(); ++i) cout << array1[i] << " "; cout << endl; cout << "FINISH Array Test" << endl; // ----------------------------------------------------- cout << endl << "BEGIN PD Test" << endl; pd.sendSymbol("fromOF", "test"); cout << "FINISH PD Test" << endl << endl; // ----------------------------------------------------- cout << endl << "BEGIN Instance Test" << endl; // open 10 instances for(int i = 0; i < 10; ++i) { Patch p = pd.openPatch("pd/instance.pd"); instances.push_back(p); } // send a hello bang to each instance individually using the dollarZero // to [r $0-instance] which should print the instance dollarZero unique id // and a unique random number for(int i = 0; i < instances.size(); ++i) { pd.sendBang(instances[i].dollarZeroStr()+"-instance"); } // send a random float between 0 and 100 for(int i = 0; i < instances.size(); ++i) { pd.sendFloat(instances[i].dollarZeroStr()+"-instance", int(ofRandom(0, 100))); } // send a symbol for(int i = 0; i < instances.size(); ++i) { pd.sendSymbol(instances[i].dollarZeroStr()+"-instance", "howdy dude"); } // close all instances for(int i = 0; i < instances.size(); ++i) { pd.closePatch(instances[i]); } instances.clear(); cout << "FINISH Instance Test" << endl; // ----------------------------------------------------- // play a tone by sending a list // [list tone pitch 72 ( pd.startMessage(); pd.addSymbol("pitch"); pd.addFloat(72); pd.finishList("tone"); pd.sendBang("tone"); }
void ErrorHandler::operator() (const char* fmt, int n1, int n2) { if (StartMessage()) { fprintf(stderr, fmt, n1, n2); EndMessage(); } }
void ErrorHandler::operator() (const char* fmt, const char* msg, int n) { if (StartMessage()) { fprintf(stderr, fmt, msg, n); EndMessage(); } }
void ErrorHandler::operator() (const char* msg) { if (StartMessage()) { fputs(msg, stderr); EndMessage(); } }