@mthines/reaper-mcp 0.78.1 → 0.79.0-beta.96.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.
@@ -0,0 +1,205 @@
1
+ ---
2
+ name: make-plugin
3
+ description: >
4
+ Makes the user a REAPER plugin for a specific need, end to end: reduces the request to the
5
+ smallest plugin that does it, writes it as a self-contained JSFX with the shared UI toolkit
6
+ (a small core view, advanced controls behind a section), loads it on a scratch track, proves
7
+ by measurement that it does what was asked, and iterates. The result is just a plugin: it
8
+ works without the bridge, the MCP server or a browser. Use when the user asks to "make/create/
9
+ build a plugin that...", wants an effect that does not exist ("randomly mutate my samples and
10
+ add reverb", "a trance gate", "keep my bass mono"), or to change a plugin made earlier.
11
+ Triggers on "/make-plugin".
12
+ argument-hint: '[what the plugin should do | update <plugin>: <what to change>]'
13
+ license: MIT
14
+ metadata:
15
+ author: mthines
16
+ version: '1.2.0'
17
+ workflow_type: applied
18
+ tags: [plugins, jsfx, dsp, ui, reaper, live-verification]
19
+ ---
20
+
21
+ # /make-plugin
22
+
23
+ Makes a plugin the user can keep: one `.jsfx` file in `Effects/reaper-mcp-generated/` that
24
+ REAPER loads like any other plugin. Everything it needs is inside the file, so it keeps working
25
+ on a machine with no reaper-mcp. This skill, `write_jsfx` and the bridge are only how it gets
26
+ made.
27
+
28
+ **Three principles, in this order of authority when they conflict:**
29
+
30
+ 1. **Simple.** The smallest plugin that satisfies the request. Every control and every line of
31
+ DSP has to earn its place. A plugin that does one thing well beats one that does five.
32
+ 2. **Fast.** It runs in the audio thread. No work per sample that can be done per block or per
33
+ change; nothing allocated while running; the UI redraws only when something changed.
34
+ `reference/dsp-perf.md` is the checklist.
35
+ 3. **Advanced controls by progressive disclosure.** The core view holds what is changed in most
36
+ uses (3-5 controls, a level meter counts as one) and fills the window. Everything else sits
37
+ in an **Advanced** drawer that slides up over the core view (the core never moves or
38
+ shrinks). The lint enforces the counts.
39
+
40
+ ## Rules that hold the whole way
41
+
42
+ - **Scratch track only.** Never add the plugin to the user's tracks, and never change their
43
+ tracks, FX, selection or transport. Name it `[MCP] make-plugin <slug>`, add it at the end,
44
+ and delete it **by exact name** when you are done, even when a step failed. Track indices
45
+ shift while the user works: look the track up by name before every write.
46
+ - **No playback of the user's material.** Test with an item on the scratch track, rendered
47
+ offline (`analyze_track_offline`, `verify_edit`); do not start the transport.
48
+ - **Ask at most one question**, and only when the request cannot be reduced to a plugin
49
+ without it. Otherwise decide, say what you decided, and build.
50
+ - **The plugin has no dependencies**: no `gmem`, no bridge calls, no telemetry. The lint
51
+ refuses `gmem`.
52
+ - **Never renumber a slider that has shipped.** Saved automation points at slider numbers.
53
+ New controls go at the end. `write_jsfx` refuses a changed range or a removed slider unless
54
+ `breaking: true`.
55
+ - **Do not commit** anything unless the user asks.
56
+
57
+ ## Instructions
58
+
59
+ ### Step 0: Load what earlier runs learned
60
+
61
+ Read the LoreKit lessons (`memory.list` in `project::reaper-mcp`, tag `loop::make-plugin-lessons`,
62
+ at most 5). They are considerations, not rules. Continue without them if LoreKit is not
63
+ connected, and say so in the report.
64
+
65
+ ### Step 1: Reduce the request to a spec
66
+
67
+ In two or three lines, write down and show the user:
68
+
69
+ - **What it does**, in one sentence of DSP ("on each hit, replays a short mutated grain through
70
+ a reverb").
71
+ - **Core controls** (3-5): what a person changes in most uses. Always include a way to set the
72
+ amount (Mix, or the effect's own amount) and, for anything that changes level, Output.
73
+ - **Advanced controls** (0-8): set-and-forget, character, safety. If nothing qualifies, there is
74
+ no Advanced section.
75
+ - **Suggested presets** (3-5): settings that teach what the plugin is for, each named for its
76
+ intent in 2-3 words ("Ghost tails", "Crushed drums", "Tight low end"), values picked from what
77
+ the user asked for. No "Default"/"Init" preset: REAPER has one.
78
+
79
+ Cut before you add. If a control could be a sensible fixed value, make it one. Pick the closest
80
+ example in `examples/` (`mutate-verb.jsfx` random and granular plus reverb, `tape-sat.jsfx`
81
+ nonlinear plus tilt EQ, `width-bass-mono.jsfx` linear stereo plus meter) and read it. Each has its
82
+ suggested presets beside it (`<name>.presets.json`): the shape `write_jsfx` takes.
83
+
84
+ ### Step 2: Write the source
85
+
86
+ Read `reference/toolkit.md` (the UI API) and `reference/dsp-perf.md`. Start from the closest
87
+ example and change what the spec changes. The shape is always:
88
+
89
+ - header: `desc:Name`, **unnamed** sliders (`slider1:0.5<0,1,0.01>Label`), then `@init`,
90
+ `@slider`, `@block`, `@sample`, `@gfx W H`.
91
+ - `@init` ends with `ui_boot(animated)` (1 when the UI has a meter); allocate buffers from
92
+ `ui_mem`; compute coefficients in `update()`, called from `@init`, `@slider` and
93
+ `@block: ui_changed() ? update();`.
94
+ - `@gfx` draws the core row(s), then `ui_section("Advanced") ? ( ... )` for the rest.
95
+ - Do not write the toolkit: `write_jsfx` inlines it.
96
+ - Never assign `ui_adv_open` (or any `ui_` state) in plugin code: REAPER re-runs `@init` when
97
+ playback starts, so the Advanced drawer would snap shut on Play (lint `ui-state-reset`).
98
+ - `desc:` is the plain name: do not add `(reaper-mcp)` yourself, `write_jsfx` appends it.
99
+ - Never set the accent (`ui_cAccent`, `ui_theme`) or read keys/mouse yourself: the toolkit owns
100
+ gestures (double-click types a value, Cmd/Ctrl/Alt-click resets, Shift-drag is fine).
101
+
102
+ ### Step 3: Write it
103
+
104
+ Call `write_jsfx` with `name`, `source`, a one-line `request` (a comment in the file, never
105
+ sent anywhere or shown) and `presets` (the 3-5 from the spec: `[{name, values: {"Mix": 0.3, "Size":
106
+ 0.8}}]`, keyed by slider label or index, in the slider's own units; sliders left out take their
107
+ default). A lint refusal lists every problem with its rule id and line: fix them all and call
108
+ again. A preset value outside its slider's range or step refuses the whole call too. Nothing is
109
+ written until everything passes. The presets land in the plugin's preset dropdown in REAPER;
110
+ presets the user saved there are never touched. Check one: `set_fx_preset` then
111
+ `get_fx_parameters` (raw values).
112
+
113
+ **Colour.** Each plugin gets its own accent from its name. When the user asks for a colour
114
+ ("make it orange", "#ff8800"), call `write_jsfx` again with the same `source`, `overwrite: true`
115
+ and `accent: "orange"` (names: blue, teal, green, amber, orange, red, pink, violet; or `#rrggbb`).
116
+ Do not touch the source for a colour. Later writes without `accent` keep it; `accent: "auto"`
117
+ goes back to the name's colour.
118
+
119
+ ### Step 4: Load it
120
+
121
+ 1. Add the scratch track (`add_track`, name `[MCP] make-plugin <slug>`) and an item with a test
122
+ signal on it. Generate one (a few seconds of band-limited noise bursts and a sine) with a
123
+ short `node` script into the scratchpad as a WAV and `insert_audio_file` it, or use the
124
+ user's own audio file if they gave one.
125
+ 2. `add_fx` with the `fxName` that `write_jsfx` returned, then `get_fx_parameters`: the declared
126
+ sliders are all there (REAPER adds Bypass, Wet and Delta after yours).
127
+ 3. **A loaded plugin does not recompile when its file changes.** After every `write_jsfx`:
128
+ `remove_fx`, then `add_fx` again.
129
+
130
+ ### Step 5: Prove it by measurement
131
+
132
+ JSFX code does not run until audio is processed, so a compile error shows up as a plugin that
133
+ **does nothing**, not as an error. Never conclude "it loaded" from the parameter list alone.
134
+ Measure the track offline (`analyze_track_offline`, `verify_edit`, `measure_masking`,
135
+ `analyze_stereo_bands`, `analyze_loudness_curve`, as the plugin calls for), with and without the
136
+ plugin (`set_fx_enabled`):
137
+
138
+ 1. **It runs.** At its default settings the output differs from the bypassed output
139
+ (`verify_edit` with `expect: "changed"`, or a loudness/spectrum difference). Identical output
140
+ means the plugin did not compile: look for an unbalanced parenthesis, an undefined function,
141
+ a `1e9` literal, `local()` at the top of a section, then re-add it (Step 4.3).
142
+ 2. **Transparent where it should be.** With the amount at 0 (Mix 0, Width 1...) the output is
143
+ identical to bypass (`verify_edit`, `expect: "identical"`).
144
+ 3. **Safe.** At defaults the true peak stays at or below 0 dBTP; no silence, no NaN.
145
+ 4. **Does what was asked.** One check chosen from the request: a reverb tail after the last
146
+ note (`analyze_loudness_curve`), correlation near 1 below the crossover
147
+ (`analyze_stereo_bands`), added harmonics for a saturator (`analyze_track_offline` band
148
+ balance), a gate's rhythm (`detect_transients`).
149
+ 5. **Extremes.** Each control at its minimum and maximum: no blow-up (peak under +6 dBFS),
150
+ no stuck silence. Use `set_fx_parameter` (values are normalized 0-1).
151
+
152
+ Fix the **plugin**, not the check. At most 4 rounds; after that stop and tell the user what
153
+ still fails.
154
+
155
+ ### Step 6: Clean up
156
+
157
+ Delete the scratch track by exact name and confirm it is gone (`list_tracks` with
158
+ `nameContains`). The plugin file stays: it is the deliverable.
159
+
160
+ ### Step 7: Report
161
+
162
+ Call `report_plugin_build` (outcome, rounds, checks passed/failed, the example you started
163
+ from, `scratchTag` = the slug in your track name), then one short message: the plugin's name
164
+ and where to find it (FX browser, folder **reaper-mcp-generated**), the core and advanced
165
+ controls in plain words, what you measured (with the numbers), and what you could not check.
166
+ It is a plain REAPER plugin: say so, and that the UI draws inside its own window.
167
+
168
+ ### Step 8: Lessons
169
+
170
+ Save each non-obvious thing you hit as a LoreKit lesson in `project::reaper-mcp`, tag
171
+ `loop::make-plugin-lessons`, phrased as an observation. Nothing that is already in this file,
172
+ the toolkit or the code.
173
+
174
+ ## Updating a plugin
175
+
176
+ `Read` the file, change the plugin part only (the toolkit block is replaced for you), and pass
177
+ the whole file back to `write_jsfx` with `overwrite: true`. Keep every existing slider's number,
178
+ range and options; add new sliders at the end. The old version is kept outside `Effects/`.
179
+ Pass `presets` again when they should change (without it the preset file is left as it is; with
180
+ `breaking: true` and no `presets`, the old suggested presets are removed).
181
+ Then Steps 4-8.
182
+
183
+ ## Definition of done
184
+
185
+ - [ ] Core view 3-5 widgets, Advanced at most 8, nothing the request did not need
186
+ - [ ] `write_jsfx` accepted it (lint clean) with 3-5 suggested presets
187
+ - [ ] Measured: runs, transparent at zero, safe at defaults, does the one thing, extremes
188
+ - [ ] Scratch track deleted by name and confirmed gone; the user's tracks untouched
189
+ - [ ] `report_plugin_build` called; lessons saved (or the report says why not)
190
+
191
+ ## Known gotchas (seed lessons)
192
+
193
+ - JSFX code does not run until audio is processed. A slider set in `@init`/`@slider`/`@block`
194
+ reads back unchanged through `get_fx_parameters` (probed live, every variant), so there is no
195
+ way to read a "compiled" flag: the audio check in Step 5 is the compile check.
196
+ - `1e9`-style literals make EEL2 reject the whole plugin and run no code. Write `1000000000`.
197
+ - `local()` is only valid inside a function, never at the top of `@sample`/`@block`.
198
+ - Named sliders (`slider1:g=0<...`) do not keep their value in `sliderN`: always unnamed.
199
+ - Memory below `ui_mem` (1024) belongs to the toolkit: allocate from it.
200
+ - `@init` runs again whenever playback starts (and on a sample-rate change). Anything it assigns
201
+ is reset on Play: keep UI and interaction state out of unguarded `@init` assignments.
202
+ - `rand()` cannot be seeded: use the seeded generator in `examples/mutate-verb.jsfx` when a
203
+ result must be repeatable.
204
+ - REAPER names the second plugin with the same `desc` with its path appended
205
+ (`JS: Name [reaper-mcp-generated/x.jsfx]`): do not read that as a compile signal.
@@ -0,0 +1,148 @@
1
+ desc:Mutate Verb
2
+ // accent: violet
3
+ import mcp_ui.jsfx-inc
4
+
5
+ // Every hit that comes in is answered a moment later by a mutated afterimage of itself: a short grain
6
+ // of what was just played, at a random pitch, maybe reversed, through a random low-pass, thrown into a
7
+ // reverb. Core view: Mutate, Size, Mix, Output. Everything else is under Advanced.
8
+
9
+ slider1:0.5<0,1,0.01>Mutate
10
+ slider2:0.5<0,1,0.01>Size
11
+ slider3:0.3<0,1,0.01>Mix
12
+ slider4:0<-24,12,0.1>Output
13
+ slider5:1<1,999,1>Seed
14
+ slider6:7<0,12,1>Pitch range
15
+ slider7:0.3<0,1,0.01>Reverse
16
+ slider8:0.6<0,1,0.01>Bright
17
+ slider9:10<0,100,1>Pre-delay
18
+ slider10:0.4<0,1,0.01>Damping
19
+
20
+ @init
21
+ ui_ptr = ui_mem;
22
+ function alloc(n) ( ui_ptr += n; ui_ptr - n; );
23
+
24
+ // capture buffer (the grain reads from it), 0.6 s per channel
25
+ bufn = floor(srate * 0.6);
26
+ bufl = alloc(bufn); bufr = alloc(bufn);
27
+ memset(bufl, 0, bufn); memset(bufr, 0, bufn);
28
+ wpos = 0;
29
+ glen = floor(srate * 0.25); ginv = 1 / glen;
30
+
31
+ // pre-delay line
32
+ plen = floor(srate * 0.1) + 2; pdbuf = alloc(plen); memset(pdbuf, 0, plen); ppos = 0;
33
+
34
+ // reverb: 4 combs + 2 all-passes per side (right side a little longer), lengths from 44.1 kHz
35
+ k = srate / 44100;
36
+ tl = alloc(4); tl[0] = 1116; tl[1] = 1188; tl[2] = 1277; tl[3] = 1356;
37
+ ta = alloc(2); ta[0] = 556; ta[1] = 441;
38
+ cs = alloc(8 * 4); aps = alloc(4 * 3);
39
+ i = 0;
40
+ loop(8,
41
+ len = floor((tl[i % 4] + (i >= 4 ? 23 : 0)) * k);
42
+ p = cs + i * 4; p[0] = alloc(len); memset(p[0], 0, len); p[1] = len; p[2] = 0; p[3] = 0;
43
+ i += 1;
44
+ );
45
+ i = 0;
46
+ loop(4,
47
+ len = floor((ta[i % 2] + (i >= 2 ? 23 : 0)) * k);
48
+ p = aps + i * 3; p[0] = alloc(len); memset(p[0], 0, len); p[1] = len; p[2] = 0;
49
+ i += 1;
50
+ );
51
+
52
+ function rnd() ( rs = (rs * 1664525 + 1013904223) % 4294967296; rs / 4294967296; );
53
+
54
+ function comb(i, x) local(p, b, l, pos, y, lp) (
55
+ p = cs + i * 4; b = p[0]; l = p[1]; pos = p[2];
56
+ y = b[pos];
57
+ lp = p[3] = y * (1 - damp) + p[3] * damp;
58
+ b[pos] = x + lp * fb;
59
+ pos += 1; pos >= l ? pos = 0; p[2] = pos;
60
+ y;
61
+ );
62
+
63
+ function allpass(i, x) local(p, b, l, pos, z) (
64
+ p = aps + i * 3; b = p[0]; l = p[1]; pos = p[2];
65
+ z = b[pos]; b[pos] = x + z * 0.5;
66
+ pos += 1; pos >= l ? pos = 0; p[2] = pos;
67
+ z - x;
68
+ );
69
+
70
+ function start_grain() local(semi) (
71
+ semi = (rnd() * 2 - 1) * prange;
72
+ grate = 2 ^ (semi / 12);
73
+ grev = rnd() < rev;
74
+ gstart = wpos - glen; gstart < 0 ? gstart += bufn;
75
+ ga = 1 - exp(-2 * $pi * (300 + (bright * 0.6 + rnd() * 0.4) * 12000) / srate);
76
+ gp = 0; gon = 1; gfl = 0; gfr = 0;
77
+ );
78
+
79
+ // coefficients: here, never per sample
80
+ function update() (
81
+ mutate = slider1;
82
+ fb = 0.7 + slider2 * 0.28;
83
+ mix = slider3;
84
+ gain = 10 ^ (slider4 / 20);
85
+ prange = slider6; rev = slider7; bright = slider8;
86
+ pdn = floor(slider9 * 0.001 * srate);
87
+ damp = 0.05 + slider10 * 0.85;
88
+ glevel = 0.5 + 0.5 * mutate;
89
+ slider5 != lastseed ? ( lastseed = slider5; rs = slider5 * 7919; );
90
+ );
91
+ update();
92
+ ui_boot(0);
93
+
94
+ @slider
95
+ update();
96
+
97
+ @block
98
+ ui_changed() ? update();
99
+
100
+ @sample
101
+ // a hit: the fast envelope jumps over the slow one
102
+ a = max(abs(spl0), abs(spl1));
103
+ ef += (a - ef) * 0.01;
104
+ es += (a - es) * 0.0003;
105
+ cool > 0 ? cool -= 1;
106
+ (ef > es * 2.5 && ef > 0.02 && cool <= 0 && pend <= 0 && !gon) ? (
107
+ cool = srate * 0.12;
108
+ rnd() < mutate ? pend = glen;
109
+ );
110
+ pend > 0 ? ( pend -= 1; pend <= 0 ? start_grain(); );
111
+
112
+ bufl[wpos] = spl0; bufr[wpos] = spl1;
113
+
114
+ gl = 0; gr = 0;
115
+ gon ? (
116
+ idx = gstart + (grev ? glen - gp : gp); idx >= bufn ? idx -= bufn;
117
+ i0 = min(floor(idx), bufn - 1); f = idx - i0;
118
+ i1 = i0 + 1; i1 >= bufn ? i1 = 0;
119
+ w = sin($pi * gp * ginv) * glevel;
120
+ gfl += ((bufl[i0] + (bufl[i1] - bufl[i0]) * f) - gfl) * ga;
121
+ gfr += ((bufr[i0] + (bufr[i1] - bufr[i0]) * f) - gfr) * ga;
122
+ gl = gfl * w; gr = gfr * w;
123
+ gp += grate; gp >= glen ? gon = 0;
124
+ );
125
+ wpos += 1; wpos >= bufn ? wpos = 0;
126
+
127
+ dl = spl0 + gl; dr = spl1 + gr;
128
+ rin = (dl + dr) * 0.5;
129
+ pdbuf[ppos] = rin;
130
+ ridx = ppos - pdn; ridx < 0 ? ridx += plen;
131
+ rin = pdbuf[ridx] * 0.015;
132
+ ppos += 1; ppos >= plen ? ppos = 0;
133
+
134
+ wl = allpass(0, allpass(1, comb(0, rin) + comb(1, rin) + comb(2, rin) + comb(3, rin)));
135
+ wr = allpass(2, allpass(3, comb(4, rin) + comb(5, rin) + comb(6, rin) + comb(7, rin)));
136
+ spl0 = (dl * (1 - mix) + wl * 3 * mix) * gain;
137
+ spl1 = (dr * (1 - mix) + wr * 3 * mix) * gain;
138
+
139
+ @gfx 380 250
140
+ ui_begin(1, 2) ? (
141
+ ui_row(4);
142
+ ui_knob(1, "Mutate", 2); ui_knob(2, "Size", 2); ui_knob(3, "Mix", 2); ui_knob(4, "Output", 1);
143
+ ui_section("Advanced") ? (
144
+ ui_row(3); ui_knob(5, "Seed", 5); ui_knob(6, "Pitch range", 5); ui_knob(7, "Reverse", 2);
145
+ ui_row(3); ui_knob(8, "Bright", 2); ui_knob(9, "Pre-delay", 4); ui_knob(10, "Damping", 2);
146
+ );
147
+ ui_end();
148
+ );
@@ -0,0 +1,6 @@
1
+ [
2
+ { "name": "Subtle glue", "values": { "Mutate": 0.15, "Size": 0.35, "Mix": 0.15, "Pitch range": 0, "Reverse": 0, "Bright": 0.5, "Pre-delay": 15, "Damping": 0.5 } },
3
+ { "name": "Ghost tails", "values": { "Mutate": 0.6, "Size": 0.85, "Mix": 0.4, "Output": -2, "Pitch range": 5, "Reverse": 0.6, "Bright": 0.35, "Pre-delay": 40, "Damping": 0.6 } },
4
+ { "name": "Broken tape", "values": { "Mutate": 0.9, "Size": 0.5, "Mix": 0.5, "Output": -3, "Pitch range": 12, "Reverse": 0.4, "Bright": 0.8, "Pre-delay": 5, "Damping": 0.2 } },
5
+ { "name": "Dark room", "values": { "Mutate": 0.3, "Size": 0.6, "Mix": 0.3, "Pitch range": 3, "Reverse": 0.1, "Bright": 0.15, "Pre-delay": 20, "Damping": 0.85 } }
6
+ ]
@@ -0,0 +1,86 @@
1
+ desc:Tape Sat
2
+ // accent: orange
3
+ import mcp_ui.jsfx-inc
4
+
5
+ // A soft saturator with a tilt EQ after it. Core view: Drive, Tone, Mix, Output. Advanced: bias
6
+ // (asymmetry), wow and flutter (a wobbling short delay), and a cheap 2x oversampling switch.
7
+
8
+ slider1:6<0,24,0.1>Drive
9
+ slider2:0<-1,1,0.01>Tone
10
+ slider3:1<0,1,0.01>Mix
11
+ slider4:0<-24,12,0.1>Output
12
+ slider5:0<0,0.5,0.01>Bias
13
+ slider6:0<0,1,0.01>Wow
14
+ slider7:0<0,1,0.01>Flutter
15
+ slider8:0<0,1,1>2x
16
+
17
+ @init
18
+ ui_ptr = ui_mem;
19
+ function alloc(n) ( ui_ptr += n; ui_ptr - n; );
20
+ dn = floor(srate * 0.02) + 4; // 20 ms modulation delay
21
+ dl = alloc(dn); dr = alloc(dn); memset(dl, 0, dn); memset(dr, 0, dn); dpos = 0;
22
+ wph = 0; fph = 0;
23
+
24
+ // rational soft clip, close to tanh and cheap
25
+ function sat(x) ( x = min(3, max(-3, x)); x * (27 + x * x) / (27 + 9 * x * x); );
26
+
27
+ function update() (
28
+ drive = 10 ^ (slider1 / 20);
29
+ tilt = slider2 * 0.5;
30
+ mix = slider3;
31
+ gain = 10 ^ (slider4 / 20);
32
+ bias = slider5;
33
+ wow = slider6 * 0.003 * srate; // up to 3 ms
34
+ flut = slider7 * 0.0004 * srate; // up to 0.4 ms
35
+ wstep = 0.6 / srate; fstep = 7 / srate;
36
+ lpa = 1 - exp(-2 * $pi * 1000 / srate); // tilt pivot, 1 kHz
37
+ os = slider8 > 0.5;
38
+ comp = 1 / sat(drive * 0.5); // keeps the level near unity as drive rises
39
+ );
40
+ update();
41
+ ui_boot(0);
42
+
43
+ @slider
44
+ update();
45
+
46
+ @block
47
+ ui_changed() ? update();
48
+
49
+ @sample
50
+ // wow and flutter: read the input back through a delay that wobbles
51
+ dl[dpos] = spl0; dr[dpos] = spl1;
52
+ wph += wstep; wph >= 1 ? wph -= 1; fph += fstep; fph >= 1 ? fph -= 1;
53
+ d = 2 + wow * (0.5 + 0.5 * sin(2 * $pi * wph)) + flut * (0.5 + 0.5 * sin(2 * $pi * fph));
54
+ ri = dpos - d; ri < 0 ? ri += dn;
55
+ i0 = floor(ri); f = ri - i0; i1 = i0 + 1; i1 >= dn ? i1 = 0;
56
+ xl = dl[i0] + (dl[i1] - dl[i0]) * f;
57
+ xr = dr[i0] + (dr[i1] - dr[i0]) * f;
58
+ dpos += 1; dpos >= dn ? dpos = 0;
59
+
60
+ // saturate, with a second pass on the midpoint when 2x is on
61
+ yl = sat(xl * drive + bias) - sat(bias);
62
+ yr = sat(xr * drive + bias) - sat(bias);
63
+ os ? (
64
+ yl = (yl + sat((xl + pxl) * 0.5 * drive + bias) - sat(bias)) * 0.5;
65
+ yr = (yr + sat((xr + pxr) * 0.5 * drive + bias) - sat(bias)) * 0.5;
66
+ );
67
+ pxl = xl; pxr = xr;
68
+ yl *= comp; yr *= comp;
69
+
70
+ // tilt: low part up and high part down, or the other way round
71
+ lowl += (yl - lowl) * lpa; lowr += (yr - lowr) * lpa;
72
+ yl = lowl * (1 - tilt) + (yl - lowl) * (1 + tilt);
73
+ yr = lowr * (1 - tilt) + (yr - lowr) * (1 + tilt);
74
+
75
+ spl0 = (spl0 * (1 - mix) + yl * mix) * gain;
76
+ spl1 = (spl1 * (1 - mix) + yr * mix) * gain;
77
+
78
+ @gfx 340 250
79
+ ui_begin(1, 1) ? (
80
+ ui_row(4);
81
+ ui_knob(1, "Drive", 1); ui_knob(2, "Tone", 0); ui_knob(3, "Mix", 2); ui_knob(4, "Output", 1);
82
+ ui_section("Advanced") ? (
83
+ ui_row(4); ui_knob(5, "Bias", 0); ui_knob(6, "Wow", 2); ui_knob(7, "Flutter", 2); ui_toggle(8, "2x");
84
+ );
85
+ ui_end();
86
+ );
@@ -0,0 +1,6 @@
1
+ [
2
+ { "name": "Warm bus", "values": { "Drive": 3, "Tone": -0.15, "Mix": 1, "Output": -1, "Bias": 0.05, "Wow": 0.05, "Flutter": 0.05, "2x": 1 } },
3
+ { "name": "Crushed drums", "values": { "Drive": 18, "Tone": 0.2, "Mix": 0.6, "Output": -8, "Bias": 0.15, "2x": 1 } },
4
+ { "name": "Old cassette", "values": { "Drive": 8, "Tone": -0.5, "Mix": 1, "Output": -3, "Bias": 0.1, "Wow": 0.5, "Flutter": 0.4 } },
5
+ { "name": "Vocal sheen", "values": { "Drive": 4.5, "Tone": 0.3, "Mix": 0.7, "Output": -1.5, "2x": 1 } }
6
+ ]
@@ -0,0 +1,59 @@
1
+ desc:Width / Bass Mono
2
+ // accent: teal
3
+ import mcp_ui.jsfx-inc
4
+
5
+ // Widens the stereo image and keeps the low end mono: the side signal is high-passed at the crossover,
6
+ // so everything below it is identical in both channels. Core view: Width, Mono below, Output and a
7
+ // level meter. Advanced: the crossover slope and mid/side trims.
8
+
9
+ slider1:1<0,2,0.01>Width
10
+ slider2:120<20,300,1>Mono below
11
+ slider3:0<-24,12,0.1>Output
12
+ slider4:1<0,1,1{12 dB,24 dB}>Slope
13
+ slider5:0<-12,12,0.1>Mid
14
+ slider6:0<-12,12,0.1>Side
15
+
16
+ @init
17
+ function update() local(w0, c, alpha, a0) (
18
+ width = slider1;
19
+ gain = 10 ^ (slider3 / 20);
20
+ steep = slider4 > 0.5;
21
+ mid = 10 ^ (slider5 / 20); side = 10 ^ (slider6 / 20);
22
+ // 2nd-order Butterworth low-pass (RBJ), run once or twice on the side signal
23
+ w0 = 2 * $pi * slider2 / srate; c = cos(w0); alpha = sin(w0) / 1.4142;
24
+ a0 = 1 + alpha;
25
+ b0 = (1 - c) / 2 / a0; b1 = (1 - c) / a0;
26
+ a1 = -2 * c / a0; a2 = (1 - alpha) / a0;
27
+ );
28
+ update();
29
+ ui_boot(1);
30
+
31
+ @slider
32
+ update();
33
+
34
+ @block
35
+ ui_changed() ? update();
36
+
37
+ @sample
38
+ m = (spl0 + spl1) * 0.5 * mid;
39
+ s = (spl0 - spl1) * 0.5 * side;
40
+ y = b0 * s + z1; z1 = b1 * s - a1 * y + z2; z2 = b0 * s - a2 * y;
41
+ steep ? (
42
+ y2 = b0 * y + z3; z3 = b1 * y - a1 * y2 + z4; z4 = b0 * y - a2 * y2;
43
+ y = y2;
44
+ );
45
+ s = (s - y) * width; // the side signal without its lows
46
+ spl0 = (m + s) * gain;
47
+ spl1 = (m - s) * gain;
48
+ pk = max(pk, max(abs(spl0), abs(spl1)));
49
+
50
+ @gfx 340 250
51
+ ui_begin(1, 1) ? (
52
+ ui_row(4);
53
+ ui_knob(1, "Width", 2); ui_knob(2, "Mono below", 3); ui_knob(3, "Output", 1); ui_meter(pk, "Out");
54
+ pk = 0;
55
+ ui_section("Advanced") ? (
56
+ ui_row(3); ui_choice(4, "Slope"); ui_knob(5, "Mid", 1); ui_knob(6, "Side", 1);
57
+ );
58
+ ui_end();
59
+ );
@@ -0,0 +1,6 @@
1
+ [
2
+ { "name": "Tight low end", "values": { "Width": 1, "Mono below": 150, "Slope": 1 } },
3
+ { "name": "Wide chorus bus", "values": { "Width": 1.5, "Mono below": 120, "Side": 1.5, "Output": -1 } },
4
+ { "name": "Gentle spread", "values": { "Width": 1.2, "Mono below": 90, "Slope": 0 } },
5
+ { "name": "Mono check", "values": { "Width": 0 } }
6
+ ]
@@ -0,0 +1,15 @@
1
+ # JSFX performance checklist
2
+
3
+ The plugin runs in REAPER's audio thread, once per sample. Check every line of `@sample` against this.
4
+
5
+ 1. **Coefficients live in `update()`**, called from `@init`, `@slider` and `@block`. Never `exp`, `sin`, `^`, `pow` or `/ srate` of something that only changes with a knob, inside `@sample`.
6
+ 2. **Multiply by a reciprocal** you computed once, instead of dividing per sample.
7
+ 3. **No loops, `memset`, `memcpy` or `strcpy` in `@sample`.** Clear buffers in `@init` or when a parameter changes. A short fixed unrolled sequence beats a loop (the reverb in `mutate-verb.jsfx` calls `comb(0..7)` one by one).
8
+ 4. **Allocate once, in `@init`, sized for the worst case** (`srate` can be 192000): a delay of `N` seconds is `floor(srate * N)`. Nothing grows while running.
9
+ 5. **Denormals.** A feedback path that decays to nothing can make the CPU crawl. Keep feedback gain below 1 (clamp it, `0.7 + x * 0.28`), and if a tail can reach silence, snap tiny values to 0 (`abs(y) < 0.0000000001 ? y = 0`).
10
+ 6. **Skip work that is not needed.** A grain that is not playing costs one test; a section whose amount is 0 can return early.
11
+ 7. **Oversampling is opt-in and advanced.** It multiplies the cost; offer it as a toggle, never on by default.
12
+ 8. **Report latency.** A look-ahead needs `pdc_delay = samples;` and `pdc_bot_ch = 0; pdc_top_ch = 2;`.
13
+ 9. **Smooth with one-pole filters per sample only where a click would be audible** (gain); everything else can change at block rate in `@block`.
14
+ 10. **The UI is free.** `@gfx` runs on another thread and redraws only when something changed; do not put DSP in it. Share values with `@sample` only as scalars (a peak kept with `max()`).
15
+ 11. **No scientific notation** (`1e-9`): EEL2 drops the whole plugin. Write `0.000000001`.
@@ -0,0 +1,90 @@
1
+ # The UI toolkit (`reaper/mcp_ui.jsfx-inc`)
2
+
3
+ `write_jsfx` pastes the toolkit into your plugin's `@init`. You only call it. Every name starts
4
+ with `ui_`. Sliders must be **unnamed** and numbered 1..32.
5
+
6
+ ## The plugin's side
7
+
8
+ ```
9
+ @init ...your setup... ui_boot(animated); // 1 when the UI has a meter, else 0
10
+ @slider update();
11
+ @block ui_changed() ? update(); // a knob moved by dragging in @gfx
12
+ @gfx 380 250 // the window's starting size
13
+ ui_begin(core_rows, adv_rows) ? ( // 0 = nothing changed, skip drawing
14
+ ui_row(4); // a row of 4 equal cells
15
+ ui_knob(1, "Mix", 2); ui_knob(2, "Size", 2); ...
16
+ ui_section("Advanced") ? ( // the drawer; 1 while visible
17
+ ui_row(3); ui_knob(5, "Seed", 5); ...
18
+ );
19
+ ui_end();
20
+ );
21
+ ```
22
+
23
+ `core_rows` is how many `ui_row`s the core view has, `adv_rows` how many sit in the Advanced
24
+ drawer (0 when there is none). The core view fills the window and keeps its layout: the Advanced
25
+ drawer is a bar along the bottom that slides up **over** the core view when clicked (the core dims
26
+ behind it and does not react until it closes; click the bar or anywhere above the drawer to close).
27
+ Every widget is one block, label above, control, value below, sized the same across a row.
28
+
29
+ ## Widgets
30
+
31
+ | Call | Draws | Slider |
32
+ |---|---|---|
33
+ | `ui_knob(idx, "Label", fmt)` | knob, label above, value below | any range |
34
+ | `ui_toggle(idx, "Label")` | on/off pill | `<0,1,1>` |
35
+ | `ui_choice(idx, "Label")` | box showing the option, click = next, right-click = previous | `<0,N-1,1{A,B,C}>` |
36
+ | `ui_meter(level, "Label")` | vertical peak meter, -60..+6 dB, holds and falls 30 dB/s | none: pass the peak you kept with `max()` in `@sample`, then set it back to 0 |
37
+ | `ui_section("Label")` | the Advanced drawer (bar when closed, panel over the core when open); returns 1 while visible | none |
38
+
39
+ `fmt` for knobs: `0` number (`0.00`), `1` dB, `2` percent of 0..1, `3` Hz or kHz, `4` ms, `5` integer.
40
+
41
+ Interaction (all automatic, the FabFilter/Serum convention): drag up/down (200 px = the full
42
+ range, **Shift**-drag = 10x finer), mouse wheel (Shift = finer), **double-click** opens a small
43
+ value box next to the knob (type the value in the knob's units: dB, %, Hz with an optional `k`,
44
+ ms, integers; Enter sets it, clamped and snapped like a drag; a click outside cancels;
45
+ Backspace works), **Cmd-click / Ctrl-click / Alt-click** resets to the default. Toggles and
46
+ choices: click; a modifier-click resets them too. Never handle the mouse or keyboard in plugin
47
+ code (lint `own-key-handling` warns on `gfx_getchar`).
48
+
49
+ Esc: REAPER closes a floating FX window on Esc before the plugin sees it (probed in 7.40). Only
50
+ when the user turns on the FX window's **+ > Send all keyboard input to plug-in** does Esc reach
51
+ the plugin; then it closes the value box, the About dialog, then the drawer (and the window
52
+ closes with its close button, as every key now goes to the plugin).
53
+
54
+ Every plugin also gets, with no code of its own: a small "reaper-mcp" credit at the bottom right
55
+ (in the drawer bar, or the bottom padding when there is no drawer; hidden in a narrow window).
56
+ A click opens the **About** dialog drawn in the plugin: what reaper-mcp is, the repository
57
+ address as plain text (JSFX cannot open a browser or write the clipboard), and this plugin's
58
+ name, version, toolkit version, accent, control count and the day it was written (filled in by
59
+ `write_jsfx`; never the user's request). Set `ui_credit = 0;` in the toolkit to hide it.
60
+
61
+ **Accent.** Each plugin has its own accent colour (knob arcs, hover, the Advanced title, the
62
+ toggle's on state, the footer hover, a faint tint in the background), set by `write_jsfx`:
63
+ by default derived from the plugin's name, or `accent: "orange"` / `"#rrggbb"`. Never set
64
+ `ui_cAccent` or call `ui_theme()` in plugin code (lint `accent-assign`). Meters keep their green,
65
+ amber and red. **Background**: a very subtle vertical gradient with fine grain (`ui_texture = 0`
66
+ in the toolkit makes it flat), rendered once into an offscreen image and blitted, rebuilt only on
67
+ a resize or an accent change. The toolkit also hides REAPER's slider panel
68
+ above the UI (`ui_hide_sliders`): the sliders stay real parameters (automation, MIDI learn, the
69
+ Param menu, presets).
70
+
71
+ ## State and @init
72
+
73
+ REAPER re-runs `@init` whenever playback starts. The toolkit sets its UI state once (guarded by
74
+ `ui_ready`), so pressing Play never closes the drawer. Do the same in plugin code: never assign
75
+ `ui_adv_open` (the lint warns, `ui-state-reset`); `@serialize`'s `file_var(0, ui_adv_open)`
76
+ restores it with the project.
77
+
78
+ ## Rules the lint enforces
79
+
80
+ - At most **5** widgets before the first `ui_section` (a meter counts); at most 8 after it (a warning).
81
+ - Every visible slider needs a widget (hide one on purpose with a leading `-` in its label).
82
+ - `@init` calls `ui_boot`, `@block` calls `ui_changed`, `@gfx` calls `ui_begin`.
83
+ - No `gmem`, no named sliders, no scientific-notation literals, no `slider33` and up.
84
+ - `max()`/`min()` with exactly two arguments; no `local()` at the top of `@sample`/`@block`.
85
+ - A warning when the plugin assigns `ui_adv_open`.
86
+
87
+ ## Memory
88
+
89
+ Memory below `ui_mem` (1024) belongs to the toolkit. Allocate your buffers from it (the examples
90
+ use a tiny `alloc(n)`).