changeset 45:c2fffc8ea84d

10 timbre params.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Tue, 23 Apr 2013 18:29:55 +0100
parents a1e75b94c505
children 1e266647840d
files AppCore.h AppCore.mm SliderViewController.h SliderViewController.mm TopButtonViewController.xib grid.mm presetManager.h testApp.h testApp.mm
diffstat 9 files changed, 286 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/AppCore.h	Mon Apr 22 18:32:34 2013 +0100
+++ b/AppCore.h	Tue Apr 23 18:29:55 2013 +0100
@@ -20,7 +20,7 @@
 class AppCore : public PdReceiver, public PdMidiReceiver {
 
 	public:
-
+        string patchName;
 		// main
 		void setup(const int numOutChannels, const int numInChannels,
 				   const int sampleRate, const int ticksPerBuffer);
--- a/AppCore.mm	Mon Apr 22 18:32:34 2013 +0100
+++ b/AppCore.mm	Tue Apr 23 18:29:55 2013 +0100
@@ -50,7 +50,8 @@
 	pd.start();
 
 	// open patch
-	Patch patch = pd.openPatch("synth5param.pd");
+    patchName = "synth10param.pd";
+	Patch patch = pd.openPatch(patchName);
 	cout << patch << endl;
 
 
--- a/SliderViewController.h	Mon Apr 22 18:32:34 2013 +0100
+++ b/SliderViewController.h	Tue Apr 23 18:29:55 2013 +0100
@@ -17,6 +17,7 @@
 - (void)slider:(int)which changedTo:(float)value;
 - (void)setSlider:(int)which to:(float)value;
 @property (retain,nonatomic) NSMutableArray *paramNames;
+@property (retain,nonatomic) NSMutableArray *paramNamesTimbre;
 @property (retain,nonatomic) NSMutableArray * sliderArray;
 
 @end
--- a/SliderViewController.mm	Mon Apr 22 18:32:34 2013 +0100
+++ b/SliderViewController.mm	Tue Apr 23 18:29:55 2013 +0100
@@ -15,6 +15,8 @@
 
 @implementation SliderViewController
 
+
+// init with either sequencer or all timbre
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
 {
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
@@ -103,11 +105,15 @@
 }
 - (void)populateParamNames{
     
-    
+    /*
     self.paramNames = [NSArray arrayWithObjects:
                        @"Transpose",@"1/4 note",@"1/6 note",@"1/7 note",@"1/8 note",
-                       @"Waveform",@"Filter Type",@"Filter Cutoff",@"Envelope",@"FM amount",
+                       @"Waveform",@"Filter Type",@"Filter Cutoff",@"Envelope",@"FM freq",
                        nil];
-    
+    */
+    self.paramNames = [NSArray arrayWithObjects:
+                       @"Amp Env",@"Waveform",@"FM amount",@"FM frequency",@"Reverb",
+                       @"Filter Type",@"Filter Cut off",@"Filter Resonance",@"Filter Env Shape",@"Filt Env Amount",
+                       nil];
 }
 @end
--- a/TopButtonViewController.xib	Mon Apr 22 18:32:34 2013 +0100
+++ b/TopButtonViewController.xib	Tue Apr 23 18:29:55 2013 +0100
@@ -95,7 +95,6 @@
 								<int key="IBUISystemItemIdentifier">18</int>
 							</object>
 							<object class="IBUIBarButtonItem" id="552018169">
-								<bool key="IBUIEnabled">NO</bool>
 								<string key="targetRuntimeIdentifier">IBIPadFramework</string>
 								<int key="IBUIStyle">1</int>
 								<reference key="IBUIToolbar" ref="358683122"/>
--- a/grid.mm	Mon Apr 22 18:32:34 2013 +0100
+++ b/grid.mm	Tue Apr 23 18:29:55 2013 +0100
@@ -535,17 +535,19 @@
 //--------------------------------------------------------------
 void Grid::snapCheck(){
     lEvent *closestEvalPt;
-    if(interpolateMode == INTERPOLATE_GRID){
-        snapped = false;
-        closestPreset = NULL;
-        snapCentre = centre;
-        return;
-    } // no presets visible
+
     
     // check environs for presets.
     
     vector<Preset *> closePresets = presetManager.getPresetsInRange(centre - snapDist*scale, centre + snapDist*scale);
     if(closePresets.size() > 0){
+        if(interpolateMode == INTERPOLATE_GRID){
+            snapped = false;
+            closestPreset = NULL;
+            snapCentre = centre;
+            return;
+        } // no presets visible
+        
         snapped = true;
         presetWasTapped = false;
         closestPreset = getClosestPresetOf(closePresets);
@@ -554,6 +556,7 @@
 
        
     }else{
+        // look for evaluation points
         // do an evaluation snap check . duplicate code >:[
 
         vector<lEvent *> closeEvalPoints = eventLogger.getEvaluationPointsInRange(centre - snapDist*scale, centre + snapDist*scale);
--- a/presetManager.h	Mon Apr 22 18:32:34 2013 +0100
+++ b/presetManager.h	Tue Apr 23 18:29:55 2013 +0100
@@ -40,6 +40,7 @@
     vector<ofColor> pixVals; // hmmm
     TwoVector       coordinates;  // position on grid
     vector<int>     params;         // actual parameters???
+    int whichSequence;
     // not so important - not uploaded
     
     // from save button press
@@ -53,6 +54,7 @@
 
         cout << "Create preset sys time: " << creationTime << "\n";
         pixVals = makePresetPicture(coordinates);
+        //whichSequence = seq;
     
     };
     // from json value
--- a/testApp.h	Mon Apr 22 18:32:34 2013 +0100
+++ b/testApp.h	Tue Apr 23 18:29:55 2013 +0100
@@ -166,9 +166,15 @@
     void sendFiltType(int ctrlin);
     void sendFiltFreq(int ctrlin);
     void sendEnvShape(int ctrlin);
+    void sendResonance(int ctrlin);
     void sendAmpEnvShape(int ctrlin);
     void sendFiltEnvShape(int ctrlin);
     void sendModFreq(int ctrlin);
+    void sendFMAmt(int ctrlin);
+    void sendDistortion(int ctrlin);
+    void sendRevAmt(int ctrlin);
+    void sendFiltEnvModAmt(int ctrlin);
+    
     void sendMidiParams();
     void sendMidiParam(int which);
     ofxUICanvas *zoomGUI;
@@ -201,6 +207,8 @@
 	int note, ctl;
 	vector<unsigned char> bytes;
     
+    void sendFiltTypeOld(int ctrlin);
+    
 };
 
 // should be off split into
--- a/testApp.mm	Mon Apr 22 18:32:34 2013 +0100
+++ b/testApp.mm	Tue Apr 23 18:29:55 2013 +0100
@@ -552,52 +552,90 @@
 #pragma mark sending to pd and midi
 void testApp::sendParametersToPD(){
     static int previousSequence;
-    // frequencer stuff to get 16 steps
     
-     vector<double> vals;
-     
-     
-     vals.push_back((sliderVals[0]+32)*8.); // DC offset
-     for(int i=1; i<5;i++){
-     vals.push_back((sliderVals[i] - 64)*2.);
-     }
-    
-    vector<double> steps = frequencer.freqMagEdit(freqIndexes, vals);
-    List seqSteps;
-    seqSteps.addSymbol("seqSteps");
-    for(int i=0; i < 16; i++){
-        seqSteps.addFloat(round(steps[i]));
+    if(core.patchName == "synth5paramMM.pd"){
+        // frequencer stuff to get 16 steps
+        
+        vector<double> vals;
+        
+        
+        vals.push_back((sliderVals[0]+32)*8.); // DC offset
+        for(int i=1; i<5;i++){
+            vals.push_back((sliderVals[i] - 64)*2.);
+        }
+        
+        vector<double> steps = frequencer.freqMagEdit(freqIndexes, vals);
+        List seqSteps;
+        seqSteps.addSymbol("seqSteps");
+        for(int i=0; i < 16; i++){
+            seqSteps.addFloat(round(steps[i]));
+        }
+        core.pd.sendList("fromOF", seqSteps);
+        
+        
+        // send synth params
+        sendOscShape(sliderVals[5]);
+        sendFiltType(sliderVals[6]);
+        sendFiltFreq(sliderVals[7]);
+        sendEnvShape(sliderVals[8]);
+        sendModFreq(sliderVals[9]);
+        
+    }else if (core.patchName == "synth10param.pd"){
+        // for 10 param synth we get sequence from saved presets
+        // and send 5 extra synth params
+        if(currentSequence != previousSequence){
+            List seqSteps;
+            
+            seqSteps.addSymbol("seqSteps");
+            if(currentSequence >= sequences.size() || currentSequence < 0){
+                cout << "ERROR: not a valid sequence index\n";
+                for(int i=0; i < 16; i++){
+                    seqSteps.addFloat(50);
+                }
+            }else{
+                for(int i=0; i < 16; i++){
+                    seqSteps.addFloat(round(sequences[currentSequence][i]));
+                }
+            }
+            
+            core.pd.sendList("fromOF", seqSteps);
+            previousSequence = currentSequence;
+        }
+        /*
+         @"Amp Env",@"Waveform",@"FM amount",@"FM frequency",@"Reverb",
+         @"Filter Type",@"Filter Cut off",@"Filter Resonance",@"Filter Envelope",@"SOMETHING",
+         */
+        // send synth params
+        sendAmpEnvShape(sliderVals[0]);
+        sendOscShape(sliderVals[1]);
+        sendFMAmt(sliderVals[2]);
+        sendModFreq(sliderVals[3]);
+        sendRevAmt(sliderVals[4]);
+        
+        sendFiltType(sliderVals[5]);
+        sendFiltFreq(sliderVals[6]);
+        sendResonance(sliderVals[7]);
+        sendFiltEnvShape(sliderVals[8]);
+        sendFiltEnvModAmt(sliderVals[9]);
+        //sendUmame(sliderVals[8]);
+        //sendX(sliderVals[2]);
+        //sendX(sliderVals[3]);
+        
+        
+        
+
+        
+        
     }
-    core.pd.sendList("fromOF", seqSteps);
+
 
     /*
-    if(currentSequence != previousSequence){
-        List seqSteps;
-        
-        seqSteps.addSymbol("seqSteps");
-        if(currentSequence >= sequences.size() || currentSequence < 0){
-            cout << "ERROR: not a valid sequence index\n";
-            for(int i=0; i < 16; i++){
-                seqSteps.addFloat(50);
-            }
-        }else{
-            for(int i=0; i < 16; i++){
-                seqSteps.addFloat(round(sequences[currentSequence][i]));
-            }
-        }
-        
-        core.pd.sendList("fromOF", seqSteps);
-        previousSequence = currentSequence;
+    cout << "SLIDERVALS: ";
+    for(int i=0;i<10;i++){
+        cout << sliderVals[i] << ",";
     }
-     */
-    
-    // send synth params
-    sendOscShape(sliderVals[5]);
-    sendFiltType(sliderVals[6]);
-    sendFiltFreq(sliderVals[7]);
-    sendEnvShape(sliderVals[8]);
-    sendModFreq(sliderVals[9]);
-
+    cout << '\n';
+    */
     
 }
 //--------------------------------------------------------------
@@ -1009,6 +1047,9 @@
     return y0;
 }
 //---------------------------------------------------------------
+//---------------------------------------------------------------
+//---------------------------------------------------------------
+#pragma mark SYNTH PARAM SENDING TO PD CURVES 
 void testApp::sendOscShape(int ctrlin){
     if(ctrlin < 0 || ctrlin > 127){
         cout << "ERROR: bad slider value!";
@@ -1019,13 +1060,13 @@
     static int numcontrols = 5;
     //float values[points][controls] =
     float ctrlout[numcontrols];
-    string ctrlName[5] = {"pWidth" , "sqVol", "sawVol", "sineVol", "FMAmt"};
-    float values[5][5] =
-    {{0.5, 0., 0., 1., 1.}, // 0
-        {0.5, 0., 0., 1., 0.},  // 32
-        {0.5, 0., 1., 0., 0.},  // 64
-        {0.5, 1., 1., 0., 0.},  // 96
-        {0.01,1., 1., 0., 0.}}; // 127
+    string ctrlName[4] = {"pWidth" , "sqVol", "sawVol", "sineVol"};
+    float values[5][4] =
+    {{0.5, 0., 0., 1.}, // 0
+        {0.5, 0., 0., 1.},  // 32
+        {0.5, 0., 1., 0.},  // 64
+        {0.5, 1., 1., 0.},  // 96
+        {0.01,1., 1., 0.}}; // 127
     
     float fidx = (numpoints-1)*ctrlin/128.;
     int idx = floor(fidx);
@@ -1049,6 +1090,49 @@
         cout << "ERROR: bad slider value!";
         return;
     }
+    /*
+    static int numpoints = 3;
+    static int numcontrols = 2;
+    //float values[points][controls] =
+    float ctrlout[numcontrols];
+    string ctrlName[2] = {"fType","reson"};
+    float values[3][2] =
+    {{0., 45}, // 0
+        {0.5, 120},  // 64
+        {1., 55}}; // 127
+      */
+    
+    static int numpoints = 2;
+    static int numcontrols = 1;
+    //float values[points][controls] =
+    float ctrlout[numcontrols];
+    string ctrlName[2] = {"fType"};
+    float values[2][1] =
+    {{0.}, // 0
+        {1.},}; // 127
+    
+    float fidx = (numpoints-1)*ctrlin/128.;
+    int idx = floor(fidx);
+    float frac = fidx - idx;
+
+    for(int i=0; i < numcontrols; i++){
+        ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
+        // send to PD
+        List toPD;
+        
+        toPD.addSymbol(ctrlName[i]);
+        toPD.addFloat(ctrlout[i]); // rounding here??
+        
+        core.pd.sendList("fromOF", toPD);
+        //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
+    }
+}
+//---------------------------------------------------------------
+void testApp::sendFiltTypeOld(int ctrlin){
+    if(ctrlin < 0 || ctrlin > 127){
+        cout << "ERROR: bad slider value!";
+        return;
+    }
     static int numpoints = 3;
     static int numcontrols = 4;
     //float values[points][controls] =
@@ -1192,6 +1276,21 @@
     }
 }
 //---------------------------------------------------------------
