@mthines/reaper-mcp 0.104.0 → 0.105.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mthines/reaper-mcp",
3
- "version": "0.104.0",
3
+ "version": "0.105.0",
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",
package/reaper/CLAUDE.md CHANGED
@@ -40,7 +40,7 @@ Files installed INTO the REAPER DAW by the `setup` command. These run inside REA
40
40
  2. Reads `command_{uuid}.json` from bridge directory
41
41
  3. Dispatches to handler function in the `handlers` table
42
42
  4. Writes `response_{uuid}.json` with results
43
- 5. Writes `heartbeat.json` every 1s for liveness detection
43
+ 5. Writes `heartbeat.json` every 1s for liveness detection (removed on exit). At start, a fresh heartbeat in the folder means another bridge serves it: the new one waits up to 6 s (a restarting bridge stops writing it) and then stands down with a console message, because two bridges on one folder would split the commands between two REAPERs. A second REAPER needs its own resource folder (`reaper-mcp instance create`). The whole startup lives in `run_bridge()` since the main chunk is at the 200-locals limit
44
44
  6. Publishes a status feed to ExtState `MCPBridge/status` for the web status page (`apps/bridge-ui`)
45
45
 
46
46
  ### Adding a Handler
@@ -5793,35 +5793,70 @@ local function open_status_window(url)
5793
5793
  os.execute(cmd)
5794
5794
  end
5795
5795
 
