@mthines/reaper-mcp 0.76.0 → 0.77.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.76.0",
3
+ "version": "0.77.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",
@@ -616,6 +616,57 @@ local function item_view(params, before)
616
616
  return r
617
617
  end
618
618
 
619
+ -- Item selection: the media items selected, per track (0-based item indexes), tracks without any left out
620
+ local function selected_items()
621
+ local out = {}
622
+ for t = 0, (api.CountTracks(0) or 0) - 1 do
623
+ local tr = api.GetTrack(0, t)
624
+ local picked
625
+ for i = 0, (api.CountTrackMediaItems(tr) or 0) - 1 do
626
+ if api.IsMediaItemSelected(api.GetTrackMediaItem(tr, i)) then
627
+ picked = picked or {}
628
+ picked[#picked + 1] = i
629
+ end
630
+ end
631
+ if picked then out[t] = picked end
632
+ end
633
+ return out
634
+ end
635
+
636
+ -- The timeline with a lane per track that has selected items, now or before (the first four): every item on the
637
+ -- track, which ones are selected (`picked`) and which were (`wasPicked`)
638
+ local function selection_view(before)
639
+ local now, was = selected_items(), before or {}
640
+ local order, seen = {}, {}
641
+ for _, set in ipairs({ now, was }) do
642
+ for t in pairs(set) do
643
+ if not seen[t] then seen[t] = true; order[#order + 1] = t end
644
+ end
645
+ end
646
+ table.sort(order)
647
+ local r = timeline_snapshot()
648
+ r.lanes, r.selected, r.wasSelected = {}, 0, 0
649
+ for _, picked in pairs(now) do r.selected = r.selected + #picked end
650
+ for _, picked in pairs(was) do r.wasSelected = r.wasSelected + #picked end
651
+ local all = {}
652
+ for i = 1, math.min(#order, 4) do
653
+ local t = order[i]
654
+ local tr = api.GetTrack(0, t)
655
+ local lane = { t = name_of(tr), items = track_items(tr) }
656
+ local function within(list)
657
+ local out = {}
658
+ for _, idx in ipairs(list or {}) do if idx < EDIT_MAX_MARKS then out[#out + 1] = idx end end
659
+ return #out > 0 and out or nil
660
+ end
661
+ lane.picked, lane.wasPicked = within(now[t]), within(was[t])
662
+ r.lanes[i] = lane
663
+ for _, it in ipairs(lane.items) do all[#all + 1] = it end
664
+ end
665
+ if #order > 4 then r.moreTracks = #order - 4 end
666
+ r.len = project_length(r, all)
667
+ return r
668
+ end
669
+
619
670
  -- Arrangement edits: the whole timeline before and after, a lane for up to four tracks the
620
671
  -- edit touches, and the span it worked on (copied from, opened, cut) and where it copied to
621
672
  local ARRANGE = {}
@@ -871,7 +922,8 @@ local WAVE_MAX_SAMPLES = 2000000 -- longer renders are read with a stride
871
922
  local WAV_SAMPLE = { [1] = { [16] = { "<i2", 32768 }, [24] = { "<i3", 8388608 }, [32] = { "<i4", 2147483648 } },
872
923
  [3] = { [32] = { "<f", 1 }, [64] = { "<d", 1 } } }
873
924
 
874
- local function wav_waveform(path)
925
+ local function wav_waveform(path, buckets, max_samples)
926
+ buckets, max_samples = buckets or WAVE_BUCKETS, max_samples or WAVE_MAX_SAMPLES
875
927
  if type(path) ~= "string" then return nil end
876
928
  local f = io.open(path, "rb")
877
929
  if not f then return nil end
@@ -897,12 +949,12 @@ local function wav_waveform(path)
897
949
  local frame_bytes = width * channels
898
950
  local frames = data_len // frame_bytes
899
951
  if frames < 1 then return nil end
900
- local stride = math.max(1, math.ceil(frames * channels / WAVE_MAX_SAMPLES))
952
+ local stride = math.max(1, math.ceil(frames * channels / max_samples))
901
953
  local hi, lo = {}, {}
902
- for b = 1, WAVE_BUCKETS do hi[b], lo[b] = 0, 0 end
954
+ for b = 1, buckets do hi[b], lo[b] = 0, 0 end
903
955
  local peak, sum, count, clipped = 0, 0, 0, 0
904
956
  for fr = 0, frames - 1, stride do
905
- local b = fr * WAVE_BUCKETS // frames + 1
957
+ local b = fr * buckets // frames + 1
906
958
  local at = data_pos + fr * frame_bytes
907
959
  for _ = 1, channels do
908
960
  local v = string.unpack(fmt, s, at) / scale
@@ -916,9 +968,44 @@ local function wav_waveform(path)
916
968
  count = count + 1
917
969
  end
918
970
  end
919
- for b = 1, WAVE_BUCKETS do hi[b], lo[b] = round2(hi[b]), round2(lo[b]) end
971
+ for b = 1, buckets do hi[b], lo[b] = round2(hi[b]), round2(lo[b]) end
920
972
  local db = function(v) return v > 0 and round2(20 * math.log(v, 10)) or -150 end
921
- return { hi = hi, lo = lo, peakDb = db(peak), rmsDb = db(math.sqrt(sum / count)), clipped = clipped, channels = channels }
973
+ -- The stride read is the second value, so a caller that merges the table into a result never carries it
974
+ return { hi = hi, lo = lo, peakDb = db(peak), rmsDb = db(math.sqrt(sum / count)), clipped = clipped, channels = channels }, stride
975
+ end
976
+
977
+ -- render_tracks_to_wav: one waveform per rendered track on a shared time axis, read from the cached files (the
978
+ -- bridge keeps them). Coarser than a single render's (fewer slices, a stride through long files) and read within
979
+ -- a time budget, so a 16-track render does not hold the main thread; tracks past the cap or the budget are counted
980
+ local WAVES_MAX_TRACKS = 8
981
+ local WAVES_BUCKETS = 60
982
+ local WAVES_MAX_SAMPLES = 300000
983
+ local WAVES_BUDGET_S = 1.0
984
+
985
+ local function waves_view(params, data)
986
+ if type(data) ~= "table" or type(data.tracks) ~= "table" then return nil end
987
+ local clock = api.time_precise
988
+ local started = clock and clock() or 0
989
+ local rows, more, duration, approx = {}, 0, nil, false
990
+ for _, t in ipairs(data.tracks) do
991
+ duration = duration or round2(t.durationSeconds)
992
+ local ok, wave, stride = false, nil, 1
993
+ if #rows < WAVES_MAX_TRACKS and (not clock or clock() - started < WAVES_BUDGET_S) then
994
+ ok, wave, stride = pcall(wav_waveform, t.wavPath, WAVES_BUCKETS, WAVES_MAX_SAMPLES)
995
+ end
996
+ if ok and wave then
997
+ -- Past the sample cap only every `stride`th frame is read: the clipped count is scaled up and marked approximate
998
+ if (stride or 1) > 1 then approx = true end
999
+ rows[#rows + 1] = { name = t.trackName or "", hi = wave.hi, lo = wave.lo, peakDb = wave.peakDb, rmsDb = wave.rmsDb, clipped = wave.clipped * (stride or 1) }
1000
+ else
1001
+ more = more + 1
1002
+ end
1003
+ end
1004
+ if #rows == 0 then return nil end
1005
+ return {
1006
+ tracks = rows, more = more > 0 and more or nil, durationSeconds = duration, start = round2(tonumber(params.startTime)),
1007
+ approx = approx and 1 or nil, rendered = data.rendered or 0, cached = data.cached or 0,
1008
+ }
922
1009
  end
923
1010
 
924
1011
  -- Mixing depth views: built from the handler's own result, which carries the state before
@@ -1284,6 +1371,8 @@ function M.before(cmd_type, params)
1284
1371
  return ARRANGE.before(cmd_type, params)
1285
1372
  elseif cmd_type == "set_time_selection" or cmd_type == "set_cursor_position" then
1286
1373
  return time_state()
1374
+ elseif cmd_type == "set_selected_items" then
1375
+ return selected_items()
1287
1376
  elseif ROUTING_COMMANDS[cmd_type] and cmd_type ~= "get_track_routing" then
1288
1377
  local tr = routing_track(params)
1289
1378
  return tr and { track = tr, routes = routes_of(tr) }
@@ -1335,6 +1424,10 @@ function M.summary(cmd_type, params, data, before)
1335
1424
  return ARRANGE.view(cmd_type, params, data, before)
1336
1425
  elseif TIME_COMMANDS[cmd_type] then
1337
1426
  return time_view(before)
1427
+ elseif cmd_type == "set_selected_items" then
1428
+ return selection_view(before)
1429
+ elseif cmd_type == "render_tracks_to_wav" then
1430
+ return waves_view(params, data)
1338
1431
  elseif ROUTING_COMMANDS[cmd_type] then
1339
1432
  -- A write reads the same track it read before (remove_send can leave nothing to resolve by index)
1340
1433
  local tr = before and before.track or routing_track(params)