@mthines/reaper-mcp 0.73.0 → 0.75.0-beta.89.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.
package/main.js CHANGED
@@ -4453,6 +4453,71 @@ function ensureSnapshotActions(kb) {
4453
4453
  const body = kb === "" || kb.endsWith("\n") ? kb : kb + eol;
4454
4454
  return { kb: body + lines.join(eol) + eol, added };
4455
4455
  }
4456
+ var AUTOSTART_MARKER = "reaper-mcp: start the bridge with REAPER";
4457
+ var AUTOSTART_BEGIN = `-- ${AUTOSTART_MARKER} (begin)`;
4458
+ var AUTOSTART_END = `-- ${AUTOSTART_MARKER} (end)`;
4459
+ var AUTOSTART_BLOCK = [
4460
+ AUTOSTART_BEGIN,
4461
+ "-- Written by `reaper-mcp setup`. Turn it off in the bridge window: Settings \u2192 Start with REAPER.",
4462
+ "do",
4463
+ ' local bridge = reaper.GetResourcePath() .. "/Scripts/mcp_bridge.lua"',
4464
+ ' if reaper.GetExtState("MCPBridge", "cfg_autostart") ~= "0" and reaper.file_exists(bridge) then',
4465
+ " local id = reaper.AddRemoveReaScript(true, 0, bridge, true)",
4466
+ " if id and id > 0 then reaper.Main_OnCommand(id, 0) end",
4467
+ " end",
4468
+ "end",
4469
+ AUTOSTART_END
4470
+ ];
4471
+ function ensureBridgeAutostart(startup) {
4472
+ const eol = startup.includes("\r\n") ? "\r\n" : "\n";
4473
+ const block = AUTOSTART_BLOCK.join(eol);
4474
+ const lines = startup.split(/\r?\n/);
4475
+ const begin = lines.indexOf(AUTOSTART_BEGIN);
4476
+ const end = begin === -1 ? -1 : lines.indexOf(AUTOSTART_END, begin);
4477
+ let text7;
4478
+ if (begin !== -1 && end !== -1) {
4479
+ text7 = [...lines.slice(0, begin), ...AUTOSTART_BLOCK, ...lines.slice(end + 1)].join(eol);
4480
+ } else if (startup.trim() === "") {
4481
+ text7 = block + eol;
4482
+ } else {
4483
+ text7 = block + eol + eol + startup;
4484
+ }
4485
+ return { text: text7, changed: text7 !== startup };
4486
+ }
4487
+ function readExtState(ini, section, key) {
4488
+ let inSection = false;
4489
+ for (const line of ini.split(/\r?\n/)) {
4490
+ const header = /^\s*\[(.*)\]\s*$/.exec(line);
4491
+ if (header) {
4492
+ inSection = header[1] === section;
4493
+ } else if (inSection) {
4494
+ const eq = line.indexOf("=");
4495
+ if (eq !== -1 && line.slice(0, eq).trim() === key) return line.slice(eq + 1).trim();
4496
+ }
4497
+ }
4498
+ return void 0;
4499
+ }
4500
+ function autostartCheck(startup, extstate, reaperRunning) {
4501
+ const label = "Start with REAPER";
4502
+ if (startup === null || !startup.includes(AUTOSTART_MARKER)) {
4503
+ return {
4504
+ label,
4505
+ status: "warn",
4506
+ detail: "Not in REAPER's Scripts/__startup.lua: run mcp_bridge.lua by hand in each REAPER session",
4507
+ fix: "reaper-mcp setup"
4508
+ };
4509
+ }
4510
+ const saved = reaperRunning ? " (as REAPER last saved it)" : "";
4511
+ if (extstate !== null && readExtState(extstate, "MCPBridge", "cfg_autostart") === "0") {
4512
+ return {
4513
+ label,
4514
+ status: "info",
4515
+ detail: `Off in the bridge window${saved}: run mcp_bridge.lua by hand in each REAPER session`,
4516
+ fix: "turn it back on in the bridge window: Settings \u2192 Start with REAPER"
4517
+ };
4518
+ }
4519
+ return { label, status: "ok", detail: `On \xB7 REAPER's startup script runs the bridge at launch${saved}` };
4520
+ }
4456
4521
  var MCP_TOOL_NAMES = [
4457
4522
  // project
4458
4523
  "get_project_info",
@@ -5863,7 +5928,7 @@ function registerOfflineTools(server) {
5863
5928
  );
5864
5929
  server.tool(
5865
5930
  "verify_edit",
5866
- `Check the result of an edit you just made, since you cannot hear it: compare the edited track with the audio from before the edit and get a verdict per check. Compensated null: the delay (ms, + = later), gain (dB) and polarity between the two are estimated and removed, and the residual left (dB below the reference) says whether anything else changed (noise, a splice, a different waveform, a swapped stereo channel; it is relative to referenceRmsDb, so with a quiet reference the rounding noise of a 16-bit bounce can set it). Discontinuity: the largest sample-to-sample jump on any channel against the reference's own, with where it happens and which channel (a click or hard splice). Use expect 'identical' (default) for edits that should leave the sound alone apart from level, delay and polarity (alignment, gain, split, crossfade): the residual is judged ok/warn/fail. Use "changed" for EQ, compression and the like: the residual is reported without a verdict. Set timeScale to the playback rate when the edit changed the timing (1.1 = the edit is 10% shorter): the waveform null is then skipped and the click check runs with three warn-only character checks against the reference warped through that rate: pitch drift in cents (skipped for unpitched material), tone (long-term spectrum distance in dB) and transients (smeared attacks). The reference is another track (e.g. a copy you kept) or an audio file of the same range from before the edit (a bounce), not an undo. Keep a reference track unmuted so it renders. The tone check misses a phase vocoder's smearing and the transient check is blind on drums. A passing result is evidence, not a replacement for listening. Requires the Python sidecar.`,
5931
+ `Check the result of an edit you just made, since you cannot hear it: compare the edited track with the audio from before the edit and get a verdict per check. Compensated null: the delay (ms, + = later), gain (dB) and polarity between the two are estimated and removed, and the residual left (dB below the reference) says whether anything else changed (noise, a splice, a different waveform, a swapped stereo channel; it is relative to referenceRmsDb, so with a quiet reference the rounding noise of a 16-bit bounce can set it). Discontinuity: the largest sample-to-sample jump on any channel against the reference's own, with where it happens and which channel (a click or hard splice). Use expect 'identical' (default) for edits that should leave the sound alone apart from level, delay and polarity (alignment, gain, split, crossfade): the residual is judged ok/warn/fail. Use "changed" for EQ, compression and the like: the residual is reported without a verdict. Set timeScale to the playback rate when the edit changed the timing (1.1 = the edit is 10% shorter): the waveform null is then skipped and the click check runs with three warn-only character checks against the reference warped through that rate: pitch drift in cents (skipped for unpitched material), tone (long-term spectrum distance in dB, line 1.5 dB, provisional) and transients (smeared attacks). When the pitch moved by what the speed change alone causes (a plain speed change, pitch follows speed), pitch and tone are reported as info, not warned; a pitch move the speed does not explain still warns. None of them hears the stretch artifact of a large slow-down: listen to those. The reference is another track (e.g. a copy you kept) or an audio file of the same range from before the edit (a bounce), not an undo. Keep a reference track unmuted so it renders. The tone check misses a phase vocoder's smearing and the transient check is blind on drums. A passing result is evidence, not a replacement for listening. Requires the Python sidecar.`,
5867
5932
  {
5868
5933
  trackIndex: z28.coerce.number().int().min(0).describe("Zero-based index of the edited track"),
5869
5934
  referenceTrack: z28.coerce.number().int().min(0).optional().describe("Zero-based index of a track holding the audio from before the edit (give this or referencePath)"),
@@ -9215,15 +9280,15 @@ async function setup() {
9215
9280
  } else {
9216
9281
  console.log(` Not found: ${join12(wwwSrc, BRIDGE_UI_FILE)} (build bridge-ui first)`);
9217
9282
  }
9283
+ installBridgeAutostart(scriptsDir);
9218
9284
  const webPort = await enableWebInterface();
9219
9285
  await registerSnapshotActions();
9220
9286
  console.log("\nSetup complete!\n");
9221
9287
  console.log("Next steps:");
9222
- console.log(" 1. Open REAPER");
9223
- console.log(" 2. Actions > Show action list > Load ReaScript");
9224
- console.log(` 3. Select: ${join12(scriptsDir, "mcp_bridge.lua")}`);
9225
- console.log(" 4. Run the script (it will keep running in background via defer loop)");
9226
- console.log(" 5. Add reaper-mcp to your Claude Code config (see: reaper-mcp doctor)");
9288
+ console.log(" 1. Start REAPER: the bridge starts with it. If REAPER is already open, restart it,");
9289
+ console.log(" or run the bridge once by hand: Actions > Show action list > Load ReaScript,");
9290
+ console.log(` select ${join12(scriptsDir, "mcp_bridge.lua")} and click Run.`);
9291
+ console.log(" 2. Add reaper-mcp to your Claude Code config (see: reaper-mcp doctor)");
9227
9292
  if (webPort) {
9228
9293
  console.log(`
9229
9294
  The bridge opens its status window on start: http://localhost:${webPort}/${BRIDGE_UI_FILE}`);
@@ -9275,6 +9340,14 @@ async function enableWebInterface() {
9275
9340
  console.log(` Enabled on port ${result.port} (override with REAPER_WEB_PORT)`);
9276
9341
  return result.port;
9277
9342
  }
9343
+ function installBridgeAutostart(scriptsDir) {
9344
+ console.log("\nStarting the bridge with REAPER...");
9345
+ const path = join12(scriptsDir, "__startup.lua");
9346
+ const { text: text7, changed } = ensureBridgeAutostart(existsSync7(path) ? readFileSync5(path, "utf-8") : "");
9347
+ if (changed) writeFileSync5(path, text7, "utf-8");
9348
+ console.log(changed ? " Added to Scripts/__startup.lua (REAPER runs it at launch)" : " Already in Scripts/__startup.lua");
9349
+ console.log(" Turn it off in the bridge window: Settings > Start with REAPER.");
9350
+ }
9278
9351
  async function registerSnapshotActions() {
9279
9352
  console.log("\nRegistering snapshot actions (quick save, next, previous)...");
9280
9353
  const kbPath = join12(getReaperResourcePath(), "reaper-kb.ini");
@@ -9316,7 +9389,7 @@ async function init() {
9316
9389
  console.log("\nIf you haven't yet, install the bridge:");
9317
9390
  }
9318
9391
  console.log(" reaper-mcp setup # Lua bridge + JSFX \u2192 REAPER");
9319
- console.log("then load mcp_bridge.lua in REAPER.");
9392
+ console.log("then start (or restart) REAPER: the bridge starts with it.");
9320
9393
  if (!findCloneRoot(__dirname2)) console.log("\nWant it to remember plugins and your corrections? Connect LoreKit (free): https://lorekit.io. /learn-plugin will walk you through it.");
9321
9394
  console.log('\nTry: /mixer "Please gain stage my tracks" \xB7 /critique "Roast my mix"');
9322
9395
  }
@@ -9400,6 +9473,12 @@ async function doctor() {
9400
9473
  core2.push(
9401
9474
  bridgeRunning ? { label: "Lua bridge", status: "ok", detail: "Connected" } : { label: "Lua bridge", status: "fail", detail: "Not detected", fix: "reaper-mcp setup, then run mcp_bridge.lua in REAPER" }
9402
9475
  );
9476
+ const readIfExists = (path) => existsSync7(path) ? readFileSync5(path, "utf-8") : null;
9477
+ core2.push(autostartCheck(
9478
+ readIfExists(join12(getReaperScriptsPath(), "__startup.lua")),
9479
+ readIfExists(join12(getReaperResourcePath(), "reaper-extstate.ini")),
9480
+ await isReaperRunning()
9481
+ ));
9403
9482
  const globalClaudeDir = join12(homedir8(), ".claude");
9404
9483
  const localSkills = existsSync7(join12(process.cwd(), ".claude", "skills", "mixer", "SKILL.md"));
9405
9484
  const globalSkills = existsSync7(join12(globalClaudeDir, "skills", "mixer", "SKILL.md"));
@@ -9651,11 +9730,11 @@ Usage:
9651
9730
  Quick Start (from npm):
9652
9731
  npm install -g @mthines/reaper-mcp
9653
9732
  reaper-mcp setup && reaper-mcp init # bridge into REAPER, tools + skills into Claude Code
9654
- # then load mcp_bridge.lua in REAPER (Actions > Load ReaScript > Run)
9733
+ # then start (or restart) REAPER: the bridge starts with it
9655
9734
 
9656
9735
  Quick Start (from your clone):
9657
9736
  ./scripts/install.sh # build, link CLI, bridge, symlink skills + knowledge, configure
9658
- # then load mcp_bridge.lua in REAPER (Actions > Load ReaScript > Run)
9737
+ # then start (or restart) REAPER: the bridge starts with it
9659
9738
 
9660
9739
  Then in Claude Code:
9661
9740
  /mixer "Please gain stage my tracks" \xB7 /critique "Roast my mix"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mthines/reaper-mcp",
3
- "version": "0.73.0",
3
+ "version": "0.75.0-beta.89.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",
@@ -4668,6 +4668,7 @@ end
4668
4668
 
4669
4669
  -- Settings written by the status page through REAPER's web interface (/_/SET/EXTSTATE...).
4670
4670
  -- cfg_paused is in-memory only (resets with REAPER); the others persist in reaper-extstate.ini.
4671
+ -- cfg_autostart is read at REAPER's launch by the startup block setup writes into Scripts/__startup.lua.
4671
4672
  local function cfg(key)
4672
4673
  return reaper.GetExtState(STATUS_SECTION, key) == "1"
4673
4674
  end
@@ -4692,7 +4693,7 @@ local _, script_path, _, script_cmd_id = reaper.get_action_context()
4692
4693
  local script_source = script_path and read_file(script_path)
4693
4694
  local HEALTH_INTERVAL = 10
4694
4695
  local last_health_check = -HEALTH_INTERVAL
4695
- local health = { sws = false, jsfx = true, outdated = false }
4696
+ local health = { sws = false, jsfx = true, outdated = false, autostart = false }
4696
4697
  local JSFX_FILES = { "mcp_analyzer.jsfx", "mcp_lufs_meter.jsfx", "mcp_correlation_meter.jsfx", "mcp_crest_factor.jsfx", "mcp_midi_emitter.jsfx" }
4697
4698
 
4698
4699
  local function check_health(now)
@@ -4710,8 +4711,13 @@ local function check_health(now)
4710
4711
  missingJsfx = #missing > 0 and missing or nil,
4711
4712
  -- The installed script changed under us (setup ran): this running copy is stale until restarted
4712
4713
  outdated = script_source ~= nil and installed ~= nil and installed ~= script_source,
4714
+ -- REAPER's startup script holds the block `reaper-mcp setup` writes (AUTOSTART_BLOCK in cli.ts), which
4715
+ -- starts the bridge with REAPER unless the page's cfg_autostart is "0"
4716
+ autostart = ((read_file(reaper.GetResourcePath() .. "/Scripts/__startup.lua") or "")
4717
+ :find("reaper-mcp: start the bridge with REAPER", 1, true)) ~= nil,
4713
4718
  }
4714
- if next_health.sws ~= health.sws or next_health.jsfx ~= health.jsfx or next_health.outdated ~= health.outdated then
4719
+ if next_health.sws ~= health.sws or next_health.jsfx ~= health.jsfx or next_health.outdated ~= health.outdated
4720
+ or next_health.autostart ~= health.autostart then
4715
4721
  status_dirty = true
4716
4722
  end
4717
4723
  health = next_health
@@ -5294,7 +5300,11 @@ local function publish_status(now, force)
5294
5300
  deferMs = defer_n > 0 and math.floor(defer_sum / defer_n * 100000 + 0.5) / 100 or 0,
5295
5301
  recent = status.recent,
5296
5302
  sessions = session_list(),
5297
- settings = { paused = cfg("cfg_paused"), readonly = cfg("cfg_readonly"), openOnStart = open_on_start(), dev = dev_mode() },
5303
+ settings = {
5304
+ paused = cfg("cfg_paused"), readonly = cfg("cfg_readonly"), openOnStart = open_on_start(), dev = dev_mode(),
5305
+ -- Start with REAPER: on unless turned off ("0"); read by the startup block, not by this script
5306
+ autostart = reaper.GetExtState(STATUS_SECTION, "cfg_autostart") ~= "0",
5307
+ },
5298
5308
  health = health,
5299
5309
  web = web_watch.status,
5300
5310
  control = control_status(),
@@ -270,11 +270,35 @@ def test_a_stretch_that_keeps_the_pitch_passes_every_character_check():
270
270
  assert checks["transients"]["verdict"] == "ok"
271
271
 
272
272
 
273
- def test_varispeed_is_reported_as_pitch_drift_in_cents():
273
+ def test_a_plain_speed_change_is_reported_as_pitch_drift_in_cents_not_warned():
274
274
  reference = _voice(4)
275
275
  checks = _character(reference, _resampled(reference, 1.1), 1.1)
276
- assert checks["pitch"]["verdict"] == "warn"
276
+ assert checks["pitch"]["verdict"] == "info"
277
+ assert checks["pitch"]["varispeed"] is True
277
278
  assert checks["pitch"]["driftCents"] == pytest.approx(1200 * np.log2(1.1), abs=15)
279
+ assert checks["pitch"]["expectedCents"] == pytest.approx(1200 * np.log2(1.1), abs=0.2)
280
+
281
+
282
+ def test_a_slow_down_that_moves_the_pitch_is_also_a_plain_speed_change():
283
+ reference = _voice(4)
284
+ checks = _character(reference, _resampled(reference, 0.92), 0.92)
285
+ assert checks["pitch"]["verdict"] == "info"
286
+ assert checks["pitch"]["driftCents"] < -100
287
+
288
+
289
+ def test_a_pitch_error_the_speed_change_does_not_explain_still_warns_after_a_speed_change():
290
+ reference = _voice(4)
291
+ off = _resampled(_voice(4, pitch_scale=2 ** (1.0 / 12)), 1.1) # a semitone further up than the speed alone
292
+ checks = _character(reference, off, 1.1)
293
+ assert checks["pitch"]["verdict"] == "warn"
294
+ assert "varispeed" not in checks["pitch"]
295
+
296
+
297
+ def test_the_tone_shift_of_a_speed_change_is_reported_not_warned():
298
+ reference = _voice(4)
299
+ checks = _character(reference, _resampled(reference, 1.25), 1.25)
300
+ assert checks["tone"]["distanceDb"] >= verify.TONE_WARN_DB
301
+ assert checks["tone"]["verdict"] == "info"
278
302
 
279
303
 
280
304
  def test_a_half_semitone_error_is_found():
@@ -313,5 +337,6 @@ def test_character_checks_only_run_when_the_timing_changed(source):
313
337
 
314
338
  def test_a_character_warning_makes_the_verdict_a_warning_never_a_fail():
315
339
  reference = _voice(4)
316
- result = verify.verify_edit(reference, _resampled(reference, 1.1), SR, time_scale=1.1)
340
+ off = _resampled(_voice(4, pitch_scale=2 ** (1.0 / 12)), 1.1)
341
+ result = verify.verify_edit(reference, off, SR, time_scale=1.1)
317
342
  assert result["verdict"] == "warn"
package/sidecar/verify.py CHANGED
@@ -44,7 +44,9 @@ SILENCE = 1e-6
44
44
 
45
45
  # Character checks (only when the timing changed): warn lines from the issue 81 experiment
46
46
  PITCH_WARN_CENTS = 20.0
47
- TONE_WARN_DB = 0.7
47
+ TONE_WARN_DB = 1.5
48
+ # A drift this close to what the speed change alone predicts is a plain speed change (varispeed), reported, not warned
49
+ VARISPEED_TOLERANCE_CENTS = 35.0
48
50
  TRANSIENT_WARN_LOG = -0.25
49
51
  MIN_VOICED_FRAMES = 12
50
52
  MIN_VOICED_SHARE = 0.25
@@ -251,11 +253,14 @@ def pitch_drift(reference: np.ndarray, edited: np.ndarray, sample_rate: int, rat
251
253
  return {"verdict": "skipped", "reason": "too few voiced frames in both to compare"}
252
254
  cents = 1200.0 * np.log2(edit_f0[both] / ref_f0[index][both])
253
255
  drift = float(np.median(cents))
256
+ expected = 1200.0 * np.log2(rate) # what a plain speed change (pitch follows the speed) would do
257
+ varispeed = abs(expected) >= PITCH_WARN_CENTS and abs(drift - expected) <= VARISPEED_TOLERANCE_CENTS
254
258
  return {
255
- "verdict": "warn" if abs(drift) >= PITCH_WARN_CENTS else "ok",
259
+ "verdict": "info" if varispeed else "warn" if abs(drift) >= PITCH_WARN_CENTS else "ok",
256
260
  "driftCents": round(drift, 1),
257
261
  "referenceHz": round(centre, 1),
258
262
  "framesCompared": int(both.sum()),
263
+ **({"varispeed": True, "expectedCents": round(expected, 1)} if varispeed else {}),
259
264
  }
260
265
 
261
266
 
@@ -279,11 +284,19 @@ def _long_term_bands(x: np.ndarray, sample_rate: int) -> np.ndarray:
279
284
  return levels[frame_level > frame_level.max() - 40.0].mean(axis=0)
280
285
 
281
286
 
282
- def tone_difference(reference: np.ndarray, edited: np.ndarray, sample_rate: int) -> dict[str, Any]:
283
- """Rms dB difference of the long-term spectrum, overall gain removed."""
287
+ def tone_difference(reference: np.ndarray, edited: np.ndarray, sample_rate: int, varispeed: bool = False) -> dict[str, Any]:
288
+ """
289
+ Rms dB difference of the long-term spectrum, overall gain removed. After a plain speed change the whole
290
+ spectrum moves with the pitch by design, so a distance over the line is reported, not warned.
291
+ """
284
292
  delta = _long_term_bands(reference, sample_rate) - _long_term_bands(edited, sample_rate)
285
293
  distance = float(np.sqrt(np.mean((delta - delta.mean()) ** 2)))
286
- return {"verdict": "warn" if distance >= TONE_WARN_DB else "ok", "distanceDb": round(distance, 2)}
294
+ over = distance >= TONE_WARN_DB
295
+ return {
296
+ "verdict": ("info" if varispeed else "warn") if over else "ok",
297
+ "distanceDb": round(distance, 2),
298
+ **({"reason": "the spectrum moves with the pitch after a plain speed change"} if over and varispeed else {}),
299
+ }
287
300
 
288
301
 
289
302
  def _flux_peakiness(x: np.ndarray) -> float:
@@ -355,7 +368,7 @@ def verify_edit(reference: np.ndarray, edited: np.ndarray, sample_rate: int, *,
355
368
  checks["null"] = {"verdict": "skipped", "reason": "timing changed (timeScale != 1): a waveform null needs the same timing"}
356
369
  ref_mono, edit_mono = _mono(reference), _mono(edited)
357
370
  checks["pitch"] = pitch_drift(ref_mono, edit_mono, sample_rate, time_scale)
358
- checks["tone"] = tone_difference(ref_mono, edit_mono, sample_rate)
371
+ checks["tone"] = tone_difference(ref_mono, edit_mono, sample_rate, bool(checks["pitch"].get("varispeed")))
359
372
  checks["transients"] = transient_change(ref_mono, edit_mono)
360
373
  else:
361
374
  null = compensated_null(reference, edited, sample_rate, max_lag_ms)