#include "ofApp.h" using namespace std; int MAX_POINTS=40000; int LASER_INTENSITY=37; //-------------------------------------------------------------- void ofApp::setup(){ ofSetCircleResolution(80); ofSetFrameRate(0); ofBackground(255); ofEnableSmoothing(); ofEnableAlphaBlending(); ofSetVerticalSync(false); bufferSize = 512; sampleRate = 44100; useMic = 1; isPaused = 0; player.setLoop(true); mfccMax = 0; showMFCC = 0; vector features = ofxGist::getFeatureNames(); int num = features.size(); for(int v = 0;vsetShowSmoothedCurve(1); */ //gist.setUseForOnsetDetection(GIST_PEAK_ENERGY); //gist.setUseForOnsetDetection(GIST_SPECTRAL_DIFFERENCE); //gist.setThreshold(GIST_SPECTRAL_DIFFERENCE, .2); gist.setUseForOnsetDetection(GIST_PEAK_ENERGY); gist.setThreshold(GIST_PEAK_ENERGY, .05);// ofAddListener(GistEvent::ON,this,&ofApp::onNoteOn); ofAddListener(GistEvent::OFF,this,&ofApp::onNoteOff); noteOnRadius = 0; soundStream.setup(this,0, 1, sampleRate, bufferSize, 1); //loadSong("12 Ferric Appetite.aiff"); loadSong("passades/1 The Ninth Set-sector1:sector2pt.1.aiff"); //loadSong("assets/sounds/Coltrane_acc_VUIMM.wav"); laser.set_pts(MAX_POINTS); laser.set_intensity(LASER_INTENSITY); } void ofApp::onNoteOn(GistEvent &e){ noteOnRadius = 100; }; void ofApp::onNoteOff(GistEvent &e){ //noteOnRadius = 0; }; //-------------------------------------------------------------- void ofApp::update(){ } //-------------------------------------------------------------- void ofApp::updateOutput(ofEventArgs& e){ if(isPaused){ return; } if(!useMic){ if(player.isLoaded()){ vector output = player.getCurrentBuffer(bufferSize); processAudio(&output[0], bufferSize, 2); fftSmoothed = player.getFFT(); plotter.addpoints(fft?fftSmoothed:centre); } } int num = ofxGist::getFeatureNames().size(); for(int v = 0;vsetRange(gist.getMin(v),gist.getMax(v)); plots[v]->update(gist.getValue(v)); } vectormfcc = gist.getMelFrequencyCepstralCoefficients(); //vectormfcc = gist.getMelFrequencySpectrum(); if(mfccSmoothed.size().999f){ mfccSmoothed[f] = mfcc[i]; } // let the smoothed value sink to zero: mfccSmoothed[i] *= damping; f++; if(mfccMaxsetRange(gist.getMFCCMin(i),gist.getMFCCMax(i)); mfccPlots[i]->update(mfcc[i]); } /* //crest avg plots.back()->setRange(gist.getMin(GIST_SPECTRAL_CREST),gist.getMax(GIST_SPECTRAL_CREST)); plots.back()->update(gist.getAvg(GIST_SPECTRAL_CREST)); */ if(noteOnRadius>0){ noteOnRadius--; } } //-------------------------------------------------------------- void ofApp::draw(){ ofBackground(0); gui.draw(); chaosgui.draw(); lasergui.draw(); } //-------------------------------------------------------------- void ofApp::drawOutput(ofEventArgs & args){ ofBackground(0); /* ofFill(); // draw the left: //ofSetHexColor(0x333333); int waveHeight = ofGetHeight(); //ofRect(0,0,256,waveHeight); float barW = ofGetWidth()/(float)fftSmoothed.size(); float currX = 0; ofSetColor(255,255,255,100); for (int i = 0; i < fftSmoothed.size(); i++){ ofRect(currX,waveHeight,barW,-fftSmoothed[i]*waveHeight); currX+=barW; } currX = 0; waveHeight = ofGetHeight(); barW = ofGetWidth()/(float)mfccSmoothed.size(); ofSetColor(255,100,100,200); for (int i = 0; i < mfccSmoothed.size() && showMFCC; i++){ ofRect(currX,ofGetHeight(),barW,- ofMap(mfccSmoothed[i], 0.0,mfccMax, 0.0,1.0,true )*waveHeight); currX+=barW; } ofNoFill(); ofSetColor(0,255,100,255); for (int i = 0; i < left.size(); i++){ //ofLine(i,300+left[i]*waveHeight,i,300+left[i]*waveHeight+1); } ofSetColor(000,100,255,255); for (int i = 0; i < right.size(); i++){ //ofLine(i,500+right[i]*waveHeight,i,500+right[i]*waveHeight+1); } */ /* int num; int margin = 5; if(showMFCC){ num = mfccPlots.size(); int plotHeight = (ofGetHeight()-margin*num)/(float)num; for(int v = 0;vdraw(margin,margin+plotHeight*v, ofGetWidth()-20, 100); } }else{ num = plots.size(); int plotHeight = (ofGetHeight()-margin*num)/(float)num; for(int v = 0;vdraw(margin,margin+plotHeight*v, ofGetWidth()-20, 100); } } ofFill(); ofSetColor(255,0,0,200); ofCircle(ofGetWidth()/2,ofGetHeight()/2,noteOnRadius); if(!showMFCC){ ofSetColor(0,0,0,250); ofRect(5,5,600,180); stringstream str; if(plots.size() ){ for(int v = 0;vgetVariableName()<<" | min: "<x,xform->y,0); ofMatrix4x4 r; r.makeRotationMatrix(rotate,0,0,1); ofMatrix4x4 s; s.makeScaleMatrix(scale->x,scale->y,1.0f); ofMatrix4x4 x=r*t*s; vector lines=plotter.output(x,scalePlot,decayPlot); //PROJECTION MAPPING //how best to move this to it's own class? glm::vec2 src[]={ glm::vec2(0,0), glm::vec2(ofGetWidth(),0), glm::vec2(ofGetWidth(),ofGetWidth()), glm::vec2(0,ofGetHeight()) }; glm::vec2 mp=glm::vec2(ofGetWidth()/2,ofGetWidth()/2); glm::vec2 scaled_dest[]={ ((warpframe[0]-mp)*outputScale)+mp, ((warpframe[1]-mp)*outputScale)+mp, ((warpframe[2]-mp)*outputScale)+mp, ((warpframe[3]-mp)*outputScale)+mp }; ofMatrix4x4 scaled_warp =lineTransformer::getPerspectiveTransformMatrix(src,scaled_dest); ofMatrix4x4 warp =lineTransformer::getPerspectiveTransformMatrix(src,warpframe); vector warpedOutput; vector scaledWarpedOutput; for (auto s:lines){ warpedOutput.push_back(lineTransformer::polyLineTransform(warp,s)); scaledWarpedOutput.push_back(lineTransformer::polyLineTransform(scaled_warp,s)); } //PREVIEW //ofTranslate(0,ofGetHeight()/2); //for (auto& line:lines){ // line->draw(); //} int pnum=0; for (auto& shape:warpedOutput){ shape.draw(); pnum+=shape.size(); } if (drawWarpFrame){ lineTransformer::drawWarpFrame(warpframe); } //LASER laser.set_subdivide(subdivide); laser.set_blanknum(blank_num); laser.set_maxangle(max_angle); laser.set_intensity(intensity); //int num=laser.draw(lines,30); int num=laser.draw(scaledWarpedOutput); ofSetWindowTitle(ofToString(ofGetFrameRate())+" fps, "+ofToString(num)+" pts"); } //-------------------------------------------------------------- void ofApp::exit() { } ofxHistoryPlot* ofApp::addGraph(string varName,float max,ofColor color){ ofxHistoryPlot* graph = new ofxHistoryPlot(NULL, varName, max, false); //true for autoupdate //graph2->setLowerRange(0); //set only the lowest part of the range upper is adaptative to curve graph->setAutoRangeShrinksBack(true); //graph2 scale can shrink back after growing if graph2 curves requires it graph->setRange(0,max); graph->setColor(color); graph->setShowNumericalInfo(true); graph->setRespectBorders(true); graph->setLineWidth(2); graph->setDrawBackground(false); graph->setDrawGrid(true); graph->setGridColor(ofColor(30)); //grid lines color graph->setGridUnit(14); graph->setShowSmoothedCurve(0); //graph2 a smoothed version of the values, but alos the original in lesser alpha graph->setSmoothFilter(0.1); //smooth filter strength graph->setMaxHistory(2000); return graph; }; void ofApp::clear(){ } void ofApp::loadSong(string str){ cout<<"loadSong "<max){ max=centre[i]; } } //ofLog()<<"audio data max "<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; } processAudio(input, bufferSize, nChannels); } //-------------------------------------------------------------- void ofApp::outputKeyPressed(ofKeyEventArgs &args){ keyPressed(args.key); } //-------------------------------------------------------------- void ofApp::keyPressed(int key){ if(key =='f'){ ofToggleFullscreen(); } if(key =='m'){ useMic = !useMic; if(!useMic){ player.play(); }else{ player.stop(); } gist.clearHistory(); } if(key ==' '){ isPaused = !isPaused; player.setPaused(isPaused); } if(key =='r'){ gist.clearHistory(); } if(key =='c'){ showMFCC = !showMFCC; } } //-------------------------------------------------------------- void ofApp::outputKeyReleased(ofKeyEventArgs &args){ keyReleased(args.key); } //-------------------------------------------------------------- void ofApp::keyReleased(int key){ } //-------------------------------------------------------------- void ofApp::mouseMoved(int x, int y ){ } //-------------------------------------------------------------- void ofApp::outputMouseDragged(ofMouseEventArgs & args){ //if (select_warpframe>-1){ // warpframe[select_warpframe]=glm::vec2(args.x,args.y); //} } //-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ if(!useMic){ player.setPosition(x/(float)ofGetWidth()); } float t = x/(float)ofGetWidth(); gist.setThreshold(GIST_SPECTRAL_DIFFERENCE,t); } //-------------------------------------------------------------- void ofApp::outputMousePressed(ofMouseEventArgs & args){ // for (int i=0;i<4;i++){ // if (ofPoint(args.x,args.y).distance(warpframe[i])<25){ // select_warpframe=i; // } // } } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::outputMouseReleased(ofMouseEventArgs & args){ //select_warpframe=-1; } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::outputWindowResized(ofResizeEventArgs &resizeargs){ } //-------------------------------------------------------------- void ofApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void ofApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ clear(); vector paths = ofSplitString(dragInfo.files[0], "data/"); loadSong(paths[1]); } void ofApp::newMidiMessage(ofxMidiMessage& msg) { }