+void testApp::sendFiltEnvModAmt(int ctrlin){
+    if(ctrlin < 0 || ctrlin > 127){
+        cout << "ERROR: bad slider value!";
+        return;
+    }
+    float amt = ctrlin/127.0;
+    List toPD;
+    
+    toPD.addSymbol("fenv");
+    toPD.addSymbol("amount");
+    toPD.addFloat(amt); // rounding here??
+    
+    core.pd.sendList("fromOF", toPD);
+}
+//---------------------------------------------------------------
 void testApp::sendModFreq(int ctrlin){
     if(ctrlin < 0 || ctrlin > 127){
         cout << "ERROR: bad slider value!";
@@ -1206,9 +1305,110 @@
     core.pd.sendList("fromOF", toPD);
 }
 //---------------------------------------------------------------
+//---------------------------------------------------------------
+void testApp::sendRevAmt(int ctrlin){
+    if(ctrlin < 0 || ctrlin > 127){
+        cout << "ERROR: bad slider value!";
+        return;
+    }
+    static int numpoints = 5;
+    static int numcontrols = 2;
+    //float values[points][controls] =
+    float ctrlout[numcontrols];
+    string ctrlName[3] = {"revDryWet" , "revLength"};
+    float values[5][3] =
+        {{0., 0.1}, // 0
+        {0., 0.1},  // 32
+        {0.3, 30.},  // 64
+        {0.6, 60.},  // 96
+        {1., 95.}}; // 127
+    
+    float fidx = (numpoints-1)*ctrlin/128.;
+    int idx = floor(fidx);
+    float frac = fidx - idx;
+    for(int i=0; i < numcontrols; i++){
+        ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
+        // send to PD
+        List toPD;
+        toPD.addSymbol(ctrlName[i]);
+        toPD.addFloat(ctrlout[i]); // rounding here??
+        
+        core.pd.sendList("fromOF", toPD);
+        //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
+    }
 
-
-
+}
+//---------------------------------------------------------------
+void testApp::sendResonance(int ctrlin){
+    if(ctrlin < 0 || ctrlin > 127){
+        cout << "ERROR: bad slider value!";
+        return;
+    }
+    float res = ctrlin;
+    List toPD;
+    
+    toPD.addSymbol("reson");
+    toPD.addFloat(res); // rounding here??
+    
+    core.pd.sendList("fromOF", toPD);
+}
+//---------------------------------------------------------------------------
+void testApp::sendFMAmt(int ctrlin){
+    static int numpoints = 4;
+    static int numcontrols = 1;
+    //float values[points][controls] =
+    float ctrlout[numcontrols];
+    string ctrlName[1] = {"FMAmt"};
+    float values[4][1] =
+    {{0.}, // 0
+        {0.},  // 
+        {0.3},  //
+        {1.}}; // 127
+    
+    float fidx = (numpoints-1)*ctrlin/128.;
+    int idx = floor(fidx);
+    float frac = fidx - idx;
+    for(int i=0; i < numcontrols; i++){
+        ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
+        // send to PD
+        List toPD;
+        toPD.addSymbol(ctrlName[i]);
+        toPD.addFloat(ctrlout[i]); // rounding here??
+        
+        core.pd.sendList("fromOF", toPD);
+        //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
+    }
+}
+//---------------------------------------------------------------------------
+void testApp::sendDistortion(int ctrlin){
+    static int numpoints = 5;
+    static int numcontrols = 2;
+    //float values[points][controls] =
+    float ctrlout[numcontrols];
+    string ctrlName[2] = {"sigGain", "sineGain"};
+    float values[5][2] =
+    {{0., 0.}, // 0
+        {0., 0.},  //
+        {20, 0.},  //
+        {45 , 0.},  //
+        {0, 18}}; // 127
+    
+    float fidx = (numpoints-1)*ctrlin/128.;
+    int idx = floor(fidx);
+    float frac = fidx - idx;
+    for(int i=0; i < numcontrols; i++){
+        ctrlout[i] = (1 - frac)*values[idx][i] + (frac)*values[idx+1][i];
+        // send to PD
+        List toPD;
+        toPD.addSymbol(ctrlName[i]);
+        toPD.addFloat(ctrlout[i]); // rounding here??
+        
+        core.pd.sendList("fromOF", toPD);
+        //cout << ctrlName[i] << "sending" << ctrlout[i] << "\n";
+    }
+}
+//---------------------------------------------------------------------------
+//===========================================================================
 //---------------------------------------------------------------------------
 void saveSequences(){
     ofFile sequenceFile(ofxiPhoneGetDocumentsDirectory() + "pilot_sequences.json" ,ofFile::WriteOnly);
@@ -1254,7 +1454,10 @@
 void testApp::loadSequences(){
     
     // read in sequence preset file
-    string jsonFile = ofxiPhoneGetDocumentsDirectory() + "pilot_sequences.json";
+    string jsonFile = ofFilePath::getAbsolutePath(ofToDataPath("pilot_sequences.json"));
+
+    cout << "SQUENCES FILE: " << jsonFile << "\n";
+    //string jsonFile = ofxiPhoneGetDocumentsDirectory() + "pilot_sequences.json";
     
     Json::Value root;
     Json::Reader reader;