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@0
|
27
|
andrewm@0
|
28 const int TouchkeyControlMappingFactory::kDefaultController = 1;
|
andrewm@0
|
29 const float TouchkeyControlMappingFactory::kDefaultOutputRangeMin = 0.0;
|
andrewm@0
|
30 const float TouchkeyControlMappingFactory::kDefaultOutputRangeMax = 127.0;
|
andrewm@0
|
31 const float TouchkeyControlMappingFactory::kDefaultOutputDefault = 0.0;
|
andrewm@0
|
32
|
andrewm@0
|
33 TouchkeyControlMappingFactory::TouchkeyControlMappingFactory(PianoKeyboard &keyboard, MidiKeyboardSegment& segment) :
|
andrewm@0
|
34 TouchkeyBaseMappingFactory<TouchkeyControlMapping>(keyboard, segment),
|
andrewm@0
|
35 inputParameter_(TouchkeyControlMapping::kInputParameterYPosition),
|
andrewm@0
|
36 inputType_(TouchkeyControlMapping::kTypeAbsolute),
|
andrewm@0
|
37 outputRangeMin_(kDefaultOutputRangeMin), outputRangeMax_(kDefaultOutputRangeMax),
|
andrewm@0
|
38 outputDefault_(kDefaultOutputDefault), threshold_(0.0),
|
andrewm@0
|
39 ignoresTwoFingers_(TouchkeyControlMapping::kDefaultIgnoresTwoFingers),
|
andrewm@0
|
40 ignoresThreeFingers_(TouchkeyControlMapping::kDefaultIgnoresThreeFingers),
|
andrewm@0
|
41 direction_(TouchkeyControlMapping::kDefaultDirection)
|
andrewm@0
|
42 {
|
andrewm@0
|
43 setController(kDefaultController);
|
andrewm@0
|
44 }
|
andrewm@0
|
45
|
andrewm@0
|
46 // ***** Destructor *****
|
andrewm@0
|
47
|
andrewm@0
|
48 TouchkeyControlMappingFactory::~TouchkeyControlMappingFactory() {
|
andrewm@0
|
49
|
andrewm@0
|
50 }
|
andrewm@0
|
51
|
andrewm@0
|
52 // ***** Accessors / Modifiers *****
|
andrewm@0
|
53
|
andrewm@0
|
54 void TouchkeyControlMappingFactory::setInputParameter(int inputParameter) {
|
andrewm@0
|
55 inputParameter_ = inputParameter;
|
andrewm@0
|
56 }
|
andrewm@0
|
57
|
andrewm@0
|
58 void TouchkeyControlMappingFactory::setInputType(int inputType) {
|
andrewm@0
|
59 inputType_ = inputType;
|
andrewm@0
|
60 }
|
andrewm@0
|
61
|
andrewm@0
|
62 void TouchkeyControlMappingFactory::setController(int controller) {
|
andrewm@0
|
63 // Before changing the controller, check if we were going to or from the pitch wheel.
|
andrewm@0
|
64 // If so, we should scale the value to or from a 14-bit value
|
andrewm@0
|
65 if(midiControllerNumber_ == MidiKeyboardSegment::kControlPitchWheel &&
|
andrewm@0
|
66 controller != MidiKeyboardSegment::kControlPitchWheel) {
|
andrewm@0
|
67 outputRangeMax_ = outputRangeMax_ / 128.0;
|
andrewm@0
|
68 if(outputRangeMax_ > 127.0)
|
andrewm@0
|
69 outputRangeMax_ = 127.0;
|
andrewm@0
|
70 outputRangeMin_ = outputRangeMin_ / 128.0;
|
andrewm@0
|
71 if(outputRangeMin_ > 127.0)
|
andrewm@0
|
72 outputRangeMin_ = 127.0;
|
andrewm@0
|
73 outputDefault_ = outputDefault_ / 128.0;
|
andrewm@0
|
74 if(outputDefault_ > 127.0)
|
andrewm@0
|
75 outputDefault_ = 127.0;
|
andrewm@0
|
76 }
|
andrewm@0
|
77 else if(midiControllerNumber_ != MidiKeyboardSegment::kControlPitchWheel &&
|
andrewm@0
|
78 controller == MidiKeyboardSegment::kControlPitchWheel) {
|
andrewm@0
|
79 if(outputRangeMax_ == 127.0)
|
andrewm@0
|
80 outputRangeMax_ = 16383.0;
|
andrewm@0
|
81 else
|
andrewm@0
|
82 outputRangeMax_ = outputRangeMax_ * 128.0;
|
andrewm@0
|
83 if(outputRangeMin_ == 127.0)
|
andrewm@0
|
84 outputRangeMin_ = 16383.0;
|
andrewm@0
|
85 else
|
andrewm@0
|
86 outputRangeMin_ = outputRangeMin_ * 128.0;
|
andrewm@0
|
87 if(outputDefault_ == 127.0)
|
andrewm@0
|
88 outputDefault_ = 16383.0;
|
andrewm@0
|
89 else
|
andrewm@0
|
90 outputDefault_ = outputDefault_ * 128.0;
|
andrewm@0
|
91 }
|
andrewm@0
|
92
|
andrewm@0
|
93 setMidiParameters(controller, inputRangeMin_, inputRangeMax_, inputRangeCenter_,
|
andrewm@0
|
94 outputDefault_, outputRangeMin_, outputRangeMax_);
|
andrewm@0
|
95
|
andrewm@0
|
96 // Listen to incoming controls from the keyboard too, if this is enabled
|
andrewm@0
|
97 // in MidiKeyboardSegment
|
andrewm@0
|
98 if(midiConverter_ != 0) {
|
andrewm@0
|
99 midiConverter_->listenToIncomingControl(midiControllerNumber_);
|
andrewm@0
|
100 }
|
andrewm@0
|
101 }
|
andrewm@0
|
102
|
andrewm@0
|
103 /*void TouchkeyControlMappingFactory::setRange(float inputMin, float inputMax, float inputCenter, float outputMin, float outputMax, float outputDefault) {
|
andrewm@0
|
104 // All possible input parameters are in the range [-1, 1],
|
andrewm@0
|
105 // and actually in the range [0, 1] if absolute values are used
|
andrewm@0
|
106 // (though we don't check this here)
|
andrewm@0
|
107 if(inputMin < -1.0)
|
andrewm@0
|
108 inputRangeMin_ = -1.0;
|
andrewm@0
|
109 else if(inputMin > 1.0)
|
andrewm@0
|
110 inputRangeMin_ = 1.0;
|
andrewm@0
|
111 else
|
andrewm@0
|
112 inputRangeMin_ = inputMin;
|
andrewm@0
|
113 if(inputMax < -1.0)
|
andrewm@0
|
114 inputRangeMax_ = -1.0;
|
andrewm@0
|
115 else if(inputMax > 1.0)
|
andrewm@0
|
116 inputRangeMax_ = 1.0;
|
andrewm@0
|
117 else
|
andrewm@0
|
118 inputRangeMax_ = inputMax;
|
andrewm@0
|
119 if(inputCenter < -1.0)
|
andrewm@0
|
120 inputRangeCenter_ = -1.0;
|
andrewm@0
|
121 else if(inputCenter > 1.0)
|
andrewm@0
|
122 inputRangeCenter_ = 1.0;
|
andrewm@0
|
123 else
|
andrewm@0
|
124 inputRangeCenter_ = inputCenter;
|
andrewm@0
|
125 outputRangeMin_ = outputMin;
|
andrewm@0
|
126 outputRangeMax_ = outputMax;
|
andrewm@0
|
127 outputDefault_ = outputDefault;
|
andrewm@0
|
128
|
andrewm@0
|
129 // Update control
|
andrewm@0
|
130 if(midiConverter_ == 0)
|
andrewm@0
|
131 return;
|
andrewm@0
|
132 midiConverter_->removeAllControls();
|
andrewm@0
|
133 midiConverter_->addControl(controlName_.c_str(), 1, inputRangeMin_, inputRangeMax_, inputRangeCenter_, OscMidiConverter::kOutOfRangeClip);
|
andrewm@0
|
134 }*/
|
andrewm@0
|
135
|
andrewm@0
|
136 void TouchkeyControlMappingFactory::setRangeInputMin(float inputMin) {
|
andrewm@0
|
137 if(inputMin < -1.0)
|
andrewm@0
|
138 inputRangeMin_ = -1.0;
|
andrewm@0
|
139 else if(inputMin > 1.0)
|
andrewm@0
|
140 inputRangeMin_ = 1.0;
|
andrewm@0
|
141 else
|
andrewm@0
|
142 inputRangeMin_ = inputMin;
|
andrewm@0
|
143
|
andrewm@0
|
144 // Update control
|
andrewm@0
|
145 //if(midiConverter_ == 0)
|
andrewm@0
|
146 // return;
|
andrewm@0
|
147 //midiConverter_->setControlMinValue(controlName_.c_str(), inputRangeMin_);
|
andrewm@0
|
148 setMidiParameters(midiControllerNumber_, inputRangeMin_, inputRangeMax_, inputRangeCenter_,
|
andrewm@0
|
149 outputDefault_, outputRangeMin_, outputRangeMax_);
|
andrewm@0
|
150 }
|
andrewm@0
|
151
|
andrewm@0
|
152 void TouchkeyControlMappingFactory::setRangeInputMax(float inputMax) {
|
andrewm@0
|
153 if(inputMax < -1.0)
|
andrewm@0
|
154 inputRangeMax_ = -1.0;
|
andrewm@0
|
155 else if(inputMax > 1.0)
|
andrewm@0
|
156 inputRangeMax_ = 1.0;
|
andrewm@0
|
157 else
|
andrewm@0
|
158 inputRangeMax_ = inputMax;
|
andrewm@0
|
159
|
andrewm@0
|
160 // Update control
|
andrewm@0
|
161 //if(midiConverter_ == 0)
|
andrewm@0
|
162 // return;
|
andrewm@0
|
163 //midiConverter_->setControlMaxValue(controlName_.c_str(), inputRangeMax_);
|
andrewm@0
|
164 setMidiParameters(midiControllerNumber_, inputRangeMin_, inputRangeMax_, inputRangeCenter_,
|
andrewm@0
|
165 outputDefault_, outputRangeMin_, outputRangeMax_);
|
andrewm@0
|
166 }
|
andrewm@0
|
167
|
andrewm@0
|
168 void TouchkeyControlMappingFactory::setRangeInputCenter(float inputCenter) {
|
andrewm@0
|
169 if(inputCenter < -1.0)
|
andrewm@0
|
170 inputRangeCenter_ = -1.0;
|
andrewm@0
|
171 else if(inputCenter > 1.0)
|
andrewm@0
|
172 inputRangeCenter_ = 1.0;
|
andrewm@0
|
173 else
|
andrewm@0
|
174 inputRangeCenter_ = inputCenter;
|
andrewm@0
|
175
|
andrewm@0
|
176 // Update control
|
andrewm@0
|
177 //if(midiConverter_ == 0)
|
andrewm@0
|
178 // return;
|
andrewm@0
|
179 //midiConverter_->setControlCenterValue(controlName_.c_str(), inputRangeCenter_);
|
andrewm@0
|
180 setMidiParameters(midiControllerNumber_, inputRangeMin_, inputRangeMax_, inputRangeCenter_,
|
andrewm@0
|
181 outputDefault_, outputRangeMin_, outputRangeMax_);
|
andrewm@0
|
182 }
|
andrewm@0
|
183
|
andrewm@0
|
184 void TouchkeyControlMappingFactory::setRangeOutputMin(float outputMin) {
|
andrewm@0
|
185 outputRangeMin_ = outputMin;
|
andrewm@0
|
186
|
andrewm@0
|
187 setMidiParameters(midiControllerNumber_, inputRangeMin_, inputRangeMax_, inputRangeCenter_,
|
andrewm@0
|
188 outputDefault_, outputRangeMin_, outputRangeMax_);
|
andrewm@0
|
189 }
|
andrewm@0
|
190
|
andrewm@0
|
191 void TouchkeyControlMappingFactory::setRangeOutputMax(float outputMax) {
|
andrewm@0
|
192 outputRangeMax_ = outputMax;
|
andrewm@0
|
193
|
andrewm@0
|
194 setMidiParameters(midiControllerNumber_, inputRangeMin_, inputRangeMax_, inputRangeCenter_,
|
andrewm@0
|
195 outputDefault_, outputRangeMin_, outputRangeMax_);
|
andrewm@0
|
196 }
|
andrewm@0
|
197
|
andrewm@0
|
198 void TouchkeyControlMappingFactory::setRangeOutputDefault(float outputDefault) {
|
andrewm@0
|
199 outputDefault_ = outputDefault;
|
andrewm@0
|
200
|
andrewm@0
|
201 setMidiParameters(midiControllerNumber_, inputRangeMin_, inputRangeMax_, inputRangeCenter_,
|
andrewm@0
|
202 outputDefault_, outputRangeMin_, outputRangeMax_);
|
andrewm@0
|
203 }
|
andrewm@0
|
204
|
andrewm@0
|
205 void TouchkeyControlMappingFactory::setThreshold(float threshold) {
|
andrewm@0
|
206 threshold_ = threshold;
|
andrewm@0
|
207 }
|
andrewm@0
|
208
|
andrewm@0
|
209 void TouchkeyControlMappingFactory::setIgnoresTwoFingers(bool ignoresTwo) {
|
andrewm@0
|
210 ignoresTwoFingers_ = ignoresTwo;
|
andrewm@0
|
211 }
|
andrewm@0
|
212
|
andrewm@0
|
213 void TouchkeyControlMappingFactory::setIgnoresThreeFingers(bool ignoresThree) {
|
andrewm@0
|
214 ignoresThreeFingers_ = ignoresThree;
|
andrewm@0
|
215 }
|
andrewm@0
|
216
|
andrewm@0
|
217 void TouchkeyControlMappingFactory::setDirection(int direction) {
|
andrewm@0
|
218 direction_ = direction;
|
andrewm@0
|
219 }
|
andrewm@0
|
220
|
andrewm@0
|
221 // ***** GUI Support *****
|
andrewm@0
|
222 MappingEditorComponent* TouchkeyControlMappingFactory::createBasicEditor() {
|
andrewm@0
|
223 return new TouchkeyControlMappingShortEditor(*this);
|
andrewm@0
|
224 }
|
andrewm@0
|
225
|
andrewm@0
|
226 // ***** Private Methods *****
|
andrewm@0
|
227
|
andrewm@0
|
228 void TouchkeyControlMappingFactory::initializeMappingParameters(int noteNumber, TouchkeyControlMapping *mapping) {
|
andrewm@0
|
229 // Set parameters
|
andrewm@0
|
230 mapping->setInputParameter(inputParameter_, inputType_);
|
andrewm@0
|
231 mapping->setRange(inputRangeMin_, inputRangeMax_, outputRangeMin_, outputRangeMax_, outputDefault_);
|
andrewm@0
|
232 mapping->setThreshold(threshold_);
|
andrewm@0
|
233 mapping->setIgnoresMultipleFingers(ignoresTwoFingers_, ignoresThreeFingers_);
|
andrewm@0
|
234 mapping->setDirection(direction_);
|
andrewm@0
|
235 }
|