@mthines/reaper-mcp 0.76.0 → 0.77.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.
@@ -0,0 +1,46 @@
1
+ ---
2
+ name: Vocal Alignment
3
+ id: vocal-alignment
4
+ description: Tighten doubles, harmonies and backing vocals to a lead by timing, and check the result without listening
5
+ ---
6
+
7
+ # Vocal Alignment
8
+
9
+ ## When to Use
10
+
11
+ - "Tighten the backing vocals to the lead"
12
+ - A double, harmony or call-and-response that drifts against the guide
13
+ - Any stretch or slow-down of a vocal where you need to know if it still sounds clean
14
+
15
+ The ear decides in the end. These steps find the problems the agent can measure and say which edits to hand to the user for listening.
16
+
17
+ ## Tools
18
+
19
+ - `align_audio_to_guide`: hits of a guide item and 1-8 doubles (read from their **source files**), paired in order within `maxShiftMs`, then one stretch marker per hit moves the double onto the guide. `dryRun` shows the move first, `strength` scales it, `protectConsonants` keeps high-band hits rigid. A guide that already has stretch markers is refused. It does not hear take FX: Melodyne and the like are take FX on the item, and the alignment ignores them.
20
+ - `verify_edit`: compares the result with the audio from before the edit (a kept copy on an unmuted reference track, or a bounce). Set `timeScale` to the playback rate when the timing changed (1.1 = the edit is 10% shorter) and `expect: "changed"` for a stretch.
21
+ - `measure_track_alignment`: delay and polarity between two tracks, with the play offset and phase to set.
22
+
23
+ ## Steps
24
+
25
+ 1. **Keep the originals.** Copy the guide and each double to new tracks (`T ref`, `T edit` are fine as temporary names, delete them when done) and edit the copies. Never touch the user's items or solo state. Tracks created without a master send are silent in playback but still render, so turn the master send on for tracks the user will audition.
26
+ 2. **Pick the guide.** The louder, tighter take. A quiet backing vocal against a loud lead is a good test: onsets are found per source file, so level does not matter.
27
+ 3. **Dry run.** `align_audio_to_guide` with `dryRun: true`: read the offset before and after (avg and max ms) per double. Start with `strength` around 0.8 and a `maxShiftMs` under the typical phrase gap; raise it only when hits are missed.
28
+ 4. **Apply** (same call without `dryRun`), then `verify_edit` against the kept copy with `timeScale: 1` for a pure alignment (stretch markers keep the length) and `expect: "changed"`. Judge it by the `discontinuity` check (no click) and the align call's after-offsets; the null residual is one number for the whole window and under `expect: "changed"` is only reported, so it does not say where audio moved.
29
+ 5. **Listen** before accepting: play the aligned range with the guide. The tool checks for damage, not for taste.
30
+
31
+ ## Stretching a vocal: what the checks mean
32
+
33
+ Measured on a real lead and backings with REAPER's stretch (42 edits, two listening rounds):
34
+
35
+ - **Pitch-kept stretches** from 0.92x to 1.25x sound clean: pitch drift within a few cents, tone under 1.5 dB.
36
+ - **Below 0.9x** a pitch-kept slow-down gets audible stretch artifacts (0.80x clearly, 0.85x and 0.88x slightly, 0.90x clean). They pass pitch, tone and transients; `verify_edit` adds a **dropout** check there (deepest loudness dip under the original, warn from 12 dB). The line is provisional (one phrase), and the rate gate does most of the work: treat anything below 0.9x as "listen first", and use it as a dub rather than a lead.
37
+ - **A plain speed change** (preserve pitch cleared, so the pitch follows the speed) is reported as `info`, not a warning, when the speed alone predicts a pitch move of at least 55 cents (rates outside about 0.97x-1.03x): pitch moves by `1200*log2(rate)` cents and the tone moves with it. Up to about 1.5 semitones was accepted by ear. Nearer 1.0 the move is too small to tell from an error, so a drift of 20 cents or more there still warns, and so does any pitch move the speed does not explain.
38
+ - A pitch shift with the timing unchanged (`timeScale` 1) gets no pitch check; shifting and stretching in one edit does.
39
+ - A pass is evidence, not proof. Ratings near the audible edge are noisy (the same audio was heard as artifacted once and clean twice).
40
+
41
+ ## REAPER gotchas for building test edits
42
+
43
+ - `playRate` does not change an item's length: set length = source length / rate.
44
+ - A copied item has preserve pitch on; run action 40796 (clear take preserve pitch) for a varispeed, 40795 sets it.
45
+ - Item pitch: actions 40204 / 40205 (one semitone up / down) act on the selected items.
46
+ - **Put each copy straight at its final position** (`copy_media_items` with `position`). Batch-moving items on one track re-sorts their indexes mid-edit and edits land on the wrong items.
@@ -3,12 +3,12 @@ name: editing
3
3
  description: >
