@mthines/reaper-mcp 0.82.0 → 0.82.1-beta.113.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,7 +23,8 @@
23
23
  // 1168..1199 ui_grm gain reduction per band in dB (8) -- slots 8..31 spare
24
24
  // 1200..1327 ui_kb MIDI keyboard: velocity per note 0..127 (0 = off)
25
25
  // 1328..1455 ui_fi the input trace for the before/after view (same 96 points as ui_fg)
26
- // 1456..2047 spare for the toolkit
26
+ // 1456..1489 ui_kq the keys played with the mouse: 16 note/velocity slots, then head and tail (ui_kpoll)
27
+ // 1490..2047 spare for the toolkit
27
28
  // 2048.. ui_mem the plugin
28
29
  // Every global starts with ui_. Sliders must be UNNAMED (slider1:0.5<0,1,0.01>Label): named
29
30
  // sliders do not keep their value in sliderN, which the toolkit reads through slider(idx).
@@ -46,7 +47,7 @@
46
47
  // @serialize file_var(0, ui_adv_open); // added for you when the plugin has none
47
48
 
48
49
  ui_ver = 1.3;
49
- ui_hm = 0; ui_ho = 0; // the header knobs' sliders (ui_header), 0 = none
50
+ ui_hm = 0; ui_ho = 0; // the header bars' sliders (ui_header), 0 = none
50
51
 
51
52
  // Design tokens: the bridge status page's palette (apps/bridge-ui/src/styles.css). The accent is
52
53
  // the plugin's own: write_jsfx emits ui_theme($xRRGGBB) after this block (from the plugin's name,
@@ -75,7 +76,7 @@ ui_pver = 0; ui_nctl = 0; ui_akind = 0; ui_example = 0;
75
76
  ui_min = 0; ui_max = 65; ui_def = 130; ui_stp = 195;
76
77
  ui_mtr = 400; // meter state: 2 slots per meter (level in dB, last time)
77
78
  ui_gn = 96; // frequency graph trace points (log-spaced); at most 128
78
- ui_fg = 1024; ui_ge = 1152; ui_grm = 1168; ui_kb = 1200; ui_fi = 1328; ui_gt = ui_fg; // graph widgets' memory, see the map above
79
+ ui_fg = 1024; ui_ge = 1152; ui_grm = 1168; ui_kb = 1200; ui_fi = 1328; ui_kq = 1456; ui_gt = ui_fg; // graph widgets' memory, see the map above
79
80
  ui_mem = 2048; // first free memory index for the plugin's own buffers
80
81
  // REAPER re-runs @init when playback starts (and on sample-rate changes): the UI state below
81
82
  // is set once, so pressing Play never closes the drawer or drops a drag. Plugin code must not
