@mthines/reaper-mcp 0.80.0 → 0.80.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.
@@ -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.2.0'
16
+ version: '1.3.0'
17
17
  workflow_type: applied
18
18
  tags: [plugins, jsfx, dsp, ui, reaper, live-verification]
19
19
  ---
@@ -78,7 +78,9 @@ In two or three lines, write down and show the user:
78
78
 
79
79
  Cut before you add. If a control could be a sensible fixed value, make it one. Pick the closest
80
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
81
+ nonlinear plus tilt EQ, `width-bass-mono.jsfx` linear stereo plus meter, `multiband-compressor.jsfx` frequency graph with
82
+ crossover handles in Hz, per-band gain reduction and a transfer curve via `ui_freqgraph`,
83
+ `ui_fhandle`, `ui_grmeter`, `ui_transfer`; `ui_keyboard` shows MIDI notes) and read it. Each has its
82
84
  suggested presets beside it (`<name>.presets.json`): the shape `write_jsfx` takes.
83
85
 
84
86
  ### Step 2: Write the source
@@ -88,7 +90,7 @@ example and change what the spec changes. The shape is always:
88
90
 
89
91
  - header: `desc:Name`, **unnamed** sliders (`slider1:0.5<0,1,0.01>Label`), then `@init`,
90
92
  `@slider`, `@block`, `@sample`, `@gfx W H`.
91
- - `@init` ends with `ui_boot(animated)` (1 when the UI has a meter); allocate buffers from
93
+ - `@init` ends with `ui_boot(animated)` (1 when the UI has a meter, 2 when it has graph feeds: redraws only on activity); allocate buffers from
92
94
  `ui_mem`; compute coefficients in `update()`, called from `@init`, `@slider` and
93
95
  `@block: ui_changed() ? update();`.
94
96
  - `@gfx` draws the core row(s), then `ui_section("Advanced") ? ( ... )` for the rest.
@@ -196,7 +198,7 @@ Then Steps 4-8.
196
198
  - `1e9`-style literals make EEL2 reject the whole plugin and run no code. Write `1000000000`.
197
199
  - `local()` is only valid inside a function, never at the top of `@sample`/`@block`.
198
200
  - 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.
201
+ - Memory below `ui_mem` (2048) belongs to the toolkit: allocate from it.
200
202
  - `@init` runs again whenever playback starts (and on a sample-rate change). Anything it assigns
201
203
  is reset on Play: keep UI and interaction state out of unguarded `@init` assignments.
202
204
  - `rand()` cannot be seeded: use the seeded generator in `examples/mutate-verb.jsfx` when a