4
4
  Edits a live REAPER session through the reaper MCP tools: MIDI parts (writing,
5
5
  rewriting, quantizing, importing), arrangement (split, move, copy, insert or
6
- remove time), timing and phase, crossfades and comping, voice recordings into
6
+ remove time), timing and phase, vocal alignment and stretch checks, crossfades and comping, voice recordings into
7
7
  arrangements, audio stem separation, and A/B-testing variations in fixed lanes.
8
8
  Changes notes and items, not levels or FX; use /mixer for those. Use when asked
9
9
  to edit, rewrite, tighten, comp, change the groove, compare parts, turn humming
10
10
  or beatboxing into music, or split a recording into stems. Triggers on "edit
11
- the drums", "change the chorus", "make a variation", "A/B these takes",
11
+ the drums", "align the backing vocals", "change the chorus", "make a variation", "A/B these takes",
12
12
  "comp this", "tighten the timing", "compose from this recording", "turn my
13
13
  humming into a song", "split stems", "/editing".
14
14
  argument-hint: '[what to edit, voice recording, stems, or versions to compare]'
@@ -261,6 +261,23 @@ Gotchas:
261
261
  arrangement, snapshots (`/mixer`) for faders, EQ and the master.
262
262
  - For a few-note tweak, edit in place; lanes are for whole alternatives.
263
263
 
264
+ ## Aligning and stretching vocals
265
+
266
+ Tightening doubles, harmonies or backing vocals to a lead, and judging a stretch,
267
+ use `knowledge/workflows/vocal-alignment.md`; load it first. In short:
268
+
269
+ 1. Edit **copies** on temporary tracks (the user's items and solo state stay
270
+ untouched) and delete them when the user is done.
271
+ 2. `align_audio_to_guide` with `dryRun` first, then apply; it reads the items'
272
+ source files, so take FX such as Melodyne are not heard.
273
+ 3. Check the result with `verify_edit` (`timeScale` = the playback rate,
274
+ `expect: "changed"` for a stretch), then **tell the user which edits to
275
+ listen to**. A plain speed change (rates outside about 0.97x-1.03x) is reported as info (pitch follows speed);
276
+ a pitch-kept slow-down below 0.9x gets stretch artifacts that only the
277
+ dropout check and the user's ear catch. A pass is evidence, not a verdict.
278
+ 4. Put each copied item straight at its final position; batch-moving items on a
279
+ track re-sorts their indexes.
280
+
264
281
  ## Workflow
265
282
 
266
283
  1. **Understand** the edit and the song structure (`list_regions`, `list_markers`,
@@ -132,7 +132,7 @@ Shipped baseline at the project `.claude/knowledge/` or `~/.claude/knowledge/`
132
132
  - `genres/{genre}.md` — genre EQ/compression/LUFS conventions (if a genre is named)
133
133
  - `workflows/{task}.md` — step-by-step procedures; map the request to one:
134
134
  gain-staging · session-prep · vocal-chain · drum-bus · low-end · stereo-image ·
135
- master-bus · stem-prep · delivery · section-levels · transient-lighting
135
+ master-bus · stem-prep · delivery · section-levels · transient-lighting · editing · vocal-alignment
136
136
  - `reference/*.md` — frequencies, compression, metering, perceived-loudness, aesthetics-scoring,
137
137
  common-mistakes (read these instead of guessing).
138
138
 
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.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",
@@ -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)