@mthines/reaper-mcp 0.78.1-beta.95.1 → 0.78.2
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.
- package/README.md +98 -38
- package/bridge-ui/mcp_bridge.html +10 -10
- package/claude/skills/make-plugin/SKILL.md +205 -0
- package/claude/skills/make-plugin/examples/mutate-verb.jsfx +148 -0
- package/claude/skills/make-plugin/examples/mutate-verb.presets.json +6 -0
- package/claude/skills/make-plugin/examples/tape-sat.jsfx +86 -0
- package/claude/skills/make-plugin/examples/tape-sat.presets.json +6 -0
- package/claude/skills/make-plugin/examples/width-bass-mono.jsfx +59 -0
- package/claude/skills/make-plugin/examples/width-bass-mono.presets.json +6 -0
- package/claude/skills/make-plugin/reference/dsp-perf.md +15 -0
- package/claude/skills/make-plugin/reference/toolkit.md +90 -0
- package/main.js +939 -149
- package/package.json +1 -1
- package/reaper/CLAUDE.md +1 -0
- package/reaper/mcp_ui.jsfx-inc +627 -0
package/package.json
CHANGED
package/reaper/CLAUDE.md
CHANGED
|
@@ -30,6 +30,7 @@ Files installed INTO the REAPER DAW by the `setup` command. These run inside REA
|
|
|
30
30
|
| `mcp_correlation_meter.jsfx` | JSFX/EEL2 | Stereo correlation and width analysis |
|
|
31
31
|
| `mcp_crest_factor.jsfx` | JSFX/EEL2 | Crest factor (peak-to-RMS) measurement |
|
|
32
32
|
| `mcp_gain_trace.jsfx` | JSFX/EEL2 | Pre/post gain trace for pumping/ducking: pair it around a chain (Mode pre/post, same Slot), read p5/p1/std after playback. No `1e9`-style literals (EEL2 rejects them; `jsfx-lint.test.ts` checks) |
|
|
33
|
+
| `mcp_ui.jsfx-inc` | JSFX/EEL2 | The `@gfx` toolkit generated plugins inline (`write_jsfx` pastes it into their `@init`). Canonical source: edit here, never in a generated plugin. Globals are `ui_`-prefixed; sliders must be unnamed; no `1e9`-style literals |
|
|
33
34
|
| `install.sh` | Shell | Manual install helper |
|
|
34
35
|
|
|
35
36
|
## Lua Bridge (`mcp_bridge.lua`)
|
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
// mcp_ui.jsfx-inc: the reaper-mcp @gfx toolkit, v1.2.0
|
|
2
|
+
//
|
|
3
|
+
// Canonical source. `write_jsfx` pastes the body below (everything after this header) into the
|
|
4
|
+
// plugin's own @init section, so a generated plugin is ONE file with no dependency on this one,
|
|
5
|
+
// the bridge or the MCP server. Edit it here, never in a generated plugin.
|
|
6
|
+
//
|
|
7
|
+
// Principles: fast (redraw only when something changed, no allocation in @gfx, coefficients
|
|
8
|
+
// belong in the plugin's update()), simple (five widgets), progressive disclosure (a core view
|
|
9
|
+
// that fills the window and never moves, an Advanced drawer that slides up over it).
|
|
10
|
+
//
|
|
11
|
+
// Gestures on a knob (the FabFilter/Serum convention): drag up/down, Shift-drag = 10x finer,
|
|
12
|
+
// wheel (Shift = finer), double-click = type a value, Cmd-click / Ctrl-click / Alt-click = reset
|
|
13
|
+
// to the default. Toggles and choices: click; a modifier-click resets them too.
|
|
14
|
+
// Esc: REAPER closes the FX window on Esc before the plugin sees it. Only with the FX window's
|
|
15
|
+
// "+" menu > "Send all keyboard input to plug-in" does Esc reach the plugin; then it closes the
|
|
16
|
+
// value box, the About dialog or the drawer (and the window closes with its close button).
|
|
17
|
+
//
|
|
18
|
+
// Memory 0..1023 is reserved for the toolkit: the plugin's own buffers start at ui_mem.
|
|
19
|
+
// Every global starts with ui_. Sliders must be UNNAMED (slider1:0.5<0,1,0.01>Label): named
|
|
20
|
+
// sliders do not keep their value in sliderN, which the toolkit reads through slider(idx).
|
|
21
|
+
// EEL2: max()/min() take exactly two arguments; no 1e-9 style literals.
|
|
22
|
+
//
|
|
23
|
+
// Plugin side:
|
|
24
|
+
// @init ... ui_boot(animated); // animated = 1 when the UI has a meter
|
|
25
|
+
// @block ui_changed() ? update(); // a slider moved by a click or drag in @gfx
|
|
26
|
+
// @gfx 380 220
|
|
27
|
+
// ui_begin(core_rows, adv_rows) ? (
|
|
28
|
+
// ui_row(3); ui_knob(1, "Mix", 2); ui_knob(2, "Size", 2); ui_toggle(3, "Freeze");
|
|
29
|
+
// ui_section("Advanced") ? ( ui_row(2); ui_knob(4, "Damping", 2); ui_knob(5, "Pre-delay", 4); );
|
|
30
|
+
// ui_end();
|
|
31
|
+
// );
|
|
32
|
+
// @serialize file_var(0, ui_adv_open); // added for you when the plugin has none
|
|
33
|
+
|
|
34
|
+
ui_ver = 1.2;
|
|
35
|
+
|
|
36
|
+
// Design tokens: the bridge status page's palette (apps/bridge-ui/src/styles.css). The accent is
|
|
37
|
+
// the plugin's own: write_jsfx emits ui_theme($xRRGGBB) after this block (from the plugin's name,
|
|
38
|
+
// or the colour the user picked). Plugin code never sets it.
|
|
39
|
+
ui_cBg = $x0e0f11; ui_cPanel = $x15171a; ui_cPanel2 = $x1b1d21; ui_cLine = $x24272c;
|
|
40
|
+
ui_cText = $xe7e9ec; ui_cMuted = $x8a909a; ui_cAccent = $x7cc4ff; ui_cLive = $x4ade80;
|
|
41
|
+
ui_cWarn = $xf5b84b; ui_cBad = $xf87171;
|
|
42
|
+
|
|
43
|
+
// The footer credit (bottom right). 0 hides it. A click opens the About dialog (JSFX cannot open
|
|
44
|
+
// a browser or write the clipboard, so it shows the repository address as text).
|
|
45
|
+
ui_credit = 1;
|
|
46
|
+
// 1 hides REAPER's slider panel above the UI (it duplicates the knobs and squeezes them). The
|
|
47
|
+
// sliders stay real parameters: automation, MIDI learn and the Param menu still list them.
|
|
48
|
+
ui_hide_sliders = 1;
|
|
49
|
+
// 1 = a very subtle vertical gradient (tinted by the accent) with fine film grain behind the UI,
|
|
50
|
+
// rendered once into an offscreen image and blitted; 0 = a flat background.
|
|
51
|
+
ui_texture = 1;
|
|
52
|
+
ui_grain = 0.3; // grain strength: the tile is bg-level noise of +/-0.06, blended at this opacity
|
|
53
|
+
ui_img_bg = 120; ui_img_tile = 121;
|
|
54
|
+
|
|
55
|
+
// Filled in by write_jsfx's metadata block (shown in the About dialog): never the user's request.
|
|
56
|
+
strcpy(#ui_name, "Plugin"); strcpy(#ui_date, ""); strcpy(#ui_tkv, "1.2.0");
|
|
57
|
+
ui_pver = 0; ui_nctl = 0; ui_akind = 0; ui_example = 0;
|
|
58
|
+
|
|
59
|
+
// Per-slider metadata (index 1..64), filled by write_jsfx from the slider lines.
|
|
60
|
+
ui_min = 0; ui_max = 65; ui_def = 130; ui_stp = 195;
|
|
61
|
+
ui_mtr = 400; // meter state: 2 slots per meter (level in dB, last time)
|
|
62
|
+
ui_mem = 1024; // first free memory index for the plugin's own buffers
|
|
63
|
+
// REAPER re-runs @init when playback starts (and on sample-rate changes): the UI state below
|
|
64
|
+
// is set once, so pressing Play never closes the drawer or drops a drag. Plugin code must not
|
|
65
|
+
// assign ui_adv_open either (only @serialize's file_var restores it).
|
|
66
|
+
ui_ready ? ( ui_hash = -1; ) : (
|
|
67
|
+
ui_adv_open = 0; // Advanced drawer open (saved with the project and presets)
|
|
68
|
+
ui_hash = -1;
|
|
69
|
+
ui_p = -1; // drawer position 0..1 (animated); -1 = not drawn yet
|
|
70
|
+
ui_ed = 0; // slider whose value box is open (typing a value), 0 = none
|
|
71
|
+
ui_about = 0; // About dialog open
|
|
72
|
+
ui_ready = 1;
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
function ui_meta(idx, lo, hi, df, st) (
|
|
76
|
+
ui_min[idx] = lo; ui_max[idx] = hi; ui_def[idx] = df; ui_stp[idx] = st;
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
function ui_boot(animated) (
|
|
80
|
+
gfx_ext_retina = 1;
|
|
81
|
+
gfx_clear = -1;
|
|
82
|
+
ui_animated = animated;
|
|
83
|
+
ui_hide_sliders ? slider_show(4294967295, 0);
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
// A slider moved from @gfx: returns 1 once, so @block can re-run the plugin's update().
|
|
87
|
+
function ui_changed() local(r) ( r = ui_chg; ui_chg = 0; r; );
|
|
88
|
+
|
|
89
|
+
function ui_c(c, a) local(r, g, b) (
|
|
90
|
+
r = floor(c / 65536) & 255; g = floor(c / 256) & 255; b = c & 255;
|
|
91
|
+
gfx_set(r / 255, g / 255, b / 255, a);
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
// The mix of two packed colours as a packed colour (t = 0: c1, 1: c2).
|
|
95
|
+
function ui_mixc(c1, c2, t) (
|
|
96
|
+
floor((floor(c1 / 65536) & 255) * (1 - t) + (floor(c2 / 65536) & 255) * t + 0.5) * 65536
|
|
97
|
+
+ floor((floor(c1 / 256) & 255) * (1 - t) + (floor(c2 / 256) & 255) * t + 0.5) * 256
|
|
98
|
+
+ floor((c1 & 255) * (1 - t) + (c2 & 255) * t + 0.5);
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
// The plugin's accent and every token derived from it, computed once (not per frame).
|
|
102
|
+
function ui_theme(c) (
|
|
103
|
+
ui_cAccent = c;
|
|
104
|
+
ui_cAccentHi = ui_mixc(c, ui_cText, 0.18); // hover
|
|
105
|
+
ui_cAccentAct = ui_mixc(c, ui_cText, 0.35); // dragging
|
|
106
|
+
ui_cTrack = ui_mixc(ui_mixc(ui_cLine, ui_cMuted, 0.12), c, 0.07);
|
|
107
|
+
ui_cTrackHot = ui_mixc(ui_mixc(ui_cLine, ui_cMuted, 0.22), c, 0.12);
|
|
108
|
+
ui_cTop = ui_mixc(ui_mixc(ui_cBg, $xffffff, 0.012), c, 0.02); // gradient: a hair lighter (and tinted) on top,
|
|
109
|
+
ui_cBot = ui_mixc(ui_cBg, 0, 0.15); // a hair darker at the bottom
|
|
110
|
+
);
|
|
111
|
+
ui_theme($x7cc4ff);
|
|
112
|
+
|
|
113
|
+
// Opaque mix of two colors (t = 0: c1, 1: c2): blending without alpha, so shapes never seam.
|
|
114
|
+
function ui_cm(c1, c2, t) local(r, g, b) (
|
|
115
|
+
r = (floor(c1 / 65536) & 255) * (1 - t) + (floor(c2 / 65536) & 255) * t;
|
|
116
|
+
g = (floor(c1 / 256) & 255) * (1 - t) + (floor(c2 / 256) & 255) * t;
|
|
117
|
+
b = (c1 & 255) * (1 - t) + (c2 & 255) * t;
|
|
118
|
+
gfx_set(r / 255, g / 255, b / 255, 1);
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
function ui_q(idx, v) local(lo, hi, st) (
|
|
122
|
+
lo = ui_min[idx]; hi = ui_max[idx]; st = ui_stp[idx];
|
|
123
|
+
st > 0 ? v = lo + floor((v - lo) / st + 0.5) * st;
|
|
124
|
+
min(hi, max(lo, v));
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
function ui_set(idx, v) (
|
|
128
|
+
v != slider(idx) ? (
|
|
129
|
+
slider(idx) = v;
|
|
130
|
+
slider_automate(2 ^ (idx - 1));
|
|
131
|
+
ui_chg = 1;
|
|
132
|
+
);
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// ---- drawing helpers ----------------------------------------------------------------------
|
|
136
|
+
|
|
137
|
+
// Filled rounded rectangle (opaque colors only: the corners overlap the sides).
|
|
138
|
+
function ui_rrect(x, y, w, h, r) (
|
|
139
|
+
r = min(r, min(w, h) / 2);
|
|
140
|
+
gfx_rect(x + r, y, w - 2 * r, h);
|
|
141
|
+
gfx_rect(x, y + r, r, h - 2 * r);
|
|
142
|
+
gfx_rect(x + w - r, y + r, r, h - 2 * r);
|
|
143
|
+
gfx_circle(x + r, y + r, r, 1, 1); gfx_circle(x + w - r - 1, y + r, r, 1, 1);
|
|
144
|
+
gfx_circle(x + r, y + h - r - 1, r, 1, 1); gfx_circle(x + w - r - 1, y + h - r - 1, r, 1, 1);
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
// One solid stroke along a circle: a ring segment filled as quads, its edges anti-aliased,
|
|
148
|
+
// round caps. Angles in radians, 0 = 12 o'clock, clockwise.
|
|
149
|
+
function ui_ring(cx, cy, r0, r1, a0, a1) local(n, d, a, b, ra, rb) (
|
|
150
|
+
n = max(2, ceil(abs(a1 - a0) / 0.07)); d = (a1 - a0) / n; a = a0;
|
|
151
|
+
loop(n,
|
|
152
|
+
b = a + d;
|
|
153
|
+
gfx_triangle(cx + sin(a) * r1, cy - cos(a) * r1, cx + sin(b) * r1, cy - cos(b) * r1,
|
|
154
|
+
cx + sin(b) * r0, cy - cos(b) * r0, cx + sin(a) * r0, cy - cos(a) * r0);
|
|
155
|
+
a = b;
|
|
156
|
+
);
|
|
157
|
+
gfx_arc(cx, cy, r1, a0, a1, 1); gfx_arc(cx, cy, r1 - 0.5, a0, a1, 1);
|
|
158
|
+
gfx_arc(cx, cy, r0, a0, a1, 1); gfx_arc(cx, cy, r0 + 0.5, a0, a1, 1);
|
|
159
|
+
ra = (r1 - r0) / 2; rb = (r0 + r1) / 2;
|
|
160
|
+
gfx_circle(cx + sin(a0) * rb, cy - cos(a0) * rb, ra, 1, 1);
|
|
161
|
+
gfx_circle(cx + sin(a1) * rb, cy - cos(a1) * rb, ra, 1, 1);
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// #ui_txt = the label in capitals (drawn small and muted above each widget)
|
|
165
|
+
function ui_caps(s) local(i, c) (
|
|
166
|
+
strcpy(#ui_txt, s); i = 0;
|
|
167
|
+
loop(strlen(#ui_txt), c = str_getchar(#ui_txt, i); (c >= 97 && c <= 122) ? str_setchar(#ui_txt, i, c - 32); i += 1;);
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
function ui_ctext(x, y, w, h) (
|
|
171
|
+
gfx_measurestr(#ui_txt, ui_tw, ui_th);
|
|
172
|
+
gfx_x = x + (w - ui_tw) / 2; gfx_y = y + (h - ui_th) / 2;
|
|
173
|
+
gfx_drawstr(#ui_txt);
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
function ui_chev(cx, cy, up) local(d, k) (
|
|
177
|
+
d = 4 * ui_s; k = 0;
|
|
178
|
+
loop(2,
|
|
179
|
+
gfx_line(cx - d, cy + (up ? d / 2 : -d / 2) + k, cx, cy + (up ? -d / 2 : d / 2) + k, 1);
|
|
180
|
+
gfx_line(cx, cy + (up ? -d / 2 : d / 2) + k, cx + d, cy + (up ? d / 2 : -d / 2) + k, 1);
|
|
181
|
+
k += 1;
|
|
182
|
+
);
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
// The background image: gradient + grain, built on the first frame and when the window size or
|
|
186
|
+
// the accent changes, never per frame. The grain is one 128 px tile of noise made once and tiled.
|
|
187
|
+
function ui_bgbuild() local(x, y, v, m, rt, gt, bt) (
|
|
188
|
+
!ui_tiled ? (
|
|
189
|
+
// Noise centred on the background's own level, so blending it never lifts or dims the page.
|
|
190
|
+
m = ((floor(ui_cBg / 65536) & 255) + (floor(ui_cBg / 256) & 255) + (ui_cBg & 255)) / 765;
|
|
191
|
+
gfx_setimgdim(ui_img_tile, 128, 128); gfx_dest = ui_img_tile;
|
|
192
|
+
y = 0; loop(128, x = 0; loop(128, v = m + (rand(1) - 0.5) * 0.12; gfx_x = x; gfx_y = y; gfx_setpixel(v, v, v); x += 1;); y += 1;);
|
|
193
|
+
ui_tiled = 1;
|
|
194
|
+
);
|
|
195
|
+
gfx_setimgdim(ui_img_bg, gfx_w, gfx_h); gfx_dest = ui_img_bg;
|
|
196
|
+
rt = (floor(ui_cTop / 65536) & 255) / 255; gt = (floor(ui_cTop / 256) & 255) / 255; bt = (ui_cTop & 255) / 255;
|
|
197
|
+
gfx_gradrect(0, 0, gfx_w, gfx_h, rt, gt, bt, 1, 0, 0, 0, 0,
|
|
198
|
+
((floor(ui_cBot / 65536) & 255) / 255 - rt) / gfx_h, ((floor(ui_cBot / 256) & 255) / 255 - gt) / gfx_h, ((ui_cBot & 255) / 255 - bt) / gfx_h, 0);
|
|
199
|
+
gfx_mode = 6; gfx_a = ui_grain; // 2: ignore the tile's alpha, 4: no filtering (crisp grain)
|
|
200
|
+
y = 0; loop(ceil(gfx_h / 128), x = 0; loop(ceil(gfx_w / 128), gfx_blit(ui_img_tile, 1, 0, 0, 0, 128, 128, x, y, 128, 128); x += 128;); y += 128;);
|
|
201
|
+
gfx_mode = 0; gfx_a = 1; gfx_dest = -1;
|
|
202
|
+
ui_bgw = gfx_w; ui_bgh = gfx_h; ui_bgc = ui_cTop;
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
function ui_bg() (
|
|
206
|
+
ui_texture ? (
|
|
207
|
+
(gfx_w != ui_bgw || gfx_h != ui_bgh || ui_bgc != ui_cTop) ? ui_bgbuild();
|
|
208
|
+
gfx_x = 0; gfx_y = 0; gfx_mode = 6; gfx_a = 1;
|
|
209
|
+
gfx_blit(ui_img_bg, 1, 0);
|
|
210
|
+
gfx_mode = 0;
|
|
211
|
+
) : (
|
|
212
|
+
ui_c(ui_cBg, 1); gfx_rect(0, 0, gfx_w, gfx_h);
|
|
213
|
+
);
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
// ---- typing a value ------------------------------------------------------------------------
|
|
217
|
+
|
|
218
|
+
// The value box's text: the value in the knob's display units, without the unit.
|
|
219
|
+
function ui_fmted(fmt, v) (
|
|
220
|
+
fmt == 1 ? sprintf(#ui_edt, "%.1f", v) :
|
|
221
|
+
fmt == 2 ? sprintf(#ui_edt, "%.0f", v * 100) :
|
|
222
|
+
(fmt == 3 || fmt == 4) ? sprintf(#ui_edt, "%.0f", v) :
|
|
223
|
+
fmt == 5 ? sprintf(#ui_edt, "%d", v) :
|
|
224
|
+
sprintf(#ui_edt, "%.2f", v);
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
function ui_edopen(idx, fmt, label, x, y) (
|
|
228
|
+
ui_ed = idx; ui_edfmt = fmt; ui_edx = x; ui_edy = y; ui_edsel = 1;
|
|
229
|
+
strcpy(#ui_edl, label); ui_fmted(fmt, slider(idx));
|
|
230
|
+
while (gfx_getchar() > 0) ( 0; ); // keys typed before the box opened are not part of the value
|
|
231
|
+
ui_active = 0; ui_lci = 0; ui_press = 0;
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
// Enter: read the typed number (digits, one '.', '-', a 'k' = x1000), percent knobs store a
|
|
235
|
+
// fraction, then clamp and snap it like a drag would. Nothing typed = nothing changes.
|
|
236
|
+
function ui_edcommit() local(i, c, v, sg, fr, d, k, any) (
|
|
237
|
+
i = 0; v = 0; sg = 1; fr = 0; d = 1; k = 1; any = 0;
|
|
238
|
+
loop(strlen(#ui_edt),
|
|
239
|
+
c = str_getchar(#ui_edt, i);
|
|
240
|
+
c == 45 ? sg = -sg :
|
|
241
|
+
c == 46 ? fr = 1 :
|
|
242
|
+
c == 107 ? k = 1000 :
|
|
243
|
+
(c >= 48 && c <= 57) ? ( any = 1; fr ? ( d *= 0.1; v += (c - 48) * d; ) : v = v * 10 + c - 48; );
|
|
244
|
+
i += 1;
|
|
245
|
+
);
|
|
246
|
+
any ? (
|
|
247
|
+
v *= sg * k;
|
|
248
|
+
ui_edfmt == 2 ? v /= 100;
|
|
249
|
+
ui_set(ui_ed, ui_q(ui_ed, v)); slider_automate(2 ^ (ui_ed - 1), 1);
|
|
250
|
+
);
|
|
251
|
+
ui_ed = 0;
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
function ui_edkey(c) (
|
|
255
|
+
c == 13 ? ui_edcommit() :
|
|
256
|
+
c == 8 ? (
|
|
257
|
+
ui_edsel ? strcpy(#ui_edt, "") : strlen(#ui_edt) > 0 ? str_delsub(#ui_edt, strlen(#ui_edt) - 1, 1);
|
|
258
|
+
ui_edsel = 0;
|
|
259
|
+
) :
|
|
260
|
+
((c >= 48 && c <= 57) || c == 46 || c == 45 || ((c == 107 || c == 75) && ui_edfmt == 3)) ? (
|
|
261
|
+
ui_edsel ? strcpy(#ui_edt, ""); ui_edsel = 0;
|
|
262
|
+
strlen(#ui_edt) < 12 ? ( sprintf(#ui_tmp, "%c", c == 75 ? 107 : c); strcat(#ui_edt, #ui_tmp); );
|
|
263
|
+
);
|
|
264
|
+
);
|
|
265
|
+
|
|
266
|
+
// Keys are read only while a layer is open. Esc (only delivered with "Send all keyboard input
|
|
267
|
+
// to plug-in") closes the top layer: value box, then About, then the drawer.
|
|
268
|
+
function ui_keys() local(c) (
|
|
269
|
+
(ui_ed || ui_about || ui_adv_open) ? (
|
|
270
|
+
c = gfx_getchar();
|
|
271
|
+
while (c > 0) (
|
|
272
|
+
c == 27 ? ( ui_ed ? ui_ed = 0 : ui_about ? ui_about = 0 : ui_adv_open = 0; ) : ui_ed ? ui_edkey(c);
|
|
273
|
+
ui_edv += 1;
|
|
274
|
+
c = gfx_getchar();
|
|
275
|
+
);
|
|
276
|
+
);
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
// ---- layout -------------------------------------------------------------------------------
|
|
280
|
+
|
|
281
|
+
// Returns 1 when the frame needs drawing. Nothing changed = nothing drawn, the old frame stays.
|
|
282
|
+
// The core rows keep one fixed layout; the Advanced drawer slides over them and never resizes them.
|
|
283
|
+
function ui_begin(core_rows, adv_rows) local(h, i, now, e, top) (
|
|
284
|
+
ui_s = max(gfx_ext_retina, 1);
|
|
285
|
+
ui_pad = 10 * ui_s; ui_lh = 14 * ui_s;
|
|
286
|
+
ui_bar = adv_rows > 0 ? 28 * ui_s : 0;
|
|
287
|
+
ui_down = mouse_cap & 1;
|
|
288
|
+
ui_press = ui_down && !ui_was_down;
|
|
289
|
+
ui_rel = !ui_down && ui_was_down;
|
|
290
|
+
ui_rpress = (mouse_cap & 2) && !ui_was_r;
|
|
291
|
+
ui_was_down = ui_down; ui_was_r = mouse_cap & 2;
|
|
292
|
+
ui_keys();
|
|
293
|
+
ui_modal = ui_ed > 0 || ui_about; // a value box or the About dialog takes every click
|
|
294
|
+
|
|
295
|
+
// the drawer glides open/closed in about 0.15 s
|
|
296
|
+
now = time_precise();
|
|
297
|
+
ui_p < 0 ? ui_p = ui_adv_open;
|
|
298
|
+
ui_p = ui_adv_open ? min(1, ui_p + (now - ui_lt) / 0.15) : max(0, ui_p - (now - ui_lt) / 0.15);
|
|
299
|
+
ui_lt = now;
|
|
300
|
+
|
|
301
|
+
h = gfx_w * 7 + gfx_h * 13 + mouse_x * 3 + mouse_y * 5 + mouse_cap * 11 + ui_adv_open * 17
|
|
302
|
+
+ mouse_wheel * 23 + floor(now * 2) * 19 + ui_p * 29 + ui_ed * 31 + ui_edv * 37 + ui_about * 41;
|
|
303
|
+
i = 1; loop(64, h += slider(i) * (i + 0.37); i += 1;);
|
|
304
|
+
ui_dirty = ui_animated || h != ui_hash || (ui_p > 0 && ui_p < 1);
|
|
305
|
+
ui_hash = h;
|
|
306
|
+
|
|
307
|
+
ui_dirty ? (
|
|
308
|
+
ui_bg();
|
|
309
|
+
gfx_setfont(1, "Arial", 12 * ui_s);
|
|
310
|
+
gfx_setfont(2, "Arial", 9.5 * ui_s, 'b');
|
|
311
|
+
gfx_setfont(3, "Arial", 10.5 * ui_s);
|
|
312
|
+
gfx_setfont(4, "Arial", 15 * ui_s, 'b');
|
|
313
|
+
gfx_setfont(1);
|
|
314
|
+
ui_core = 1;
|
|
315
|
+
ui_blocked = adv_rows > 0 && (ui_adv_open || ui_p > 0);
|
|
316
|
+
// core: the window minus the drawer's closed bar (or the footer line when there is no drawer)
|
|
317
|
+
ui_rowh = (gfx_h - ui_pad - (adv_rows > 0 ? ui_bar + 4 * ui_s : ui_pad + (ui_credit ? 6 * ui_s : 0))) / max(1, core_rows);
|
|
318
|
+
ui_y = ui_pad; ui_mi = 0;
|
|
319
|
+
// the drawer: rows of a comfortable fixed height, leaving a strip of the core view above it
|
|
320
|
+
ui_arowh = adv_rows > 0 ? min(100 * ui_s, max(60 * ui_s, (gfx_h - 40 * ui_s - ui_bar - ui_pad) / adv_rows)) : 0;
|
|
321
|
+
top = max(8 * ui_s, gfx_h - ui_bar - adv_rows * ui_arowh - ui_pad);
|
|
322
|
+
e = ui_p * ui_p * (3 - 2 * ui_p);
|
|
323
|
+
ui_sy = gfx_h - ui_bar - (gfx_h - ui_bar - top) * e;
|
|
324
|
+
ui_e = e;
|
|
325
|
+
);
|
|
326
|
+
ui_dirty;
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
// The footer credit: "reaper-mcp" in the bottom-right corner; a click opens the About dialog.
|
|
330
|
+
// Hidden in a narrow window.
|
|
331
|
+
function ui_footer(y, h) local(x, hit) (
|
|
332
|
+
ui_credit && gfx_w >= 240 * ui_s ? (
|
|
333
|
+
gfx_setfont(2); strcpy(#ui_txt, "reaper-mcp"); gfx_measurestr(#ui_txt, ui_tw, ui_th);
|
|
334
|
+
x = gfx_w - ui_pad - ui_tw - (ui_bar > 0 ? 26 * ui_s : 0);
|
|
335
|
+
hit = mouse_x >= x - 4 * ui_s && mouse_x < x + ui_tw + 4 * ui_s && mouse_y >= y && mouse_y < y + h && !ui_modal;
|
|
336
|
+
ui_c(hit ? ui_cAccent : ui_cMuted, hit ? 1 : 0.55);
|
|
337
|
+
gfx_x = x; gfx_y = y + (h - ui_th) / 2; gfx_drawstr(#ui_txt);
|
|
338
|
+
hit != ui_cur ? ( gfx_setcursor(hit ? 32649 : 32512); ui_cur = hit; );
|
|
339
|
+
hit && ui_press ? ( ui_about = 1; ui_press = 0; );
|
|
340
|
+
gfx_setfont(1);
|
|
341
|
+
hit;
|
|
342
|
+
) : 0;
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
// A panel floating over everything: shadow, hairline, fill.
|
|
346
|
+
function ui_float(x, y, w, h) local(k) (
|
|
347
|
+
k = 0; loop(5, ui_c(0, 0.07 * (5 - k)); ui_rrect(x - k * ui_s, y - k * ui_s + 2 * ui_s, w + 2 * k * ui_s, h + 2 * k * ui_s, 10 * ui_s + k * ui_s); k += 1;);
|
|
348
|
+
ui_c(ui_cLine, 1); ui_rrect(x - ui_s, y - ui_s, w + 2 * ui_s, h + 2 * ui_s, 10 * ui_s);
|
|
349
|
+
ui_c(ui_cPanel, 1); ui_rrect(x, y, w, h, 9 * ui_s);
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
// The value box next to a knob: type, Enter sets it. A click outside it cancels.
|
|
353
|
+
function ui_popover() local(w, h, x, y, fx, fy, fw, fh, tx) (
|
|
354
|
+
w = 132 * ui_s; h = 62 * ui_s;
|
|
355
|
+
x = min(gfx_w - w - 6 * ui_s, max(6 * ui_s, ui_edx - w / 2));
|
|
356
|
+
y = ui_edy + 14 * ui_s; y + h > gfx_h - 6 * ui_s ? y = ui_edy - h - 14 * ui_s; y = max(6 * ui_s, y);
|
|
357
|
+
ui_press && (mouse_x < x || mouse_x >= x + w || mouse_y < y || mouse_y >= y + h) ? ui_ed = 0;
|
|
358
|
+
ui_press = 0;
|
|
359
|
+
ui_ed ? (
|
|
360
|
+
ui_c(ui_cBg, 0.45); gfx_rect(0, 0, gfx_w, gfx_h);
|
|
361
|
+
ui_float(x, y, w, h);
|
|
362
|
+
gfx_setfont(2); ui_caps(#ui_edl); ui_c(ui_cMuted, 1);
|
|
363
|
+
gfx_x = x + 10 * ui_s; gfx_y = y + 8 * ui_s; gfx_drawstr(#ui_txt);
|
|
364
|
+
strcpy(#ui_txt, "ENTER"); gfx_measurestr(#ui_txt, ui_tw, ui_th); ui_c(ui_cMuted, 0.6);
|
|
365
|
+
gfx_x = x + w - 10 * ui_s - ui_tw; gfx_y = y + 8 * ui_s; gfx_drawstr(#ui_txt);
|
|
366
|
+
fx = x + 8 * ui_s; fy = y + 26 * ui_s; fw = w - 16 * ui_s; fh = 26 * ui_s;
|
|
367
|
+
ui_c(ui_cAccent, 1); ui_rrect(fx - ui_s, fy - ui_s, fw + 2 * ui_s, fh + 2 * ui_s, 7 * ui_s);
|
|
368
|
+
ui_c(ui_cBg, 1); ui_rrect(fx, fy, fw, fh, 6 * ui_s);
|
|
369
|
+
gfx_setfont(1); gfx_measurestr(#ui_edt, ui_tw, ui_th);
|
|
370
|
+
tx = fx + 8 * ui_s;
|
|
371
|
+
ui_edsel && ui_tw > 0 ? ( ui_c(ui_cAccent, 0.35); gfx_rect(tx - 2 * ui_s, fy + (fh - ui_th) / 2 - ui_s, ui_tw + 4 * ui_s, ui_th + 2 * ui_s); );
|
|
372
|
+
ui_c(ui_cText, 1); gfx_x = tx; gfx_y = fy + (fh - ui_th) / 2; gfx_drawstr(#ui_edt);
|
|
373
|
+
// caret, blinking
|
|
374
|
+
!ui_edsel && floor(time_precise() * 2) % 2 == 0 ? ( ui_c(ui_cAccent, 1); gfx_rect(tx + ui_tw + ui_s, fy + 6 * ui_s, max(1, ui_s), fh - 12 * ui_s); );
|
|
375
|
+
strcpy(#ui_txt, ui_edfmt == 1 ? "dB" : ui_edfmt == 2 ? "%" : ui_edfmt == 3 ? "Hz" : ui_edfmt == 4 ? "ms" : "");
|
|
376
|
+
gfx_measurestr(#ui_txt, ui_tw, ui_th); ui_c(ui_cMuted, 1);
|
|
377
|
+
gfx_x = fx + fw - 8 * ui_s - ui_tw; gfx_y = fy + (fh - ui_th) / 2; gfx_drawstr(#ui_txt);
|
|
378
|
+
);
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
// One "label value" line of the About dialog.
|
|
382
|
+
function ui_arow(x, y, w, label, val) (
|
|
383
|
+
gfx_setfont(3); ui_c(ui_cMuted, 1); gfx_x = x; gfx_y = y; gfx_drawstr(label);
|
|
384
|
+
ui_c(ui_cText, 1); gfx_x = x + 70 * ui_s; gfx_y = y; gfx_drawstr(val);
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
// The About dialog: what reaper-mcp is, where to find it, and this plugin's facts. Closes on a
|
|
388
|
+
// click outside it or on its x. In a short window the description lines go first.
|
|
389
|
+
function ui_aboutdraw() local(w, h, x, y, lh, nd, rows, bx, cy, hitx) (
|
|
390
|
+
lh = 13 * ui_s;
|
|
391
|
+
nd = max(0, min(3, floor((gfx_h - 16 * ui_s - 186 * ui_s) / lh)));
|
|
392
|
+
rows = nd > 0 ? 6 : max(2, min(6, floor((gfx_h - 16 * ui_s - 108 * ui_s) / lh)));
|
|
393
|
+
w = min(gfx_w - 16 * ui_s, 300 * ui_s);
|
|
394
|
+
h = (12 + 22 + 6 + 4 + 28 + 10 + 16 + 10) * ui_s + nd * lh + rows * lh;
|
|
395
|
+
x = (gfx_w - w) / 2; y = max(8 * ui_s, (gfx_h - h) / 2);
|
|
396
|
+
bx = x + w - 26 * ui_s;
|
|
397
|
+
hitx = mouse_x >= bx && mouse_x < bx + 20 * ui_s && mouse_y >= y + 8 * ui_s && mouse_y < y + 28 * ui_s;
|
|
398
|
+
ui_press && (hitx || mouse_x < x || mouse_x >= x + w || mouse_y < y || mouse_y >= y + h) ? ui_about = 0;
|
|
399
|
+
ui_press = 0;
|
|
400
|
+
hitx != ui_cur ? ( gfx_setcursor(hitx ? 32649 : 32512); ui_cur = hitx; );
|
|
401
|
+
ui_about ? (
|
|
402
|
+
ui_c(ui_cBg, 0.7); gfx_rect(0, 0, gfx_w, gfx_h);
|
|
403
|
+
ui_float(x, y, w, h);
|
|
404
|
+
// close x
|
|
405
|
+
ui_c(hitx ? ui_cText : ui_cMuted, 1); cy = y + 18 * ui_s;
|
|
406
|
+
gfx_line(bx + 6 * ui_s, cy - 4 * ui_s, bx + 14 * ui_s, cy + 4 * ui_s, 1); gfx_line(bx + 6 * ui_s, cy + 4 * ui_s, bx + 14 * ui_s, cy - 4 * ui_s, 1);
|
|
407
|
+
gfx_line(bx + 7 * ui_s, cy - 4 * ui_s, bx + 15 * ui_s, cy + 4 * ui_s, 1); gfx_line(bx + 7 * ui_s, cy + 4 * ui_s, bx + 15 * ui_s, cy - 4 * ui_s, 1);
|
|
408
|
+
// wordmark
|
|
409
|
+
x += 14 * ui_s; y += 12 * ui_s;
|
|
410
|
+
gfx_setfont(4); ui_c(ui_cAccent, 1); gfx_x = x; gfx_y = y; gfx_drawstr("reaper-mcp");
|
|
411
|
+
gfx_setfont(2); ui_c(ui_cMuted, 0.8); strcpy(#ui_txt, "ABOUT"); gfx_measurestr(#ui_txt, ui_tw, ui_th);
|
|
412
|
+
gfx_x += 8 * ui_s; gfx_y = y + 5 * ui_s; gfx_drawstr(#ui_txt);
|
|
413
|
+
y += 22 * ui_s + 6 * ui_s;
|
|
414
|
+
gfx_setfont(3); ui_c(ui_cText, 0.85);
|
|
415
|
+
nd > 0 ? ( gfx_x = x; gfx_y = y; gfx_drawstr("AI-made plugins for REAPER: ask Claude Code to make"); y += lh; );
|
|
416
|
+
nd > 1 ? ( gfx_x = x; gfx_y = y; gfx_drawstr("or tweak one and it writes this file. The plugin then"); y += lh; );
|
|
417
|
+
nd > 2 ? ( gfx_x = x; gfx_y = y; gfx_drawstr("works on its own, without reaper-mcp running."); y += lh; );
|
|
418
|
+
y += 4 * ui_s;
|
|
419
|
+
ui_c(ui_cMuted, 1); gfx_x = x; gfx_y = y; gfx_drawstr("Source and docs (type it into a browser):"); y += 14 * ui_s;
|
|
420
|
+
ui_c(ui_cText, 1); gfx_x = x; gfx_y = y; gfx_drawstr("github.com/mthines/reaper-mcp"); y += 14 * ui_s + 10 * ui_s;
|
|
421
|
+
ui_c(ui_cLine, 1); gfx_rect(x, y - 6 * ui_s, w - 28 * ui_s, max(1, ui_s));
|
|
422
|
+
gfx_setfont(2); ui_c(ui_cMuted, 1); gfx_x = x; gfx_y = y; gfx_drawstr("THIS PLUGIN"); y += 16 * ui_s;
|
|
423
|
+
ui_example ? sprintf(#ui_txt, "%s (example)", #ui_name) : strcpy(#ui_txt, #ui_name);
|
|
424
|
+
ui_arow(x, y, w, "Name", #ui_txt); y += lh;
|
|
425
|
+
rows > 1 ? ( sprintf(#ui_txt, "%d", ui_pver); ui_arow(x, y, w, "Version", #ui_txt); y += lh; );
|
|
426
|
+
rows > 2 ? ( sprintf(#ui_txt, "mcp_ui %s", #ui_tkv); ui_arow(x, y, w, "Toolkit", #ui_txt); y += lh; );
|
|
427
|
+
rows > 3 ? (
|
|
428
|
+
sprintf(#ui_txt, " %s #%06x", ui_akind == 2 ? "custom" : ui_akind == 1 ? "named" : "auto", ui_cAccent);
|
|
429
|
+
ui_arow(x, y, w, "Accent", #ui_txt);
|
|
430
|
+
ui_c(ui_cAccent, 1); gfx_circle(x + 70 * ui_s + 5 * ui_s, y + 6.5 * ui_s, 4.5 * ui_s, 1, 1);
|
|
431
|
+
y += lh;
|
|
432
|
+
);
|
|
433
|
+
rows > 4 ? ( sprintf(#ui_txt, "%d", ui_nctl); ui_arow(x, y, w, "Controls", #ui_txt); y += lh; );
|
|
434
|
+
rows > 5 ? ( ui_arow(x, y, w, "Written", strlen(#ui_date) ? #ui_date : "-"); y += lh; );
|
|
435
|
+
gfx_setfont(1);
|
|
436
|
+
);
|
|
437
|
+
);
|
|
438
|
+
|
|
439
|
+
function ui_end() (
|
|
440
|
+
ui_bar == 0 ? ui_footer(gfx_h - ui_pad - 6 * ui_s, ui_pad + 6 * ui_s);
|
|
441
|
+
ui_ed ? ui_popover() : ui_about ? ui_aboutdraw();
|
|
442
|
+
mouse_wheel = 0;
|
|
443
|
+
);
|
|
444
|
+
|
|
445
|
+
function ui_row(n) (
|
|
446
|
+
ui_ci = 0; ui_n = max(1, n);
|
|
447
|
+
ui_cw = (gfx_w - 2 * ui_pad) / ui_n;
|
|
448
|
+
ui_ry0 = ui_y; ui_y += ui_rowh;
|
|
449
|
+
);
|
|
450
|
+
|
|
451
|
+
function ui_cell() (
|
|
452
|
+
ui_rx = ui_pad + ui_ci * ui_cw; ui_ry = ui_ry0; ui_rw = ui_cw; ui_rh = ui_rowh;
|
|
453
|
+
ui_ci += 1;
|
|
454
|
+
ui_hit = mouse_x >= ui_rx && mouse_x < ui_rx + ui_rw && mouse_y >= ui_ry && mouse_y < ui_ry + ui_rh
|
|
455
|
+
&& !(ui_core && ui_blocked) && !ui_modal;
|
|
456
|
+
// every widget is one block centred in its cell: label, body (a knob's height), value.
|
|
457
|
+
// The same for every cell of a row, so labels and values line up across widget types.
|
|
458
|
+
ui_kr = max(4 * ui_s, min(64 * ui_s, min(ui_rw / 2 - 8 * ui_s, (ui_rh - 2 * ui_lh - 22 * ui_s) / 2)));
|
|
459
|
+
ui_lby = ui_ry + (ui_rh - 2 * ui_lh - 12 * ui_s - 2 * ui_kr) / 2;
|
|
460
|
+
ui_by = ui_lby + ui_lh + 6 * ui_s; ui_bh = 2 * ui_kr;
|
|
461
|
+
);
|
|
462
|
+
|
|
463
|
+
// label (top) and value line (bottom) of the current cell; #ui_txt holds the value
|
|
464
|
+
function ui_label(label, hot) (
|
|
465
|
+
gfx_setfont(2); ui_caps(label);
|
|
466
|
+
ui_c(hot ? ui_cText : ui_cMuted, 1); ui_ctext(ui_rx, ui_lby, ui_rw, ui_lh);
|
|
467
|
+
gfx_setfont(1);
|
|
468
|
+
);
|
|
469
|
+
function ui_value(col) ( ui_c(col, 1); ui_ctext(ui_rx, ui_by + ui_bh + 6 * ui_s, ui_rw, ui_lh); );
|
|
470
|
+
|
|
471
|
+
// fmt: 0 number, 1 dB, 2 percent of 0..1, 3 Hz/kHz, 4 ms, 5 integer
|
|
472
|
+
function ui_fmtv(fmt, v) (
|
|
473
|
+
fmt == 1 ? sprintf(#ui_txt, "%.1f dB", v) :
|
|
474
|
+
fmt == 2 ? sprintf(#ui_txt, "%.0f%%", v * 100) :
|
|
475
|
+
fmt == 3 ? (v >= 1000 ? sprintf(#ui_txt, "%.1f kHz", v / 1000) : sprintf(#ui_txt, "%.0f Hz", v)) :
|
|
476
|
+
fmt == 4 ? sprintf(#ui_txt, "%.0f ms", v) :
|
|
477
|
+
fmt == 5 ? sprintf(#ui_txt, "%d", v) :
|
|
478
|
+
sprintf(#ui_txt, "%.2f", v);
|
|
479
|
+
);
|
|
480
|
+
|
|
481
|
+
// Drag (200 px = the full range, Shift = 10x finer), wheel, Cmd/Ctrl/Alt-click = default
|
|
482
|
+
// (mouse_cap 4 = Cmd on macOS / Ctrl elsewhere, 32 = Ctrl on macOS, 16 = Alt), double-click =
|
|
483
|
+
// type a value (a box opens next to the knob at x, y).
|
|
484
|
+
function ui_reset(idx) ( ui_set(idx, ui_def[idx]); slider_automate(2 ^ (idx - 1), 1); ui_lci = 0; );
|
|
485
|
+
function ui_ctl(idx, fmt, label, x, y) local(lo, hi, st, t, fine) (
|
|
486
|
+
lo = ui_min[idx]; hi = ui_max[idx]; st = ui_stp[idx];
|
|
487
|
+
ui_hit && ui_press ? (
|
|
488
|
+
t = time_precise();
|
|
489
|
+
(mouse_cap & 52) ? ui_reset(idx) :
|
|
490
|
+
(ui_lci == idx && t - ui_lct < 0.45) ? ui_edopen(idx, fmt, label, x, y) :
|
|
491
|
+
( ui_active = idx; ui_ly = mouse_y; ui_acc = slider(idx); ui_lci = idx; ui_lct = t; );
|
|
492
|
+
);
|
|
493
|
+
ui_active == idx && ui_down ? (
|
|
494
|
+
fine = mouse_cap & 8;
|
|
495
|
+
ui_acc += (ui_ly - mouse_y) / (200 * ui_s * (fine ? 10 : 1)) * (hi - lo);
|
|
496
|
+
ui_acc = min(hi, max(lo, ui_acc));
|
|
497
|
+
ui_ly = mouse_y;
|
|
498
|
+
ui_set(idx, ui_q(idx, ui_acc));
|
|
499
|
+
);
|
|
500
|
+
ui_hit && mouse_wheel != 0 ? (
|
|
501
|
+
ui_set(idx, ui_q(idx, slider(idx) + sign(mouse_wheel) * (st > 0 ? st : (hi - lo) / ((mouse_cap & 8) ? 200 : 40))));
|
|
502
|
+
);
|
|
503
|
+
ui_active == idx && ui_rel ? ( slider_automate(2 ^ (idx - 1), 1); ui_active = 0; );
|
|
504
|
+
);
|
|
505
|
+
|
|
506
|
+
// ---- widgets ------------------------------------------------------------------------------
|
|
507
|
+
|
|
508
|
+
// A ring knob: dim track, one accent stroke for the value (from 0 when the range crosses it),
|
|
509
|
+
// a face with a dot pointing at the value. 7:30 to 4:30 o'clock.
|
|
510
|
+
function ui_knob(idx, label, fmt) local(lo, hi, t, t0, r, th, cx, cy, a0, a1, av, aa, fr, hot, dr) (
|
|
511
|
+
ui_cell(); ui_ctl(idx, fmt, label, ui_rx + ui_rw / 2, ui_by + ui_bh / 2);
|
|
512
|
+
lo = ui_min[idx]; hi = ui_max[idx];
|
|
513
|
+
t = min(1, max(0, (slider(idx) - lo) / (hi - lo)));
|
|
514
|
+
t0 = (lo < 0 && hi > 0) ? -lo / (hi - lo) : 0;
|
|
515
|
+
hot = ui_active == idx || ui_hit;
|
|
516
|
+
r = ui_kr;
|
|
517
|
+
cx = ui_rx + ui_rw / 2; cy = ui_by + ui_bh / 2;
|
|
518
|
+
th = max(3 * ui_s, r * 0.14);
|
|
519
|
+
a0 = -2.35; a1 = 2.35;
|
|
520
|
+
av = a0 + (a1 - a0) * t; aa = a0 + (a1 - a0) * t0;
|
|
521
|
+
ui_c(hot ? ui_cTrackHot : ui_cTrack, 1); ui_ring(cx, cy, r - th, r, a0, a1);
|
|
522
|
+
abs(t - t0) > 0.002 ? (
|
|
523
|
+
ui_c(ui_active == idx ? ui_cAccentAct : (hot ? ui_cAccentHi : ui_cAccent), 1);
|
|
524
|
+
ui_ring(cx, cy, r - th, r, min(aa, av), max(aa, av));
|
|
525
|
+
);
|
|
526
|
+
fr = r - th - max(3 * ui_s, r * 0.12);
|
|
527
|
+
fr > 4 * ui_s ? (
|
|
528
|
+
ui_cm(ui_cPanel2, ui_cLine, hot ? 0.9 : 0.4); gfx_circle(cx, cy, fr, 1, 1);
|
|
529
|
+
ui_cm(ui_cLine, ui_cMuted, hot ? 0.3 : 0.15); gfx_circle(cx, cy, fr, 0, 1);
|
|
530
|
+
dr = max(1.5 * ui_s, fr * 0.12);
|
|
531
|
+
ui_c(hot ? ui_cAccent : ui_cText, 1);
|
|
532
|
+
gfx_circle(cx + sin(av) * (fr - dr * 2.2), cy - cos(av) * (fr - dr * 2.2), dr, 1, 1);
|
|
533
|
+
);
|
|
534
|
+
ui_label(label, hot);
|
|
535
|
+
ui_fmtv(fmt, slider(idx)); ui_value(ui_active == idx ? ui_cAccent : ui_cText);
|
|
536
|
+
);
|
|
537
|
+
|
|
538
|
+
function ui_toggle(idx, label) local(on, w, h, x, y, hot) (
|
|
539
|
+
ui_cell();
|
|
540
|
+
ui_hit && ui_press ? ( (mouse_cap & 52) ? ui_reset(idx) : ( ui_set(idx, slider(idx) ? 0 : 1); slider_automate(2 ^ (idx - 1), 1); ); );
|
|
541
|
+
on = slider(idx) > 0.5; hot = ui_hit;
|
|
542
|
+
w = min(ui_rw - 12 * ui_s, 42 * ui_s); h = 22 * ui_s;
|
|
543
|
+
x = ui_rx + (ui_rw - w) / 2; y = ui_by + (ui_bh - h) / 2;
|
|
544
|
+
on ? ui_c(hot ? ui_cAccentHi : ui_cAccent, 1) : ui_cm(ui_cLine, ui_cMuted, hot ? 0.2 : 0.06);
|
|
545
|
+
ui_rrect(x, y, w, h, h / 2);
|
|
546
|
+
ui_c(on ? ui_cBg : ui_cText, on ? 1 : 0.75);
|
|
547
|
+
gfx_circle(on ? x + w - h / 2 - 1 : x + h / 2, y + h / 2 - 0.5, h / 2 - 3 * ui_s, 1, 1);
|
|
548
|
+
ui_label(label, hot);
|
|
549
|
+
strcpy(#ui_txt, on ? "On" : "Off"); ui_value(on ? ui_cAccent : ui_cMuted);
|
|
550
|
+
);
|
|
551
|
+
|
|
552
|
+
// Click = next option, right-click = previous, Cmd/Ctrl/Alt-click = default. Option names come from the slider's {A,B,C} list.
|
|
553
|
+
function ui_choice(idx, label) local(n, k, w, h, x, y, hot, m) (
|
|
554
|
+
ui_cell();
|
|
555
|
+
n = ui_max[idx] - ui_min[idx] + 1; k = slider(idx) - ui_min[idx];
|
|
556
|
+
ui_hit && ui_press ? ( (mouse_cap & 52) ? ui_reset(idx) : ( ui_set(idx, ui_min[idx] + (k + 1) % n); slider_automate(2 ^ (idx - 1), 1); ); );
|
|
557
|
+
ui_hit && ui_rpress ? ( ui_set(idx, ui_min[idx] + (k + n - 1) % n); slider_automate(2 ^ (idx - 1), 1); );
|
|
558
|
+
k = slider(idx) - ui_min[idx]; hot = ui_hit;
|
|
559
|
+
w = min(ui_rw - 12 * ui_s, 104 * ui_s); h = 24 * ui_s;
|
|
560
|
+
x = ui_rx + (ui_rw - w) / 2; y = ui_by + (ui_bh - h) / 2;
|
|
561
|
+
ui_cm(ui_cPanel2, ui_cLine, hot ? 0.9 : 0.35); ui_rrect(x, y, w, h, 6 * ui_s);
|
|
562
|
+
ui_c(hot ? ui_cAccent : ui_cLine, 1); gfx_roundrect(x, y, w - 1, h - 1, 6 * ui_s, 1);
|
|
563
|
+
ui_c(ui_cText, 1); strcpy(#ui_txt, idx * 8 + k); ui_ctext(x, y, w, h);
|
|
564
|
+
// small arrows at both ends: it steps
|
|
565
|
+
m = y + h / 2; ui_c(hot ? ui_cAccent : ui_cMuted, 1);
|
|
566
|
+
gfx_triangle(x + 7 * ui_s, m, x + 11 * ui_s, m - 3.5 * ui_s, x + 11 * ui_s, m + 3.5 * ui_s);
|
|
567
|
+
gfx_triangle(x + w - 7 * ui_s, m, x + w - 11 * ui_s, m - 3.5 * ui_s, x + w - 11 * ui_s, m + 3.5 * ui_s);
|
|
568
|
+
ui_label(label, hot);
|
|
569
|
+
sprintf(#ui_txt, "%d / %d", k + 1, n); ui_value(ui_cMuted);
|
|
570
|
+
);
|
|
571
|
+
|
|
572
|
+
// level: the peak (linear) the audio thread kept with max(); reset it to 0 after the call.
|
|
573
|
+
// Holds a fast attack and a 30 dB/s release, drawn from -60 to +6 dB.
|
|
574
|
+
function ui_meter(level, label) local(db, p, now, base, w, h, x, y, t, fh, z) (
|
|
575
|
+
ui_cell();
|
|
576
|
+
now = time_precise(); base = ui_mtr + ui_mi * 2; ui_mi += 1;
|
|
577
|
+
db = 20 * log10(max(level, 0.000001));
|
|
578
|
+
p = ui_mtr[base] - 30 * (now - ui_mtr[base + 1]);
|
|
579
|
+
ui_mtr[base] = max(max(db, p), -60); ui_mtr[base + 1] = now;
|
|
580
|
+
w = 8 * ui_s; h = ui_bh;
|
|
581
|
+
x = ui_rx + (ui_rw - w) / 2; y = ui_by;
|
|
582
|
+
ui_cm(ui_cPanel2, ui_cLine, 0.5); ui_rrect(x, y, w, h, w / 2);
|
|
583
|
+
t = (ui_mtr[base] + 60) / 66; fh = h * t;
|
|
584
|
+
fh > 1 ? (
|
|
585
|
+
ui_c(ui_mtr[base] > -0.5 ? ui_cBad : (ui_mtr[base] > -6 ? ui_cWarn : ui_cLive), 1);
|
|
586
|
+
ui_rrect(x, y + h - fh, w, fh, min(w / 2, fh / 2));
|
|
587
|
+
);
|
|
588
|
+
// ticks at 0 and -12 dB
|
|
589
|
+
z = y + h * 6 / 66; ui_c(ui_cMuted, 0.8); gfx_rect(x - 4 * ui_s, z, 3 * ui_s, max(1, ui_s));
|
|
590
|
+
gfx_rect(x + w + ui_s, z, 3 * ui_s, max(1, ui_s));
|
|
591
|
+
z = y + h * 18 / 66; ui_c(ui_cMuted, 0.4); gfx_rect(x - 3 * ui_s, z, 2 * ui_s, max(1, ui_s));
|
|
592
|
+
gfx_rect(x + w + ui_s, z, 2 * ui_s, max(1, ui_s));
|
|
593
|
+
ui_label(label, 0);
|
|
594
|
+
ui_mtr[base] > -59.5 ? sprintf(#ui_txt, "%.1f", ui_mtr[base]) : strcpy(#ui_txt, "-inf");
|
|
595
|
+
ui_value(ui_mtr[base] > -0.5 ? ui_cBad : ui_cMuted);
|
|
596
|
+
);
|
|
597
|
+
|
|
598
|
+
// The Advanced drawer. Closed: a bar along the bottom. Open: a panel that slides up over the
|
|
599
|
+
// core view (which keeps its size and dims behind it). Returns 1 while visible: draw the
|
|
600
|
+
// Advanced rows then. Close it with the bar or a click above it (or Esc, only when the FX window
|
|
601
|
+
// sends all keyboard input to the plug-in; see the header).
|
|
602
|
+
function ui_section(label) local(y, hit, k) (
|
|
603
|
+
ui_bar == 0 ? ui_bar = 28 * ui_s;
|
|
604
|
+
y = ui_sy;
|
|
605
|
+
ui_e > 0 ? (
|
|
606
|
+
ui_c(ui_cBg, 0.62 * ui_e); gfx_rect(0, 0, gfx_w, y);
|
|
607
|
+
ui_adv_open && ui_press && mouse_y < y && !ui_modal ? ( ui_adv_open = 0; ui_press = 0; );
|
|
608
|
+
// soft shadow above the panel
|
|
609
|
+
k = 0; loop(6, ui_c(0, 0.05 * ui_e * (6 - k)); gfx_rect(0, y - k * ui_s - ui_s, gfx_w, ui_s); k += 1;);
|
|
610
|
+
);
|
|
611
|
+
ui_c(ui_cPanel, 1); ui_rrect(0, y, gfx_w, gfx_h - y + 14 * ui_s, 12 * ui_s);
|
|
612
|
+
ui_c(ui_cLine, 1); gfx_roundrect(0, y, gfx_w - 1, gfx_h - y + 14 * ui_s, 12 * ui_s, 1);
|
|
613
|
+
hit = mouse_y >= y && mouse_y < y + ui_bar && mouse_x >= 0 && mouse_x < gfx_w && !ui_modal;
|
|
614
|
+
ui_footer(y, ui_bar) ? hit = 0;
|
|
615
|
+
hit && ui_press ? ( ui_adv_open = !ui_adv_open; ui_press = 0; );
|
|
616
|
+
// grab handle, title, chevron
|
|
617
|
+
ui_cm(ui_cLine, ui_cMuted, hit ? 0.5 : 0.25); ui_rrect(gfx_w / 2 - 14 * ui_s, y + 5 * ui_s, 28 * ui_s, 3 * ui_s, 1.5 * ui_s);
|
|
618
|
+
gfx_setfont(2); ui_caps(label);
|
|
619
|
+
ui_c(hit || ui_adv_open ? ui_cAccent : ui_cMuted, 1);
|
|
620
|
+
gfx_measurestr(#ui_txt, ui_tw, ui_th);
|
|
621
|
+
gfx_x = ui_pad + 2 * ui_s; gfx_y = y + (ui_bar - ui_th) / 2 + 2 * ui_s; gfx_drawstr(#ui_txt);
|
|
622
|
+
gfx_setfont(1);
|
|
623
|
+
ui_c(hit ? ui_cAccent : ui_cMuted, 1); ui_chev(gfx_w - ui_pad - 6 * ui_s, y + ui_bar / 2 + ui_s, !ui_adv_open);
|
|
624
|
+
ui_core = 0;
|
|
625
|
+
ui_y = y + ui_bar; ui_rowh = ui_arowh;
|
|
626
|
+
ui_e > 0;
|
|
627
|
+
);
|