@@ -0,0 +1,150 @@
1
+ desc:Multiband Compressor
2
+ // accent: orange
3
+ import mcp_ui.jsfx-inc
4
+
5
+ // Three bands with Linkwitz-Riley 4th-order crossovers (the bands sum flat), one compressor per band.
6
+ // Every band has its own threshold, ratio and gain. Core view: a log frequency graph of the output with
7
+ // the two crossovers as draggable handles (drag them to pick the bands in Hz) and a threshold line per
8
+ // band (hover a band and drag up or down to move its threshold, Shift-drag for its gain, wheel for its ratio), per-band
9
+ // gain-reduction bars, and Threshold, Ratio and Gain knobs that edit the selected band (click a band on
10
+ // the graph or a bar to select it). Advanced: the selected band's transfer curve with its live level,
11
+ // attack, release and output, and Compare input, which draws the input spectrum over the output one.
12
+
13
+ slider1:200<40,800,1>Low crossover
14
+ slider2:2500<1000,12000,1>High crossover
15
+ slider3:-18<-60,0,0.1>Low threshold
16
+ slider4:-18<-60,0,0.1>Mid threshold
17
+ slider5:-18<-60,0,0.1>High threshold
18
+ slider6:3<1,20,0.1>Low ratio
19
+ slider7:3<1,20,0.1>Mid ratio
20
+ slider8:3<1,20,0.1>High ratio
21
+ slider9:0<-12,12,0.1>Low gain
22
+ slider10:0<-12,12,0.1>Mid gain
23
+ slider11:0<-12,12,0.1>High gain
24
+ slider12:10<1,100,1>Attack
25
+ slider13:120<20,1000,1>Release
26
+ slider14:0<-12,12,0.1>Output
27
+ slider15:0<0,1,1{Off,On}>Compare input
28
+
29
+ @init
30
+ ui_ptr = ui_mem;
31
+ function alloc(n) ( ui_ptr += n; ui_ptr - n; );
32
+ cf = alloc(20); // biquad coefficients: low-pass and high-pass at both crossovers, 5 each
33
+ st = alloc(48); // biquad states: 12 stages per channel, 2 each
34
+ ring = alloc(2048); // the last 2048 output samples (mono) for the spectrum
35
+ inr = alloc(2048); // the same for the input, only used while Compare input is on
36
+ mag2 = alloc(1024);
37
+ work = alloc(4096); // the FFT's complex buffer
38
+ win = alloc(2048); // Hann window
39
+ mag = alloc(1024); // magnitudes handed to the graph
40
+ thr = alloc(3); slope = alloc(3); tlo = alloc(3); tg = alloc(3); // per band: threshold, slope, floor, gain
41
+ env = alloc(3); // each band's level follower
42
+ grpk = alloc(3); // gain reduction peak since the last block, per band
43
+ grshow = alloc(3); // what the meter shows: the peak, released slowly
44
+ i = 0; loop(2048, win[i] = 0.5 - 0.5 * cos(2 * $pi * i / 2048); i += 1;);
45
+
46
+ // one 2nd-order Butterworth section (RBJ), both a low-pass and a high-pass; two in a row make a
47
+ // Linkwitz-Riley 4th-order slope
48
+ function coefs(c, f) local(w0, k, alpha, a0) (
49
+ w0 = 2 * $pi * min(f, srate * 0.45) / srate; k = cos(w0); alpha = sin(w0) / 1.41421356;
50
+ a0 = 1 + alpha;
51
+ cf[c] = (1 - k) / 2 / a0; cf[c + 1] = (1 - k) / a0; cf[c + 2] = cf[c]; cf[c + 3] = -2 * k / a0; cf[c + 4] = (1 - alpha) / a0; // low-pass
52
+ cf[c + 5] = (1 + k) / 2 / a0; cf[c + 6] = -(1 + k) / a0; cf[c + 7] = cf[c + 5]; cf[c + 8] = cf[c + 3]; cf[c + 9] = cf[c + 4]; // high-pass
53
+ );
54
+ function bq(c, s, x) local(y) (
55
+ y = cf[c] * x + st[s];
56
+ st[s] = cf[c + 1] * x - cf[c + 3] * y + st[s + 1];
57
+ st[s + 1] = cf[c + 2] * x - cf[c + 4] * y;
58
+ y;
59
+ );
60
+ // the gain reduction (dB, 0 or more) of a level (dB) against the threshold, with a 6 dB soft knee
61
+ function reduce(k, lvl) local(over) (
62
+ over = lvl - thr[k];
63
+ over <= -3 ? 0 : over >= 3 ? over * slope[k] : slope[k] * (over + 3) * (over + 3) / 12;
64
+ );
65
+ // follow one band: returns its linear gain and keeps the gain reduction peak
66
+ function band(k, x) local(a, g, gr) (
67
+ a = abs(x);
68
+ env[k] += (a - env[k]) * (a > env[k] ? ca : cr);
69
+ g = 1;
70
+ env[k] > tlo[k] ? (
71
+ gr = reduce(k, 20 * log10(env[k]));
72
+ gr > grpk[k] ? grpk[k] = gr;
73
+ g = exp(-gr * 0.11512925);
74
+ );
75
+ g;
76
+ );
77
+ function update() (
78
+ coefs(0, slider1); coefs(10, slider2);
79
+ k = 0;
80
+ loop(3,
81
+ thr[k] = slider(3 + k); slope[k] = 1 - 1 / slider(6 + k);
82
+ tlo[k] = 10 ^ ((thr[k] - 3) / 20); // below this level nothing is reduced: skip the logarithm
83
+ tg[k] = 10 ^ (slider(9 + k) / 20);
84
+ k += 1;
85
+ );
86
+ ca = 1 - exp(-1 / (slider12 * 0.001 * srate)); cr = 1 - exp(-1 / (slider13 * 0.001 * srate));
87
+ out = 10 ^ (slider14 / 20);
88
+ );
89
+ update();
90
+ ui_boot(2);
91
+
92
+ @slider
93
+ update();
94
+
95
+ @block
96
+ ui_changed() ? update();
97
+ k = 0;
98
+ loop(3,
99
+ grshow[k] = max(grpk[k], grshow[k] * 0.85); grpk[k] = 0;
100
+ ui_gr(k, grshow[k]);
101
+ k += 1;
102
+ );
103
+ ui_glevel(20 * log10(max(env[min(2, ui_fsel)], 0.000001)));
104
+ fresh ? (
105
+ i = 0;
106
+ loop(2048, work[i * 2] = ring[(rp + i) % 2048] * win[i]; work[i * 2 + 1] = 0; i += 1;);
107
+ fft(work, 2048); fft_permute(work, 2048);
108
+ i = 0;
109
+ loop(1024, mag[i] = sqrt(work[i * 2] * work[i * 2] + work[i * 2 + 1] * work[i * 2 + 1]) / 512; i += 1;);
110
+ ui_gfeed(mag, 1024);
111
+ slider15 ? (
112
+ i = 0;
113
+ loop(2048, work[i * 2] = inr[(rp + i) % 2048] * win[i]; work[i * 2 + 1] = 0; i += 1;);
114
+ fft(work, 2048); fft_permute(work, 2048);
115
+ i = 0;
116
+ loop(1024, mag2[i] = sqrt(work[i * 2] * work[i * 2] + work[i * 2 + 1] * work[i * 2 + 1]) / 512; i += 1;);
117
+ ui_gfeed2(mag2, 1024);
118
+ );
119
+ fresh = 0;
120
+ );
121
+
122
+ @sample
123
+ // left (s 0..23) and right (s 24..47): split at the low crossover, split the rest at the high one,
124
+ // and run the low band through an all-pass at the high one so the three bands add up flat
125
+ inr[rp] = (spl0 + spl1) * 0.5;
126
+ lo = bq(0, 0, bq(0, 2, spl0)); hi = bq(5, 4, bq(5, 6, spl0));
127
+ md = bq(10, 8, bq(10, 10, hi)); hh = bq(15, 12, bq(15, 14, hi));
128
+ lo = bq(10, 16, bq(10, 18, lo)) + bq(15, 20, bq(15, 22, lo));
129
+ ro = bq(0, 24, bq(0, 26, spl1)); ri = bq(5, 28, bq(5, 30, spl1));
130
+ rm = bq(10, 32, bq(10, 34, ri)); rh = bq(15, 36, bq(15, 38, ri));
131
+ ro = bq(10, 40, bq(10, 42, ro)) + bq(15, 44, bq(15, 46, ro));
132
+ g0 = band(0, max(abs(lo), abs(ro))); g1 = band(1, max(abs(md), abs(rm))); g2 = band(2, max(abs(hh), abs(rh)));
133
+ spl0 = (lo * g0 * tg[0] + md * g1 * tg[1] + hh * g2 * tg[2]) * out;
134
+ spl1 = (ro * g0 * tg[0] + rm * g1 * tg[1] + rh * g2 * tg[2]) * out;
135
+ ring[rp] = (spl0 + spl1) * 0.5; rp += 1;
136
+ rp >= 2048 ? ( rp = 0; fresh = 1; );
137
+
138
+ @gfx 440 360
139
+ ui_header(0, 14);
140
+ ui_begin(3, 3) ? (
141
+ ui_tall(2); ui_row(1);
142
+ ui_gshow(slider15); ui_freqgraph("Bands"); ui_fhandle(1, "Low crossover"); ui_fhandle(2, "High crossover"); ui_fthresh(3, 6, 9, 3);
143
+ ui_row(4);
144
+ ui_grmeter(3, "Reduction"); ui_bandknob(3, 3, "Threshold", 1); ui_bandknob(6, 3, "Ratio", 0); ui_bandknob(9, 3, "Gain", 1);
145
+ ui_section("Advanced") ? (
146
+ ui_tall(2); ui_row(3); ui_transfer(3, 6, 6); ui_knob(12, "Attack", 4); ui_knob(13, "Release", 4);
147
+ ui_row(3); ui_toggle(15, "Compare input");
148
+ );
149
+ ui_end();
150
+ );
@@ -0,0 +1,70 @@
1
+ [
2
+ {
3
+ "name": "Gentle glue",
4
+ "values": {
5
+ "Low threshold": -20,
6
+ "Mid threshold": -20,
7
+ "High threshold": -20,
8
+ "Low ratio": 2,
9
+ "Mid ratio": 2,
10
+ "High ratio": 2,
11
+ "Attack": 20,
12
+ "Release": 200
13
+ }
14
+ },
15
+ {
16
+ "name": "Tame the lows",
17
+ "values": {
18
+ "Low crossover": 150,
19
+ "Low threshold": -26,
20
+ "Low ratio": 4,
21
+ "Mid threshold": -14,
22
+ "Mid ratio": 1.5,
23
+ "High threshold": -12,
24
+ "High ratio": 1.5,
25
+ "Attack": 15,
26
+ "Release": 150,
27
+ "Low gain": -1
28
+ }
29
+ },
30
+ {
31
+ "name": "De-harsh highs",
32
+ "values": {
33
+ "High crossover": 4500,
34
+ "Low threshold": 0,
35
+ "Low ratio": 1,
36
+ "Mid threshold": -14,
37
+ "Mid ratio": 1.5,
38
+ "High threshold": -24,
39
+ "High ratio": 3.5,
40
+ "Attack": 3,
41
+ "Release": 80,
42
+ "High gain": -1.5
43
+ }
44
+ },
45
+ {
46
+ "name": "Loud and even",
47
+ "values": {
48
+ "Low threshold": -28,
49
+ "Mid threshold": -28,
50
+ "High threshold": -28,
51
+ "Low ratio": 6,
52
+ "Mid ratio": 6,
53
+ "High ratio": 6,
54
+ "Attack": 5,
55
+ "Release": 100,
56
+ "Output": 3
57
+ }
58
+ },
59
+ {
60
+ "name": "Neutral",
61
+ "values": {
62
+ "Low threshold": 0,
63
+ "Mid threshold": 0,
64
+ "High threshold": 0,
65
+ "Low ratio": 1,
66
+ "Mid ratio": 1,
67
+ "High ratio": 1
68
+ }
69
+ }
70
+ ]
@@ -137,9 +137,10 @@ slider10:0.4<0,1,0.01>Damping
137
137
  spl1 = (dr * (1 - mix) + wr * 3 * mix) * gain;