@@ -304,8 +305,9 @@ function ui_namedraw() local(x, y, i, c, n) (
304
305
  gfx_w >= 150 * ui_s ? (
305
306
  gfx_setfont(5);
306
307
  ui_caps(#ui_name);
307
- x = ui_pad; y = 4 * ui_s;
308
- ui_c(ui_cAccent, 0.9); gfx_circle(x + 1.5 * ui_s, y + 4.5 * ui_s, 1.5 * ui_s, 1, 1);
308
+ gfx_measurestr("A", ui_tw, ui_th);
309
+ x = ui_pad; y = 15 * ui_s - ui_th / 2; // centred on the header band, level with the Mix / Output bars
310
+ ui_c(ui_cAccent, 0.9); gfx_circle(x + 1.5 * ui_s, 15 * ui_s, 1.5 * ui_s, 1, 1);
309
311
  x += 8 * ui_s;
310
312
  ui_c(ui_cMuted, 0.85);
311
313
  i = 0; n = strlen(#ui_txt);
@@ -384,14 +386,18 @@ function ui_arow(x, y, w, label, val) (
384
386
  ui_c(ui_cText, 1); gfx_x = x + 70 * ui_s; gfx_y = y; gfx_drawstr(val);
385
387
  );
386
388
 
387
- // The About dialog: what reaper-mcp is, where to find it, and this plugin's facts. Closes on a
388
- // click outside it or on its x. In a short window the description lines go first.
389
- function ui_aboutdraw() local(w, h, x, y, lh, nd, rows, bx, cy, hitx) (
389
+ // The About dialog: what reaper-mcp is, where to find it, this plugin's facts and how the controls are
390
+ // used (the gestures every knob, bar and handle shares). Closes on a click outside it or on its x. In a
391
+ // short window the description lines go first, then the plugin's facts; the gestures stay while they fit.
392
+ function ui_aboutdraw() local(w, h, x, y, lh, nd, rows, bx, cy, hitx, kb, av) (
390
393
  lh = 13 * ui_s;
391
- nd = max(0, min(3, floor((gfx_h - 16 * ui_s - 186 * ui_s) / lh)));
392
- rows = nd > 0 ? 6 : max(2, min(6, floor((gfx_h - 16 * ui_s - 108 * ui_s) / lh)));
394
+ av = gfx_h - 16 * ui_s;
395
+ kb = av >= 225 * ui_s + 2 * lh; // the gesture block: a heading and five lines
396
+ av -= kb * 91 * ui_s;
397
+ nd = av - 186 * ui_s >= 3 * lh ? 3 : 0; // the description is all three lines or none, never cut mid-sentence
398
+ rows = nd > 0 ? 6 : max(2, min(6, floor((av - 108 * ui_s) / lh)));
393
399
  w = min(gfx_w - 16 * ui_s, 300 * ui_s);
394
- h = (12 + 22 + 6 + 4 + 28 + 10 + 16 + 10) * ui_s + nd * lh + rows * lh;
400
+ h = (12 + 22 + 6 + 4 + 28 + 10 + 16 + 10) * ui_s + nd * lh + rows * lh + kb * 91 * ui_s;
395
401
  x = (gfx_w - w) / 2; y = max(8 * ui_s, (gfx_h - h) / 2);
396
402
  bx = x + w - 26 * ui_s;
397
403
  hitx = mouse_x >= bx && mouse_x < bx + 20 * ui_s && mouse_y >= y + 8 * ui_s && mouse_y < y + 28 * ui_s;
@@ -432,6 +438,16 @@ function ui_aboutdraw() local(w, h, x, y, lh, nd, rows, bx, cy, hitx) (
432
438
  );
433
439
  rows > 4 ? ( sprintf(#ui_txt, "%d", ui_nctl); ui_arow(x, y, w, "Controls", #ui_txt); y += lh; );
434
440
  rows > 5 ? ( ui_arow(x, y, w, "Written", strlen(#ui_date) ? #ui_date : "-"); y += lh; );
441
+ kb ? (
442
+ y += 10 * ui_s;
443
+ ui_c(ui_cLine, 1); gfx_rect(x, y - 6 * ui_s, w - 28 * ui_s, max(1, ui_s));
444
+ gfx_setfont(2); ui_c(ui_cMuted, 1); gfx_x = x; gfx_y = y; gfx_drawstr("CONTROLS"); y += 16 * ui_s;
445
+ ui_arow(x, y, w, "Drag", "change the value"); y += lh;
446
+ ui_arow(x, y, w, "Shift-drag", "fine adjust (10x finer)"); y += lh;
447
+ ui_arow(x, y, w, "Wheel", "step the value"); y += lh;
448
+ ui_arow(x, y, w, "Dbl-click", "type an exact value"); y += lh;
449
+ ui_arow(x, y, w, "Cmd-click", "reset to default (Ctrl, Alt too)"); y += lh;
450
+ );
435
451
  gfx_setfont(1);
436
452
  );
437
453
  );
@@ -511,32 +527,60 @@ function ui_ctl(idx, fmt, label, x, y) local(lo, hi, st, t, fine) (
511
527
  );
512
528
 
513
529
  // Mix and Output in the top right of every plugin that has them: call ui_header(mix_idx, out_idx) in @gfx
514
- // before ui_begin (0 = this plugin has no such slider). Two small knobs with the usual gestures; the
530
+ // before ui_begin (0 = this plugin has no such slider). Two slim horizontal bars with the usual gestures; the
515
531
  // label shows the value while you hover or drag. Do not draw those two sliders as widgets as well.
516
532
  function ui_header(m, o) ( ui_hm = max(0, floor(m)); ui_ho = max(0, floor(o)); );
517
533
 
518
- // One small header knob whose right edge is xr; returns the x of the next one to its left.
519
- function ui_hknob(idx, label, fmt, xr) local(r, cx, cy, lo, hi, t, t0, a0, a1, av, aa, th, hot, tw0) (
520
- r = 8 * ui_s; cx = xr - r - 2 * ui_s; cy = 15 * ui_s;
521
- ui_hit = !(ui_core && ui_blocked) && !ui_modal && mouse_x >= xr - 62 * ui_s && mouse_x < xr && mouse_y >= 4 * ui_s && mouse_y < 26 * ui_s;
522
- ui_ctl(idx, fmt, label, cx, cy + 12 * ui_s);
523
- lo = ui_min[idx]; hi = ui_max[idx];
534
+ // A pill exactly h pixels tall: the end caps are circles of diameter h, so they never stick out past the bar.
535
+ function ui_pill(x, y, w, h) local(r) (
536
+ r = h / 2;
537
+ w <= h ? gfx_rect(x, y, w, h) : (
538
+ gfx_rect(x + r, y, w - h, h);
539
+ gfx_circle(x + r - 0.5, y + r - 0.5, r - 0.5, 1, 1);
540
+ gfx_circle(x + w - r - 0.5, y + r - 0.5, r - 0.5, 1, 1);
541
+ );
542
+ );
543
+
544
+ // One slim horizontal bar (like the level bar in Vital's header) whose right edge is xr; returns the x of the
545
+ // next one to its left. Drag left or right (Shift = fine), wheel, double-click to type, modifier-click resets.
546
+ // The header band is centred on y = 15 px, the same line the plugin name sits on.
547
+ function ui_hbar(idx, label, fmt, xr) local(bw, bh, bx, cy, by, lo, hi, st, t, t0, hot, tt, x0, x1) (
548
+ bw = 58 * ui_s; bh = 6 * ui_s; bx = xr - bw; cy = 15 * ui_s;
549
+ by = cy - 0.5 * ui_s; // the caps' ink sits half a pixel above the line box's middle: the bar follows the ink
550
+ lo = ui_min[idx]; hi = ui_max[idx]; st = ui_stp[idx];
551
+ ui_hit = !(ui_core && ui_blocked) && !ui_modal && mouse_x >= xr - 112 * ui_s && mouse_x < xr && mouse_y >= cy - 10 * ui_s && mouse_y < cy + 10 * ui_s;
552
+ ui_hit && ui_press ? (
553
+ tt = time_precise();
554
+ (mouse_cap & 52) ? ui_reset(idx) :
555
+ (ui_lci == idx && tt - ui_lct < 0.45) ? ui_edopen(idx, fmt, label, bx, cy + 12 * ui_s) :
556
+ ( ui_active = idx; ui_lx = mouse_x; ui_acc = slider(idx); ui_lci = idx; ui_lct = tt; );
557
+ );
558
+ ui_active == idx && ui_down ? (
559
+ ui_acc = min(hi, max(lo, ui_acc + (mouse_x - ui_lx) / (bw * ((mouse_cap & 8) ? 10 : 1)) * (hi - lo)));
560
+ ui_lx = mouse_x;
561
+ ui_set(idx, ui_q(idx, ui_acc));
562
+ );
563
+ ui_hit && mouse_wheel != 0 ? (
564
+ ui_set(idx, ui_q(idx, slider(idx) + sign(mouse_wheel) * (st > 0 ? st : (hi - lo) / ((mouse_cap & 8) ? 200 : 40))));
565
+ );
566
+ ui_active == idx && ui_rel ? ( slider_automate(2 ^ (idx - 1), 1); ui_active = 0; );
524
567
  t = min(1, max(0, (slider(idx) - lo) / (hi - lo)));
525
568
  t0 = (lo < 0 && hi > 0) ? -lo / (hi - lo) : 0;
526
569
  hot = ui_active == idx || ui_hit;
527
- th = max(2 * ui_s, r * 0.22);
528
- a0 = -2.35; a1 = 2.35; av = a0 + (a1 - a0) * t; aa = a0 + (a1 - a0) * t0;
529
- ui_c(hot ? ui_cTrackHot : ui_cTrack, 1); ui_ring(cx, cy, r - th, r, a0, a1);
530
- abs(t - t0) > 0.002 ? ( ui_c(ui_active == idx ? ui_cAccentAct : (hot ? ui_cAccentHi : ui_cAccent), 1); ui_ring(cx, cy, r - th, r, min(aa, av), max(aa, av)); );
531
- ui_cm(ui_cPanel2, ui_cLine, hot ? 0.9 : 0.4); gfx_circle(cx, cy, r - th - ui_s, 1, 1);
532
- ui_c(hot ? ui_cAccent : ui_cText, 1); gfx_circle(cx + sin(av) * (r - th - 3 * ui_s), cy - cos(av) * (r - th - 3 * ui_s), max(1, ui_s), 1, 1);
570
+ ui_c(hot ? ui_cTrackHot : ui_cTrack, 1); ui_pill(bx, by - bh / 2, bw, bh);
571
+ abs(t - t0) > 0.002 ? (
572
+ x0 = bx + bw * min(t, t0); x1 = bx + bw * max(t, t0);
573
+ ui_c(ui_active == idx ? ui_cAccentAct : (hot ? ui_cAccentHi : ui_cAccent), 1);
574
+ ui_pill(x0, by - bh / 2, max(1, x1 - x0), bh);
575
+ );
576
+ ui_c(hot ? ui_cText : ui_cMuted, 1); gfx_rect(bx + bw * t - ui_s / 2, by - bh, max(1, ui_s), bh * 2);
533
577
  gfx_setfont(2);
534
578
  hot ? ui_fmtv(fmt, slider(idx)) : ui_caps(label);
535
579
  gfx_measurestr(#ui_txt, ui_tw, ui_th);
536
580
  ui_c(ui_active == idx ? ui_cAccent : (hot ? ui_cText : ui_cMuted), 1);
537
- gfx_x = cx - r - 5 * ui_s - ui_tw; gfx_y = cy - ui_th / 2; gfx_drawstr(#ui_txt);
581
+ gfx_x = bx - 6 * ui_s - ui_tw; gfx_y = cy - ui_th / 2; gfx_drawstr(#ui_txt);
538
582
  gfx_setfont(1);
539
- xr - 66 * ui_s;
583
+ xr - 118 * ui_s;
540
584
  );
541
585
 
542
586
  // Returns 1 when the frame needs drawing. Nothing changed = nothing drawn, the old frame stays.
@@ -574,15 +618,15 @@ function ui_begin(core_rows, adv_rows) local(h, i, now, e, top) (
574
618
  gfx_setfont(4, "Arial", 15 * ui_s, 'b');
575
619
  gfx_setfont(5, "Arial", 8.5 * ui_s, 'b');
576
620
  gfx_setfont(1);
577
- ui_ytop = ui_pad + ((ui_hm || ui_ho) ? 20 : 8) * ui_s; // below the name (and the header knobs)
578
- ui_nlim = gfx_w - ui_pad - ((ui_hm > 0) + (ui_ho > 0)) * 66 * ui_s;
621
+ ui_ytop = 25 * ui_s; // name and bars are centred on y = 15; the first row's own padding makes the gap below match the 11 px above
622
+ ui_nlim = gfx_w - ui_pad - ((ui_hm > 0) + (ui_ho > 0)) * 118 * ui_s;
579
623
  ui_namedraw();
580
624
  ui_core = 1;
581
625
  ui_blocked = adv_rows > 0 && (ui_adv_open || ui_p > 0);
582
- (ui_hm || ui_ho) && gfx_w >= 240 * ui_s ? (
626
+ (ui_hm || ui_ho) && gfx_w >= 280 * ui_s ? (
583
627
  i = gfx_w - ui_pad;
584
- ui_ho ? i = ui_hknob(ui_ho, "Output", 1, i);
585
- ui_hm ? i = ui_hknob(ui_hm, "Mix", 2, i);
628
+ ui_ho ? i = ui_hbar(ui_ho, "Output", 1, i);
629
+ ui_hm ? i = ui_hbar(ui_hm, "Mix", 2, i);
586
630
  );
587
631
  // core: the window minus the drawer's closed bar (or the footer line when there is no drawer)
588
632
  ui_rowh = (gfx_h - ui_ytop - (adv_rows > 0 ? ui_bar + 4 * ui_s : ui_pad + (ui_credit ? 6 * ui_s : 0))) / max(1, core_rows);
@@ -783,6 +827,24 @@ function ui_kkey(note, vel) local(n, q0, q1) (
783
827
  ui_kb[n] = q1 ? min(127, max(1, vel)) : 0;
784
828
  );
785
829
 
830
+ // The keys the user plays with the mouse reach @block through a small queue (ui_kq: 16 slots of note and
831
+ // velocity, then a head and a tail). ui_kput is called by the keyboard widget; the plugin calls ui_kpoll() in
832
+ // @block until it returns 0: each 1 means ui_kn is a note and ui_kv its velocity (0 = note off).
833
+ // A note-on is queued only while two slots are free, so every queued note-on keeps room for its note-off
834
+ // (a full queue drops the newest event; a lost note-off would leave the note stuck when @block resumes).
835
+ function ui_kput(note, vel) local(t, f) (
836
+ t = (ui_kq[33] + 1) % 16;
837
+ f = (ui_kq[32] - ui_kq[33] + 15) % 16; // free slots
838
+ f >= (vel > 0 ? 2 : 1) ? ( ui_kq[ui_kq[33] * 2] = note; ui_kq[ui_kq[33] * 2 + 1] = vel; ui_kq[33] = t; );
839
+ );
840
+ function ui_kpoll() (
841
+ ui_kq[32] != ui_kq[33] ? (
842
+ ui_kn = ui_kq[ui_kq[32] * 2]; ui_kv = ui_kq[ui_kq[32] * 2 + 1];
843
+ ui_kq[32] = (ui_kq[32] + 1) % 16;
844
+ 1;
845
+ ) : 0;
846
+ );
847
+
786
848
  // ---- frequency graph ----------------------------------------------------------------------------
787
849
 
788
850
  // x of a frequency and the frequency of an x on the current graph (log axis, 20 Hz to 20 kHz).
@@ -984,6 +1046,58 @@ function ui_fthresh(thr_first, ratio_first, gain_first, n) local(k, a, b, x, y,
984
1046
  );
985
1047
  );
986
1048
 
1049
+ // ---- per-band levels --------------------------------------------------------------------------------
1050
+
1051
+ // A level line across each band of the frequency graph, one slider per band (first_idx .. first_idx + n - 1, any
1052
+ // range, drawn across the graph's height), for a plugin whose bands each have one amount (an EQ's gain, a split's
1053
+ // level). Hover a band and drag up or down to change its level, Shift-drag for fine steps, wheel for small steps,
1054
+ // a click selects the band (ui_fsel, which ui_bandknob follows), double-click types a value, Cmd/Ctrl/Alt-click
1055
+ // resets it. fmt is the knob formats (1 = dB). n is the number of bands (the handles + 1). Call it after the handles.
1056
+ function ui_fband(first_idx, n, fmt) local(k, a, b, y, idx, lo, hi, hot, drag, near, i, sel, t, mn, mx) (
1057
+ n = max(1, min(8, floor(n)));
1058
+ k = 0;
1059
+ loop(n,
1060
+ idx = first_idx + k; mn = ui_min[idx]; mx = ui_max[idx];
1061
+ lo = k == 0 ? 20 : slider(ui_ge[k - 1]); hi = k == n - 1 ? 20000 : slider(ui_ge[k]);
1062
+ a = ui_fxof(lo); b = ui_fxof(hi);
1063
+ y = ui_gy + ui_gh * (1 - (slider(idx) - mn) / (mx - mn));
1064
+ near = 0; i = 0;
1065
+ loop(n - 1, abs(mouse_x - ui_fxof(slider(ui_ge[i]))) < 9 * ui_s ? near = 1; i += 1;);
1066
+ hot = !near && !(ui_core && ui_blocked) && !ui_modal && ui_active == 0 && mouse_x >= a && mouse_x < b
1067
+ && mouse_y >= ui_gy && mouse_y < ui_gy + ui_gh;
1068
+ hot && ui_press ? (
1069
+ ui_fsel = k; t = time_precise();
1070
+ (mouse_cap & 52) ? ui_reset(idx) :
1071
+ (ui_lci == idx && t - ui_lct < 0.45) ? ui_edopen(idx, fmt, "Level", (a + b) / 2, y) :
1072
+ ( ui_active = idx; ui_ftd = 1; ui_ly = mouse_y; ui_acc = slider(idx); ui_lci = idx; ui_lct = t; );
1073
+ ui_press = 0;
1074
+ );
1075
+ ui_ftd && ui_active == idx && ui_down ? ( // only a drag this widget started
1076
+ ui_acc = min(mx, max(mn, ui_acc - (mouse_y - ui_ly) * (mx - mn) / ui_gh * ((mouse_cap & 8) ? 0.2 : 1)));
1077
+ ui_ly = mouse_y;
1078
+ ui_set(idx, ui_q(idx, ui_acc));
1079
+ );
1080
+ hot && mouse_wheel != 0 ? ui_set(idx, ui_q(idx, slider(idx) + sign(mouse_wheel) * (ui_stp[idx] > 0 ? ui_stp[idx] : (mx - mn) / 48))); // a stepped slider moves one step, or ui_q would round the nudge away
1081
+ ui_active == idx && ui_rel ? ( slider_automate(2 ^ (idx - 1), 1); ui_active = 0; ui_ftd = 0; );
1082
+ drag = ui_active == idx;
1083
+ (hot || drag) ? ui_gany = 2;
1084
+ sel = k == ui_fsel;
1085
+ y = ui_gy + ui_gh * (1 - (slider(idx) - mn) / (mx - mn));
1086
+ (hot || drag) ? ( ui_c(ui_cAccent, 0.07); gfx_rect(a, ui_gy, max(1, b - a), ui_gh); );
1087
+ ui_c(drag ? ui_cAccentAct : (sel || hot ? ui_cAccentHi : ui_cAccent), drag ? 1 : (sel ? 0.95 : (hot ? 0.8 : 0.4)));
1088
+ gfx_rect(a + 2 * ui_s, y, max(1, b - a - 4 * ui_s), max(1, sel ? 2 * ui_s : ui_s));
1089
+ (sel || hot || drag) && b - a > 50 * ui_s ? (
1090
+ gfx_setfont(2);
1091
+ fmt == 1 ? sprintf(#ui_txt, "%+.1f dB", slider(idx)) : ui_fmtv(fmt, slider(idx));
1092
+ gfx_measurestr(#ui_txt, ui_tw, ui_th);
1093
+ ui_c(drag || sel ? ui_cAccent : ui_cText, 1);
1094
+ gfx_x = a + 6 * ui_s; gfx_y = max(ui_gy + 2 * ui_s, y - ui_th - 3 * ui_s); gfx_drawstr(#ui_txt);
1095
+ gfx_setfont(1);
1096
+ );
1097
+ k += 1;
1098
+ );
1099
+ );
1100
+
987
1101
  // A knob for the selected band's slider: slider first_idx + ui_fsel of n, its label prefixed with the
988
1102
  // band's name (Low / Mid / High for 3 bands, Low / High for 2, else Band N).
989
1103
  function ui_bandknob(first_idx, n, label, fmt) local(k) (
@@ -1076,23 +1190,27 @@ function ui_transfer(thr_idx, ratio_idx, knee_db) local(k, t, r, bs, bx, by, i,
1076
1190
  // ---- MIDI keyboard ------------------------------------------------------------------------------
1077
1191
 
1078
1192
  // Piano keys lo..hi (MIDI notes; start and end on white keys: C, D, E, F, G, A, B), the notes fed with
1079
- // ui_kkey lit in the accent. Display only: a JSFX cannot send MIDI from @gfx.
1080
- function ui_keyboard(lo, hi, label) local(nw, n, pc, wi, ww, kx, ky, kw, kh, bk, x, v, k) (
1193
+ // ui_kkey lit in the accent. Playable: a click or drag queues notes the plugin reads with ui_kpoll() in @block
1194
+ // (a JSFX cannot send MIDI from @gfx, so the plugin sounds them itself).
1195
+ function ui_keyboard(lo, hi, label) local(nw, n, pc, wi, ww, kx, ky, kw, kh, bk, x, v, k, hn, hw, vel) (
1081
1196
  ui_cell();
1082
1197
  nw = 0; n = lo;
1083
1198
  loop(hi - lo + 1, ((2 ^ (n % 12)) & 1354) ? 0 : nw += 1; n += 1;);
1084
1199
  kw = ui_rw - 8 * ui_s; kx = ui_rx + 4 * ui_s; ky = ui_ry + 16 * ui_s;
1085
- kh = min(ui_rh - 20 * ui_s, 90 * ui_s);
1200
+ kh = min(ui_rh - 20 * ui_s, 52 * ui_s);
1201
+ ky = ui_ry + ui_rh - kh - 4 * ui_s; // along the bottom of its cell
1086
1202
  nw > 0 && kh > 16 * ui_s ? (
1087
1203
  ww = kw / nw;
1088
1204
  gfx_setfont(2); ui_caps(label);
1089
- ui_c(ui_cMuted, 1); gfx_x = kx; gfx_y = ui_ry + 2 * ui_s; gfx_drawstr(#ui_txt);
1205
+ ui_c(ui_cMuted, 1); gfx_x = kx; gfx_y = ky - 14 * ui_s; gfx_drawstr(#ui_txt);
1090
1206
  gfx_setfont(1);
1207
+ hn = -1; hw = -1;
1091
1208
  // white keys
1092
1209
  wi = 0; n = lo;
1093
1210
  loop(hi - lo + 1,
1094
1211
  ((2 ^ (n % 12)) & 1354) ? 0 : (
1095
1212
  x = kx + wi * ww; v = ui_kb[n] > 0;
1213
+ mouse_x >= x && mouse_x < x + ww && mouse_y >= ky && mouse_y < ky + kh ? hw = n;
1096
1214
  v ? ui_c(ui_cAccent, 1) : ui_cm(ui_cPanel2, ui_cText, 0.82);
1097
1215
  ui_rrect(x + 0.5 * ui_s, ky, ww - ui_s, kh, 3 * ui_s);
1098
1216
  wi += 1;
@@ -1105,6 +1223,7 @@ function ui_keyboard(lo, hi, label) local(nw, n, pc, wi, ww, kx, ky, kw, kh, bk,
1105
1223
  ((2 ^ (n % 12)) & 1354) ? (
1106
1224
  wi > 0 ? (
1107
1225
  bk = ww * 0.6; x = kx + wi * ww - bk / 2; v = ui_kb[n] > 0;
1226
+ mouse_x >= x && mouse_x < x + bk && mouse_y >= ky && mouse_y < ky + kh * 0.62 ? hn = n;
1108
1227
  ui_c(ui_cLine, 1); ui_rrect(x - ui_s, ky, bk + 2 * ui_s, kh * 0.62 + ui_s, 3 * ui_s);
1109
1228
  v ? ui_cm(ui_cAccent, ui_cBg, 0.35) : ui_cm(ui_cBg, ui_cPanel2, 0.5);
1110
1229
  ui_rrect(x, ky, bk, kh * 0.62, 3 * ui_s);
@@ -1112,5 +1231,18 @@ function ui_keyboard(lo, hi, label) local(nw, n, pc, wi, ww, kx, ky, kw, kh, bk,
1112
1231
  ) : wi += 1;
1113
1232
  n += 1;
1114
1233
  );
1234
+ // play the keys: press = note on (higher up the key = softer), drag across keys = glissando, release = note off
1235
+ hn < 0 ? hn = hw;
1236
+ vel = floor(35 + 92 * min(1, max(0, (mouse_y - ky) / kh)));
1237
+ hn >= 0 && ui_active == 0 && ui_press && !(ui_core && ui_blocked) && !ui_modal ? (
1238
+ ui_active = 64; ui_kheld = hn + 1; ui_kput(hn, vel); ui_kkey(hn, vel); ui_press = 0;
1239
+ );
1240
+ ui_active == 64 && ui_down && hn >= 0 && hn + 1 != ui_kheld ? (
1241
+ ui_kput(ui_kheld - 1, 0); ui_kkey(ui_kheld - 1, 0);
1242
+ ui_kheld = hn + 1; ui_kput(hn, vel); ui_kkey(hn, vel);
1243
+ );
1244
+ ui_active == 64 && !ui_down ? (
1245
+ ui_kput(ui_kheld - 1, 0); ui_kkey(ui_kheld - 1, 0); ui_kheld = 0; ui_active = 0;
1246
+ );
1115
1247
  );
1116
1248
  );