Mercurial > hg > touchkeys
comparison Source/Mappings/MultiFingerTrigger/TouchkeyMultiFingerTriggerMappingFactory.cpp @ 42:1526d2fbe01e
Updates to multi-finger trigger mapping, and a fix for control-change retransmission on loading presets.
author | Andrew McPherson <andrewm@eecs.qmul.ac.uk> |
---|---|
date | Thu, 21 Aug 2014 17:02:39 +0100 |
parents | 0deac2806a7b |
children | 90ce403d0dc5 |
comparison
equal
deleted
inserted
replaced
41:85577160a0d4 | 42:1526d2fbe01e |
---|---|
21 finger trigger mapping, which performs actions when two or more fingers | 21 finger trigger mapping, which performs actions when two or more fingers |
22 are added or removed from the key. | 22 are added or removed from the key. |
23 */ | 23 */ |
24 | 24 |
25 #include "TouchkeyMultiFingerTriggerMappingFactory.h" | 25 #include "TouchkeyMultiFingerTriggerMappingFactory.h" |
26 #include "TouchkeyMultiFingerTriggerMappingShortEditor.h" | |
27 | |
28 TouchkeyMultiFingerTriggerMappingFactory::TouchkeyMultiFingerTriggerMappingFactory(PianoKeyboard &keyboard, MidiKeyboardSegment& segment) | |
29 : TouchkeyBaseMappingFactory<TouchkeyMultiFingerTriggerMapping>(keyboard, segment), | |
30 numTouchesForTrigger_(TouchkeyMultiFingerTriggerMapping::kDefaultNumTouchesForTrigger), | |
31 numFramesForTrigger_(TouchkeyMultiFingerTriggerMapping::kDefaultNumFramesForTrigger), | |
32 numConsecutiveTapsForTrigger_(TouchkeyMultiFingerTriggerMapping::kDefaultNumConsecutiveTapsForTrigger), | |
33 maxTapSpacing_(TouchkeyMultiFingerTriggerMapping::kDefaultMaxTapSpacing), | |
34 needsMidiNoteOn_(true), | |
35 triggerOnAction_(TouchkeyMultiFingerTriggerMapping::kDefaultTriggerOnAction), | |
36 triggerOffAction_(TouchkeyMultiFingerTriggerMapping::kDefaultTriggerOffAction), | |
37 triggerOnNoteNum_(TouchkeyMultiFingerTriggerMapping::kDefaultTriggerOnNoteNum), | |
38 triggerOffNoteNum_(TouchkeyMultiFingerTriggerMapping::kDefaultTriggerOffNoteNum), | |
39 triggerOnNoteVel_(TouchkeyMultiFingerTriggerMapping::kDefaultTriggerOnNoteVel), | |
40 triggerOffNoteVel_(TouchkeyMultiFingerTriggerMapping::kDefaultTriggerOffNoteVel) | |
41 { | |
42 | |
43 } | |
44 | |
45 void TouchkeyMultiFingerTriggerMappingFactory::setTouchesForTrigger(int touches) { | |
46 if(touches < 1) | |
47 touches = 1; | |
48 if(touches > 3) | |
49 touches = 3; | |
50 numTouchesForTrigger_ = touches; | |
51 } | |
52 | |
53 void TouchkeyMultiFingerTriggerMappingFactory::setFramesForTrigger(int frames) { | |
54 if(frames < 1) | |
55 frames = 1; | |
56 numFramesForTrigger_ = frames; | |
57 } | |
58 | |
59 void TouchkeyMultiFingerTriggerMappingFactory::setConsecutiveTapsForTrigger(int taps) { | |
60 if(taps < 1) | |
61 taps = 1; | |
62 numConsecutiveTapsForTrigger_ = taps; | |
63 } | |
64 | |
65 void TouchkeyMultiFingerTriggerMappingFactory::setMaxTimeBetweenTapsForTrigger(timestamp_diff_type timeDiff) { | |
66 if(timeDiff < 0) | |
67 timeDiff = 0; | |
68 maxTapSpacing_ = timeDiff; | |
69 } | |
70 | |
71 void TouchkeyMultiFingerTriggerMappingFactory::setNeedsMidiNoteOn(bool needsMidi) { | |
72 needsMidiNoteOn_ = needsMidi; | |
73 } | |
74 | |
75 void TouchkeyMultiFingerTriggerMappingFactory::setTriggerOnAction(int action) { | |
76 if(action > 0 && action < TouchkeyMultiFingerTriggerMapping::kActionMax) | |
77 triggerOnAction_ = action; | |
78 } | |
79 | |
80 void TouchkeyMultiFingerTriggerMappingFactory::setTriggerOffAction(int action) { | |
81 if(action > 0 && action < TouchkeyMultiFingerTriggerMapping::kActionMax) | |
82 triggerOffAction_ = action; | |
83 } | |
84 | |
85 void TouchkeyMultiFingerTriggerMappingFactory::setTriggerOnNoteNumber(int note) { | |
86 triggerOnNoteNum_ = note; | |
87 } | |
88 | |
89 void TouchkeyMultiFingerTriggerMappingFactory::setTriggerOffNoteNumber(int note) { | |
90 triggerOffNoteNum_ = note; | |
91 } | |
92 | |
93 void TouchkeyMultiFingerTriggerMappingFactory::setTriggerOnNoteVelocity(int velocity) { | |
94 if(velocity > 127) | |
95 velocity = 127; | |
96 triggerOnNoteVel_ = velocity; | |
97 } | |
98 | |
99 void TouchkeyMultiFingerTriggerMappingFactory::setTriggerOffNoteVelocity(int velocity) { | |
100 if(velocity > 127) | |
101 velocity = 127; | |
102 triggerOffNoteVel_ = velocity; | |
103 } | |
104 | |
105 // ***** GUI Support ***** | |
106 MappingEditorComponent* TouchkeyMultiFingerTriggerMappingFactory::createBasicEditor() { | |
107 return new TouchkeyMultiFingerTriggerMappingShortEditor(*this); | |
108 } | |
26 | 109 |
27 // ****** Preset Save/Load ****** | 110 // ****** Preset Save/Load ****** |
28 XmlElement* TouchkeyMultiFingerTriggerMappingFactory::getPreset() { | 111 XmlElement* TouchkeyMultiFingerTriggerMappingFactory::getPreset() { |
29 PropertySet properties; | 112 PropertySet properties; |
30 | 113 |
31 storeCommonProperties(properties); | 114 storeCommonProperties(properties); |
32 | 115 |
33 // No properties for now | 116 properties.setValue("numTouchesForTrigger", numTouchesForTrigger_); |
117 properties.setValue("numFramesForTrigger", numFramesForTrigger_); | |
118 properties.setValue("numConsecutiveTapsForTrigger", numConsecutiveTapsForTrigger_); | |
119 properties.setValue("maxTapSpacing", maxTapSpacing_); | |
120 properties.setValue("needsMidiNoteOn", needsMidiNoteOn_); | |
121 properties.setValue("triggerOnAction", triggerOnAction_); | |
122 properties.setValue("triggerOffAction", triggerOffAction_); | |
123 properties.setValue("triggerOnNoteNum", triggerOnNoteNum_); | |
124 properties.setValue("triggerOffNoteNum", triggerOffNoteNum_); | |
125 properties.setValue("triggerOnNoteVel", triggerOnNoteVel_); | |
126 properties.setValue("triggerOffNoteVel", triggerOffNoteVel_); | |
34 | 127 |
35 XmlElement* preset = properties.createXml("MappingFactory"); | 128 XmlElement* preset = properties.createXml("MappingFactory"); |
36 preset->setAttribute("type", "MultiFingerTrigger"); | 129 preset->setAttribute("type", "MultiFingerTrigger"); |
37 | 130 |
38 return preset; | 131 return preset; |
46 properties.restoreFromXml(*preset); | 139 properties.restoreFromXml(*preset); |
47 | 140 |
48 if(!loadCommonProperties(properties)) | 141 if(!loadCommonProperties(properties)) |
49 return false; | 142 return false; |
50 | 143 |
51 // Nothing specific to do for now | 144 // Load specific properties |
145 if(properties.containsKey("numTouchesForTrigger")) | |
146 numTouchesForTrigger_ = properties.getIntValue("numTouchesForTrigger"); | |
147 if(properties.containsKey("numFramesForTrigger")) | |
148 numFramesForTrigger_ = properties.getIntValue("numFramesForTrigger"); | |
149 if(properties.containsKey("numConsecutiveTapsForTrigger")) | |
150 numConsecutiveTapsForTrigger_ = properties.getIntValue("numConsecutiveTapsForTrigger"); | |
151 if(properties.containsKey("maxTapSpacing")) | |
152 maxTapSpacing_ = properties.getDoubleValue("maxTapSpacing"); | |
153 if(properties.containsKey("needsMidiNoteOn")) | |
154 needsMidiNoteOn_ = properties.getBoolValue("needsMidiNoteOn"); | |
155 if(properties.containsKey("triggerOnAction")) | |
156 triggerOnAction_ = properties.getBoolValue("triggerOnAction"); | |
157 if(properties.containsKey("triggerOffAction")) | |
158 triggerOffAction_ = properties.getBoolValue("triggerOffAction"); | |
159 if(properties.containsKey("triggerOnNoteNum")) | |
160 triggerOnNoteNum_ = properties.getBoolValue("triggerOnNoteNum"); | |
161 if(properties.containsKey("triggerOffNoteNum")) | |
162 triggerOffNoteNum_ = properties.getBoolValue("triggerOffNoteNum"); | |
163 if(properties.containsKey("triggerOnNoteVel")) | |
164 triggerOnNoteVel_ = properties.getBoolValue("triggerOnNoteVel"); | |
165 if(properties.containsKey("triggerOffNoteVel")) | |
166 triggerOffNoteVel_ = properties.getBoolValue("triggerOffNoteVel"); | |
52 | 167 |
53 return true; | 168 return true; |
54 } | 169 } |
170 | |
171 // ***** Private Methods ***** | |
172 | |
173 // Set the initial parameters for a new mapping | |
174 void TouchkeyMultiFingerTriggerMappingFactory::initializeMappingParameters(int noteNumber, TouchkeyMultiFingerTriggerMapping *mapping) { | |
175 mapping->setTouchesForTrigger(numTouchesForTrigger_); | |
176 mapping->setFramesForTrigger(numFramesForTrigger_); | |
177 mapping->setConsecutiveTapsForTrigger(numConsecutiveTapsForTrigger_); | |
178 mapping->setMaxTimeBetweenTapsForTrigger(maxTapSpacing_); | |
179 mapping->setNeedsMidiNoteOn(needsMidiNoteOn_); | |
180 mapping->setTriggerOnAction(triggerOnAction_); | |
181 mapping->setTriggerOffAction(triggerOffAction_); | |
182 mapping->setTriggerOnNoteNumber(triggerOnNoteNum_); | |
183 mapping->setTriggerOffNoteNumber(triggerOffNoteNum_); | |
184 mapping->setTriggerOnNoteVelocity(triggerOnNoteVel_); | |
185 mapping->setTriggerOffNoteVelocity(triggerOffNoteVel_); | |
186 } |