@mthines/reaper-mcp 0.83.0-beta.118.1 → 0.83.0

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.
@@ -1,4 +1,4 @@
1
- // mcp_ui.jsfx-inc: the reaper-mcp @gfx toolkit, v1.3.0
1
+ // mcp_ui.jsfx-inc: the reaper-mcp @gfx toolkit, v1.4.0
2
2
  //
3
3
  // Canonical source. `write_jsfx` pastes the body below (everything after this header) into the
4
4
  // plugin's own @init section, so a generated plugin is ONE file with no dependency on this one,
@@ -24,7 +24,10 @@
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
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
+ // 1490..1505 ui_pd the pads: when a key-struck pad lets go (time_precise), 0 = held or off (ui_pads)
28
+ // 1520..1775 ui_sqsl the sequencer's selected notes (lane * 32 + note), 1 = selected (ui_seq)
29
+ // 1776..2031 ui_sqor where the selected notes started when a drag began (ui_seq)
30
+ // 1506..1519 and 2032..2047 spare for the toolkit
28
31
  // 2048.. ui_mem the plugin
29
32
  // Every global starts with ui_. Sliders must be UNNAMED (slider1:0.5<0,1,0.01>Label): named
30
33
  // sliders do not keep their value in sliderN, which the toolkit reads through slider(idx).
@@ -69,15 +72,25 @@ ui_grain = 0.3; // grain strength: the tile is bg-level noise of +/-0.06,
69
72
  ui_img_bg = 120; ui_img_tile = 121;
70
73
 
71
74
  // Filled in by write_jsfx's metadata block (shown in the About dialog): never the user's request.
