diff options
Diffstat (limited to 'gui/src/ofApp.cpp')
| -rw-r--r-- | gui/src/ofApp.cpp | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/gui/src/ofApp.cpp b/gui/src/ofApp.cpp index 7641664..2b7a9e1 100644 --- a/gui/src/ofApp.cpp +++ b/gui/src/ofApp.cpp @@ -5,13 +5,14 @@ const ofPoint outputWindowSize=ofPoint(1200,900); const float guiScale=560.0f/4096.0f; -string sourcenames[5]={ +string sourcenames[6 ]={ "TEST", // "NDI", "Player", "SVG outlines", "SVG segmenters", - "Audio" + "Audio", + "OSC" }; //-------------------------------------------------------------- @@ -176,6 +177,10 @@ void ofApp::setup(){ outputScale=XML.getValue("SCALE", 1.0f); + cout << "listening for osc messages on port " << PORT << "\n"; + receiver.setup(PORT); + + ofSetFrameRate(60); } //====================== audio functions @@ -667,6 +672,22 @@ void ofApp::drawOutput(ofEventArgs & args){ scale_amt=(((sin(scale_phase)*0.5)+0.5)*(xf_scale_max-xf_scale_min))+xf_scale_min; + int received_frames=0; + int numpoints=0; + ofBuffer buf; + + while(receiver.hasWaitingMessages()){ + ofxOscMessage m; + receiver.getNextMessage(m); + if(m.getAddress() == "/points"){ + numpoints=m.getArgAsInt(0); + buf=m.getArgAsBlob(1); + received_frames++; + } + } + + string stats_message; + switch (source){ case TEST:{ ofMatrix4x4 m = ofMatrix4x4::newIdentityMatrix(); @@ -814,6 +835,42 @@ void ofApp::drawOutput(ofEventArgs & args){ polyOutput=plotter.output(scalePlot,decayPlot); break; } + case OSC:{ + + if (numpoints){ + + char* data=buf.getData(); + float* floats=(float*) data; + uint32_t* ints=(uint32_t*)(floats); + oscpoly.clear(); + colourPolyline poly; + ofColor lastcol; + for (int i=0;i<numpoints;i++){ + uint8_t* pixel=(uint8_t*)(&ints[i*4+3]); + uint32_t alpha=(uint32_t)pixel[3]; + ofColor col=alpha?ofColor((pixel[2]*alpha)>>8,(pixel[1]*alpha)>>8,(pixel[0]*alpha)>>8):lastcol; + lastcol=col; + + poly.addVertex( + floats[i*4]*ofGetWidth(), + floats[i*4+1]*ofGetHeight(), + col); + if (!alpha&&poly.size()){ + poly.addVertex( + floats[i*4]*ofGetWidth(), + floats[i*4+1]*ofGetHeight(), + ofColor(0,0,0)); + oscpoly.push_back(poly); + poly.clear(); + } + } + std::cout<<"created "<<oscpoly.size()<<" polygons"<<std::endl; + + stats_message=ofToString(received_frames)+": "+ofToString(oscpoly.size()); //+" dumped: "+ofToString(dumped_frames); + } + polyOutput=oscpoly; + break; + } default: { break; } @@ -959,10 +1016,12 @@ void ofApp::keyPressed(ofKeyEventArgs &args){ if (source<0){ source=Source_end-1; } + std::cout << sourcenames[source] << std::endl; break; } case 'p':{ source=(source+1)%Source_end; + std::cout << sourcenames[source] << std::endl; break; } case 'w':{ |
