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@6
|
34
|
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@8
|
83 protected:
|
rt300@8
|
84
|
rt300@8
|
85 PDSynthWrapper candidateSynth;
|
rt300@0
|
86 PDSynthWrapper targetSynth;
|
rt300@9
|
87 ButtonPanel* bottomPanel; // shows during test : play buttons and submit
|
rt300@9
|
88 SliderPanel* panel;
|
rt300@9
|
89 map<int,UIElement*> currentMapping; // could get more sophisticated if not 1-1 ?
|
rt300@8
|
90
|
rt300@0
|
91
|
rt300@9
|
92 void triggerCandidateSound(){
|
rt300@9
|
93 // log event
|
rt300@9
|
94 sendSynthValuesAgain();
|
rt300@9
|
95 candidateSynth.trigger();
|
rt300@9
|
96 eventLogger.logEvent(CANDIDATE_PLAYED);
|
rt300@9
|
97 // flash panel?
|
rt300@9
|
98 panel->flash();
|
rt300@9
|
99 }
|
rt300@0
|
100
|
rt300@9
|
101 void paramChangeCallback(int mappingID, int value){
|
rt300@9
|
102
|
rt300@9
|
103 if(onlyChangeCandidateOnTrigger){
|
rt300@9
|
104 candidateSynth.paramChangeCallback(mappingID, value, false);
|
rt300@9
|
105 }else{
|
rt300@9
|
106 candidateSynth.paramChangeCallback(mappingID, value, true);
|
rt300@9
|
107 }
|
rt300@0
|
108
|
rt300@9
|
109 vector<int> evtData;
|
rt300@9
|
110 evtData.push_back(mappingID); // or just index?
|
rt300@9
|
111 evtData.push_back(value);
|
rt300@9
|
112
|
rt300@9
|
113 eventLogger.logEvent(CANDIDATE_PARAM_ADJUSTED, evtData);
|
rt300@9
|
114 };
|
rt300@0
|
115
|
rt300@0
|
116 void sendSynthValuesAgain(){
|
rt300@0
|
117 candidateSynth.sendAllParams();
|
rt300@0
|
118 targetSynth.sendAllParams();
|
rt300@0
|
119 };
|
rt300@8
|
120
|
rt300@0
|
121
|
rt300@4
|
122 void setAllSlidersToValues(vector<int> values){
|
rt300@4
|
123 for(int i = 0; i < values.size(); i++){
|
rt300@4
|
124 setUIToParam(i, values[i]);
|
rt300@4
|
125 }
|
rt300@4
|
126 }
|
rt300@0
|
127 // we want to set UI object
|
rt300@0
|
128 void setUIToParam(int index, int value){ // e.g. from MIDI incoming, will handle both box and sliders...
|
rt300@0
|
129 // theXY->setValueAndScale(candidateSynth.getParamValueForID(mids[i]), candidateSynth.getParamValueForID(mids[i+1]));
|
rt300@0
|
130 UIElement* elem;
|
rt300@0
|
131 // get the element
|
rt300@0
|
132 if(panel->subElements.size() <= index){
|
rt300@4
|
133 cout << "ERROR: index out of range for num sliders" << endl;
|
rt300@0
|
134 return;
|
rt300@0
|
135 }
|
rt300@0
|
136 elem = panel->subElements[index];
|
rt300@0
|
137 if ( elem->getType() == SLIDER){
|
rt300@0
|
138 ButtronSlider* theSlider = (ButtronSlider*)elem;
|
rt300@0
|
139 theSlider->setValueAndScale(value);
|
rt300@0
|
140
|
rt300@0
|
141 }else{
|
rt300@0
|
142 cout << "ERROR ERROR: ui type not handled by setUIToParam!" << endl;
|
rt300@0
|
143 }
|
rt300@0
|
144
|
rt300@0
|
145 };
|
rt300@0
|
146
|
rt300@0
|
147
|
rt300@0
|
148 void mapControlToParam(UIElement* control, int mappingID){
|
rt300@0
|
149
|
rt300@0
|
150 UICallbackFunction callbackF;
|
rt300@0
|
151 callbackF = boost::bind(&MessageOrganiser::paramChangeCallback, this, _1,_2);
|
rt300@0
|
152 control->addHandler(callbackF, mappingID);
|
rt300@0
|
153 // put in our map so we can send param values to gui
|
rt300@0
|
154 currentMapping.insert(std::pair<int,UIElement*>(mappingID,control));
|
rt300@0
|
155 cout << " Mapped control to ID: " << mappingID << "Name: " << candidateSynth.getNameForMappingID(mappingID) << endl;
|
rt300@0
|
156 control->setLabel(candidateSynth.getNameForMappingID(mappingID));
|
rt300@0
|
157 };
|
rt300@0
|
158
|
rt300@0
|
159 void mapXYToParams(ButtronXY* control, int mappingIDX, int mappingIDY){
|
rt300@0
|
160 UICallbackFunction callback;
|
rt300@0
|
161
|
rt300@0
|
162 callback = boost::bind(&MessageOrganiser::paramChangeCallback, this, _1,_2);
|
rt300@0
|
163
|
rt300@0
|
164 control->addHandler(callback, mappingIDX, mappingIDY);
|
rt300@0
|
165
|
rt300@0
|
166 // put in our map so we can send param values to gui
|
rt300@0
|
167 //currentMapping.insert(std::pair<int,UIElement*>(mappingID,control));
|
rt300@0
|
168
|
rt300@0
|
169
|
rt300@0
|
170 cout << " Mapped control to XID: " << mappingIDX << "Name: " << candidateSynth.getNameForMappingID(mappingIDX) << endl;
|
rt300@0
|
171 cout << " Mapped control to YID: " << mappingIDY << "Name: " << candidateSynth.getNameForMappingID(mappingIDY) << endl;
|
rt300@0
|
172 control->setLabel(candidateSynth.getNameForMappingID(mappingIDX), candidateSynth.getNameForMappingID(mappingIDY));
|
rt300@0
|
173
|
rt300@0
|
174 };
|
rt300@8
|
175
|
rt300@0
|
176
|
rt300@0
|
177 void mapControlToParam(UIElement* control, string paramName){
|
rt300@0
|
178 // get mapping ID from synth
|
rt300@0
|
179 int mappingID = candidateSynth.getMappingIDForName(paramName);
|
rt300@0
|
180 mapControlToParam(control, mappingID);
|
rt300@0
|
181 control->setLabel(paramName);
|
rt300@0
|
182 };
|
rt300@0
|
183
|
rt300@8
|
184 virtual void buttonPressCallback(int mappingID, int value){
|
rt300@0
|
185
|
rt300@0
|
186 };
|
rt300@3
|
187
|
rt300@3
|
188
|
rt300@3
|
189 void setSlidersToTarget(){
|
rt300@3
|
190 // this will actually show sliders with target vals - for "memorisation" purposes mwa heh heh
|
rt300@3
|
191 // get target values
|
rt300@3
|
192 // set ui
|
rt300@3
|
193 vector<int> vals = targetSynth.getAllParamValues();
|
rt300@3
|
194 for(int i=1; i < vals.size(); i++){
|
rt300@3
|
195 setUIToParam(i, vals[i]);
|
rt300@3
|
196 }
|
rt300@2
|
197 }
|
rt300@9
|
198
|
rt300@9
|
199 bool onlyChangeCandidateOnTrigger;
|
rt300@0
|
200
|
rt300@0
|
201 };
|
rt300@0
|
202
|