-
Notifications
You must be signed in to change notification settings - Fork 2
/
freeboard_block.littefoot
542 lines (482 loc) · 19 KB
/
freeboard_block.littefoot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
/*
<metadata description="Seaboard Block script for standalone config changes" target="Seaboard" tags="Default;MPE;MIDI;Melodic">
<groups>
</groups>
<variables>
<variable name="none" type="bool" value="true" />
</variables>
</metadata>
*/
/* DOCS
https://docs.juce.com/master/namespaceBlocksProtocol.html#ad54d15b68ca1356e84793a7c60c5b524a9f2dba367b1b285d34769e56819b4537
https://docs.juce.com/blocks/the_littlefoot_language.html
https://docs.juce.com/blocks/group__LittleFootFunctions.html#ga68c037539d2d64289162d5c5b68e5964
pixel x0 y0 and x1 y0 is mode button pixels
pressure modes (config 32) are 0 for poly aftertouch, 1 for last played, 2 highest,3 lowest, 4 disabled, 5 hardest
Max X value(right): 5.8/10
Max Z value(down): 3.0/10
Config item max: 95, 64 and up are user values
config 64 used as function layer (mode button pressed) indicator
00NT: 701795
9S11: 714086
/*
If pressing mode button, octave down enables "normal" midi operation, channel set by key before letting go of mode key (function key)
and octave up enables MPE mode
All changes in config sync between all blocks in the chain
Midi CC 80 on channel 1 sets midi channel. 0 = MPE
Midi CC 81 on channel 1 sets Piano Mode. 0 = Piano mode off, 1 = on (and turns expression on/off as well)
*/
const float octaveDownXloc = 0.0;
const float octaveDownYloc = 0.0;
const float octaveUpXloc = 5.75;
const float octaveUpYloc = 0.0;
const float octaveSwitchXSize = 0.3;
const float octaveSwitchYSize = 0.2;
// Max Y value for top row, min for bottom (grows from right left corner 0,0)
const float topRow = 0.39;
const float botRow = 2.46;
// upper X limits for key mapping ( this has been calculated taking 3 key presses (1c, 2c, 3c), averaging them and averaging that to the average of the next one
// (((1c + 2c + 3c)/3)+((1Csharp + 2Csharp + 3Csharp)/3))/2
const float C = 0.276;
const float CSharp = 0.497;
const float D = 0.714;
const float DSharp = 0.910;
const float E = 1.249;
const float F = 1.597;
const float FSharp = 1.823;
const float G = 2.040;
const float GSharp = 2.259;
const float A = 2.458;
const float ASharp = 2.665;
const float B = 3.011;
const float C2 = 3.335;
const float CSharp2 = 3.545;
const float D2 = 3.779;
const float DSharp2 = 3.997;
const float E2 = 4.317;
const float F2 = 4.654;
const float FSharp2 = 4.857;
const float G2 = 5.060;
const float GSharp2 = 5.289;
const float A2 = 5.506;
const float ASharp2 = 5.722;
const float B2 = 5.835;
// Colours for mode button
const int blue = 0xff0000ff;
const int teal = 0xff00ffff;
const int yellow = 0xffffff00;
const int purple = 0xffff00ff;
const int orange = 0xfffd3c00;
//Default values for 5D
const int defaultVel = 37;
const int defaultLift = 127;
const int defaultGlide = 120;
const int defaultSlide = 62;
const int defaultPress = 87;
const int defaultAfterMode = 5; // Hardest
int xPos;
int presetIndex;
int topOctaveShift;
int clusterWidthLast;
bool settingsRequested;
// Config settings to sync
void initialise()
{
setLocalConfigActiveState (0, true, true);
setLocalConfigActiveState (1, true, true);
setLocalConfigActiveState (2, true, true);
setLocalConfigActiveState (3, true, true);
setLocalConfigActiveState (4, true, true);
setLocalConfigActiveState (5, true, false);
setLocalConfigActiveState (6, true, true);
setLocalConfigActiveState (7, true, true);
setLocalConfigActiveState (10, true, true);
setLocalConfigActiveState (11, true, true);
setLocalConfigActiveState (12, true, true);
setLocalConfigActiveState (13, true, true);
setLocalConfigActiveState (14, true, true);
setLocalConfigActiveState (15, true, true);
setLocalConfigActiveState (16, true, true);
setLocalConfigActiveState (17, true, true);
setLocalConfigActiveState (18, true, true);
setLocalConfigActiveState (30, true, true);
setLocalConfigActiveState (31, true, true);
setLocalConfigActiveState (32, true, true);
setLocalConfigActiveState (64, true, false);
setLocalConfigItemRange (4, -2, 4);
setLocalConfigItemRange (64, 0, 1);
setLocalConfig(4, 1); //so one lonely block gets middle C
setLocalConfig(64, 0);
setLocalConfig(32, defaultAfterMode);
setLocalConfig(10, defaultVel);
setLocalConfig(14, defaultLift);
setLocalConfig(11, defaultGlide);
setLocalConfig(12, defaultSlide);
setLocalConfig(13, defaultPress);
presetIndex = 0;
topOctaveShift = 255;
clusterWidthLast = 1;
updateTopologyShift();
settingsRequested = false;
syncBlockToMaster();
}
void sendConfigItemToCluster (int itemId)
{
if (getClusterWidth() < 2)
return;
int numBlocksInCluster = getNumBlocksInCurrentCluster();
for (int i = 0; i < numBlocksInCluster; ++i)
setRemoteConfig (getBlockIdForBlockInCluster(i), itemId, getLocalConfig (itemId));
}
void updateTopologyShift ()
{
if (getClusterWidth() > 1)
{
int newTopOct = 0;
int octStart = ((getClusterWidth() - 1) / 2);
newTopOct = (getClusterXpos() - octStart) * 2;
if (getClusterWidth() == 2) setLocalConfigItemRange(4,-2,2); // if 2 blocks wide, only allow 2 octave up and down
if (topOctaveShift != newTopOct)
{
topOctaveShift = newTopOct;
setLocalConfig (8, topOctaveShift);
}
if ((! getClusterXpos() && ! isMasterInCurrentCluster()) || (isMasterInCurrentCluster() && isMasterBlock()))
{
if (clusterWidthLast != getClusterWidth() || xPos != getClusterXpos())
{
clusterWidthLast = getClusterWidth();
sendConfigItemToCluster (4);
}
}
xPos = getClusterXpos();
}
else if (topOctaveShift != 0)
{
topOctaveShift = 0;
setLocalConfig (8, topOctaveShift);
}
if (getClusterWidth() == 1) setLocalConfigItemRange (4, -2, 4);
}
void repaint()
{
updateTopologyShift();
clearDisplay();
if (! getBlockIDOnPort(0)) // if leftmost block light up key
{
if (getLocalConfig(2) == 1) clearDisplay(teal); //if MPE mode
else if ((getLocalConfig(2) == 0) || (getLocalConfig(2) == 2)) // If normal mode show Yellow or orange if no piano mode
{
clearDisplay(yellow);
if (getLocalConfig(17) == 1) fillPixel(yellow,1,0);
if (getLocalConfig(17) == 0) fillPixel(orange,1,0);
if (getLocalConfig(15) == 1) fillPixel(purple,0,0);
}
}
}
void touchStart (int index, float x, float y, float z, float vz)
{
//int xi = int (x * 1000);
//int yi = int (y * 1000); //Random logging for debugging
//log(xi);
//log(yi);
//log(getBlockIdForBlockInCluster(0));
//log(getLocalConfig(9));
// Handle octave switches
if (x >= octaveDownXloc && x <= octaveDownXloc + octaveSwitchXSize &&
y >= octaveDownYloc && y <= octaveDownYloc + octaveSwitchYSize)
{
if (getLocalConfig(64) == 1) // If pressing mode button, octave down enables "normal" midi operation
{
enablePianoMode(true);
setChannelMode(1,1);
}
else if (getClusterWidth() > 1 && getClusterXpos() != 0) // if not the leftmost block, ignore the octave down key
{
handleTouchAsSeaboard (index);
}
else setLocalConfig(4, getLocalConfig (4) - 1);
}
else if (x >= octaveUpXloc && x <= octaveUpXloc + octaveSwitchXSize &&
y >= octaveUpYloc && y <= octaveUpYloc + octaveSwitchYSize)
{
if (getLocalConfig(64) == 1) // octave up and mode button makes mpe mode
{
enablePianoMode(false);
setChannelMode(0,0);
syncAllBlocks();
}
else if (getClusterWidth() > 1 && getClusterXpos() < getNumBlocksInCurrentCluster() - 1) // if not the rightmost block, ignore octave up key
{
handleTouchAsSeaboard (index);
}
else setLocalConfig(4, getLocalConfig (4) + 1);
}
// Handle midi channel choosing
else if (getLocalConfig(64) == 1) // if mode key is pressed
{
if (getLocalConfig(2)== 0) // If mpe is off, choose midi
{
if (x < C)
{
if (y < botRow && y > topRow) setChannelMode(1,0);
else if (y < 30.0 && y > botRow) setChannelMode(0,1);
}
else if (x > C && x < CSharp)
{
if (y < botRow && y > topRow) setChannelMode(2,0);
else if (y < 30.0 && y > botRow) setChannelMode(0,2);
else if (y > 0.0 && y < topRow) // Piano mode switch over Csharp
{
if (getLocalConfig(17) == 1) setLocalConfig(17,0);
else if (getLocalConfig(17) == 0) setLocalConfig(17,1);
}
}
else if (x > CSharp && x < D)
{
if (y < botRow && y > topRow) setChannelMode(3,0);
else if (y < 30.0 && y > botRow) setChannelMode(0,3);
}
else if (x > D && x < DSharp)
{
if (y < botRow && y > topRow) setChannelMode(4,0);
else if (y < 30.0 && y > botRow) setChannelMode(0,4);
else if (y > 0.0 && y < topRow) // Fixed velocity switch over Dsharp
{
if (getLocalConfig(15) == 1) setLocalConfig(15,0);
else if (getLocalConfig(15) == 0) setLocalConfig(15,1);
}
}
else if (x > DSharp && x < E)
{
if (y < botRow && y > topRow) setChannelMode(5,0);
else if (y < 30.0 && y > botRow) setChannelMode(0,5);
}
else if (x > E && x < F)
{
if (y < botRow && y > topRow) setChannelMode(6,0);
else if (y < 30.0 && y > botRow) setChannelMode(0,6);
}
else if (x > F && x < FSharp)
{
if (y < botRow && y > topRow) setChannelMode(7,0);
else if (y < 30.0 && y > botRow) setChannelMode(0,7);
else if (y > 0.0 && y < topRow) setLocalConfig(32,0); // set poly aftertouch over Fsharp
}
else if (x > FSharp && x < G)
{
if (y < botRow && y > topRow) setChannelMode(8,0);
else if (y < 30.0 && y > botRow) setChannelMode(0,8);
}
else if (x > G && x < GSharp)
{
if (y < botRow && y > topRow) setChannelMode(9,0);
else if (y < 30.0 && y > botRow) setChannelMode(0,9);
else if (y > 0.0 && y < topRow) setLocalConfig(32,defaultAfterMode); // Aftertouch default over Gsharp
}
else if (x > GSharp && x < A)
{
if (y < botRow && y > topRow) setChannelMode(10,0);
else if (y < 30.0 && y > botRow) setChannelMode(0,10);
}
else if (x > A && x < ASharp)
{
if (y < botRow && y > topRow) setChannelMode(11,0);
else if (y < 30.0 && y > botRow) setChannelMode(0,11);
else if (y > 0.0 && y < topRow) setLocalConfig(32,4); // Aftertouch disable over Asharp
}
else if (x > ASharp && x < B)
{
if (y < botRow && y > topRow) setChannelMode(12,0);
else if (y < 30.0 && y > botRow) setChannelMode(0,12);
}
}
//Here we use the secont octave for settings, defaults and some toggles
// The sharps are velocity, lift, glide, slide and press.
if (x > C2 && x < CSharp2) // If "key"
{
if (y > topRow) //and not in top row
{
int value = 127 - int (abs(map(y, 0.39, 3.0, 0.0 , 127.0))); //Get value in 0-127 range and absolute from y pos)
setLocalConfig(10, value); // and set it to the setting (vel,lift,glide,slide or press)
}
else if (y >= 0.0 && y < topRow) setLocalConfig(10, defaultVel); // if in top row reset to default set in variables up top
}
else if (x > D2 && x < DSharp2)
{
if (y > topRow)
{
int value = 127 - int (abs(map(y, 0.39, 3.0, 0.0 , 127.0)));
setLocalConfig(14, value);
}
else if (y >= 0.0 && y < topRow) setLocalConfig(14, defaultLift);
}
else if (x > F2 && x < FSharp2)
{
if (y > topRow)
{
int value = 127 - int (abs(map(y, 0.39, 3.0, 0.0 , 127.0)));
setLocalConfig(11, value);
}
else if (y >= 0.0 && y < topRow) setLocalConfig(11, defaultGlide);
}
else if (x > G2 && x < GSharp2)
{
if (y > topRow)
{
int value = 127 - int (abs(map(y, 0.39, 3.0, 0.0 , 127.0)));
setLocalConfig(12, value);
}
else if (y >= 0.0 && y < topRow) setLocalConfig(12, defaultSlide);
}
else if (x > A2 && x < ASharp2){
if (y > topRow)
{
int value = 127 - int (abs(map(y, 0.39, 3.0, 0.0 , 127.0)));
log(value);
setLocalConfig(13, value);
}
else if (y >= 0.0 && y < topRow) setLocalConfig(13, defaultPress);
}
syncAllBlocks();
}
else // All other touches are treated as seaboard playing
{
handleTouchAsSeaboard (index);
}
}
void handleRequest (int id, int blockID)
{
if (id == 0) sendMessageToBlock (blockID, 0x783E, 0, getBlockIDForIndex (0));
}
void handleMessage (int data0, int data1, int data2)
{
if (data0 == 0x783C) handleRequest (data1, data2); // Request message
}
void handleButtonDown (int index)
{
if (index == 0) {
setLocalConfig(64,1); // when mode button is pressed, enable function layer globally using setting 64
sendConfigItemToCluster(64);
syncBlockToMaster();
sendMIDI(0x7B);
sendMIDI(0x78);
}
}
void handleButtonUp (int index)
{
if (index == 0) {
// When mode button is released, disable it
setLocalConfig(64, 0);
sendConfigItemToCluster(64);
}
}
void setChannelMode(int midiChannel, int endChannel)
{
if (midiChannel == 0 && endChannel == 0)
{
setLocalConfig(0, 2); // start channel
setLocalConfig(1, 16); // end channel
setLocalConfig(2, 1); // MPE on
}
else if ((midiChannel > 0 && midiChannel <= 16) || (endChannel > 0 && endChannel <= 16))
{
if (midiChannel != 0) setLocalConfig(0, midiChannel); // start channel
if (endChannel != 0) setLocalConfig(1, endChannel); // if end channel set, set it
setLocalConfig(2, 0); // MPE off
}
syncAllBlocks();
}
void enablePianoMode(bool enable) {
if (enable) {
setLocalConfig(17, 1); // Piano mode (i.e. slides trigger new notes)
setLocalConfig(11, 0); // Glide sensitivity
setLocalConfig(12, 0); // Slide sensitivity
setLocalConfig(13, 0); // Pressure sensitivity
setLocalConfig(15, 0); // fixed velocity off
}
else {
setLocalConfig(17, 0); // MPE mode
setLocalConfig(11, defaultGlide); // Glide sensitivity
setLocalConfig(12, defaultSlide); // Slide sensitivity
setLocalConfig(13, defaultPress); // Pressure sensitivity
}
syncAllBlocks();
}
void syncAllBlocks() {
// Updates some values relevant
sendConfigItemToCluster (0);
sendConfigItemToCluster (1);
sendConfigItemToCluster (2);
sendConfigItemToCluster (3);
sendConfigItemToCluster (5);
sendConfigItemToCluster (6);
sendConfigItemToCluster (7);
sendConfigItemToCluster (10);
sendConfigItemToCluster (11);
sendConfigItemToCluster (12);
sendConfigItemToCluster (13);
sendConfigItemToCluster (14);
sendConfigItemToCluster (15);
sendConfigItemToCluster (16);
sendConfigItemToCluster (17);
sendConfigItemToCluster (18);
sendConfigItemToCluster (30);
sendConfigItemToCluster (31);
sendConfigItemToCluster (32);
}
void syncBlockToMaster()
{
int masterAddr;
if (getClusterWidth() < 2)
return;
int numBlocksInCluster = getNumBlocksInCurrentCluster();
if (isMasterBlock())
{
syncAllBlocks();
}
else if (isMasterInCurrentCluster())
{
int port = getPortToMaster();
if (port != 0xff)
{
masterAddr = getBlockIDOnPort(port);
}
else
{
masterAddr = getBlockIDForIndex(0);
}
setLocalConfig( 0,int (requestRemoteConfig(masterAddr, 0)));
setLocalConfig( 1,int (requestRemoteConfig(masterAddr, 1)));
setLocalConfig( 2,int (requestRemoteConfig(masterAddr, 2)));
setLocalConfig( 3,int (requestRemoteConfig(masterAddr, 3)));
setLocalConfig( 5,int (requestRemoteConfig(masterAddr, 5)));
setLocalConfig( 6,int (requestRemoteConfig(masterAddr, 6)));
setLocalConfig( 7,int (requestRemoteConfig(masterAddr, 7)));
setLocalConfig( 10,int (requestRemoteConfig(masterAddr, 10)));
setLocalConfig( 11,int (requestRemoteConfig(masterAddr, 11)));
setLocalConfig( 12,int (requestRemoteConfig(masterAddr, 12)));
setLocalConfig( 13,int (requestRemoteConfig(masterAddr, 13)));
setLocalConfig( 14,int (requestRemoteConfig(masterAddr, 14)));
setLocalConfig( 15,int (requestRemoteConfig(masterAddr, 15)));
setLocalConfig( 16,int (requestRemoteConfig(masterAddr, 16)));
setLocalConfig( 17,int (requestRemoteConfig(masterAddr, 17)));
setLocalConfig( 18,int (requestRemoteConfig(masterAddr, 18)));
setLocalConfig( 30,int (requestRemoteConfig(masterAddr, 30)));
setLocalConfig( 31,int (requestRemoteConfig(masterAddr, 31)));
setLocalConfig( 32,int (requestRemoteConfig(masterAddr, 32)));
}
}
void handleMIDI(int byte0, int byte1, int byte2) {
// use CC #80 on midi channel 0 to set midi channel. Value 0 means MPE Mode
int channel = (byte0 & 0xF) + 1;
int command = byte0 >> 4;
if (channel == 1 && command == 11) { // 11 = midi CC command
if (byte1 == 80) {
setChannelMode(byte2,byte2);
}
else if (byte1 == 81) {
enablePianoMode(byte2 > 0 ? true : false);
}
}
}