#include "testApp.h" previewWindow::~previewWindow(){ cout << "preview window destroyed" << endl; } void previewWindow::setup(){} void previewWindow::setBuffer(ofFbo *buffer){ rb=buffer; } void previewWindow::draw(){ rb->draw(0,0,ofGetWidth(),ofGetHeight()); } //-------------------------------------------------------------- void testApp::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); } midiIn.listPorts(); midiIn.openPort(midiPort); midiIn.addListener(this); // to register only to one controller pass the id as first argument // midiIn.addListener(84,this); // to debug // midiIn.setVerbose(true); controllers=new unsigned char[NUM_CONTROLLERS]; memset(controllers,NUM_CONTROLLERS,0); note=0; makeColours(); controlColours=false; debug=false; noteRandomiseColours=false; transparentBlack=false; reversemain=false; vp1.setup(768,1024,1024,0,-90,-256,-384); vp2.setup(1024,768,0,0,0,-512,-384); showFPS=false; ofBackground(0,0,0); ofSetBackgroundAuto(false); xshift=-1; yshift=-1; fadetime=0; mode=BLOCKS; lastnoteTime=ofGetElapsedTimef(); decayTime=1.0f; //ofSetVerticalSync(true); deosn't seem effective //glXSwapIntervalSGI(1); /* printf("hue of red is %f\n",ofColor(255,0,0).getHue()); printf("hue of green is %f\n",ofColor(0,255,0).getHue()); printf("hue of blue is %f\n",ofColor(0,0,255).getHue()); hue is float from 0.0-255.0 */ ofSetFrameRate(60); rotate=-90; scale=1.0f; fscale=1.0f; //window stuff ofxFenster* win=ofxFensterManager::get()->createFenster(0, 0, 600, 800, OF_WINDOW); 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.setBuffer(&vp1.rb2); fullscreenoutput=false; } void testApp::makeColours() { controller_colours=new ofColor[NUM_CONTROLLERS]; for (int i=0;iupdate(); } //-------------------------------------------------------------- void testApp::draw(){ float lambda=max(0.0f,1.0f-((ofGetElapsedTimef()-lastnoteTime)/decayTime)); ofSetColor(255-fadetime,255-fadetime,255-fadetime); //for feedback vp1.draw(lambda,controllers,xshift,yshift,list,transparentBlack,note,mode,controller_colours,controlColours,scale,fscale); 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); ofSetColor(255,255,255); if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20); /* rb1.begin(); // can this work? //grab.setAnchorPoint(xshift,yshift); //grab.setTextureWrap( GL_WRAP_BORDER, GL_WRAP_BORDER); //grab.draw(0,0); // xshift,yshift); ofSetColor(255-fadetime,255-fadetime,255-fadetime); for (int i=(xshift>0?xshift-rb1.getWidth():xshift);i0?yshift-rb1.getHeight():yshift);j0) { switch(mode) { case BLOCKS: for (int i=0;i>7,(controller_colours[i].g*controllers[i])>>7,(controller_colours[i].b*controllers[i])>>7)); ofRect((note-START_NOTE)*notewidth,i*noteheight,notewidth,noteheight); } break; case LIST: if (list.lock()) { //if playlist is loaded ofPushMatrix(); ofTranslate(rb1.getWidth()/2,rb1.getHeight()/2); ofScale(scale,scale,scale); ofRotate(rotate); ofTranslate(-rb1.getWidth()/2,-rb1.getHeight()/2); if (list.layers.find(note)!=list.layers.end()) { if (controlColours) list.layers[note]->draw(lamda,controllers,512,384,transparentBlack); else list.layers[note]->draw(lamda,512,384); } ofPopMatrix(); list.unlock(); } break; } } //for (int i=0;idraw(); ofSetColor(255,255,255); if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20); rb1.end(); rb2.begin(); ofSetColor(255,255,255); rb1.draw(0,0); rb2.end(); rb2.draw(1024,0); rb3.begin(); //landscape ofSetColor(255-fadetime,255-fadetime,255-fadetime); for (int i=(xshift>0?xshift-rb3.getWidth():xshift);i0?yshift-rb3.getHeight():yshift);j0) { switch(mode) { case BLOCKS: for (int i=0;i>7,(controller_colours[i].g*controllers[i])>>7,(controller_colours[i].b*controllers[i])>>7)); ofRect((note-START_NOTE)*notewidth,i*noteheight,notewidth,noteheight); } break; case LIST: if (list.lock()) { //if playlist is loaded ofPushMatrix(); ofTranslate(rb3.getWidth()/2,rb3.getHeight()/2); ofScale(scale,scale,scale); ofRotate(rotate); ofTranslate(-rb3.getWidth()/2,-rb3.getHeight()/2); if (list.layers.find(note)!=list.layers.end()) { if (controlColours) list.layers[note]->draw(lamda,controllers,512,384,transparentBlack); else list.layers[note]->draw(lamda,512,384); } ofPopMatrix(); list.unlock(); } break; } } ofPopMatrix(); //for (int i=0;idraw(); ofSetColor(255,255,255); if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20); rb3.end(); rb4.begin(); ofSetColor(255,255,255); rb3.draw(0,0); rb4.end(); rb4.draw(0,0); */ /* test screen shape ofSetColor(255,0,0); ofRect(0,0,1024,768); ofSetColor(0,255,0); ofRect(1024,0,1024,768); */ } //-------------------------------------------------------------- void testApp::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 testApp::keyPressed(int key){ if(key == 'q'){ list.load("insects.xml"); } if(key == 'Q'){ list.load("birds.xml"); } if(key == 'w'){ list.load("teamsports.xml"); } if(key == 'W'){ list.load("american_football.xml"); } if(key == 'e'){ list.load("organs.xml"); } if(key == 'E'){ list.load("crests.xml"); } if(key == 'r'){ list.load("tai_chi.xml"); } if(key == 'R'){ list.load("cricket.xml"); } if(key == 't'){ list.load("reptiles.xml"); } if(key == 'y'){ list.load("miltary_ladies.xml"); } if(key == 'Y'){ list.load("women_ethnic.xml"); } if(key == 'u'){ list.load("knights.xml"); } if(key == 'i'){ list.load("mil_historic.xml"); } if(key == 'I'){ list.load("mil_ethnic.xml"); } if(key == 'o'){ list.load("yoga.xml"); } if(key == 'p'){ list.load("dancing.xml"); } if(key == 'P'){ list.load("trainers.xml"); } 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){ yshift++; } if(key == 268){ yshift--; } if(key == 269){ xshift--; } if(key == 270){ xshift++; } if(key == '='){ makeColours(); } if(key == '-'){ controlColours=!controlColours; printf("%s control colours\n",controlColours?"do":"don't"); } 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 == 'l'){ noteRandomiseColours=!noteRandomiseColours; printf("%s randomise colours\n",noteRandomiseColours?"do":"don't"); } if (key=='k') { transparentBlack=!transparentBlack; printf("%s transparent black\n",transparentBlack?"use":"don't use"); } if (key=='j') { fscale=1.0f; } if (key=='h') { scale=1.0f; } if (key=='h') { reversemain=!reversemain; printf("%s main screen\n",reversemain?"reversing":"not reversing"); } } //-------------------------------------------------------------- void testApp::keyReleased(int key){ } //-------------------------------------------------------------- void testApp::mouseMoved(int x, int y ){ } //-------------------------------------------------------------- void testApp::mouseDragged(int x, int y, int button){ } //-------------------------------------------------------------- void testApp::mouseReleased(int x, int y, int button){ } void testApp::mousePressed(int x, int y, int button) { } //-------------------------------------------------------------- void testApp::windowResized(int w, int h){ } //-------------------------------------------------------------- void testApp::gotMessage(ofMessage msg){ } //-------------------------------------------------------------- void testApp::dragEvent(ofDragInfo dragInfo){ } void testApp::mousePressedEvent(ofMouseEventArgs &args) { //printf("mouse: %i,%i %i of %ix%i\n",args.x,args.y,args.button,ofGetWidth(),ofGetHeight()); //0-2 switch (args.button) { case 0: xshift=args.x-(ofGetWidth()/2); yshift=args.y-(ofGetHeight()/2); break; case 1: scale=pow(pow(args.x-(ofGetWidth()/2),2)+pow(args.y-(ofGetHeight()/2),2),0.5)/(ofGetWidth()*.1); break; case 2: fscale=(pow(pow(args.x-(ofGetWidth()/2),2)+pow(args.y-(ofGetHeight()/2),2),0.5)/(ofGetWidth()))+0.5; break; } } void testApp::keyPressedEvent(ofKeyEventArgs &args) { //printf("window key pressed: %i (%c)\n",args.key,args.key); keyPressed(args.key); } void testApp::toggleFPS(){ showFPS=!showFPS; } void testApp::newMidiMessage(ofxMidiEventArgs& eventArgs){ //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); bool noteOn; //this old thing! if ((midiChannel==0)||(eventArgs.channel==midiChannel)) { switch(eventArgs.status) { case 144: //noteon-off channel 0 noteOn=(eventArgs.byteTwo==0?false:true); //for (int i=0;inote==eventArgs.byteOne) layers[i]->setActive(noteOn); //} if (debug) printf("note: %i %i\n",eventArgs.byteOne,eventArgs.byteTwo); note=eventArgs.byteOne; lastnoteTime=ofGetElapsedTimef(); if (noteRandomiseColours) makeColours(); 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",eventArgs.byteOne,eventArgs.byteTwo); controllers[eventArgs.byteOne-START_CONTROLLER]=eventArgs.byteTwo; } } }