72
- strcpy(#ui_name, "Plugin"); strcpy(#ui_date, ""); strcpy(#ui_tkv, "1.3.0");
75
+ strcpy(#ui_name, "Plugin"); strcpy(#ui_date, ""); strcpy(#ui_tkv, "1.4.0");
73
76
  ui_pver = 0; ui_nctl = 0; ui_akind = 0; ui_example = 0;
74
77
 
75
78
  // Per-slider metadata (index 1..64), filled by write_jsfx from the slider lines.
76
79
  ui_min = 0; ui_max = 65; ui_def = 130; ui_stp = 195;
77
80
  ui_mtr = 400; // meter state: 2 slots per meter (level in dB, last time)
78
81
  ui_gn = 96; // frequency graph trace points (log-spaced); at most 128
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
82
+ ui_fg = 1024; ui_ge = 1152; ui_grm = 1168; ui_kb = 1200; ui_fi = 1328; ui_kq = 1456; ui_pd = 1490; ui_gt = ui_fg; // graph widgets' memory, see the map above
80
83
  ui_mem = 2048; // first free memory index for the plugin's own buffers
84
+ // Drum pads (ui_pads): the bank's first note, size and shape, set by the widget; ui_keys reads them every frame.
85
+ ui_pn = 36; ui_pc = 0; ui_pcols = 4; ui_prows = 4;
86
+ // Computer keys for the pads, bottom row first (pad 1 is bottom-left, like an MPC); needs REAPER's
87
+ // "Send all keyboard input to plug-in" and the FX window focused. Shift = a hard hit.
88
+ strcpy(#ui_pkeys, "zxcvasdfqwer1234");
89
+ strcpy(#ui_pword, "PAD"); // what ui_padmap calls a cell: ui_seq makes it LANE
90
+ // Step sequencer (ui_seq): the plugin's buffer, lane count and loop length, set by the widget; ui_sqon = lanes drawn (0 = none)
91
+ ui_sqon = 0; ui_sqsl = 1520; ui_sqor = 1776;
92
+ ui_tipn = 0; ui_tipf = 0; ui_tipt = 0; ui_tipx = 0; ui_tipy = 0; // the knob tooltip: hovered slider, its frame flag, since when, where
93
+ ui_sqph = -1; // the playhead in loop ticks, -1 = stopped: the plugin sets it in @block
81
94
  // REAPER re-runs @init when playback starts (and on sample-rate changes): the UI state below
82
95
  // is set once, so pressing Play never closes the drawer or drops a drag. Plugin code must not
83
96
  // assign ui_adv_open either (only @serialize's file_var restores it).
@@ -90,6 +103,11 @@ ui_ready ? ( ui_hash = -1; ) : (
90
103
  ui_glv = -90; // live level for the transfer curve (-90 = none)
91
104
  ui_fsel = 0; // selected band of the frequency graph (the plugin reads it)
92
105
  ui_gi = 0; loop(128, ui_fg[ui_gi] = -120; ui_fi[ui_gi] = -120; ui_gi += 1;); ui_fcmp = 0; // an empty trace
106
+ ui_pheld = 0; // the pad held with the mouse, 1-based, 0 = none
107
+ ui_sqbl = 2; ui_sqbf = 0; // the sequencer's brush: length 0..3 (1/4 1/8 1/16 1/32) and feel 0..2 (straight, triplet, dotted)
108
+ ui_sqb = 0; ui_sqnl = 4; // the buffer and lane count survive the @init rerun on Play, like the pattern in them
109
+ ui_sqmode = 0; ui_sqcid = -1; ui_sqct = 0; ui_sqsure = 0;
110
+ ui_squh = 0; ui_squn = 0; ui_sqrh = 0; ui_sqrn = 0; ui_sqpd = 0; // undo history: next slot and depth of the undo and redo rings
93
111
  ui_ready = 1;
94
112
  );
95
113
 
@@ -286,14 +304,145 @@ function ui_edkey(c) (
286
304
 
287
305
  // Keys are read only while a layer is open. Esc (only delivered with "Send all keyboard input
288
306
  // to plug-in") closes the top layer: value box, then About, then the drawer.
289
- function ui_keys() local(c) (
290
- (ui_ed || ui_about || ui_adv_open) ? (
307
+ // A MIDI note on (vel 1..127) or off (vel 0), from @block's midirecv loop.
308
+ function ui_kkey(note, vel) local(n, q0, q1) (
309
+ n = min(127, max(0, floor(note)));
310
+ q0 = ui_kb[n] > 0; q1 = vel > 0;
311
+ ui_fh3 += (q1 - q0) * (n + 1);
312
+ ui_kb[n] = q1 ? min(127, max(1, vel)) : 0;
313
+ );
314
+
315
+ // The keys the user plays with the mouse reach @block through a small queue (ui_kq: 16 slots of note and
316
+ // velocity, then a head and a tail). ui_kput is called by the keyboard widget; the plugin calls ui_kpoll() in
317
+ // @block until it returns 0: each 1 means ui_kn is a note and ui_kv its velocity (0 = note off).
318
+ // A note-on is queued only while two slots are free, so every queued note-on keeps room for its note-off
319
+ // (a full queue drops the newest event; a lost note-off would leave the note stuck when @block resumes).
320
+ function ui_kput(note, vel) local(t, f) (
321
+ t = (ui_kq[33] + 1) % 16;
322
+ f = (ui_kq[32] - ui_kq[33] + 15) % 16; // free slots
323
+ f >= (vel > 0 ? 2 : 1) ? ( ui_kq[ui_kq[33] * 2] = note; ui_kq[ui_kq[33] * 2 + 1] = vel; ui_kq[33] = t; );
324
+ );
325
+ function ui_kpoll() (
326
+ ui_kq[32] != ui_kq[33] ? (
327
+ ui_kn = ui_kq[ui_kq[32] * 2]; ui_kv = ui_kq[ui_kq[32] * 2 + 1];
328
+ ui_kq[32] = (ui_kq[32] + 1) % 16;
329
+ 1;
330
+ ) : 0;
331
+ );
332
+
333
+ // A pad on (vel 1..127) or off for pad i (0-based, bottom-left first): queued for the plugin's ui_kpoll() like a
334
+ // played key and lit like a note from MIDI. The note is ui_pn + i.
335
+ function ui_padon(i, vel) local(n) (
336
+ n = ui_pn + i; ui_kput(n, vel); ui_kkey(n, vel); ui_pd[i] = 0;
337
+ );
338
+ function ui_padoff(i) local(n) (
339
+ n = ui_pn + i; ui_kput(n, 0); ui_kkey(n, 0); ui_pd[i] = 0;
340
+ );
341
+ // The pad a typed character strikes, -1 for none. The keys are a 4 x 4 block (zxcv / asdf / qwer / 1234, bottom
342
+ // row first); a smaller grid uses its bottom-left corner of it.
343
+ function ui_padkey(c) local(k, q, col, row) (
344
+ k = -1; q = 0;
345
+ loop(16, str_getchar(#ui_pkeys, q) == c ? k = q; q += 1;);
346
+ col = k % 4; row = floor(k / 4);
347
+ (k >= 0 && col < ui_pcols && row < ui_prows) ? row * ui_pcols + col : -1;
348
+ );
349
+
350
+ // ---- the sequencer's selection (lives next to the keys: ui_sqkey uses it) ----------------------
351
+ // Flags per note (lane * 32 + index) in ui_sqsl; a note's index shifts when another is deleted (the last takes its
352
+ // place), so ui_sqdel moves the flag with it.
353
+ function ui_sqdesel() local(i) ( i = 0; loop(256, ui_sqsl[i] = 0; i += 1;); );
354
+ function ui_sqselall() local(l, i, p) (
355
+ ui_sqdesel(); l = 0;
356
+ loop(ui_sqnl, p = ui_sqb + 8 + l * 98; i = 0; loop(p[0], ui_sqsl[l * 32 + i] = 1; i += 1;); l += 1;);
357
+ );
358
+ // Undo history: 100 snapshots of the pattern (everything but the loop length, which a slider owns), kept in the
359
+ // plugin's memory after its own buffers: buf + 1200 and 158400 numbers on (an undo ring, then a redo ring, 792 a slot).
360
+ // ui_sqpush() before every change; ui_sqpush1() once per gesture (ui_seq clears the flag when the mouse lets go).
361
+ function ui_squbase(r, slot) ( ui_sqb + 1200 + (r * 100 + slot) * 792; );
362
+ function ui_sqpush() (
363
+ memcpy(ui_squbase(0, ui_squh) + 1, ui_sqb + 1, 791);
364
+ ui_squh = (ui_squh + 1) % 100; ui_squn = min(100, ui_squn + 1); ui_sqrn = 0;
365
+ );
366
+ function ui_sqpush1() ( ui_sqpd ? 0 : ( ui_sqpush(); ui_sqpd = 1; ); );
367
+ function ui_squndo() (
368
+ ui_squn > 0 ? (
369
+ memcpy(ui_squbase(1, ui_sqrh) + 1, ui_sqb + 1, 791);
370
+ ui_sqrh = (ui_sqrh + 1) % 100; ui_sqrn = min(100, ui_sqrn + 1);
371
+ ui_squh = (ui_squh + 99) % 100; ui_squn -= 1;
372
+ memcpy(ui_sqb + 1, ui_squbase(0, ui_squh) + 1, 791);
373
+ ui_sqdesel();
374
+ );
375
+ );
376
+ function ui_sqredo() (
377
+ ui_sqrn > 0 ? (
378
+ memcpy(ui_squbase(0, ui_squh) + 1, ui_sqb + 1, 791);
379
+ ui_squh = (ui_squh + 1) % 100; ui_squn = min(100, ui_squn + 1);
380
+ ui_sqrh = (ui_sqrh + 99) % 100; ui_sqrn -= 1;
381
+ memcpy(ui_sqb + 1, ui_squbase(1, ui_sqrh) + 1, 791);
382
+ ui_sqdesel();
383
+ );
384
+ );
385
+ // Removes every selected note (from the end, so a note moved into a hole has already been looked at).
386
+ function ui_sqdelsel() local(l, i, p, k, n) (
387
+ n = 0; l = 0;
388
+ loop(ui_sqnl, p = ui_sqb + 8 + l * 98; i = 0; loop(p[0], n += ui_sqsl[l * 32 + i] ? 1 : 0; i += 1;); l += 1;);
389
+ n > 0 ? ui_sqpush1();
390
+ l = 0;
391
+ loop(ui_sqnl,
392
+ p = ui_sqb + 8 + l * 98; i = p[0] - 1;
393
+ loop(p[0],
394
+ i >= 0 && ui_sqsl[l * 32 + i] ? (
395
+ k = p[0] - 1;
396
+ p[2 + i * 3] = p[2 + k * 3]; p[3 + i * 3] = p[3 + k * 3]; p[4 + i * 3] = p[4 + k * 3];
397
+ ui_sqsl[l * 32 + i] = ui_sqsl[l * 32 + k]; ui_sqsl[l * 32 + k] = 0;
398
+ p[0] = k;
399
+ );
400
+ i -= 1;
401
+ );
402
+ l += 1;
403
+ );
404
+ );
405
+
406
+ // The sequencer's typed keys (REAPER's "Send all keyboard input to plug-in"): 1-4 set the brush length, q / w / e its
407
+ // feel, Delete or Backspace removes the selected notes, Cmd/Ctrl+A selects all.
408
+ function ui_sqkey(c) (
409
+ (c == 6579564 || c == 8) ? ( ui_sqdelsel(); ui_edv += 1; ) :
410
+ c == 1 ? ( ui_sqselall(); ui_edv += 1; ) :
411
+ c == 26 ? ( (mouse_cap & 8) ? ui_sqredo() : ui_squndo(); ui_edv += 1; ) :
412
+ c == 25 ? ( ui_sqredo(); ui_edv += 1; ) :
413
+ (c == 122 || c == 90) && (mouse_cap & 36) ? ( (mouse_cap & 8) ? ui_sqredo() : ui_squndo(); ui_edv += 1; ) :
414
+ c >= 65 && c <= 90 ? c += 32;
415
+ c >= 49 && c <= 52 ? ( ui_sqbl = c - 49; ui_edv += 1; ) :
416
+ c == 113 ? ( ui_sqbf = 0; ui_edv += 1; ) :
417
+ c == 119 ? ( ui_sqbf = 1; ui_edv += 1; ) :
418
+ c == 101 ? ( ui_sqbf = 2; ui_edv += 1; );
419
+ );
420
+
421
+ function ui_keys() local(c, i, now, vel) (
422
+ // a pad struck from the keyboard lets go 0.12 s later (a drum is a one-shot)
423
+ ui_pc > 0 ? (
424
+ now = time_precise();
425
+ i = 0; loop(ui_pc, ui_pd[i] > 0 && now >= ui_pd[i] ? ui_padoff(i); i += 1;);
426
+ );
427
+ (ui_ed || ui_about) ? (
291
428
  c = gfx_getchar();
292
429
  while (c > 0) (
293
- c == 27 ? ( ui_ed ? ui_ed = 0 : ui_about ? ui_about = 0 : ui_adv_open = 0; ) : ui_ed ? ui_edkey(c);
430
+ c == 27 ? ( ui_ed ? ui_ed = 0 : ui_about = 0; ) : ui_ed ? ui_edkey(c);
294
431
  ui_edv += 1;
295
432
  c = gfx_getchar();
296
433
  );
434
+ ) : (ui_adv_open || ui_pc > 0 || ui_sqon > 0) ? (
435
+ // the drawer being open does not stop the pad keys: you can hear a pad while you map it
436
+ c = gfx_getchar();
437
+ while (c > 0) (
438
+ c == 27 ? ( ui_adv_open = 0; ui_edv += 1; ) : ui_sqon > 0 ? ui_sqkey(c) : ui_pc > 0 ? (
439
+ vel = (c >= 65 && c <= 90) ? 127 : 100;
440
+ (c >= 65 && c <= 90) ? c += 32;
441
+ i = ui_padkey(c);
442
+ i >= 0 && ui_pheld != i + 1 ? ( ui_padon(i, vel); ui_pd[i] = now + 0.12; );
443
+ );
444
+ c = gfx_getchar();
445
+ );
297
446
  );
298
447
  );
299
448
 
@@ -452,10 +601,46 @@ function ui_aboutdraw() local(w, h, x, y, lh, nd, rows, bx, cy, hitx, kb, av) (
452
601
  );
453
602
  );
454
603
 
604
+ // A line of help for a knob, shown as a tooltip after the mouse rests on it for half a second (a few lines, ~44
605
+ // characters wide, so keep it to a sentence or two). Call once, in @init: ui_help(slider_idx, "text"). The text sits in
606
+ // string slot 900 + idx (numbered slots 0..1023 are the plugin's).
607
+ function ui_help(idx, text) ( strcpy(900 + idx, text); );
608
+ function ui_tipdraw() local(n, i, ls, ml, w, h, x, y, lines, at, brk) (
609
+ ui_tipn > 0 && ui_tipf == ui_tipn && time_precise() - ui_tipt > 0.5 && strlen(900 + ui_tipn) > 0 && !ui_modal && ui_active == 0 ? (
610
+ gfx_setfont(3);
611
+ n = strlen(900 + ui_tipn); at = 0; lines = 0; w = 0;
612
+ // break the text into lines of at most 44 characters, at a space where it can
613
+ while (at < n && lines < 4) (
614
+ ml = min(44, n - at); brk = ml;
615
+ at + ml < n ? ( i = ml; while (i > 20 && str_getchar(900 + ui_tipn, at + i) != 32) ( i -= 1; ); i > 20 ? brk = i; );
616
+ strcpy_substr(#ui_tmp, 900 + ui_tipn, at, brk);
617
+ gfx_measurestr(#ui_tmp, ui_tw, ui_th); w = max(w, ui_tw);
618
+ lines += 1; at += brk; str_getchar(900 + ui_tipn, at) == 32 ? at += 1;
619
+ );
620
+ h = lines * (ui_th + 2 * ui_s) + 10 * ui_s; w += 14 * ui_s;
621
+ x = max(4 * ui_s, min(gfx_w - w - 4 * ui_s, ui_tipx - w / 2)); y = max(4 * ui_s, ui_tipy - h - 6 * ui_s);
622
+ ui_c(ui_cLine, 1); ui_rrect(x - ui_s, y - ui_s, w + 2 * ui_s, h + 2 * ui_s, 6 * ui_s);
623
+ ui_c(ui_cPanel2, 1); ui_rrect(x, y, w, h, 6 * ui_s);
624
+ ui_c(ui_cText, 1);
625
+ at = 0; ls = 0;
626
+ while (at < n && ls < lines) (
627
+ ml = min(44, n - at); brk = ml;
628
+ at + ml < n ? ( i = ml; while (i > 20 && str_getchar(900 + ui_tipn, at + i) != 32) ( i -= 1; ); i > 20 ? brk = i; );
629
+ strcpy_substr(#ui_tmp, 900 + ui_tipn, at, brk);
630
+ gfx_x = x + 7 * ui_s; gfx_y = y + 5 * ui_s + ls * (ui_th + 2 * ui_s); gfx_drawstr(#ui_tmp);
631
+ ls += 1; at += brk; str_getchar(900 + ui_tipn, at) == 32 ? at += 1;
632
+ );
633
+ gfx_setfont(1);
634
+ );
635
+ ui_tipf == 0 ? ui_tipn = 0;
636
+ ui_tipf = 0;
637
+ );
638
+
455
639
  function ui_end() (
456
640
  ui_gany != ui_gcur ? ( gfx_setcursor(ui_gany == 2 ? 32645 : (ui_gany ? 32644 : 32512)); ui_gcur = ui_gany; ); // a band handle: resize cursor
457
641
  ui_gany = 0;
458
642
  ui_bar == 0 ? ui_footer(gfx_h - ui_pad - 6 * ui_s, ui_pad + 6 * ui_s);
643
+ ui_tipdraw();
459
644
  ui_ed ? ui_popover() : ui_about ? ui_aboutdraw();
460
645
  mouse_wheel = 0;
461
646
  );
@@ -605,7 +790,8 @@ function ui_begin(core_rows, adv_rows) local(h, i, now, e, top) (
605
790
 
606
791
  h = gfx_w * 7 + gfx_h * 13 + mouse_x * 3 + mouse_y * 5 + mouse_cap * 11 + ui_adv_open * 17
607
792
  + mouse_wheel * 23 + floor(now * 2) * 19 + ui_p * 29 + ui_ed * 31 + ui_edv * 37 + ui_about * 41
608
- + ui_fh * 43 + ui_fh2 * 47 + ui_fh3 * 53 + ui_fh4 * 59 + ui_fsel * 61 + ui_fcmp * 67;
793
+ + ui_fh * 43 + ui_fh2 * 47 + ui_fh3 * 53 + ui_fh4 * 59 + ui_fsel * 61 + ui_fcmp * 67
794
+ + (ui_tipn > 0 ? floor(now * 8) * 83 : 0) + floor(ui_sqph / 6) * 71 + ui_sqbl * 73 + ui_sqbf * 79;
609
795
  i = 1; loop(64, h += slider(i) * (i + 0.37); i += 1;);
610
796
  ui_dirty = ui_animated == 1 || h != ui_hash || (ui_p > 0 && ui_p < 1);
611
797
  ui_hash = h;
@@ -651,6 +837,10 @@ function ui_knob(idx, label, fmt) local(lo, hi, t, t0, r, th, cx, cy, a0, a1, av
651
837
  t = min(1, max(0, (slider(idx) - lo) / (hi - lo)));
652
838
  t0 = (lo < 0 && hi > 0) ? -lo / (hi - lo) : 0;
653
839
  hot = ui_active == idx || ui_hit;
840
+ ui_hit && ui_active == 0 && !ui_modal && strlen(900 + idx) > 0 ? (
841
+ ui_tipn != idx ? ( ui_tipn = idx; ui_tipt = time_precise(); );
842
+ ui_tipf = idx; ui_tipx = ui_rx + ui_rw / 2; ui_tipy = ui_by;
843
+ );
654
844
  r = ui_kr;
655
845
  cx = ui_rx + ui_rw / 2; cy = ui_by + ui_bh / 2;
656
846
  th = max(3 * ui_s, r * 0.14);
@@ -819,32 +1009,6 @@ function ui_glevel(db) (
819
1009
  ui_fh4 = floor((ui_glv + 90) / 1);
820
1010
  );
821
1011
 
822
- // A MIDI note on (vel 1..127) or off (vel 0), from @block's midirecv loop.
823
- function ui_kkey(note, vel) local(n, q0, q1) (
824
- n = min(127, max(0, floor(note)));
825
- q0 = ui_kb[n] > 0; q1 = vel > 0;
826
- ui_fh3 += (q1 - q0) * (n + 1);
827
- ui_kb[n] = q1 ? min(127, max(1, vel)) : 0;
828
- );
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
-
848
1012
  // ---- frequency graph ----------------------------------------------------------------------------
849
1013
 
850
1014
  // x of a frequency and the frequency of an x on the current graph (log axis, 20 Hz to 20 kHz).
@@ -1246,3 +1410,644 @@ function ui_keyboard(lo, hi, label) local(nw, n, pc, wi, ww, kx, ky, kw, kh, bk,
1246
1410
  );
1247
1411
  );
1248
1412
  );
1413
+
1414
+ // ---- drum pads ----------------------------------------------------------------------------------
1415
+
1416
+ // A bank of drum pads: `cols` x `rows` (at most 16 pads), pad 1 bottom-left on MIDI note `first` (36 = GM kick),
1417
+ // counting right then up. Playable: a press strikes the pad (lower on the pad = harder), a drag across pads moves
1418
+ // the hit, a release lets go; the typed keys strike them too. Pads light, brighter the harder, for the notes
1419
+ // fed with ui_kkey (MIDI in) and the ones the user strikes. Read what the user struck in @block with
1420
+ // `while (ui_kpoll()) ( ... )`, as for ui_keyboard. Give the row some height (ui_tall(2)).
1421
+ function ui_pads(first, cols, rows, label) local(gx, gy, gw, gh, gap, pw, ph, i, col, row, x, y, v, hov, hot, vel) (
1422
+ ui_cell();
1423
+ ui_pcols = min(8, max(1, floor(cols))); ui_prows = min(8, max(1, floor(rows)));
1424
+ while (ui_pcols * ui_prows > 16) ( ui_prows -= 1; );
1425
+ ui_pn = min(127 - ui_pcols * ui_prows + 1, max(0, floor(first)));
1426
+ ui_pc = ui_pcols * ui_prows;
1427
+ gap = 6 * ui_s; gx = ui_rx + 4 * ui_s; gw = ui_rw - 8 * ui_s;
1428
+ gy = ui_ry + 16 * ui_s; gh = ui_rh - 20 * ui_s;
1429
+ pw = (gw - gap * (ui_pcols - 1)) / ui_pcols; ph = (gh - gap * (ui_prows - 1)) / ui_prows;
1430
+ pw > 10 * ui_s && ph > 10 * ui_s ? (
1431
+ gfx_setfont(2); ui_caps(label);
1432
+ ui_c(ui_cMuted, 1); gfx_x = gx; gfx_y = ui_ry + 2 * ui_s; gfx_drawstr(#ui_txt);
1433
+ hot = -1; i = 0;
1434
+ loop(ui_pc,
1435
+ col = i % ui_pcols; row = floor(i / ui_pcols);
1436
+ x = gx + col * (pw + gap); y = gy + gh - (row + 1) * ph - row * gap;
1437
+ hov = mouse_x >= x && mouse_x < x + pw && mouse_y >= y && mouse_y < y + ph;
1438
+ hov ? ( hot = i; vel = floor(35 + 92 * min(1, max(0, (mouse_y - y) / ph))); );
1439
+ v = ui_kb[ui_pn + i];
1440
+ ui_c(ui_cLine, 1); ui_rrect(x - ui_s, y - ui_s, pw + 2 * ui_s, ph + 2 * ui_s, 7 * ui_s);
1441
+ v > 0 ? ui_cm(ui_cPanel2, ui_cAccent, 0.35 + 0.65 * v / 127) : hov ? ui_cm(ui_cPanel2, ui_cText, 0.08) : ui_c(ui_cPanel2, 1);
1442
+ ui_rrect(x, y, pw, ph, 6 * ui_s);
1443
+ // the typed key in the corner (the 4 x 4 block), the note bottom-right
1444
+ gfx_setfont(5);
1445
+ v > 0 ? ui_cm(ui_cBg, ui_cPanel2, 0.2) : ui_c(ui_cMuted, 1);
1446
+ col < 4 && row < 4 ? (
1447
+ strcpy_substr(#ui_pt, #ui_pkeys, row * 4 + col, 1); ui_caps(#ui_pt);
1448
+ gfx_x = x + 6 * ui_s; gfx_y = y + 5 * ui_s; gfx_drawstr(#ui_txt);
1449
+ );
1450
+ sprintf(#ui_txt, "%d", ui_pn + i);
1451
+ gfx_measurestr(#ui_txt, ui_tw, ui_th);
1452
+ gfx_x = x + pw - ui_tw - 6 * ui_s; gfx_y = y + ph - ui_th - 5 * ui_s; gfx_drawstr(#ui_txt);
1453
+ i += 1;
1454
+ );
1455
+ gfx_setfont(1);
1456
+ // strike: press = hit (lower on the pad = harder), drag across pads moves the hit, release lets go
1457
+ hot >= 0 && ui_active == 0 && ui_press && !(ui_core && ui_blocked) && !ui_modal ? (
1458
+ ui_active = 65; ui_pheld = hot + 1; ui_padon(hot, vel); ui_press = 0;
1459
+ );
1460
+ ui_active == 65 && ui_down && hot >= 0 && hot + 1 != ui_pheld ? (
1461
+ ui_padoff(ui_pheld - 1); ui_pheld = hot + 1; ui_padon(hot, vel);
1462
+ );
1463
+ ui_active == 65 && !ui_down ? (
1464
+ ui_pheld > 0 ? ui_padoff(ui_pheld - 1); ui_pheld = 0; ui_active = 0;
1465
+ );
1466
+ );
1467
+ );
1468
+
1469
+ // ---- pad map ------------------------------------------------------------------------------------
1470
+
1471
+ // A note's name in #ui_txt, middle C = C4 (so MIDI 36 is C2, as REAPER shows it).
1472
+ function ui_notename(n) local(pc) (
1473
+ pc = floor(n) % 12;
1474
+ strcpy_substr(#ui_nn, "C C#D D#E F F#G G#A A#B ", pc * 2, ((2 ^ pc) & 1354) ? 2 : 1);
1475
+ sprintf(#ui_txt, "%s%d", #ui_nn, floor(n / 12) - 1);
1476
+ );
1477
+
1478
+ // Which MIDI note each pad sends, drawn in the same grid as ui_pads (`cols` x `rows`, pad 1 bottom-left) so a
1479
+ // cell sits where its pad is. One slider per pad, first_idx.. in pad order, each a note 0-127. Every cell shows
1480
+ // the note's name large and its number small. Drag a cell up or down (Shift = fine), scroll over it (Shift =
1481
+ // an octave), double-click to type a number, Cmd/Ctrl/Alt-click resets it. Put it in Advanced next to a
1482
+ // ui_pads core.
1483
+ function ui_padmap(first_idx, cols, rows, label) local(gx, gy, gw, gh, gap, pw, ph, i, col, row, x, y, idx, v, hov, now, on, hint) (
1484
+ ui_cell();
1485
+ cols = min(8, max(1, floor(cols))); rows = min(8, max(1, floor(rows)));
1486
+ while (cols * rows > 16) ( rows -= 1; );
1487
+ gap = 6 * ui_s; gx = ui_rx + 4 * ui_s; gw = ui_rw - 8 * ui_s;
1488
+ gy = ui_ry + 16 * ui_s; gh = ui_rh - 20 * ui_s;
1489
+ pw = (gw - gap * (cols - 1)) / cols; ph = (gh - gap * (rows - 1)) / rows;
1490
+ hint = 0;
1491
+ pw > 14 * ui_s && ph > 14 * ui_s ? (
1492
+ gfx_setfont(2); ui_caps(label);
1493
+ ui_c(ui_cMuted, 1); gfx_x = gx; gfx_y = ui_ry + 2 * ui_s; gfx_drawstr(#ui_txt);
1494
+ now = time_precise(); i = 0;
1495
+ loop(cols * rows,
1496
+ col = i % cols; row = floor(i / cols); idx = first_idx + i;
1497
+ x = gx + col * (pw + gap); y = gy + gh - (row + 1) * ph - row * gap;
1498
+ hov = mouse_x >= x && mouse_x < x + pw && mouse_y >= y && mouse_y < y + ph && !(ui_core && ui_blocked) && !ui_modal;
1499
+ hov && ui_press ? (
1500
+ (mouse_cap & 52) ? ui_reset(idx) :
1501
+ (ui_lci == idx && now - ui_lct < 0.45) ? ui_edopen(idx, 5, "Note", x, y) :
1502
+ ( ui_active = idx; ui_ly = mouse_y; ui_acc = slider(idx); ui_lci = idx; ui_lct = now; );
1503
+ );
1504
+ ui_active == idx && ui_down ? (
1505
+ ui_acc = min(127, max(0, ui_acc + (ui_ly - mouse_y) / (9 * ui_s * ((mouse_cap & 8) ? 10 : 1))));
1506
+ ui_ly = mouse_y;
1507
+ ui_set(idx, ui_q(idx, floor(ui_acc + 0.5)));
1508
+ );
1509
+ hov && mouse_wheel != 0 ? ui_set(idx, ui_q(idx, slider(idx) + sign(mouse_wheel) * ((mouse_cap & 8) ? 12 : 1)));
1510
+ ui_active == idx && ui_rel ? ( slider_automate(2 ^ (idx - 1), 1); ui_active = 0; );
1511
+ v = slider(idx); on = ui_active == idx;
1512
+ on || ui_kb[ui_pn + i] > 0 ? ui_c(ui_cAccent, 1) : ui_c(ui_cLine, 1); ui_rrect(x - ui_s, y - ui_s, pw + 2 * ui_s, ph + 2 * ui_s, 7 * ui_s);
1513
+ ui_kb[ui_pn + i] > 0 ? ui_cm(ui_cPanel2, ui_cAccent, 0.35 + 0.65 * ui_kb[ui_pn + i] / 127) : on ? ui_cm(ui_cPanel2, ui_cAccent, 0.2) : hov ? ui_cm(ui_cPanel2, ui_cText, 0.08) : ui_c(ui_cPanel2, 1);
1514
+ ui_rrect(x, y, pw, ph, 6 * ui_s);
1515
+ gfx_setfont(5); ui_c(ui_cMuted, 1);
1516
+ sprintf(#ui_txt, "%s %d", #ui_pword, i + 1); ui_caps(#ui_txt); gfx_x = x + 6 * ui_s; gfx_y = y + 5 * ui_s; gfx_drawstr(#ui_txt);
1517
+ sprintf(#ui_txt, "%d", v); gfx_measurestr(#ui_txt, ui_tw, ui_th);
1518
+ gfx_x = x + pw - ui_tw - 6 * ui_s; gfx_y = y + ph - ui_th - 5 * ui_s; gfx_drawstr(#ui_txt);
1519
+ gfx_setfont(4); ui_notename(v);
1520
+ hov || on ? ui_c(ui_cAccent, 1) : ui_c(ui_cText, 1);
1521
+ gfx_measurestr(#ui_txt, ui_tw, ui_th);
1522
+ gfx_x = x + (pw - ui_tw) / 2; gfx_y = y + (ph - ui_th) / 2; gfx_drawstr(#ui_txt);
1523
+ // hover or drag: arrows above and below the note say it can be dragged up and down
1524
+ hov || on ? (
1525
+ hint = 1;
1526
+ ui_c(ui_cAccent, on ? 1 : 0.85);
1527
+ ui_chev(x + pw / 2, y + (ph - ui_th) / 2 - 7 * ui_s, 1);
1528
+ ui_chev(x + pw / 2, y + (ph + ui_th) / 2 + 7 * ui_s, 0);
1529
+ );
1530
+ i += 1;
1531
+ );
1532
+ // the gestures, on the label line, while the mouse is over a cell
1533
+ hint ? (
1534
+ gfx_setfont(5); ui_c(ui_cMuted, 1);
1535
+ strcpy(#ui_txt, "DRAG OR SCROLL / DOUBLE-CLICK TO TYPE");
1536
+ gfx_measurestr(#ui_txt, ui_tw, ui_th);
1537
+ gfx_x = gx + gw - ui_tw; gfx_y = ui_ry + 3 * ui_s; gfx_drawstr(#ui_txt);
1538
+ );
1539
+ gfx_setfont(1);
1540
+ );
1541
+ );
1542
+
1543
+ // ---- step sequencer -----------------------------------------------------------------------------
1544
+
1545
+ // A loop of notes on up to 8 lanes, in ticks (96 per quarter note). A note's length is a code value * 3 + feel:
1546
+ // value 0..3 = 1/4 1/8 1/16 1/32, feel 0 straight, 1 triplet, 2 dotted. The plugin owns the buffer `buf` (800
1547
+ // numbers at most: ui_mem..ui_mem + 799); per lane: [0] note count, [1] muted, then up to 32 notes of (start tick,
1548
+ // code, velocity). buf[0] is the loop length in ticks; lane l starts at buf + 8 + l * 98.
1549
+ function ui_sqlen(c) local(v, f) (
1550
+ v = floor(c / 3); f = c - v * 3;
1551
+ floor(96 / (2 ^ v) * (f == 1 ? 2 / 3 : f == 2 ? 1.5 : 1) + 0.5);
1552
+ );
1553
+ function ui_sqfeel(c) ( c - floor(c / 3) * 3; );
1554
+ // the note length's name in #ui_txt: 1/16, 1/8T, 1/8D
1555
+ function ui_sqname(c) local(v, f) (
1556
+ v = floor(c / 3); f = c - v * 3;
1557
+ sprintf(#ui_txt, "1/%d", 4 * (2 ^ v));
1558
+ f == 1 ? strcat(#ui_txt, "T") : f == 2 ? strcat(#ui_txt, "D");
1559
+ );
1560
+ function ui_sqlane(l) ( ui_sqb + 8 + l * 98; );
1561
+ // Empties the pattern and sets its shape: call once in @init (guarded, so a rerun on Play keeps the notes).
1562
+ function ui_sqclear(buf, lanes, ticks) local(i, p) (
1563
+ ui_sqb = buf; ui_sqnl = max(1, min(8, floor(lanes))); ui_sqb[0] = ticks; ui_sqb[2] = 0;
1564
+ i = 0; loop(ui_sqnl, p = ui_sqlane(i); p[0] = 0; p[1] = 0; i += 1;);
1565
+ ui_sqdesel();
1566
+ );
1567
+ // the note of lane l that starts at tick s, -1 for none
1568
+ function ui_sqat(l, s) local(p, i, r) (
1569
+ p = ui_sqlane(l); r = -1; i = 0;
1570
+ loop(p[0], p[2 + i * 3] == s ? r = i; i += 1;);
1571
+ r;
1572
+ );
1573
+ // A note at tick s (one already there is replaced); returns its index, -1 when the lane is full (32 notes).
1574
+ function ui_sqadd(l, s, c, v) local(p, n, i) (
1575
+ p = ui_sqlane(l); n = p[0]; i = ui_sqat(l, s);
1576
+ i >= 0 ? ( p[3 + i * 3] = c; p[4 + i * 3] = v; i; ) :
1577
+ n < 32 ? ( p[2 + n * 3] = s; p[3 + n * 3] = c; p[4 + n * 3] = v; p[0] = n + 1; ui_sqsl[l * 32 + n] = 0; n; ) : -1;
1578
+ );
1579
+ // Removes note i (the last one takes its place, so indexes shift).
1580
+ function ui_sqdel(l, i) local(p, k) (
1581
+ p = ui_sqlane(l); k = p[0] - 1;
1582
+ i >= 0 && i <= k ? (
1583
+ p[2 + i * 3] = p[2 + k * 3]; p[3 + i * 3] = p[3 + k * 3]; p[4 + i * 3] = p[4 + k * 3];
1584
+ ui_sqsl[l * 32 + i] = ui_sqsl[l * 32 + k]; ui_sqsl[l * 32 + k] = 0;
1585
+ p[0] = k;
1586
+ );
1587
+ );
1588
+ // the note covering tick t (latest start wins; one shorter than `slack` ticks still counts as that wide), -1 for none
1589
+ function ui_sqfind(l, t, slack) local(p, i, s, best) (
1590
+ p = ui_sqlane(l); best = -1; i = 0;
1591
+ loop(p[0],
1592
+ s = p[2 + i * 3];
1593
+ t >= s && t < s + max(slack, ui_sqlen(p[3 + i * 3])) && (best < 0 || s > p[2 + best * 3]) ? best = i;
1594
+ i += 1;
1595
+ );
1596
+ best;
1597
+ );
1598
+ // the length code of the value with this feel that is closest to `len` ticks
1599
+ function ui_sqnear(len, feel) local(best, d, v) (
1600
+ best = feel; d = abs(ui_sqlen(feel) - len); v = 1;
1601
+ loop(3,
1602
+ abs(ui_sqlen(v * 3 + feel) - len) < d ? ( best = v * 3 + feel; d = abs(ui_sqlen(best) - len); );
1603
+ v += 1;
1604
+ );
1605
+ best;
1606
+ );
1607
+ // the grid cell the pointer is in (its left edge), the place a new note goes
1608
+ function ui_sqcell(t, st) ( min(ui_sqb[0] - 1, max(0, floor(t / st) * st)); );
1609
+ function ui_sqsnap(t, st) ( min(ui_sqb[0] - 1, max(0, floor(t / st + 0.5) * st)); );
1610
+
1611
+ // Remembers where every selected note starts: a drag moves them all from here.
1612
+ function ui_sqorg() local(l, i, p) (
1613
+ l = 0; loop(ui_sqnl, p = ui_sqlane(l); i = 0; loop(p[0], ui_sqor[l * 32 + i] = p[2 + i * 3]; i += 1;); l += 1;);
1614
+ );
1615
+ // Moves the selected notes to their remembered starts + delta ticks, all by the same amount, kept inside the loop;
1616
+ // nothing moves when a note would land on one that is not selected.
1617
+ function ui_sqshift(delta) local(l, i, p, lo, hi, ok, o) (
1618
+ lo = 99999; hi = -1; l = 0;
1619
+ loop(ui_sqnl, p = ui_sqlane(l); i = 0; loop(p[0], ui_sqsl[l * 32 + i] ? ( lo = min(lo, ui_sqor[l * 32 + i]); hi = max(hi, ui_sqor[l * 32 + i]); ); i += 1;); l += 1;);
1620
+ hi >= 0 ? (
1621
+ delta = max(-lo, min(ui_sqb[0] - 1 - hi, delta));
1622
+ ok = 1; l = 0;
1623
+ loop(ui_sqnl, p = ui_sqlane(l); i = 0;
1624
+ loop(p[0],
1625
+ ui_sqsl[l * 32 + i] ? ( o = ui_sqat(l, ui_sqor[l * 32 + i] + delta); o >= 0 && !ui_sqsl[l * 32 + o] ? ok = 0; );
1626
+ i += 1;
1627
+ );
1628
+ l += 1;
1629
+ );
1630
+ ok ? (
1631
+ l = 0;
1632
+ loop(ui_sqnl, p = ui_sqlane(l); i = 0; loop(p[0], ui_sqsl[l * 32 + i] ? p[2 + i * 3] = ui_sqor[l * 32 + i] + delta; i += 1;); l += 1;);
1633
+ );
1634
+ );
1635
+ );
1636
+ // How many notes of lane l are selected.
1637
+ function ui_sqlsel(l) local(i, n, p) (
1638
+ p = ui_sqlane(l); n = 0; i = 0; loop(p[0], n += ui_sqsl[l * 32 + i] ? 1 : 0; i += 1;); n;
1639
+ );
1640
+ // Moves every selected note dl lanes (up or down, same start, length and velocity). Nothing moves, and 0 comes
1641
+ // back, when one would leave the lanes, land on a note that stays, or overfill a lane (32 notes).
1642
+ function ui_sqlanes(dl) local(l, t, i, p, q, ok, s, c, v, o) (
1643
+ ok = dl != 0; l = 0;
1644
+ loop(ui_sqnl,
1645
+ p = ui_sqlane(l); t = l + dl;
1646
+ ui_sqlsel(l) > 0 ? (
1647
+ t < 0 || t >= ui_sqnl ? ok = 0 : (
1648
+ i = 0;
1649
+ loop(p[0],
1650
+ ui_sqsl[l * 32 + i] ? ( o = ui_sqat(t, p[2 + i * 3]); o >= 0 && !ui_sqsl[t * 32 + o] ? ok = 0; );
1651
+ i += 1;
1652
+ );
1653
+ q = ui_sqlane(t); q[0] - ui_sqlsel(t) + ui_sqlsel(l) > 32 ? ok = 0;
1654
+ );
1655
+ );
1656
+ l += 1;
1657
+ );
1658
+ ok ? (
1659
+ l = dl > 0 ? ui_sqnl - 1 : 0;
1660
+ loop(ui_sqnl,
1661
+ p = ui_sqlane(l); i = p[0] - 1;
1662
+ loop(p[0],
1663
+ i >= 0 && ui_sqsl[l * 32 + i] ? (
1664
+ s = p[2 + i * 3]; c = p[3 + i * 3]; v = p[4 + i * 3];
1665
+ ui_sqdel(l, i);
1666
+ o = ui_sqadd(l + dl, s, c, v); o >= 0 ? ui_sqsl[(l + dl) * 32 + o] = 1;
1667
+ );
1668
+ i -= 1;
1669
+ );
1670
+ l += dl > 0 ? -1 : 1;
1671
+ );
1672
+ );
1673
+ ok;
1674
+ );
1675
+ // Adjustments act on the whole selection. ui_sqvorg remembers the selected notes' velocities as a drag starts, ui_sqvel
1676
+ // sets each to that + delta (kept 1..127), ui_sqsetlen gives every selected note the length code c, and ui_sqadj
1677
+ // steps the length (or, with vel, the velocity) of a scrolled note, and of the whole selection when that note is in it.
1678
+ function ui_sqvorg() local(l, i, p) (
1679
+ l = 0; loop(ui_sqnl, p = ui_sqlane(l); i = 0; loop(p[0], ui_sqor[l * 32 + i] = p[4 + i * 3]; i += 1;); l += 1;);
1680
+ );
1681
+ function ui_sqvel(delta) local(l, i, p) (
1682
+ l = 0; loop(ui_sqnl, p = ui_sqlane(l); i = 0; loop(p[0], ui_sqsl[l * 32 + i] ? p[4 + i * 3] = min(127, max(1, ui_sqor[l * 32 + i] + delta)); i += 1;); l += 1;);
1683
+ );
1684
+ function ui_sqsetlen(c) local(l, i, p) (
1685
+ l = 0; loop(ui_sqnl, p = ui_sqlane(l); i = 0; loop(p[0], ui_sqsl[l * 32 + i] ? p[3 + i * 3] = c; i += 1;); l += 1;);
1686
+ );
1687
+ function ui_sqadj(ln, hi, d, vel, step) local(l, i, p, all) (
1688
+ all = ui_sqsl[ln * 32 + hi];
1689
+ l = 0;
1690
+ loop(ui_sqnl,
1691
+ p = ui_sqlane(l); i = 0;
1692
+ loop(p[0],
1693
+ (all ? ui_sqsl[l * 32 + i] : l == ln && i == hi) ? (
1694
+ vel ? p[4 + i * 3] = min(127, max(1, p[4 + i * 3] - d * step)) :
1695
+ p[3 + i * 3] = min(3, max(0, floor(p[3 + i * 3] / 3) + d)) * 3 + ui_sqfeel(p[3 + i * 3]);
1696
+ );
1697
+ i += 1;
1698
+ );
1699
+ l += 1;
1700
+ );
1701
+ );
1702
+ // Selects the notes that overlap lanes l0..l1 and ticks t0..t1 (add = keep the ones already selected).
1703
+ function ui_sqmarq(l0, l1, t0, t1, add) local(l, i, p, s, inside) (
1704
+ l = 0;
1705
+ loop(ui_sqnl,
1706
+ p = ui_sqlane(l); i = 0;
1707
+ loop(p[0],
1708
+ s = p[2 + i * 3];
1709
+ inside = l >= l0 && l <= l1 && s < t1 && s + ui_sqlen(p[3 + i * 3]) > t0;
1710
+ add ? ( inside ? ui_sqsl[l * 32 + i] = 1; ) : ( ui_sqsl[l * 32 + i] = inside; );
1711
+ i += 1;
1712
+ );
1713
+ l += 1;
1714
+ );
1715
+ );
1716
+ function ui_sqcount() local(l, i, p, n) (
1717
+ n = 0; l = 0; loop(ui_sqnl, p = ui_sqlane(l); i = 0; loop(p[0], n += ui_sqsl[l * 32 + i] ? 1 : 0; i += 1;); l += 1;);
1718
+ n;
1719
+ );
1720
+
1721
+ // A small button; returns 1 on the frame it is pressed.
1722
+ function ui_sqchip(x, y, w, h, on, label) local(hov) (
1723
+ hov = mouse_x >= x && mouse_x < x + w && mouse_y >= y && mouse_y < y + h && !(ui_core && ui_blocked) && !ui_modal;
1724
+ on ? ui_c(ui_cAccent, 1) : hov ? ui_cm(ui_cPanel2, ui_cText, 0.12) : ui_c(ui_cPanel2, 1);
1725
+ ui_rrect(x, y, w, h, 4 * ui_s);
1726
+ gfx_setfont(5); ui_c(on ? ui_cBg : hov ? ui_cText : ui_cMuted, 1);
1727
+ strcpy(#ui_txt, label); ui_ctext(x, y, w, h);
1728
+ hov && ui_press && ui_active == 0 ? ( ui_press = 0; 1; ) : 0;
1729
+ );
1730
+
1731
+ // The note colour: straight = the accent, triplet = green, dotted = amber.
1732
+ function ui_sqcol(f) ( f == 1 ? ui_cLive : f == 2 ? ui_cWarn : ui_cAccent; );
1733
+
1734
+ // The pattern editor. `buf` is the plugin's buffer (see above), `lanes` 1-8, `note_idx` the first of `lanes` sliders
1735
+ // holding each lane's MIDI note (shown beside the lane; click it to hear it, Cmd/Ctrl-click to mute the lane).
1736
+ // Give it a tall row (ui_tall(3)). Set ui_sqph in @block (the loop tick of the playhead, -1 when stopped) and read the
1737
+ // notes there; light a lane from @block with ui_kkey(lane, vel). Put ui_padmap(note_idx, lanes, 1, ...) in Advanced.
1738
+ //
1739
+ // Like REAPER's MIDI editor: a click on empty space adds a note, a drag makes a selection (a marquee), Shift-drag
1740
+ // paints a run of notes, Delete (or Backspace, or the DELETE button) removes the selected notes, Cmd/Ctrl+A selects
1741
+ // all, and dragging a selected note moves the whole selection. A BRUSH sets what a click or a painted run adds: a
1742
+ // length (the 1/4 .. 1/32 buttons, keys 1-4, or scroll over empty space) and a feel (straight / triplet / dotted
1743
+ // buttons, keys q w e). Shift and Alt never change the feel, so a Shift-drag paints in the brush's own value; the
1744
+ // grid redraws on the lines of what you are about to place. On a note: Cmd/Ctrl-click adds it to the selection, drag = move, Shift-drag = velocity (up/down), drag its right edge to
1745
+ // resize, scroll = length (Cmd/Ctrl-scroll = velocity), right-click or double-click deletes it, and Alt/Option-drag erases every note the pointer crosses. Cmd/Ctrl while placing
1746
+ // or moving ignores the grid.
1747
+ function ui_seq(buf, lanes, note_idx, label) local(ux, gx, gw, gy, rh, lw, lt, nl, hov, ln, t, hi, p, k, i, l, x, y, w, h, c, v, fe, st, s, d, dx, dy, ns, o, e, f2, now, edge, ex, cx, cw, ch, n, hint, base, rhov, uhov) (
1748
+ ui_cell();
1749
+ ui_sqb = buf; ui_sqnl = max(1, min(8, floor(lanes))); nl = ui_sqnl; ui_sqon = nl;
1750
+ ui_pn = 0; strcpy(#ui_pword, "LANE"); // a ui_padmap beside it lights lane i like note i
1751
+ lt = ui_sqb[0]; now = time_precise();
1752
+ fe = ui_sqbf;
1753
+ lw = 40 * ui_s; gx = ui_rx + 4 * ui_s + lw; gw = ui_rw - 8 * ui_s - lw;
1754
+ gy = ui_ry + 33 * ui_s; rh = (ui_ry + ui_rh - 16 * ui_s - gy) / nl;
1755
+ gw > 60 * ui_s && rh > 12 * ui_s ? (
1756
+ // header: the label and the brush buttons (length, then feel)
1757
+ gfx_setfont(2); ui_caps(label); ui_c(ui_cMuted, 1);
1758
+ gfx_x = ui_rx + 4 * ui_s; gfx_y = ui_ry + 5 * ui_s; gfx_drawstr(#ui_txt);
1759
+ cw = 31 * ui_s; ch = 17 * ui_s; cx = ui_rx + ui_rw - 4 * ui_s - 3 * 29 * ui_s - 4 * cw - 8 * ui_s;
1760
+ ui_rw > 300 * ui_s ? (
1761
+ i = 0; loop(4,
1762
+ ui_sqname(i * 3 + 0); ui_sqchip(cx + i * cw, ui_ry + 2 * ui_s, cw - 2 * ui_s, ch, i == ui_sqbl, #ui_txt) ? ( ui_sqbl = i; );
1763
+ i += 1;
1764
+ );
1765
+ cx += 4 * cw + 8 * ui_s;
1766
+ i = 0; loop(3,
1767
+ ui_sqchip(cx + i * 29 * ui_s, ui_ry + 2 * ui_s, 27 * ui_s, ch, i == fe, i == 0 ? "STR" : i == 1 ? "TRI" : "DOT") ? ( ui_sqbf = i; );
1768
+ i += 1;
1769
+ );
1770
+ );
1771
+
1772
+ // pointer: where it is on the grid, which note it is over
1773
+ hov = mouse_x >= gx && mouse_x < gx + gw && mouse_y >= gy && mouse_y < gy + rh * nl && !(ui_core && ui_blocked) && !ui_modal && (ui_active == 0 || ui_active == 66);
1774
+ ln = hov ? min(nl - 1, floor((mouse_y - gy) / rh)) : -1;
1775
+ t = (mouse_x - gx) / gw * lt;
1776
+ hi = hov ? ui_sqfind(ln, t, 6 * ui_s / gw * lt) : -1;
1777
+ edge = 0;
1778
+ hi >= 0 ? (
1779
+ p = ui_sqlane(ln);
1780
+ ex = gx + (p[2 + hi * 3] + ui_sqlen(p[3 + hi * 3])) / lt * gw;
1781
+ edge = ui_sqlen(p[3 + hi * 3]) / lt * gw > 14 * ui_s && mouse_x >= ex - 5 * ui_s;
1782
+ );
1783
+ hov && edge && ui_active == 0 ? ui_gany = 1;
1784
+
1785
+ // press: a note (toggle its feel, select it, or start a drag), or empty space (a click adds a note, a drag selects,
1786
+ // Shift-drag paints a run)
1787
+ ui_active != 66 ? ui_sqpd = 0;
1788
+ // the ruler above the grid: a click sets where playing starts (header slot 2, in ticks; the same spot again, or beat 1, clears it)
1789
+ rhov = ui_active == 0 && mouse_x >= gx && mouse_x < gx + gw && mouse_y >= gy - 14 * ui_s && mouse_y < gy && !(ui_core && ui_blocked) && !ui_modal;
1790
+ rhov && ui_press ? (
1791
+ ui_press = 0;
1792
+ s = min(lt - 24, max(0, floor(t / 24 + 0.5) * 24));
1793
+ ui_sqpush1(); ui_sqb[2] = (s == ui_sqb[2]) ? 0 : s;
1794
+ );
1795
+ // Alt (Option)-drag erases every note the pointer crosses, like REAPER's MIDI editor
1796
+ hov && ui_press && ui_active == 0 && (mouse_cap & 16) ? (
1797
+ ui_press = 0; ui_active = 66; ui_sqmode = 8; ui_sqln = ln; ui_sqi = 0;
1798
+ hi >= 0 ? ( ui_sqpush1(); ui_sqdel(ln, hi); );
1799
+ );
1800
+ hov && ui_press && ui_active == 0 ? (
1801
+ ui_press = 0;
1802
+ hi < 0 ? (
1803
+ ui_active = 66; ui_sqmode = 6; ui_sqln = ln; ui_sqx0 = mouse_x; ui_sqy0 = mouse_y;
1804
+ ui_sqpt = t; ui_sqfe = fe; ui_sqpsh = mouse_cap & 8; ui_sqpal = mouse_cap & 16; ui_sqpcm = mouse_cap & 4;
1805
+ ) : (
1806
+ p = ui_sqlane(ln); k = p + 3 + hi * 3; cx = ln * 10000 + p[2 + hi * 3];
1807
+ (ui_sqcid == cx && now - ui_sqct < 0.35) ? (
1808
+ ui_sqpush(); ui_sqdel(ln, hi); ui_sqcid = -1;
1809
+ ) : (
1810
+ ui_sqcid = cx; ui_sqct = now;
1811
+ // Cmd/Ctrl toggles this note in the selection; otherwise it becomes the selection unless it is part of it
1812
+ (mouse_cap & 4) ? ui_sqsl[ln * 32 + hi] = !ui_sqsl[ln * 32 + hi] :
1813
+ !ui_sqsl[ln * 32 + hi] ? ( ui_sqdesel(); ui_sqsl[ln * 32 + hi] = 1; );
1814
+ ui_active = 66; ui_sqmode = edge ? 3 : 5; ui_sqln = ln; ui_sqi = hi; ui_sqx0 = mouse_x; ui_sqy0 = mouse_y; ui_sqpcm = mouse_cap & 4; ui_sqpsh = mouse_cap & 8;
1815
+ ui_sqs0 = p[2 + hi * 3]; ui_sqv0 = p[4 + hi * 3];
1816
+ );
1817
+ );
1818
+ );
1819
+ hov && ui_rpress && ui_active == 0 && hi >= 0 ? ( ui_sqpush(); ui_sqdel(ln, hi); );
1820
+
1821
+ // drag
1822
+ ui_active == 66 && ui_down ? (
1823
+ p = ui_sqlane(ui_sqln); i = ui_sqi; k = p + 2 + i * 3;
1824
+ dx = mouse_x - ui_sqx0; dy = mouse_y - ui_sqy0;
1825
+ ui_sqmode == 8 && hov ? (
1826
+ i = ui_sqfind(ln, t, 6 * ui_s / gw * lt); i >= 0 ? ( ui_sqpush1(); ui_sqdel(ln, i); );
1827
+ );
1828
+ ui_sqmode == 6 && (abs(dx) >= 4 * ui_s || abs(dy) >= 4 * ui_s) ? (
1829
+ ui_sqpsh ? (
1830
+ // Shift-drag paints, with the brush's own length and feel
1831
+ ui_sqcode = ui_sqbl * 3 + ui_sqbf; ui_sqst = ui_sqlen(ui_sqcode);
1832
+ ui_sqs0 = ui_sqpcm ? min(lt - 1, max(0, floor(ui_sqpt + 0.5))) : ui_sqcell(ui_sqpt, ui_sqst);
1833
+ ui_sqk = 0; ui_sqpush1(); ui_sqdesel(); ui_sqadd(ui_sqln, ui_sqs0, ui_sqcode, 100); ui_kput(slider(note_idx + ui_sqln), 100);
1834
+ ui_sqmode = 1;
1835
+ ) : (
1836
+ ui_sqmode = 7; ui_sqpcm ? 0 : ui_sqdesel();
1837
+ );
1838
+ );
1839
+ ui_sqmode == 5 ? (
1840
+ ui_sqpsh && abs(dy) >= 4 * ui_s ? (
1841
+ ui_sqmode = 4; ui_sqpush1();
1842
+ ui_sqsl[ui_sqln * 32 + i] ? 0 : ( ui_sqdesel(); ui_sqsl[ui_sqln * 32 + i] = 1; );
1843
+ ui_sqvorg();
1844
+ ) : !ui_sqpsh && (abs(dx) >= 4 * ui_s || abs(dy) >= 4 * ui_s) ? (
1845
+ ui_sqmode = 2; ui_sqs0 = k[0]; ui_sqpush1();
1846
+ ui_sqsl[ui_sqln * 32 + i] ? 0 : ( ui_sqdesel(); ui_sqsl[ui_sqln * 32 + i] = 1; );
1847
+ ui_sqorg();
1848
+ );
1849
+ );
1850
+ ui_sqmode == 4 ? ( ui_sqvel(floor(0 - dy / ui_s * 1.5 + 0.5)); ) :
1851
+ ui_sqmode == 2 ? (
1852
+ // up or down to another lane: every selected note goes along
1853
+ i = max(0, min(nl - 1, floor((mouse_y - gy) / rh))) - ui_sqln;
1854
+ i != 0 ? (
1855
+ s = k[0];
1856
+ ui_sqlanes(i) ? (
1857
+ ui_sqln += i; ui_sqi = ui_sqat(ui_sqln, s);
1858
+ ui_sqorg(); ui_sqs0 = s; ui_sqx0 = mouse_x;
1859
+ p = ui_sqlane(ui_sqln); k = p + 2 + ui_sqi * 3; dx = 0;
1860
+ );
1861
+ );
1862
+ // every selected note moves by the same number of ticks, on the brush's grid (its length and feel), not the note's own
1863
+ ns = ui_sqsnap(ui_sqs0 + dx / gw * lt, (mouse_cap & 4) ? 1 : ui_sqlen(ui_sqbl * 3 + ui_sqbf));
1864
+ ui_sqshift(ns - ui_sqs0);
1865
+ ) :
1866
+ ui_sqmode == 3 ? ( ns = ui_sqnear(t - k[0], ui_sqfeel(k[1])); ns != k[1] ? ( ui_sqpush1(); ui_sqsetlen(ns); ); ) :
1867
+ ui_sqmode == 7 ? (
1868
+ // marquee: select what the rectangle touches
1869
+ ui_sqmarq(max(0, min(nl - 1, floor((min(mouse_y, ui_sqy0) - gy) / rh))), max(0, min(nl - 1, floor((max(mouse_y, ui_sqy0) - gy) / rh))), min(t, ui_sqpt), max(t, ui_sqpt), ui_sqpcm);
1870
+ ) :
1871
+ ui_sqmode == 1 ? (
1872
+ // painting: a note at every step the pointer passes, either way, of the length the drag began with
1873
+ n = floor((t - ui_sqs0) / ui_sqst);
1874
+ loop(96,
1875
+ ui_sqk != n ? (
1876
+ ui_sqk += sign(n - ui_sqk);
1877
+ s = ui_sqs0 + ui_sqk * ui_sqst;
1878
+ s >= 0 && s < lt ? ( ui_sqadd(ui_sqln, s, ui_sqcode, 100) >= 0 ? ui_kput(slider(note_idx + ui_sqln), 100); );
1879
+ );
1880
+ );
1881
+ );
1882
+ );
1883
+ ui_active == 66 && !ui_down ? (
1884
+ ui_sqmode == 6 ? (
1885
+ // a click on empty space adds one note and selects it
1886
+ st = ui_sqlen(ui_sqbl * 3 + ui_sqfe);
1887
+ s = ui_sqpcm ? min(lt - 1, max(0, floor(ui_sqpt + 0.5))) : ui_sqcell(ui_sqpt, st);
1888
+ ui_sqpush(); i = ui_sqadd(ui_sqln, s, ui_sqbl * 3 + ui_sqfe, 100);
1889
+ i >= 0 ? ( ui_sqdesel(); ui_sqsl[ui_sqln * 32 + i] = 1; ui_kput(slider(note_idx + ui_sqln), 100); );
1890
+ ) : ui_sqmode == 5 && !ui_sqpcm ? (
1891
+ // a click on a note, no drag: it is the only one selected
1892
+ ui_sqdesel(); ui_sqsl[ui_sqln * 32 + ui_sqi] = 1;
1893
+ );
1894
+ ui_active = 0; ui_sqmode = 0;
1895
+ );
1896
+ // Esc or a click on nothing in particular leaves the selection alone; the pointer leaving never clears it
1897
+
1898
+ // scroll: a note's length (Cmd/Ctrl: velocity), or the brush length over empty space
1899
+ hov && mouse_wheel != 0 ? (
1900
+ d = mouse_wheel > 0 ? -1 : 1; // up = longer
1901
+ hi >= 0 ? (
1902
+ ui_sqpush(); ui_sqadj(ln, hi, d, (mouse_cap & 4) ? 1 : 0, (mouse_cap & 8) ? 1 : 8);
1903
+ ) : ( ui_sqbl = min(3, max(0, ui_sqbl + d)); );
1904
+ );
1905
+
1906
+ // rows: the lane's note on the left, a track behind the notes
1907
+ ui_c(ui_cMuted, 0.8); gfx_setfont(5);
1908
+ l = 0; loop(nl,
1909
+ y = gy + l * rh; p = ui_sqlane(l); v = slider(note_idx + l);
1910
+ x = ui_rx + 4 * ui_s;
1911
+ ui_kb[l] > 0 ? ui_cm(ui_cPanel2, ui_cAccent, 0.35 + 0.65 * ui_kb[l] / 127) :
1912
+ (mouse_x >= x && mouse_x < x + lw - 4 * ui_s && mouse_y >= y && mouse_y < y + rh && !(ui_core && ui_blocked) && !ui_modal) ? ui_cm(ui_cPanel2, ui_cText, 0.1) : ui_c(ui_cPanel2, 1);
1913
+ ui_rrect(x, y + ui_s, lw - 4 * ui_s, rh - 2 * ui_s, 4 * ui_s);
1914
+ gfx_setfont(3); ui_notename(v); ui_c(p[1] ? ui_cMuted : ui_cText, p[1] ? 0.5 : 1);
1915
+ gfx_measurestr(#ui_txt, ui_tw, ui_th);
1916
+ gfx_x = x + (lw - 4 * ui_s - ui_tw) / 2; gfx_y = y + (rh - ui_th) / 2 - (rh >= 30 * ui_s ? 5 * ui_s : 0); gfx_drawstr(#ui_txt);
1917
+ rh >= 30 * ui_s ? (
1918
+ gfx_setfont(5); ui_c(ui_cMuted, 1); sprintf(#ui_txt, p[1] ? "MUTED" : "%d", v);
1919
+ gfx_measurestr(#ui_txt, ui_tw, ui_th);
1920
+ gfx_x = x + (lw - 4 * ui_s - ui_tw) / 2; gfx_y = y + rh / 2 + 4 * ui_s; gfx_drawstr(#ui_txt);
1921
+ );
1922
+ // click = hear it, Cmd/Ctrl-click = mute
1923
+ ui_press && ui_active == 0 && !(ui_core && ui_blocked) && !ui_modal && mouse_x >= x && mouse_x < x + lw - 4 * ui_s && mouse_y >= y && mouse_y < y + rh ? (
1924
+ ui_press = 0;
1925
+ (mouse_cap & 4) ? ( ui_sqpush(); p[1] = !p[1]; ) : ui_kput(v, 100);
1926
+ );
1927
+ ui_c(ui_cPanel2, 1); ui_rrect(gx, y + ui_s, gw, rh - 2 * ui_s, 4 * ui_s);
1928
+ l += 1;
1929
+ );
1930
+
1931
+ // the grid: beats, the straight 1/16 lines (faint), and the lines of the note about to be placed
1932
+ gfx_setfont(5);
1933
+ i = 0; loop(ceil(lt / 24),
1934
+ x = gx + i * 24 / lt * gw;
1935
+ ui_c(ui_cLine, (i % 4) == 0 ? 1 : 0.5);
1936
+ gfx_rect(x, gy + ui_s, max(1, ui_s), rh * nl - 2 * ui_s);
1937
+ i += 1;
1938
+ );
1939
+ i = 0; loop(ceil(lt / 96),
1940
+ x = gx + i * 96 / lt * gw;
1941
+ sprintf(#ui_txt, "%d", i + 1); ui_c(ui_cMuted, 0.8);
1942
+ gfx_x = x + 3 * ui_s; gfx_y = gy - 12 * ui_s; gfx_drawstr(#ui_txt);
1943
+ i += 1;
1944
+ );
1945
+ // the start marker: a flag on the ruler and a line down the grid; a faint one under the pointer on the ruler
1946
+ ui_sqb[2] > 0 && ui_sqb[2] < lt ? (
1947
+ x = gx + ui_sqb[2] / lt * gw;
1948
+ ui_c(ui_cAccent, 0.9); gfx_rect(x, gy - 2 * ui_s, max(1, 1.5 * ui_s), rh * nl + 2 * ui_s);
1949
+ gfx_triangle(x, gy - 1 * ui_s, x + 9 * ui_s, gy - 8 * ui_s, x, gy - 14 * ui_s);
1950
+ );
1951
+ rhov ? ( ui_c(ui_cText, 0.35); gfx_rect(gx + floor(t / 24 + 0.5) * 24 / lt * gw, gy - 14 * ui_s, max(1, ui_s), 14 * ui_s); );
1952
+ st = ui_sqlen(ui_sqbl * 3 + fe);
1953
+ ui_c(ui_sqcol(fe), 0.3);
1954
+ i = 0; loop(ceil(lt / st),
1955
+ x = gx + i * st / lt * gw;
1956
+ gfx_rect(x, gy + ui_s, max(1, ui_s), rh * nl - 2 * ui_s);
1957
+ i += 1;
1958
+ );
1959
+
1960
+ // the notes
1961
+ l = 0; loop(nl,
1962
+ y = gy + l * rh; p = ui_sqlane(l); i = 0;
1963
+ loop(p[0],
1964
+ s = p[2 + i * 3]; c = p[3 + i * 3]; v = p[4 + i * 3];
1965
+ x = gx + s / lt * gw; w = max(5 * ui_s, min(ui_sqlen(c), lt - s) / lt * gw - 1.5 * ui_s);
1966
+ h = rh - 8 * ui_s; f2 = ui_sqfeel(c);
1967
+ e = (l == ln && i == hi) || (ui_active == 66 && l == ui_sqln && i == ui_sqi);
1968
+ ui_cm(ui_cPanel2, ui_sqcol(f2), (p[1] ? 0.15 : 0.3) + (p[1] ? 0.25 : 0.7) * v / 127);
1969
+ ui_rrect(x, y + 4 * ui_s, w, h, 3 * ui_s);
1970
+ ui_sqsl[l * 32 + i] ? (
1971
+ ui_c(ui_cText, 0.95);
1972
+ gfx_rect(x, y + 4 * ui_s, w, max(1, 1.5 * ui_s)); gfx_rect(x, y + 4 * ui_s + h - max(1, 1.5 * ui_s), w, max(1, 1.5 * ui_s));
1973
+ gfx_rect(x, y + 4 * ui_s, max(1, 1.5 * ui_s), h); gfx_rect(x + w - max(1, 1.5 * ui_s), y + 4 * ui_s, max(1, 1.5 * ui_s), h);
1974
+ );
1975
+ e ? ( ui_c(ui_cText, 0.9); gfx_rect(x + w - 3 * ui_s, y + 4 * ui_s + 2 * ui_s, 2 * ui_s, h - 4 * ui_s); );
1976
+ w > 30 * ui_s && h > 11 * ui_s ? (
1977
+ ui_sqname(c); ui_c(v >= 70 && !p[1] ? ui_cBg : ui_cText, 1);
1978
+ gfx_x = x + 4 * ui_s; gfx_y = y + 4 * ui_s + (h - 9 * ui_s) / 2; gfx_drawstr(#ui_txt);
1979
+ );
1980
+ i += 1;
1981
+ );
1982
+ l += 1;
1983
+ );
1984
+ // ghost: the note a click here would add
1985
+ hov && ui_active == 0 && hi < 0 ? (
1986
+ s = (mouse_cap & 4) ? min(lt - 1, max(0, floor(t + 0.5))) : ui_sqcell(t, st);
1987
+ ui_sqat(ln, s) < 0 ? (
1988
+ x = gx + s / lt * gw; w = max(5 * ui_s, min(st, lt - s) / lt * gw - 1.5 * ui_s); h = rh - 8 * ui_s;
1989
+ ui_cm(ui_cPanel2, ui_sqcol(fe), 0.35); ui_rrect(x, gy + ln * rh + 4 * ui_s, w, h, 3 * ui_s);
1990
+ w > 30 * ui_s && h > 11 * ui_s ? (
1991
+ ui_sqname(ui_sqbl * 3 + fe); ui_c(ui_cText, 0.9);
1992
+ gfx_x = x + 4 * ui_s; gfx_y = gy + ln * rh + 4 * ui_s + (h - 9 * ui_s) / 2; gfx_drawstr(#ui_txt);
1993
+ );
1994
+ );
1995
+ );
1996
+ // the marquee being dragged
1997
+ ui_active == 66 && ui_sqmode == 7 ? (
1998
+ x = min(gx + ui_sqpt / lt * gw, mouse_x); w = abs(mouse_x - (gx + ui_sqpt / lt * gw));
1999
+ y = min(ui_sqy0, mouse_y); h = abs(mouse_y - ui_sqy0);
2000
+ ui_c(ui_cAccent, 0.15); gfx_rect(x, y, w, h);
2001
+ ui_c(ui_cAccent, 0.9); gfx_rect(x, y, w, ui_s); gfx_rect(x, y + h, w, ui_s); gfx_rect(x, y, ui_s, h); gfx_rect(x + w, y, ui_s, h);
2002
+ );
2003
+ // the playhead
2004
+ ui_sqph >= 0 ? ( ui_c(ui_cText, 0.85); gfx_rect(gx + ui_sqph / lt * gw, gy - 3 * ui_s, max(1, 1.5 * ui_s), rh * nl + 3 * ui_s); );
2005
+
2006
+ // footer: what the pointer would do, or a readout while dragging; Clear (twice) on the right
2007
+ y = ui_ry + ui_rh - 14 * ui_s;
2008
+ ui_sqsure && now - ui_sqsure > 2.5 ? ui_sqsure = 0;
2009
+ ui_sqcount() > 0 ? (
2010
+ sprintf(#ui_tmp, "DELETE %d", ui_sqcount());
2011
+ ui_sqchip(ui_rx + ui_rw - 4 * ui_s - 44 * ui_s - 6 * ui_s - 54 * ui_s, y - 1 * ui_s, 54 * ui_s, 14 * ui_s, 0, #ui_tmp) ? ( ui_sqdelsel(); );
2012
+ );
2013
+ ui_sqchip(ui_rx + ui_rw - 4 * ui_s - 44 * ui_s - 6 * ui_s - 54 * ui_s - 6 * ui_s - 40 * ui_s, y - 1 * ui_s, 40 * ui_s, 14 * ui_s, 0, "REDO") && ui_sqrn > 0 ? ui_sqredo();
2014
+ ui_sqchip(ui_rx + ui_rw - 4 * ui_s - 44 * ui_s - 6 * ui_s - 54 * ui_s - 6 * ui_s - 40 * ui_s - 44 * ui_s, y - 1 * ui_s, 40 * ui_s, 14 * ui_s, 0, "UNDO") && ui_squn > 0 ? ui_squndo();
2015
+ ui_sqchip(ui_rx + ui_rw - 4 * ui_s - 44 * ui_s, y - 1 * ui_s, 44 * ui_s, 14 * ui_s, ui_sqsure > 0, ui_sqsure > 0 ? "SURE?" : "CLEAR") ? (
2016
+ ui_sqsure > 0 ? (
2017
+ ui_sqpush(); l = 0; loop(nl, p = ui_sqlane(l); p[0] = 0; l += 1;); ui_sqsure = 0;
2018
+ ) : ui_sqsure = now;
2019
+ );
2020
+ // over UNDO / REDO: how to reach them from the keyboard
2021
+ ux = ui_rx + ui_rw - 4 * ui_s - 44 * ui_s - 6 * ui_s - 54 * ui_s - 6 * ui_s - 40 * ui_s - 44 * ui_s;
2022
+ uhov = mouse_x >= ux && mouse_x < ux + 84 * ui_s && mouse_y >= y - 1 * ui_s && mouse_y < y + 13 * ui_s && ui_active == 0;
2023
+ gfx_setfont(5); ui_c(ui_cMuted, 1);
2024
+ ui_active == 66 ? (
2025
+ p = ui_sqlane(ui_sqln); k = p + 2 + ui_sqi * 3;
2026
+ ui_sqmode == 4 ? sprintf(#ui_txt, "VELOCITY %d", k[2]) :
2027
+ ui_sqmode == 2 ? sprintf(#ui_txt, "MOVING %d SELECTED", ui_sqcount()) :
2028
+ ui_sqmode == 7 ? strcpy(#ui_txt, "SELECTING DELETE REMOVES") :
2029
+ ui_sqmode == 8 ? strcpy(#ui_txt, "ERASING NOTES") :
2030
+ ui_sqmode == 6 ? strcpy(#ui_txt, "DRAG TO SELECT") :
2031
+ ui_sqmode == 1 ? ( ui_sqname(ui_sqcode); strcpy(#ui_tmp, #ui_txt); sprintf(#ui_txt, "PAINTING %s NOTES", #ui_tmp); ) :
2032
+ ( ui_sqname(k[1]); strcpy(#ui_tmp, #ui_txt); sprintf(#ui_txt, "LENGTH %s", #ui_tmp); );
2033
+ ui_c(ui_cText, 1);
2034
+ ) : uhov ? (
2035
+ sprintf(#ui_txt, "UNDO %d REDO %d KEYS: CMD+Z, CMD+SHIFT+Z (FX WINDOW + MENU: SEND ALL KEYBOARD INPUT)", ui_squn, ui_sqrn);
2036
+ ui_c(ui_cText, 1);
2037
+ ) : rhov ? (
2038
+ strcpy(#ui_txt, ui_sqb[2] > 0 ? "CLICK THE RULER: PLAY STARTS THERE CLICK THE FLAG: BACK TO BEAT 1" : "CLICK THE RULER: PLAY STARTS THERE INSTEAD OF BEAT 1");
2039
+ ui_c(ui_cText, 1);
2040
+ ) : hov ? (
2041
+ hi >= 0 ? (
2042
+ strcpy(#ui_txt, "DRAG: MOVE (UP/DOWN = OTHER LANE) SHIFT-DRAG: VELOCITY EDGE: LENGTH ALT-DRAG: ERASE DELETE REMOVES");
2043
+ ) : (
2044
+ ui_sqname(ui_sqbl * 3 + fe); strcpy(#ui_tmp, #ui_txt);
2045
+ sprintf(#ui_txt, "CLICK ADDS %s DRAG SELECTS SHIFT-DRAG PAINTS ALT-DRAG ERASES", #ui_tmp);
2046
+ );
2047
+ ) : strcpy(#ui_txt, "KEYS 1-4 LENGTH Q W E FEEL DELETE REMOVES SELECTED");
2048
+ gfx_measurestr(#ui_txt, ui_tw, ui_th);
2049
+ ui_tw > gw + lw - 196 * ui_s ? ui_caps("DRAG SELECT SHIFT-DRAG PAINT DELETE");
2050
+ gfx_x = ui_rx + 4 * ui_s; gfx_y = y + (14 * ui_s - ui_th) / 2; gfx_drawstr(#ui_txt);
2051
+ gfx_setfont(1);
2052
+ );
2053
+ );