summaryrefslogtreecommitdiff
path: root/liveengineUnmapped/src/testApp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'liveengineUnmapped/src/testApp.cpp')
-rwxr-xr-xliveengineUnmapped/src/testApp.cpp249
1 files changed, 129 insertions, 120 deletions
diff --git a/liveengineUnmapped/src/testApp.cpp b/liveengineUnmapped/src/testApp.cpp
index bd9d911..12388ea 100755
--- a/liveengineUnmapped/src/testApp.cpp
+++ b/liveengineUnmapped/src/testApp.cpp
@@ -3,6 +3,9 @@ previewWindow::~previewWindow(){
cout << "preview window destroyed" << endl;
}
void previewWindow::setup(){}
+void previewWindow::setParent(testApp *p){
+ parent=p;
+}
void previewWindow::setBuffer(ofFbo *buffer){
rb=buffer;
}
@@ -11,6 +14,9 @@ void previewWindow::draw(){
rb->draw(0,0,ofGetWidth(),ofGetHeight()); //why crash?
}
+void previewWindow::keyPressed(int key, ofxFenster* win){
+ parent->keyPressed(key);
+}
//--------------------------------------------------------------
guiWindow::~guiWindow(){
cout << "gui window destroyed" << endl;
@@ -38,16 +44,16 @@ void guiWindow::windowMoved(int x,int y){
}
//--------------------------------------------------------------
-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);
+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);
if(XML.pushTag("liveEngine")) {
int numViews=XML.getNumTags("viewport");
@@ -65,17 +71,17 @@ void testApp::setup(){
}
}
else printf("no viewports!\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.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];
@@ -93,23 +99,23 @@ void testApp::setup(){
//vp1.setup(768,1024,1024,0,-90,-256,-384);
//vp2.setup(1024,768,0,0,0,-512,-384);
-
- showFPS=false;
+
+ showFPS=false;
ofBackground(0,0,0);
- ofSetBackgroundAuto(false);
-
- xshift=-1;
+ ofSetBackgroundAuto(false);
+
+ xshift=-1;
yshift=-1;
fadetime=0;
-
+
mode=BLOCKS;
lastnoteTime=ofGetElapsedTimef();
- decayTime=1.0f;
-
- //ofSetVerticalSync(true); deosn't seem effective
+ decayTime=1.0f;
+
+ //ofSetVerticalSync(true); deosn't seem effective
//glXSwapIntervalSGI(1);
/*
printf("hue of red is %f\n",ofColor(255,0,0).getHue());
@@ -132,6 +138,7 @@ void testApp::setup(){
win->setWindowTitle("preview");
win->addListener(prevWin);
prevWin->setup();
+ prevWin->setParent(this);
prevWin->setBuffer(&viewports[0]->rb2);
fullscreenoutput=false;
@@ -146,6 +153,8 @@ void testApp::setup(){
gui.add(resetFBscale.setup("reset FB scale"));
fadeScale=128;
gui.add(fS.setup("fade scale",fadeScale,0,255,255));
+ fadeBackground=0;
+ gui.add(fB.setup("fade scale",fadeBackground,0,255,255));
decayTime=1.0f;
gui.add(dT.setup("decay time",decayTime,0,10.0,255));
@@ -171,7 +180,7 @@ void testApp::setup(){
guiWin->setParent(this);
debug=false;
-
+
}
void testApp::resetDrawscalePressed(bool & pressed){
@@ -187,7 +196,7 @@ void testApp::makeColours() {
colShift=ofRandom(255.0f);
}
//--------------------------------------------------------------
-void testApp::update(){
+void testApp::update(){
//for (int i=0;i<numLayers;i++) layers[i]->update();
}
@@ -198,14 +207,14 @@ void testApp::draw(){
int ft=255-(fadetime*((float)fadeScale)*0.1f);
//if(ofGetFrameNum()%25==0) printf("fadeScale %i\n",(int)fadeScale);
- ofSetColor(ft,ft,ft); //for feedback
+ ofSetColor(ft,ft,ft); //for feedback
float os=oscScale?(sin((breakOsc?ofGetElapsedTimef()-(randomOsc?randOffs:lastnoteTime):ofGetElapsedTimef()))*scaleFrequency)*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;i<viewports.size();i++) {
bool even=!(i%2);
- viewports[i]->draw(lambda,controllers,even&&reversemain?-xshift:xshift,yshift,list,transparentBlack,note,mode,controller_colours,controlColours,even&&reversemain?1.0f/(scale+os):scale+os,even&&reversemain?1.0f/fscale:fscale,noteRandomiseColours?colShift:0.0f);
+ viewports[i]->draw(lambda,controllers,even&&reversemain?-xshift:xshift,yshift,list,transparentBlack,note,mode,controller_colours,controlColours,even&&reversemain?1.0f/(scale+os):scale+os,even&&reversemain?1.0f/fscale:fscale,noteRandomiseColours?colShift:0.0f,fadeBackground);
}
ofSetColor(255,255,255);
@@ -231,35 +240,35 @@ void testApp::draw(){
float noteheight=rb1.getHeight()/NUM_CONTROLLERS;
-
- if (note>0) {
- switch(mode) {
+
+ 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;
+ }
+ break;
case LIST:
- if (list.lock()) { //if playlist is loaded
+ 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);
+ 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;
- }
- }
+ }
+ break;
+ }
+ }
- //for (int i=0;i<numLayers;i++) layers[i]->draw();
- ofSetColor(255,255,255);
+ //for (int i=0;i<numLayers;i++) layers[i]->draw();
+ ofSetColor(255,255,255);
if (showFPS) ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20);
rb1.end();
@@ -338,7 +347,7 @@ void testApp::draw(){
ofRect(0,0,1024,768);
ofSetColor(0,255,0);
ofRect(1024,0,1024,768);
- */
+ */
}
@@ -352,51 +361,51 @@ void testApp::keyPressed(int key, ofxFenster* win){
else keyPressed(key);
}
void testApp::keyPressed(int key){
- if(key =='q'){
+ if(key =='q'){
nmidiMessage(144,ofRandom(64)+36,127);
}
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){
- xshift--;
- }
- if(key == 268){
- xshift++;
- }
- if(key == 269){
- yshift--;
- }
- if(key == 270){
+ }
+ 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 == '='){
+ makeColours();
}
- if(key == '_'){
- fadetime=max(0,fadetime-1);
+ if(key == '+'){
+ fadetime=min(128,fadetime+1);
}
- if(key == ']'){
- scale*=1.01;
+ if(key == '_'){
+ fadetime=max(0,fadetime-1);
}
- if(key == '['){
- scale/=1.01;
+ if(key == ']'){
+ scale*=1.01;
}
- if(key == '}'){
- rotate+=90;
+ if(key == '['){
+ scale/=1.01;
}
- if(key == '{'){
- rotate-=90;
+ if(key == '}'){
+ rotate+=90;
+ }
+ if(key == '{'){
+ rotate-=90;
}
@@ -433,7 +442,7 @@ void testApp::mouseReleased(int x, int y, int button){
}
-void testApp::mousePressed(int x, int y, int button) {
+void testApp::mousePressed(int x, int y, int button) {
}
//--------------------------------------------------------------
@@ -484,41 +493,41 @@ void testApp::mousePressedEvent(ofMouseEventArgs &args) {
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::toggleFPS(){
+ showFPS=!showFPS;
+}
+
void testApp::newMidiMessage(ofxMidiEventArgs& eventArgs){
if ((midiChannel==0)||(eventArgs.channel==midiChannel)) {
nmidiMessage(eventArgs.status,eventArgs.byteOne,eventArgs.byteTwo);
}
-}
-
- //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);
+}
+
+ //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 testApp::nmidiMessage(int event,int data1, int data2) {
- if (debug) printf("midi: %i %i\n",event,data1);
- bool noteOn; //this old thing!
- int i;
- switch(event) {
- case 144: //noteon-off channel 0
- noteOn=(data2==0?false:true);
- //for (int i=0;i<numLayers;i++){
- // if (layers[i]->note==eventArgs.byteOne) layers[i]->setActive(noteOn);
+ if (debug) printf("midi: %i %i\n",event,data1);
+ bool noteOn; //this old thing!
+ int i;
+ switch(event) {
+ case 144: //noteon-off channel 0
+ noteOn=(data2==0?false:true);
+ //for (int i=0;i<numLayers;i++){
+ // if (layers[i]->note==eventArgs.byteOne) layers[i]->setActive(noteOn);
//}
note=data1;
@@ -529,19 +538,19 @@ void testApp::nmidiMessage(int event,int data1, int data2) {
// list.layers[itr->first]->setNote(note);
//}
list.layers[note]->setNote(note);
- list.unlock();
+ list.unlock();
}
if (noteRandomiseColours) {
makeColours(); //
}
- randOffs=ofRandom(100.0f);
- break;
- case 176: //control change channel 0
- //for (int i=0;i<numLayers;i++){
- // if (layers[i]->mix==eventArgs.byteOne) layers[i]->setMixAmt(((float)eventArgs.byteTwo)/127.0f);
+ randOffs=ofRandom(100.0f);
+ break;
+ case 176: //control change channel 0
+ //for (int i=0;i<numLayers;i++){
+ // if (layers[i]->mix==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;
- }
-}
+ if (data1>=START_CONTROLLER) controllers[data1-START_CONTROLLER]=data2;
+ }
+}