Release 2.0.0: metronome, rig mute + shortcuts, set-list ordering, per-rig persistence
- 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>
This commit is contained in:
@@ -22,6 +22,46 @@ public enum InputSource: Equatable {
|
||||
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.
|
||||
///
|
||||
|
||||
@@ -43,6 +43,14 @@ public struct RigEntry: Codable, Identifiable, Equatable {
|
||||
/// The full rig snapshot — every board, segment, and pedal parameter.
|
||||
public let state: ShoeGazeState
|
||||
|
||||
/// The rig's position in the user's manually-ordered set list, or `nil` for a rig that has
|
||||
/// not been placed (a legacy entry saved before ordering existed, or one not yet reordered).
|
||||
///
|
||||
/// Persisted per-file and inside archive export/import, so a set-list order travels with a
|
||||
/// shared or backed-up library. `RigLibraryStore` sorts placed entries by this index and
|
||||
/// falls back to name/date for unplaced ones. Optional, so older files decode cleanly.
|
||||
public let sortIndex: Int?
|
||||
|
||||
/// Creates a rig library entry.
|
||||
///
|
||||
/// - Parameters:
|
||||
@@ -51,11 +59,13 @@ public struct RigEntry: Codable, Identifiable, Equatable {
|
||||
/// - savedAt: Save timestamp. Defaults to `Date()` (now). Rounded to the nearest
|
||||
/// whole second so persistence round-trips are lossless.
|
||||
/// - state: The ``ShoeGazeState`` rig snapshot to store.
|
||||
/// - sortIndex: Manual set-list position, or `nil` when unplaced. Defaults to `nil`.
|
||||
public init(
|
||||
id: UUID = UUID(),
|
||||
name: String,
|
||||
savedAt: Date = Date(),
|
||||
state: ShoeGazeState
|
||||
state: ShoeGazeState,
|
||||
sortIndex: Int? = nil
|
||||
) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
@@ -64,6 +74,16 @@ public struct RigEntry: Codable, Identifiable, Equatable {
|
||||
// disk round-trip.
|
||||
self.savedAt = Date(timeIntervalSince1970: savedAt.timeIntervalSince1970.rounded())
|
||||
self.state = state
|
||||
self.sortIndex = sortIndex
|
||||
}
|
||||
|
||||
/// Returns a copy of this entry placed at `index` in the set list, keeping its identity,
|
||||
/// name, timestamp, and state. Used by `RigLibraryStore` reordering.
|
||||
///
|
||||
/// - Parameter index: The new set-list position, or `nil` to unplace.
|
||||
/// - Returns: A copy at the new `sortIndex`.
|
||||
public func reordered(to index: Int?) -> RigEntry {
|
||||
RigEntry(id: id, name: name, savedAt: savedAt, state: state, sortIndex: index)
|
||||
}
|
||||
|
||||
/// Returns a copy of this entry with a new `name`, a fresh `id`, and `savedAt` updated to
|
||||
@@ -78,7 +98,9 @@ public struct RigEntry: Codable, Identifiable, Equatable {
|
||||
name: String,
|
||||
date: Date = Date()
|
||||
) -> RigEntry {
|
||||
RigEntry(id: UUID(), name: name, savedAt: date, state: state)
|
||||
// A duplicate is unplaced (`sortIndex: nil`) so the store appends it to the set list rather
|
||||
// than colliding with the source's position.
|
||||
RigEntry(id: UUID(), name: name, savedAt: date, state: state, sortIndex: nil)
|
||||
}
|
||||
|
||||
/// Returns a copy of this entry with a new `name` and `savedAt` updated to `date`, keeping
|
||||
@@ -93,6 +115,7 @@ public struct RigEntry: Codable, Identifiable, Equatable {
|
||||
to name: String,
|
||||
date: Date = Date()
|
||||
) -> RigEntry {
|
||||
RigEntry(id: id, name: name, savedAt: date, state: state)
|
||||
// Preserve the set-list position on rename — only the name and timestamp change.
|
||||
RigEntry(id: id, name: name, savedAt: date, state: state, sortIndex: sortIndex)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,14 +176,17 @@ public final class RigLibraryStore {
|
||||
/// asynchronously on a background queue and only logs on failure — call
|
||||
/// ``flushPendingWrites()`` to wait for it (e.g. in tests or at app termination).
|
||||
public func save(_ entry: RigEntry) throws {
|
||||
// Place the entry in the set list first (new rigs append; overwrites keep their position),
|
||||
// so the persisted file carries a stable `sortIndex`.
|
||||
let placed: RigEntry = placedForSave(entry)
|
||||
// Encode synchronously (cheap, CPU) so an encoding failure is surfaced to the caller; then
|
||||
// update the in-memory list immediately and push the disk write to the background queue.
|
||||
let data: Data = try encode(entry)
|
||||
let target: URL = fileURL(for: entry)
|
||||
let data: Data = try encode(placed)
|
||||
let target: URL = fileURL(for: placed)
|
||||
let directory: URL = self.directory
|
||||
let id: UUID = entry.id
|
||||
let id: UUID = placed.id
|
||||
let coordinated: Bool = isICloud
|
||||
upsert(entry)
|
||||
upsert(placed)
|
||||
ioQueue.async {
|
||||
// Remove any prior file for this id first (a rename changes the name-prefixed filename).
|
||||
if let stale: URL = RigLibraryStore.existingFileURL(for: id, in: directory),
|
||||
@@ -198,6 +201,87 @@ public final class RigLibraryStore {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Reordering
|
||||
|
||||
/// Moves entries within the set list (SwiftUI `onMove` semantics), renumbers every entry's
|
||||
/// `sortIndex` to its new dense position, and persists the changed files.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - source: The indices being moved, into the current `entries` order.
|
||||
/// - destination: The insertion offset, per SwiftUI `List.onMove`.
|
||||
public func move(fromOffsets source: IndexSet, toOffset destination: Int) {
|
||||
var ordered: [RigEntry] = entries
|
||||
ordered.move(fromOffsets: source, toOffset: destination)
|
||||
renumberAndPersist(ordered)
|
||||
}
|
||||
|
||||
/// Moves `entry` one slot earlier in the set list. No-op if it is already first or absent.
|
||||
public func moveUp(_ entry: RigEntry) {
|
||||
guard let index: Int = entries.firstIndex(where: { $0.id == entry.id }), index > 0 else { return }
|
||||
var ordered: [RigEntry] = entries
|
||||
ordered.swapAt(index, index - 1)
|
||||
renumberAndPersist(ordered)
|
||||
}
|
||||
|
||||
/// Moves `entry` one slot later in the set list. No-op if it is already last or absent.
|
||||
public func moveDown(_ entry: RigEntry) {
|
||||
guard let index: Int = entries.firstIndex(where: { $0.id == entry.id }),
|
||||
index < entries.count - 1 else { return }
|
||||
var ordered: [RigEntry] = entries
|
||||
ordered.swapAt(index, index + 1)
|
||||
renumberAndPersist(ordered)
|
||||
}
|
||||
|
||||
/// Reorders the set list to match `orderedIDs`, renumbers every entry, and persists the changes.
|
||||
/// Any entry not named in `orderedIDs` is appended in its current relative order (a safety net;
|
||||
/// drag reorder always passes the full id list). Used by the sidebar's drag-to-reorder.
|
||||
///
|
||||
/// - Parameter orderedIDs: The desired full ordering, by entry id.
|
||||
public func applyOrder(_ orderedIDs: [UUID]) {
|
||||
let byID: [UUID: RigEntry] = Dictionary(entries.map { ($0.id, $0) }, uniquingKeysWith: { first, _ in first })
|
||||
var ordered: [RigEntry] = orderedIDs.compactMap { byID[$0] }
|
||||
for entry: RigEntry in entries where !orderedIDs.contains(entry.id) {
|
||||
ordered.append(entry)
|
||||
}
|
||||
renumberAndPersist(ordered)
|
||||
}
|
||||
|
||||
/// Renumbers `ordered` so each entry's `sortIndex` equals its position, updates the in-memory
|
||||
/// list, and writes only the files whose index actually changed.
|
||||
private func renumberAndPersist(_ ordered: [RigEntry]) {
|
||||
var renumbered: [RigEntry] = []
|
||||
var changed: [RigEntry] = []
|
||||
for (position, entry) in ordered.enumerated() {
|
||||
if entry.sortIndex == position {
|
||||
renumbered.append(entry)
|
||||
} else {
|
||||
let moved: RigEntry = entry.reordered(to: position)
|
||||
renumbered.append(moved)
|
||||
changed.append(moved)
|
||||
}
|
||||
}
|
||||
entries = RigLibraryStore.sorted(renumbered)
|
||||
for entry: RigEntry in changed { persistToDisk(entry) }
|
||||
}
|
||||
|
||||
/// Writes `entry`'s JSON file on the background queue without touching the in-memory list or
|
||||
/// re-sorting — the reorder path already updated `entries` in one shot.
|
||||
private func persistToDisk(_ entry: RigEntry) {
|
||||
guard let data: Data = try? encode(entry) else { return }
|
||||
let target: URL = fileURL(for: entry)
|
||||
let directory: URL = self.directory
|
||||
let id: UUID = entry.id
|
||||
let coordinated: Bool = isICloud
|
||||
ioQueue.async {
|
||||
if let stale: URL = RigLibraryStore.existingFileURL(for: id, in: directory),
|
||||
stale.standardizedFileURL != target.standardizedFileURL {
|
||||
try? RigLibraryStore.removeFile(at: stale, coordinated: coordinated)
|
||||
}
|
||||
do { try RigLibraryStore.writeData(data, to: target, coordinated: coordinated) }
|
||||
catch { print("[RigLibraryStore] reorder write failed: \(error)") }
|
||||
}
|
||||
}
|
||||
|
||||
/// Deletes `entry` from memory immediately and removes its file on the background queue.
|
||||
///
|
||||
/// - Parameter entry: The rig entry to remove.
|
||||
@@ -328,10 +412,13 @@ public final class RigLibraryStore {
|
||||
let existingIDs: Set<UUID> = Set(entries.map(\.id))
|
||||
var added: Int = 0
|
||||
for entry: RigEntry in imported {
|
||||
// Avoid clobbering an existing rig that happens to share this id.
|
||||
// Avoid clobbering an existing rig that happens to share this id. Either way, clear the
|
||||
// set-list position so the import appends after the existing entries (in archive order)
|
||||
// rather than colliding with their indices — `duplicated` already unplaces; a
|
||||
// non-colliding entry is explicitly unplaced via `reordered(to: nil)`.
|
||||
let toSave: RigEntry = existingIDs.contains(entry.id)
|
||||
? entry.duplicated(name: entry.name, date: entry.savedAt)
|
||||
: entry
|
||||
: entry.reordered(to: nil)
|
||||
try save(toSave)
|
||||
added += 1
|
||||
}
|
||||
@@ -549,14 +636,31 @@ public final class RigLibraryStore {
|
||||
entries = RigLibraryStore.sorted(next)
|
||||
}
|
||||
|
||||
/// Sorts entries by name (case-insensitive), then most-recently-saved first, then id for a
|
||||
/// fully deterministic order.
|
||||
/// Sorts entries by manual set-list position first (placed entries, ascending), then — for
|
||||
/// unplaced entries or ties — by name (case-insensitive), most-recently-saved first, and id,
|
||||
/// for a fully deterministic order.
|
||||
private static func sorted(_ entries: [RigEntry]) -> [RigEntry] {
|
||||
entries.sorted { lhs, rhs in
|
||||
let lhsIndex: Int = lhs.sortIndex ?? Int.max
|
||||
let rhsIndex: Int = rhs.sortIndex ?? Int.max
|
||||
if lhsIndex != rhsIndex { return lhsIndex < rhsIndex }
|
||||
let byName: ComparisonResult = lhs.name.localizedCaseInsensitiveCompare(rhs.name)
|
||||
if byName != .orderedSame { return byName == .orderedAscending }
|
||||
if lhs.savedAt != rhs.savedAt { return lhs.savedAt > rhs.savedAt }
|
||||
return lhs.id.uuidString < rhs.id.uuidString
|
||||
}
|
||||
}
|
||||
|
||||
/// Assigns a set-list position to an entry about to be saved so every stored rig is placed:
|
||||
/// an explicit index is kept as-is; overwriting an existing rig with an unplaced snapshot
|
||||
/// preserves that rig's current position; a brand-new unplaced rig appends after the last one.
|
||||
private func placedForSave(_ entry: RigEntry) -> RigEntry {
|
||||
if entry.sortIndex != nil { return entry }
|
||||
if let existing: RigEntry = entries.first(where: { $0.id == entry.id }),
|
||||
let existingIndex: Int = existing.sortIndex {
|
||||
return entry.reordered(to: existingIndex)
|
||||
}
|
||||
let nextIndex: Int = (entries.compactMap { $0.sortIndex }.max() ?? -1) + 1
|
||||
return entry.reordered(to: nextIndex)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,35 @@ extension ShoeGaze {
|
||||
try rebuildAllBoards(from: snapshot)
|
||||
}
|
||||
|
||||
/// Applies a rig snapshot's saved hardware channel layout (``ShoeGazeState/numInputChannels`` /
|
||||
/// ``ShoeGazeState/numOutputChannels``) to the engine — a **deliberate opt-in**.
|
||||
///
|
||||
/// ``loadRig(from:)`` persists a rig's I/O but does not auto-apply it: forcing the engine's
|
||||
/// channel layout on every load would override the user's global engine config and clobber the
|
||||
/// enable-live-input flow. Call this explicitly (e.g. from the engine-config UI, or a "match rig
|
||||
/// I/O" action) when you do want the rig's saved layout. Reuses ``reconfigureEngine(...)`` — so
|
||||
/// it captures the current rig and rebuilds every board at the new layout.
|
||||
///
|
||||
/// A no-op (returns `false`) when the snapshot carries no saved counts or they already match.
|
||||
///
|
||||
/// - Parameter state: The rig snapshot whose channel layout should be applied.
|
||||
/// - Returns: `true` if the engine was reconfigured, `false` if nothing needed to change.
|
||||
/// - Throws: `SynthesisEngineConfigError.engineIsRunning` if the engine is running, or any error
|
||||
/// from ``reconfigureEngine(sampleRate:inputChannels:outputChannels:)``.
|
||||
@discardableResult
|
||||
public func applyChannelLayout(from state: ShoeGazeState) throws -> Bool {
|
||||
guard !engine.isRunning else { throw SynthesisEngineConfigError.engineIsRunning }
|
||||
guard let inCount: Int = state.numInputChannels,
|
||||
let outCount: Int = state.numOutputChannels else { return false }
|
||||
guard inCount != engine.numInputChannels || outCount != engine.numOutputChannels else { return false }
|
||||
try reconfigureEngine(
|
||||
sampleRate: engine.sampleRate,
|
||||
inputChannels: inCount,
|
||||
outputChannels: outCount
|
||||
)
|
||||
return true
|
||||
}
|
||||
|
||||
/// Default samples-per-frame captured by the scope tap.
|
||||
public static let defaultScopeBufferSize: Int = 2_048
|
||||
|
||||
|
||||
@@ -18,7 +18,15 @@ extension ShoeGaze {
|
||||
/// - Returns: A `ShoeGazeState` reflecting the current rig.
|
||||
public func captureState() -> ShoeGazeState {
|
||||
let boardStates: [BoardState] = boards.map { $0.captureState() }
|
||||
return ShoeGazeState(boards: boardStates, midiMap: midiMap)
|
||||
return ShoeGazeState(
|
||||
boards: boardStates,
|
||||
midiMap: midiMap,
|
||||
bpm: clock.bpm,
|
||||
tempoEnabled: tempoEnabled,
|
||||
inputSource: inputSource,
|
||||
numInputChannels: engine.numInputChannels,
|
||||
numOutputChannels: engine.numOutputChannels
|
||||
)
|
||||
}
|
||||
|
||||
/// Captures the current rig as a named ``RigEntry`` suitable for the rig library.
|
||||
@@ -93,11 +101,39 @@ extension ShoeGaze {
|
||||
throw PresetError.unsupportedVersion(state.version)
|
||||
}
|
||||
|
||||
// Note: `state.numInputChannels` / `numOutputChannels` are persisted with the rig (see
|
||||
// `captureState`) but intentionally NOT auto-applied here. Forcing the engine's channel
|
||||
// layout on every load would fight the global engine config and clobber the iOS
|
||||
// enable-live-input flow (rebuild engine to 1 input, then load a rig saved with 0). Apply a
|
||||
// rig's saved layout deliberately via `applyChannelLayout(from:)` / the config UI instead.
|
||||
|
||||
// Restore the saved input source before rebuilding, since board construction reads it. A
|
||||
// saved live-input channel that no longer exists on this engine falls back to the test loop
|
||||
// (same guard as reconfigureEngine), so the rebuild's addBoard() can't throw on a stale
|
||||
// channel. Absent (older rig) → leave the current input source untouched.
|
||||
if let savedInput: InputSource = state.inputSource {
|
||||
if case .liveInput(let channel) = savedInput,
|
||||
channel < 0 || channel >= engine.numInputChannels {
|
||||
inputSource = .testLoop
|
||||
} else {
|
||||
inputSource = savedInput
|
||||
}
|
||||
}
|
||||
|
||||
teardown()
|
||||
try rebuildAllBoards(from: state)
|
||||
// Restore the rig's MIDI bindings after the boards exist, so a MIDIController re-reading the
|
||||
// map resolves against the freshly rebuilt boards.
|
||||
midiMap = state.midiMap
|
||||
|
||||
// Tempo restore is graph-independent, so it happens after the rebuild. Absent (older rig) →
|
||||
// leave the current session tempo untouched.
|
||||
if let savedBpm: Double = state.bpm {
|
||||
clock.bpm = savedBpm
|
||||
}
|
||||
if let savedTempoEnabled: Bool = state.tempoEnabled {
|
||||
setTempoEnabled(savedTempoEnabled)
|
||||
}
|
||||
}
|
||||
|
||||
/// Rebuilds every board from a snapshot with all-or-nothing semantics.
|
||||
|
||||
@@ -34,26 +34,69 @@ public struct ShoeGazeState: Codable, Equatable {
|
||||
/// version bump is required for this additive field.
|
||||
public let midiMap: MIDIMap?
|
||||
|
||||
/// The rig's tempo in BPM at save time, or `nil` for a rig saved before tempo persistence.
|
||||
/// Restored onto the shared clock on load; `nil` leaves the current session tempo untouched.
|
||||
public let bpm: Double?
|
||||
|
||||
/// Whether the tempo indicator and tempo-synced features were enabled at save time, or `nil`
|
||||
/// for a rig saved before tempo persistence.
|
||||
public let tempoEnabled: Bool?
|
||||
|
||||
/// How the board head bus was fed at save time (test loop or a live-input channel), or `nil`
|
||||
/// for a rig saved before input persistence. A saved live-input channel that no longer exists
|
||||
/// on the loading engine falls back to the test loop.
|
||||
public let inputSource: InputSource?
|
||||
|
||||
/// The engine's hardware input-channel count at save time, or `nil` for a rig saved before I/O
|
||||
/// persistence. Reapplied on load (when the engine is stopped and the count differs), so a rig
|
||||
/// can restore its channel layout. Hardware that can't supply the count is negotiated at
|
||||
/// `engine.start()`, exactly as with a manual reconfigure.
|
||||
public let numInputChannels: Int?
|
||||
|
||||
/// The engine's hardware output-channel count at save time, or `nil` for a rig saved before I/O
|
||||
/// persistence. Reapplied on load under the same conditions as ``numInputChannels``.
|
||||
public let numOutputChannels: Int?
|
||||
|
||||
/// Creates a rig state snapshot.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - version: Preset format version. Defaults to `presetFormatVersion`.
|
||||
/// - boards: Ordered list of board state snapshots.
|
||||
/// - midiMap: The rig's MIDI bindings, or `nil` when there are none. Defaults to `nil`.
|
||||
/// - bpm: The rig's tempo in BPM, or `nil` to not persist a tempo. Defaults to `nil`.
|
||||
/// - tempoEnabled: Whether tempo features were enabled, or `nil`. Defaults to `nil`.
|
||||
/// - inputSource: The rig's input selection, or `nil` to not persist one. Defaults to `nil`.
|
||||
/// - numInputChannels: The engine input-channel count, or `nil`. Defaults to `nil`.
|
||||
/// - numOutputChannels: The engine output-channel count, or `nil`. Defaults to `nil`.
|
||||
public init(
|
||||
version: Int = presetFormatVersion,
|
||||
boards: [BoardState],
|
||||
midiMap: MIDIMap? = nil
|
||||
midiMap: MIDIMap? = nil,
|
||||
bpm: Double? = nil,
|
||||
tempoEnabled: Bool? = nil,
|
||||
inputSource: InputSource? = nil,
|
||||
numInputChannels: Int? = nil,
|
||||
numOutputChannels: Int? = nil
|
||||
) {
|
||||
self.version = version
|
||||
self.boards = boards
|
||||
self.midiMap = midiMap
|
||||
self.bpm = bpm
|
||||
self.tempoEnabled = tempoEnabled
|
||||
self.inputSource = inputSource
|
||||
self.numInputChannels = numInputChannels
|
||||
self.numOutputChannels = numOutputChannels
|
||||
}
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case version
|
||||
case boards
|
||||
case midiMap
|
||||
case bpm
|
||||
case tempoEnabled
|
||||
case inputSource
|
||||
case numInputChannels
|
||||
case numOutputChannels
|
||||
}
|
||||
|
||||
/// Decodes a rig snapshot, tolerating an absent, malformed, OR legacy-format `midiMap`.
|
||||
@@ -79,5 +122,12 @@ public struct ShoeGazeState: Codable, Equatable {
|
||||
} else {
|
||||
self.midiMap = nil
|
||||
}
|
||||
|
||||
// Additive tempo + input + I/O fields: absent in older rigs, so decode leniently to `nil`.
|
||||
self.bpm = try container.decodeIfPresent(Double.self, forKey: .bpm)
|
||||
self.tempoEnabled = try container.decodeIfPresent(Bool.self, forKey: .tempoEnabled)
|
||||
self.inputSource = try container.decodeIfPresent(InputSource.self, forKey: .inputSource)
|
||||
self.numInputChannels = try container.decodeIfPresent(Int.self, forKey: .numInputChannels)
|
||||
self.numOutputChannels = try container.decodeIfPresent(Int.self, forKey: .numOutputChannels)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,6 +43,23 @@ public struct HelpView: View {
|
||||
"Bypass Rig compares your sound with and without the whole pedalboard.",
|
||||
]
|
||||
)
|
||||
topicSection(
|
||||
icon: "keyboard",
|
||||
title: "Keyboard Shortcuts",
|
||||
intro: "With a hardware keyboard, these speed up live use.",
|
||||
steps: [
|
||||
"⌘1–⌘9 switch to (and solo) boards 1–9 — the fastest way to change board live.",
|
||||
"⌘⇧1–⌘⇧9 and ⌘⇧0 load set-list rigs 1–10 in the order shown in the Rigs list — "
|
||||
+ "build a set list by reordering rigs, then step through them hands-free.",
|
||||
"⌘Z mutes and unmutes the whole rig — a hard silence of all output (distinct "
|
||||
+ "from Bypass Rig, which passes your dry signal through).",
|
||||
"On macOS the menu bar adds: ⌘N New Rig, ⌘S Save Rig, ⌘E Export Archive, "
|
||||
+ "⌘I Import Archive, ⌘B Add Board, ⇧⌘R Start / Stop Recording, ⌘? Help, and "
|
||||
+ "Rigs ▸ Set List (the ⌘⇧ rig slots).",
|
||||
"The board and set-list shortcuts and ⌘Z also work on iOS / iPadOS with a "
|
||||
+ "hardware keyboard attached.",
|
||||
]
|
||||
)
|
||||
topicSection(
|
||||
icon: "waveform",
|
||||
title: "Choosing an Input",
|
||||
@@ -64,6 +81,9 @@ public struct HelpView: View {
|
||||
+ "crossfade time; each board has S (solo) and B (bypass).",
|
||||
"The Rigs sidebar lists saved rigs, with New, Save, Save As, Duplicate, Rename, "
|
||||
+ "Delete, and Erase All.",
|
||||
"Reorder rigs into a set list by dragging a row, or via each rig's Move Up / "
|
||||
+ "Move Down menu. The order is saved and travels with an exported archive; "
|
||||
+ "the top ten map to ⌘⇧1–⌘⇧0.",
|
||||
]
|
||||
)
|
||||
topicSection(
|
||||
|
||||
@@ -16,4 +16,8 @@ public extension Notification.Name {
|
||||
|
||||
/// Create a new, named, empty rig and make it current.
|
||||
static let shoeGazeNewRig: Notification.Name = Notification.Name("net.realizedsound.shoegaze.newRig")
|
||||
|
||||
/// Load the set-list rig at a zero-based slot index (0…9, mapped to ⌘⇧1…⌘⇧0 on macOS). The
|
||||
/// slot index is posted as the notification's `object` (an `NSNumber`/`Int`).
|
||||
static let shoeGazeLoadRigSlot: Notification.Name = Notification.Name("net.realizedsound.shoegaze.loadRigSlot")
|
||||
}
|
||||
|
||||
@@ -149,7 +149,20 @@ struct RigLibrarySidebarView: View {
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
// Drag the row onto another to reorder; dropping inserts it just before the target. Works
|
||||
// on macOS (mouse drag) and iPad (long-press drag); taps still select.
|
||||
.draggable(entry.id.uuidString)
|
||||
.dropDestination(for: String.self) { droppedIDs, _ in
|
||||
guard let first: String = droppedIDs.first else { return false }
|
||||
moveDragged(first, onto: entry)
|
||||
return true
|
||||
}
|
||||
.contextMenu {
|
||||
Button("Move Up") { store.moveUp(entry) }
|
||||
.disabled(isFirst(entry))
|
||||
Button("Move Down") { store.moveDown(entry) }
|
||||
.disabled(isLast(entry))
|
||||
Divider()
|
||||
Button("Rename…") { onRename(entry) }
|
||||
Button("Duplicate…") { onDuplicate(entry) }
|
||||
// Encoding a fully-concrete RigEntry to JSON does not fail in practice; on the
|
||||
@@ -167,6 +180,28 @@ struct RigLibrarySidebarView: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Reorder helpers
|
||||
|
||||
private func isFirst(_ entry: RigEntry) -> Bool {
|
||||
store.entries.first?.id == entry.id
|
||||
}
|
||||
|
||||
private func isLast(_ entry: RigEntry) -> Bool {
|
||||
store.entries.last?.id == entry.id
|
||||
}
|
||||
|
||||
/// Moves the dragged entry (by id string) to sit just before `target` in the set list.
|
||||
private func moveDragged(_ draggedIDString: String, onto target: RigEntry) {
|
||||
guard let draggedID: UUID = UUID(uuidString: draggedIDString), draggedID != target.id else { return }
|
||||
var order: [UUID] = store.entries.map(\.id)
|
||||
guard let from: Int = order.firstIndex(of: draggedID) else { return }
|
||||
order.remove(at: from)
|
||||
// Target's index in the post-removal array; inserting there drops the dragged row before it.
|
||||
guard let to: Int = order.firstIndex(of: target.id) else { return }
|
||||
order.insert(draggedID, at: to)
|
||||
store.applyOrder(order)
|
||||
}
|
||||
|
||||
// MARK: - Action bar
|
||||
|
||||
private var actionBar: some View {
|
||||
|
||||
@@ -65,6 +65,9 @@ public struct ShoeGazeBuilderView: View {
|
||||
private static let maxCrossfadeSeconds: Double = 10.0
|
||||
/// Highest board reachable via a ⌘-number switch shortcut.
|
||||
private static let maxBoardShortcuts: Int = 9
|
||||
|
||||
/// The number of set-list rigs reachable by ⌘⇧1…⌘⇧0 (the top ten).
|
||||
private static let maxRigShortcuts: Int = 10
|
||||
/// Default filename offered when exporting the whole library as an archive.
|
||||
private static let defaultArchiveFileName: String = "ShoeGaze Library"
|
||||
/// Extra width reserved for the rig-library sidebar on top of the builder's minimum width.
|
||||
@@ -311,6 +314,11 @@ public struct ShoeGazeBuilderView: View {
|
||||
.onReceive(NotificationCenter.default.publisher(for: .shoeGazeNewRig)) { _ in
|
||||
promptNewRig()
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: .shoeGazeLoadRigSlot)) { note in
|
||||
if let index: Int = note.object as? Int {
|
||||
loadRigSlot(index)
|
||||
}
|
||||
}
|
||||
.confirmationDialog(
|
||||
"Clear all boards?",
|
||||
isPresented: $showClearDialog,
|
||||
@@ -578,14 +586,7 @@ public struct ShoeGazeBuilderView: View {
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
rigBypassButton
|
||||
// fixedSize stops the switch Toggle from expanding to fill the row (which pushed
|
||||
// the following controls far to the right, under the scope).
|
||||
Toggle("Mute rig", isOn: Binding(
|
||||
get: { shoeGaze.tunerMutesRig },
|
||||
set: { shoeGaze.tunerMutesRig = $0 }
|
||||
))
|
||||
.toggleStyle(.switch)
|
||||
.fixedSize()
|
||||
rigMuteButton
|
||||
helpButton
|
||||
if let midi: MIDIController = midi {
|
||||
MIDIIndicatorView(controller: midi) { showMIDISheet = true }
|
||||
@@ -942,6 +943,7 @@ public struct ShoeGazeBuilderView: View {
|
||||
}
|
||||
helpButton
|
||||
rigBypassButton
|
||||
rigMuteButton
|
||||
EngineConfigView(
|
||||
shoeGaze: shoeGaze,
|
||||
hardwareSampleRate: hardwareSampleRate,
|
||||
@@ -951,12 +953,13 @@ public struct ShoeGazeBuilderView: View {
|
||||
.frame(height: TempoView.enabledHeight)
|
||||
|
||||
HStack(spacing: ShoeGazeBuilderView.rowSpacing) {
|
||||
// Mute-rig-while-tuning toggle sits to the left of the input selector.
|
||||
Toggle("Mute rig", isOn: Binding(
|
||||
// Whether engaging the tuner silences the rig; sits left of the input selector.
|
||||
Toggle("Mute while tuning", isOn: Binding(
|
||||
get: { shoeGaze.tunerMutesRig },
|
||||
set: { shoeGaze.tunerMutesRig = $0 }
|
||||
))
|
||||
.toggleStyle(.switch)
|
||||
.fixedSize()
|
||||
|
||||
Text("Input:")
|
||||
.font(.subheadline)
|
||||
@@ -1010,6 +1013,22 @@ public struct ShoeGazeBuilderView: View {
|
||||
.help("Bypass the entire rig — every board passes your dry input straight through")
|
||||
}
|
||||
|
||||
/// Global rig mute — a hard gate to silence the whole output (distinct from Bypass, which
|
||||
/// passes the dry signal through). Lit when engaged. A live performance panic/silence control.
|
||||
private var rigMuteButton: some View {
|
||||
let muted: Bool = shoeGaze.rigMuted
|
||||
return Button {
|
||||
shoeGaze.toggleRigMuted()
|
||||
} label: {
|
||||
Label(muted ? "Rig Muted" : "Mute Rig",
|
||||
systemImage: muted ? "speaker.slash.fill" : "speaker.wave.2.fill")
|
||||
.font(.subheadline)
|
||||
}
|
||||
.buttonStyle(.bordered)
|
||||
.tint(muted ? .red : .gray)
|
||||
.help("Mute the entire rig output — silences all sound")
|
||||
}
|
||||
|
||||
// MARK: - Board area
|
||||
|
||||
private var boardArea: some View {
|
||||
@@ -1213,19 +1232,40 @@ public struct ShoeGazeBuilderView: View {
|
||||
// MARK: - Board-switch shortcuts
|
||||
|
||||
/// Hidden ⌘1…⌘9 buttons that solo (live-switch to) the matching board and select it as the
|
||||
/// edit target. Kept at zero opacity so the shortcuts stay active without showing chrome.
|
||||
/// edit target, plus ⌘M to toggle the rig mute. Kept at zero opacity so the shortcuts stay
|
||||
/// active without showing chrome.
|
||||
private var boardSwitchShortcuts: some View {
|
||||
ZStack {
|
||||
ForEach(0 ..< min(ShoeGazeBuilderView.maxBoardShortcuts, shoeGaze.boards.count), id: \.self) { index in
|
||||
Button("") { switchToBoard(index) }
|
||||
// Titles are invisible (the ZStack is opacity 0) but feed the iPadOS ⌘-hold
|
||||
// discoverability HUD, so the shortcut reads as a named command there.
|
||||
Button("Switch to Board \(index + 1)") { switchToBoard(index) }
|
||||
.keyboardShortcut(KeyEquivalent(Character("\(index + 1)")), modifiers: .command)
|
||||
}
|
||||
// ⌘Z toggles rig mute on iOS/iPadOS hardware keyboards. On macOS the Board menu item
|
||||
// owns the ⌘Z equivalent, so it is not also bound here (a double-bound event is ambiguous).
|
||||
#if !os(macOS)
|
||||
Button("Mute / Unmute Rig") { shoeGaze.toggleRigMuted() }
|
||||
.keyboardShortcut("z", modifiers: .command)
|
||||
// ⌘⇧1…⌘⇧9 + ⌘⇧0 load set-list rigs 1…10. macOS binds these via the Rigs ▸ Set List menu
|
||||
// instead, so they are not also bound here.
|
||||
ForEach(0 ..< ShoeGazeBuilderView.maxRigShortcuts, id: \.self) { slot in
|
||||
Button("Load Set List Rig \(slot + 1)") { loadRigSlot(slot) }
|
||||
.keyboardShortcut(ShoeGazeBuilderView.rigSlotKey(slot), modifiers: [.command, .shift])
|
||||
}
|
||||
#endif
|
||||
}
|
||||
.opacity(0)
|
||||
.frame(width: 0, height: 0)
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
|
||||
/// The key equivalent for set-list slot `slot` (0-based): slots 0…8 map to `1`…`9`, slot 9 to
|
||||
/// `0` — matching the ⌘⇧1…⌘⇧0 physical row.
|
||||
private static func rigSlotKey(_ slot: Int) -> KeyEquivalent {
|
||||
KeyEquivalent(Character(slot < 9 ? "\(slot + 1)" : "0"))
|
||||
}
|
||||
|
||||
/// Solos board `index` (a live amp-channel-style switch) and makes it the edit target.
|
||||
private func switchToBoard(_ index: Int) {
|
||||
guard index < shoeGaze.boards.count else { return }
|
||||
@@ -1315,6 +1355,16 @@ public struct ShoeGazeBuilderView: View {
|
||||
transportTick.toggle()
|
||||
}
|
||||
|
||||
/// Loads the set-list rig at zero-based `index` (the library's manual order), if one exists.
|
||||
/// Backs the ⌘⇧1…⌘⇧0 shortcuts and the macOS Rigs ▸ Set List menu. Routes through
|
||||
/// ``requestLoad(_:)`` so the unsaved-changes prompt and no-op-if-current behaviour apply.
|
||||
///
|
||||
/// - Parameter index: Zero-based slot index (0…9).
|
||||
private func loadRigSlot(_ index: Int) {
|
||||
guard index >= 0, index < library.entries.count else { return }
|
||||
requestLoad(library.entries[index])
|
||||
}
|
||||
|
||||
/// Switches to `entry`, prompting to save first when the current rig has unsaved changes.
|
||||
/// No-op when `entry` is already the current rig.
|
||||
private func requestLoad(_ entry: RigEntry) {
|
||||
|
||||
@@ -19,13 +19,32 @@ public struct TempoView: View {
|
||||
// MARK: - Constants
|
||||
|
||||
private static let pollIntervalNanoseconds: UInt64 = 33_333_333 // ~30 Hz
|
||||
/// Fraction of each beat the LED stays lit — a short flash, not a 50% duty-cycle blink.
|
||||
private static let flashDutyCycle: Double = 0.15
|
||||
private static let minBpm: Double = 30.0
|
||||
private static let maxBpm: Double = 300.0
|
||||
private static let bpmStep: Double = 1.0
|
||||
private static let ledDiameter: CGFloat = 14
|
||||
private static let rowSpacing: CGFloat = 10
|
||||
|
||||
// Metronome track: a dot swings wall-to-wall once per beat, pausing at each wall (the beat)
|
||||
// so the eye can anticipate the hit. Pendulum easing comes for free from the cosine map.
|
||||
private static let trackWidth: CGFloat = 150
|
||||
private static let trackHeight: CGFloat = 16
|
||||
private static let trackCornerRadius: CGFloat = 4
|
||||
private static let trackBrightness: Double = 0.14
|
||||
private static let trackBorderOpacity: Double = 0.35
|
||||
private static let trackBorderWidth: CGFloat = 1
|
||||
/// Vertical playhead sweeping horizontally across the track (Looper-style), full track height.
|
||||
private static let lineWidth: CGFloat = 3
|
||||
/// Playhead opacity floor at mid-swing; ramps to full at the walls so it fades as it travels
|
||||
/// toward center and re-brightens into each beat.
|
||||
private static let lineMinOpacity: Double = 0.25
|
||||
/// Curve on the wall-proximity → brightness map; > 1 dims harder through the middle.
|
||||
private static let brightnessFadeCurve: Double = 1.6
|
||||
/// Soft glow drawn behind the playhead; its opacity peaks at the turnaround (on the beat).
|
||||
private static let glowWidth: CGFloat = 16
|
||||
private static let glowMaxOpacity: Double = 0.7
|
||||
/// End-wall tick marks sit on the beat positions.
|
||||
private static let wallTickWidth: CGFloat = 2
|
||||
private static let wallTickOpacity: Double = 0.4
|
||||
/// Fixed row height = the enabled (BPM/TAP-visible) height, so toggling doesn't shift layout.
|
||||
static let enabledHeight: CGFloat = 34
|
||||
|
||||
@@ -34,7 +53,8 @@ public struct TempoView: View {
|
||||
private let shoeGaze: ShoeGaze
|
||||
|
||||
@State private var displayedBpm: Double
|
||||
@State private var ledOn: Bool = false
|
||||
/// Continuous beat position, polled from the clock; drives the metronome dot.
|
||||
@State private var beat: Double = 0.0
|
||||
|
||||
// MARK: - Init
|
||||
|
||||
@@ -57,7 +77,7 @@ public struct TempoView: View {
|
||||
.help("Show the tempo indicator and enable tempo-synced controls")
|
||||
|
||||
if shoeGaze.tempoEnabled {
|
||||
led
|
||||
metronome
|
||||
Text("\(Int(displayedBpm.rounded())) BPM")
|
||||
.font(.system(size: 18, weight: .semibold, design: .rounded))
|
||||
.foregroundStyle(Color.white)
|
||||
@@ -84,9 +104,7 @@ public struct TempoView: View {
|
||||
.frame(height: TempoView.enabledHeight)
|
||||
.task(id: shoeGaze.tempoEnabled) {
|
||||
while shoeGaze.tempoEnabled && !Task.isCancelled {
|
||||
let beat: Double = shoeGaze.clock.currentBeat
|
||||
let phase: Double = beat - beat.rounded(.down)
|
||||
ledOn = phase < TempoView.flashDutyCycle
|
||||
beat = shoeGaze.clock.currentBeat
|
||||
displayedBpm = shoeGaze.clock.bpm
|
||||
try? await Task.sleep(nanoseconds: TempoView.pollIntervalNanoseconds)
|
||||
}
|
||||
@@ -95,10 +113,62 @@ public struct TempoView: View {
|
||||
|
||||
// MARK: - Subviews
|
||||
|
||||
private var led: some View {
|
||||
Circle()
|
||||
.fill(ledOn ? Color.red : Color.red.opacity(0.15))
|
||||
.frame(width: TempoView.ledDiameter, height: TempoView.ledDiameter)
|
||||
/// Horizontal pendulum: the dot maps `beat` through a cosine so it eases to a stop at each
|
||||
/// wall (an integer beat) and moves fastest at mid-swing — the wall pauses give the eye a
|
||||
/// runway to anticipate the beat. `x01 = (1 − cos(π·swing)) / 2`, `swing = beat mod 2`, puts
|
||||
/// the left wall on even beats and the right wall on odd beats (one wall hit per beat).
|
||||
private var metronome: some View {
|
||||
// Reduce beat mod 2 before the cosine so precision holds over a long session.
|
||||
let swing: Double = beat.truncatingRemainder(dividingBy: 2)
|
||||
let x01: Double = (1 - cos(.pi * swing)) / 2
|
||||
// Proximity to a wall in [0, 1]: 1 at a wall (on the beat), 0 at mid-swing. The curve dims
|
||||
// harder through the middle so the playhead visibly fades as it travels toward center.
|
||||
let wallGlow: Double = pow(1 - 2 * min(x01, 1 - x01), TempoView.brightnessFadeCurve)
|
||||
|
||||
return ZStack(alignment: .leading) {
|
||||
RoundedRectangle(cornerRadius: TempoView.trackCornerRadius)
|
||||
.fill(Color(white: TempoView.trackBrightness))
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: TempoView.trackCornerRadius)
|
||||
.strokeBorder(
|
||||
Color.white.opacity(TempoView.trackBorderOpacity),
|
||||
lineWidth: TempoView.trackBorderWidth
|
||||
)
|
||||
)
|
||||
// Beat-position tick marks flush against each end wall.
|
||||
.overlay(alignment: .leading) { wallTick }
|
||||
.overlay(alignment: .trailing) { wallTick }
|
||||
|
||||
playhead(x01: x01, wallGlow: wallGlow)
|
||||
}
|
||||
.frame(width: TempoView.trackWidth, height: TempoView.trackHeight)
|
||||
.clipShape(RoundedRectangle(cornerRadius: TempoView.trackCornerRadius))
|
||||
}
|
||||
|
||||
private var wallTick: some View {
|
||||
Rectangle()
|
||||
.fill(Color.white.opacity(TempoView.wallTickOpacity))
|
||||
.frame(width: TempoView.wallTickWidth)
|
||||
}
|
||||
|
||||
private func playhead(x01: Double, wallGlow: Double) -> some View {
|
||||
// Travel spans the track minus the line's own width so the playhead kisses each wall.
|
||||
let travel: CGFloat = TempoView.trackWidth - TempoView.lineWidth
|
||||
let x: CGFloat = CGFloat(x01) * travel
|
||||
let lineOpacity: Double = TempoView.lineMinOpacity + (1 - TempoView.lineMinOpacity) * wallGlow
|
||||
|
||||
// Center glow + line share a leading-aligned box; offset positions the line's leading edge.
|
||||
return ZStack {
|
||||
Rectangle()
|
||||
.fill(Color.red.opacity(TempoView.glowMaxOpacity * wallGlow))
|
||||
.frame(width: TempoView.glowWidth, height: TempoView.trackHeight)
|
||||
.blur(radius: TempoView.glowWidth / 3)
|
||||
Rectangle()
|
||||
.fill(Color.red.opacity(lineOpacity))
|
||||
.frame(width: TempoView.lineWidth, height: TempoView.trackHeight)
|
||||
}
|
||||
.frame(width: TempoView.lineWidth, height: TempoView.trackHeight, alignment: .center)
|
||||
.offset(x: x)
|
||||
}
|
||||
|
||||
private var tapArea: some View {
|
||||
|
||||
Reference in New Issue
Block a user