diff options
Diffstat (limited to 'gui/src/ofApp.cpp')
| -rw-r--r-- | gui/src/ofApp.cpp | 304 |
1 files changed, 264 insertions, 40 deletions
diff --git a/gui/src/ofApp.cpp b/gui/src/ofApp.cpp index 14e669d..e684254 100644 --- a/gui/src/ofApp.cpp +++ b/gui/src/ofApp.cpp @@ -5,13 +5,20 @@ const ofPoint outputWindowSize=ofPoint(1200,900); const float guiScale=560.0f/4096.0f; +string sourcenames[5]={ + "TEST", +// "NDI", + "Player", + "SVG outlines", + "SVG segmenters", + "Audio" +}; + //-------------------------------------------------------------- void ofApp::setup(){ - gui.setup(); - - source=SVG_outlines; - + source=Audio; +/* //==================================================== ofxNDI senderName[0] = 0; // The sender name used for display @@ -26,33 +33,74 @@ void ofApp::setup(){ // For received frame fps calculations - independent of the rendering rate startTime = lastTime = frameTime = 0; fps = frameRate = 1; // starting value - - //============================ GUI - - gui.add(contour_threshold.setup("threshold", 140, 0, 255)); - gui.add(contour_simplify.setup("simplify", 0.8, 0.0, 1.0)); - gui.add(contour_useColour.setup("use colour", true)); - gui.add(laser_R.setup("red", 140, 0, 255)); - gui.add(laser_G.setup("green", 140, 0, 255)); - gui.add(laser_B.setup("blue", 140, 0, 255)); - gui.add(laser_intensity.setup("intensity", 30, 0, 255)); - gui.add(laser_points.setup("points", 20000, 0, 40000)); - gui.add(video_speed.setup("playback speed", 1.0, 0.0, 3.0)); - gui.add(shapes_randomise.setup("randomise shapes", true)); - gui.add(shapes_amount.setup("shapes amount", 0.2, 0.0, 0.8)); - gui.add(shapes_duration.setup("shape duration", 5, 0, 25)); - gui.add(use_mask.setup("use mask", true)); - gui.add(invert_mask.setup("invert mask", false)); - gui.add(use_segmenter.setup("use segmenter", false)); - gui.add(segmenter_speed.setup("segmenter speed", 0.2, -1.0, 1.0)); - gui.add(segmenter_length.setup("segmenter length", 0.2, 0.0, 1.0)); - gui.add(segmenter_number.setup("segmenter number", 1, 1, 8)); - gui.add(use_rotate.setup("XF rotate", false)); - gui.add(xf_rotate.setup("rotate speed", 0.0, -1.0, 1.0)); - gui.add(use_scale.setup("XF scale", false)); - gui.add(xf_scale_speed.setup("scale speed", 1.0, 0.0, 10.0)); - gui.add(xf_scale_min.setup("scale min", 1.0, 0.0, 3.0)); - gui.add(xf_scale_max.setup("scale max", 2.0, 0.0, 3.0)); +*/ + + //============================= Audio + + plotter.setup(5,true); + + bufferSize = 2048; + sampleRate = 44100; + + gist.setUseForOnsetDetection(GIST_PEAK_ENERGY); + gist.setThreshold(GIST_PEAK_ENERGY, .05);// + + ofAddListener(GistEvent::ON,this,&ofApp::onNoteOn); + ofAddListener(GistEvent::OFF,this,&ofApp::onNoteOff); + + // ofAddListener(ofApp::useMic->Value,this,&ofApp::useMicChanged); + + soundStream.setup(this,0, 1, sampleRate, bufferSize, 1); + + //loadSong("12 Ferric Appetite.aiff"); + loadSong("passades/1 The Ninth Set-sector1:sector2pt.1.aiff"); + + //============================ gui + + lasergui.setup("laser"); + lasergui.add(laser_power.set("power", false)); + lasergui.add(laser_intensity.set("intensity", 30, 0, 255)); + lasergui.add(laser_points.set("points", 30000, 0, 40000)); + lasergui.add(laser_subdivide.set("subdivide", 15, 1, 100)); + lasergui.add(laser_blank_num.set("blank points", 8, 0, 32)); + lasergui.add(laser_max_angle.set("max angle", 15.0f, 1.0f, 90.0f)); + + drawgui.setup("drawing","",10,150); + drawgui.add(contour_threshold.setup("threshold", 140, 0, 255)); + drawgui.add(contour_simplify.setup("simplify", 0.8, 0.0, 1.0)); + drawgui.add(contour_useColour.setup("use colour", true)); + drawgui.add(laser_R.setup("red", 140, 0, 255)); + drawgui.add(laser_G.setup("green", 140, 0, 255)); + drawgui.add(laser_B.setup("blue", 140, 0, 255)); + drawgui.add(video_speed.setup("playback speed", 1.0, 0.0, 3.0)); + drawgui.add(shapes_randomise.setup("randomise shapes", true)); + drawgui.add(shapes_amount.setup("shapes amount", 0.2, 0.0, 0.8)); + drawgui.add(shapes_duration.setup("shape duration", 5, 0, 25)); + drawgui.add(use_mask.setup("use mask", true)); + drawgui.add(invert_mask.setup("invert mask", false)); + drawgui.add(use_segmenter.setup("use segmenter", false)); + drawgui.add(segmenter_speed.setup("segmenter speed", 0.2, -1.0, 1.0)); + drawgui.add(segmenter_length.setup("segmenter length", 0.2, 0.0, 1.0)); + drawgui.add(segmenter_number.setup("segmenter number", 1, 1, 8)); + drawgui.add(use_rotate.setup("XF rotate", false)); + drawgui.add(xf_rotate.setup("rotate speed", 0.0, -1.0, 1.0)); + drawgui.add(use_scale.setup("XF scale", false)); + drawgui.add(xf_scale_speed.setup("scale speed", 1.0, 0.0, 10.0)); + drawgui.add(xf_scale_min.setup("scale min", 1.0, 0.0, 3.0)); + drawgui.add(xf_scale_max.setup("scale max", 2.0, 0.0, 3.0)); + + audiogui.setup("audio","",10,600); + audiogui.add(useMic.set("mic",true)); + audiogui.add(useFft.set("fft",false)); + audiogui.add(scalePlot.set("scale plot", 0.1f, 0.0f, 1.0f )); + audiogui.add(decayPlot.set("decay", 0.9f, 0.0f, 1.0f )); + audiogui.add(plotter.joined.set("joined",true)); + audiogui.add(plotter.bars.set("bars",true)); + audiogui.add(plotter.width.set("point width", 2, 1, 256)); + audiogui.add(plotter.num_points.set("num points", 50, 1, 512)); + audiogui.add(plotter.history_size.set("num plots", 5, 1, 100)); + audiogui.add(plotter.startColour.set("start",ofColor(255,255,255))); + audiogui.add(plotter.endColour.set("end",ofColor(0,0,0))); framecounter=0; @@ -110,6 +158,109 @@ void ofApp::setup(){ } +//====================== audio functions + +void ofApp::loadSong(string str){ + + cout<<"loadSong "<<str<<endl; + + player.stop(); + player.loadSound(str); + player.setLoop(true); + player.play(); + useMic = 0; + gist.clearHistory(); +} + +void ofApp::onNoteOn(GistEvent &e){ + + //noteOnRadius = 100; +}; + + +void ofApp::onNoteOff(GistEvent &e){ + + //noteOnRadius = 0; +}; + +void ofApp::processAudio(float * input, int bufferSize, int nChannels){ + //convert float array to vector + + + left.resize(bufferSize/nChannels); + right.resize(bufferSize/nChannels); + centre.resize(bufferSize/nChannels); + + float max=0.0f; + + + if (nChannels==2){ + + + for (int i = 0; i < bufferSize/nChannels; i++){ + left[i] = input[i*nChannels]; + right[i] = input[i*nChannels+1]; + centre[i] = (left[i]+right[i])*0.5; + if (centre[i]>max){ + max=centre[i]; + } + } + + + } + else if (nChannels==1){ + for (int i = 0; i < bufferSize;i++){ + left[i] = input[i]; + right[i] = input[i]; + centre[i] = input[i]; + if (centre[i]>max){ + max=centre[i]; + } + } + } + + //ofLog()<<"audio data max "<<max; + //float audio data is +- 0.5 + + + vector<float>buffer; + buffer.assign(&input[0],&input[bufferSize]); + + gist.processAudio(buffer, bufferSize, nChannels,sampleRate); +} + + +void ofApp::audioIn(float * input, int bufferSize, int nChannels){ + if(!useMic){ + return; + } + + //ofLog() << "processing "<<bufferSize<<" samples from mic"; + + processAudio(input, bufferSize, nChannels); + +} + +void ofApp::useMicChanged(){ + if (useMic) { + player.stop(); + } + else { + player.play(); + } +} + +//====================== settings + +void ofApp::default_settings(){ + warpframe[0]=glm::vec2(0,0); + warpframe[1]=glm::vec2(outputWindowSize.x,0); + warpframe[2]=glm::vec2(outputWindowSize.x,outputWindowSize.y); + warpframe[3]=glm::vec2(0,outputWindowSize.y); + outputPosition=ofPoint(0,0); + outputScale=1.0f; +} + void ofApp::save_settings(){ XML.setValue("WARP:p0:X", warpframe[0].x); XML.setValue("WARP:p0:Y", warpframe[0].y); @@ -131,15 +282,72 @@ void ofApp::save_settings(){ //-------------------------------------------------------------- void ofApp::updateOutput(ofEventArgs & args){ +//todo: set up listener for laser params or move them into a lasergui class laser.set_pts(laser_points); + laser.set_subdivide(laser_subdivide); + laser.set_blanknum(laser_blank_num); + laser.set_maxangle(laser_max_angle); + laser.set_intensity(laser_intensity); movie.setSpeed(video_speed); + if(!useMic){ + if(player.isLoaded()){ + if (player.isPlaying()){ + vector<float> output = player.getCurrentBuffer(bufferSize); + processAudio(&output[0], bufferSize, 2); + // + if (useFft){ + fftSmoothed = player.getFFT(); + /* + float * fft = ofSoundGetSpectrum(plotter.num_points); + fftSmoothed.resize(plotter.num_points); + //printf("fft: "); + for (int i=0;i<plotter.num_points;i++){ + fftSmoothed[i]=fft[i]; + //printf("%f,",fftSmoothed[i]); + } + //printf("\r\n"); + */ + plotter.addpoints(fftSmoothed); + } + else { + plotter.addpoints(centre); + } + } + else { + player.play(); + } + } + + } + else { + if (player.isPlaying()){ + player.stop(); + } + if (centre.size()){ + if (useFft){ + float * fft = ofSoundGetSpectrum(plotter.num_points); + fftSmoothed.resize(plotter.num_points); + printf("fft: "); + for (int i=0;i<plotter.num_points;i++){ + fftSmoothed[i]=fft[i]; + printf("%f,",fftSmoothed[i]); + } + printf("\r\n"); + plotter.addpoints(fftSmoothed); + } + else { + plotter.addpoints(centre); + } + } + } + } void ofApp::update(){ - +/* // Update the NDI sender list to find new senders // There is no delay if no new senders are found nSenders = ndiReceiver.FindSenders(); @@ -230,7 +438,7 @@ void ofApp::update(){ } } - +*/ if (movie.isLoaded()){ movie.update(); } @@ -278,8 +486,9 @@ void ofApp::draw(){ glPopMatrix(); } else { - - gui.draw(); + lasergui.draw(); + drawgui.draw(); + audiogui.draw(); //================================== NDI /* @@ -448,6 +657,7 @@ void ofApp::drawOutput(ofEventArgs & args){ polyOutput.push_back(colourPolyline(poly,ofColor(laser_R,laser_G,laser_B))); } +/* case NDI:{ ofPoint scale=ofPoint(outputWindowSize.x/ndiImage.getWidth(),outputWindowSize.x/ndiImage.getHeight()); @@ -480,6 +690,7 @@ void ofApp::drawOutput(ofEventArgs & args){ break; } +*/ case Player:{ if (movie.isLoaded()){ ofPoint scale=ofPoint(outputWindowSize.x/movie.getWidth(),outputWindowSize.y/movie.getHeight()); @@ -538,6 +749,17 @@ void ofApp::drawOutput(ofEventArgs & args){ } break; } + case Audio:{ + ofMatrix4x4 x=ofMatrix4x4(1.0f,0.0f,0.0f,0.0f, + 0.0f,1.0f,0.0f,0.0f, + 0.0f,0.0f,1.0f,0.0f, + 0.0f,0.0f,0.0f,1.0f); + polyOutput=plotter.output(x,scalePlot,decayPlot); + break; + } + default: { + break; + } } vector <colourPolyline> transformedOutput; @@ -618,7 +840,9 @@ void ofApp::drawOutput(ofEventArgs & args){ int pnum=0; if (polyOutput.size()){ - num=laser.draw(scaledWarpedOutput); + if (laser_power) { + num=laser.draw(scaledWarpedOutput); + } for (auto& shape:warpedOutput){ shape.draw(); pnum+=shape.size(); @@ -630,11 +854,11 @@ void ofApp::drawOutput(ofEventArgs & args){ } if (num>0){ - ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser points: "+ofToString(num)); + ofSetWindowTitle(sourcenames[source]+": "+ofToString(ofGetFrameRate(), 2)+" fps laser points: "+ofToString(num)); } else { - ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser error points: "+ofToString(pnum)); + ofSetWindowTitle(sourcenames[source]+": "+ofToString(ofGetFrameRate(), 2)+" fps laser error points: "+ofToString(pnum)); } } @@ -679,8 +903,8 @@ void ofApp::keyPressed(ofKeyEventArgs &args){ bDrawFrame=!bDrawFrame; break; } - case OF_KEY_COMMAND:{ - commandPressed=true; + case 'd':{ + default_settings(); break; } case 's':{ |
