diff options
| author | Tim Redfern <tim@eclectronics.org> | 2012-08-31 09:21:00 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2012-08-31 09:21:00 +0100 |
| commit | ba7cc94d4ae55e171f0e08126abb0cb13d8f9f8f (patch) | |
| tree | e015563027592464817796f3b9da72ba62ebcaff /liveengine/src/testApp.cpp | |
| parent | 766266368648487735894e6bf01c0330db6be2aa (diff) | |
blocking loading playlists
Diffstat (limited to 'liveengine/src/testApp.cpp')
| -rwxr-xr-x | liveengine/src/testApp.cpp | 130 |
1 files changed, 96 insertions, 34 deletions
diff --git a/liveengine/src/testApp.cpp b/liveengine/src/testApp.cpp index 9a84eda..ee89f6a 100755 --- a/liveengine/src/testApp.cpp +++ b/liveengine/src/testApp.cpp @@ -1,11 +1,39 @@ #include "testApp.h" - +void testApp::loadplaylist(string _name){ + int numLayers=0; + layers.clear(); + if( !XML.loadFile(_name) ){
+ printf("unable to load %s check data/ folder\n",_name.c_str());
+ }else{ + if(XML.pushTag("playlist")) {
+ numLayers=XML.getNumTags("svglayer");
+ if(numLayers) {
+ for (int i=0;i<numLayers;i++) {
+ string s=XML.getAttribute("svglayer", "file", "",i);
+ printf("loading %s: ",s.c_str());
+ layers[XML.getAttribute("svglayer", "note", 0,i)]=new svglayer(XML.getAttribute("svglayer", "file", "",i));
+ }
+ }
+ else printf("no SVG layers loaded!\n");
+ numLayers=XML.getNumTags("imglayer");
+ if(numLayers) {
+ for (int i=0;i<numLayers;i++) {
+ string s=XML.getAttribute("imglayer", "file", "",i);
+ printf("%s: ",s.c_str());
+ //int i=XML.getAttribute("imglayer", "note", 0,i);
+ //ofImage i =
+ layers[XML.getAttribute("imglayer", "note", 0,i)]=new imglayer(XML.getAttribute("imglayer", "file", "",i));
+ }
+ }
+ else printf("no IMG layers loaded!\n");
+ } + } +} //-------------------------------------------------------------- void testApp::setup(){
int midiPort=0;
midiChannel=0;
- int numLayers=0;
if( !XML.loadFile("settings.xml") ){
printf("unable to load settings.xml check data/ folder\n");
}else{
@@ -14,19 +42,7 @@ void testApp::setup(){ 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")) {
- numLayers=XML.getNumTags("svglayer");
- if(numLayers) {
- for (int i=0;i<numLayers;i++) {
- string s=XML.getAttribute("svglayer", "file", "",i);
- printf("loading %s: ",s.c_str());
- layers[XML.getAttribute("svglayer", "note", 0,i)]=new svglayer(XML.getAttribute("svglayer", "file", "",i));
- }
- }
- else printf("no layers loaded!\n");
- }
-
- }
+ }
midiIn.listPorts();
midiIn.openPort(midiPort);
@@ -45,14 +61,22 @@ void testApp::setup(){ controller_colours=new ofColor[NUM_CONTROLLERS]; for (int i=0;i<NUM_CONTROLLERS;i++) controller_colours[i]=ofColor::fromHsb(ofRandom(255), 255, 255); - //grab.allocate(ofGetWidth(), ofGetHeight(),OF_IMAGE_COLOR_ALPHA); - grab.setUseTexture(true); + grab.allocate(ofGetWidth(), ofGetHeight(),GL_RGB); + //grab.setUseTexture(true); showFPS=false;
ofBackground(0,0,0); -
-
+ ofSetBackgroundAuto(false);
+
+ xshift=1;
+ yshift=1;
+
+ mode=BLOCKS; + + lastnoteTime=ofGetElapsedTimef(); + decayTime=2.0f;
+
//ofSetVerticalSync(true); deosn't seem effective
//glXSwapIntervalSGI(1);
} @@ -65,24 +89,33 @@ void testApp::update(){ //-------------------------------------------------------------- void testApp::draw(){
ofSetColor(255,255,255); - grab.grabScreen( 0, 0, ofGetWidth(), ofGetHeight() ); - grab.update();
- grab.reloadTexture(); - ofBackground(0,0,0); - //grab.draw( 1,1); + grab.loadScreenData( 0, 0, ofGetWidth(), ofGetHeight() ); + //grab.update();
+ //grab.reloadTexture(); + //ofBackground(0,0,0); + grab.draw( xshift,yshift); float notewidth=ofGetWidth()/NUM_NOTES; float noteheight=ofGetHeight()/NUM_CONTROLLERS; - for (int i=0;i<NUM_CONTROLLERS;i++){ - ofSetColor(ofColor((controller_colours[i].r*controllers[i])>>7,(controller_colours[i].g*controllers[i])>>7,(controller_colours[i].b*controllers[i])>>7)); - ofRect(note*notewidth,i*noteheight,notewidth,noteheight); + float lamda=max(0.0f,1.0f-((ofGetElapsedTimef()-lastnoteTime)/decayTime)); +
+ if (note>0) {
+ switch(mode) {
+ case BLOCKS: + for (int i=0;i<NUM_CONTROLLERS;i++){ + ofSetColor(ofColor((controller_colours[i].r*controllers[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:
+ ofPushMatrix();
+ //ofScale(sin(ofGetElapsedTimef())+1.1,sin(ofGetElapsedTimef())+1.1);
+ if (layers.find(note)!=layers.end()) layers[note]->draw(lamda);
+ ofPopMatrix();
+ break;
+ }
}
- ofSetColor((sin(ofGetElapsedTimef())+1)*128,255,255);
- ofPushMatrix();
- //ofScale(sin(ofGetElapsedTimef())+1.1,sin(ofGetElapsedTimef())+1.1);
- if (layers.find(note)!=layers.end()) layers[note]->draw();
- ofPopMatrix();
//for (int i=0;i<numLayers;i++) layers[i]->draw();
ofSetColor(255,255,255);
@@ -92,13 +125,41 @@ void testApp::draw(){ //-------------------------------------------------------------- void testApp::keyPressed (int key){ + if(key == 'q'){
+ loadplaylist("insects.xml");
+ } + if(key == 'w'){
+ loadplaylist("barcelona.xml");
+ } + if(key == 'e'){
+ loadplaylist("organs.xml");
+ } + if(key == 'r'){
+ loadplaylist("tai_chi.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 == OF_KEY_LEFT){
+ xshift--;
+ }
+ if(key == OF_KEY_RIGHT){
+ xshift++;
+ }
+ if(key == OF_KEY_DOWN){
+ yshift--;
+ }
+ if(key == OF_KEY_UP){
+ yshift++;
+ }
+ } //-------------------------------------------------------------- @@ -170,7 +231,8 @@ void testApp::newMidiMessage(ofxMidiEventArgs& eventArgs){ // if (layers[i]->note==eventArgs.byteOne) layers[i]->setActive(noteOn);
//} printf("note: %i %i\n",eventArgs.byteOne,eventArgs.byteTwo); - note=eventArgs.byteOne-START_NOTE;
+ note=eventArgs.byteOne; + lastnoteTime=ofGetElapsedTimef();
break;
case 176: //control change channel 0
//for (int i=0;i<numLayers;i++){
|
