#include "ofApp.h" /* //-------------------------------------------------------------- void ofApp::setup(){ ofSetFrameRate(60); ofSetWindowPosition(0, 0); ofSetWindowTitle("MAIN WINDOW"); ofxFensterManager::get()->setupWindow(&window); } //-------------------------------------------------------------- void ofApp::update(){ } //-------------------------------------------------------------- void ofApp::draw(){ ofBackground(30, 0, 0); ofSetColor(255); ofDrawBitmapString("I am the regular OF window\n\nOver there is another one -->", 10, 30); } //-------------------------------------------------------------- void ofApp::keyPressed(int key){ } //-------------------------------------------------------------- void ofApp::keyReleased(int key){ } //-------------------------------------------------------------- void ofApp::mouseMoved(int x, int y ){ } //-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mousePressed(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void ofApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ } */ previewWindow::~previewWindow(){ cout << "preview window destroyed" << endl; } void previewWindow::setup(){ setWindowShape(600,800); setWindowPosition(260, 0); setWindowTitle("PREVIEW"); } void previewWindow::setParent(ofBaseApp *p){ ofAddListener(onMouseDragged, p, &ofBaseApp::mousePressed); ofAddListener(onMouseReleased, p, &ofBaseApp::mousePressed); ofAddListener(onMousePressed, p, &ofBaseApp::mousePressed); //parent=p; } void previewWindow::setBuffer(ofFbo *buffer){ rb=buffer; } void previewWindow::draw(){ rb->draw(0,0,getWidth(),getHeight()); //why crash? } //-------------------------------------------------------------- outputWindow::~outputWindow(){ } void outputWindow::setup(){ setWindowShape(1440,270); setWindowPosition(0, 0); setWindowTitle("OUTPUT"); } void outputWindow::setParent(ofApp *p){ parent=p; } void outputWindow::draw(){ float lambda=max(0.0f,1.0f-((ofGetElapsedTimef()-parent->lastnoteTime)/parent->decayTime)); int ft=255-(parent->fadetime*((float)parent->fadeScale)*0.1f); //if(ofGetFrameNum()%25==0) printf("fadeScale %i\n",(int)fadeScale); ofSetColor(ft,ft,ft); //for feedback float os=parent->oscScale?(sin((parent->breakOsc?ofGetElapsedTimef()-(parent->randomOsc?parent->randOffs:parent->lastnoteTime):ofGetElapsedTimef()))*parent->scaleFrequency)*parent->scaleAmplitude:0.0f; //vp1.draw(lambda,controllers,xshift,yshift,list,transparentBlack,note,mode,controller_colours,controlColours,scale,fscale,noteRandomiseColours?colShift:0.0f); //vp2.draw(lambda,controllers,reversemain?-xshift:xshift,yshift,list,transparentBlack,note,mode,controller_colours,controlColours,reversemain?1.0f/scale:scale,reversemain?1.0f/fscale:fscale,noteRandomiseColours?colShift:0.0f); for (int i=0;iviewports.size();i++) { bool even=!(i%2); bool do_reverse=parent->reverse?!(even&&parent->reversemain):even&&parent->reversemain; parent->viewports[i]->draw(lambda,parent->controllers,do_reverse?-parent->xshift:parent->xshift,parent->yshift,parent->list,parent->transparentBlack,parent->note,parent->mode,parent->controller_colours,parent->controlColours,do_reverse?1.0f/(parent->scale+os):parent->scale+os,do_reverse?1.0f/parent->fscale:parent->fscale,parent->noteRandomiseColours?parent->colShift:0.0f,parent->fadeBackground); } ofSetColor(255,255,255); if (parent->showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20); } void outputWindow::windowMoved(int x,int y){ //printf("window moved!\n"); } void outputWindow::keyPressed(int key, ofxFenster* win){ printf("output key %d\n",key); parent->keyPressed(key); } //-------------------------------------------------------------- void ofApp::setup(){ int midiPort=0; midiChannel=0; if( !XML.loadFile("settings.xml") ){ printf("unable to load settings.xml check data/ folder\n"); }else{ printf("settings loaded!\n"); midiPort=ofToInt(XML.getAttribute("liveEngine", "port", "0")); //default to 0/all midiChannel=ofToInt(XML.getAttribute("liveEngine", "channel", "0")); if (midiChannel) printf("listening on port %d, midi channel %d\n",midiPort,midiChannel); else printf("listening on port %d, all midi channels\n",midiPort); if(XML.pushTag("liveEngine")) { int numViews=XML.getNumTags("viewport"); if(numViews) { for (int i=0;icreateFenster(0, 0, 600, 800, OF_WINDOW); ofxFensterManager::get()->setupWindow(prevWin); //ofAddListener(win->events.mouseDragged, this, &testApp::mousePressedEvent); //ofAddListener(win->events.mousePressed, this, &testApp::mousePressedEvent); //ofAddListener(win->events.keyPressed, this, &testApp::keyPressedEvent); //win->setWindowTitle("preview"); //win->addListener(prevWin); //prevWin->setup(); prevWin->setParent(this); prevWin->setBuffer(&viewports[2]->rb2); fullscreenoutput=false; gui.setup(""); gui.add(reverse.set("reverse", false)); gui.add(reversemain.set("reverse main", false)); gui.add(controlColours.set("control colours", false)); gui.add(noteRandomiseColours.set("randomise note colours", false)); gui.add(transparentBlack.set("transparent black", false)); gui.add(resetDrawscale.setup("reset draw scale")); gui.add(resetFBscale.setup("reset FB scale")); gui.add(fadeScale.set("decay draw",128,0,255)); gui.add(decayTime.set("decay time",1.0,0.0,10.0)); gui.add(fadeBackground.set("decay background",0,0,255)); gui.add(oscScale.set("scale size LFO", false)); gui.add(breakOsc.set("break oscillators", false)); gui.add(randomOsc.set("randomise oscillators", false)); gui.add(scaleAmplitude.set("fade scale",0.5f,0.0f,2.0f)); gui.add(scaleFrequency.set("fade freq",1.0f,0.0f,5.0f)); /*. fadeScale=128; gui.add(fS.setup("decay draw",fadeScale,0,255,255)); decayTime=1.0f; gui.add(dT.setup("decay time",decayTime,0,10.0,255)); fadeBackground=0; gui.add(fB.setup("decay background",fadeBackground,0,255,255)); gui.add(oscScale.setup("scale size LFO", false)); gui.add(breakOsc.setup("break oscillators", false)); gui.add(randomOsc.setup("randomise oscillators", false)); scaleAmplitude=0.5f; gui.add(sA.setup("fade scale",scaleAmplitude,0,2.0,255)); scaleFrequency=1.0f; gui.add(sF.setup("fade freq",scaleFrequency,0,5.0,255)); */ //gui window stuff //ofxFenster* win2=ofxFensterManager::get()->createFenster(0, 0, 200, 400, OF_WINDOW); outWin=new outputWindow(); ofxFensterManager::get()->setupWindow(outWin); //ofAddListener(win2->events.windowResized, this, &testApp::windowEvent); //win2->setWindowTitle("config"); //win2->addListener(guiWin); //guiWin->setup(); outWin->setParent(this); ofAddListener(outWin->onKeyPressed, this, &ofApp::keyPressedEvent); //debug=true; //ofAddListener(onDrag, baseApp, &ofBaseApp::dragged); } void ofApp::makeColours() { controller_colours=new ofColor[NUM_CONTROLLERS]; for (int i=0;iupdate(); if (resetDrawscale) scale=1.0f; if (resetFBscale) fscale=1.0f; } //-------------------------------------------------------------- void ofApp::draw(){ ofBackground(0,0,0); gui.draw(); if (list.lock()) { //if loaded if (!list.thumbnailed) list.makeThumbnail(); if (list.thumbnailed) list.thumbnail.draw(20,ofGetHeight()-150); list.unlock(); } ofDrawBitmapString(list.name,20,ofGetHeight()-10); } //-------------------------------------------------------------- void ofApp::keyPressed(int key, ofxFenster* win){ if(key == ' '){ fullscreenoutput=!fullscreenoutput; win->setFullscreen(fullscreenoutput); printf("resolution: %ix%i %s\n",win->getWidth(),win->getHeight(),fullscreenoutput?"fullscreen":"windowed"); } else keyPressed(key); } void ofApp::keyPressed(int key){ if(key == ' '){ fullscreenoutput=!fullscreenoutput; outWin->setFullscreen(fullscreenoutput); printf("resolution: %ix%i %s\n",outWin->getWidth(),outWin->getHeight(),fullscreenoutput?"fullscreen":"windowed"); } if(key =='q'){ nmidiMessage(144,127,ofRandom(64)+36); } if(key == 's'){ XML.saveFile("settings.xml"); printf("settings saved!\n"); } if(key == 'f'){ toggleFPS(); } if(key >='0' && key <= '9'){ mode=key-'0'; } if(key == 267||key==OF_KEY_LEFT){ xshift--; } if(key == 268||key==OF_KEY_RIGHT){ xshift++; } if(key == 269||key==OF_KEY_UP){ yshift--; } if(key == 270||key==OF_KEY_DOWN){ yshift++; } if(key == '='){ makeColours(); } if(key == '+'){ fadetime=min(128,fadetime+1); } if(key == '_'){ fadetime=max(0,fadetime-1); } if(key == ']'){ scale*=1.01; } if(key == '['){ scale/=1.01; } if(key == '}'){ rotate+=90; } if(key == '{'){ rotate-=90; } if(key == 'd'){ debug=!debug; } if (key=='j') { fscale=1.0f; } if (key=='h') { scale=1.0f; } } //-------------------------------------------------------------- void ofApp::keyReleased(int key){ } //-------------------------------------------------------------- void ofApp::mouseMoved(int x, int y ){ } //-------------------------------------------------------------- void ofApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::mouseReleased(int x, int y, int button){ } //-------------------------------------------------------------- void ofApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void ofApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ printf("got draginfo: %s\n",dragInfo.files[0].c_str()); int sta=dragInfo.files[0].find_last_of("\\/")+1; int len=(dragInfo.files[0].find_last_of(".")+4)-sta; string filename="images/"+dragInfo.files[0].substr(sta,len); printf("loading %s\n",filename.c_str()); list.load(filename); } void ofApp::windowEvent(ofResizeEventArgs &args){ printf("window event\n"); } void ofApp::mousePressed( int x, int y, int button ) { printf("%d %d %d %d %d\n",x,y,button,ofGetKeyPressed(OF_KEY_SHIFT),ofGetKeyPressed(OF_KEY_CONTROL)); //hmm fenster doesn't pass on modifer keys or buttons switch (button) { case 0: xshift=x-(prevWin->getWidth()/2); yshift=y-(prevWin->getHeight()/2); break; case 1: scale=pow(pow(x-(prevWin->getWidth()/2),2)+pow(y-(prevWin->getHeight()/2),2),0.5)/(prevWin->getWidth()*.1); break; case 2: fscale=(pow(pow(x-(prevWin->getWidth()/2),2)+pow(y-(prevWin->getHeight()/2),2),0.5)/(prevWin->getWidth()))+0.5; break; } } void ofApp::keyPressedEvent(ofKeyEventArgs &args) { //printf("window key pressed: %i (%c)\n",args.key,args.key); keyPressed(args.key); } void ofApp::toggleFPS(){ showFPS=!showFPS; } void ofApp::newMidiMessage(ofxMidiMessage& eventArgs){ if ((midiChannel==0)||(eventArgs.channel==midiChannel)) { nmidiMessage(eventArgs.status,eventArgs.bytes[0],eventArgs.bytes[1]); } } //newMessage(eventArgs.port, eventArgs.channel, eventArgs.byteTwo, eventArgs.timestamp); //byteOne : message type /* int port; int channel; int status; int byteOne; int byteTwo; double timestamp; */ //printf("%d %d %d %d %d\n",eventArgs.port,eventArgs.channel,eventArgs.status,eventArgs.byteOne,eventArgs.byteTwo); void ofApp::nmidiMessage(int event,int data1, int data2) { //printf("midi: %i %i\n",event,data1); bool noteOn; //this old thing! int i; switch(event) { case 144: //noteon-off channel 0 //printf("note %i %i %i\n",event,data1,data2); noteOn=(data1==0?false:true); //for (int i=0;inote==eventArgs.byteOne) layers[i]->setActive(noteOn); //} note=data2; lastnoteTime=ofGetElapsedTimef(); if (list.layers.size()&&list.lock()) { //if playlist is loaded map::iterator itr; //for(itr = list.layers.begin(); itr != list.layers.end(); ++itr){ // list.layers[itr->first]->setNote(note); //} if (list.layers.find(note)!=list.layers.end()) list.layers[note]->setNote(note); list.unlock(); } if (noteRandomiseColours) { makeColours(); // } randOffs=ofRandom(100.0f); break; case 176: //control change channel 0 //for (int i=0;imix==eventArgs.byteOne) layers[i]->setMixAmt(((float)eventArgs.byteTwo)/127.0f); //} if (debug) printf("cc: %i %i\n",data1,data2); if (data1>=START_CONTROLLER) controllers[data1-START_CONTROLLER]=data2; } }