andrewm@0
|
1 /*
|
andrewm@0
|
2 TouchKeys: multi-touch musical keyboard control software
|
andrewm@0
|
3 Copyright (c) 2013 Andrew McPherson
|
andrewm@0
|
4
|
andrewm@0
|
5 This program is free software: you can redistribute it and/or modify
|
andrewm@0
|
6 it under the terms of the GNU General Public License as published by
|
andrewm@0
|
7 the Free Software Foundation, either version 3 of the License, or
|
andrewm@0
|
8 (at your option) any later version.
|
andrewm@0
|
9
|
andrewm@0
|
10 This program is distributed in the hope that it will be useful,
|
andrewm@0
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
andrewm@0
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
andrewm@0
|
13 GNU General Public License for more details.
|
andrewm@0
|
14
|
andrewm@0
|
15 You should have received a copy of the GNU General Public License
|
andrewm@0
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
|
andrewm@0
|
17
|
andrewm@0
|
18 =====================================================================
|
andrewm@0
|
19
|
andrewm@0
|
20 TouchkeyControlMappingFactory.cpp: factory for the TouchKeys control
|
andrewm@0
|
21 mapping, which converts an arbitrary touch parameter into a MIDI or
|
andrewm@0
|
22 OSC control message.
|
andrewm@0
|
23 */
|
andrewm@0
|
24
|
andrewm@0
|
25 #include "TouchkeyControlMappingFactory.h"
|
andrewm@0
|
26 #include "TouchkeyControlMappingShortEditor.h"
|
andrewm@41
|
27 #include "TouchkeyControlMappingExtendedEditor.h"
|
andrewm@0
|
28
|
andrewm@0
|
29 const int TouchkeyControlMappingFactory::kDefaultController = 1;
|
andrewm@0
|
30 const float TouchkeyControlMappingFactory::kDefaultOutputRangeMin = 0.0;
|
andrewm@0
|
31 const float TouchkeyControlMappingFactory::kDefaultOutputRangeMax = 127.0;
|
andrewm@0
|
32 const float TouchkeyControlMappingFactory::kDefaultOutputDefault = 0.0;
|
andrewm@0
|
33
|
andrewm@0
|
34 TouchkeyControlMappingFactory::TouchkeyControlMappingFactory(PianoKeyboard &keyboard, MidiKeyboardSegment& segment) :
|
andrewm@0
|
35 TouchkeyBaseMappingFactory<TouchkeyControlMapping>(keyboard, segment),
|
andrewm@0
|
36 inputParameter_(TouchkeyControlMapping::kInputParameterYPosition),
|
andrewm@0
|
37 inputType_(TouchkeyControlMapping::kTypeAbsolute),
|
andrewm@0
|
38 outputRangeMin_(kDefaultOutputRangeMin), outputRangeMax_(kDefaultOutputRangeMax),
|
andrewm@0
|
39 outputDefault_(kDefaultOutputDefault), threshold_(0.0),
|
andrewm@0
|
40 ignoresTwoFingers_(TouchkeyControlMapping::kDefaultIgnoresTwoFingers),
|
andrewm@0
|
41 ignoresThreeFingers_(TouchkeyControlMapping::kDefaultIgnoresThreeFingers),
|
andrewm@0
|
42 direction_(TouchkeyControlMapping::kDefaultDirection)
|
andrewm@0
|
43 {
|
andrewm@0
|
44 setController(kDefaultController);
|
andrewm@0
|
45 }
|
andrewm@0
|
46
|
andrewm@0
|
47 // ***** Destructor *****
|
andrewm@0
|
48
|
andrewm@0
|
49 TouchkeyControlMappingFactory::~TouchkeyControlMappingFactory() {
|
andrewm@0
|
50
|
andrewm@0
|
51 }
|
andrewm@0
|
52
|
andrewm@0
|
53 // ***** Accessors / Modifiers *****
|
andrewm@0
|
54
|
andrewm@41
|
55 int TouchkeyControlMappingFactory::getDirection() {
|
andrewm@41
|
56 // Get the direction of motion. This is always positive for
|
andrewm@41
|
57 if(inputType_ == TouchkeyControlMapping::kTypeAbsolute)
|
andrewm@41
|
58 return TouchkeyControlMapping::kDirectionPositive;
|
andrewm@41
|
59 return direction_;
|
andrewm@41
|
60 }
|
andrewm@41
|
61
|
andrewm@0
|
62 void TouchkeyControlMappingFactory::setInputParameter(int inputParameter) {
|
andrewm@49
|
63 if(inputParameter >= 1 && inputParameter < TouchkeyControlMapping::kInputParameterMaxValue)
|
andrewm@49
|
64 inputParameter_ = inputParameter;
|
andrewm@0
|
65 }
|
andrewm@0
|
66
|
andrewm@0
|
67 void TouchkeyControlMappingFactory::setInputType(int inputType) {
|
andrewm@49
|
68 if(inputType >= 1 && inputType < TouchkeyControlMapping::kTypeMaxValue)
|
andrewm@49
|
69 inputType_ = inputType;
|
andrewm@0
|
70 }
|
andrewm@0
|
71
|
andrewm@0
|
72 void TouchkeyControlMappingFactory::setController(int controller) {
|
andrewm@52
|
73 if(controller < 1 ||
|
andrewm@52
|
74 controller >= MidiKeyboardSegment::kControlMax)
|
andrewm@49
|
75 return;
|
andrewm@49
|
76
|
andrewm@0
|
77 // Before changing the controller, check if we were going to or from the pitch wheel.
|
andrewm@0
|
78 // If so, we should scale the value to or from a 14-bit value
|
andrewm@0
|
79 if(midiControllerNumber_ == MidiKeyboardSegment::kControlPitchWheel &&
|
andrewm@0
|
80 controller != MidiKeyboardSegment::kControlPitchWheel) {
|
andrewm@0
|
81 outputRangeMax_ = outputRangeMax_ / 128.0;
|
andrewm@0
|
82 if(outputRangeMax_ > 127.0)
|
andrewm@0
|
83 outputRangeMax_ = 127.0;
|
andrewm@0
|
84 outputRangeMin_ = outputRangeMin_ / 128.0;
|
andrewm@0
|
85 if(outputRangeMin_ > 127.0)
|
andrewm@0
|
86 outputRangeMin_ = 127.0;
|
andrewm@0
|
87 outputDefault_ = outputDefault_ / 128.0;
|
andrewm@0
|
88 if(outputDefault_ > 127.0)
|
andrewm@0
|
89 outputDefault_ = 127.0;
|
andrewm@0
|
90 }
|
andrewm@0
|
91 else if(midiControllerNumber_ != MidiKeyboardSegment::kControlPitchWheel &&
|
andrewm@0
|
92 controller == MidiKeyboardSegment::kControlPitchWheel) {
|
andrewm@0
|
93 if(outputRangeMax_ == 127.0)
|
andrewm@0
|
94 outputRangeMax_ = 16383.0;
|
andrewm@0
|
95 else
|
andrewm@0
|
96 outputRangeMax_ = outputRangeMax_ * 128.0;
|
andrewm@0
|
97 if(outputRangeMin_ == 127.0)
|
andrewm@0
|
98 outputRangeMin_ = 16383.0;
|
andrewm@0
|
99 else
|
andrewm@0
|
100 outputRangeMin_ = outputRangeMin_ * 128.0;
|
andrewm@0
|
101 if(outputDefault_ == 127.0)
|
andrewm@0
|
102 outputDefault_ = 16383.0;
|
andrewm@0
|
103 else
|
andrewm@0
|
104 outputDefault_ = outputDefault_ * 128.0;
|
andrewm@0
|
105 }
|
andrewm@0
|
106
|
andrewm@0
|
107 setMidiParameters(controller, inputRangeMin_, inputRangeMax_, inputRangeCenter_,
|
andrewm@41
|
108 outputDefault_, outputRangeMin_, outputRangeMax_,
|
andrewm@41
|
109 -1, use14BitControl_, outOfRangeBehavior_);
|
andrewm@0
|
110
|
andrewm@0
|
111 // Listen to incoming controls from the keyboard too, if this is enabled
|
andrewm@0
|
112 // in MidiKeyboardSegment
|
andrewm@0
|
113 if(midiConverter_ != 0) {
|
andrewm@0
|
114 midiConverter_->listenToIncomingControl(midiControllerNumber_);
|
andrewm@0
|
115 }
|
andrewm@0
|
116 }
|
andrewm@0
|
117
|
andrewm@0
|
118 void TouchkeyControlMappingFactory::setRangeInputMin(float inputMin) {
|
andrewm@0
|
119 if(inputMin < -1.0)
|
andrewm@0
|
120 inputRangeMin_ = -1.0;
|
andrewm@0
|
121 else if(inputMin > 1.0)
|
andrewm@0
|
122 inputRangeMin_ = 1.0;
|
andrewm@0
|
123 else
|
andrewm@0
|
124 inputRangeMin_ = inputMin;
|
andrewm@0
|
125
|
andrewm@0
|
126 // Update control
|
andrewm@0
|
127 //if(midiConverter_ == 0)
|
andrewm@0
|
128 // return;
|
andrewm@0
|
129 //midiConverter_->setControlMinValue(controlName_.c_str(), inputRangeMin_);
|
andrewm@0
|
130 setMidiParameters(midiControllerNumber_, inputRangeMin_, inputRangeMax_, inputRangeCenter_,
|
andrewm@41
|
131 outputDefault_, outputRangeMin_, outputRangeMax_,
|
andrewm@41
|
132 -1, use14BitControl_, outOfRangeBehavior_);
|
andrewm@0
|
133 }
|
andrewm@0
|
134
|
andrewm@0
|
135 void TouchkeyControlMappingFactory::setRangeInputMax(float inputMax) {
|
andrewm@0
|
136 if(inputMax < -1.0)
|
andrewm@0
|
137 inputRangeMax_ = -1.0;
|
andrewm@0
|
138 else if(inputMax > 1.0)
|
andrewm@0
|
139 inputRangeMax_ = 1.0;
|
andrewm@0
|
140 else
|
andrewm@0
|
141 inputRangeMax_ = inputMax;
|
andrewm@0
|
142
|
andrewm@0
|
143 // Update control
|
andrewm@0
|
144 //if(midiConverter_ == 0)
|
andrewm@0
|
145 // return;
|
andrewm@0
|
146 //midiConverter_->setControlMaxValue(controlName_.c_str(), inputRangeMax_);
|
andrewm@0
|
147 setMidiParameters(midiControllerNumber_, inputRangeMin_, inputRangeMax_, inputRangeCenter_,
|
andrewm@41
|
148 outputDefault_, outputRangeMin_, outputRangeMax_,
|
andrewm@41
|
149 -1, use14BitControl_, outOfRangeBehavior_);
|
andrewm@0
|
150 }
|
andrewm@0
|
151
|
andrewm@0
|
152 void TouchkeyControlMappingFactory::setRangeInputCenter(float inputCenter) {
|
andrewm@0
|
153 if(inputCenter < -1.0)
|
andrewm@0
|
154 inputRangeCenter_ = -1.0;
|
andrewm@0
|
155 else if(inputCenter > 1.0)
|
andrewm@0
|
156 inputRangeCenter_ = 1.0;
|
andrewm@0
|
157 else
|
andrewm@0
|
158 inputRangeCenter_ = inputCenter;
|
andrewm@0
|
159
|
andrewm@0
|
160 // Update control
|
andrewm@0
|
161 //if(midiConverter_ == 0)
|
andrewm@0
|
162 // return;
|
andrewm@0
|
163 //midiConverter_->setControlCenterValue(controlName_.c_str(), inputRangeCenter_);
|
andrewm@0
|
164 setMidiParameters(midiControllerNumber_, inputRangeMin_, inputRangeMax_, inputRangeCenter_,
|
andrewm@41
|
165 outputDefault_, outputRangeMin_, outputRangeMax_,
|
andrewm@41
|
166 -1, use14BitControl_, outOfRangeBehavior_);
|
andrewm@0
|
167 }
|
andrewm@0
|
168
|
andrewm@0
|
169 void TouchkeyControlMappingFactory::setRangeOutputMin(float outputMin) {
|
andrewm@0
|
170 outputRangeMin_ = outputMin;
|
andrewm@0
|
171
|
andrewm@0
|
172 setMidiParameters(midiControllerNumber_, inputRangeMin_, inputRangeMax_, inputRangeCenter_,
|
andrewm@41
|
173 outputDefault_, outputRangeMin_, outputRangeMax_,
|
andrewm@41
|
174 -1, use14BitControl_, outOfRangeBehavior_);
|
andrewm@0
|
175 }
|
andrewm@0
|
176
|
andrewm@0
|
177 void TouchkeyControlMappingFactory::setRangeOutputMax(float outputMax) {
|
andrewm@0
|
178 outputRangeMax_ = outputMax;
|
andrewm@0
|
179
|
andrewm@0
|
180 setMidiParameters(midiControllerNumber_, inputRangeMin_, inputRangeMax_, inputRangeCenter_,
|
andrewm@41
|
181 outputDefault_, outputRangeMin_, outputRangeMax_,
|
andrewm@41
|
182 -1, use14BitControl_, outOfRangeBehavior_);
|
andrewm@0
|
183 }
|
andrewm@0
|
184
|
andrewm@0
|
185 void TouchkeyControlMappingFactory::setRangeOutputDefault(float outputDefault) {
|
andrewm@0
|
186 outputDefault_ = outputDefault;
|
andrewm@0
|
187
|
andrewm@0
|
188 setMidiParameters(midiControllerNumber_, inputRangeMin_, inputRangeMax_, inputRangeCenter_,
|
andrewm@41
|
189 outputDefault_, outputRangeMin_, outputRangeMax_,
|
andrewm@41
|
190 -1, use14BitControl_, outOfRangeBehavior_);
|
andrewm@0
|
191 }
|
andrewm@0
|
192
|
andrewm@0
|
193 void TouchkeyControlMappingFactory::setThreshold(float threshold) {
|
andrewm@0
|
194 threshold_ = threshold;
|
andrewm@0
|
195 }
|
andrewm@0
|
196
|
andrewm@0
|
197 void TouchkeyControlMappingFactory::setIgnoresTwoFingers(bool ignoresTwo) {
|
andrewm@0
|
198 ignoresTwoFingers_ = ignoresTwo;
|
andrewm@0
|
199 }
|
andrewm@0
|
200
|
andrewm@0
|
201 void TouchkeyControlMappingFactory::setIgnoresThreeFingers(bool ignoresThree) {
|
andrewm@0
|
202 ignoresThreeFingers_ = ignoresThree;
|
andrewm@0
|
203 }
|
andrewm@0
|
204
|
andrewm@0
|
205 void TouchkeyControlMappingFactory::setDirection(int direction) {
|
andrewm@0
|
206 direction_ = direction;
|
andrewm@0
|
207 }
|
andrewm@0
|
208
|
andrewm@41
|
209 void TouchkeyControlMappingFactory::setOutOfRangeBehavior(int behavior) {
|
andrewm@41
|
210 outOfRangeBehavior_ = behavior;
|
andrewm@41
|
211
|
andrewm@41
|
212 setMidiParameters(midiControllerNumber_, inputRangeMin_, inputRangeMax_, inputRangeCenter_,
|
andrewm@41
|
213 outputDefault_, outputRangeMin_, outputRangeMax_,
|
andrewm@41
|
214 -1, use14BitControl_, outOfRangeBehavior_);
|
andrewm@41
|
215 }
|
andrewm@41
|
216
|
andrewm@41
|
217 void TouchkeyControlMappingFactory::setUses14BitControl(bool use) {
|
andrewm@41
|
218 use14BitControl_ = use;
|
andrewm@41
|
219
|
andrewm@41
|
220 setMidiParameters(midiControllerNumber_, inputRangeMin_, inputRangeMax_, inputRangeCenter_,
|
andrewm@41
|
221 outputDefault_, outputRangeMin_, outputRangeMax_,
|
andrewm@41
|
222 -1, use14BitControl_, outOfRangeBehavior_);
|
andrewm@41
|
223 }
|
andrewm@41
|
224
|
andrewm@49
|
225 #ifndef TOUCHKEYS_NO_GUI
|
andrewm@0
|
226 // ***** GUI Support *****
|
andrewm@0
|
227 MappingEditorComponent* TouchkeyControlMappingFactory::createBasicEditor() {
|
andrewm@0
|
228 return new TouchkeyControlMappingShortEditor(*this);
|
andrewm@0
|
229 }
|
andrewm@0
|
230
|
andrewm@41
|
231 MappingEditorComponent* TouchkeyControlMappingFactory::createExtendedEditor() {
|
andrewm@41
|
232 return new TouchkeyControlMappingExtendedEditor(*this);
|
andrewm@41
|
233 }
|
andrewm@49
|
234 #endif
|
andrewm@49
|
235
|
andrewm@49
|
236 // ****** OSC Control Support ******
|
andrewm@49
|
237 OscMessage* TouchkeyControlMappingFactory::oscControlMethod(const char *path, const char *types,
|
andrewm@49
|
238 int numValues, lo_arg **values, void *data) {
|
andrewm@49
|
239 if(!strcmp(path, "/set-input-parameter")) {
|
andrewm@49
|
240 // Change the input parameter for the control mapping
|
andrewm@49
|
241 if(numValues > 0) {
|
andrewm@49
|
242 if(types[0] == 'i') {
|
andrewm@49
|
243 setInputParameter(values[0]->i);
|
andrewm@49
|
244 return OscTransmitter::createSuccessMessage();
|
andrewm@49
|
245 }
|
andrewm@49
|
246 }
|
andrewm@49
|
247 }
|
andrewm@49
|
248 else if(!strcmp(path, "/set-input-type")) {
|
andrewm@49
|
249 // Change the input type (absolute/relative)
|
andrewm@49
|
250 if(numValues > 0) {
|
andrewm@49
|
251 if(types[0] == 'i') {
|
andrewm@49
|
252 setInputType(values[0]->i);
|
andrewm@49
|
253 return OscTransmitter::createSuccessMessage();
|
andrewm@49
|
254 }
|
andrewm@49
|
255 }
|
andrewm@49
|
256 }
|
andrewm@49
|
257 else if(!strcmp(path, "/set-input-range-min")) {
|
andrewm@49
|
258 // Change the input range
|
andrewm@49
|
259 if(numValues > 0) {
|
andrewm@49
|
260 if(types[0] == 'f') {
|
andrewm@49
|
261 setRangeInputMin(values[0]->f);
|
andrewm@49
|
262 return OscTransmitter::createSuccessMessage();
|
andrewm@49
|
263 }
|
andrewm@49
|
264 }
|
andrewm@49
|
265 }
|
andrewm@49
|
266 else if(!strcmp(path, "/set-input-range-max")) {
|
andrewm@49
|
267 // Change the input range
|
andrewm@49
|
268 if(numValues > 0) {
|
andrewm@49
|
269 if(types[0] == 'f') {
|
andrewm@49
|
270 setRangeInputMax(values[0]->f);
|
andrewm@49
|
271 return OscTransmitter::createSuccessMessage();
|
andrewm@49
|
272 }
|
andrewm@49
|
273 }
|
andrewm@49
|
274 }
|
andrewm@49
|
275 else if(!strcmp(path, "/set-input-range-center")) {
|
andrewm@49
|
276 // Change the input range
|
andrewm@49
|
277 if(numValues > 0) {
|
andrewm@49
|
278 if(types[0] == 'f') {
|
andrewm@49
|
279 setRangeInputCenter(values[0]->f);
|
andrewm@49
|
280 return OscTransmitter::createSuccessMessage();
|
andrewm@49
|
281 }
|
andrewm@49
|
282 }
|
andrewm@49
|
283 }
|
andrewm@49
|
284 else if(!strcmp(path, "/set-output-range-min")) {
|
andrewm@49
|
285 // Change the output range
|
andrewm@49
|
286 if(numValues > 0) {
|
andrewm@49
|
287 if(types[0] == 'f') {
|
andrewm@49
|
288 setRangeOutputMin(values[0]->f);
|
andrewm@49
|
289 return OscTransmitter::createSuccessMessage();
|
andrewm@49
|
290 }
|
andrewm@49
|
291 }
|
andrewm@49
|
292 }
|
andrewm@49
|
293 else if(!strcmp(path, "/set-output-range-max")) {
|
andrewm@49
|
294 // Change the output range
|
andrewm@49
|
295 if(numValues > 0) {
|
andrewm@49
|
296 if(types[0] == 'f') {
|
andrewm@49
|
297 setRangeOutputMax(values[0]->f);
|
andrewm@49
|
298 return OscTransmitter::createSuccessMessage();
|
andrewm@49
|
299 }
|
andrewm@49
|
300 }
|
andrewm@49
|
301 }
|
andrewm@49
|
302 else if(!strcmp(path, "/set-output-default")) {
|
andrewm@49
|
303 // Change the output range
|
andrewm@49
|
304 if(numValues > 0) {
|
andrewm@49
|
305 if(types[0] == 'f') {
|
andrewm@49
|
306 setRangeOutputDefault(values[0]->f);
|
andrewm@49
|
307 return OscTransmitter::createSuccessMessage();
|
andrewm@49
|
308 }
|
andrewm@49
|
309 }
|
andrewm@49
|
310 }
|
andrewm@49
|
311 else if(!strcmp(path, "/set-out-of-range-behavior")) {
|
andrewm@49
|
312 // Change how out-of-range inputs are handled
|
andrewm@49
|
313 if(numValues > 0) {
|
andrewm@49
|
314 if(types[0] == 'i') {
|
andrewm@49
|
315 setOutOfRangeBehavior(values[0]->i);
|
andrewm@49
|
316 return OscTransmitter::createSuccessMessage();
|
andrewm@49
|
317 }
|
andrewm@49
|
318 }
|
andrewm@49
|
319 }
|
andrewm@49
|
320 else if(!strcmp(path, "/set-midi-controller")) {
|
andrewm@49
|
321 // Set the MIDI output CC, including pitchwheel etc. and 14-bit options
|
andrewm@49
|
322 if(numValues > 0) {
|
andrewm@49
|
323 if(types[0] == 'i') {
|
andrewm@49
|
324 if(numValues >= 2)
|
andrewm@49
|
325 if(types[1] == 'i')
|
andrewm@49
|
326 setUses14BitControl(values[1]->i != 0);
|
andrewm@49
|
327
|
andrewm@49
|
328 setController(values[0]->i);
|
andrewm@49
|
329 return OscTransmitter::createSuccessMessage();
|
andrewm@49
|
330 }
|
andrewm@49
|
331 }
|
andrewm@49
|
332 }
|
andrewm@49
|
333 else if(!strcmp(path, "/set-threshold")) {
|
andrewm@49
|
334 // Set the threshold for relative activations
|
andrewm@49
|
335 if(numValues > 0) {
|
andrewm@49
|
336 if(types[0] == 'f') {
|
andrewm@49
|
337 setThreshold(values[0]->f);
|
andrewm@49
|
338 return OscTransmitter::createSuccessMessage();
|
andrewm@49
|
339 }
|
andrewm@49
|
340 }
|
andrewm@49
|
341 }
|
andrewm@49
|
342 else if(!strcmp(path, "/set-ignores-multiple-fingers")) {
|
andrewm@49
|
343 // Change whether two or three finger touches are ignored
|
andrewm@49
|
344 if(numValues >= 2) {
|
andrewm@49
|
345 if(types[0] == 'i' && types[1] == 'i') {
|
andrewm@49
|
346 setIgnoresTwoFingers(values[0]->i);
|
andrewm@49
|
347 setIgnoresThreeFingers(values[1]->i);
|
andrewm@49
|
348 return OscTransmitter::createSuccessMessage();
|
andrewm@49
|
349 }
|
andrewm@49
|
350 }
|
andrewm@49
|
351 }
|
andrewm@49
|
352 else if(!strcmp(path, "/set-direction")) {
|
andrewm@49
|
353 // Set the direction of the mapping (normal/reverse/absolute val)
|
andrewm@49
|
354 if(numValues > 0) {
|
andrewm@49
|
355 if(types[0] == 'i') {
|
andrewm@49
|
356 setDirection(values[0]->i);
|
andrewm@49
|
357 return OscTransmitter::createSuccessMessage();
|
andrewm@49
|
358 }
|
andrewm@49
|
359 else if(types[0] == 's') {
|
andrewm@49
|
360 const char *str = &values[0]->s;
|
andrewm@49
|
361
|
andrewm@49
|
362 if(!strncmp(str, "norm", 4)) {
|
andrewm@49
|
363 setDirection(TouchkeyControlMapping::kDirectionPositive);
|
andrewm@49
|
364 return OscTransmitter::createSuccessMessage();
|
andrewm@49
|
365 }
|
andrewm@49
|
366 else if(!strncmp(str, "rev", 3)) {
|
andrewm@49
|
367 setDirection(TouchkeyControlMapping::kDirectionNegative);
|
andrewm@49
|
368 return OscTransmitter::createSuccessMessage();
|
andrewm@49
|
369 }
|
andrewm@49
|
370 if(!strncmp(str, "always", 6) || !strncmp(str, "both", 4)) {
|
andrewm@49
|
371 setDirection(TouchkeyControlMapping::kDirectionBoth);
|
andrewm@49
|
372 return OscTransmitter::createSuccessMessage();
|
andrewm@49
|
373 }
|
andrewm@49
|
374 else
|
andrewm@49
|
375 return OscTransmitter::createFailureMessage();
|
andrewm@49
|
376 }
|
andrewm@49
|
377 }
|
andrewm@49
|
378 }
|
andrewm@49
|
379
|
andrewm@49
|
380 // If no match, check the base class
|
andrewm@49
|
381 return TouchkeyBaseMappingFactory<TouchkeyControlMapping>::oscControlMethod(path, types, numValues, values, data);
|
andrewm@49
|
382 }
|
andrewm@41
|
383
|
andrewm@41
|
384
|
andrewm@33
|
385 // ****** Preset Save/Load ******
|
andrewm@33
|
386 XmlElement* TouchkeyControlMappingFactory::getPreset() {
|
andrewm@34
|
387 PropertySet properties;
|
andrewm@34
|
388
|
andrewm@34
|
389 storeCommonProperties(properties);
|
andrewm@34
|
390 properties.setValue("inputParameter", inputParameter_);
|
andrewm@34
|
391 properties.setValue("inputType", inputType_);
|
andrewm@34
|
392 properties.setValue("outputRangeMin", outputRangeMin_);
|
andrewm@34
|
393 properties.setValue("outputRangeMax", outputRangeMax_);
|
andrewm@34
|
394 properties.setValue("outputDefault", outputDefault_);
|
andrewm@34
|
395 properties.setValue("threshold", threshold_);
|
andrewm@34
|
396 properties.setValue("ignoresTwoFingers", ignoresTwoFingers_);
|
andrewm@34
|
397 properties.setValue("ignoresThreeFingers", ignoresThreeFingers_);
|
andrewm@34
|
398 properties.setValue("direction", direction_);
|
andrewm@43
|
399 properties.setValue("use14Bit", use14BitControl_);
|
andrewm@34
|
400
|
andrewm@34
|
401 XmlElement* preset = properties.createXml("MappingFactory");
|
andrewm@33
|
402 preset->setAttribute("type", "Control");
|
andrewm@34
|
403
|
andrewm@33
|
404 return preset;
|
andrewm@33
|
405 }
|
andrewm@33
|
406
|
andrewm@33
|
407 bool TouchkeyControlMappingFactory::loadPreset(XmlElement const* preset) {
|
andrewm@34
|
408 if(preset == 0)
|
andrewm@34
|
409 return false;
|
andrewm@34
|
410
|
andrewm@34
|
411 PropertySet properties;
|
andrewm@34
|
412 properties.restoreFromXml(*preset);
|
andrewm@34
|
413
|
andrewm@34
|
414 if(!loadCommonProperties(properties))
|
andrewm@34
|
415 return false;
|
andrewm@34
|
416 if(!properties.containsKey("inputParameter") ||
|
andrewm@34
|
417 !properties.containsKey("inputType") ||
|
andrewm@34
|
418 !properties.containsKey("outputRangeMin") ||
|
andrewm@34
|
419 !properties.containsKey("outputRangeMax") ||
|
andrewm@34
|
420 !properties.containsKey("outputDefault") ||
|
andrewm@34
|
421 !properties.containsKey("threshold") ||
|
andrewm@34
|
422 !properties.containsKey("ignoresTwoFingers") ||
|
andrewm@34
|
423 !properties.containsKey("ignoresThreeFingers") ||
|
andrewm@34
|
424 !properties.containsKey("direction"))
|
andrewm@34
|
425 return false;
|
andrewm@34
|
426
|
andrewm@34
|
427 inputParameter_ = properties.getIntValue("inputParameter");
|
andrewm@34
|
428 inputType_ = properties.getIntValue("inputType");
|
andrewm@35
|
429 outputRangeMin_ = properties.getDoubleValue("outputRangeMin");
|
andrewm@35
|
430 outputRangeMax_ = properties.getDoubleValue("outputRangeMax");
|
andrewm@35
|
431 outputDefault_ = properties.getDoubleValue("outputDefault");
|
andrewm@35
|
432 threshold_ = properties.getDoubleValue("threshold");
|
andrewm@35
|
433 ignoresTwoFingers_ = properties.getBoolValue("ignoresTwoFingers");
|
andrewm@35
|
434 ignoresThreeFingers_ = properties.getBoolValue("ignoresThreeFingers");
|
andrewm@34
|
435 direction_ = properties.getIntValue("direction");
|
andrewm@34
|
436
|
andrewm@43
|
437 // These values added to later versions of the presets so check
|
andrewm@43
|
438 // whether they actually exist or not
|
andrewm@43
|
439 if(properties.containsKey("use14Bit"))
|
andrewm@43
|
440 use14BitControl_ = properties.getBoolValue("use14Bit");
|
andrewm@43
|
441
|
andrewm@34
|
442 // Update MIDI information; this doesn't actually change the controller
|
andrewm@34
|
443 // (which is already set) but it adds a listener and updates the ranges
|
andrewm@34
|
444 setController(midiControllerNumber_);
|
andrewm@34
|
445
|
andrewm@33
|
446 return true;
|
andrewm@33
|
447 }
|
andrewm@33
|
448
|
andrewm@0
|
449 // ***** Private Methods *****
|
andrewm@0
|
450
|
andrewm@0
|
451 void TouchkeyControlMappingFactory::initializeMappingParameters(int noteNumber, TouchkeyControlMapping *mapping) {
|
andrewm@0
|
452 // Set parameters
|
andrewm@0
|
453 mapping->setInputParameter(inputParameter_, inputType_);
|
andrewm@0
|
454 mapping->setRange(inputRangeMin_, inputRangeMax_, outputRangeMin_, outputRangeMax_, outputDefault_);
|
andrewm@0
|
455 mapping->setThreshold(threshold_);
|
andrewm@0
|
456 mapping->setIgnoresMultipleFingers(ignoresTwoFingers_, ignoresThreeFingers_);
|
andrewm@0
|
457 mapping->setDirection(direction_);
|
andrewm@0
|
458 }
|