-
Notifications
You must be signed in to change notification settings - Fork 38
/
MidiLearnUI.fl
576 lines (560 loc) · 18.5 KB
/
MidiLearnUI.fl
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
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
# data file for the Fltk User Interface Designer (fluid)
version 1.0304
header_name {.h}
code_name {.cc}
comment {MidiLearnUI.h} {not_in_source in_header
}
comment {MidiLearnUI.cc} {in_source not_in_header
}
comment {Copyright (C) 2016-2017, Will Godfrey
This file is part of yoshimi, which is free software: you can redistribute
it and/or modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
yoshimi is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License (version 2 or
later) for more details.
You should have received a copy of the GNU General Public License along with
yoshimi; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA 02110-1301, USA.
Modified September 2017} {in_source in_header
}
decl {\#include <FL/fl_ask.H>
\#include "Misc/Config.h"
\#include "Misc/SynthEngine.h"} {private global
}
decl {using namespace std;} {public local
}
decl {\#include "MasterUI.h"} {private global
}
decl {\#include "Misc/SynthEngine.h"} {private local
}
decl {\# include "Misc/MiscFuncs.h"} {private local
}
decl {\#include "UI/MiscGui.h"
\#include "EffUI.h"
\#include "BankUI.h"
\#include "ADnoteUI.h"
\#include "SUBnoteUI.h"
\#include "PADnoteUI.h"
\#include "UI/WidgetMWSlider.h"
\#include "Params/Controller.h"
\#include "Misc/MiscFuncs.h"} {public global
}
class MidiLearnKitItem {: {public Fl_Group}
} {
Function {make_window()} {} {
Fl_Window midilearnkititem {
xywh {8 649 825 20} type Double hide
class Fl_Group
} {
Fl_Group midilearnkititemgroup {
xywh {56 -4 745 23} box FLAT_BOX
} {
Fl_Spinner CCcounter {
callback {send_data(16);}
tooltip {Continuous Controller to recognise} xywh {80 0 43 15} labelsize 12 minimum 0 maximum 129 value 14 textsize 12
}
Fl_Button {} {
callback {// does nothing - hides spinner arrows}
xywh {114 0 15 16} box FLAT_BOX down_box FLAT_BOX
}
Fl_Button nrpn {
label {8888 h}
tooltip {NRPN value} xywh {76 0 49 15} box THIN_DOWN_BOX down_box THIN_DOWN_BOX color 247 selection_color 7 labelsize 12 hide
}
Fl_Light_Button sevenbit {
callback {send_data(4);}
tooltip {Set for 7bit NRPN} xywh {59 0 13 15} box NO_BOX color 28 selection_color 1 hide
}
Fl_Choice channelchoice {
callback {send_data(48);}
tooltip {Incoming channel} xywh {137 0 39 15} down_box BORDER_BOX selection_color 49 labelsize 12 textsize 12
} {
MenuItem {} {
label 1
xywh {0 0 26 15} labelsize 11
}
MenuItem {} {
label 2
xywh {10 10 26 15} labelsize 11
}
MenuItem {} {
label 3
xywh {20 20 26 15} labelsize 11
}
MenuItem {} {
label 4
xywh {30 30 26 15} labelsize 11
}
MenuItem {} {
label 5
xywh {40 40 26 15} labelsize 11
}
MenuItem {} {
label 6
xywh {50 50 26 15} labelsize 11
}
MenuItem {} {
label 7
xywh {60 60 26 15} labelsize 11
}
MenuItem {} {
label 8
xywh {70 70 26 15} labelsize 11
}
MenuItem {} {
label 9
xywh {80 80 26 15} labelsize 11
}
MenuItem {} {
label 10
xywh {90 90 26 15} labelsize 11
}
MenuItem {} {
label 11
xywh {100 100 26 15} labelsize 11
}
MenuItem {} {
label 12
xywh {110 110 26 15} labelsize 11
}
MenuItem {} {
label 13
xywh {120 120 26 15} labelsize 11
}
MenuItem {} {
label 14
xywh {130 130 26 15} labelsize 11
}
MenuItem {} {
label 15
xywh {140 140 26 15} labelsize 11
}
MenuItem {} {
label 16
xywh {150 150 26 15} labelsize 11
}
MenuItem {} {
label All
xywh {160 160 26 15} labelsize 11
}
}
Fl_Check_Button compresscheck {
callback {send_data(1);}
tooltip {Limit or compress incoming value} xywh {324 0 15 15} down_box DOWN_BOX labelfont 1 align 4
}
Fl_Check_Button blockcheck {
callback {send_data(0);}
tooltip {Stop any later lines (or system controls) responding to this CC/Channel pair} xywh {360 0 20 15} down_box DOWN_BOX labelfont 1 align 4
}
Fl_Light_Button activity {
callback {if (o->value() != 0)
o->value(0);
else
o->value(1);}
xywh {180 0 13 15} box NO_BOX color 15 selection_color 2
}
Fl_Spinner minval {
callback {send_data(5);}
tooltip {Minimum % to pass on} xywh {197 0 52 15} type Float labelsize 12 minimum 0 step 0.5 value 0 textsize 12
}
Fl_Button {} {
callback {// does nothing - hides spinner arrows}
xywh {240 0 15 16} box FLAT_BOX down_box FLAT_BOX
}
Fl_Spinner maxval {
callback {send_data(6);}
tooltip {Maximim % to pass on} xywh {261 0 52 15} type Float labelsize 12 minimum 0 step 0.5 value 100 textsize 12
}
Fl_Button {} {
callback {// does nothing - hides spinner arrows}
xywh {303 0 15 16} box FLAT_BOX down_box FLAT_BOX
}
Fl_Button commandName {
label text
callback {send_data(8);}
tooltip {To delete, hold CTRL and click here.} xywh {395 0 400 15} box THIN_DOWN_BOX color 247 selection_color 247 labelfont 1 labelsize 10 align 64
}
}
Fl_Check_Button mutecheck {
label 999
callback {//
if (o->value())
midilearnkititemgroup->deactivate();
else
midilearnkititemgroup->activate();
send_data(2);}
tooltip {Completely ignore this line} xywh {39 0 21 15} down_box DOWN_BOX labelfont 1 labelsize 13 align 4
code0 {o->copy_label(to_string(n + 1).c_str());}
}
}
}
Function {send_data(int control)} {} {
code {//
bool doit = true;
int type = 0;
int CC = 0xff;
int chan = 0xff;
int min = 0xff;
int max = 0xff;
switch (control)
{
case 0:
if (blockcheck->value() != 0)
type = 1;
break;
case 1:
if (compresscheck->value() != 0)
type = 2;
break;
case 2:
if (mutecheck->value() != 0)
type = 4;
break;
case 4:
if (sevenbit->value() != 0)
type = 16;
break;
case 5:
min = lrint(minval->value() * 2.0f);
break;
case 6:
max = lrint(maxval->value() * 2.0f);
break;
case 8:
doit = (Fl::event_state(FL_CTRL) != 0);
if (doit)
doit = (fl_choice("Remove line. %d %s?", NULL, "No", "Yes", n + 1, commandName->label()) > 1);
break;
case 16:
CC = lrint(CCcounter->value());
break;
case 48: // gets changed to 16
chan = lrint(channelchoice->value());
break;
}
if (doit)
collect_data(synth, n, type, control & 0x1f, 216, CC, chan, min, max, 0);} {}
}
Function {MidiLearnKitItem(int x,int y, int w, int h, const char *label=0):Fl_Group(x,y,w,h,label)} {} {
code {n=0;} {}
}
Function {~MidiLearnKitItem()} {} {
code {midilearnkititem->hide();
delete(midilearnkititem);} {}
}
Function {init(SynthEngine *synth_, int n_)} {} {
code {//
synth = synth_;
n = n_;
make_window();
show();
end();} {}
}
decl {int n;} {private local
}
decl {char label[50];} {private local
}
decl {SynthEngine *synth;} {private local
}
decl {unsigned char stat;} {public local
}
}
class MidiLearnUI {selected : {private MiscFuncs}
} {
Function {make_window()} {} {
Fl_Window midilearnwindow {
label {Midi Learn}
tooltip {Editor for all learned controllers.
CTRL-right click on any knob/slider to learn.
Note: Adding/deleting entries or changing CC/Chan will renumber the lines.} xywh {7 694 820 285} type Double hide
code0 {send_data(22, 0, 3);}
} {
Fl_Scroll kitlist {
tooltip {Editor for all learned controllers.
CTRL-Right click on knobs/sliders to learn.
Note: Adding/deleting entries or changing CC/Chan will renumber the lines.} xywh {0 15 818 245} type VERTICAL box DOWN_FRAME
} {}
Fl_Box none {
label {No Entries}
xywh {290 131 206 44} labelsize 32
}
Fl_Box {} {
label Mute
xywh {18 0 41 15} labelfont 1 labelsize 11 align 18
}
Fl_Box {} {
label CC
xywh {80 0 40 15} labelfont 1 labelsize 11 align 18
}
Fl_Box {} {
label Chan
xywh {139 0 40 15} labelfont 1 labelsize 11 align 18
}
Fl_Box {} {
label Block
xywh {355 0 50 15} labelfont 1 labelsize 11 align 18
}
Fl_Box {} {
label Limit
xywh {310 0 48 15} labelfont 1 labelsize 11 align 18
}
Fl_Box {} {
label {Control Function}
xywh {530 0 130 15} labelfont 1 labelsize 11 align 18
}
Fl_Box {} {
label {Min %}
xywh {200 0 40 15} labelfont 1 labelsize 11 align 18
}
Fl_Box {} {
label {Max %}
xywh {263 0 40 15} labelfont 1 labelsize 11 align 18
}
Fl_Button {} {
label Close
callback {midilearnwindow->hide();}
xywh {730 262 63 20} box THIN_UP_BOX
}
Fl_Button load {
label Load
callback {char *filename;
filename = fl_file_chooser("Load:", "({*.xly})", NULL, 0);
if (filename == NULL)
return;
loadMidi(filename);}
tooltip {Load complete learned list} xywh {30 264 70 18} down_box DOWN_BOX labelfont 1 labelsize 12
}
Fl_Button save {
label Save
callback {char *filename;
filename = fl_file_chooser("Load:", "({*.xly})", NULL, 0);
if (filename == NULL)
return;
send_data(245, 0, 0, 0, 0, 0, 0, miscMsgPush((string) filename));
recent->activate();
setWindowTitle(findleafname(filename));}
tooltip {Save complete learned list} xywh {130 264 70 18} down_box DOWN_BOX labelfont 1 labelsize 12 deactivate
}
Fl_Button clear {
label Clear
callback {//
if (fl_choice("Remove all entries", NULL, "No", "Yes") < 2)
return;
send_data(96,0,0);
o->deactivate();
setWindowTitle();}
tooltip {Remove all entries} xywh {330 264 70 18} down_box DOWN_BOX labelfont 1 labelsize 12 deactivate
}
Fl_Button recent {
label Recent
callback {synth->getGuiMaster()->paramsui->Recent->position(midilearnwindow->x() + recent->x() - 80, midilearnwindow->y() + recent->y() - 187);
synth->getGuiMaster()->paramsui->Show(6);}
tooltip {Load from recently seen list} xywh {230 264 70 18} down_box DOWN_BOX labelfont 1 labelsize 12
code0 {vector<string> &listType = *synth->getHistory(6);}
code1 {if (listType.size() == 0) o->deactivate(); else o->activate();}
}
}
Fl_Window message {
xywh {4 20 290 85} type Double labelsize 12 hide
code0 {o->copy_label(synth->makeUniqueName("").c_str());}
} {
Fl_Box words {
label {?}
xywh {5 9 280 45} color 55 selection_color 55 labelfont 1 labelsize 12 align 149
}
Fl_Button {} {
label Close
callback {message->hide();}
xywh {211 60 70 20}
}
Fl_Button cancel {
label Cancel
callback {send_data(255, 0, 3);
o->hide();}
xywh {130 60 70 20} hide
}
}
}
Function {send_data(int control, float value, int type, int kititem = 0xff, int engine = 0xff, int insert = 0xff, int parameter = 0xff, int par2 = 0xff)} {} {
code {//
collect_data(synth, value, type, control, 216, kititem, engine, insert, parameter, par2);} {}
}
Function {returns_update(CommandBlock *getData)} {} {
code {//
int value = lrint(getData->data.value);
unsigned char type = getData->data.type;
unsigned char control = getData->data.control;
unsigned char kititem = getData->data.kit;
unsigned char engine = getData->data.engine;
unsigned char insert = getData->data.insert;
unsigned char parameter = getData->data.parameter;
unsigned char par2 = getData->data.par2;
string hex;
int nrpnTot;
unsigned int IDold;
unsigned int IDnew;
switch(control)
{
case 0:
break;
case 7:
if(type < 255) // edit line in place
{
midilearnkititem[value]->blockcheck->value((type & 1) != 0);
midilearnkititem[value]->compresscheck->value((type & 2) != 0);
midilearnkititem[value]->mutecheck->value((type & 4) != 0);
midilearnkititem[value]->sevenbit->value((type & 16) != 0);
if (type & 4) // it's muted
midilearnkititem[value]->midilearnkititemgroup->deactivate();
else
midilearnkititem[value]->midilearnkititemgroup->activate();
}
if (kititem < 255)
midilearnkititem[value]->CCcounter->value(kititem);
if (engine < 255)
midilearnkititem[value]->channelchoice->value(engine);
if (insert < 255)
midilearnkititem[value]->minval->value(insert / 2.0f);
if (parameter < 255)
midilearnkititem[value]->maxval->value(parameter / 2.0f);
break;
case 9: // set NRPN fixed value in place
nrpnTot = (int(engine) << 8) + (int(kititem));
/* These were stored 8 bit values so must be joined then
* split as two 7 bit values to give NRPN msb and lsb
*/
hex = (asHexString(nrpnTot >> 7)) + " " + (asHexString(nrpnTot & 0x7f));
midilearnkititem[value]->stat |= 0x10;
midilearnkititem[value]->nrpn->copy_label(hex.c_str());
midilearnkititem[value]->CCcounter->hide();
midilearnkititem[value]->nrpn->show();
midilearnkititem[value]->sevenbit->show();
break;
case 16:
addLine(getData);
break;
case 20: // not using this yet
break;
case 21:
words->copy_label(miscMsgPop(par2).c_str());
cancel->show();
message->position(Fl::event_x_root() + 16, Fl::event_y_root());
message->show();
break;
case 22:
midilearnwindow->show();
break;
case 24: // flash LED
IDold = kititem | (engine << 8);
for(int i = 0; i < MIDI_LEARN_BLOCK; ++ i)
{
if (midilearnkititem[i] != NULL && midilearnkititem[i]->mutecheck->value() == 0)
{
unsigned char newchan = midilearnkititem[i]->channelchoice->value();
if (newchan == 16) // all of them
newchan = engine; // force it to match
IDnew = (unsigned int)midilearnkititem[i]->CCcounter->value() | (newchan << 8);
if (IDold == IDnew && (type & 0x10) == (midilearnkititem[i]->stat & 0x10))
{
midilearnkititem[i]->activity->do_callback();
if (midilearnkititem[i]->blockcheck->value() != 0)
IDold = 0xffffff; // block following lines
}
}
}
break;
case 96:
clearAll(value == 0);
break;
case 255:
cancel->hide();
words->copy_label("Learn cancelled");
message->show();
break;
}} {}
}
Function {addLine(CommandBlock *getData)} {} {
code {//
int lineNo = ((int)getData->data.value);
int status = getData->data.type;
string name = miscMsgPop(getData->data.par2);
none->hide();
clear->activate();
save->activate();
midilearnkititem[lineNo] = new MidiLearnKitItem(0, 0,818,20,"");
midilearnkititem[lineNo]->init(synth, lineNo);
kitlist->add(midilearnkititem[lineNo]);
midilearnkititem[lineNo]->position(2, 21 + lineNo*20);
midilearnkititem[lineNo]->stat = (status & 0x10);
midilearnkititem[lineNo]->mutecheck->value(status & 4);
midilearnkititem[lineNo]->CCcounter->value(getData->data.kit);
midilearnkititem[lineNo]->channelchoice->value(getData->data.engine);
midilearnkititem[lineNo]->minval->value(getData->data.insert / 2.0f);
midilearnkititem[lineNo]->maxval->value(getData->data.parameter / 2.0f);
midilearnkititem[lineNo]->compresscheck->value(status & 2);
midilearnkititem[lineNo]->blockcheck->value(status & 1);
midilearnkititem[lineNo]->commandName->copy_label(name.c_str());
if (status & 4)
midilearnkititem[lineNo]->midilearnkititemgroup->deactivate();
midilearnwindow->redraw();} {}
}
Function {MidiLearnUI(SynthEngine *_synth)} {} {
code {//
synth = _synth;
for (int i = 0; i < MIDI_LEARN_BLOCK; ++i)
midilearnkititem[i] = NULL;
make_window();
setWindowTitle();
num = 0;} {}
}
Function {~MidiLearnUI()} {} {
code {;} {}
}
Function {Show()} {} {
code {//
midilearnwindow->show();} {}
}
Function {Hide()} {} {
code {//
midilearnwindow->hide();} {}
}
Function {clearAll(bool empty)} {} {
code {//
kitlist->clear();
for (int i = 0; i < MIDI_LEARN_BLOCK; ++i)
midilearnkititem[i] = NULL;
if (empty)
{
none->show();
clear->deactivate();
save->deactivate();
cancel->hide();
message->hide();
}
kitlist->redraw();
kitlist->show();} {}
}
Function {loadMidi(string file)} {} {
code {//
send_data(241, 0, 0, 0, 0, 0, 0, miscMsgPush((string) file));
recent->activate();
setWindowTitle(findleafname(file));} {}
}
Function {setWindowTitle(string name = "")} {} {
code {//
if (name > "")
name = " - " + name;
midilearnwindow->copy_label(synth->makeUniqueName("MIDI Learn" + name).c_str());} {}
}
decl {int lastkititem;} {public local
}
decl {SynthEngine *synth;} {private local
}
decl {MidiLearnKitItem *midilearnkititem[MIDI_LEARN_BLOCK];} {private local
}
decl {int num;} {private local
}
}