@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.
@@ -13,7 +13,7 @@ argument-hint: '[what the plugin should do | update <plugin>: <what to change>]'
13
13
  license: MIT
14
14
  metadata:
15
15
  author: mthines
16
- version: '1.3.0'
16
+ version: '1.4.0'
17
17
  workflow_type: applied
18
18
  tags: [plugins, jsfx, dsp, ui, reaper, live-verification]
19
19
  ---
@@ -117,10 +117,26 @@ example and change what the spec changes. The shape is always:
117
117
  above it makes the keys a short strip right above the Advanced bar): read it in `@block` with `while (ui_kpoll()) ( ui_kv > 0 ?
118
118
  <note on ui_kn, ui_kv> : <note off ui_kn> );` next to the MIDI-in loop (a synth turns them into
119
119
  voices, a MIDI effect `midisend`s them). Notes from MIDI light the keys with `ui_kkey(note, vel)`.
120
+ - **Drum pads: `ui_pads(36, 4, 4, "Pads")`** for a drum machine, sampler or trigger plugin: a playable grid on
121
+ `ui_tall(2)`, read like the keyboard (`while (ui_kpoll()) ( ... )`, `ui_kkey(note, vel)` to light a pad
122
+ from MIDI in). Pad 1 is bottom-left; the typed keys strike pads too, but only when the user has REAPER's
123
+ "Send all keyboard input to plug-in" on, so never make a pad reachable *only* by key.
124
+ - **A pattern is drawn, not typed: `ui_seq(ui_mem, 4, 6, "Pattern")`** for a step sequencer, arpeggiator or any
125
+ looping MIDI plugin: a loop of notes in ticks (96 per quarter) on 1-8 lanes, on `ui_tall(3)`. Each note has its own
126
+ length (1/4 to 1/32) and feel (straight, triplet, dotted), so one lane mixes them. The brush is the 1/4 .. 1/32
127
+ buttons plus straight / triplet / dotted (keys 1-4 and q / w / e); Shift and Alt never change the feel, so Shift-drag keeps the brush's value, and the grid redraws on the lines of what you are about to place. It follows the MIDI editor (the full mouse and key map is `reference/midi-editor-mouse.md`: read it before adding a gesture to any note editor): drag selects, Alt-drag erases, Delete removes, Shift-drag paints a run of notes at the brush's length. It sends MIDI, so it goes **before** the instrument in the FX chain (after a synth it triggers nothing). Copy
128
+ `examples/step-sequencer.jsfx` (the pattern buffer, the tick-based `@block` that plays it, `@serialize`).
129
+ The lane notes go in Advanced as `ui_padmap(first, lanes, 1, "Note each lane sends")` so any library's map works.
130
+ - **Every control you drag or scroll must say so when the mouse is over it.** Hovering shows an up and down arrow
131
+ (`ui_chev`) beside the value, and the gesture is written on the label line (`ui_padmap` does both: "DRAG OR SCROLL /
132
+ DOUBLE-CLICK TO TYPE"). A custom widget never relies on the user guessing a gesture: hover shows the arrows or
133
+ the cursor, and a hint line says what the pointer would do now (and what Alt, Shift and Cmd/Ctrl change).
134
+ Prefer visible buttons for a small set of choices (the sequencer's length buttons) over a hidden drag.
120
135
  - Do not write the toolkit: `write_jsfx` inlines it.
121
136
  - Never assign `ui_adv_open` (or any `ui_` state) in plugin code: REAPER re-runs `@init` when
122
137
  playback starts, so the Advanced drawer would snap shut on Play (lint `ui-state-reset`).
123
138
  - `desc:` is the plain name: do not add `(reaper-mcp)` yourself, `write_jsfx` appends it.
139
+ - A `while (cond)` body is always in parentheses: `while (cond) ( ... );` (a bare statement compiles to nothing; lint `while-no-body`).
124
140
  - Never set the accent (`ui_cAccent`, `ui_theme`) or read keys/mouse yourself: the toolkit owns
125
141
  gestures (double-click types a value, Cmd/Ctrl/Alt-click resets, Shift-drag is fine).
126
142
 
@@ -0,0 +1,89 @@
1
+ desc:Drum Pads
2
+ // accent: red
3
+ import mcp_ui.jsfx-inc
4
+
5
+ // An eight-pad drum synth that needs no samples: click or drag the pads, press z x c v / a s d f on
6
+ // the keyboard (Shift = hard), or play MIDI notes 36-43. Each pad is a small synthesized voice
7
+ // (kicks, snare, clap, hats, tom, rim). Core view: Level, Tune, Decay and the pads.
8
+ // Shows ui_pads, played by ui_kpoll() and lit by ui_kkey().
9
+
10
+ slider1:-6<-24,6,0.1>Level
11
+ slider2:0<-12,12,1>Tune
12
+ slider3:1<0.4,2,0.01>Decay
13
+
14
+ @init
15
+ // voice i: state at ui_mem + i * 8 (phase, amp, pitch env, last noise, velocity);
16
+ // sound i: ui_mem + 64 + i * 8 (start Hz, end Hz, pitch decay s, amp decay s, noise mix, noise high-pass,
17
+ // then the two per-sample decay coefficients update() fills in)
18
+ function sound(i, f0, f1, pd, ad, nz, hp) local(p) (
19
+ p = ui_mem + 64 + i * 8;
20
+ p[0] = f0; p[1] = f1; p[2] = pd; p[3] = ad; p[4] = nz; p[5] = hp;
21
+ );
22
+ sound(0, 160, 48, 0.04, 0.35, 0.02, 0); // kick
23
+ sound(1, 110, 38, 0.06, 0.6, 0, 0); // deep kick
24
+ sound(2, 220, 160, 0.03, 0.18, 0.75, 0); // snare
25
+ sound(3, 0, 0, 0.01, 0.22, 1, 1); // clap
26
+ sound(4, 0, 0, 0.01, 0.05, 1, 1); // closed hat
27
+ sound(5, 0, 0, 0.01, 0.35, 1, 1); // open hat
28
+ sound(6, 200, 110, 0.05, 0.3, 0.05, 0); // tom
29
+ sound(7, 1700, 1500, 0.01, 0.06, 0.1, 0); // rim
30
+ function hit(i, vel) local(v) (
31
+ i >= 0 && i < 8 ? (
32
+ v = ui_mem + i * 8;
33
+ v[1] = 1; v[2] = 1; v[4] = vel / 127;
34
+ );
35
+ );
36
+ function update() local(i, p) (
37
+ level = 10 ^ (slider1 / 20);
38
+ tune = 2 ^ (slider2 / 12);
39
+ step = 2 * $pi / srate;
40
+ i = 0;
41
+ loop(8,
42
+ p = ui_mem + 64 + i * 8;
43
+ p[6] = exp(-1 / (p[2] * srate));
44
+ p[7] = exp(-1 / (p[3] * slider3 * srate));
45
+ i += 1;
46
+ );
47
+ );
48
+ function voice(i) local(v, p, f, n) (
49
+ v = ui_mem + i * 8; p = ui_mem + 64 + i * 8;
50
+ v[1] > 0.0005 ? (
51
+ f = (p[1] + (p[0] - p[1]) * v[2]) * tune;
52
+ v[0] += f * step; v[0] > 2 * $pi ? v[0] -= 2 * $pi;
53
+ v[2] *= p[6];
54
+ n = rand(2) - 1;
55
+ p[5] > 0.5 ? ( f = n - v[3]; v[3] = n; n = f * 0.5; );
56
+ out += (sin(v[0]) * (1 - p[4]) + n * p[4]) * v[1] * v[4];
57
+ v[1] *= p[7];
58
+ );
59
+ );
60
+ update();
61
+ ui_boot(2);
62
+
63
+ @slider
64
+ update();
65
+
66
+ @block
67
+ ui_changed() ? update();
68
+ // MIDI in: notes 36-43 hit the pads and light them
69
+ while (midirecv(ofs, m1, m2, m3)) (
70
+ (m1 & 240) == 144 && m3 > 0 ? ( hit(m2 - 36, m3); ui_kkey(m2, m3); ) :
71
+ ((m1 & 240) == 128 || ((m1 & 240) == 144 && m3 == 0)) ? ui_kkey(m2, 0);
72
+ );
73
+ // pads the user struck with the mouse or the keyboard
74
+ while (ui_kpoll()) ( ui_kv > 0 ? hit(ui_kn - 36, ui_kv); );
75
+
76
+ @sample
77
+ out = 0;
78
+ voice(0); voice(1); voice(2); voice(3); voice(4); voice(5); voice(6); voice(7);
79
+ out *= level;
80
+ spl0 = out; spl1 = out;
81
+
82
+ @gfx 420 340
83
+ ui_begin(3, 0) ? (
84
+ ui_row(3);
85
+ ui_knob(1, "Level", 1); ui_knob(2, "Tune", 5); ui_knob(3, "Decay", 0);
86
+ ui_tall(2); ui_row(1);
87
+ ui_pads(36, 4, 2, "Pads");
88
+ ui_end();
89
+ );
@@ -0,0 +1,6 @@
1
+ [
2
+ { "name": "Tight", "values": { "Level": -6, "Tune": 0, "Decay": 0.6 } },
3
+ { "name": "Roomy", "values": { "Level": -8, "Tune": 0, "Decay": 1.6 } },
4
+ { "name": "Low and long", "values": { "Level": -6, "Tune": -5, "Decay": 1.4 } },
5
+ { "name": "Bright and short", "values": { "Level": -7, "Tune": 4, "Decay": 0.5 } }
6
+ ]
@@ -0,0 +1,84 @@
1
+ desc:Pad MIDI
2
+ // accent: amber
3
+ import mcp_ui.jsfx-inc
4
+
5
+ // Eight playable pads that send MIDI notes instead of sound: put a sampler or drum library after it.
6
+ // Hit the pads (mouse, keys z x c v / a s d f, Shift = hard) or play MIDI notes 36-43 into it. Each
7
+ // pad sends the note you map to it in Advanced, so a library with its own layout needs no re-keying.
8
+ // Timing and Velocity humanize every hit (Timing only ever delays, by up to that many ms, so the
9
+ // plugin adds that much latency at most). Other MIDI passes through untouched.
10
+
11
+ slider1:0<0,30,0.5>Timing
12
+ slider2:0<0,0.5,0.01>Velocity
13
+ slider3:120<20,500,1>Length
14
+ slider4:1<1,16,1>Channel
15
+ slider5:36<0,127,1>-Pad 1
16
+ slider6:37<0,127,1>-Pad 2
17
+ slider7:38<0,127,1>-Pad 3
18
+ slider8:39<0,127,1>-Pad 4
19
+ slider9:40<0,127,1>-Pad 5
20
+ slider10:41<0,127,1>-Pad 6
21
+ slider11:42<0,127,1>-Pad 7
22
+ slider12:43<0,127,1>-Pad 8
23
+
24
+ @init
25
+ // the send queue: 64 slots of 4 numbers at ui_mem (due in samples, status, note, velocity; due 0 = free)
26
+ inited ? 0 : ( i = 0; loop(256, ui_mem[i] = 0; i += 1;); t = 1; inited = 1; );
27
+ function update() (
28
+ jit = slider1 * 0.001 * srate;
29
+ vjit = slider2;
30
+ len = slider3 * 0.001 * srate;
31
+ ch = slider4 - 1;
32
+ );
33
+ // a note on (at due) and its off (len samples later): both queued or neither, so a full queue never leaves a note held
34
+ function sendpair(due, st, n, v) local(a, b, q) (
35
+ a = 0; while (a < 64 && ui_mem[a * 4] != 0) ( a += 1; );
36
+ b = a + 1; while (b < 64 && ui_mem[b * 4] != 0) ( b += 1; );
37
+ b < 64 ? (
38
+ q = ui_mem + a * 4; q[0] = due; q[1] = 144 + st; q[2] = n; q[3] = v;
39
+ q = ui_mem + b * 4; q[0] = due + len; q[1] = 128 + st; q[2] = n; q[3] = 0;
40
+ );
41
+ );
42
+ // pad p (0-7) struck at sample offset ofs: the mapped note on now (plus a little lateness), off after Length
43
+ function strike(p, vel, ofs) local(due, v) (
44
+ due = t + ofs + rand(1) * jit;
45
+ v = floor(vel * (1 + (rand(2) - 1) * vjit) + 0.5);
46
+ v = min(127, max(1, v));
47
+ sendpair(due, ch, slider(5 + p), v);
48
+ );
49
+ update();
50
+ ui_boot(2);
51
+
52
+ @slider
53
+ update();
54
+
55
+ @block
56
+ ui_changed() ? update();
57
+ while (midirecv(ofs, m1, m2, m3)) (
58
+ ((m1 & 240) == 144 || (m1 & 240) == 128) && m2 >= 36 && m2 < 44 ? (
59
+ (m1 & 240) == 144 && m3 > 0 ? ( strike(m2 - 36, m3, ofs); ui_kkey(m2, m3); ) : ui_kkey(m2, 0);
60
+ ) : midisend(ofs, m1, m2, m3);
61
+ );
62
+ // pads the user struck with the mouse or the keyboard
63
+ while (ui_kpoll()) ( ui_kv > 0 ? strike(ui_kn - 36, ui_kv, 0); );
64
+ // send what falls inside this block
65
+ s = 0;
66
+ loop(64,
67
+ q = ui_mem + s * 4;
68
+ q[0] != 0 && q[0] < t + samplesblock ? (
69
+ midisend(max(0, floor(q[0] - t)), q[1], q[2], q[3]);
70
+ q[0] = 0;
71
+ );
72
+ s += 1;
73
+ );
74
+ t += samplesblock;
75
+
76
+ @gfx 440 400
77
+ ui_begin(3, 2) ? (
78
+ ui_row(4);
79
+ ui_knob(1, "Timing", 4); ui_knob(2, "Velocity", 2); ui_knob(3, "Length", 4); ui_knob(4, "Channel", 5);
80
+ ui_tall(2); ui_row(1);
81
+ ui_pads(36, 4, 2, "Pads");
82
+ ui_section("Advanced") ? ( ui_tall(2); ui_row(1); ui_padmap(5, 4, 2, "Note each pad sends"); );
83
+ ui_end();
84
+ );
@@ -0,0 +1,6 @@
1
+ [
2
+ { "name": "Plain (36-43)", "values": { "Timing": 0, "Velocity": 0, "Length": 120, "Pad 1": 36, "Pad 2": 37, "Pad 3": 38, "Pad 4": 39, "Pad 5": 40, "Pad 6": 41, "Pad 7": 42, "Pad 8": 43 } },
3
+ { "name": "GM kit", "values": { "Pad 1": 36, "Pad 2": 35, "Pad 3": 38, "Pad 4": 39, "Pad 5": 42, "Pad 6": 46, "Pad 7": 45, "Pad 8": 37 } },
4
+ { "name": "Chromatic from C2", "values": { "Pad 1": 48, "Pad 2": 49, "Pad 3": 50, "Pad 4": 51, "Pad 5": 52, "Pad 6": 53, "Pad 7": 54, "Pad 8": 55 } },
5
+ { "name": "Loose human", "values": { "Timing": 12, "Velocity": 0.15, "Length": 120 } }
6
+ ]
@@ -0,0 +1,169 @@
1
+ desc:Step Sequencer
2
+ // accent: green
3
+ import mcp_ui.jsfx-inc
4
+
5
+ // A loop of MIDI notes you draw, four lanes (up to eight, set in Advanced), on the project's beat: put a sampler or drum library after it.
6
+ // Click a lane to add a note of the brush's length (1/4 to 1/32, keys 1-4) in the brush's
7
+ // feel (straight, triplet or dotted: keys q w e), so one lane can mix all three. Each lane sends the note you map to it in
8
+ // Advanced. Beats is the loop length (3 or 5 give odd bars); Gate shortens each note; Timing and Velocity humanize
9
+ // (Timing only ever delays by up to that many ms). It plays while the project plays; other MIDI passes through.
10
+ // Put it BEFORE the instrument in the FX chain: it sends MIDI to whatever comes after it.
11
+ // The playhead follows the sound; if it still runs ahead of what you hear, change Playhead in Advanced (ms; 190 matched REAPER's default look-ahead on the machine this was tuned on).
12
+ // Click the ruler above the grid to make Play start the loop there instead of at beat 1.
13
+ // Editing is like REAPER's MIDI editor: click adds, drag selects, Shift-drag paints a run, Delete removes.
14
+
15
+ slider1:4<1,8,1>Beats
16
+ slider2:80<10,100,1>Gate
17
+ slider3:0<0,30,0.5>Timing
18
+ slider4:0<0,0.5,0.01>Velocity
19
+ slider5:1<1,16,1>Channel
20
+ slider6:36<0,127,1>-Lane 1
21
+ slider7:38<0,127,1>-Lane 2
22
+ slider8:42<0,127,1>-Lane 3
23
+ slider9:46<0,127,1>-Lane 4
24
+ slider10:39<0,127,1>-Lane 5
25
+ slider11:41<0,127,1>-Lane 6
26
+ slider12:43<0,127,1>-Lane 7
27
+ slider13:49<0,127,1>-Lane 8
28
+ slider14:4<4,8,1>-Lanes
29
+ slider15:190<0,500,1>-Playhead delay
30
+
31
+ @init
32
+ // the pattern at ui_mem (see ui_seq), the send queue after it: 64 slots of 5 numbers
33
+ // (due in samples, status, note, velocity, lane; due 0 = free)
34
+ qb = ui_mem + 800;
35
+ ui_sqb = ui_mem;
36
+ // The marker that the pattern exists lives in the pattern's own memory (header slot 1), not in a variable: when
37
+ // REAPER re-runs @init on Play the notes you drew must survive, whatever happens to the variables.
38
+ ui_sqb[1] != 7351 ? (
39
+ ui_sqclear(ui_mem, 8, 384);
40
+ i = 0; loop(320, qb[i] = 0; i += 1;);
41
+ // a starting pattern: four-on-the-floor kick, backbeat snare, eighth hats, a triplet fill
42
+ ui_sqadd(0, 0, 6, 110); ui_sqadd(0, 96, 6, 110); ui_sqadd(0, 192, 6, 110); ui_sqadd(0, 288, 6, 110);
43
+ ui_sqadd(1, 96, 6, 105); ui_sqadd(1, 288, 6, 105);
44
+ i = 0; loop(8, ui_sqadd(2, i * 48, 3, i % 2 ? 70 : 95); i += 1;);
45
+ ui_sqadd(3, 320, 4, 90); ui_sqadd(3, 352, 4, 90);
46
+ ui_sqb[1] = 7351;
47
+ );
48
+ inited ? 0 : ( t = 1; lastplay = 0; po = 0; inited = 1; );
49
+ function update() (
50
+ ui_sqb[0] = floor(slider1 * 96 + 0.5);
51
+ gate = slider2 * 0.01;
52
+ jit = slider3 * 0.001 * srate;
53
+ vjit = slider4;
54
+ ch = slider5 - 1;
55
+ nl = max(4, min(8, floor(slider14 + 0.5)));
56
+ );
57
+ // a note on (at due) and its off (after len samples), both or neither
58
+ function sendpair(due, len, st, n, v, lane) local(a, b, q) (
59
+ a = 0; while (a < 64 && qb[a * 5] != 0) ( a += 1; );
60
+ b = a + 1; while (b < 64 && qb[b * 5] != 0) ( b += 1; );
61
+ b < 64 ? (
62
+ q = qb + a * 5; q[0] = due; q[1] = 144 + st; q[2] = n; q[3] = v; q[4] = lane;
63
+ q = qb + b * 5; q[0] = due + len; q[1] = 128 + st; q[2] = n; q[3] = 0; q[4] = lane;
64
+ );
65
+ );
66
+ function hit(lane, c, vel, ofs) local(due, v) (
67
+ due = t + ofs + rand(1) * jit;
68
+ v = floor(vel * (1 + (rand(2) - 1) * vjit) + 0.5);
69
+ sendpair(due, max(0.005 * srate, ui_sqlen(c) * spt * gate), ch, slider(6 + lane), min(127, max(1, v)), lane);
70
+ );
71
+ // the notes of every lane that start in ticks [a, b) of this pass; shift moves a tick to samples from the block start
72
+ function run(a, b, shift) local(l, p, i, s, o) (
73
+ l = 0;
74
+ loop(nl,
75
+ p = ui_sqlane(l);
76
+ p[1] == 0 ? (
77
+ i = 0;
78
+ loop(p[0],
79
+ s = p[2 + i * 3];
80
+ s >= a && s < b ? (
81
+ o = max(0, min(samplesblock - 1, floor((s + shift) * spt)));
82
+ hit(l, p[3 + i * 3], p[4 + i * 3], o);
83
+ );
84
+ i += 1;
85
+ );
86
+ );
87
+ l += 1;
88
+ );
89
+ );
90
+ update();
91
+ ui_help(1, "Loop length in beats. 4 is one bar of 4/4; 3 or 5 give odd-length bars.");
92
+ ui_help(2, "How long each note is held, as a percent of the length you drew.");
93
+ ui_help(3, "Humanize: delays each hit by a random time up to this. Never plays early.");
94
+ ui_help(4, "Humanize: varies each hit's velocity at random by up to this much.");
95
+ ui_help(5, "The MIDI channel the notes are sent on.");
96
+ ui_help(14, "How many rows the pattern has, 4 to 8. Hidden rows keep their notes.");
97
+ ui_help(15, "Moves the playing line to match what you hear. REAPER renders ahead, so the line runs early: raise this until it lands on the beat.");
98
+ ui_boot(2);
99
+
100
+ @slider
101
+ update();
102
+
103
+ @block
104
+ ui_changed() ? update();
105
+ while (midirecv(ofs, m1, m2, m3)) ( midisend(ofs, m1, m2, m3); );
106
+ spt = 60 * srate / max(1, tempo) / 96;
107
+ nt = samplesblock / spt;
108
+ lt = ui_sqb[0];
109
+ play = (play_state & 1) ? 1 : 0;
110
+ play ? (
111
+ tb = beat_position * 96;
112
+ // pressing Play starts the loop at the flag set on the ruler (header slot 2), else on the project's own beat 1
113
+ !lastplay ? po = (ui_sqb[2] > 0 && ui_sqb[2] < lt) ? ui_sqb[2] - (tb - floor(tb / lt) * lt) : 0;
114
+ tb += po;
115
+ w0 = tb - floor(tb / lt) * lt;
116
+ w1 = w0 + nt;
117
+ // the playhead is drawn where the sound is, not where this block starts: one block behind (what is queued to play), plus
118
+ // the Playhead delay knob for the audio interface's own latency
119
+ ph = w0 - (samplesblock / srate * 1000 + slider15) * 0.001 * tempo / 60 * 96;
120
+ ph < 0 ? ph += lt;
121
+ ui_sqph = ph;
122
+ w1 > lt ? (
123
+ run(ceil(w0 - 0.000001), lt, -w0);
124
+ run(0, ceil(w1 - lt - 0.000001), lt - w0);
125
+ ) : run(ceil(w0 - 0.000001), ceil(w1 - 0.000001), -w0);
126
+ ) : ui_sqph = -1;
127
+ // stopping lets go of whatever is sounding
128
+ lastplay && !play ? (
129
+ l = 0; loop(8, midisend(0, 128 + ch, slider(6 + l), 0); ui_kkey(l, 0); l += 1;);
130
+ s = 0; loop(64, qb[s * 5] = 0; s += 1;);
131
+ );
132
+ lastplay = play;
133
+ // a lane's name clicked in the editor: hear it
134
+ while (ui_kpoll()) (
135
+ ui_kv > 0 ? (
136
+ l = 0; loop(nl, slider(6 + l) == ui_kn ? hit(l, 6, ui_kv, 0); l += 1;);
137
+ );
138
+ );
139
+ // send what falls inside this block
140
+ s = 0;
141
+ loop(64,
142
+ q = qb + s * 5;
143
+ q[0] != 0 && q[0] < t + samplesblock ? (
144
+ midisend(max(0, floor(q[0] - t)), q[1], q[2], q[3]);
145
+ q[4] >= 0 ? ui_kkey(q[4], (q[1] & 240) == 144 ? q[3] : 0);
146
+ q[0] = 0;
147
+ );
148
+ s += 1;
149
+ );
150
+ t += samplesblock;
151
+
152
+ @serialize
153
+ file_var(0, ui_adv_open);
154
+ // REAPER's own undo (Cmd+Z) loads saved state back: a drawer restored from then would pop open by itself
155
+ file_avail(0) >= 0 ? ui_adv_open = 0;
156
+ file_mem(0, ui_mem, 8 + 8 * 98);
157
+
158
+ @gfx 520 440
159
+ ui_begin(4, 2) ? (
160
+ ui_tall(3); ui_row(1);
161
+ ui_seq(ui_mem, slider14, 6, "Pattern");
162
+ ui_row(4);
163
+ ui_knob(1, "Beats", 5); ui_knob(2, "Gate", 5); ui_knob(3, "Timing", 4); ui_knob(4, "Velocity", 2);
164
+ ui_section("Advanced") ? (
165
+ ui_row(3); ui_knob(5, "Channel", 5); ui_knob(14, "Lanes", 5); ui_knob(15, "Playhead", 4);
166
+ ui_row(1); ui_padmap(6, slider14, 1, "Note each lane sends");
167
+ );
168
+ ui_end();
169
+ );
@@ -0,0 +1,47 @@
1
+ [
2
+ {
3
+ "name": "Plain",
4
+ "values": {
5
+ "Beats": 4,
6
+ "Gate": 80,
7
+ "Timing": 0,
8
+ "Velocity": 0,
9
+ "Lane 1": 36,
10
+ "Lane 2": 38,
11
+ "Lane 3": 42,
12
+ "Lane 4": 46,
13
+ "Lane 5": 39,
14
+ "Lane 6": 41,
15
+ "Lane 7": 43,
16
+ "Lane 8": 49,
17
+ "Lanes": 4
18
+ }
19
+ },
20
+ {
21
+ "name": "Loose human",
22
+ "values": {
23
+ "Timing": 12,
24
+ "Velocity": 0.15,
25
+ "Gate": 70
26
+ }
27
+ },
28
+ {
29
+ "name": "Three beats",
30
+ "values": {
31
+ "Beats": 3,
32
+ "Gate": 80,
33
+ "Timing": 0,
34
+ "Velocity": 0
35
+ }
36
+ },
37
+ {
38
+ "name": "Chromatic from C2",
39
+ "values": {
40
+ "Lane 1": 36,
41
+ "Lane 2": 37,
42
+ "Lane 3": 38,
43
+ "Lane 4": 39,
44
+ "Gate": 100
45
+ }
46
+ }
47
+ ]
@@ -0,0 +1,76 @@
1
+ # REAPER MIDI editor: mouse and key map
2
+
3
+ What REAPER's own MIDI editor does with the mouse and keyboard, so a note editor in a generated plugin (`ui_seq`, a piano roll, a pad grid) behaves the way a REAPER user expects. **Match this map before inventing a gesture.**
4
+
5
+ **Status of the entries.** *Confirmed* = the plugin's owner stated it or it was checked against REAPER. *Believed* = REAPER's default as remembered, not checked in this repo. Anyone can verify and change the real bindings in REAPER: Preferences > Editing Behavior > Mouse Modifiers > "MIDI editor" contexts (the user's overrides are stored in `reaper-mouse.ini`, sections `MM_CTX_MIDI_*`; only changed bindings are written there, never the defaults). Move an entry to *Confirmed* once checked.
6
+
7
+ JSFX reads modifiers from `mouse_cap`: 1 left button, 2 right button, 4 Cmd (macOS) / Ctrl, 8 Shift, 16 Alt/Option, 32 Ctrl on macOS, 64 Win key.
8
+
9
+ ## Pointer gestures
10
+
11
+ | Gesture | Native MIDI editor | Status | In `ui_seq` |
12
+ | --- | --- | --- | --- |
13
+ | Click empty space | Adds a note (draw/insert) at the grid, length = the grid or the note-length setting | Confirmed | Adds one note in the cell under the pointer (left edge of the cell, not the nearest line), at the brush length, selects it and sounds its lane |
14
+ | Drag on empty space, no modifier | Marquee: selects the notes inside the rectangle | Confirmed | Marquee (Cmd/Ctrl keeps the earlier selection) |
15
+ | Shift-drag on empty space | Creates several notes in a row, one per grid step | Confirmed | Paints a run at the brush length and feel, either direction |
16
+ | Alt/Option-drag | Erases the notes the pointer crosses | Confirmed (owner) | Erases every note crossed |
17
+ | Click a note | Selects it (and deselects the rest) | Believed | Same |
18
+ | Cmd/Ctrl-click a note | Adds it to / removes it from the selection | Believed | Same |
19
+ | Drag a note | Moves it (and the selection) in time and pitch | Believed | Moves the selection in time, and up/down to another lane (a lane is the pitch). Shift-drag changes the pressed note's velocity |
20
+ | Drag a note's right edge | Changes its length | Believed | Same |
21
+ | Cmd/Ctrl while placing or moving | Ignores the grid (free position) | Believed | Same |
22
+ | Double-click a note | Deletes it | Believed | Deletes it |
23
+ | Right-click a note | Deletes it / context menu | Believed (menu in the editor, delete in `ui_seq`) | Deletes it |
24
+ | Mouse wheel over notes | Scrolls (zoom with Cmd/Ctrl) | Believed | Over a note: its length (Cmd/Ctrl = velocity). Over empty space: the brush length |
25
+
26
+ The modifier never changes the note's *value* (length or feel): a plugin keeps those on the brush (buttons and keys), so a Shift-drag that paints four notes always paints four of the same kind.
27
+
28
+ ## Keys
29
+
30
+ | Key | Native | Status | In `ui_seq` |
31
+ | --- | --- | --- | --- |
32
+ | Delete / Backspace | Deletes the selected notes | Confirmed | Same, plus a DELETE n button for hosts that do not forward the key |
33
+ | Cmd/Ctrl+A | Selects all notes | Believed | Same |
34
+ | Cmd/Ctrl+Z, Cmd/Ctrl+Shift+Z | Undo, redo | Believed | Same, 100 steps inside the plugin; UNDO and REDO buttons too, since REAPER may keep the keys |
35
+ | Esc | Clears the selection / leaves a mode | Believed | Leaves the selection alone |
36
+ | 1-4 | Not a native binding | n/a | Brush length 1/4 1/8 1/16 1/32 |
37
+ | Q / W / E | Not a native binding | n/a | Brush feel: straight / triplet / dotted |
38
+
39
+ ## Value widgets (every plugin)
40
+
41
+ These are the toolkit's own gestures (the FabFilter/Serum convention), not REAPER's; they are the same on every widget, so a user learns them once. Source of truth: the header of `reaper/mcp_ui.jsfx-inc` and each widget's comment. Confirmed in the toolkit code.
42
+
43
+ | Widget | Drag | Shift | Wheel | Double-click | Cmd/Ctrl/Alt-click | Other |
44
+ | --- | --- | --- | --- | --- | --- | --- |
45
+ | `ui_knob` | Up/down (200 px = the full range) | 10x finer | Steps (Shift = finer) | Type a value | Reset to default | Hover shows the up/down arrows |
46
+ | `ui_padmap` note cell | Up/down, 9 px per semitone | 10x finer | +/- 1 note | Type a number | Reset | Name large, number small; arrows on hover |
47
+ | `ui_hbar` (header Mix/Output) | Left/right | 10x finer | Steps | Type a value | Reset | |
48
+ | `ui_toggle`, `ui_choice` | n/a | n/a | n/a | n/a | Reset | Click = on/off or next option, right-click = previous option |
49
+ | `ui_fhandle` (band edge) | Left/right, kept between its neighbours | | Nudge | Type Hz | Reset | |
50
+ | `ui_fthresh` (threshold line) | Hovered band up/down = its threshold | Moves the band's gain instead | Ratio | Type a threshold | Reset | A click selects the band |
51
+ | `ui_fband` (level line) | Hovered band up/down = its level | Fine steps | Small steps | Type a value | Reset | A click selects the band |
52
+ | `ui_keyboard`, `ui_pads` | Press plays (pads: lower = harder), drag across moves the hit | n/a | n/a | n/a | n/a | The plugin sounds the note itself via `ui_kpoll()` |
53
+ | `ui_seq` lane name | n/a | n/a | n/a | n/a | Cmd/Ctrl-click mutes the lane | Click auditions the lane's note |
54
+
55
+ Rules that go with them:
56
+
57
+ 1. **Dragging up/down changes a value, always.** A knob, a note cell, a threshold and a velocity all follow it: up = more. Left/right is for position (time, frequency) and for horizontal bars.
58
+ 2. **Hover must say so.** Any control you drag or scroll shows the up/down arrows (`ui_chev`) while the mouse is over it; this is the standard for every new widget.
59
+ 3. **Shift = finer** on every continuous drag (10x), except where Shift already means a different tool (paint in `ui_seq`, gain on `ui_fthresh`); say so in the hint.
60
+ 4. **Double-click types a value, a modifier-click resets** (Cmd, Ctrl or Alt), on every widget that holds a slider.
61
+ 5. **A hint line or tooltip names the gesture while it runs** ("VELOCITY 96", "LENGTH 1/8").
62
+
63
+ **Keys need the host's setting.** REAPER keeps its own shortcuts (Cmd+Z is the project's undo) unless the FX window's "+" menu has **"Send all keyboard input to plug-in"** ticked (confirmed: with it on, the plugin's Cmd+Z / Cmd+Shift+Z work). Never rely on a key alone: give every key action a visible button (UNDO, REDO, DELETE) and say in the hint what the setting does.
64
+
65
+ ## Rules for a plugin editor
66
+
67
+ 0. **Selection decides what an adjustment touches.** Moving, velocity, length and scroll act on every selected note when the one you grab is selected, and on that note alone when it is not.
68
+
69
+ 1. **No modifier = the plain gesture; a modifier = a different tool, never a different value.** Selection, paint, erase and off-grid placement are tools; length and feel are the brush.
70
+ 2. **A drag on empty space selects.** Creating notes by dragging needs Shift (paint), as in REAPER. A plain click still adds one.
71
+ 3. **Delete and Backspace remove the selection**, and a visible button does too, since a JSFX window does not always receive keys.
72
+ 4. **Show the active tool in a hint line** when the pointer is over the grid, and name the gesture while it runs ("ERASING NOTES", "PAINTING 1/16 NOTES").
73
+ 5. **Never bind a feel or value to Shift/Alt**, they belong to paint and erase.
74
+ 6. Keep `Cmd/Ctrl` for "more": add to the selection, or ignore the grid.
75
+
76
+ When REAPER's behaviour is in doubt, check it in the real MIDI editor (or the Mouse Modifiers preferences) and record the answer here.
@@ -49,6 +49,9 @@ Every widget is one block, label above, control, value below, sized the same acr
49
49
  | `ui_grmeter(n, "Label")` | `n` (1-8) gain-reduction bars hanging from the top, amber from 6 dB, red from 12; a click selects the band | `ui_gr(k, db)` per band from `@block` (db 0 or more) |
50
50
  | `ui_transfer(thr_idx, ratio_idx, knee_db)` | a compressor transfer curve that follows the threshold and ratio sliders (the selected band's, `thr_idx + ui_fsel`, with a graph), with a live level dot | `ui_glevel(db)` from `@block` |
51
51
  | `ui_keyboard(lo, hi, "Label")` | piano keys `lo`..`hi` (MIDI notes, 21-108 is the full 88), short and full width: put it as the last core row, below the knobs. **Playable**: press a key to play it (higher up the key = softer), drag across keys for a glissando, release to stop | `ui_kkey(note, vel)` on note on, `ui_kkey(note, 0)` on note off, for notes the plugin hears; the notes the user plays arrive in `@block` through `while (ui_kpoll()) ( ... )`: each 1 means `ui_kn` is a note and `ui_kv` its velocity (0 = off) |
52
+ | `ui_pads(first, cols, rows, "Label")` | a bank of drum pads, at most 16 (4x4 is the MPC shape), pad 1 bottom-left on MIDI note `first` (36 = GM kick), counting right then up; give the row height with `ui_tall(2)`. **Playable**: press = hit (lower on the pad = harder), drag across pads moves the hit, release lets go. The typed keys `zxcv / asdf / qwer / 1234` strike them too (Shift = hard; only with the FX window's "Send all keyboard input to plug-in" on and the window focused), shown in each pad's corner | the same as `ui_keyboard`: `ui_kkey(note, vel)` for notes the plugin hears (lights the pad), and `while (ui_kpoll()) ( ... )` for the pads the user strikes. A key hit lets go 0.12 s later, so treat pads as one-shots |
53
+ | `ui_padmap(first_idx, cols, rows, "Label")` | which MIDI note each pad sends, in the same grid as `ui_pads` (one slider per pad from `first_idx`, in pad order, 0-127): each cell shows the note name (C4 = 60) large and its number small. Drag a cell up/down (Shift = fine), scroll (Shift = an octave), double-click to type, Cmd/Ctrl/Alt-click resets. Put it in Advanced (`ui_tall(2); ui_row(1);`) and hide the sliders from REAPER's panel with a leading `-` in their labels | none: read `slider(first_idx + pad)` in the plugin |
54
+ | `ui_seq(buf, lanes, note_idx, "Label")` | a pattern editor: a loop of notes in ticks (96 per quarter) on 1-8 lanes, in a tall row (`ui_tall(3)`). `buf` is the plugin's buffer at `ui_mem` (800 numbers: `buf[0]` the loop length in ticks, then per lane a count, a mute flag and up to 32 notes of start tick, length code and velocity); initialise it once with `ui_sqclear(buf, lanes, ticks)` and add notes with `ui_sqadd(lane, tick, code, vel)` (code = value * 3 + feel: value 0..3 = 1/4 1/8 1/16 1/32, feel 0 straight, 1 triplet, 2 dotted; `ui_sqlen(code)` = ticks). `note_idx` = the first of `lanes` sliders holding each lane's MIDI note, shown beside the lane (click = hear it, Cmd/Ctrl-click = mute). The brush (length buttons 1/4..1/32 or keys 1-4, feel buttons or q / w / e) sets what a click adds, and no modifier changes it; **Cmd/Ctrl** = off the grid; like REAPER's MIDI editor: a click adds a note in the cell under the pointer (and sounds its lane), a drag makes a selection, **Shift-drag paints a run** of notes at the brush's length, Delete/Backspace (or the DELETE button) removes the selection, Cmd/Ctrl+A selects all (the length is only set by the buttons, keys 1-4 or scroll). On a note: Cmd/Ctrl-click adds a note to the selection, drag = move the selection (sideways in time, up/down to another lane), **Shift-drag = velocity**, edge drag = length and scroll = length/velocity, all for every selected note, drag the right edge = resize, scroll = length (Cmd/Ctrl-scroll = velocity), right-click or double-click deletes, **Alt/Option-drag erases** every note the pointer crosses. Cmd/Ctrl+Z undoes and Cmd/Ctrl+Shift+Z redoes (100 steps, kept in plugin memory, not saved; UNDO and REDO buttons in the footer too), and moving snaps to the brush's grid. Clear (asks twice) is in the footer. **Leave `buf + 1200` and the 158400 numbers after it free** for the undo history | in `@block` set `ui_sqph` (the playhead in loop ticks, -1 stopped), read the notes from the buffer, and light a lane with `ui_kkey(lane, vel)`; clicking a lane's name queues its note for `while (ui_kpoll())`. Save with `@serialize`: `file_var(0, ui_adv_open); file_avail(0) >= 0 ? ui_adv_open = 0; file_mem(0, ui_mem, 8 + lanes * 98);` |
52
55
  | `ui_tall(span)` | the next `ui_row` is `span` times as tall (a graph needs height); knobs in it keep their size | none |
53
56
 
54
57
  Use `ui_boot(2)` in a plugin with these feeds: it redraws only when a feed, a control or the window
@@ -93,12 +96,17 @@ a resize or an accent change. The toolkit also hides REAPER's slider panel
93
96
  above the UI (`ui_hide_sliders`): the sliders stay real parameters (automation, MIDI learn, the
94
97
  Param menu, presets).
95
98
 
99
+ ## Knob help
100
+
101
+ `ui_help(slider_idx, "one or two sentences")`, called once in `@init`, gives that knob a tooltip that appears when the mouse rests on it for half a second (wrapped at about 44 characters, at most four lines; stored in string slot 900 + idx, so leave those numbered slots alone). Give one to every knob whose name alone does not say what it does (a humanize amount, a delay in ms, a hidden count). The Step Sequencer example shows it.
102
+
96
103
  ## State and @init
97
104
 
98
105
  REAPER re-runs `@init` whenever playback starts. The toolkit sets its UI state once (guarded by
99
106
  `ui_ready`), so pressing Play never closes the drawer. Do the same in plugin code: never assign
100
- `ui_adv_open` (the lint warns, `ui-state-reset`); `@serialize`'s `file_var(0, ui_adv_open)`
101
- restores it with the project.
107
+ `ui_adv_open` (the lint warns, `ui-state-reset`); `@serialize`'s `file_var(0, ui_adv_open)` is
108
+ required, but follow it with `file_avail(0) >= 0 ? ui_adv_open = 0;` when the plugin also saves data: REAPER's own undo
109
+ (Cmd+Z) loads saved state back, and a restored drawer would pop open by itself.
102
110
 
103
111
  ## Rules the lint enforces
104
112