diff options
Diffstat (limited to 'liveengine/src')
| -rw-r--r-- | liveengine/src/main.cpp | 17 | ||||
| -rwxr-xr-x | liveengine/src/testApp.cpp | 165 | ||||
| -rwxr-xr-x | liveengine/src/testApp.h | 37 |
3 files changed, 219 insertions, 0 deletions
diff --git a/liveengine/src/main.cpp b/liveengine/src/main.cpp new file mode 100644 index 0000000..f5eaddd --- /dev/null +++ b/liveengine/src/main.cpp @@ -0,0 +1,17 @@ +#include "ofMain.h" +#include "testApp.h" +#include "ofAppGlutWindow.h" + +//======================================================================== +int main( ){ + + ofAppGlutWindow window; + ofSetupOpenGL(&window, 400,300, OF_WINDOW); // <-------- setup the GL context + //ofSetupOpenGL(&window, 1024,768, OF_WINDOW); + + // this kicks off the running of my app + // can be OF_WINDOW or OF_FULLSCREEN + // pass in width and height too: + ofRunApp( new testApp()); + +} diff --git a/liveengine/src/testApp.cpp b/liveengine/src/testApp.cpp new file mode 100755 index 0000000..9ecb92f --- /dev/null +++ b/liveengine/src/testApp.cpp @@ -0,0 +1,165 @@ +#include "testApp.h" + + +//-------------------------------------------------------------- +void testApp::setup(){
+ int midiPort=0;
+ midiChannel=0;
+ //numLayers=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")) { + /*
+ numLayers=XML.getNumTags("layer");
+ if(numLayers) {
+ layers=new globeLayer*[numLayers];
+ for (int i=0;i<numLayers;i++){
+ XML.pushTag("layer",i);
+ string layerType=XML.getAttribute("content", "type", "");
+ XML.pushTag("content");
+ float x=ofToFloat(XML.getAttribute("pos", "x", ""));
+ float y=ofToFloat(XML.getAttribute("pos", "y", ""));
+ float w=ofToFloat(XML.getAttribute("pos", "w", ""));
+ float h=ofToFloat(XML.getAttribute("pos", "h", ""));
+ int midiNote=ofToInt(XML.getAttribute("midi", "note", "0"));
+ int midiMix=ofToInt(XML.getAttribute("midi", "mix", "0"));
+ if (layerType=="player") {
+ string fileName=XML.getAttribute("media", "name", "0");
+ layers[i]=new globePlayer(x,y,w,h,midiNote,midiMix,fileName);
+ }
+ if (layerType=="grabber") { + bool deInt=ofToInt(XML.getAttribute("grab", "deInt", "0"));
+ layers[i]=new globeGrabber(x,y,w,h,midiNote,midiMix,deInt);
+ }
+ XML.popTag();
+ XML.popTag();
+ }
+ } + */
+ }
+ //if (numLayers==0) printf("no layers loaded!\n");
+ }
+
+ 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);
+ showFPS=false;
+} + +//-------------------------------------------------------------- +void testApp::update(){
+ //for (int i=0;i<numLayers;i++) layers[i]->update(); +} + +//-------------------------------------------------------------- +void testApp::draw(){ + ofBackground(0,0,0);
+ + //for (int i=0;i<numLayers;i++) layers[i]->draw();
+
+ if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20);
+ +} + +//-------------------------------------------------------------- +void testApp::keyPressed (int key){ + if(key == 's'){ + XML.saveFile("settings.xml"); + printf("settings saved!\n"); + }
+ if(key == 'f'){
+ toggleFPS();
+ } +} + +//-------------------------------------------------------------- +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::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
+ noteOn=(eventArgs.byteTwo==0?false:true);
+ //for (int i=0;i<numLayers;i++){
+ // if (layers[i]->note==eventArgs.byteOne) layers[i]->setActive(noteOn);
+ //} + printf("note: %i %i\n",eventArgs.byteOne,eventArgs.byteTwo);
+ break;
+ case 176: //control change
+ //for (int i=0;i<numLayers;i++){
+ // if (layers[i]->mix==eventArgs.byteOne) layers[i]->setMixAmt(((float)eventArgs.byteTwo)/127.0f);
+ //} + printf("cc: %i %i\ n",eventArgs.byteOne,eventArgs.byteTwo);
+ }
+ }
+}
+ diff --git a/liveengine/src/testApp.h b/liveengine/src/testApp.h new file mode 100755 index 0000000..9b07764 --- /dev/null +++ b/liveengine/src/testApp.h @@ -0,0 +1,37 @@ +#pragma once + +#include "ofMain.h" +#include "ofxXmlSettings.h"
+
+#define OF_ADDON_USING_OFXMIDIIN
+
+#include "ofxMidi.h" + +class testApp : public ofBaseApp, public ofxMidiListener{ + + public: + + void setup(); + void update(); + void draw(); + + void keyPressed(int key); + void keyReleased(int key); + void mouseMoved(int x, int y ); + void mouseDragged(int x, int y, int button); + void mousePressed(int x, int y, int button); + void mouseReleased(int x, int y, int button); + void windowResized(int w, int h); + void dragEvent(ofDragInfo dragInfo); + void gotMessage(ofMessage msg); + + void toggleFPS(); + bool showFPS; + + ofxXmlSettings XML;
+
+ int midiChannel;
+ ofxMidiIn midiIn;
+ void newMidiMessage(ofxMidiEventArgs& eventArgs); +}; + |
