//---------------------------------------- void initializeQuicktime(){ if (bQuicktimeInitialized == false){ //---------------------------------- // do we have quicktime installed at all? // http://www.apple.com/quicktime/download/win.html // can gestalt help with versions, or is that only after init? OSErr myErr = noErr; #ifdef TARGET_WIN32 myErr = InitializeQTML(0); if (myErr != noErr){ ofLog(OF_LOG_ERROR, "-----------------------------------------------------"); ofLog(OF_LOG_ERROR, "sorry, there is a problem with quicktime starting up... please check!"); OF_EXIT_APP(0); } #endif myErr = EnterMovies (); if (myErr != noErr){ ofLog(OF_LOG_ERROR, "-----------------------------------------------------"); ofLog(OF_LOG_ERROR, "sorry, there is a problem with quicktime starting up... please check!"); OF_EXIT_APP(0); } bQuicktimeInitialized = true; } }
static LRESULT CALLBACK winProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam){ //we catch close and destroy messages //and send them to OF switch(Msg){ case WM_CLOSE: OF_EXIT_APP(0); break; case WM_DESTROY: OF_EXIT_APP(0); break; case WM_DROPFILES: // Call our function we created to display all the files. // We pass the wParam because it's the HDROP handle. HandleFiles(wParam); break; default: return CallWindowProc(currentWndProc, handle, Msg, wParam, lParam); break; } return 0; }
//--------------------------------------------------------------------------- void ParamMap::check_new_var( void *value, string name ) { //проверка, что нет такой переменной for (int i=0; i<vars.size(); i++) { if ( value == vars[i].pointer ) { cout << "ERROR: duplicated var pointer in ParamMap: " << name << endl; OF_EXIT_APP(0); } if ( name == vars[i].name ) { cout << "ERROR: duplicated var name in ParamMap: " << name << endl; OF_EXIT_APP(0); } } }
//-------------------------------------------------------------- void AppCore::setup(const int numOutChannels, const int numInChannels, const int sampleRate, const int ticksPerBuffer) { ofSetFrameRate(60); ofSetVerticalSync(true); // setup pd if(!pd.init(numOutChannels, numInChannels, sampleRate, ticksPerBuffer)) { ofLog(OF_LOG_ERROR, "Could not init pd"); OF_EXIT_APP(1); } pd.subscribe("mix"); pd.subscribe("transpose"); pd.subscribe("inputGain"); pd.subscribe("outputGain"); pd.addToSearchPath("pd"); pd.start(); // open patch Patch patch = pd.openPatch("pd/_main.pd"); cout << patch << endl; // setup GUI int x = -12, width = 100, step = 75; x += step; transposeSlider.setup(x, 34, width, 700, -12, 12, 0, true, true); x += width + step*2; mixSlider.setup(x, 34, width, 700, 0, 1, 1.0, true, true); x += width + step*2; inGainSlider.setup(x, 34, width, 700, 0, 1, 0.5, true, true); x += width + step*2; outGainSlider.setup(x, 34, 100, 700, 0, 1, 0.25, true, true); transposeSlider.setLabelString("Transpose"); mixSlider.setLabelString("Wet/Dry Mix"); inGainSlider.setLabelString("Input Gain"); outGainSlider.setLabelString("Output Gain"); }
//------------------------------------------------------------ void ofxAppNoWindow::runAppViaInfiniteLoop(ofBaseApp * appPtr){ ofSetCurrentRenderer(ofPtr<ofBaseRenderer>(new ofNoopRenderer)); ofAppPtr = appPtr; #if defined TARGET_OSX || defined TARGET_LINUX // for keyboard //set_conio_terminal_mode(); #endif ofNotifySetup(); // ofLogNotice("ofxAppNoWindow") // << "***" << endl // << "***" << endl // << "*** running a headless (no window) app" << endl // << "***" << endl // << "*** keyboard input works here" << endl // << "***"<< endl // << "*** press Esc or Ctrl-C to quit" << endl // << "***" << endl; while (true) { /// listen for escape #ifdef TARGET_WIN32 if (GetAsyncKeyState(VK_ESCAPE)) ofNotifyKeyPressed(OF_KEY_ESC); #endif #if defined TARGET_OSX || defined TARGET_LINUX while ( kbhit() ) { int key = getch(); if ( key == 27 ) { ofNotifyKeyPressed(OF_KEY_ESC); } else if ( key == /* ctrl-c */ 3 ) { ofLogNotice("ofxAppNoWindow") << "Ctrl-C pressed" << endl; OF_EXIT_APP(0); } else { ofNotifyKeyPressed(key); } } #endif ofNotifyUpdate(); ofNotifyDraw(); } }
//------------------------------------------------------------ void ofAppNoWindow::exitApp(){ ofLogVerbose("ofAppNoWindow") << "terminating headless (no window) app!"; #if defined TARGET_OSX || defined TARGET_LINUX // this doesn't exist on windows and gives linking errors, so commented out. reset_terminal_mode(); #endif OF_EXIT_APP(0); }
static LRESULT CALLBACK winProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam){ //we catch close and destroy messages //and send them to OF switch(Msg){ case WM_CLOSE: OF_EXIT_APP(0); break; case WM_DESTROY: OF_EXIT_APP(0); break; default: return CallWindowProc(currentWndProc, handle, Msg, wParam, lParam); break; } return 0; }
// main void pdSound::setup(const int numOutChannels, const int numInChannels, const int sampleRate, const int ticksPerBuffer) { if(!pd.init(numOutChannels, numInChannels, sampleRate, ticksPerBuffer)) { ofLog(OF_LOG_ERROR, "Could not init pd"); OF_EXIT_APP(1); } Patch patch = pd.openPatch("vertexnoize_sound.pd"); pd.dspOn(); }
//-------------------------------------------------------------- void testApp::mousePressed(int x, int y, int button){ if( state == APP_WAITING_LAUNCH ){ splash.checkPress(x, y); } if( state >= APP_RUN_NORMALLY ){ if( x < 50 && y < 50 && ofGetElapsedTimef() < showMouseTillTime ){ OF_EXIT_APP(0); }else{ cam.mousePressed(x, y, button); } } }
//------------------------------------------------------------ void ofxSDLAppWindow::exitApp() { ofLog(OF_LOG_VERBOSE, "SDL OF app is being terminated!"); // clean up SDL for (int j = 0; j < numJoys; j++) { if (joys[j] && SDL_JoystickOpened(j)) { SDL_JoystickClose(joys[j]); joys[j] = NULL; } } SDL_Quit(); OF_EXIT_APP(0); }
void PckReceiver::setup(){ //serial.listDevices(); vector <ofSerialDeviceInfo> deviceList = serial.getDeviceList(); if(deviceList.size() == 0){ ofLog(OF_LOG_FATAL_ERROR) << "PckReceiver: no serial / CDC devices found. application abort...\n"; OF_EXIT_APP(1); } ofLog() << "PckReceiver: list of all available devices"; vector <ofSerialDeviceInfo>::iterator it = deviceList.begin(); while(it != deviceList.end()){ ofSerialDeviceInfo info = *it; ofLog() << info.getDevicePath() << " " << info.getDeviceName() << " " <<info.getDeviceID(); it++; } int baud = 9600; if(!serial.setup("/dev/ttyACM0",baud)){ ofLog(OF_LOG_FATAL_ERROR) << "PckReceiver: could not initialize serial"; OF_EXIT_APP(1); } ofLog() << "PckReceiver: established connection to Peacock Hardware"; clearMatrix(preMatrix); }
void FrameGrabber::grabFrame(){ frameCounter++; if(frameCounter <= maxFrames){ string file = fileName + ofToString(frameCounter, 0) + ".png"; img.grabScreen(0,0,ofGetWidth(), ofGetHeight()); img.saveImage(file); float elapsedTime = ofGetElapsedTimef(); seconds = (int)elapsedTime%60; minutes = (int)(elapsedTime/60); string ellapsed = " elapsed: " + ofToString(minutes, 0) + "min "+ ofToString(seconds, 0) + "sec\n"; std::cout << ofToString(frameCounter, 0) + " of " + ofToString(maxFrames, 0) + " frames " + "at " + ofToString(ofGetFrameRate(),2) + "fps" + ellapsed; } else if(close)OF_EXIT_APP(0); }
//------------------------------------------------------------ void ofAppNoWindow::exitApp() { // -- This already exists in ofExitCallback static ofEventArgs voidEventArgs; #ifdef OF_USING_POCO ofNotifyEvent( ofEvents().exit, voidEventArgs ); #endif ofLog(OF_LOG_VERBOSE,"No Window OF app is being terminated!"); reset_terminal_mode(); OF_EXIT_APP(0); }
//------------------------------------------------------------ void ofAppQtWindow::exitApp(){ // -- This already exists in ofExitCallback // static ofEventArgs voidEventArgs; // // if(ofAppPtr)ofAppPtr->exit(); // // #ifdef OF_USING_POCO // ofNotifyEvent( ofEvents.exit, voidEventArgs ); // #endif ofLog(OF_LOG_VERBOSE,"GLUT OF app is being terminated!"); OF_EXIT_APP(0); }
//-------------------------------------------------------------- void testApp::setup() { bSetup = false; string video_dir = ofToDataPath("video"); dirList.open(video_dir.c_str()); numFiles = dirList.listDir(); videoFiles = dirList.getFiles(); if(numFiles == 0) { printf("[ERROR] No files found in %s\n", video_dir); OF_EXIT_APP(0); } else { printf("[OK] Read %d files\n", numFiles); for (int i = 0; i < numFiles; i++) { printf("%d.) %s\n", i+1, videoFiles[i].getAbsolutePath().c_str()); } } currentFile = 0; videoReader = new ofVideoPlayer(); videoReader->loadMovie(videoFiles[currentFile].getAbsolutePath()); totalFrames = videoReader->getTotalNumFrames(); currentFrame = 0; allVideoFrames = 0; imageScalar = 2; cvColorImg.allocate(videoReader->getWidth(), videoReader->getHeight()); cvGrayImg.allocate(videoReader->getWidth(), videoReader->getHeight()); cvGrayImgResized.allocate(videoReader->getWidth()/imageScalar, videoReader->getHeight()/imageScalar); detector = FeatureDetector::create("DynamicSURF"); extractor = DescriptorExtractor::create("SURF"); maxKeypointsPerFrame = 16; keypointDimension = extractor->descriptorSize(); numFeatures = maxKeypointsPerFrame * keypointDimension; numFrames = totalFrames; totalKeypoints = 0; dataset.create(numFrames, numFeatures, CV_32FC1); ofSetVerticalSync(false); ofSetWindowShape(760, 520); ofSetFrameRate(1000); }
void kinactorApp::exit() { kinect.setCameraTiltAngle(0); // zero the tilt on exit kinect.close(); // ON EXIT SAVE GUI and DELETE guileft->saveSettings("GUI/guileftSettings.xml"); delete guileft; guiright->saveSettings("GUI/guirightSettings.xml"); delete guiright; guilogger->saveSettings("GUI/guiloggerSettings.xml"); delete guilogger; #ifdef DEBUG std::cerr << "END OF EXIT ROUTINE ...." << std::endl; #endif OF_EXIT_APP(0); }
//-------------------------------------------------------------- void AppCore::setup(const int numOutChannels, const int numInChannels, const int sampleRate, const int ticksPerBuffer) { ofSetFrameRate(60); ofSetVerticalSync(true); // 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); } pd.start(); // open patch Patch patch = pd.openPatch("pd/pd.pd"); cout << patch << endl; }
//------------------------------------------------------------ void ofxAppNoWindow::exitApp(){ // -- This already exists in ofExitCallback // static ofEventArgs voidEventArgs; // // if(ofAppPtr)ofAppPtr->exit(); // // #ifdef OF_USING_POCO // ofNotifyEvent( ofEvents.exit, voidEventArgs ); // #endif ofLogVerbose("ofxAppNoWindow") << "terminating headless (no window) app!"; #if defined TARGET_OSX || defined TARGET_LINUX // this doesn't exist on windows and gives linking errors, so commented out. reset_terminal_mode(); #endif OF_EXIT_APP(0); }
//-------------------------------------------------------------- void AppCore::setup(const int numOutChannels, const int numInChannels, const int sampleRate, const int ticksPerBuffer) { ofSetFrameRate(30); ofSetVerticalSync(true); //ofSetLogLevel(OF_LOG_VERBOSE); // double check where we are ... cout << ofFilePath::getCurrentWorkingDirectory() << endl; //----------------------------------- PD START------------------------------------------- if(!pd.init(numOutChannels, numInChannels, sampleRate, ticksPerBuffer)) { OF_EXIT_APP(1); } Externals::setup(); midiChan = 1; // midi channels are 1-16 // subscribe to receive source names pd.subscribe("toOf"); pd.subscribe("env"); pd.addReceiver(*this); // automatically receives from all subscribed sources pd.ignore(*this, "env"); // don't receive from "env" pd.addMidiReceiver(*this); // automatically receives from all channels pd.addToSearchPath("pd/abs"); pd.start(); //Patch patch = pd.openPatch("pd/somename.pd"); //cout << patch << endl; //----------------------------------- PD END------------------------------------------- //----------------------------------- KINECT START ------------------------------------------- kinect.listDevices(); kinect.init(); kinect.open("A00365917784047A"); kinect.setCameraTiltAngle(0); grayImage.allocate(kinect.width, kinect.height); kinect1.init(); kinect1.open("A00364A11700045A"); kinect1.setCameraTiltAngle(0); grayImage1.allocate(kinect1.width, kinect1.height); bothKinects.allocate(kinect.height*2, kinect.width); combinedVideo = (unsigned char*)malloc(640 * 480 * 2 * sizeof(unsigned char*)); blobs.resize(100); blobCenterX.resize(100); blobCenterXmap.resize(100); blobCenterY.resize(100); blobCenterYmap.resize(100); //----------------------------------- KINECT END ------------------------------------------- // Setup OSC Sender sender.setup(HOST, PORT); allPipes = new ofPipe*[TUBE_NUM]; // an array of pointers for the objects persons = new ofPerson*[PERSON_NUM]; //the string is printed at the top of the app //to give the user some feedback message = "loading data.xml"; //we load our data file if( XML.loadFile("data.xml") ){ message = "data.xml loaded!"; }else{ message = "unable to load data.xml check data/ folder"; } XML.pushTag("document"); newXML.addTag("document"); newXML.pushTag("document"); for(int i=0; i<TUBE_NUM; i++){ XML.pushTag("tube",i); float x = XML.getValue("y",0.0); float y = XML.getValue("x",0.0); // rotate float angle = ofDegToRad(-20); float rX = (x*cos(angle) - y*sin(angle)); float rY = (x*sin(angle) + y*cos(angle)); // map to the of window size float mult = 6; x = (rX * mult + ofGetWidth() / 2) - 50; y = rY * mult + ofGetHeight() / 2; float radius = XML.getValue("diameter",0.0 ) / 1.8; float length = XML.getValue("length",0.0 ); float height= XML.getValue("height",0.0); float frequency = 342 / ((length*2)/100); int idNum = XML.getValue("num",0); int element = XML.getValue("element",0 ); int open = XML.getValue("oc",0 ); allPipes[i] = new ofPipe(x,y,radius,length,height,frequency, idNum, element, open); newXML.addTag("tube"); newXML.pushTag("tube", i); newXML.addValue("num", idNum); newXML.addValue("length", length); newXML.addValue("height", height); newXML.addValue("diameter", radius); newXML.addValue("x", ofMap(x, 0, ofGetWidth(), 0, 1)); newXML.addValue("y", ofMap(y, 0, ofGetHeight(), 0, 1)); newXML.addValue("element", element); newXML.addValue("oc", open); XML.popTag(); newXML.popTag(); } newXML.saveFile("newXML.xml"); // load the PD patches and create the people for(int i = 0; i<PERSON_NUM; i++){ //patches[i] = pd.openPatch("pd/main.pd"); persons[i] = new ofPerson(0.0,0.0,0.0, i); } // load a separate patch for the mouse //mousePatch = pd.openPatch("pd/main.pd"); mPerson = new ofPerson(0.0,0.0,0.0,0); outputState=false; }
//------------------------------------------------------------ void ofAppNoWindow::runAppViaInfiniteLoop(ofBaseApp * appPtr) { static ofEventArgs voidEventArgs; ofAppPtr = appPtr; if(ofAppPtr) { ofAppPtr->setup(); ofAppPtr->update(); } #if defined TARGET_OSX || defined TARGET_LINUX // for keyboard set_conio_terminal_mode(); #endif #ifdef OF_USING_POCO ofNotifyEvent( ofEvents().setup, voidEventArgs ); ofNotifyEvent( ofEvents().update, voidEventArgs ); #endif ofLogNotice()<< "***\n***\n*** ofAppNoWindow running a headerless openFrameworks app\n" "***\n*** keyboard input works here\n" "***\n*** press Esc or Ctrl-C to quit\n" "***\n"; // Register signal handler to handle kill signal signalHandler.setupSignalHandlers(); while (true) { if (nFrameCount != 0 && bFrameRateSet == true) { diffMillis = ofGetElapsedTimeMillis() - prevMillis; if (diffMillis > millisForFrame) { ; // we do nothing, we are already slower than target frame } else { int waitMillis = millisForFrame - diffMillis; #ifdef TARGET_WIN32 Sleep(waitMillis); //windows sleep in milliseconds #else usleep(waitMillis * 1000); //mac sleep in microseconds - cooler :) #endif } } prevMillis = ofGetElapsedTimeMillis(); // you have to measure here /// listen for escape #ifdef TARGET_WIN32 if (GetAsyncKeyState(VK_ESCAPE)) OF_EXIT_APP(0); #endif #if defined TARGET_OSX || defined TARGET_LINUX while ( kbhit() ) { int key = getch(); if ( key == 27 ) { if(ofAppPtr) { ofAppPtr->exit(); } exitApp(); } if (key == 'q' || key == 'Q') { if(ofAppPtr) { ofAppPtr->exit(); } exitApp(); } else if ( key == /* ctrl-c */ 3 ) { if(ofAppPtr) { ofAppPtr->exit(); } ofLogNotice()<< "Ctrl-C pressed\n"; exitApp(); } else { ofAppPtr->keyPressed( key ); } } #endif /// update if (ofAppPtr) ofAppPtr->update(); #ifdef OF_USING_POCO ofNotifyEvent( ofEvents().update, voidEventArgs); #endif // Check for exit signal if (signalHandler.gotExitSignal()) { if(ofAppPtr) { ofAppPtr->exit(); } exitApp(); } // -------------- fps calculation: timeNow = ofGetElapsedTimef(); double diff = timeNow-timeThen; if( diff > 0.00001 ) { fps = 1.0 / diff; frameRate *= 0.9f; frameRate += 0.1f*fps; } lastFrameTime = diff; timeThen = timeNow; // -------------- nFrameCount++; // increase the overall frame count } }
//------------------------------------------------------------ void ofAppGlutWindow::exitApp(){ ofLog(OF_LOG_VERBOSE,"GLUT OF app is being terminated!"); OF_EXIT_APP(0); }
//-------------------------------------------------------------- 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 testApp::closeApp() { // deallocate OF_EXIT_APP(0); }
//-------------------------------------------------------------- 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 testApp::update(){ /* sigma = 2.0 * kernelSize * sinf(ofGetElapsedTimef() / 12.0) / 5.0; theta = 180.0 * cosf(ofGetElapsedTimef() / 6.0); freq = sinf(ofGetElapsedTimef() / 2.0); */ if (!bFirstTrial && ofGetElapsedTimeMillis() >= MS_PER_STIMULI) { ofResetElapsedTimeCounter(); bNoiseState = !bNoiseState; if (bNoiseState) { currentLut++; if (currentLut == 512) { currentLut = 0; currentTrial++; if (currentTrial == 10) { cout << "[OK] Finished!" << endl; outfile.close(); OF_EXIT_APP(0); } outfile.close(); string filename = getNextFilename("eeg-record-trial-" + ofToString(currentTrial), "txt"); outfile.open( ofToDataPath(filename).c_str() ); } } } if (bNoiseState) { } else { sigma = kernelSize * sigmas[lut[currentLut][0]]; theta = thetas[lut[currentLut][1]]; freq = freqs[lut[currentLut][2]]; atom.update(sigma, theta, freq); } string delimiter = ","; #ifdef USE_OSC while (oscReceiver.hasWaitingMessages()) { ofxOscMessage m; if(oscReceiver.getNextMessage(&m)) { if (m.getAddress() == "/eeg") { #endif outfile << ofGetTimestampString() << delimiter << bNoiseState << delimiter << currentTrial << delimiter << currentLut << delimiter << sigma << delimiter << theta << delimiter << freq; #ifdef USE_OSC for (int ch = 0; ch < 22; ch++) { outfile << delimiter << m.getArgAsFloat(ch); } #endif outfile << delimiter; outfile << endl; #ifdef USE_OSC } } } #endif }
void exitApp(){ ofLogVerbose("ofEvents") << "OF app is being terminated!"; OF_EXIT_APP(0); }
void exitApp(){ ofLog(OF_LOG_VERBOSE,"OF app is being terminated!"); OF_EXIT_APP(0); }
//-------------------------------------------------------------- void AppCore::setup(const int numOutChannels, const int numInChannels, const int sampleRate, const int ticksPerBuffer) { ofSetFrameRate(60); ofSetVerticalSync(true); //ofSetLogLevel(OF_LOG_VERBOSE); cout << Poco::Path::current() << endl; if(!pd.init(numOutChannels, numInChannels, sampleRate, ticksPerBuffer)) { ofLog(OF_LOG_ERROR, "Could not init pd"); OF_EXIT_APP(1); } // add recieve source names pd.addSource("toOF"); pd.addSource("env"); pd.addSource("one"); // add listener pd.addListener(*this); pd.subscribe(*this); // listen to everything pd.unsubscribe(*this, "env"); // don't listen to "env" //pd.subscribe(*this, "toOF"); // listen to "toOF" //pd.unsubscribe(*this); // don't listen to anything // add the data/pd folder to the search path pd.addToSearchPath("pd"); // audio processing on pd.dspOn(); cout << endl << "BEGIN Patch Test" << endl; // open patch Patch patch = pd.openPatch("droid2.pd"); cout << patch << endl; /* // close patch pd.closePatch(patch); cout << patch << endl; // open patch patch = pd.openPatch("mintest2.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"); // send a list pd.startList("fromOF"); pd.addFloat(1.23); pd.addSymbol("a symbol"); pd.finish(); // send a message to the $0 reciever ie $0-toOF pd.startList(patch.dollarZeroStr()+"-fromOF"); pd.addFloat(1.23); pd.addSymbol("a symbol"); pd.finish(); cout << "FINISH Message Test" << endl; cout << endl << "BEGIN MIDI Test" << endl; // send functions pd.sendNote(60); pd.sendCtl(100, 64); pd.sendPgm(100); pd.sendBend(2000); pd.sendTouch(100); pd.sendPolyTouch(64, 100); pd.sendMidiByte(239, 1); pd.sendSysExByte(239, 1); pd.sendSysRTByte(239, 1); // stream pd << Note(60) << Ctl(100, 64) << Bend(2000) << Touch(100) << PolyTouch(64, 100) << StartMidi(1) << 239 << Finish() << StartSysEx(1) << 239 << Finish() << StartSysRT(1) << 239 << Finish(); cout << "FINISH MIDI Test" << endl; cout << endl << "BEGIN Array Test" << endl; // array check length cout << "array1 len: " << pd.getArrayLen("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; // play a tone by sending a list // [list tone pitch 72 ( pd.startList("tone"); pd.addSymbol("pitch"); pd.addFloat(72); pd.finish(); pd.sendBang("tone"); */ }
//-------------------------------------------- int ofAppGLFWWindow::exit_cb(){ OF_EXIT_APP(0); return 0; }
void ofAppGLFWWindow::display(void){ static ofEventArgs voidEventArgs; int width, height; width = getWindowSize().x; height = getWindowSize().y; height = height > 0 ? height : 1; // set viewport, clear the screen glViewport( 0, 0, width, height ); float * bgPtr = ofBgColorPtr(); bool bClearAuto = ofbClearBg(); // I don't know why, I need more than one frame at the start in fullscreen mode // also, in non-fullscreen mode, windows/intel graphics, this bClearAuto just fails. // I seem to have 2 buffers, alot of flickering // and don't accumulate the way I expect. // with this line: if ((bClearAuto == true) || nFrameCount < 3){ // we do nFrameCount < 3, so that the buffers are cleared at the start of the app // or else we have video memory garbage to draw on to... //glDrawBuffer( GL_BACK ); printf("nFrameCount %i \n", nFrameCount); glDrawBuffer( GL_FRONT_AND_BACK ); // glDrawBuffer( GL_FRONT ); #ifdef TARGET_WIN32 //windows doesn't get accumulation in window mode if ((bClearAuto == true || windowMode == OF_WINDOW) || nFrameCount < 3){ #else //mac and linux does :) if ( bClearAuto == true || nFrameCount < 3){ #endif glClearColor(bgPtr[0],bgPtr[1],bgPtr[2], bgPtr[3]); // printf("clearing the screen \n"); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } if( bEnableSetupScreen )ofSetupScreen(); if(ofAppPtr) ofAppPtr->draw(); #ifdef OF_USING_POCO ofNotifyEvent( ofEvents().draw, voidEventArgs ); #endif // Swap front and back buffers (we use a double buffered display) glfwSwapBuffers(); } //------------------------------------------------------------ void ofAppGLFWWindow::exitApp(){ // -- This is already happening in ofAppRunner // static ofEventArgs voidEventArgs; // if(ofAppPtr)ofAppPtr->exit(); // // #ifdef OF_USING_POCO // ofNotifyEvent( ofEvents().exit, voidEventArgs ); // #endif ofLog(OF_LOG_VERBOSE,"GLFW app is being terminated!"); // Terminate GLFW glfwTerminate(); OF_EXIT_APP(0); }