|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | /////////// KNOB Factory |
| 8 | +// Multitouch MIDI knob GUI |
8 | 9 | function knob_factory() { |
9 | 10 | const DEFAULT_KNOB_TOUCHS = 1; |
10 | 11 | const DEFAULT_KNOB_RADIUS = 250; |
@@ -49,13 +50,24 @@ function knob_factory() { |
49 | 50 | this.center = mouseEvent.point; |
50 | 51 | this.theta = deg_to_rad(DEFAULT_KNOB_OFFSET); |
51 | 52 | this.data.msg = []; |
52 | | - let midi_touch; |
| 53 | + let touch_msg; |
53 | 54 | for (let _touch = 0; _touch < DEFAULT_KNOB_TOUCHS; _touch++) { |
54 | | - midi_touch = {}; |
55 | | - midi_touch.radius = midi_msg_builder(DEFAULT_KNOB_MODE_R); |
56 | | - midi_touch.theta = midi_msg_builder(DEFAULT_KNOB_MODE_T); |
57 | | - midi_touch.press = midi_msg_builder(DEFAULT_KNOB_MODE_Z); |
58 | | - this.data.msg.push(midi_touch); |
| 55 | + touch_msg = {}; |
| 56 | + touch_msg.radius = midi_msg_builder(DEFAULT_KNOB_MODE_R); |
| 57 | + touch_msg.theta = midi_msg_builder(DEFAULT_KNOB_MODE_T); |
| 58 | + switch (this.data.mode_z) { |
| 59 | + case NOTE_ON: |
| 60 | + touch_msg.note = midi_msg_builder(NOTE_ON); |
| 61 | + break; |
| 62 | + case C_CHANGE: |
| 63 | + touch_msg.press = midi_msg_builder(C_CHANGE); |
| 64 | + break; |
| 65 | + case AFTERTOUCH_POLY: |
| 66 | + touch_msg.note = midi_msg_builder(NOTE_ON); |
| 67 | + touch_msg.press = midi_msg_builder(C_CHANGE); |
| 68 | + break; |
| 69 | + } |
| 70 | + this.data.msg.push(touch_msg); |
59 | 71 | } |
60 | 72 | }, |
61 | 73 |
|
@@ -89,33 +101,46 @@ function knob_factory() { |
89 | 101 | this.data.mode_z = this.children["knob-group"].data.mode_z; |
90 | 102 |
|
91 | 103 | this.data.msg = []; |
92 | | - let midi_touch; |
93 | | - if (this.data.mode_z != previous_touch_mode_z) { |
94 | | - for (let _touch = 0; _touch < this.data.touchs; _touch++) { |
95 | | - midi_touch = {}; |
96 | | - midi_touch.radius = midi_msg_builder(DEFAULT_KNOB_MODE_R); |
97 | | - midi_touch.theta = midi_msg_builder(DEFAULT_KNOB_MODE_T); |
98 | | - midi_touch.press = midi_msg_builder(this.data.mode_z); |
99 | | - this.data.msg.push(midi_touch); |
| 104 | + for (let _touch = 0; _touch < this.data.touchs; _touch++) { |
| 105 | + let touch_msg = {}; |
| 106 | + if (this.data.mode_z != previous_touch_mode_z) { |
| 107 | + touch_msg.radius = midi_msg_builder(DEFAULT_KNOB_MODE_R); |
| 108 | + touch_msg.theta = midi_msg_builder(DEFAULT_KNOB_MODE_T); |
| 109 | + switch (this.data.mode_z) { |
| 110 | + case NOTE_ON: |
| 111 | + touch_msg.note = midi_msg_builder(NOTE_ON); |
| 112 | + break; |
| 113 | + case C_CHANGE: |
| 114 | + touch_msg.press = midi_msg_builder(C_CHANGE); |
| 115 | + break; |
| 116 | + case AFTERTOUCH_POLY: |
| 117 | + touch_msg.note = midi_msg_builder(NOTE_ON); |
| 118 | + touch_msg.press = midi_msg_builder(C_CHANGE); |
| 119 | + break; |
| 120 | + } |
100 | 121 | } |
101 | | - } |
102 | | - else { |
103 | | - for (let _touch = 0; _touch < this.data.touchs; _touch++) { |
| 122 | + else { |
104 | 123 | if (_touch < previous_touch_count) { |
105 | | - // ERROR -> QUIK_FIXME |
106 | | - //let status = midi_msg_status_unpack(this.children["touchs-group"].children[_touch].msg.press.midi.status); |
107 | | - //let new_status = midi_msg_status_pack(this.data.mode_z, status.channel); |
108 | | - //this.children["touchs-group"].children[_touch].msg.press.midi.status = new_status; |
109 | | - this.data.msg.push(this.children["touchs-group"].children[_touch].msg); |
| 124 | + touch_msg = this.children["touchs-group"].children[_touch].msg; |
110 | 125 | } |
111 | 126 | else { |
112 | | - midi_touch = {}; |
113 | | - midi_touch.radius = midi_msg_builder(DEFAULT_KNOB_MODE_R); |
114 | | - midi_touch.theta = midi_msg_builder(DEFAULT_KNOB_MODE_T); |
115 | | - midi_touch.press = midi_msg_builder(this.data.mode_z); |
116 | | - this.data.msg.push(midi_touch); |
| 127 | + touch_msg.radius = midi_msg_builder(DEFAULT_KNOB_MODE_R); |
| 128 | + touch_msg.theta = midi_msg_builder(DEFAULT_KNOB_MODE_T); |
| 129 | + switch (this.data.mode_z) { |
| 130 | + case NOTE_ON: |
| 131 | + touch_msg.note = midi_msg_builder(NOTE_ON); |
| 132 | + break; |
| 133 | + case C_CHANGE: |
| 134 | + touch_msg.press = midi_msg_builder(C_CHANGE); |
| 135 | + break; |
| 136 | + case AFTERTOUCH_POLY: |
| 137 | + touch_msg.note = midi_msg_builder(NOTE_ON); |
| 138 | + touch_msg.press = midi_msg_builder(C_CHANGE); |
| 139 | + break; |
| 140 | + } |
117 | 141 | } |
118 | 142 | } |
| 143 | + this.data.msg.push(touch_msg); |
119 | 144 | } |
120 | 145 | this.center = this.children["knob-group"].center; |
121 | 146 | this.radius = this.children["knob-group"].radius; |
@@ -173,28 +198,68 @@ function knob_factory() { |
173 | 198 | previous_touch = current_touch; |
174 | 199 | current_touch = _touch_group; |
175 | 200 | break; |
| 201 | + case THROUGH_MODE: |
| 202 | + switch (_knob.data.mode_z) { |
| 203 | + case NOTE_ON: |
| 204 | + _touch_group.msg.note.midi.status = (_touch_group.msg.note.midi.status | NOTE_ON); |
| 205 | + _touch_group.msg.note.midi.data2 = 127; |
| 206 | + send_midi_msg(_touch_group.msg.note.midi); |
| 207 | + break; |
| 208 | + case C_CHANGE: |
| 209 | + _touch_group.msg.press.midi.data2 = get_random_int(64, 127); |
| 210 | + send_midi_msg(_touch_group.msg.press.midi); |
| 211 | + break; |
| 212 | + case AFTERTOUCH_POLY: |
| 213 | + _touch_group.msg.note.midi.status = (_touch_group.msg.note.midi.status | NOTE_ON); |
| 214 | + _touch_group.msg.note.midi.data2 = 127; |
| 215 | + send_midi_msg(_touch_group.msg.note.midi); |
| 216 | + _touch_group.msg.press.midi.data2 = get_random_int(64, 127); |
| 217 | + send_midi_msg(_touch_group.msg.press.midi); |
| 218 | + break; |
| 219 | + } |
| 220 | + break; |
176 | 221 | case PLAY_MODE: |
177 | | - // Set midi_msg status to NOTE_ON |
178 | | - _touch_group.msg.press.midi.status = _touch_group.msg.press.midi.status | NOTE_ON; |
179 | | - _touch_group.msg.press.midi.data2 = 127; |
180 | | - send_midi_msg(_touch_group.msg.press.midi); |
| 222 | + // N/A |
181 | 223 | break; |
182 | 224 | } |
183 | 225 | } |
184 | 226 |
|
185 | 227 | _knob_touch.onMouseUp = function () { |
186 | | - // Set midi_msg status to NOTE_OFF |
187 | | - _touch_group.msg.press.midi.status = _touch_group.msg.press.midi.status & NOTE_OFF; |
188 | | - _touch_group.msg.press.midi.data2 = 0; |
189 | | - send_midi_msg(_touch_group.msg.press.midi); |
| 228 | + switch (e256_current_mode) { |
| 229 | + case EDIT_MODE: |
| 230 | + break; |
| 231 | + case THROUGH_MODE: |
| 232 | + switch (_knob.data.mode_z) { |
| 233 | + case NOTE_ON: |
| 234 | + _touch_group.msg.note.midi.status = (_touch_group.msg.note.midi.status & NOTE_OFF); |
| 235 | + _touch_group.msg.note.midi.data2 = 0; |
| 236 | + send_midi_msg(_touch_group.msg.note.midi); |
| 237 | + break; |
| 238 | + case C_CHANGE: |
| 239 | + _touch_group.msg.press.midi.data2 = 0; |
| 240 | + send_midi_msg(_touch_group.msg.press.midi); |
| 241 | + break; |
| 242 | + case AFTERTOUCH_POLY: |
| 243 | + _touch_group.msg.note.midi.status = (_touch_group.msg.note.midi.status & NOTE_OFF); |
| 244 | + _touch_group.msg.note.midi.data2 = 0; |
| 245 | + send_midi_msg(_touch_group.msg.note.midi); |
| 246 | + _touch_group.msg.press.midi.data2 = 0; |
| 247 | + send_midi_msg(_touch_group.msg.press.midi); |
| 248 | + break; |
| 249 | + } |
| 250 | + break; |
| 251 | + case PLAY_MODE: |
| 252 | + // N/A |
| 253 | + break; |
| 254 | + } |
190 | 255 | } |
191 | 256 |
|
192 | 257 | _knob_touch.onMouseDrag = function (mouseEvent) { |
193 | 258 | switch (e256_current_mode) { |
194 | 259 | case EDIT_MODE: |
195 | 260 | // N/A |
196 | 261 | break; |
197 | | - case PLAY_MODE: |
| 262 | + case THROUGH_MODE: |
198 | 263 | let x = mouseEvent.point.x - _knob.center.x; // Place the x origin to the circle center |
199 | 264 | let y = mouseEvent.point.y - _knob.center.y; // Place the y origin to the circle center |
200 | 265 | let polar = cart_to_pol(x, y); |
@@ -223,13 +288,16 @@ function knob_factory() { |
223 | 288 | send_midi_msg(_touch_group.msg.theta.midi); |
224 | 289 | } |
225 | 290 | break; |
| 291 | + case PLAY_MODE: |
| 292 | + break; |
226 | 293 | } |
227 | 294 | } |
228 | 295 |
|
229 | 296 | let _touch_txt = new paper.PointText({ |
230 | 297 | "name": "touch-txt", |
231 | 298 | "point": new paper.Point(_touch_group.center.x + _knob_touch_pos.x, _touch_group.center.y + _knob_touch_pos.y), |
232 | | - "content": _touch_group.msg.press.midi.data1, |
| 299 | + //"content": JSON.stringify(_touch_group.msg), // MAKE TI DESIGN ;-) |
| 300 | + "content": null, |
233 | 301 | "locked": true |
234 | 302 | }); |
235 | 303 |
|
|
0 commit comments