138
138
 
139
139
  @gfx 380 250
140
+ ui_header(3, 4); // Mix and Output live in the top right
140
141
  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);
142
+ ui_row(2);
143
+ ui_knob(1, "Mutate", 2); ui_knob(2, "Size", 2);
143
144
  ui_section("Advanced") ? (
144
145
  ui_row(3); ui_knob(5, "Seed", 5); ui_knob(6, "Pitch range", 5); ui_knob(7, "Reverse", 2);
145
146
  ui_row(3); ui_knob(8, "Bright", 2); ui_knob(9, "Pre-delay", 4); ui_knob(10, "Damping", 2);
@@ -76,9 +76,10 @@ slider8:0<0,1,1>2x
76
76
  spl1 = (spl1 * (1 - mix) + yr * mix) * gain;
77
77
 
78
78
  @gfx 340 250
79
+ ui_header(3, 4); // Mix and Output live in the top right
79
80
  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);
81
+ ui_row(2);
82
+ ui_knob(1, "Drive", 1); ui_knob(2, "Tone", 0);
82
83
  ui_section("Advanced") ? (
83
84
  ui_row(4); ui_knob(5, "Bias", 0); ui_knob(6, "Wow", 2); ui_knob(7, "Flutter", 2); ui_toggle(8, "2x");
84
85
  );
