diff options
Diffstat (limited to 'basedProject/src/ofApp.cpp')
| -rw-r--r-- | basedProject/src/ofApp.cpp | 142 |
1 files changed, 110 insertions, 32 deletions
diff --git a/basedProject/src/ofApp.cpp b/basedProject/src/ofApp.cpp index 1b2a074..86c50a7 100644 --- a/basedProject/src/ofApp.cpp +++ b/basedProject/src/ofApp.cpp @@ -1,7 +1,7 @@ #include "ofApp.h" //-------------------------------------------------------------- ofApp::~ofApp(){ - saveSettings("settings.xml"); + //saveSettings("settings.xml"); } //-------------------------------------------------------------- @@ -12,9 +12,11 @@ void ofApp::setup() { ///ofSetVerticalSync(true); + + //some model / light stuff /* - glEnable (GL_DEPTH_TEST); + glShadeModel (GL_SMOOTH); glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable (GL_COLOR_MATERIAL); @@ -26,30 +28,95 @@ void ofApp::setup() { fullscreen=false; activeView=0; - xhair.loadImage("crosshairs.png"); + checkers=new ofImage[3]; + + checkers[0].loadImage("checker_blue.png"); + checkers[1].loadImage("checker_green.png"); + checkers[2].loadImage("checker_red.png"); - int bufferSize= 512; //should be based on the size of glitch buffer + int bufferSize= beat.getBufferSize(); //should be based on the size of glitch buffer soundStream.listDevices(); //nb all you have to do to make audio work is to turn off pulseaudio in configuration - soundStream.setup(this, 0, 1, 44100, bufferSize, 1); + soundStream.setup(this, 0, 1, 44100, bufferSize, 4); + samples.resize(bufferSize); - glitch.setup(512,384,&samples); - glitch.set_interp(ofRandom(30)+2,ofRandom(22)+2); + glitch1.setup(512,384,&samples); + glitch2.setup(512,384,&samples); + glitch3.setup(512,384,&samples); + + mode=MODE_RUN; + + kick=snare=hihat=false; + } //-------------------------------------------------------------- void ofApp::update() { ofSetWindowTitle(ofToString(ofGetFrameRate())); - glitch.update(); + if (mode==MODE_RUN){ + + beat.update(ofGetElapsedTimeMillis()); + + + //if (ofRandom(10000)<3) glitch1.set_interp(ofRandom(18)+2,ofRandom(14)+2); + //if (ofRandom(10000)<8) glitch2.set_interp(ofRandom(18)+2,ofRandom(14)+2); + //if (ofRandom(10000)<20) glitch3.set_interp(ofRandom(18)+2,ofRandom(14)+2); + if (beat.kick()>0.9){ + if (!kick){ + int which=ofRandom(3); + switch (which) { + case 0: + glitch1.set_interp(ofRandom(18)+2,ofRandom(14)+2); + break; + case 1: + glitch2.set_interp(ofRandom(18)+2,ofRandom(14)+2); + break; + case 2: + glitch3.set_interp(ofRandom(18)+2,ofRandom(14)+2); + break; + } + kick=true; + } + } + else { + if (kick) kick=false; + } + + if (beat.snare()>0.9){ + if (!snare){ + int which=ofRandom(3); + switch (which) { + case 0: + glitch1.set_scale((ofRandom(100)*.002)+1.0); + break; + case 1: + glitch2.set_scale((ofRandom(100)*.002)+1.0); + break; + case 2: + glitch3.set_scale((ofRandom(100)*.002)+1.0); + break; + } + snare=true; + } + } + else { + if (snare) snare=false; + } + + glitch1.update(); + glitch2.update(); + glitch3.update(); + } } void ofApp::audioIn(float * input, int bufferSize, int nChannels){ for (int i=0;i<bufferSize/nChannels;i+=nChannels){ samples[i]=input[i*nChannels]; } + beat.audioReceived(input, bufferSize, nChannels); } //-------------------------------------------------------------- @@ -57,6 +124,21 @@ void ofApp::draw() { //ofSetColor(255,255, 255); //glitch.draw(0,0); + ofBaseHasTexture *texts[3]; + + switch(mode) { + case MODE_RUN: + texts[0]=&glitch1.renderFBO; + texts[1]=&glitch2.renderFBO; + texts[2]=&glitch3.renderFBO; + break; + case MODE_CALIB: + texts[0]=&checkers[0]; + texts[1]=&checkers[1]; + texts[2]=&checkers[2]; + break; + } + for (int i=0;i<views.size();i++) { views[i].setLight(); } @@ -66,25 +148,20 @@ void ofApp::draw() { ofFill(); - //glitch.renderFBO. - //xhair.getTextureReference().bind(); - bindTexture(glitch.renderFBO); - //ofEnableAlphaBlending(); - //ofSetColor(0, 0, 255, 255); + + bindTexture(*texts[0]); ofDrawSphere(0,0,0,145); - //ofSpherePrimitive s=ofSpherePrimitive(145,50); - //s.enableTextures(); - //s.draw(); - //ofSetColor(0, 255, 0, 255); - ofDrawSphere(200,0,230,75); - //ofSetColor(255, 0,0, 255); - ofDrawSphere(-60,-190,280,47.5); - //ofSetColor(255, 255,255, 255); - //xhair.draw(0,0,views[i].getWidth(),views[i].getHeight()); - //glitch.renderFBO. - //xhair.getTextureReference().unbind(); - unbindTexture(glitch.renderFBO); - //views[i].end2d(); + unbindTexture(*texts[0]); + + bindTexture(*texts[1]); + ofDrawSphere(200,290,0,75); + unbindTexture(*texts[1]); + + bindTexture(*texts[2]); + ofDrawSphere(-70,340,175,44); + unbindTexture(*texts[2]); + ofSetColor(255, 255,255); + views[i].end(); } @@ -131,19 +208,20 @@ void ofApp::keyPressed(int key){ case 'z': loadSettings("defaults.xml"); break; - case ',': - case '<': - //prevMovie(); + case OF_KEY_LEFT: + mode=mode-1; + if (mode<0) mode=NUM_MODES-1; break; - case '.': - case '>': - //nextMovie(); + case OF_KEY_RIGHT: + mode=(mode+1)%NUM_MODES; break; case '/': //light=!light; //printf(light?"LIGHT ON\n":"LIGHT OFF\n"); break; } + if (mode==MODE_RUN) glDisable (GL_DEPTH_TEST); + else glEnable (GL_DEPTH_TEST); } void ofApp::keyReleased(int key){ |
