e051521c04
- Visual metronome tempo indicator (pendulum playhead) replacing the flashing LED - Rig Mute (Cmd-Z) hard-silence, distinct from Bypass Rig; wired to header, board menu, MIDI - Keyboard shortcuts: Cmd-1..9 board switch, Cmd-Shift-1..0 set-list rig load, Cmd-Z mute (macOS native menus + iOS/iPadOS hardware keyboards) - Rig set-list ordering: drag or Move Up/Down in the picker; order saved and archive-portable - Persist tempo, input selection, and engine I/O with a rig (I/O applied via opt-in applyChannelLayout, not forced on load) - Fix archive import colliding set-list positions with existing rigs - Remove ShoeGazeDemo / ShoeGazeiOSDemo apps and projects; keep the two Builder apps - Bump marketing version to 2.0.0 on both Builder projects; pin Lyrebird 1.2.3 - Add CHANGELOG.md Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
93 lines
3.5 KiB
Swift
93 lines
3.5 KiB
Swift
// InputSource.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import LyrebirdSynth
|
|
|
|
/// Selects how the pedalboard's head bus is fed with audio.
|
|
///
|
|
/// - `.testLoop`: A synthesized test tone (`TestLoopSource`) writes to the head bus.
|
|
/// Suitable for testing the pedalboard with no hardware connected.
|
|
/// - `.liveInput(channel:)`: A hardware input channel feeds the head bus. `channel` is
|
|
/// the zero-based hardware input channel index (`0` = first input). It maps to engine
|
|
/// audio-bus index `numOutputChannels + channel` (hardware input buses follow the
|
|
/// output buses). Requires the engine to be created with `numInputChannels > channel`.
|
|
public enum InputSource: Equatable {
|
|
/// Synthesized test signal — no hardware required.
|
|
case testLoop
|
|
/// Live hardware input from the given zero-based input channel. The engine must be
|
|
/// created with `numInputChannels > channel`.
|
|
case liveInput(channel: Int)
|
|
}
|
|
|
|
// MARK: - Codable
|
|
|
|
/// Persisted so a saved rig round-trips its input selection. Encoded as a `kind` discriminator
|
|
/// plus an optional `channel`, so adding future cases stays forward-tolerant.
|
|
extension InputSource: Codable {
|
|
|
|
private enum Kind: String, Codable {
|
|
case testLoop
|
|
case liveInput
|
|
}
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
case kind
|
|
case channel
|
|
}
|
|
|
|
public init(from decoder: Decoder) throws {
|
|
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
|
|
let kind: Kind = try container.decode(Kind.self, forKey: .kind)
|
|
switch kind {
|
|
case .testLoop:
|
|
self = .testLoop
|
|
case .liveInput:
|
|
let channel: Int = try container.decode(Int.self, forKey: .channel)
|
|
self = .liveInput(channel: channel)
|
|
}
|
|
}
|
|
|
|
public func encode(to encoder: Encoder) throws {
|
|
var container: KeyedEncodingContainer<CodingKeys> = encoder.container(keyedBy: CodingKeys.self)
|
|
switch self {
|
|
case .testLoop:
|
|
try container.encode(Kind.testLoop, forKey: .kind)
|
|
case .liveInput(let channel):
|
|
try container.encode(Kind.liveInput, forKey: .kind)
|
|
try container.encode(channel, forKey: .channel)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Validates a `.liveInput` channel against the engine and returns the engine audio-bus
|
|
/// index of that hardware input channel.
|
|
///
|
|
/// Hardware input buses occupy indices `numOutputChannels ..< (numOutputChannels +
|
|
/// numInputChannels)`, so input channel `channel` lives at `numOutputChannels + channel`.
|
|
///
|
|
/// - Parameters:
|
|
/// - channel: Zero-based hardware input channel index.
|
|
/// - engine: The engine whose bus layout is queried.
|
|
/// - Returns: The audio-bus index to read the requested input channel from.
|
|
/// - Throws:
|
|
/// - `ShoeGazeError.liveInputRequiresInputChannels` if the engine has no input channels.
|
|
/// - `ShoeGazeError.inputChannelOutOfRange` if `channel` is negative or `>= numInputChannels`.
|
|
internal func liveInputBusIndex(
|
|
channel: Int,
|
|
engine: SynthesisEngine
|
|
) throws -> Int {
|
|
guard engine.numInputChannels > 0 else {
|
|
throw ShoeGazeError.liveInputRequiresInputChannels
|
|
}
|
|
guard channel >= 0, channel < engine.numInputChannels else {
|
|
throw ShoeGazeError.inputChannelOutOfRange(
|
|
requested: channel,
|
|
available: engine.numInputChannels
|
|
)
|
|
}
|
|
return engine.numOutputChannels + channel
|
|
}
|