diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-05-29 14:47:17 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-05-29 14:47:17 +0100 |
| commit | 809d05f2b17409c0b18951c0107c7fc275621b0c (patch) | |
| tree | c26fff53e0b324f2fda14898db729c4f9816a136 /src | |
| parent | 296e1ecf1d4402166bb0d958980f8bf0faba4f5f (diff) | |
drag drop palettes
Diffstat (limited to 'src')
| -rwxr-xr-x | src/testApp.cpp | 89 | ||||
| -rwxr-xr-x | src/testApp.h | 2 | ||||
| -rwxr-xr-x | src/viewport.h | 16 |
3 files changed, 66 insertions, 41 deletions
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 "<<dx<<","<<dy<<" ,loading into window "<<which<<endl; + + parent->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;i<parent->viewports.size();i++) { - parent->viewports[i].Palette=p; + if (whichport==-1) { + for (int i=0;i<viewports.size();i++) { + viewports[i].Palette=p; + } } + else viewports[whichport].Palette=p; } else printf("could not load %s\n",filename.c_str()); } +} +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 f=dragInfo.files[0].substr(sta,len); + + parent->loadPalette(f,-1); + parent->dragEvent(dragInfo); } //-------------------------------------------------------------- @@ -55,13 +77,15 @@ void testApp::backupPalettes(){ } } void testApp::restorePalettes(){ - for (int i=0;i<viewports.size();i++){ - viewports[i].Palette=backups[i%backups.size()]; + if (backups.size()){ + for (int i=0;i<viewports.size();i++){ + viewports[i].Palette=backups[i%backups.size()]; + } } } void testApp::create1port(bool & pressed){ if (!pressed) return; - backupPalettes(); + backupPalettes(); viewports.clear(); viewports.push_back(viewport(4*windowsize,2*windowsize,0,0,0)); createports(1); @@ -105,7 +129,6 @@ void testApp::createports(int num){ //-------------------------------------------------------------- void testApp::setup(){ - previewscale=5; showFPS=false; ofBackground(0,0,0); @@ -185,29 +208,29 @@ void testApp::setup(){ guiWin->setup(); 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<palette> backups; vector<viewport> 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 <float> left;
vector <float> right;
vector <float> 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;
};
|
