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@0
|
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@8
|
66 }
|
rt300@8
|
67 // could template for ui element type??
|
rt300@8
|
68 void mapButtonToAction(UIElement* control, int mappingID){
|
rt300@8
|
69 UICallbackFunction callbackF;
|
rt300@8
|
70 callbackF = boost::bind(&MessageOrganiser::buttonPressCallback, this, _1,_2);
|
rt300@8
|
71 control->addHandler(callbackF, mappingID);
|
rt300@8
|
72 currentMapping.insert(std::pair<int,UIElement*>(mappingID,control));
|
rt300@8
|
73 }
|
rt300@8
|
74 protected:
|
rt300@8
|
75
|
rt300@8
|
76 PDSynthWrapper candidateSynth;
|
rt300@0
|
77 PDSynthWrapper targetSynth;
|
rt300@8
|
78
|
rt300@0
|
79
|
rt300@0
|
80 map<int,UIElement*> currentMapping; // could get more sophisticated if not 1-1 ?
|
rt300@0
|
81
|
rt300@0
|
82 SliderPanel* panel;
|
rt300@0
|
83
|
rt300@0
|
84
|
rt300@0
|
85 void sendSynthValuesAgain(){
|
rt300@0
|
86 candidateSynth.sendAllParams();
|
rt300@0
|
87 targetSynth.sendAllParams();
|
rt300@0
|
88 };
|
rt300@8
|
89
|
rt300@0
|
90
|
rt300@4
|
91 void setAllSlidersToValues(vector<int> values){
|
rt300@4
|
92 for(int i = 0; i < values.size(); i++){
|
rt300@4
|
93 setUIToParam(i, values[i]);
|
rt300@4
|
94 }
|
rt300@4
|
95 }
|
rt300@0
|
96 // we want to set UI object
|
rt300@0
|
97 void setUIToParam(int index, int value){ // e.g. from MIDI incoming, will handle both box and sliders...
|
rt300@0
|
98 // theXY->setValueAndScale(candidateSynth.getParamValueForID(mids[i]), candidateSynth.getParamValueForID(mids[i+1]));
|
rt300@0
|
99 UIElement* elem;
|
rt300@0
|
100 // get the element
|
rt300@0
|
101 if(panel->subElements.size() <= index){
|
rt300@4
|
102 cout << "ERROR: index out of range for num sliders" << endl;
|
rt300@0
|
103 return;
|
rt300@0
|
104 }
|
rt300@0
|
105 elem = panel->subElements[index];
|
rt300@0
|
106 if ( elem->getType() == SLIDER){
|
rt300@0
|
107 ButtronSlider* theSlider = (ButtronSlider*)elem;
|
rt300@0
|
108 theSlider->setValueAndScale(value);
|
rt300@0
|
109
|
rt300@0
|
110 }else{
|
rt300@0
|
111 cout << "ERROR ERROR: ui type not handled by setUIToParam!" << endl;
|
rt300@0
|
112 }
|
rt300@0
|
113
|
rt300@0
|
114 };
|
rt300@0
|
115
|
rt300@0
|
116
|
rt300@0
|
117 void mapControlToParam(UIElement* control, int mappingID){
|
rt300@0
|
118
|
rt300@0
|
119 UICallbackFunction callbackF;
|
rt300@0
|
120 callbackF = boost::bind(&MessageOrganiser::paramChangeCallback, this, _1,_2);
|
rt300@0
|
121 control->addHandler(callbackF, mappingID);
|
rt300@0
|
122 // put in our map so we can send param values to gui
|
rt300@0
|
123 currentMapping.insert(std::pair<int,UIElement*>(mappingID,control));
|
rt300@0
|
124 cout << " Mapped control to ID: " << mappingID << "Name: " << candidateSynth.getNameForMappingID(mappingID) << endl;
|
rt300@0
|
125 control->setLabel(candidateSynth.getNameForMappingID(mappingID));
|
rt300@0
|
126 };
|
rt300@0
|
127
|
rt300@0
|
128 void mapXYToParams(ButtronXY* control, int mappingIDX, int mappingIDY){
|
rt300@0
|
129 UICallbackFunction callback;
|
rt300@0
|
130
|
rt300@0
|
131 callback = boost::bind(&MessageOrganiser::paramChangeCallback, this, _1,_2);
|
rt300@0
|
132
|
rt300@0
|
133 control->addHandler(callback, mappingIDX, mappingIDY);
|
rt300@0
|
134
|
rt300@0
|
135 // put in our map so we can send param values to gui
|
rt300@0
|
136 //currentMapping.insert(std::pair<int,UIElement*>(mappingID,control));
|
rt300@0
|
137
|
rt300@0
|
138
|
rt300@0
|
139 cout << " Mapped control to XID: " << mappingIDX << "Name: " << candidateSynth.getNameForMappingID(mappingIDX) << endl;
|
rt300@0
|
140 cout << " Mapped control to YID: " << mappingIDY << "Name: " << candidateSynth.getNameForMappingID(mappingIDY) << endl;
|
rt300@0
|
141 control->setLabel(candidateSynth.getNameForMappingID(mappingIDX), candidateSynth.getNameForMappingID(mappingIDY));
|
rt300@0
|
142
|
rt300@0
|
143 };
|
rt300@8
|
144
|
rt300@0
|
145
|
rt300@0
|
146 void mapControlToParam(UIElement* control, string paramName){
|
rt300@0
|
147 // get mapping ID from synth
|
rt300@0
|
148 int mappingID = candidateSynth.getMappingIDForName(paramName);
|
rt300@0
|
149 mapControlToParam(control, mappingID);
|
rt300@0
|
150 control->setLabel(paramName);
|
rt300@0
|
151 };
|
rt300@0
|
152
|
rt300@8
|
153 virtual void paramChangeCallback(int mappingID, int value){
|
rt300@8
|
154 // virtual?
|
rt300@0
|
155 };
|
rt300@8
|
156 virtual void buttonPressCallback(int mappingID, int value){
|
rt300@0
|
157
|
rt300@0
|
158 };
|
rt300@3
|
159
|
rt300@3
|
160
|
rt300@3
|
161 void setSlidersToTarget(){
|
rt300@3
|
162 // this will actually show sliders with target vals - for "memorisation" purposes mwa heh heh
|
rt300@3
|
163 // get target values
|
rt300@3
|
164 // set ui
|
rt300@3
|
165 vector<int> vals = targetSynth.getAllParamValues();
|
rt300@3
|
166 for(int i=1; i < vals.size(); i++){
|
rt300@3
|
167 setUIToParam(i, vals[i]);
|
rt300@3
|
168 }
|
rt300@2
|
169 }
|
rt300@0
|
170
|
rt300@0
|
171 };
|
rt300@0
|
172
|