5796
- local web_port = find_web_port()
5797
- -- A build that never installed the status page (the Claude plugin) has nothing to open and no `reaper-mcp` command
5798
- local page_installed = file_exists(reaper.GetResourcePath() .. "/reaper_www_root/mcp_bridge.html")
5799
- if not page_installed then
5800
- -- nothing to show
5801
- elseif not web_port then
5802
- reaper.ShowConsoleMsg("MCP Bridge: running. For the status window, quit REAPER and run `reaper-mcp setup` "
5803
- .. "(or enable Preferences > Control/OSC/Web > Web browser interface).\n")
5804
- elseif open_on_start() and not ui_recently_seen() then
5805
- open_status_window("http://localhost:" .. web_port .. "/mcp_bridge.html?app=window")
5806
- end
5807
-
5808
- -- Write initial heartbeat
5809
- write_heartbeat()
5810
-
5811
- -- Log bridge start event for OTel consumption
5812
- log_event("bridge_start", { reaperVersion = reaper.GetAppVersion(), bridgeDir = bridge_dir })
5813
-
5814
- -- Register shutdown handler
5815
- -- Renders a previous run left behind
5816
- if ext.render.ok then pcall(ext.render.lib.sweep, reaper) end
5817
-
5818
- reaper.atexit(function()
5819
- if ext.render.ok then pcall(ext.render.lib.purge) end
5820
- log_event("bridge_stop", {})
5821
- save_history(reaper.time_precise(), true)
5822
- reaper.DeleteExtState(STATUS_SECTION, "status", false) -- UI flips to offline at once
5823
- for _, key in ipairs({ "history", "history_long", "log" }) do reaper.DeleteExtState(STATUS_SECTION, key, false) end
5824
- end)
5825
-
5826
- -- Start the loop
5827
- main_loop()
5796
+ -- A second bridge on one folder would split the commands between two REAPERs at random, so a bridge that
5797
+ -- finds another one's heartbeat still fresh waits a few seconds (a bridge that is being restarted stops writing
5798
+ -- it) and then stands down. No heartbeat, or a stale one, starts at once.
5799
+ -- One function holds the whole startup: the main chunk is at Lua's 200-locals limit
5800
+ local function run_bridge()
5801
+ local function start_bridge()
5802
+ local web_port = find_web_port()
5803
+ -- A build that never installed the status page (the Claude plugin) has nothing to open and no `reaper-mcp` command
5804
+ local page_installed = file_exists(reaper.GetResourcePath() .. "/reaper_www_root/mcp_bridge.html")
5805
+ if not page_installed then
5806
+ -- nothing to show
5807
+ elseif not web_port then
5808
+ reaper.ShowConsoleMsg("MCP Bridge: running. For the status window, quit REAPER and run `reaper-mcp setup` "
5809
+ .. "(or enable Preferences > Control/OSC/Web > Web browser interface).\n")
5810
+ elseif open_on_start() and not ui_recently_seen() then
5811
+ open_status_window("http://localhost:" .. web_port .. "/mcp_bridge.html?app=window")
5812
+ end
5813
+
5814
+ -- Write initial heartbeat
5815
+ write_heartbeat()
5816
+
5817
+ -- Log bridge start event for OTel consumption
5818
+ log_event("bridge_start", { reaperVersion = reaper.GetAppVersion(), bridgeDir = bridge_dir })
5819
+
5820
+ -- Register shutdown handler
5821
+ -- Renders a previous run left behind
5822
+ if ext.render.ok then pcall(ext.render.lib.sweep, reaper) end
5823
+
5824
+ reaper.atexit(function()
5825
+ if ext.render.ok then pcall(ext.render.lib.purge) end
5826
+ log_event("bridge_stop", {})
5827
+ os.remove(bridge_dir .. "heartbeat.json") -- a bridge starting right after (a restart) need not wait for it to go stale
5828
+ save_history(reaper.time_precise(), true)
5829
+ reaper.DeleteExtState(STATUS_SECTION, "status", false) -- UI flips to offline at once
5830
+ for _, key in ipairs({ "history", "history_long", "log" }) do reaper.DeleteExtState(STATUS_SECTION, key, false) end
5831
+ end)
5832
+
5833
+ -- Start the loop
5834
+ main_loop()
5835
+ end
5836
+
5837
+ local HEARTBEAT_FRESH_MS = 2500
5838
+ local GUARD_WAIT_S = 6
5839
+ local function other_bridge_alive()
5840
+ local raw = read_file(bridge_dir .. "heartbeat.json")
5841
+ local hb = raw and json_decode(raw)
5842
+ local ts = type(hb) == "table" and tonumber(hb.timestamp)
5843
+ return ts ~= nil and ts ~= false and math.abs(os.time() * 1000 - ts) < HEARTBEAT_FRESH_MS
5844
+ end
5845
+
5846
+ if not other_bridge_alive() then
5847
+ start_bridge()
5848
+ else
5849
+ local waited_from = reaper.time_precise()
5850
+ local function wait_for_folder()
5851
+ if not other_bridge_alive() then return start_bridge() end
5852
+ if reaper.time_precise() - waited_from > GUARD_WAIT_S then
5853
+ reaper.ShowConsoleMsg("MCP Bridge: another bridge is already serving " .. bridge_dir
5854
+ .. "\nA second REAPER needs its own resource folder (reaper-mcp instance create); this bridge did not start.\n")
5855
+ return
5856
+ end
5857
+ reaper.defer(wait_for_folder)
5858
+ end
5859
+ wait_for_folder()
5860
+ end
5861
+ end
5862
+ run_bridge()
@@ -485,7 +485,12 @@ function M.set_pins(api, p, inputs, outputs)
485
485
  for _, w in ipairs(writes) do
486
486
  local lo, hi = masks_of(w[3])
487
487
  if not api.TrackFX_SetPinMappings(tr, fx, w[1], w[2], lo, hi) then
488
- error("REAPER refused the mapping of " .. (w[1] == 1 and "output" or "input") .. " pin " .. w[2], 0)
488
+ -- The pin passed the count check above, so REAPER (or the plugin) is the one refusing: say how many
489
+ -- pins the plugin reports, so a plugin that lies about its pins is recognisable from the message
490
+ local side_name, count = "input", int(ins) or 0
491
+ if w[1] == 1 then side_name, count = "output", int(outs) or 0 end
492
+ error("REAPER refused the mapping of " .. side_name .. " pin " .. w[2] .. " (the FX reports " .. count
493
+ .. " " .. side_name .. " pins, 0.." .. (count - 1) .. ")", 0)
489
494
  end
490
495
  end
491
496
  local res = read_pins(api, tr, fx)