From 809d05f2b17409c0b18951c0107c7fc275621b0c Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Wed, 29 May 2013 14:47:17 +0100 Subject: drag drop palettes --- src/testApp.cpp | 89 ++++++++++++++++++++++++++++++++++++--------------------- src/testApp.h | 2 +- src/viewport.h | 16 ++++++----- 3 files changed, 66 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/testApp.cpp b/src/testApp.cpp index 72762ce..c24f1ac 100755 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -8,10 +8,25 @@ void previewWindow::setParent(testApp *p){ } void previewWindow::draw(){ - for (auto i:parent->viewports) i.draw(parent->brightSlider,parent->previewscale); + for (auto i:parent->viewports) i.draw(parent->brightSlider,previewscale); } void previewWindow::dragEvent(ofDragInfo dragInfo, ofxFenster* win){ + if (parent->viewports.size()){ + int sta=dragInfo.files[0].find_last_of("\\/")+1; + int len=(dragInfo.files[0].find_last_of(".")+4)-sta; + string f=dragInfo.files[0].substr(sta,len); + + float dx=(dragInfo.position.x-win->getWindowPosition().x)/previewscale; + float dy=(dragInfo.position.y-win->getWindowPosition().y)/previewscale; + + int which=dx/parent->viewports[0].w; + if (parent->viewports.size()==8&&dy>windowsize) which+=4; + + cerr<<"drag received at "<loadPalette(f,which); + } parent->dragEvent(dragInfo); } @@ -28,21 +43,28 @@ void guiWindow::draw(){ parent->gui.draw(); } -void guiWindow::dragEvent(ofDragInfo dragInfo, ofxFenster* win){ - int sta=dragInfo.files[0].find_last_of("\\/")+1; - int len=(dragInfo.files[0].find_last_of(".")+4)-sta; - string filename=dragInfo.files[0].substr(sta,len); - +void testApp::loadPalette(string &filename,int whichport){ if (filename.length()) { palette p; if (p.load(filename)) { printf("loaded %s\n",filename.c_str()); - for (int i=0;iviewports.size();i++) { - parent->viewports[i].Palette=p; + if (whichport==-1) { + for (int i=0;iloadPalette(f,-1); + parent->dragEvent(dragInfo); } //-------------------------------------------------------------- @@ -55,13 +77,15 @@ void testApp::backupPalettes(){ } } void testApp::restorePalettes(){ - for (int i=0;isetup(); guiWin->setParent(this); - + soundStream.listDevices(); - - //if you want to set a different device id + + //if you want to set a different device id //soundStream.setDeviceID(4); //bear in mind the device id corresponds to all audio devices, including input-only and output-only devices. - - - - + + + + soundStream.setup(this, 0, 2, 44100, bufferSize, 4); } //-------------------------------------------------------------- -void testApp::audioIn(float * input, int bufferSize, int nChannels){ - +void testApp::audioIn(float * input, int bufferSize, int nChannels){ + float curVol = 0.0; - + // samples are "interleaved" - int numCounted = 0; + int numCounted = 0; - //lets go through each sample and calculate the root mean square which is a rough way to calculate volume + //lets go through each sample and calculate the root mean square which is a rough way to calculate volume for (int i = 0; i < bufferSize; i++){ control.left[i] = input[i*2]*0.5; control.right[i] = input[i*2+1]*0.5; @@ -216,18 +239,18 @@ void testApp::audioIn(float * input, int bufferSize, int nChannels){ curVol += control.right[i] * control.right[i]; numCounted+=2; } - - //this is how we get the mean of rms :) + + //this is how we get the mean of rms :) curVol /= (float)numCounted; - - // this is how we get the root of rms :) + + // this is how we get the root of rms :) curVol = sqrt( curVol ); - + control.smoothedVol *= 0.93; control.smoothedVol += 0.07 * curVol; - + control.bufferCounter++; - + } @@ -325,12 +348,12 @@ void testApp::gotMessage(ofMessage msg){ //-------------------------------------------------------------- void testApp::dragEvent(ofDragInfo dragInfo, ofxFenster* win){ - + dragEvent(dragInfo); } void testApp::dragEvent(ofDragInfo dragInfo){ - + } diff --git a/src/testApp.h b/src/testApp.h index 037cbf7..250198e 100755 --- a/src/testApp.h +++ b/src/testApp.h @@ -90,11 +90,11 @@ class testApp : public ofxFensterListener { void backupPalettes(); void restorePalettes(); + void loadPalette(string &filename,int whichport); vector backups; vector viewports; vpcontrol control; - int previewscale; // diff --git a/src/viewport.h b/src/viewport.h index 1e3e8a8..88e9835 100755 --- a/src/viewport.h +++ b/src/viewport.h @@ -5,8 +5,9 @@ #include "ofxXmlSettings.h" static int bufferSize = 2048; -static int oversample = 8; +static int oversample = 8; static int windowsize = 32; +static int previewscale = 5; //make sure that windowsize*oversample*8 <= buffersize @@ -82,14 +83,14 @@ class vpcontrol { left.assign(bufferSize, 0.0); right.assign(bufferSize, 0.0); volHistory.assign(400, 0.0); - + bufferCounter = 0; drawCounter = 0; smoothedVol = 0.0; scaledVol = 0.0; } void update(){ - //lets scale the vol up to a 0-1 range + //lets scale the vol up to a 0-1 range scaledVol = ofMap(smoothedVol, 0.0, 0.17, 0.0, 1.0, true); //lets record the volume into an array @@ -112,10 +113,10 @@ class vpcontrol { vector left; vector right; vector volHistory; - + int bufferCounter; int drawCounter; - + float smoothedVol; float scaledVol; }; @@ -130,10 +131,11 @@ class viewport void drawport(vpcontrol &control); void draw(uint8_t brightness,float scale=1.0f); ofFbo rb1,rb2; - palette Palette; + palette Palette; + int w,h; protected: private: - int x,y,w,h,bw,bh,ox,oy,num; + int x,y,bw,bh,ox,oy,num; float seed; }; -- cgit v1.2.3