Fix dragging an existing pedal into a region lane (cross-lane move)

Drag/drop only supported add: (palette→anywhere) and same-lane reorders, so
dragging a pedal from the main chain (or another lane) into a Stereo Unzip /
Split / Parallel lane highlighted the lane but the drop was a no-op.

- New core ShoeGaze.movePedal(from:at:to:in:) moves a pedal across lanes,
  preserving its PedalState (params), with destination-index correction when the
  removal deletes a top-level segment before the target region.
- BoardFlowView routes movemain:/movebranch: payloads dropped on a lane (or the
  main chain, or another lane's card) through it via moveAcross(_:toLane:).

Tests: move a main pedal into an unzip lane (params preserved); move a pedal
that sits before the region (index-adjust path).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-26 20:24:32 -07:00
parent f87fc1d4b1
commit 3de8bcf6ed
4 changed files with 169 additions and 9 deletions
+4 -2
View File
@@ -5,8 +5,10 @@
### Fixes
- Pedal **ⓘ info button** moved to the top-left corner (under the corner screw),
out of the way of the name plate.
- Fixed **drag-and-drop into empty Stereo Unzip / Split / Parallel lanes** — an empty
lane is now fully hit-testable, so a dropped pedal registers instead of doing nothing.
- Fixed **dragging a pedal into a Stereo Unzip / Split / Parallel lane**. Dropping a pedal
from the main chain (or another lane) into a region lane now moves it there, preserving its
parameters — previously the drop was silently ignored. Empty lanes are also fully
hit-testable now.
## 1.1.0 — 2026-06-24
@@ -117,6 +117,83 @@ extension ShoeGaze {
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
}
/// Moves a pedal from one lane to another (e.g. the main chain into a stereo-unzip lane, or
/// between branches), preserving its parameter values. The moved pedal is appended to the end
/// of the destination lane.
///
/// - Parameters:
/// - sourceLane: The lane the pedal currently lives in.
/// - sourceIndex: The pedal's index within `sourceLane`.
/// - destinationLane: The lane to move the pedal into.
/// - board: The board to edit.
/// - Returns: The rebuilt board occupying the same slot in `boards`.
/// - Throws: `ShoeGazeError.pedalIndexOutOfRange`, `.notABranchRegion`, or any rebuild error.
@discardableResult
public func movePedal(
from sourceLane: PedalLane,
at sourceIndex: Int,
to destinationLane: PedalLane,
in board: PedalBoard
) throws -> PedalBoard {
var segments: [BoardSegmentState] = board.captureState().segments
// 1. Remove the pedal from its source lane, capturing its full state. Removing a main
// pedal deletes a top-level segment; record where so the destination region index can
// be corrected if it sat after the removal.
let moved: PedalState
var removedTopLevelIndex: Int?
switch sourceLane {
case .main:
let positions: [Int] = linearPedalSegmentIndices(segments)
guard sourceIndex >= 0, sourceIndex < positions.count else {
throw ShoeGazeError.pedalIndexOutOfRange(index: sourceIndex, count: positions.count)
}
let absolute: Int = positions[sourceIndex]
guard case .pedal(let state) = segments[absolute] else {
throw ShoeGazeError.pedalIndexOutOfRange(index: sourceIndex, count: positions.count)
}
moved = state
segments.remove(at: absolute)
removedTopLevelIndex = absolute
case .left, .right:
var captured: PedalState?
try mutateBranch(&segments, lane: sourceLane) { branch in
guard sourceIndex >= 0, sourceIndex < branch.count else {
throw ShoeGazeError.pedalIndexOutOfRange(index: sourceIndex, count: branch.count)
}
captured = branch.remove(at: sourceIndex)
}
guard let capturedState: PedalState = captured else {
throw ShoeGazeError.pedalIndexOutOfRange(index: sourceIndex, count: 0)
}
moved = capturedState
}
// 2. Correct the destination region index if a top-level segment before it was removed.
var destination: PedalLane = destinationLane
if let region: Int = destinationLane.regionIndex,
let removed: Int = removedTopLevelIndex, removed < region {
destination = destinationLane.isLeftBranch ? .left(region: region - 1) : .right(region: region - 1)
}
// 3. Append the moved pedal to the destination lane.
switch destination {
case .main:
let positions: [Int] = linearPedalSegmentIndices(segments)
if let lastPedal: Int = positions.last {
segments.insert(.pedal(moved), at: lastPedal + 1)
} else {
segments.append(.pedal(moved))
}
case .left, .right:
try mutateBranch(&segments, lane: destination) { branch in
branch.append(moved)
}
}
return try rebuildBoard(board, from: BoardState(label: board.label, segments: segments))
}
// MARK: - Branch regions
/// Appends an empty stereo split region (two independently authored L/R lanes) to the board.
+38 -7
View File
@@ -400,16 +400,19 @@ public struct BoardFlowView: View {
reorderMain(from: src, onto: ontoLinear)
return true
}
return false
// A branch pedal dragged back onto the main chain → cross-lane move.
return moveAcross(payload, toLane: .main)
}
private func handleLaneDrop(_ items: [String], lane: PedalLane) -> Bool {
dropTarget = nil
guard let payload: String = parse(items), let type: String = payload.afterPrefix("add:") else {
return false
guard let payload: String = parse(items) else { return false }
if let type: String = payload.afterPrefix("add:") {
append(type: type, lane: lane)
return true
}
append(type: type, lane: lane)
return true
// A pedal from the main chain or another lane dragged into this lane → cross-lane move.
return moveAcross(payload, toLane: lane)
}
private func handleBranchCardDrop(_ items: [String], lane: PedalLane, ontoIndex: Int) -> Bool {
@@ -426,7 +429,7 @@ public struct BoardFlowView: View {
append(type: type, lane: lane)
return true
}
// Reorder within the same lane only: "movebranch:<region>:<side>:<index>".
// Reorder within the same lane: "movebranch:<region>:<side>:<index>".
let parts: [Substring] = payload.split(separator: ":")
if parts.count == 4, parts[0] == "movebranch",
Int(parts[1]) == lane.regionIndex,
@@ -435,7 +438,35 @@ public struct BoardFlowView: View {
reorderBranch(from: src, onto: ontoIndex, lane: lane)
return true
}
return false
// A pedal from the main chain or a different lane dropped onto a card here → cross-lane move.
return moveAcross(payload, toLane: lane)
}
/// Moves a pedal addressed by a `movemain:`/`movebranch:` payload into `destination`,
/// preserving its parameters. Returns `false` if the payload isn't a recognised move.
private func moveAcross(_ payload: String, toLane destination: PedalLane) -> Bool {
guard let board: PedalBoard = board else { return false }
let sourceLane: PedalLane
let sourceIndex: Int
if let mainIndex: Int = payload.afterPrefix("movemain:").flatMap(Int.init) {
sourceLane = .main
sourceIndex = mainIndex
} else {
let parts: [Substring] = payload.split(separator: ":")
guard parts.count == 4, parts[0] == "movebranch",
let region: Int = Int(parts[1]), let index: Int = Int(parts[3]) else {
return false
}
sourceLane = (parts[2] == "L") ? .left(region: region) : .right(region: region)
sourceIndex = index
}
do {
_ = try shoeGaze.movePedal(from: sourceLane, at: sourceIndex, to: destination, in: board)
return true
} catch {
print("[BoardFlowView] cross-lane move failed: \(error)")
return false
}
}
// MARK: - Edit actions
@@ -582,4 +582,54 @@ struct BoardEditAPITests {
let samples: [Float] = try render(engine2, url2)
#expect(hasNonSilentOutput(samples), "loaded edited rig should render audio")
}
// MARK: - Cross-lane move (drag a pedal into a region lane)
@Test func moveMainPedalIntoStereoUnzipLanePreservingParams() throws {
// Ping-Pong (stereo) then Overdrive on the main chain; unzip after Ping-Pong.
let (sg, engine, url, board): (ShoeGaze, SynthesisEngine, URL, PedalBoard) =
try makeRig(pedals: ["Ping-Pong", "Overdrive"])
defer { try? FileManager.default.removeItem(at: url) }
var live: PedalBoard = try sg.insertStereoUnzip(afterSegment: 0, in: board)
// Tweak the live Overdrive so we can verify its params survive the move.
let overdrive: OverdrivePedal? = live.pedals.compactMap { $0 as? OverdrivePedal }.first
overdrive?.drive = 11.0
// Move the Overdrive (main linear index 1) into the unzip's left lane (region segment 1).
live = try sg.movePedal(from: .main, at: 1, to: .left(region: 1), in: live)
#expect(names(live) == ["Ping-Pong"], "Overdrive should leave the main chain")
guard let state: StereoUnzipState = unzipState(live) else {
Issue.record("No stereo unzip segment")
return
}
#expect(state.left.map { $0.type } == ["Overdrive"], "Overdrive should land in the left lane")
#expect(state.left.first?.knobValues.first == 11.0, "Drive param should survive the move")
let samples: [Float] = try render(engine, url)
#expect(hasNonSilentOutput(samples), "board renders after the cross-lane move")
}
@Test func moveMainPedalBeforeUnzipRegionAdjustsIndex() throws {
// Overdrive (mono) then Ping-Pong (stereo); unzip after Ping-Pong. Moving the Overdrive —
// which sits BEFORE the unzip region — exercises the destination-index adjustment.
let (sg, engine, url, board): (ShoeGaze, SynthesisEngine, URL, PedalBoard) =
try makeRig(pedals: ["Overdrive", "Ping-Pong"])
defer { try? FileManager.default.removeItem(at: url) }
var live: PedalBoard = try sg.insertStereoUnzip(afterSegment: 1, in: board)
// Unzip is top-level segment 2; Overdrive is main linear index 0 (top-level segment 0).
live = try sg.movePedal(from: .main, at: 0, to: .left(region: 2), in: live)
#expect(names(live) == ["Ping-Pong"], "Overdrive should leave the main chain")
guard let state: StereoUnzipState = unzipState(live) else {
Issue.record("No stereo unzip segment")
return
}
#expect(state.left.map { $0.type } == ["Overdrive"], "Overdrive should land in the left lane")
let samples: [Float] = try render(engine, url)
#expect(hasNonSilentOutput(samples), "board renders after the index-adjusted move")
}
}