rt300@0
|
1 //
|
rt300@0
|
2 // MessageOrganiser.h
|
rt300@0
|
3 // tweakathlon
|
rt300@0
|
4 //
|
rt300@0
|
5 // Created by Robert Tubb on 10/12/2013.
|
rt300@0
|
6 //
|
rt300@0
|
7 // This object handles the mapping from GUI to params
|
rt300@0
|
8 //
|
rt300@0
|
9 // and sends their messages to PD and eventLogger
|
rt300@0
|
10 #pragma once
|
rt300@0
|
11 #include "eventLogger.h"
|
rt300@0
|
12 #include <map.h>
|
rt300@0
|
13 #include <vector>
|
rt300@0
|
14 #include <string>
|
rt300@0
|
15 #include "boost/bind.hpp"
|
rt300@0
|
16 #include "boost/function.hpp"
|
rt300@0
|
17
|
rt300@0
|
18 #include <UIElement.h>
|
rt300@0
|
19 #include <Buttron.h>
|
rt300@0
|
20 #include <ButtronSlider.h>
|
rt300@0
|
21 #include <ButtronXY.h>
|
rt300@0
|
22 #include "TestController.h"
|
rt300@0
|
23 #include "timeController.h"
|
rt300@0
|
24 #include "PDSynthWrapper.h"
|
rt300@0
|
25 #include "ofxTimer.h"
|
rt300@0
|
26 #include "sliderPanel.h"
|
rt300@0
|
27 //#include "testApp.h"
|
rt300@0
|
28 #include "targetSymbol.h"
|
rt300@0
|
29 #include "3Dbox.h"
|
rt300@0
|
30 #include "TextPanel.h"
|
rt300@0
|
31 #include "CountdownText.h"
|
rt300@0
|
32 #include "buttonPanel.h"
|
rt300@6
|
33 #include "ExplorePresetManager.h"
|
rt300@16
|
34 #include "IconPanel.h"
|
rt300@6
|
35
|
rt300@6
|
36 // should be called TIMED TEST MESSAGE ORGANISER ?
|
rt300@0
|
37
|
rt300@0
|
38 // event logger needs to know
|
rt300@0
|
39 // which controls were showing in what mode
|
rt300@0
|
40 // which controls were mapped to what param
|
rt300@0
|
41 // what was the target sound params
|
rt300@0
|
42 // all the updates of control movements, submit, quit etc
|
rt300@0
|
43
|
rt300@0
|
44 // this is the bit that handles mapping from UI elements to synth i.e testApp DOESNT DO THAT
|
rt300@0
|
45
|
rt300@0
|
46 // has links to panel sliders can show hide them
|
rt300@0
|
47
|
rt300@0
|
48 // controls flow of stuff
|
rt300@0
|
49
|
rt300@0
|
50 //---------------------------------------------------------------------
|
rt300@0
|
51 //---------------------------------------------------------------------
|
rt300@0
|
52 extern TimeController timeController;
|
rt300@0
|
53
|
rt300@0
|
54 extern EventLogger eventLogger;
|
rt300@0
|
55
|
rt300@6
|
56 extern ExplorePresetManager expPresetManager;
|
rt300@4
|
57
|
rt300@11
|
58 //typedef boost::function<void(void)> AppModeChangeFunction;
|
rt300@0
|
59
|
rt300@0
|
60 class MessageOrganiser {
|
rt300@8
|
61
|
rt300@8
|
62 public:
|
rt300@8
|
63 void init(PDSynthWrapper& cs, PDSynthWrapper& ts){
|
rt300@8
|
64 candidateSynth = cs;
|
rt300@8
|
65 targetSynth = ts;
|
rt300@9
|
66
|
rt300@9
|
67 onlyChangeCandidateOnTrigger = true;
|
rt300@8
|
68 }
|
rt300@8
|
69 // could template for ui element type??
|
rt300@8
|
70 void mapButtonToAction(UIElement* control, int mappingID){
|
rt300@8
|
71 UICallbackFunction callbackF;
|
rt300@8
|
72 callbackF = boost::bind(&MessageOrganiser::buttonPressCallback, this, _1,_2);
|
rt300@8
|
73 control->addHandler(callbackF, mappingID);
|
rt300@8
|
74 currentMapping.insert(std::pair<int,UIElement*>(mappingID,control));
|
rt300@8
|
75 }
|
rt300@9
|
76 void setControlPanel(SliderPanel* p){ // a bit specific??
|
rt300@9
|
77 panel = p;
|
rt300@9
|
78
|
rt300@9
|
79 };
|
rt300@9
|
80 void setBottomPanel(ButtonPanel * ntb){
|
rt300@9
|
81 bottomPanel = ntb;
|
rt300@9
|
82 };
|
rt300@16
|
83
|
rt300@16
|
84
|
rt300@16
|
85 void setIconPanel(IconPanel * ip){
|
rt300@16
|
86 presetIconPanel = ip;
|
rt300@16
|
87 }
|
rt300@16
|
88 void setInstructionPanel(TextPanel * ip){
|
rt300@16
|
89 instructionPanel = ip;
|
rt300@16
|
90 instructionPanel->show();
|
rt300@16
|
91 }
|
rt300@16
|
92
|
rt300@16
|
93
|
rt300@16
|
94 //-----------------------------------------------------------------------------
|
rt300@16
|
95 void hideMyPanels(){
|
rt300@16
|
96 presetIconPanel->hide();
|
rt300@16
|
97 instructionPanel->hide();
|
rt300@16
|
98 bottomPanel->hide();
|
rt300@16
|
99 panel->hide();
|
rt300@16
|
100 }
|
rt300@16
|
101 void showMyPanels(){
|
rt300@16
|
102 presetIconPanel->show();
|
rt300@16
|
103 instructionPanel->show();
|
rt300@16
|
104 bottomPanel->show();
|
rt300@16
|
105 panel->show();
|
rt300@16
|
106 }
|
rt300@8
|
107 protected:
|
rt300@8
|
108
|
rt300@8
|
109 PDSynthWrapper candidateSynth;
|
rt300@0
|
110 PDSynthWrapper targetSynth;
|
rt300@9
|
111 ButtonPanel* bottomPanel; // shows during test : play buttons and submit
|
rt300@9
|
112 SliderPanel* panel;
|
rt300@16
|
113
|
rt300@16
|
114 IconPanel* presetIconPanel;
|
rt300@16
|
115 TextPanel* instructionPanel;
|
rt300@16
|
116
|
rt300@9
|
117 map<int,UIElement*> currentMapping; // could get more sophisticated if not 1-1 ?
|
rt300@8
|
118
|
rt300@0
|
119
|
rt300@9
|
120 void triggerCandidateSound(){
|
rt300@9
|
121 // log event
|
rt300@9
|
122 sendSynthValuesAgain();
|
rt300@9
|
123 candidateSynth.trigger();
|
rt300@9
|
124 eventLogger.logEvent(CANDIDATE_PLAYED);
|
rt300@9
|
125 // flash panel?
|
rt300@9
|
126 panel->flash();
|
rt300@9
|
127 }
|
rt300@0
|
128
|
rt300@9
|
129 void paramChangeCallback(int mappingID, int value){
|
rt300@9
|
130
|
rt300@9
|
131 if(onlyChangeCandidateOnTrigger){
|
rt300@9
|
132 candidateSynth.paramChangeCallback(mappingID, value, false);
|
rt300@9
|
133 }else{
|
rt300@9
|
134 candidateSynth.paramChangeCallback(mappingID, value, true);
|
rt300@9
|
135 }
|
rt300@0
|
136
|
rt300@9
|
137 vector<int> evtData;
|
rt300@9
|
138 evtData.push_back(mappingID); // or just index?
|
rt300@9
|
139 evtData.push_back(value);
|
rt300@9
|
140
|
rt300@9
|
141 eventLogger.logEvent(CANDIDATE_PARAM_ADJUSTED, evtData);
|
rt300@9
|
142 };
|
rt300@0
|
143
|
rt300@0
|
144 void sendSynthValuesAgain(){
|
rt300@0
|
145 candidateSynth.sendAllParams();
|
rt300@0
|
146 targetSynth.sendAllParams();
|
rt300@0
|
147 };
|
rt300@8
|
148
|
rt300@0
|
149
|
rt300@4
|
150 void setAllSlidersToValues(vector<int> values){
|
rt300@4
|
151 for(int i = 0; i < values.size(); i++){
|
rt300@4
|
152 setUIToParam(i, values[i]);
|
rt300@4
|
153 }
|
rt300@4
|
154 }
|
rt300@0
|
155 // we want to set UI object
|
rt300@0
|
156 void setUIToParam(int index, int value){ // e.g. from MIDI incoming, will handle both box and sliders...
|
rt300@0
|
157 // theXY->setValueAndScale(candidateSynth.getParamValueForID(mids[i]), candidateSynth.getParamValueForID(mids[i+1]));
|
rt300@0
|
158 UIElement* elem;
|
rt300@0
|
159 // get the element
|
rt300@0
|
160 if(panel->subElements.size() <= index){
|
rt300@4
|
161 cout << "ERROR: index out of range for num sliders" << endl;
|
rt300@0
|
162 return;
|
rt300@0
|
163 }
|
rt300@0
|
164 elem = panel->subElements[index];
|
rt300@0
|
165 if ( elem->getType() == SLIDER){
|
rt300@0
|
166 ButtronSlider* theSlider = (ButtronSlider*)elem;
|
rt300@0
|
167 theSlider->setValueAndScale(value);
|
rt300@0
|
168
|
rt300@0
|
169 }else{
|
rt300@0
|
170 cout << "ERROR ERROR: ui type not handled by setUIToParam!" << endl;
|
rt300@0
|
171 }
|
rt300@0
|
172
|
rt300@0
|
173 };
|
rt300@0
|
174
|
rt300@0
|
175
|
rt300@0
|
176 void mapControlToParam(UIElement* control, int mappingID){
|
rt300@0
|
177
|
rt300@0
|
178 UICallbackFunction callbackF;
|
rt300@0
|
179 callbackF = boost::bind(&MessageOrganiser::paramChangeCallback, this, _1,_2);
|
rt300@0
|
180 control->addHandler(callbackF, mappingID);
|
rt300@0
|
181 // put in our map so we can send param values to gui
|
rt300@0
|
182 currentMapping.insert(std::pair<int,UIElement*>(mappingID,control));
|
rt300@0
|
183 cout << " Mapped control to ID: " << mappingID << "Name: " << candidateSynth.getNameForMappingID(mappingID) << endl;
|
rt300@0
|
184 control->setLabel(candidateSynth.getNameForMappingID(mappingID));
|
rt300@0
|
185 };
|
rt300@0
|
186
|
rt300@16
|
187 //-----------------------------------------------------------------------------
|
rt300@16
|
188
|
rt300@16
|
189 void mapSlidersToParams(vector<UIElement*> elems, vector<int> mids){
|
rt300@16
|
190
|
rt300@16
|
191 vector<UIElement*>::iterator elit;
|
rt300@16
|
192 vector<int> typeListLog;
|
rt300@16
|
193 int i = 0;
|
rt300@16
|
194 for(elit=elems.begin(); elit<elems.end();elit++){
|
rt300@16
|
195 if ( (*elit)->getType() == SLIDER){
|
rt300@16
|
196 if(i >= mids.size()){
|
rt300@16
|
197
|
rt300@16
|
198 cout << "ERROR ERROR: too many controls for mapping IDs: " << mids.size() << endl;
|
rt300@16
|
199 }
|
rt300@16
|
200
|
rt300@16
|
201 ButtronSlider* theSlider = (ButtronSlider*)(*elit);
|
rt300@16
|
202 mapControlToParam((*elit), mids[i]);
|
rt300@16
|
203 theSlider->setValueAndScale(candidateSynth.getParamValueForID(mids[i]));
|
rt300@16
|
204 cout << "Hint Value " << targetSynth.getParamValueFromName(candidateSynth.getNameForMappingID(mids[i])) << endl;
|
rt300@16
|
205 theSlider->setHintValue(targetSynth.getParamValueFromName(candidateSynth.getNameForMappingID(mids[i])));
|
rt300@16
|
206 i++;
|
rt300@16
|
207 typeListLog.push_back(int(SLIDER));
|
rt300@16
|
208
|
rt300@16
|
209 }else{
|
rt300@16
|
210 cout << "ERROR ERROR: ui type not handled my mapping function !" << endl;
|
rt300@16
|
211 }
|
rt300@16
|
212 }
|
rt300@16
|
213
|
rt300@16
|
214 eventLogger.logEvent(CONTROL_LIST,typeListLog);
|
rt300@16
|
215 };
|
rt300@16
|
216
|
rt300@0
|
217 void mapXYToParams(ButtronXY* control, int mappingIDX, int mappingIDY){
|
rt300@0
|
218 UICallbackFunction callback;
|
rt300@0
|
219
|
rt300@0
|
220 callback = boost::bind(&MessageOrganiser::paramChangeCallback, this, _1,_2);
|
rt300@0
|
221
|
rt300@0
|
222 control->addHandler(callback, mappingIDX, mappingIDY);
|
rt300@0
|
223
|
rt300@0
|
224 // put in our map so we can send param values to gui
|
rt300@0
|
225 //currentMapping.insert(std::pair<int,UIElement*>(mappingID,control));
|
rt300@0
|
226
|
rt300@0
|
227
|
rt300@0
|
228 cout << " Mapped control to XID: " << mappingIDX << "Name: " << candidateSynth.getNameForMappingID(mappingIDX) << endl;
|
rt300@0
|
229 cout << " Mapped control to YID: " << mappingIDY << "Name: " << candidateSynth.getNameForMappingID(mappingIDY) << endl;
|
rt300@0
|
230 control->setLabel(candidateSynth.getNameForMappingID(mappingIDX), candidateSynth.getNameForMappingID(mappingIDY));
|
rt300@0
|
231
|
rt300@0
|
232 };
|
rt300@8
|
233
|
rt300@0
|
234
|
rt300@0
|
235 void mapControlToParam(UIElement* control, string paramName){
|
rt300@0
|
236 // get mapping ID from synth
|
rt300@0
|
237 int mappingID = candidateSynth.getMappingIDForName(paramName);
|
rt300@0
|
238 mapControlToParam(control, mappingID);
|
rt300@0
|
239 control->setLabel(paramName);
|
rt300@0
|
240 };
|
rt300@0
|
241
|
rt300@8
|
242 virtual void buttonPressCallback(int mappingID, int value){
|
rt300@0
|
243
|
rt300@0
|
244 };
|
rt300@3
|
245
|
rt300@3
|
246
|
rt300@3
|
247 void setSlidersToTarget(){
|
rt300@3
|
248 // this will actually show sliders with target vals - for "memorisation" purposes mwa heh heh
|
rt300@3
|
249 // get target values
|
rt300@3
|
250 // set ui
|
rt300@3
|
251 vector<int> vals = targetSynth.getAllParamValues();
|
rt300@3
|
252 for(int i=1; i < vals.size(); i++){
|
rt300@3
|
253 setUIToParam(i, vals[i]);
|
rt300@3
|
254 }
|
rt300@2
|
255 }
|
rt300@14
|
256 void setSlidersToDefault(){
|
rt300@14
|
257 for(int i=1; i < targetSynth.getNumParams(); i++){
|
rt300@14
|
258 setUIToParam(i, 0);
|
rt300@14
|
259 }
|
rt300@14
|
260 }
|
rt300@9
|
261
|
rt300@9
|
262 bool onlyChangeCandidateOnTrigger;
|
rt300@0
|
263
|
rt300@0
|
264 };
|
rt300@0
|
265
|