rt300@0
|
1 //
|
rt300@0
|
2 // pdSynthWrapper.h
|
rt300@6
|
3 // RIFTATHON
|
rt300@0
|
4 //
|
rt300@0
|
5 // Created by Robert Tubb on 14/01/2014.
|
rt300@0
|
6 //
|
rt300@0
|
7 //
|
rt300@0
|
8
|
rt300@6
|
9
|
rt300@6
|
10 // for riftathon, this is also a wrapper for the sequencer
|
rt300@0
|
11 #pragma once
|
rt300@0
|
12
|
rt300@0
|
13 #include "AppCore.h"
|
rt300@0
|
14 #include "eventLogger.h"
|
rt300@0
|
15 #include "ofxPd.h"
|
rt300@0
|
16 #include <string>
|
rt300@0
|
17 #include "boost/bind.hpp"
|
rt300@0
|
18 #include "boost/function.hpp"
|
rt300@0
|
19 #include "SynthParam.h"
|
rt300@11
|
20 #include "globalVariables.h"
|
rt300@0
|
21 //---------------------------------------------------------------------
|
rt300@0
|
22 //---------------------------------------------------------------------
|
rt300@0
|
23 //---------------------------------------------------------------------
|
rt300@0
|
24
|
rt300@0
|
25 class PDSynthWrapper {
|
rt300@0
|
26 public:
|
rt300@0
|
27 void init(AppCore* aCore, string sp){
|
rt300@0
|
28 core = aCore;
|
rt300@11
|
29
|
rt300@0
|
30 synthPrefix = sp;
|
rt300@0
|
31 // init all the params, refer to synth in pd patch
|
rt300@32
|
32 // riftathon_drum_synth
|
rt300@0
|
33 timbreParams.push_back(SynthParam(64,aCore,"Pitch",sp));
|
rt300@32
|
34 timbreParams.push_back(SynthParam(64,aCore,"PenvDecay",sp));
|
rt300@32
|
35 timbreParams.push_back(SynthParam(64,aCore,"DecayFM",sp));
|
rt300@32
|
36 timbreParams.push_back(SynthParam(64,aCore,"NzFrq1",sp));
|
rt300@32
|
37 timbreParams.push_back(SynthParam(64,aCore,"NzFrq2",sp));
|
rt300@32
|
38 timbreParams.push_back(SynthParam(64,aCore,"DecayNz",sp));
|
rt300@2
|
39
|
rt300@16
|
40 //timbreParams.push_back(SynthParam(64,aCore,"SPAM",sp));
|
rt300@16
|
41 //timbreParams.push_back(SynthParam(64,aCore,"FILTH",sp));
|
rt300@0
|
42 //timbreParams.push_back(SynthParam(64,aCore,"reson",sp));
|
rt300@0
|
43
|
rt300@0
|
44 if (timbreParams.size() != TOTAL_NUM_PARAMS){
|
rt300@0
|
45 cout << "ERROR ERROR: WRONG NUM OF timbreParams or TOTAL_NUM_PARAMS" << endl;
|
rt300@0
|
46 }
|
rt300@0
|
47 cout << "initialised synth: " << sp << " with " << timbreParams.size() << " params" << endl;
|
rt300@38
|
48 metronomeRunning = false;
|
rt300@0
|
49 };
|
rt300@15
|
50
|
rt300@15
|
51 // PD SENDERS
|
rt300@15
|
52
|
rt300@15
|
53 void trigger(){
|
rt300@15
|
54 // play the noise
|
rt300@15
|
55 List toPD;
|
rt300@15
|
56 toPD.addSymbol(synthPrefix);
|
rt300@15
|
57 toPD.addSymbol("playSound");
|
rt300@15
|
58 toPD.addFloat(1.0); // volume here, just in case??
|
rt300@15
|
59
|
rt300@15
|
60 core->pd.sendList("fromOF", toPD);
|
rt300@15
|
61
|
rt300@15
|
62 };
|
rt300@15
|
63
|
rt300@0
|
64 void sendAllParams(){
|
rt300@0
|
65 std::vector<SynthParam>::const_iterator psp;
|
rt300@0
|
66 for(psp = timbreParams.begin(); psp < timbreParams.end(); psp++){
|
rt300@0
|
67 psp->sendToPD();
|
rt300@0
|
68 }
|
rt300@0
|
69 }
|
rt300@0
|
70 void sendVolume(int value){
|
rt300@0
|
71 List toPD;
|
rt300@0
|
72 toPD.addSymbol(synthPrefix);
|
rt300@0
|
73 toPD.addSymbol("Volume");
|
rt300@0
|
74 toPD.addFloat(value); // rounding here??
|
rt300@0
|
75
|
rt300@0
|
76 core->pd.sendList("fromOF", toPD);
|
rt300@0
|
77 }
|
rt300@14
|
78
|
rt300@0
|
79 void setNoteLength(int lms){
|
rt300@0
|
80 List toPD;
|
rt300@0
|
81 toPD.addSymbol(synthPrefix);
|
rt300@0
|
82 toPD.addSymbol("noteLength");
|
rt300@0
|
83 toPD.addFloat(lms); // volume here, just in case??
|
rt300@0
|
84
|
rt300@0
|
85 core->pd.sendList("fromOF", toPD);
|
rt300@0
|
86 }
|
rt300@15
|
87
|
rt300@15
|
88 // GETTERS
|
rt300@0
|
89 const int getParamValueForID(int pid){
|
rt300@0
|
90 int v = 0;
|
rt300@0
|
91 std::vector<SynthParam>::const_iterator psp;
|
rt300@0
|
92 for(psp = timbreParams.begin(); psp < timbreParams.end(); psp++){
|
rt300@0
|
93 if (psp->getID() == pid){
|
rt300@0
|
94 v = psp->getValue();
|
rt300@0
|
95 return v;
|
rt300@0
|
96 }
|
rt300@0
|
97
|
rt300@0
|
98 }
|
rt300@0
|
99 cout << "ERROR ERROR getParamValueForID not found" << endl;
|
rt300@1
|
100 return -1;
|
rt300@0
|
101 }
|
rt300@0
|
102 const int getMappingIDForName(string name) const{
|
rt300@0
|
103
|
rt300@0
|
104 int rID = -1;
|
rt300@0
|
105 std::vector<SynthParam>::const_iterator psp;
|
rt300@0
|
106 for(psp = timbreParams.begin(); psp < timbreParams.end(); psp++){
|
rt300@0
|
107 if (psp->getName() == name){
|
rt300@0
|
108 rID = psp->getID();
|
rt300@0
|
109 return rID;
|
rt300@0
|
110 }
|
rt300@0
|
111
|
rt300@0
|
112 }
|
rt300@0
|
113 cout << "ERROR ERROR getMappingIDForName not found" << endl;
|
rt300@1
|
114 return -1;
|
rt300@0
|
115 };
|
rt300@0
|
116 const string getNameForMappingID(int pid) const{
|
rt300@0
|
117
|
rt300@0
|
118 string rname = "no name";
|
rt300@0
|
119 std::vector<SynthParam>::const_iterator psp;
|
rt300@0
|
120 for(psp = timbreParams.begin(); psp < timbreParams.end(); psp++){
|
rt300@0
|
121 if (psp->getID() == pid){
|
rt300@0
|
122 rname = psp->getName();
|
rt300@0
|
123 return rname;
|
rt300@0
|
124 }
|
rt300@0
|
125
|
rt300@0
|
126 }
|
rt300@0
|
127 cout << "ERROR ERROR getNameForMappingID not found" << endl;
|
rt300@1
|
128 return "error";
|
rt300@0
|
129 };
|
rt300@0
|
130 vector<int> getMappingIDForIndices(vector<int> idx){
|
rt300@0
|
131 vector<int> result;
|
rt300@0
|
132
|
rt300@0
|
133 for(int i = 0 ; i < idx.size(); i++){
|
rt300@0
|
134 if (idx[i] < timbreParams.size()){
|
rt300@0
|
135 int mapid = timbreParams[idx[i]].getID();
|
rt300@0
|
136
|
rt300@0
|
137 result.push_back(mapid);
|
rt300@0
|
138 //cout << " Map id for param no: " << idx[i] << " is " << *(result.end()-1);
|
rt300@0
|
139 }else{
|
rt300@0
|
140 cout << "ERROR ERROR: index bigger than num timbre params" << endl;
|
rt300@0
|
141
|
rt300@0
|
142 }
|
rt300@0
|
143 }
|
rt300@0
|
144 return result;
|
rt300@0
|
145 }
|
rt300@23
|
146 vector<int> getAllMappingIDs(){
|
rt300@23
|
147 vector<int> result;
|
rt300@23
|
148
|
rt300@23
|
149 for(int i = 0 ; i < timbreParams.size(); i++){
|
rt300@23
|
150 int mapid = timbreParams[i].getID();
|
rt300@23
|
151 result.push_back(mapid);
|
rt300@23
|
152
|
rt300@23
|
153 }
|
rt300@23
|
154 return result;
|
rt300@23
|
155 }
|
rt300@15
|
156
|
rt300@15
|
157 const int getParamValueFromName(string name) const{
|
rt300@15
|
158
|
rt300@15
|
159 int value = -1;
|
rt300@15
|
160 std::vector<SynthParam>::const_iterator psp;
|
rt300@15
|
161 for(psp = timbreParams.begin(); psp < timbreParams.end(); psp++){
|
rt300@15
|
162 if (psp->getName() == name){
|
rt300@15
|
163 value = psp->getValue();
|
rt300@15
|
164 return value;
|
rt300@15
|
165 }
|
rt300@15
|
166
|
rt300@15
|
167 }
|
rt300@15
|
168 cout << "ERROR ERROR: getParamValueFromName name not found" << endl;
|
rt300@15
|
169 return -1;
|
rt300@15
|
170 };
|
rt300@15
|
171
|
rt300@15
|
172 const int getNumParams(){
|
rt300@15
|
173 return timbreParams.size();
|
rt300@15
|
174 };
|
rt300@15
|
175
|
rt300@15
|
176 vector<int> getAllParamValues(){
|
rt300@15
|
177 vector<int> pl;
|
rt300@15
|
178 std::vector<SynthParam>::const_iterator psp;
|
rt300@15
|
179 for(psp = timbreParams.begin(); psp < timbreParams.end(); psp++){
|
rt300@15
|
180 pl.push_back(psp->getValue());
|
rt300@15
|
181 }
|
rt300@15
|
182 return pl;
|
rt300@15
|
183 }
|
rt300@41
|
184 int getIndexForMappingID(int mappingID){
|
rt300@41
|
185 std::vector<SynthParam>::iterator psp;
|
rt300@41
|
186 int i = 0;
|
rt300@41
|
187 for(psp = timbreParams.begin(); psp < timbreParams.end(); psp++){
|
rt300@41
|
188 if ( psp->getID() == mappingID){
|
rt300@41
|
189 return i;
|
rt300@41
|
190 }
|
rt300@41
|
191 i++;
|
rt300@41
|
192 }
|
rt300@41
|
193 }
|
rt300@9
|
194 void paramChangeCallback(int mappingID, int value, bool send = true){
|
rt300@0
|
195
|
rt300@0
|
196 // look for id in params
|
rt300@0
|
197 std::vector<SynthParam>::iterator psp;
|
rt300@0
|
198 for(psp = timbreParams.begin(); psp < timbreParams.end(); psp++){
|
rt300@0
|
199 if ( psp->getID() == mappingID){
|
rt300@9
|
200 if (send){
|
rt300@9
|
201 psp->setValue(value);
|
rt300@9
|
202 }else{
|
rt300@9
|
203 psp->setValueWithoutSend(value);
|
rt300@9
|
204 }
|
rt300@0
|
205 return;
|
rt300@0
|
206 }
|
rt300@0
|
207 }
|
rt300@0
|
208 cout << "ERROR ERROR: paramChangeCallback mappingID not found" << endl;
|
rt300@0
|
209 };
|
rt300@0
|
210
|
rt300@15
|
211 // SETTERS
|
rt300@0
|
212 void randomiseParams(){
|
rt300@0
|
213
|
rt300@0
|
214 cout << " randomising" << endl;
|
rt300@0
|
215 std::vector<SynthParam>::iterator psp;
|
rt300@0
|
216 for(psp = timbreParams.begin(); psp < timbreParams.end(); psp++){
|
rt300@0
|
217
|
rt300@0
|
218 int value = ofRandom(0,127);
|
rt300@0
|
219 psp->setValue(value);
|
rt300@0
|
220
|
rt300@0
|
221 }
|
rt300@0
|
222
|
rt300@0
|
223 };
|
rt300@0
|
224
|
rt300@0
|
225 void setSameAsOtherSynth(const PDSynthWrapper* otherSynth){
|
rt300@0
|
226 // loop thru all params and set them to other synth
|
rt300@0
|
227 std::vector<SynthParam>::iterator psp;
|
rt300@0
|
228 for(psp = timbreParams.begin(); psp < timbreParams.end(); psp++){
|
rt300@0
|
229 psp->setValue(otherSynth->getParamValueFromName(psp->getName()));
|
rt300@0
|
230
|
rt300@0
|
231 }
|
rt300@0
|
232 };
|
rt300@0
|
233
|
rt300@0
|
234 vector<int> randomiseParamSubset(int howMany){
|
rt300@0
|
235 vector<int> randomisedIDs;
|
rt300@0
|
236 for (int i=0;i<howMany;i++){
|
rt300@0
|
237
|
rt300@0
|
238 int value = ofRandom(0,127);
|
rt300@0
|
239 timbreParams[i].setValue(value);
|
rt300@0
|
240 randomisedIDs.push_back(i);
|
rt300@0
|
241
|
rt300@0
|
242 }
|
rt300@0
|
243 return randomisedIDs;
|
rt300@0
|
244
|
rt300@0
|
245 };
|
rt300@15
|
246
|
rt300@0
|
247
|
rt300@0
|
248 void setAllParams(vector<int> params){
|
rt300@0
|
249 if(params.size() != timbreParams.size()){
|
rt300@0
|
250 cout << "Error not right number of params in set in synth" << endl;
|
rt300@0
|
251 return;
|
rt300@0
|
252 }
|
rt300@0
|
253 std::vector<SynthParam>::iterator psp;
|
rt300@0
|
254 int i=0;
|
rt300@0
|
255 for(psp = timbreParams.begin(); psp < timbreParams.end(); psp++){
|
rt300@0
|
256 psp->setValue(params[i]);
|
rt300@0
|
257 i++;
|
rt300@0
|
258 }
|
rt300@0
|
259
|
rt300@0
|
260
|
rt300@0
|
261 }
|
rt300@31
|
262 void setAllParamsWithoutSend(vector<int> params){
|
rt300@31
|
263 if(params.size() != timbreParams.size()){
|
rt300@31
|
264 cout << "Error not right number of params in set in synth" << endl;
|
rt300@31
|
265 return;
|
rt300@31
|
266 }
|
rt300@31
|
267 std::vector<SynthParam>::iterator psp;
|
rt300@31
|
268 int i=0;
|
rt300@31
|
269 for(psp = timbreParams.begin(); psp < timbreParams.end(); psp++){
|
rt300@31
|
270 psp->setValueWithoutSend(params[i]);
|
rt300@31
|
271 i++;
|
rt300@31
|
272 }
|
rt300@31
|
273
|
rt300@31
|
274
|
rt300@31
|
275 }
|
rt300@15
|
276 // METRONOME STUFF
|
rt300@11
|
277 void registerForTicks(TickListenerFunction callback){
|
rt300@11
|
278
|
rt300@11
|
279 core->addTickListener(callback);
|
rt300@11
|
280 }
|
rt300@6
|
281 void startMetronome(){
|
rt300@6
|
282 // play the noise
|
rt300@6
|
283 List toPD;
|
rt300@6
|
284 core->pd.sendMessage("fromOF", "startMetro", toPD);
|
rt300@38
|
285 metronomeRunning = true;
|
rt300@6
|
286 }
|
rt300@12
|
287 void stopMetronome(){
|
rt300@12
|
288 // play the noise
|
rt300@12
|
289 List toPD;
|
rt300@12
|
290 core->pd.sendMessage("fromOF", "stopMetro", toPD);
|
rt300@38
|
291 metronomeRunning = false;
|
rt300@38
|
292 }
|
rt300@38
|
293 bool isMetronomeRunning(){
|
rt300@38
|
294 return metronomeRunning;
|
rt300@12
|
295 }
|
rt300@14
|
296 void setMetroTime(float t){
|
rt300@14
|
297 List toPD;
|
rt300@14
|
298 toPD.addSymbol("setMetroTime");
|
rt300@14
|
299 toPD.addFloat(t); // rounding here??
|
rt300@14
|
300
|
rt300@14
|
301 core->pd.sendList("fromOF", toPD);
|
rt300@14
|
302 }
|
rt300@37
|
303 void playDownbeatBlip(){
|
rt300@37
|
304 List toPD;
|
rt300@37
|
305 core->pd.sendMessage("fromOF", "blip", toPD);
|
rt300@37
|
306 }
|
rt300@11
|
307 void onTick(int tickNo){
|
rt300@11
|
308 //
|
rt300@11
|
309
|
rt300@11
|
310 };
|
rt300@6
|
311
|
rt300@0
|
312 private:
|
rt300@0
|
313 string synthPrefix;
|
rt300@0
|
314 AppCore* core;
|
rt300@0
|
315 vector<SynthParam> timbreParams; // array of everything in synth
|
rt300@38
|
316 bool metronomeRunning;
|
rt300@0
|
317 };
|
rt300@0
|
318
|
rt300@0
|
319 //---------------------------------------------------------------------
|
rt300@0
|
320 //--------------------------------------------------------------------- |