summaryrefslogtreecommitdiff
path: root/src/testApp.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2013-05-29 14:47:17 +0100
committerTim Redfern <tim@eclectronics.org>2013-05-29 14:47:17 +0100
commit809d05f2b17409c0b18951c0107c7fc275621b0c (patch)
treec26fff53e0b324f2fda14898db729c4f9816a136 /src/testApp.cpp
parent296e1ecf1d4402166bb0d958980f8bf0faba4f5f (diff)
drag drop palettes
Diffstat (limited to 'src/testApp.cpp')
-rwxr-xr-xsrc/testApp.cpp89
1 files changed, 56 insertions, 33 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){
-
+
}