@@ -48,9 +48,10 @@ slider6:0<-12,12,0.1>Side
48
48
  pk = max(pk, max(abs(spl0), abs(spl1)));
49
49
 
50
50
  @gfx 340 250
51
+ ui_header(0, 3); // Output lives in the top right
51
52
  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");
53
+ ui_row(3);
54
+ ui_knob(1, "Width", 2); ui_knob(2, "Mono below", 3); ui_meter(pk, "Out");
54
55
  pk = 0;
55
56
  ui_section("Advanced") ? (
56
57
  ui_row(3); ui_choice(4, "Slope"); ui_knob(5, "Mid", 1); ui_knob(6, "Side", 1);
@@ -13,3 +13,4 @@ The plugin runs in REAPER's audio thread, once per sample. Check every line of `
13
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
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
15
  11. **No scientific notation** (`1e-9`): EEL2 drops the whole plugin. Write `0.000000001`.
16
+ 12. **Graphs (`ui_freqgraph` and friends): feed the UI cheaply.** `ui_gfeed` wants one FFT every 2048 samples at most (a ring buffer filled in `@sample`, the `fft` run in `@block`, never per sample); `ui_gr` / `ui_glevel` / `ui_kkey` are scalar writes. Use `ui_boot(2)` so silence stops redrawing. The graph widgets never allocate in `@gfx`.
@@ -36,6 +36,27 @@ Every widget is one block, label above, control, value below, sized the same acr
36
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
37
  | `ui_section("Label")` | the Advanced drawer (bar when closed, panel over the core when open); returns 1 while visible | none |
38
38
 
39
+ ### Graph widgets (toolkit 1.3)
40
+
41
+ | Call | Draws | Feed / slider |
42
+ |---|---|---|
43
+ | `ui_freqgraph("Label")` | log frequency graph, 20 Hz-20 kHz, gridlines and labels, the fed trace, the selected band; a click between handles selects a band | trace: `ui_gfeed(buf, n)` with `n` FFT magnitudes (linear, low to high) from `@block`, or `ui_gset(i, db)` for a curve point (`i` 0..95) |
44
+ | `ui_gshow(on)` / `ui_gfeed2(buf, n)` | before / after: with `ui_gshow(slider)` on, the graph also draws the input as a second, lighter line labelled Input / Output; feed it with `ui_gfeed2` only while shown (a second FFT costs). Put a `ui_toggle` for it in Advanced | a `<0,1,1{Off,On}>` slider |
45
+ | `ui_fhandle(idx, "Label")` | a draggable band edge on the graph, bound to slider `idx` in Hz; drag, wheel, double-click for a value box, modifier-click resets; stays between its neighbours; automates like a knob | a Hz slider, e.g. `<40,800,1>`; call it after `ui_freqgraph`, in left-to-right order |
46
+ | `ui_fthresh(thr_first, ratio_first, gain_first, n)` | a threshold line across each of `n` bands (the handles + 1) on the graph; hover a band and drag up/down to move its threshold, **Shift**-drag its gain, wheel = its ratio, click selects it | `n` threshold sliders from `thr_first` (dB, -60..0), `n` ratio sliders from `ratio_first`, `n` gain sliders from `gain_first`; call it after the handles |
47
+ | `ui_bandknob(first_idx, n, "Label", fmt)` | a knob on the selected band's slider (`first_idx + ui_fsel`), labelled with the band (Low / Mid / High, else Band N) | `n` sliders from `first_idx`; counts as one widget |
48
+ | `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) |
49
+ | `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` |
50
+ | `ui_keyboard(lo, hi, "Label")` | piano keys `lo`..`hi` (MIDI notes), lit while held | `ui_kkey(note, vel)` on note on, `ui_kkey(note, 0)` on note off |
51
+ | `ui_tall(span)` | the next `ui_row` is `span` times as tall (a graph needs height); knobs in it keep their size | none |
52
+
53
+ Use `ui_boot(2)` in a plugin with these feeds: it redraws only when a feed, a control or the window
54
+ changed, so silence costs nothing (`ui_boot(1)` redraws every frame, `ui_boot(0)` only on change).
55
+ Feeds are rounded to a visible step before they count as change. A graph widget counts as one
56
+ widget for the core limit. The selected band is `ui_fsel` (0-based), which the plugin may read.
57
+ Memory map: 0..1023 core, 1024+ graph data (`ui_fg` trace, `ui_ge` band edges, `ui_grm`, `ui_kb`),
58
+ `ui_mem` (2048) is where your buffers start. `examples/multiband-compressor.jsfx` uses them all.
59
+
39
60
  `fmt` for knobs: `0` number (`0.00`), `1` dB, `2` percent of 0..1, `3` Hz or kHz, `4` ms, `5` integer.
40
61
 
41
62
  Interaction (all automatic, the FabFilter/Serum convention): drag up/down (200 px = the full
@@ -51,7 +72,10 @@ when the user turns on the FX window's **+ > Send all keyboard input to plug-in*
51
72
  the plugin; then it closes the value box, the About dialog, then the drawer (and the window
52
73
  closes with its close button, as every key now goes to the plugin).
53
74
 
54
- Every plugin also gets, with no code of its own: a small "reaper-mcp" credit at the bottom right
75
+ **Header knobs.** A plugin with a Mix and/or an Output slider calls `ui_header(mix_idx, out_idx)` in `@gfx` before `ui_begin` (0 for one it does not have): two small knobs in the top right, Output rightmost, with the usual gestures, the value shown while hovered. Do not draw those sliders as widgets too (they leave the core view and its widget count). The plugin name and the first row get a clear gap below the name, a little more with header knobs.
76
+
77
+ Every plugin also gets, with no code of its own: its name in small spaced capitals at the top-left
78
+ (hidden in a very narrow window), and a small "reaper-mcp" credit at the bottom right
55
79
  (in the drawer bar, or the bottom padding when there is no drawer; hidden in a narrow window).
56
80
  A click opens the **About** dialog drawn in the plugin: what reaper-mcp is, the repository
57
81
  address as plain text (JSFX cannot open a browser or write the clipboard), and this plugin's
@@ -83,8 +107,10 @@ restores it with the project.
83
107
  - No `gmem`, no named sliders, no scientific-notation literals, no `slider33` and up.
84
108
  - `max()`/`min()` with exactly two arguments; no `local()` at the top of `@sample`/`@block`.
85
109
  - A warning when the plugin assigns `ui_adv_open`.
110
+ - `unknown-ui-call` (a `ui_` function the toolkit does not define) and `ui-arity` (wrong argument
111
+ count) are errors: EEL2 would otherwise fail silently.
86
112
 
87
113
  ## Memory
88
114
 
89
- Memory below `ui_mem` (1024) belongs to the toolkit. Allocate your buffers from it (the examples
115
+ Memory below `ui_mem` belongs to the toolkit. Allocate your buffers from it (the examples
90
116
  use a tiny `alloc(n)`).
package/main.js CHANGED
@@ -173,6 +173,7 @@ var ALLOWED_SPAN_ATTRIBUTES = /* @__PURE__ */ new Set([
173
173
  "reaper.jsfx.sliders",
174
174
  "reaper.jsfx.widgets.core",
175
175
  "reaper.jsfx.widgets.advanced",
176
+ "reaper.jsfx.graphs",
176
177
  "reaper.jsfx.size",
177
178
  "reaper.jsfx.version",
178
179
  "reaper.jsfx.toolkit_version",
@@ -8718,6 +8719,72 @@ function readVersion(generated) {
8718
8719
 
8719
8720
  // apps/reaper-mcp-server/src/jsfx/lint.ts
8720
8721
  var MAX_CHOICE_OPTIONS = 8;
8722
+ var UI_API = {
8723
+ ui_meta: 5,
8724
+ ui_boot: 1,
8725
+ ui_changed: 0,
8726
+ ui_c: 2,
8727
+ ui_mixc: 3,
8728
+ ui_theme: 1,
8729
+ ui_cm: 3,
8730
+ ui_q: 2,
8731
+ ui_set: 2,
8732
+ ui_rrect: 5,
8733
+ ui_ring: 6,
8734
+ ui_caps: 1,
8735
+ ui_ctext: 4,
8736
+ ui_chev: 3,
8737
+ ui_bgbuild: 0,
8738
+ ui_bg: 0,
8739
+ ui_fmted: 2,
8740
+ ui_edopen: 5,
8741
+ ui_edcommit: 0,
8742
+ ui_edkey: 1,
8743
+ ui_keys: 0,
8744
+ ui_namedraw: 0,
8745
+ ui_begin: 2,
8746
+ ui_footer: 2,
8747
+ ui_float: 4,
8748
+ ui_popover: 0,
8749
+ ui_arow: 5,
8750
+ ui_aboutdraw: 0,
8751
+ ui_end: 0,
8752
+ ui_tall: 1,
8753
+ ui_row: 1,
8754
+ ui_cell: 0,
8755
+ ui_label: 2,
8756
+ ui_value: 1,
8757
+ ui_fmtv: 2,
8758
+ ui_reset: 1,
8759
+ ui_ctl: 5,
8760
+ ui_knob: 3,
8761
+ ui_toggle: 2,
8762
+ ui_choice: 2,
8763
+ ui_meter: 2,
8764
+ ui_section: 1,
8765
+ ui_gput: 2,
8766
+ ui_gset: 2,
8767
+ ui_gfeed: 2,
8768
+ ui_gr: 2,
8769
+ ui_glevel: 1,
8770
+ ui_kkey: 2,
8771
+ ui_fxof: 1,
8772
+ ui_fof: 1,
8773
+ ui_gyof: 1,
8774
+ ui_freqgraph: 1,
8775
+ ui_fpill: 2,
8776
+ ui_fhandle: 2,
8777
+ ui_grmeter: 2,
8778
+ ui_tcurve: 4,
8779
+ ui_transfer: 3,
8780
+ ui_keyboard: 3,
8781
+ ui_fthresh: 4,
8782
+ ui_header: 2,
8783
+ ui_hknob: 4,
8784
+ ui_gfeed2: 2,
8785
+ ui_gshow: 1,
8786
+ ui_bandknob: 4
8787
+ };
8721
8788
  var MAX_CORE_WIDGETS = 5;
8722
8789
  var MAX_ADVANCED_WIDGETS = 8;
8723
8790
  var MAX_FILE_BYTES = 64 * 1024;
@@ -8756,9 +8823,43 @@ function sections2(code) {
8756
8823
  out2.set(name, { text: buf.join("\n"), line });
8757
8824
  return out2;
8758
8825
  }
8759
- var WIDGET = /\bui_(knob|toggle|choice)\s*\(\s*(\d+)/g;
8760
- var METER = /\bui_meter\s*\(/g;
8761
- var countWidgets = (t) => [...t.matchAll(WIDGET)].length + [...t.matchAll(METER)].length;
8826
+ var WIDGET = /\bui_(knob|toggle|choice|fhandle)\s*\(\s*(\d+)/g;
8827
+ var BANDKNOB = /\bui_bandknob\s*\(\s*(\d+)\s*,\s*(\d+)/g;
8828
+ var FTHRESH = /\bui_fthresh\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/g;
8829
+ var HEADER = /\bui_header\s*\(\s*(\d+)\s*,\s*(\d+)/g;
8830
+ var TRANSFER = /\bui_transfer\s*\(\s*(\d+)\s*,\s*(\d+)/g;
8831
+ var COUNTED = /\bui_(knob|toggle|choice|meter|freqgraph|grmeter|transfer|keyboard|bandknob)\s*\(/g;
8832
+ var GRAPHS = /\bui_(freqgraph|grmeter|transfer|keyboard)\s*\(/g;
8833
+ var countWidgets = (t) => [...t.matchAll(COUNTED)].length;
8834
+ function uiCalls(code) {
8835
+ const out2 = [];
8836
+ for (const m of code.matchAll(/\b(ui_\w+)\s*\(/g)) {
8837
+ const at = m.index ?? 0;
8838
+ if (/\bfunction\s+$/.test(code.slice(Math.max(0, at - 12), at))) continue;
8839
+ let depth = 1;
8840
+ let args = 0;
8841
+ let any = false;
8842
+ let inString = false;
8843
+ for (let i = at + m[0].length; i < code.length && depth > 0; i++) {
8844
+ const ch = code[i];
8845
+ if (inString) {
8846
+ if (ch === '"') inString = false;
8847
+ continue;
8848
+ }
8849
+ if (ch === '"') {
8850
+ inString = true;
8851
+ any = true;
8852
+ } else if (ch === "(") {
8853
+ depth++;
8854
+ any = true;
8855
+ } else if (ch === ")") depth--;
8856
+ else if (ch === "," && depth === 1) args++;
8857
+ else if (/\S/.test(ch)) any = true;
8858
+ }
8859
+ out2.push({ name: m[1], args: any ? args + 1 : 0, at });
8860
+ }
8861
+ return out2;
8862
+ }
8762
8863
  function lintJsfx(source) {
8763
8864
  const findings = [];
8764
8865
  const add2 = (rule, severity, message, line) => findings.push({ rule, severity, message, ...line ? { line } : {} });
@@ -8804,12 +8905,28 @@ function lintJsfx(source) {
8804
8905
  used.add(idx);
8805
8906
  if (!byIndex.has(idx)) add2("widget-unknown-slider", "error", `ui_${m[1]}(${idx}, ...) points at slider${idx}, which is not declared.`, gfx.line + gfx.text.slice(0, m.index).split("\n").length);
8806
8907
  }
8908
+ for (const m of gfx.text.matchAll(TRANSFER)) {
8909
+ for (const idx of [Number(m[1]), Number(m[2])]) {
8910
+ used.add(idx);
8911
+ if (!byIndex.has(idx)) add2("widget-unknown-slider", "error", `ui_transfer(${m[1]}, ${m[2]}, ...) points at slider${idx}, which is not declared.`, gfx.line + gfx.text.slice(0, m.index).split("\n").length);
8912
+ }
8913
+ }
8914
+ const ranges = [];
8915
+ for (const m of gfx.text.matchAll(HEADER)) for (const v of [m[1], m[2]]) if (Number(v) > 0) ranges.push(["ui_header", Number(v), 1]);
8916
+ for (const m of gfx.text.matchAll(BANDKNOB)) ranges.push(["ui_bandknob", Number(m[1]), Number(m[2])]);
8917
+ for (const m of gfx.text.matchAll(FTHRESH)) ranges.push(["ui_fthresh", Number(m[1]), Number(m[4])], ["ui_fthresh", Number(m[2]), Number(m[4])], ["ui_fthresh", Number(m[3]), Number(m[4])]);
8918
+ for (const [fn, first, count] of ranges) {
8919
+ for (let idx = first; idx < first + count; idx++) {
8920
+ used.add(idx);
8921
+ if (!byIndex.has(idx)) add2("widget-unknown-slider", "error", `${fn} covers slider${idx}, which is not declared (it takes ${count} sliders from slider${first}).`, gfx.line);
8922
+ }
8923
+ }
8807
8924
  for (const s of sliders) {
8808
8925
  if (!s.hidden && !used.has(s.index)) add2("slider-without-widget", "error", `slider${s.index} "${s.name}" has no widget in @gfx. Draw it, or hide it with a leading "-" in its label.`);
8809
8926
  }
8810
8927
  }
8811
8928
  const init2 = secs.get("init")?.text ?? "";
8812
- if (!/\bui_boot\s*\(/.test(init2)) add2("no-ui-boot", "error", "@init must call ui_boot(animated) after the plugin's own setup (animated = 1 when the UI has a meter).");
8929
+ if (!/\bui_boot\s*\(/.test(init2)) add2("no-ui-boot", "error", "@init must call ui_boot(animated) after the plugin's own setup (animated = 1 when the UI has a meter, 2 when it has graph feeds, 0 when static).");
8813
8930
  if (!/\bui_changed\s*\(/.test(secs.get("block")?.text ?? "") && !/\bui_changed\s*\(/.test(secs.get("sample")?.text ?? "")) {
8814
8931
  add2("no-changed", "error", "@block must call ui_changed() ? update(); so a knob moved in @gfx reaches the DSP.");
8815
8932
  }
@@ -8824,6 +8941,15 @@ function lintJsfx(source) {
8824
8941
  for (const m of code.matchAll(/\bgfx_getchar\s*\(/g)) {
8825
8942
  add2("own-key-handling", "warning", "The plugin reads the keyboard (gfx_getchar): the toolkit does that while a value box is open, so typed values would go missing. Leave keyboard and mouse handling to the toolkit.", lineOf(m.index ?? 0));
8826
8943
  }
8944
+ const own = new Set([...code.matchAll(/\bfunction\s+(ui_\w+)/g)].map((m) => m[1]));
8945
+ for (const c of uiCalls(code)) {
8946
+ const expected = UI_API[c.name];
8947
+ if (expected === void 0) {
8948
+ if (!own.has(c.name)) add2("unknown-ui-call", "error", `${c.name}() is not a toolkit function: REAPER would compile the call to nothing and the widget would silently not draw. Check the spelling against reference/toolkit.md.`, lineOf(c.at));
8949
+ } else if (c.args !== expected) {
8950
+ add2("ui-arity", "error", `${c.name}() takes ${expected} argument${expected === 1 ? "" : "s"}, this call has ${c.args}: EEL2 would drop the whole plugin or read the wrong values.`, lineOf(c.at));
8951
+ }
8952
+ }
8827
8953
  for (const c of wrongMinMaxCalls(code)) {
8828
8954
  add2("two-arg-minmax", "error", `max/min take exactly two arguments, this call has ${c.count}: REAPER would fail to compile the whole plugin and pass the audio through. Nest them: max(max(a, b), c).`, lineOf(c.at));
8829
8955
  }
@@ -8834,7 +8960,7 @@ function lintJsfx(source) {
8834
8960
  if (/\/=?\s*srate\b/.test(sample.text)) add2("sample-divide-srate", "warning", "Dividing by srate per sample: compute the coefficient in update() once.", sample.line);
8835
8961
  }
8836
8962
  for (const m of code.matchAll(/\b(?:buf|mem|memory)\w*\s*=\s*(\d+)\s*;/g)) {
8837
- if (Number(m[1]) < 1024) add2("low-memory-index", "warning", `A buffer starts at index ${m[1]}: memory below ui_mem (1024) is reserved for the toolkit. Allocate from ui_mem.`, lineOf(m.index ?? 0));
8963
+ if (Number(m[1]) < 2048) add2("low-memory-index", "warning", `A buffer starts at index ${m[1]}: memory below ui_mem (2048) is reserved for the toolkit. Allocate from ui_mem.`, lineOf(m.index ?? 0));
8838
8964
  }
8839
8965
  return findings;
8840
8966
  }
@@ -8845,6 +8971,10 @@ function widgetCounts(source) {
8845
8971
  const at = gfx.search(/\bui_section\s*\(/);
8846
8972
  return { core: countWidgets(at === -1 ? gfx : gfx.slice(0, at)), advanced: at === -1 ? 0 : countWidgets(gfx.slice(at)) };
8847
8973
  }
8974
+ function graphWidgetCount(source) {
8975
+ const gfx = sections2(stripComments(source.replace(/\r\n/g, "\n"))).get("gfx")?.text ?? "";
8976
+ return [...gfx.matchAll(GRAPHS)].length;
8977
+ }
8848
8978
 
8849
8979
  // apps/reaper-mcp-server/src/jsfx/presets.ts
8850
8980
  import { existsSync as existsSync4, mkdirSync as mkdirSync5, readFileSync as readFileSync4, writeFileSync as writeFileSync4 } from "node:fs";
@@ -8994,6 +9124,7 @@ function shapeAttributes(s) {
8994
9124
  "reaper.jsfx.overwrite": s.overwrite,
8995
9125
  ...s.sliders !== void 0 ? { "reaper.jsfx.sliders": cap(s.sliders, MAX_USER_SLIDERS) } : {},
8996
9126
  ...s.widgets ? { "reaper.jsfx.widgets.core": cap(s.widgets.core, 16), "reaper.jsfx.widgets.advanced": cap(s.widgets.advanced, 16) } : {},
9127
+ ...s.graphs !== void 0 ? { "reaper.jsfx.graphs": cap(s.graphs, 8) } : {},
8997
9128
  ...s.bytes !== void 0 ? { "reaper.jsfx.size": sizeBucket(s.bytes) } : {},
8998
9129
  ...s.version !== void 0 ? { "reaper.jsfx.version": cap(s.version, MAX_VERSION) } : {},
8999
9130
  ...s.toolkit ? { "reaper.jsfx.toolkit_version": s.toolkit } : {},
@@ -9051,7 +9182,7 @@ function writeJsfx(input) {
9051
9182
  const sliders = parseSliders(args.source).sliders;
9052
9183
  const widgets = widgetCounts(args.source);
9053
9184
  const toolkit = loadToolkit();
9054
- const shape2 = { overwrite: overwrite2, sliders: sliders.length, widgets, bytes: Buffer.byteLength(args.source), toolkit: toolkitVersion(toolkit), findings, accent: accent.kind };
9185
+ const shape2 = { overwrite: overwrite2, sliders: sliders.length, widgets, graphs: graphWidgetCount(args.source), bytes: Buffer.byteLength(args.source), toolkit: toolkitVersion(toolkit), findings, accent: accent.kind };
9055
9186
  if (errorsOf(findings).length) {
9056
9187
  record({ ...shape2, outcome: "refused_lint" });
9057
9188
  emitLog("warn", "write_jsfx refused: lint errors", { "reaper.jsfx.outcome": "refused_lint", "reaper.jsfx.lint.rules": [...new Set(errorsOf(findings).map((f) => f.rule))].join(",") });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mthines/reaper-mcp",
3
- "version": "0.80.0",
3
+ "version": "0.80.1",
4
4
  "type": "module",
5
5
  "description": "MCP server for controlling REAPER DAW — real-time mixing, FX control, and frequency analysis for AI agents",
6
6
  "license": "MIT",