rt300@8
|
1 //
|
rt300@8
|
2 // TrainingMessageOrganiser.h
|
rt300@8
|
3 // riftathon
|
rt300@8
|
4 //
|
rt300@8
|
5 // Created by Robert Tubb on 17/10/2014.
|
rt300@8
|
6 //
|
rt300@8
|
7 //
|
rt300@8
|
8
|
rt300@8
|
9 #ifndef __riftathon__TrainingMessageOrganiser__
|
rt300@8
|
10 #define __riftathon__TrainingMessageOrganiser__
|
rt300@8
|
11
|
rt300@8
|
12 #include <iostream>
|
rt300@9
|
13 #include "trainingTestController.h"
|
rt300@9
|
14 #include "MessageOrganiser.h"
|
rt300@10
|
15 #include "SequenceController.h"
|
rt300@11
|
16 #include "globalVariables.h"
|
rt300@10
|
17 extern ExplorePresetManager expPresetManager;
|
rt300@10
|
18
|
rt300@9
|
19 class TrainingMessageOrganiser : public MessageOrganiser {
|
rt300@9
|
20 public:
|
rt300@9
|
21 void init( PDSynthWrapper& cs, PDSynthWrapper& ts){
|
rt300@9
|
22
|
rt300@9
|
23 trainingTestController = new TrainingTestController;
|
rt300@9
|
24
|
rt300@9
|
25 MessageOrganiser::init(cs,ts);
|
rt300@11
|
26
|
rt300@11
|
27 TickListenerFunction callback;
|
rt300@11
|
28 callback = boost::bind(&TrainingMessageOrganiser::onNextTick, this, _1);
|
rt300@11
|
29 candidateSynth.registerForTicks(callback);
|
rt300@11
|
30 }
|
rt300@8
|
31
|
rt300@9
|
32 void setupDefaultMapping(){
|
rt300@9
|
33 vector<int> mappingIDsForChangeableParams = getMappingIDsFromSynths();
|
rt300@9
|
34
|
rt300@9
|
35 controlPanelType cpt = REVISITABLE;
|
rt300@9
|
36 vector<controllerType> elemList;
|
rt300@9
|
37 for(int i = 0; i < 8; i++){
|
rt300@9
|
38 elemList.push_back(SLIDER);
|
rt300@9
|
39 }
|
rt300@9
|
40
|
rt300@9
|
41 vector<UIElement*> UIElemHandles = panel->generateControls(elemList, cpt);
|
rt300@9
|
42
|
rt300@9
|
43 mapSlidersToParams(UIElemHandles, mappingIDsForChangeableParams);
|
rt300@9
|
44
|
rt300@9
|
45 bottomPanel->show();
|
rt300@9
|
46 }
|
rt300@9
|
47
|
rt300@9
|
48 vector<int> getMappingIDsFromSynths(){
|
rt300@9
|
49 vector<int> index;
|
rt300@9
|
50 for(int i = 0; i < 8; i++){
|
rt300@9
|
51 index.push_back(i);
|
rt300@9
|
52 }
|
rt300@9
|
53 vector<int> mids = candidateSynth.getMappingIDForIndices(index);
|
rt300@9
|
54
|
rt300@9
|
55 return mids;
|
rt300@9
|
56 }
|
rt300@9
|
57
|
rt300@9
|
58 void setupNewTest(){
|
rt300@9
|
59
|
rt300@9
|
60
|
rt300@9
|
61 };
|
rt300@10
|
62
|
rt300@10
|
63 void onNextTick(int tickNumber){
|
rt300@11
|
64 cout << "TICK " << tickNumber << endl;
|
rt300@11
|
65
|
rt300@10
|
66 if ( tickNumber % 2){
|
rt300@10
|
67 // load next target preset
|
rt300@10
|
68 int i = sequenceController.getNextPresetIndex();
|
rt300@10
|
69
|
rt300@10
|
70 currentTargetPreset = expPresetManager.getPreset(i);
|
rt300@10
|
71
|
rt300@10
|
72 if (sequencePreview){
|
rt300@10
|
73 // show next target preset
|
rt300@10
|
74
|
rt300@10
|
75 // show image
|
rt300@10
|
76 // show name
|
rt300@10
|
77 // show controllersettings
|
rt300@10
|
78
|
rt300@10
|
79
|
rt300@10
|
80 }else{ // the user is matching it
|
rt300@10
|
81 // show image
|
rt300@10
|
82 // show name
|
rt300@10
|
83
|
rt300@10
|
84 // if guided
|
rt300@10
|
85 // show controller guide
|
rt300@10
|
86 }
|
rt300@10
|
87
|
rt300@10
|
88
|
rt300@10
|
89 }else{ // we're plying the sound
|
rt300@10
|
90
|
rt300@10
|
91 //
|
rt300@10
|
92 if (sequencePreview){
|
rt300@10
|
93 // send target values again
|
rt300@10
|
94 targetSynth.setAllParams(currentTargetPreset->getValues());
|
rt300@10
|
95 targetSynth.trigger();
|
rt300@10
|
96
|
rt300@10
|
97 // flash the interface?
|
rt300@10
|
98 }else{
|
rt300@10
|
99 // else the user should be hitting the play button
|
rt300@10
|
100
|
rt300@10
|
101 }
|
rt300@10
|
102 }
|
rt300@10
|
103 }
|
rt300@10
|
104
|
rt300@9
|
105
|
rt300@9
|
106 protected:
|
rt300@10
|
107
|
rt300@10
|
108 void loadPreset(string pname){
|
rt300@10
|
109
|
rt300@10
|
110 vector<int> values = expPresetManager.recallPreset(pname);
|
rt300@10
|
111 if (values.size()){
|
rt300@10
|
112 candidateSynth.setAllParams(values);
|
rt300@10
|
113 setAllSlidersToValues(values);
|
rt300@10
|
114 }else{
|
rt300@10
|
115 cout << "ERROR, no preset found" << endl;
|
rt300@10
|
116 }
|
rt300@10
|
117 }
|
rt300@10
|
118
|
rt300@10
|
119
|
rt300@10
|
120 void showATargetPresetWithGuide(Preset * p){ // this is when demoing the sequence to the user
|
rt300@10
|
121 // p.show icon
|
rt300@10
|
122 vector<int> values = p->getValues();
|
rt300@10
|
123 if (values.size()){
|
rt300@10
|
124 candidateSynth.setAllParams(values);
|
rt300@10
|
125 setAllSlidersToValues(values);
|
rt300@10
|
126 }else{
|
rt300@10
|
127 cout << "WARNING, preset to show had no values" << endl;
|
rt300@10
|
128 }
|
rt300@10
|
129 }
|
rt300@10
|
130
|
rt300@9
|
131 void mapSlidersToParams(vector<UIElement*> elems, vector<int> mids){
|
rt300@9
|
132
|
rt300@9
|
133 vector<UIElement*>::iterator elit;
|
rt300@9
|
134 vector<int> typeListLog;
|
rt300@9
|
135 int i = 0;
|
rt300@9
|
136 for(elit=elems.begin(); elit<elems.end();elit++){
|
rt300@9
|
137 if ( (*elit)->getType() == SLIDER){
|
rt300@9
|
138 if(i >= mids.size()){
|
rt300@9
|
139
|
rt300@9
|
140 cout << "ERROR ERROR: too many controls for mapping IDs: " << mids.size() << endl;
|
rt300@9
|
141 }
|
rt300@9
|
142
|
rt300@9
|
143 ButtronSlider* theSlider = (ButtronSlider*)(*elit);
|
rt300@9
|
144 mapControlToParam((*elit), mids[i]);
|
rt300@9
|
145 theSlider->setValueAndScale(candidateSynth.getParamValueForID(mids[i]));
|
rt300@9
|
146 cout << "Hint Value " << targetSynth.getParamValueFromName(candidateSynth.getNameForMappingID(mids[i])) << endl;
|
rt300@9
|
147 theSlider->setHintValue(targetSynth.getParamValueFromName(candidateSynth.getNameForMappingID(mids[i])));
|
rt300@9
|
148 i++;
|
rt300@9
|
149 typeListLog.push_back(int(SLIDER));
|
rt300@9
|
150
|
rt300@9
|
151 }else{
|
rt300@9
|
152 cout << "ERROR ERROR: ui type not handled my mapping function !" << endl;
|
rt300@9
|
153 }
|
rt300@9
|
154 }
|
rt300@9
|
155
|
rt300@9
|
156 eventLogger.logEvent(CONTROL_LIST,typeListLog);
|
rt300@9
|
157 };
|
rt300@9
|
158
|
rt300@9
|
159 void buttonPressCallback(int mappingID, int value){
|
rt300@9
|
160 if(mappingID == VOLUME_CHANGE_ID){
|
rt300@9
|
161 targetSynth.sendVolume(value);
|
rt300@9
|
162 candidateSynth.sendVolume(value);
|
rt300@10
|
163 return;
|
rt300@9
|
164 }
|
rt300@9
|
165
|
rt300@9
|
166 if (mappingID == TRIGGER_CANDIDATE_ID){
|
rt300@9
|
167 triggerCandidateSound();
|
rt300@10
|
168 // compare to target
|
rt300@11
|
169 candidateSynth.startMetronome();
|
rt300@10
|
170 return;
|
rt300@10
|
171 }
|
rt300@10
|
172 if(mappingID == SAVE_PRESET_HIT){
|
rt300@10
|
173 expPresetManager.savePreset("blah", candidateSynth.getAllParamValues());
|
rt300@10
|
174 return;
|
rt300@10
|
175 }
|
rt300@10
|
176 if(mappingID == RECALL_PRESET_HIT){
|
rt300@10
|
177
|
rt300@10
|
178 loadPreset("blah");
|
rt300@9
|
179 return;
|
rt300@9
|
180 }
|
rt300@9
|
181 }
|
rt300@10
|
182 SequenceController sequenceController;
|
rt300@9
|
183 TrainingTestController* trainingTestController;
|
rt300@10
|
184 bool sequencePreview;
|
rt300@10
|
185 Preset * currentTargetPreset;
|
rt300@8
|
186 };
|
rt300@8
|
187 #endif /* defined(__riftathon__TrainingMessageOrganiser__) */
|