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@17
|
76
|
rt300@17
|
77
|
rt300@9
|
78 void setControlPanel(SliderPanel* p){ // a bit specific??
|
rt300@9
|
79 panel = p;
|
rt300@9
|
80
|
rt300@9
|
81 };
|
rt300@9
|
82 void setBottomPanel(ButtonPanel * ntb){
|
rt300@9
|
83 bottomPanel = ntb;
|
rt300@9
|
84 };
|
rt300@16
|
85
|
rt300@16
|
86
|
rt300@16
|
87 void setIconPanel(IconPanel * ip){
|
rt300@16
|
88 presetIconPanel = ip;
|
rt300@16
|
89 }
|
rt300@16
|
90 void setInstructionPanel(TextPanel * ip){
|
rt300@16
|
91 instructionPanel = ip;
|
rt300@16
|
92 instructionPanel->show();
|
rt300@16
|
93 }
|
rt300@16
|
94
|
rt300@16
|
95
|
rt300@16
|
96 //-----------------------------------------------------------------------------
|
rt300@16
|
97 void hideMyPanels(){
|
rt300@16
|
98 presetIconPanel->hide();
|
rt300@16
|
99 instructionPanel->hide();
|
rt300@16
|
100 bottomPanel->hide();
|
rt300@16
|
101 panel->hide();
|
rt300@16
|
102 }
|
rt300@16
|
103 void showMyPanels(){
|
rt300@16
|
104 presetIconPanel->show();
|
rt300@16
|
105 instructionPanel->show();
|
rt300@16
|
106 bottomPanel->show();
|
rt300@16
|
107 panel->show();
|
rt300@16
|
108 }
|
rt300@8
|
109 protected:
|
rt300@8
|
110
|
rt300@8
|
111 PDSynthWrapper candidateSynth;
|
rt300@0
|
112 PDSynthWrapper targetSynth;
|
rt300@9
|
113 ButtonPanel* bottomPanel; // shows during test : play buttons and submit
|
rt300@9
|
114 SliderPanel* panel;
|
rt300@16
|
115
|
rt300@16
|
116 IconPanel* presetIconPanel;
|
rt300@16
|
117 TextPanel* instructionPanel;
|
rt300@16
|
118
|
rt300@9
|
119 map<int,UIElement*> currentMapping; // could get more sophisticated if not 1-1 ?
|
rt300@8
|
120
|
rt300@0
|
121
|
rt300@9
|
122 void triggerCandidateSound(){
|
rt300@9
|
123 // log event
|
rt300@9
|
124 sendSynthValuesAgain();
|
rt300@9
|
125 candidateSynth.trigger();
|
rt300@9
|
126 eventLogger.logEvent(CANDIDATE_PLAYED);
|
rt300@9
|
127 // flash panel?
|
rt300@9
|
128 panel->flash();
|
rt300@9
|
129 }
|
rt300@0
|
130
|
rt300@9
|
131 void paramChangeCallback(int mappingID, int value){
|
rt300@9
|
132
|
rt300@9
|
133 if(onlyChangeCandidateOnTrigger){
|
rt300@9
|
134 candidateSynth.paramChangeCallback(mappingID, value, false);
|
rt300@9
|
135 }else{
|
rt300@9
|
136 candidateSynth.paramChangeCallback(mappingID, value, true);
|
rt300@9
|
137 }
|
rt300@0
|
138
|
rt300@9
|
139 vector<int> evtData;
|
rt300@9
|
140 evtData.push_back(mappingID); // or just index?
|
rt300@9
|
141 evtData.push_back(value);
|
rt300@9
|
142
|
rt300@9
|
143 eventLogger.logEvent(CANDIDATE_PARAM_ADJUSTED, evtData);
|
rt300@9
|
144 };
|
rt300@0
|
145
|
rt300@0
|
146 void sendSynthValuesAgain(){
|
rt300@0
|
147 candidateSynth.sendAllParams();
|
rt300@0
|
148 targetSynth.sendAllParams();
|
rt300@0
|
149 };
|
rt300@8
|
150
|
rt300@0
|
151
|
rt300@4
|
152 void setAllSlidersToValues(vector<int> values){
|
rt300@4
|
153 for(int i = 0; i < values.size(); i++){
|
rt300@4
|
154 setUIToParam(i, values[i]);
|
rt300@4
|
155 }
|
rt300@4
|
156 }
|
rt300@0
|
157 // we want to set UI object
|
rt300@0
|
158 void setUIToParam(int index, int value){ // e.g. from MIDI incoming, will handle both box and sliders...
|
rt300@0
|
159 // theXY->setValueAndScale(candidateSynth.getParamValueForID(mids[i]), candidateSynth.getParamValueForID(mids[i+1]));
|
rt300@0
|
160 UIElement* elem;
|
rt300@0
|
161 // get the element
|
rt300@0
|
162 if(panel->subElements.size() <= index){
|
rt300@4
|
163 cout << "ERROR: index out of range for num sliders" << endl;
|
rt300@0
|
164 return;
|
rt300@0
|
165 }
|
rt300@0
|
166 elem = panel->subElements[index];
|
rt300@0
|
167 if ( elem->getType() == SLIDER){
|
rt300@0
|
168 ButtronSlider* theSlider = (ButtronSlider*)elem;
|
rt300@0
|
169 theSlider->setValueAndScale(value);
|
rt300@0
|
170
|
rt300@0
|
171 }else{
|
rt300@0
|
172 cout << "ERROR ERROR: ui type not handled by setUIToParam!" << endl;
|
rt300@0
|
173 }
|
rt300@0
|
174
|
rt300@0
|
175 };
|
rt300@0
|
176
|
rt300@0
|
177
|
rt300@0
|
178 void mapControlToParam(UIElement* control, int mappingID){
|
rt300@0
|
179
|
rt300@0
|
180 UICallbackFunction callbackF;
|
rt300@0
|
181 callbackF = boost::bind(&MessageOrganiser::paramChangeCallback, this, _1,_2);
|
rt300@0
|
182 control->addHandler(callbackF, mappingID);
|
rt300@0
|
183 // put in our map so we can send param values to gui
|
rt300@0
|
184 currentMapping.insert(std::pair<int,UIElement*>(mappingID,control));
|
rt300@0
|
185 cout << " Mapped control to ID: " << mappingID << "Name: " << candidateSynth.getNameForMappingID(mappingID) << endl;
|
rt300@0
|
186 control->setLabel(candidateSynth.getNameForMappingID(mappingID));
|
rt300@0
|
187 };
|
rt300@0
|
188
|
rt300@16
|
189 //-----------------------------------------------------------------------------
|
rt300@16
|
190
|
rt300@16
|
191 void mapSlidersToParams(vector<UIElement*> elems, vector<int> mids){
|
rt300@16
|
192
|
rt300@16
|
193 vector<UIElement*>::iterator elit;
|
rt300@16
|
194 vector<int> typeListLog;
|
rt300@16
|
195 int i = 0;
|
rt300@16
|
196 for(elit=elems.begin(); elit<elems.end();elit++){
|
rt300@16
|
197 if ( (*elit)->getType() == SLIDER){
|
rt300@16
|
198 if(i >= mids.size()){
|
rt300@16
|
199
|
rt300@16
|
200 cout << "ERROR ERROR: too many controls for mapping IDs: " << mids.size() << endl;
|
rt300@16
|
201 }
|
rt300@16
|
202
|
rt300@16
|
203 ButtronSlider* theSlider = (ButtronSlider*)(*elit);
|
rt300@16
|
204 mapControlToParam((*elit), mids[i]);
|
rt300@16
|
205 theSlider->setValueAndScale(candidateSynth.getParamValueForID(mids[i]));
|
rt300@16
|
206 cout << "Hint Value " << targetSynth.getParamValueFromName(candidateSynth.getNameForMappingID(mids[i])) << endl;
|
rt300@16
|
207 theSlider->setHintValue(targetSynth.getParamValueFromName(candidateSynth.getNameForMappingID(mids[i])));
|
rt300@16
|
208 i++;
|
rt300@16
|
209 typeListLog.push_back(int(SLIDER));
|
rt300@16
|
210
|
rt300@16
|
211 }else{
|
rt300@16
|
212 cout << "ERROR ERROR: ui type not handled my mapping function !" << endl;
|
rt300@16
|
213 }
|
rt300@16
|
214 }
|
rt300@16
|
215
|
rt300@16
|
216 eventLogger.logEvent(CONTROL_LIST,typeListLog);
|
rt300@16
|
217 };
|
rt300@16
|
218
|
rt300@0
|
219 void mapXYToParams(ButtronXY* control, int mappingIDX, int mappingIDY){
|
rt300@0
|
220 UICallbackFunction callback;
|
rt300@0
|
221
|
rt300@0
|
222 callback = boost::bind(&MessageOrganiser::paramChangeCallback, this, _1,_2);
|
rt300@0
|
223
|
rt300@0
|
224 control->addHandler(callback, mappingIDX, mappingIDY);
|
rt300@0
|
225
|
rt300@0
|
226 // put in our map so we can send param values to gui
|
rt300@0
|
227 //currentMapping.insert(std::pair<int,UIElement*>(mappingID,control));
|
rt300@0
|
228
|
rt300@0
|
229
|
rt300@0
|
230 cout << " Mapped control to XID: " << mappingIDX << "Name: " << candidateSynth.getNameForMappingID(mappingIDX) << endl;
|
rt300@0
|
231 cout << " Mapped control to YID: " << mappingIDY << "Name: " << candidateSynth.getNameForMappingID(mappingIDY) << endl;
|
rt300@0
|
232 control->setLabel(candidateSynth.getNameForMappingID(mappingIDX), candidateSynth.getNameForMappingID(mappingIDY));
|
rt300@0
|
233
|
rt300@0
|
234 };
|
rt300@8
|
235
|
rt300@0
|
236
|
rt300@0
|
237 void mapControlToParam(UIElement* control, string paramName){
|
rt300@0
|
238 // get mapping ID from synth
|
rt300@0
|
239 int mappingID = candidateSynth.getMappingIDForName(paramName);
|
rt300@0
|
240 mapControlToParam(control, mappingID);
|
rt300@0
|
241 control->setLabel(paramName);
|
rt300@0
|
242 };
|
rt300@0
|
243
|
rt300@8
|
244 virtual void buttonPressCallback(int mappingID, int value){
|
rt300@0
|
245
|
rt300@0
|
246 };
|
rt300@3
|
247
|
rt300@3
|
248
|
rt300@3
|
249 void setSlidersToTarget(){
|
rt300@3
|
250 // this will actually show sliders with target vals - for "memorisation" purposes mwa heh heh
|
rt300@3
|
251 // get target values
|
rt300@3
|
252 // set ui
|
rt300@3
|
253 vector<int> vals = targetSynth.getAllParamValues();
|
rt300@3
|
254 for(int i=1; i < vals.size(); i++){
|
rt300@3
|
255 setUIToParam(i, vals[i]);
|
rt300@3
|
256 }
|
rt300@2
|
257 }
|
rt300@14
|
258 void setSlidersToDefault(){
|
rt300@14
|
259 for(int i=1; i < targetSynth.getNumParams(); i++){
|
rt300@14
|
260 setUIToParam(i, 0);
|
rt300@14
|
261 }
|
rt300@14
|
262 }
|
rt300@9
|
263
|
rt300@9
|
264 bool onlyChangeCandidateOnTrigger;
|
rt300@0
|
265
|
rt300@0
|
266 };
|
rt300@0
|
267
|