Compare commits
46 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f61961b90b | |||
| 7e39842eb2 | |||
| 2772abdc56 | |||
| a33d5488c9 | |||
| 2c2ce06797 | |||
| 8b72957502 | |||
| e051521c04 | |||
| 4b0cf65a2b | |||
| 0bfc25ace6 | |||
| 426a288002 | |||
| 12e83bd172 | |||
| bf1e09ede3 | |||
| cd3aeb771b | |||
| e75b50b157 | |||
| 6a3c4fdca9 | |||
| 22ae022143 | |||
| 722c8d9069 | |||
| 1c9979af52 | |||
| 36202a5e95 | |||
| 19feb03fe8 | |||
| f97ba90ea6 | |||
| 67744ec89d | |||
| ba80573213 | |||
| efa193ea37 | |||
| 45b18b5ea8 | |||
| 5b343a2cce | |||
| d07247e40e | |||
| bdfbe04713 | |||
| 5090a9255f | |||
| 4e58c9bd9b | |||
| 2ce6dda9da | |||
| b6f1d78066 | |||
| 296ca1b24e | |||
| 3ef39a7a0d | |||
| 5dafc00d98 | |||
| fb3e2d2653 | |||
| ae067ac6d7 | |||
| 6f651b6e17 | |||
| 67d4434220 | |||
| b99a526df6 | |||
| d728bfa72a | |||
| fee7892101 | |||
| 83b8fff74b | |||
| 3007b76798 | |||
| 465e3e6dfd | |||
| 947dfe427a |
@@ -0,0 +1,133 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to ShoeGaze are recorded here. The format follows
|
||||||
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and the project uses
|
||||||
|
[semantic versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [2.1.0] — 2026-07-10
|
||||||
|
|
||||||
|
Tempo comes to the pedals. Delay times and modulation rates can lock to a note
|
||||||
|
division of the live tempo — a quarter-note delay, a dotted-eighth, an eighth-triplet
|
||||||
|
LFO — shown with real music-notation glyphs and following the tempo as it changes.
|
||||||
|
Delays reach further, the BPM is directly editable, and every mappable control shows
|
||||||
|
its MIDI / key binding right on the pedal.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **Tempo-synced pedal parameters.** Lock a delay time or a modulation rate to a note
|
||||||
|
division — whole down to sixteenth, including dotted and triplet values — and it is
|
||||||
|
derived from the shared tempo, following tap tempo, the stepper, the BPM field, and
|
||||||
|
MIDI. Delay time on Delay, Feedback Delay, Ping-Pong, Reverse Delay, and each of
|
||||||
|
Multi-Tap's three taps; LFO rate on Tremolo, Vibrato, Chorus, Flanger, Phaser, and
|
||||||
|
Modulation. A MIDI CC bound to a synced parameter is ignored while it stays synced
|
||||||
|
(the tempo drives the value) and resumes control once the parameter is set to Free.
|
||||||
|
- **Note-value glyphs.** The division picker uses drawn music-notation glyphs —
|
||||||
|
noteheads, stems, flags, an augmentation dot for dotted values, and a bracketed "3"
|
||||||
|
over triplets — instead of text labels.
|
||||||
|
- **Editable BPM.** The tempo readout is now a text field: type a tempo directly
|
||||||
|
(integer only, clamped to 30–300 BPM). The stepper and tap tempo still work, and a
|
||||||
|
synced pedal follows a typed change immediately.
|
||||||
|
- **In-context control mapping.** Each pedal draws a small badge on every mappable
|
||||||
|
control showing its binding source — Program Change footswitch (PC), Control Change
|
||||||
|
expression (CC), or letter Key (KEY) — with a legend above the board. Completes the
|
||||||
|
computer-keyboard control mapping.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- **Longer delays.** Maximum delay time raised to 5 seconds across the delay pedals
|
||||||
|
(previously 1–2 s), so tempo-synced values at slow tempos (whole and half notes) fit.
|
||||||
|
- Note divisions that would exceed a parameter's range at the current tempo are shown
|
||||||
|
disabled in the picker, and an active sync that has to clamp shows a warning marker.
|
||||||
|
|
||||||
|
### Compatibility
|
||||||
|
|
||||||
|
Additive: rigs saved before this release load unchanged (every parameter defaults to
|
||||||
|
"free"), and 2.1 rigs still open in older builds — the tempo-sync state is simply
|
||||||
|
ignored there.
|
||||||
|
|
||||||
|
## [2.0.0] — 2026-07-05
|
||||||
|
|
||||||
|
Major release. Performance-focused: a visual metronome, a real rig mute with
|
||||||
|
keyboard control, and rigs that remember their tempo, input, and I/O — plus a
|
||||||
|
saveable set-list order for hands-free switching between rigs live. The version
|
||||||
|
jumps to 2.0.0 to align ShoeGaze's numbering with the wider project family.
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **Visual metronome tempo indicator.** A horizontal playhead sweeps wall-to-wall
|
||||||
|
once per beat with pendulum easing (it slows into each beat so you can anticipate
|
||||||
|
it), fades toward center, and flashes a glow on the downbeat. Replaces the single
|
||||||
|
flashing LED.
|
||||||
|
- **Rig Mute (⌘Z).** A hard gate that silences the entire rig output — distinct from
|
||||||
|
Bypass Rig, which passes your dry signal through. Reachable from the header, the
|
||||||
|
per-board volume row, the macOS Board menu, and MIDI.
|
||||||
|
- **Keyboard shortcuts** (macOS native menus + iOS/iPadOS hardware keyboards):
|
||||||
|
- `⌘1`–`⌘9` — switch to / solo boards 1–9.
|
||||||
|
- `⌘⇧1`–`⌘⇧9` and `⌘⇧0` — load set-list rigs 1–10 in library order.
|
||||||
|
- `⌘Z` — toggle rig mute.
|
||||||
|
|
||||||
|
All are listed in the in-app Help.
|
||||||
|
- **macOS menus.** Board ▸ Mute Rig and Board ▸ Bypass Rig (with live state), and a
|
||||||
|
Rigs ▸ Set List submenu whose ten slots map to `⌘⇧1`–`⌘⇧0` and track the current
|
||||||
|
library order.
|
||||||
|
- **Set-list ordering.** Reorder rigs in the picker 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 the `⌘⇧` shortcuts.
|
||||||
|
- **Per-rig persistence.** A saved rig now also stores its tempo (BPM + enabled
|
||||||
|
state) and input selection. Engine input/output channel counts are saved too, and
|
||||||
|
applied on demand via `applyChannelLayout(from:)` rather than forced on every load.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- The header "Mute rig" toggle — which actually only set the tuner-mutes-rig
|
||||||
|
preference — is now a real rig-mute button. The tuner preference is relabeled
|
||||||
|
**"Mute while tuning"**.
|
||||||
|
- The rig library now honors a manual set-list order instead of sorting by name/date.
|
||||||
|
New rigs append to the end; renaming a rig keeps its position.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Importing a rig archive into a non-empty library no longer collides set-list
|
||||||
|
positions with existing rigs — imported rigs append in archive order.
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
|
||||||
|
- The **ShoeGazeDemo** (macOS) and **ShoeGazeiOSDemo** (iOS) minimal-player apps and
|
||||||
|
their Xcode projects. Only the full **ShoeGazeBuilder** (macOS) and
|
||||||
|
**ShoeGazeBuilderiOS** (iPad) apps remain.
|
||||||
|
|
||||||
|
### Compatibility
|
||||||
|
|
||||||
|
- Despite the major-version bump, rig persistence is backward-compatible: the new
|
||||||
|
tempo / input / I/O / set-list fields are additive and optional. Rigs saved by
|
||||||
|
earlier versions load unchanged (missing fields are ignored), and rigs saved by
|
||||||
|
2.0.0 still open in older builds (the new keys are ignored there). The 2.0.0 bump
|
||||||
|
reflects the scope of new features and version alignment, not a format break.
|
||||||
|
|
||||||
|
## [1.5.0] — 2026-07-04
|
||||||
|
|
||||||
|
- Looper pedal, iPad/iOS layout rework, Lyrebird 1.2.3.
|
||||||
|
|
||||||
|
## [1.4.0] — 2026-07-01
|
||||||
|
|
||||||
|
- Maintenance and refinements.
|
||||||
|
|
||||||
|
## [1.3.0] — 2026-06-28
|
||||||
|
|
||||||
|
- Rig / board sharing via the `.shoegaze` document type.
|
||||||
|
|
||||||
|
## [1.2.0] — 2026-06-28
|
||||||
|
|
||||||
|
- Ten new pedals, iCloud rig library, builder UI rework.
|
||||||
|
|
||||||
|
## [1.1.1] — 2026-06-26
|
||||||
|
|
||||||
|
- Info-button placement and region-lane drag-drop fix.
|
||||||
|
|
||||||
|
## [1.1.0] — 2026-06-26
|
||||||
|
|
||||||
|
- Refinements over the initial release.
|
||||||
|
|
||||||
|
## [1.0.0] — 2026-06-24
|
||||||
|
|
||||||
|
- Initial ShoeGaze release.
|
||||||
@@ -163,7 +163,7 @@
|
|||||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 5;
|
CURRENT_PROJECT_VERSION = 8;
|
||||||
DEAD_CODE_STRIPPING = YES;
|
DEAD_CODE_STRIPPING = YES;
|
||||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||||
@@ -176,7 +176,7 @@
|
|||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 15.0;
|
MACOSX_DEPLOYMENT_TARGET = 15.0;
|
||||||
MARKETING_VERSION = 1.3.0;
|
MARKETING_VERSION = 2.0.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilder;
|
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilder;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
@@ -194,7 +194,7 @@
|
|||||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 5;
|
CURRENT_PROJECT_VERSION = 8;
|
||||||
DEAD_CODE_STRIPPING = YES;
|
DEAD_CODE_STRIPPING = YES;
|
||||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
ENABLE_HARDENED_RUNTIME = YES;
|
||||||
@@ -206,7 +206,7 @@
|
|||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 15.0;
|
MACOSX_DEPLOYMENT_TARGET = 15.0;
|
||||||
MARKETING_VERSION = 1.3.0;
|
MARKETING_VERSION = 2.0.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilder;
|
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilder;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import LyrebirdShoeGazeUI
|
|||||||
/// The engine is **not** started automatically; the user clicks Start in the builder's toolbar.
|
/// The engine is **not** started automatically; the user clicks Start in the builder's toolbar.
|
||||||
/// On termination the engine is stopped to release Core Audio resources cleanly.
|
/// On termination the engine is stopped to release Core Audio resources cleanly.
|
||||||
@MainActor
|
@MainActor
|
||||||
final class AppDelegate: NSObject, NSApplicationDelegate {
|
final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuDelegate {
|
||||||
|
|
||||||
// MARK: - Engine configuration constants
|
// MARK: - Engine configuration constants
|
||||||
|
|
||||||
@@ -65,6 +65,26 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
/// Record toggle item, retained so `validateMenuItem(_:)` can flip its title + enabled state.
|
/// Record toggle item, retained so `validateMenuItem(_:)` can flip its title + enabled state.
|
||||||
private var recordMenuItem: NSMenuItem?
|
private var recordMenuItem: NSMenuItem?
|
||||||
|
|
||||||
|
/// Rig-mute toggle item, retained so `validateMenuItem(_:)` can flip its title + checkmark to
|
||||||
|
/// match the current mute state (which may also change from the UI, MIDI, or the tuner).
|
||||||
|
private var muteMenuItem: NSMenuItem?
|
||||||
|
|
||||||
|
/// Rig-bypass toggle item, retained so `validateMenuItem(_:)` can flip its title + checkmark to
|
||||||
|
/// match the current bypass state (which may also change from the UI or MIDI).
|
||||||
|
private var bypassMenuItem: NSMenuItem?
|
||||||
|
|
||||||
|
/// The Rigs ▸ Set List submenu, retained so its item titles can be refreshed to the current
|
||||||
|
/// library order each time it opens (via `menuNeedsUpdate(_:)`).
|
||||||
|
private var setListMenu: NSMenu?
|
||||||
|
|
||||||
|
/// The ten fixed ⌘⇧1…⌘⇧0 set-list items (tags 0…9). Their key equivalents fire whether or not
|
||||||
|
/// the menu is open; `validateMenuItem(_:)` disables slots with no rig, and `menuNeedsUpdate`
|
||||||
|
/// refreshes their titles to the rig names.
|
||||||
|
private var setListMenuItems: [NSMenuItem] = []
|
||||||
|
|
||||||
|
/// Number of set-list slots exposed as ⌘⇧1…⌘⇧0.
|
||||||
|
private static let setListSlotCount: Int = 10
|
||||||
|
|
||||||
/// The Help window, created lazily on first open and reused thereafter.
|
/// The Help window, created lazily on first open and reused thereafter.
|
||||||
private var helpWindow: LyrebirdWindow?
|
private var helpWindow: LyrebirdWindow?
|
||||||
|
|
||||||
@@ -283,6 +303,51 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
// Engine start/stop lives in the in-window EngineConfigView (with sample-rate/channel
|
// Engine start/stop lives in the in-window EngineConfigView (with sample-rate/channel
|
||||||
// config and the mismatch alert), so the Board menu only adds boards.
|
// config and the mismatch alert), so the Board menu only adds boards.
|
||||||
addItem(to: boardMenu, title: "Add Board", action: #selector(addBoardAction(_:)), key: "b")
|
addItem(to: boardMenu, title: "Add Board", action: #selector(addBoardAction(_:)), key: "b")
|
||||||
|
boardMenu.addItem(NSMenuItem.separator())
|
||||||
|
// ⌘Z toggles rig mute (a hard silence of all output; distinct from Bypass Rig's dry
|
||||||
|
// passthrough). Owns the ⌘Z key equivalent on macOS; the in-window view binds it on iOS.
|
||||||
|
self.muteMenuItem = addItem(
|
||||||
|
to: boardMenu,
|
||||||
|
title: "Mute Rig",
|
||||||
|
action: #selector(toggleMuteAction(_:)),
|
||||||
|
key: "z"
|
||||||
|
)
|
||||||
|
// Bypass Rig routes every board to its dry input (pedals skipped) — distinct from Mute's
|
||||||
|
// hard silence. No key equivalent: ⌘B is Add Board, and Bypass has a prominent on-screen button.
|
||||||
|
self.bypassMenuItem = addItem(
|
||||||
|
to: boardMenu,
|
||||||
|
title: "Bypass Rig",
|
||||||
|
action: #selector(toggleBypassAction(_:)),
|
||||||
|
key: ""
|
||||||
|
)
|
||||||
|
|
||||||
|
// Rigs menu — a Set List of the top ten library rigs, each on ⌘⇧1…⌘⇧0. The items are
|
||||||
|
// fixed; their titles refresh to the current library order on open, and their key
|
||||||
|
// equivalents fire whether or not the menu is showing.
|
||||||
|
let rigsMenuItem: NSMenuItem = NSMenuItem()
|
||||||
|
mainMenu.addItem(rigsMenuItem)
|
||||||
|
let rigsMenu: NSMenu = NSMenu(title: "Rigs")
|
||||||
|
rigsMenuItem.submenu = rigsMenu
|
||||||
|
let setListItem: NSMenuItem = NSMenuItem(title: "Set List", action: nil, keyEquivalent: "")
|
||||||
|
rigsMenu.addItem(setListItem)
|
||||||
|
let setListSubmenu: NSMenu = NSMenu(title: "Set List")
|
||||||
|
setListSubmenu.delegate = self
|
||||||
|
setListItem.submenu = setListSubmenu
|
||||||
|
for slot: Int in 0 ..< AppDelegate.setListSlotCount {
|
||||||
|
// Slots 0…8 → ⌘⇧1…⌘⇧9; slot 9 → ⌘⇧0 (matches the physical number row).
|
||||||
|
let key: String = slot < 9 ? "\(slot + 1)" : "0"
|
||||||
|
let item: NSMenuItem = NSMenuItem(
|
||||||
|
title: "\(slot + 1). —",
|
||||||
|
action: #selector(loadRigSlotAction(_:)),
|
||||||
|
keyEquivalent: key
|
||||||
|
)
|
||||||
|
item.keyEquivalentModifierMask = [.command, .shift]
|
||||||
|
item.target = self
|
||||||
|
item.tag = slot
|
||||||
|
setListSubmenu.addItem(item)
|
||||||
|
setListMenuItems.append(item)
|
||||||
|
}
|
||||||
|
self.setListMenu = setListSubmenu
|
||||||
|
|
||||||
// Record menu — choose an output folder, then toggle recording.
|
// Record menu — choose an output folder, then toggle recording.
|
||||||
let recordMenuItem: NSMenuItem = NSMenuItem()
|
let recordMenuItem: NSMenuItem = NSMenuItem()
|
||||||
@@ -382,6 +447,25 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc private func toggleMuteAction(_ sender: Any?) {
|
||||||
|
shoeGaze.toggleRigMuted()
|
||||||
|
// Reflect the new state immediately, not only on the next menu-open validation.
|
||||||
|
muteMenuItem?.title = shoeGaze.rigMuted ? "Unmute Rig" : "Mute Rig"
|
||||||
|
muteMenuItem?.state = shoeGaze.rigMuted ? .on : .off
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func toggleBypassAction(_ sender: Any?) {
|
||||||
|
shoeGaze.toggleRigBypassed()
|
||||||
|
bypassMenuItem?.title = shoeGaze.rigBypassed ? "Re-engage Rig" : "Bypass Rig"
|
||||||
|
bypassMenuItem?.state = shoeGaze.rigBypassed ? .on : .off
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Loads the set-list rig at the sender's slot tag. Forwards to the in-window builder (which
|
||||||
|
/// owns the current-rig state, the unsaved-changes prompt, and engine lifecycle) via notification.
|
||||||
|
@objc private func loadRigSlotAction(_ sender: NSMenuItem) {
|
||||||
|
NotificationCenter.default.post(name: .shoeGazeLoadRigSlot, object: sender.tag)
|
||||||
|
}
|
||||||
|
|
||||||
@objc private func addBoardAction(_ sender: Any?) {
|
@objc private func addBoardAction(_ sender: Any?) {
|
||||||
var created: PedalBoard?
|
var created: PedalBoard?
|
||||||
do {
|
do {
|
||||||
@@ -421,12 +505,45 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
|
|||||||
recordMenuItem?.title = shoeGaze.isRecording ? "Stop Recording" : "Start Recording"
|
recordMenuItem?.title = shoeGaze.isRecording ? "Stop Recording" : "Start Recording"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - NSMenuDelegate
|
||||||
|
|
||||||
|
/// Refreshes the Set List item titles to the current library order each time the submenu opens.
|
||||||
|
/// Key equivalents fire independently of this (see `setListMenuItems`); this is display only.
|
||||||
|
func menuNeedsUpdate(_ menu: NSMenu) {
|
||||||
|
guard menu === setListMenu else { return }
|
||||||
|
let entries: [RigEntry] = library.entries
|
||||||
|
for item: NSMenuItem in setListMenuItems {
|
||||||
|
let slot: Int = item.tag
|
||||||
|
if slot < entries.count {
|
||||||
|
item.title = "\(slot + 1). \(entries[slot].name)"
|
||||||
|
} else {
|
||||||
|
item.title = "\(slot + 1). —"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
|
func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
|
||||||
if menuItem == recordMenuItem {
|
if menuItem == recordMenuItem {
|
||||||
menuItem.title = shoeGaze.isRecording ? "Stop Recording" : "Start Recording"
|
menuItem.title = shoeGaze.isRecording ? "Stop Recording" : "Start Recording"
|
||||||
// Can always stop; can only start once a folder has been chosen.
|
// Can always stop; can only start once a folder has been chosen.
|
||||||
return shoeGaze.isRecording || shoeGaze.recordingFolder != nil
|
return shoeGaze.isRecording || shoeGaze.recordingFolder != nil
|
||||||
}
|
}
|
||||||
|
if menuItem == muteMenuItem {
|
||||||
|
// Mute may have changed from the UI, MIDI, or the tuner — resync title + checkmark.
|
||||||
|
menuItem.title = shoeGaze.rigMuted ? "Unmute Rig" : "Mute Rig"
|
||||||
|
menuItem.state = shoeGaze.rigMuted ? .on : .off
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if menuItem == bypassMenuItem {
|
||||||
|
// Bypass may have changed from the UI or MIDI — resync title + checkmark.
|
||||||
|
menuItem.title = shoeGaze.rigBypassed ? "Re-engage Rig" : "Bypass Rig"
|
||||||
|
menuItem.state = shoeGaze.rigBypassed ? .on : .off
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if setListMenuItems.contains(menuItem) {
|
||||||
|
// A slot is live only when the library actually holds a rig at that position.
|
||||||
|
return menuItem.tag < library.entries.count
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,21 @@
|
|||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>CFBundleDocumentTypes</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleTypeName</key>
|
||||||
|
<string>ShoeGaze Document</string>
|
||||||
|
<key>CFBundleTypeRole</key>
|
||||||
|
<string>Editor</string>
|
||||||
|
<key>LSHandlerRank</key>
|
||||||
|
<string>Owner</string>
|
||||||
|
<key>LSItemContentTypes</key>
|
||||||
|
<array>
|
||||||
|
<string>net.realizedsound.shoegaze</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>$(EXECUTABLE_NAME)</string>
|
<string>$(EXECUTABLE_NAME)</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
@@ -13,9 +28,9 @@
|
|||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>1.4.0</string>
|
<string>2.0.0</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1</string>
|
<string>7</string>
|
||||||
<key>LSApplicationCategoryType</key>
|
<key>LSApplicationCategoryType</key>
|
||||||
<string>public.app-category.music</string>
|
<string>public.app-category.music</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
@@ -40,32 +55,17 @@
|
|||||||
<string>Any</string>
|
<string>Any</string>
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
<key>CFBundleDocumentTypes</key>
|
|
||||||
<array>
|
|
||||||
<dict>
|
|
||||||
<key>CFBundleTypeName</key>
|
|
||||||
<string>ShoeGaze Document</string>
|
|
||||||
<key>CFBundleTypeRole</key>
|
|
||||||
<string>Editor</string>
|
|
||||||
<key>LSHandlerRank</key>
|
|
||||||
<string>Owner</string>
|
|
||||||
<key>LSItemContentTypes</key>
|
|
||||||
<array>
|
|
||||||
<string>net.realizedsound.shoegaze</string>
|
|
||||||
</array>
|
|
||||||
</dict>
|
|
||||||
</array>
|
|
||||||
<key>UTExportedTypeDeclarations</key>
|
<key>UTExportedTypeDeclarations</key>
|
||||||
<array>
|
<array>
|
||||||
<dict>
|
<dict>
|
||||||
<key>UTTypeIdentifier</key>
|
|
||||||
<string>net.realizedsound.shoegaze</string>
|
|
||||||
<key>UTTypeDescription</key>
|
|
||||||
<string>ShoeGaze Document</string>
|
|
||||||
<key>UTTypeConformsTo</key>
|
<key>UTTypeConformsTo</key>
|
||||||
<array>
|
<array>
|
||||||
<string>public.json</string>
|
<string>public.json</string>
|
||||||
</array>
|
</array>
|
||||||
|
<key>UTTypeDescription</key>
|
||||||
|
<string>ShoeGaze Document</string>
|
||||||
|
<key>UTTypeIdentifier</key>
|
||||||
|
<string>net.realizedsound.shoegaze</string>
|
||||||
<key>UTTypeTagSpecification</key>
|
<key>UTTypeTagSpecification</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>public.filename-extension</key>
|
<key>public.filename-extension</key>
|
||||||
|
|||||||
@@ -161,7 +161,7 @@
|
|||||||
CODE_SIGNING_REQUIRED = NO;
|
CODE_SIGNING_REQUIRED = NO;
|
||||||
CODE_SIGN_ENTITLEMENTS = ShoeGazeBuilderiOS/ShoeGazeBuilderiOS.entitlements;
|
CODE_SIGN_ENTITLEMENTS = ShoeGazeBuilderiOS/ShoeGazeBuilderiOS.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 5;
|
CURRENT_PROJECT_VERSION = 7;
|
||||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||||
INFOPLIST_FILE = ShoeGazeBuilderiOS/Info.plist;
|
INFOPLIST_FILE = ShoeGazeBuilderiOS/Info.plist;
|
||||||
@@ -172,7 +172,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.3;
|
MARKETING_VERSION = 2.0.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilderiOS;
|
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilderiOS;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SDKROOT = iphoneos;
|
SDKROOT = iphoneos;
|
||||||
@@ -191,7 +191,7 @@
|
|||||||
CODE_SIGNING_REQUIRED = NO;
|
CODE_SIGNING_REQUIRED = NO;
|
||||||
CODE_SIGN_ENTITLEMENTS = ShoeGazeBuilderiOS/ShoeGazeBuilderiOS.entitlements;
|
CODE_SIGN_ENTITLEMENTS = ShoeGazeBuilderiOS/ShoeGazeBuilderiOS.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
CURRENT_PROJECT_VERSION = 5;
|
CURRENT_PROJECT_VERSION = 7;
|
||||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
||||||
INFOPLIST_FILE = ShoeGazeBuilderiOS/Info.plist;
|
INFOPLIST_FILE = ShoeGazeBuilderiOS/Info.plist;
|
||||||
INFOPLIST_KEY_CFBundleDisplayName = ShoeGaze;
|
INFOPLIST_KEY_CFBundleDisplayName = ShoeGaze;
|
||||||
@@ -201,7 +201,7 @@
|
|||||||
"$(inherited)",
|
"$(inherited)",
|
||||||
"@executable_path/Frameworks",
|
"@executable_path/Frameworks",
|
||||||
);
|
);
|
||||||
MARKETING_VERSION = 1.3;
|
MARKETING_VERSION = 2.0.0;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilderiOS;
|
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeBuilderiOS;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SDKROOT = iphoneos;
|
SDKROOT = iphoneos;
|
||||||
|
|||||||
@@ -2,6 +2,21 @@
|
|||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
<dict>
|
<dict>
|
||||||
|
<key>CFBundleDocumentTypes</key>
|
||||||
|
<array>
|
||||||
|
<dict>
|
||||||
|
<key>CFBundleTypeName</key>
|
||||||
|
<string>ShoeGaze Document</string>
|
||||||
|
<key>CFBundleTypeRole</key>
|
||||||
|
<string>Editor</string>
|
||||||
|
<key>LSHandlerRank</key>
|
||||||
|
<string>Owner</string>
|
||||||
|
<key>LSItemContentTypes</key>
|
||||||
|
<array>
|
||||||
|
<string>net.realizedsound.shoegaze</string>
|
||||||
|
</array>
|
||||||
|
</dict>
|
||||||
|
</array>
|
||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>$(EXECUTABLE_NAME)</string>
|
<string>$(EXECUTABLE_NAME)</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
@@ -22,6 +37,18 @@
|
|||||||
<string>Copyright © 2026 realizedsound. All rights reserved.</string>
|
<string>Copyright © 2026 realizedsound. All rights reserved.</string>
|
||||||
<key>NSMicrophoneUsageDescription</key>
|
<key>NSMicrophoneUsageDescription</key>
|
||||||
<string>ShoeGaze Builder can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode.</string>
|
<string>ShoeGaze Builder can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode.</string>
|
||||||
|
<key>NSUbiquitousContainers</key>
|
||||||
|
<dict>
|
||||||
|
<key>iCloud.net.realizedsound.ShoeGazeData</key>
|
||||||
|
<dict>
|
||||||
|
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
|
||||||
|
<true/>
|
||||||
|
<key>NSUbiquitousContainerName</key>
|
||||||
|
<string>ShoeGaze</string>
|
||||||
|
<key>NSUbiquitousContainerSupportedFolderLevels</key>
|
||||||
|
<string>Any</string>
|
||||||
|
</dict>
|
||||||
|
</dict>
|
||||||
<key>UIApplicationSceneManifest</key>
|
<key>UIApplicationSceneManifest</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>UIApplicationSupportsMultipleScenes</key>
|
<key>UIApplicationSupportsMultipleScenes</key>
|
||||||
@@ -40,45 +67,19 @@
|
|||||||
<array>
|
<array>
|
||||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||||
</array>
|
<string>UIInterfaceOrientationPortrait</string>
|
||||||
<key>NSUbiquitousContainers</key>
|
|
||||||
<dict>
|
|
||||||
<key>iCloud.net.realizedsound.ShoeGazeData</key>
|
|
||||||
<dict>
|
|
||||||
<key>NSUbiquitousContainerIsDocumentScopePublic</key>
|
|
||||||
<true/>
|
|
||||||
<key>NSUbiquitousContainerName</key>
|
|
||||||
<string>ShoeGaze</string>
|
|
||||||
<key>NSUbiquitousContainerSupportedFolderLevels</key>
|
|
||||||
<string>Any</string>
|
|
||||||
</dict>
|
|
||||||
</dict>
|
|
||||||
<key>CFBundleDocumentTypes</key>
|
|
||||||
<array>
|
|
||||||
<dict>
|
|
||||||
<key>CFBundleTypeName</key>
|
|
||||||
<string>ShoeGaze Document</string>
|
|
||||||
<key>CFBundleTypeRole</key>
|
|
||||||
<string>Editor</string>
|
|
||||||
<key>LSHandlerRank</key>
|
|
||||||
<string>Owner</string>
|
|
||||||
<key>LSItemContentTypes</key>
|
|
||||||
<array>
|
|
||||||
<string>net.realizedsound.shoegaze</string>
|
|
||||||
</array>
|
|
||||||
</dict>
|
|
||||||
</array>
|
</array>
|
||||||
<key>UTExportedTypeDeclarations</key>
|
<key>UTExportedTypeDeclarations</key>
|
||||||
<array>
|
<array>
|
||||||
<dict>
|
<dict>
|
||||||
<key>UTTypeIdentifier</key>
|
|
||||||
<string>net.realizedsound.shoegaze</string>
|
|
||||||
<key>UTTypeDescription</key>
|
|
||||||
<string>ShoeGaze Document</string>
|
|
||||||
<key>UTTypeConformsTo</key>
|
<key>UTTypeConformsTo</key>
|
||||||
<array>
|
<array>
|
||||||
<string>public.json</string>
|
<string>public.json</string>
|
||||||
</array>
|
</array>
|
||||||
|
<key>UTTypeDescription</key>
|
||||||
|
<string>ShoeGaze Document</string>
|
||||||
|
<key>UTTypeIdentifier</key>
|
||||||
|
<string>net.realizedsound.shoegaze</string>
|
||||||
<key>UTTypeTagSpecification</key>
|
<key>UTTypeTagSpecification</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>public.filename-extension</key>
|
<key>public.filename-extension</key>
|
||||||
|
|||||||
@@ -13,8 +13,9 @@ import LyrebirdShoeGazeUI
|
|||||||
/// lifetime of the app. The audio engine is **not** started automatically — the user presses
|
/// lifetime of the app. The audio engine is **not** started automatically — the user presses
|
||||||
/// Start in ``ShoeGazeBuilderView``. The engine is stopped when the view disappears.
|
/// Start in ``ShoeGazeBuilderView``. The engine is stopped when the view disappears.
|
||||||
///
|
///
|
||||||
/// ``ShoeGazeBuilderView`` manages its own scroll regions (palette + builder), so it is hosted
|
/// ``ShoeGazeBuilderView`` draws its own header/title and manages its own scroll regions (palette
|
||||||
/// directly rather than wrapped in an outer `ScrollView`.
|
/// + board canvas), so it is hosted directly — no `NavigationStack`, title, or outer `ScrollView`.
|
||||||
|
/// A fill frame keeps it pinned to the full window so portrait isn't vertically centered.
|
||||||
@main
|
@main
|
||||||
struct ShoeGazeBuilderiOSApp: App {
|
struct ShoeGazeBuilderiOSApp: App {
|
||||||
|
|
||||||
@@ -23,20 +24,17 @@ struct ShoeGazeBuilderiOSApp: App {
|
|||||||
|
|
||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
NavigationStack {
|
ShoeGazeBuilderView(
|
||||||
ShoeGazeBuilderView(
|
shoeGaze: model.shoeGaze,
|
||||||
shoeGaze: model.shoeGaze,
|
library: model.library,
|
||||||
library: model.library,
|
hardwareSampleRate: { model.hardwareSampleRate },
|
||||||
hardwareSampleRate: { model.hardwareSampleRate },
|
onEnableLiveInput: { model.enableLiveInput() },
|
||||||
onEnableLiveInput: { model.enableLiveInput() },
|
midi: model.midi
|
||||||
midi: model.midi
|
)
|
||||||
)
|
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
|
||||||
.navigationTitle("ShoeGaze Builder")
|
.task { await model.startLibrary() }
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.onDisappear { model.stop() }
|
||||||
.task { await model.startLibrary() }
|
.onOpenURL { url in model.importDocument(at: url) }
|
||||||
}
|
|
||||||
.onDisappear { model.stop() }
|
|
||||||
.onOpenURL { url in model.importDocument(at: url) }
|
|
||||||
}
|
}
|
||||||
.onChange(of: scenePhase) { _, phase in
|
.onChange(of: scenePhase) { _, phase in
|
||||||
// Persist the rig whenever the app leaves the foreground.
|
// Persist the rig whenever the app leaves the foreground.
|
||||||
|
|||||||
@@ -1,397 +0,0 @@
|
|||||||
// !$*UTF8*$!
|
|
||||||
{
|
|
||||||
archiveVersion = 1;
|
|
||||||
classes = {
|
|
||||||
};
|
|
||||||
objectVersion = 60;
|
|
||||||
objects = {
|
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
|
||||||
C3B000000000000000000020 /* LyrebirdShoeGaze in Frameworks */ = {isa = PBXBuildFile; productRef = C3B00000000000000000001E /* LyrebirdShoeGaze */; };
|
|
||||||
C3B000000000000000000021 /* LyrebirdShoeGazeUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3B00000000000000000001F /* LyrebirdShoeGazeUI */; };
|
|
||||||
C3B000000000000000000022 /* Lyrebird in Frameworks */ = {isa = PBXBuildFile; productRef = C3B000000000000000000023 /* Lyrebird */; };
|
|
||||||
C3B000000000000000000024 /* LyrebirdUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3B000000000000000000025 /* LyrebirdUI */; };
|
|
||||||
C3B000000000000000000031 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C3B000000000000000000030 /* Assets.xcassets */; };
|
|
||||||
C3B0000000000000000000C /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3B000000000000000000007 /* main.swift */; };
|
|
||||||
C3B0000000000000000000D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3B000000000000000000008 /* AppDelegate.swift */; };
|
|
||||||
C3B0000000000000000000E /* DemoRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3B000000000000000000009 /* DemoRootView.swift */; };
|
|
||||||
C3B0000000000000000000F /* ShoeGazeDemoController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3B00000000000000000000A /* ShoeGazeDemoController.swift */; };
|
|
||||||
/* End PBXBuildFile section */
|
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
|
||||||
C3B000000000000000000004 /* ShoeGazeDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ShoeGazeDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
|
||||||
C3B000000000000000000006 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
|
||||||
C3B000000000000000000007 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
|
|
||||||
C3B000000000000000000008 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
|
||||||
C3B000000000000000000009 /* DemoRootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoRootView.swift; sourceTree = "<group>"; };
|
|
||||||
C3B00000000000000000000A /* ShoeGazeDemoController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoeGazeDemoController.swift; sourceTree = "<group>"; };
|
|
||||||
C3B000000000000000000030 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
|
||||||
/* End PBXFileReference section */
|
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
|
||||||
C3B000000000000000000012 /* Frameworks */ = {
|
|
||||||
isa = PBXFrameworksBuildPhase;
|
|
||||||
buildActionMask = 2147483647;
|
|
||||||
files = (
|
|
||||||
C3B000000000000000000020 /* LyrebirdShoeGaze in Frameworks */,
|
|
||||||
C3B000000000000000000021 /* LyrebirdShoeGazeUI in Frameworks */,
|
|
||||||
C3B000000000000000000022 /* Lyrebird in Frameworks */,
|
|
||||||
C3B000000000000000000024 /* LyrebirdUI in Frameworks */,
|
|
||||||
);
|
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
|
||||||
};
|
|
||||||
/* End PBXFrameworksBuildPhase section */
|
|
||||||
|
|
||||||
/* Begin PBXGroup section */
|
|
||||||
C3B000000000000000000002 = {
|
|
||||||
isa = PBXGroup;
|
|
||||||
children = (
|
|
||||||
C3B000000000000000000005 /* ShoeGazeDemo */,
|
|
||||||
C3B000000000000000000003 /* Products */,
|
|
||||||
);
|
|
||||||
sourceTree = "<group>";
|
|
||||||
};
|
|
||||||
C3B000000000000000000003 /* Products */ = {
|
|
||||||
isa = PBXGroup;
|
|
||||||
children = (
|
|
||||||
C3B000000000000000000004 /* ShoeGazeDemo.app */,
|
|
||||||
);
|
|
||||||
name = Products;
|
|
||||||
sourceTree = "<group>";
|
|
||||||
};
|
|
||||||
C3B000000000000000000005 /* ShoeGazeDemo */ = {
|
|
||||||
isa = PBXGroup;
|
|
||||||
children = (
|
|
||||||
C3B000000000000000000007 /* main.swift */,
|
|
||||||
C3B000000000000000000008 /* AppDelegate.swift */,
|
|
||||||
C3B000000000000000000009 /* DemoRootView.swift */,
|
|
||||||
C3B00000000000000000000A /* ShoeGazeDemoController.swift */,
|
|
||||||
C3B000000000000000000030 /* Assets.xcassets */,
|
|
||||||
C3B000000000000000000006 /* Info.plist */,
|
|
||||||
);
|
|
||||||
path = ShoeGazeDemo;
|
|
||||||
sourceTree = "<group>";
|
|
||||||
};
|
|
||||||
/* End PBXGroup section */
|
|
||||||
|
|
||||||
/* Begin PBXNativeTarget section */
|
|
||||||
C3B000000000000000000014 /* ShoeGazeDemo */ = {
|
|
||||||
isa = PBXNativeTarget;
|
|
||||||
buildConfigurationList = C3B000000000000000000015 /* Build configuration list for PBXNativeTarget "ShoeGazeDemo" */;
|
|
||||||
buildPhases = (
|
|
||||||
C3B000000000000000000011 /* Sources */,
|
|
||||||
C3B000000000000000000012 /* Frameworks */,
|
|
||||||
C3B000000000000000000013 /* Resources */,
|
|
||||||
);
|
|
||||||
buildRules = (
|
|
||||||
);
|
|
||||||
dependencies = (
|
|
||||||
);
|
|
||||||
name = ShoeGazeDemo;
|
|
||||||
packageProductDependencies = (
|
|
||||||
C3B00000000000000000001E /* LyrebirdShoeGaze */,
|
|
||||||
C3B00000000000000000001F /* LyrebirdShoeGazeUI */,
|
|
||||||
C3B000000000000000000023 /* Lyrebird */,
|
|
||||||
C3B000000000000000000025 /* LyrebirdUI */,
|
|
||||||
);
|
|
||||||
productName = ShoeGazeDemo;
|
|
||||||
productReference = C3B000000000000000000004 /* ShoeGazeDemo.app */;
|
|
||||||
productType = "com.apple.product-type.application";
|
|
||||||
};
|
|
||||||
/* End PBXNativeTarget section */
|
|
||||||
|
|
||||||
/* Begin PBXProject section */
|
|
||||||
C3B000000000000000000001 /* Project object */ = {
|
|
||||||
isa = PBXProject;
|
|
||||||
attributes = {
|
|
||||||
BuildIndependentTargetsInParallel = 1;
|
|
||||||
LastSwiftUpdateCheck = 1600;
|
|
||||||
LastUpgradeCheck = 2620;
|
|
||||||
TargetAttributes = {
|
|
||||||
C3B000000000000000000014 = {
|
|
||||||
CreatedOnToolsVersion = 16.0;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
buildConfigurationList = C3B000000000000000000018 /* Build configuration list for PBXProject "ShoeGazeDemo" */;
|
|
||||||
compatibilityVersion = "Xcode 14.0";
|
|
||||||
developmentRegion = en;
|
|
||||||
hasScannedForEncodings = 0;
|
|
||||||
knownRegions = (
|
|
||||||
en,
|
|
||||||
Base,
|
|
||||||
);
|
|
||||||
mainGroup = C3B000000000000000000002;
|
|
||||||
packageReferences = (
|
|
||||||
C3B00000000000000000001B /* XCLocalSwiftPackageReference ".." */,
|
|
||||||
C3B00000000000000000001C /* XCRemoteSwiftPackageReference "Lyrebird" */,
|
|
||||||
);
|
|
||||||
productRefGroup = C3B000000000000000000003 /* Products */;
|
|
||||||
projectDirPath = "";
|
|
||||||
projectRoot = "";
|
|
||||||
targets = (
|
|
||||||
C3B000000000000000000014 /* ShoeGazeDemo */,
|
|
||||||
);
|
|
||||||
};
|
|
||||||
/* End PBXProject section */
|
|
||||||
|
|
||||||
/* Begin PBXResourcesBuildPhase section */
|
|
||||||
C3B000000000000000000013 /* Resources */ = {
|
|
||||||
isa = PBXResourcesBuildPhase;
|
|
||||||
buildActionMask = 2147483647;
|
|
||||||
files = (
|
|
||||||
C3B000000000000000000031 /* Assets.xcassets in Resources */,
|
|
||||||
);
|
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
|
||||||
};
|
|
||||||
/* End PBXResourcesBuildPhase section */
|
|
||||||
|
|
||||||
/* Begin PBXSourcesBuildPhase section */
|
|
||||||
C3B000000000000000000011 /* Sources */ = {
|
|
||||||
isa = PBXSourcesBuildPhase;
|
|
||||||
buildActionMask = 2147483647;
|
|
||||||
files = (
|
|
||||||
C3B0000000000000000000C /* main.swift in Sources */,
|
|
||||||
C3B0000000000000000000D /* AppDelegate.swift in Sources */,
|
|
||||||
C3B0000000000000000000E /* DemoRootView.swift in Sources */,
|
|
||||||
C3B0000000000000000000F /* ShoeGazeDemoController.swift in Sources */,
|
|
||||||
);
|
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
|
||||||
};
|
|
||||||
/* End PBXSourcesBuildPhase section */
|
|
||||||
|
|
||||||
/* Begin XCBuildConfiguration section */
|
|
||||||
C3B000000000000000000016 /* Debug */ = {
|
|
||||||
isa = XCBuildConfiguration;
|
|
||||||
buildSettings = {
|
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
|
||||||
CODE_SIGNING_REQUIRED = NO;
|
|
||||||
CODE_SIGN_ENTITLEMENTS = ShoeGazeDemo/ShoeGazeDemo.entitlements;
|
|
||||||
CODE_SIGN_STYLE = Automatic;
|
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
|
||||||
DEAD_CODE_STRIPPING = YES;
|
|
||||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
|
||||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
|
||||||
INFOPLIST_FILE = ShoeGazeDemo/Info.plist;
|
|
||||||
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.music";
|
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
|
||||||
"$(inherited)",
|
|
||||||
"@executable_path/../Frameworks",
|
|
||||||
);
|
|
||||||
MACOSX_DEPLOYMENT_TARGET = 15.0;
|
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeDemo;
|
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
|
||||||
SWIFT_VERSION = 5.0;
|
|
||||||
};
|
|
||||||
name = Debug;
|
|
||||||
};
|
|
||||||
C3B000000000000000000017 /* Release */ = {
|
|
||||||
isa = XCBuildConfiguration;
|
|
||||||
buildSettings = {
|
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
|
||||||
CODE_SIGNING_REQUIRED = NO;
|
|
||||||
CODE_SIGN_ENTITLEMENTS = ShoeGazeDemo/ShoeGazeDemo.entitlements;
|
|
||||||
CODE_SIGN_STYLE = Automatic;
|
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
|
||||||
DEAD_CODE_STRIPPING = YES;
|
|
||||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
|
||||||
ENABLE_HARDENED_RUNTIME = YES;
|
|
||||||
INFOPLIST_FILE = ShoeGazeDemo/Info.plist;
|
|
||||||
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.music";
|
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
|
||||||
"$(inherited)",
|
|
||||||
"@executable_path/../Frameworks",
|
|
||||||
);
|
|
||||||
MACOSX_DEPLOYMENT_TARGET = 15.0;
|
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeDemo;
|
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
|
||||||
SWIFT_VERSION = 5.0;
|
|
||||||
};
|
|
||||||
name = Release;
|
|
||||||
};
|
|
||||||
C3B000000000000000000019 /* Debug */ = {
|
|
||||||
isa = XCBuildConfiguration;
|
|
||||||
buildSettings = {
|
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
|
||||||
CLANG_ANALYZER_NONNULL = YES;
|
|
||||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
|
||||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
|
||||||
CLANG_ENABLE_MODULES = YES;
|
|
||||||
CLANG_ENABLE_OBJC_ARC = YES;
|
|
||||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
|
||||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
|
||||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_COMMA = YES;
|
|
||||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
|
||||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
|
||||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
|
||||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
|
||||||
CLANG_WARN_EMPTY_BODY = YES;
|
|
||||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
|
||||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
|
||||||
CLANG_WARN_INT_CONVERSION = YES;
|
|
||||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
|
||||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
|
||||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
|
||||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
|
||||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
|
||||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
|
||||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
|
||||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
|
||||||
COPY_PHASE_STRIP = NO;
|
|
||||||
DEAD_CODE_STRIPPING = YES;
|
|
||||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
|
||||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
|
||||||
ENABLE_TESTABILITY = YES;
|
|
||||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
|
||||||
GCC_C_LANGUAGE_STANDARD = gnu17;
|
|
||||||
GCC_DYNAMIC_NO_PIC = NO;
|
|
||||||
GCC_NO_COMMON_BLOCKS = YES;
|
|
||||||
GCC_OPTIMIZATION_LEVEL = 0;
|
|
||||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
|
||||||
"DEBUG=1",
|
|
||||||
"$(inherited)",
|
|
||||||
);
|
|
||||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
|
||||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
|
||||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
|
||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
|
||||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
|
||||||
MTL_FAST_MATH = YES;
|
|
||||||
ONLY_ACTIVE_ARCH = YES;
|
|
||||||
SDKROOT = macosx;
|
|
||||||
STRING_CATALOG_GENERATE_SYMBOLS = YES;
|
|
||||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
|
||||||
};
|
|
||||||
name = Debug;
|
|
||||||
};
|
|
||||||
C3B00000000000000000001A /* Release */ = {
|
|
||||||
isa = XCBuildConfiguration;
|
|
||||||
buildSettings = {
|
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
|
||||||
CLANG_ANALYZER_NONNULL = YES;
|
|
||||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
|
||||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
|
||||||
CLANG_ENABLE_MODULES = YES;
|
|
||||||
CLANG_ENABLE_OBJC_ARC = YES;
|
|
||||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
|
||||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
|
||||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_COMMA = YES;
|
|
||||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
|
||||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
|
||||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
|
||||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
|
||||||
CLANG_WARN_EMPTY_BODY = YES;
|
|
||||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
|
||||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
|
||||||
CLANG_WARN_INT_CONVERSION = YES;
|
|
||||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
|
||||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
|
||||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
|
||||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
|
||||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
|
||||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
|
||||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
|
||||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
|
||||||
COPY_PHASE_STRIP = NO;
|
|
||||||
DEAD_CODE_STRIPPING = YES;
|
|
||||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
|
||||||
ENABLE_NS_ASSERTIONS = NO;
|
|
||||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
|
||||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
|
||||||
GCC_C_LANGUAGE_STANDARD = gnu17;
|
|
||||||
GCC_NO_COMMON_BLOCKS = YES;
|
|
||||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
|
||||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
|
||||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
|
||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
|
||||||
MTL_ENABLE_DEBUG_INFO = NO;
|
|
||||||
MTL_FAST_MATH = YES;
|
|
||||||
SDKROOT = macosx;
|
|
||||||
STRING_CATALOG_GENERATE_SYMBOLS = YES;
|
|
||||||
SWIFT_COMPILATION_MODE = wholemodule;
|
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-O";
|
|
||||||
};
|
|
||||||
name = Release;
|
|
||||||
};
|
|
||||||
/* End XCBuildConfiguration section */
|
|
||||||
|
|
||||||
/* Begin XCConfigurationList section */
|
|
||||||
C3B000000000000000000015 /* Build configuration list for PBXNativeTarget "ShoeGazeDemo" */ = {
|
|
||||||
isa = XCConfigurationList;
|
|
||||||
buildConfigurations = (
|
|
||||||
C3B000000000000000000016 /* Debug */,
|
|
||||||
C3B000000000000000000017 /* Release */,
|
|
||||||
);
|
|
||||||
defaultConfigurationIsVisible = 0;
|
|
||||||
defaultConfigurationName = Release;
|
|
||||||
};
|
|
||||||
C3B000000000000000000018 /* Build configuration list for PBXProject "ShoeGazeDemo" */ = {
|
|
||||||
isa = XCConfigurationList;
|
|
||||||
buildConfigurations = (
|
|
||||||
C3B000000000000000000019 /* Debug */,
|
|
||||||
C3B00000000000000000001A /* Release */,
|
|
||||||
);
|
|
||||||
defaultConfigurationIsVisible = 0;
|
|
||||||
defaultConfigurationName = Release;
|
|
||||||
};
|
|
||||||
/* End XCConfigurationList section */
|
|
||||||
|
|
||||||
/* Begin XCLocalSwiftPackageReference section */
|
|
||||||
C3B00000000000000000001B /* XCLocalSwiftPackageReference ".." */ = {
|
|
||||||
isa = XCLocalSwiftPackageReference;
|
|
||||||
relativePath = ..;
|
|
||||||
};
|
|
||||||
/* End XCLocalSwiftPackageReference section */
|
|
||||||
|
|
||||||
/* Begin XCRemoteSwiftPackageReference section */
|
|
||||||
C3B00000000000000000001C /* XCRemoteSwiftPackageReference "Lyrebird" */ = {
|
|
||||||
isa = XCRemoteSwiftPackageReference;
|
|
||||||
repositoryURL = "https://realizedsound.mooo.com/josh/Lyrebird";
|
|
||||||
requirement = {
|
|
||||||
kind = upToNextMajorVersion;
|
|
||||||
minimumVersion = 1.2.0;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
/* End XCRemoteSwiftPackageReference section */
|
|
||||||
|
|
||||||
/* Begin XCSwiftPackageProductDependency section */
|
|
||||||
C3B00000000000000000001E /* LyrebirdShoeGaze */ = {
|
|
||||||
isa = XCSwiftPackageProductDependency;
|
|
||||||
package = C3B00000000000000000001B /* XCLocalSwiftPackageReference ".." */;
|
|
||||||
productName = LyrebirdShoeGaze;
|
|
||||||
};
|
|
||||||
C3B00000000000000000001F /* LyrebirdShoeGazeUI */ = {
|
|
||||||
isa = XCSwiftPackageProductDependency;
|
|
||||||
package = C3B00000000000000000001B /* XCLocalSwiftPackageReference ".." */;
|
|
||||||
productName = LyrebirdShoeGazeUI;
|
|
||||||
};
|
|
||||||
C3B000000000000000000023 /* Lyrebird */ = {
|
|
||||||
isa = XCSwiftPackageProductDependency;
|
|
||||||
package = C3B00000000000000000001C /* XCRemoteSwiftPackageReference "Lyrebird" */;
|
|
||||||
productName = Lyrebird;
|
|
||||||
};
|
|
||||||
C3B000000000000000000025 /* LyrebirdUI */ = {
|
|
||||||
isa = XCSwiftPackageProductDependency;
|
|
||||||
package = C3B00000000000000000001C /* XCRemoteSwiftPackageReference "Lyrebird" */;
|
|
||||||
productName = LyrebirdUI;
|
|
||||||
};
|
|
||||||
/* End XCSwiftPackageProductDependency section */
|
|
||||||
};
|
|
||||||
rootObject = C3B000000000000000000001 /* Project object */;
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
{
|
|
||||||
"originHash" : "cfdd71f4b32d744c862bbe26a8265d75aa9e906275b0fb1b63575b7d68be1b6a",
|
|
||||||
"pins" : [
|
|
||||||
{
|
|
||||||
"identity" : "linenoise-swift",
|
|
||||||
"kind" : "remoteSourceControl",
|
|
||||||
"location" : "https://github.com/andybest/linenoise-swift",
|
|
||||||
"state" : {
|
|
||||||
"revision" : "afc897c02b030af7333105c4fedcd843a8339238",
|
|
||||||
"version" : "0.0.3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"identity" : "lyrebird",
|
|
||||||
"kind" : "remoteSourceControl",
|
|
||||||
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
|
|
||||||
"state" : {
|
|
||||||
"revision" : "032b7c39d351eba4029e8399e1ab1ee201e8bb5c",
|
|
||||||
"version" : "1.2.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"identity" : "nimble",
|
|
||||||
"kind" : "remoteSourceControl",
|
|
||||||
"location" : "https://github.com/Quick/Nimble.git",
|
|
||||||
"state" : {
|
|
||||||
"revision" : "e9d769113660769a4d9dd3afb855562c0b7ae7b0",
|
|
||||||
"version" : "7.3.4"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version" : 3
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<Scheme
|
|
||||||
LastUpgradeVersion = "2620"
|
|
||||||
version = "1.7">
|
|
||||||
<BuildAction
|
|
||||||
parallelizeBuildables = "YES"
|
|
||||||
buildImplicitDependencies = "YES"
|
|
||||||
buildArchitectures = "Automatic">
|
|
||||||
<BuildActionEntries>
|
|
||||||
<BuildActionEntry
|
|
||||||
buildForTesting = "YES"
|
|
||||||
buildForRunning = "YES"
|
|
||||||
buildForProfiling = "YES"
|
|
||||||
buildForArchiving = "YES"
|
|
||||||
buildForAnalyzing = "YES">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "C3B000000000000000000014"
|
|
||||||
BuildableName = "ShoeGazeDemo.app"
|
|
||||||
BlueprintName = "ShoeGazeDemo"
|
|
||||||
ReferencedContainer = "container:ShoeGazeDemo.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildActionEntry>
|
|
||||||
</BuildActionEntries>
|
|
||||||
</BuildAction>
|
|
||||||
<TestAction
|
|
||||||
buildConfiguration = "Debug"
|
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
|
||||||
shouldAutocreateTestPlan = "YES">
|
|
||||||
</TestAction>
|
|
||||||
<LaunchAction
|
|
||||||
buildConfiguration = "Release"
|
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
||||||
launchStyle = "0"
|
|
||||||
useCustomWorkingDirectory = "NO"
|
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
|
||||||
debugDocumentVersioning = "YES"
|
|
||||||
debugServiceExtension = "internal"
|
|
||||||
allowLocationSimulation = "YES">
|
|
||||||
<BuildableProductRunnable
|
|
||||||
runnableDebuggingMode = "0">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "C3B000000000000000000014"
|
|
||||||
BuildableName = "ShoeGazeDemo.app"
|
|
||||||
BlueprintName = "ShoeGazeDemo"
|
|
||||||
ReferencedContainer = "container:ShoeGazeDemo.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildableProductRunnable>
|
|
||||||
</LaunchAction>
|
|
||||||
<ProfileAction
|
|
||||||
buildConfiguration = "Release"
|
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
|
||||||
savedToolIdentifier = ""
|
|
||||||
useCustomWorkingDirectory = "NO"
|
|
||||||
debugDocumentVersioning = "YES">
|
|
||||||
<BuildableProductRunnable
|
|
||||||
runnableDebuggingMode = "0">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "C3B000000000000000000014"
|
|
||||||
BuildableName = "ShoeGazeDemo.app"
|
|
||||||
BlueprintName = "ShoeGazeDemo"
|
|
||||||
ReferencedContainer = "container:ShoeGazeDemo.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildableProductRunnable>
|
|
||||||
</ProfileAction>
|
|
||||||
<AnalyzeAction
|
|
||||||
buildConfiguration = "Debug">
|
|
||||||
</AnalyzeAction>
|
|
||||||
<ArchiveAction
|
|
||||||
buildConfiguration = "Release"
|
|
||||||
revealArchiveInOrganizer = "YES">
|
|
||||||
</ArchiveAction>
|
|
||||||
</Scheme>
|
|
||||||
@@ -1,153 +0,0 @@
|
|||||||
// AppDelegate.swift
|
|
||||||
// Lyrebird
|
|
||||||
//
|
|
||||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
#if os(macOS)
|
|
||||||
import AppKit
|
|
||||||
import LyrebirdSynth
|
|
||||||
import LyrebirdUI
|
|
||||||
import LyrebirdShoeGaze
|
|
||||||
import LyrebirdShoeGazeUI
|
|
||||||
|
|
||||||
/// Application delegate for the ShoeGaze demo.
|
|
||||||
///
|
|
||||||
/// Creates a `SynthesisEngine`, a `ShoeGazeDemoController` (which builds the default
|
|
||||||
/// `.boards` showcase automatically), and opens a `LyrebirdWindow` hosting `DemoRootView`.
|
|
||||||
///
|
|
||||||
/// The engine is **not** started automatically. The user clicks Start in `DemoRootView`'s
|
|
||||||
/// toolbar (or presses Stop to halt audio). On application termination, `stop()` is called
|
|
||||||
/// to release Core Audio resources cleanly.
|
|
||||||
@MainActor
|
|
||||||
final class AppDelegate: NSObject, NSApplicationDelegate {
|
|
||||||
|
|
||||||
// MARK: - Engine configuration constants
|
|
||||||
|
|
||||||
private static let blockSize: Int = 512
|
|
||||||
private static let sampleRate: Double = 48_000.0
|
|
||||||
private static let outputChannels: Int = 2
|
|
||||||
// Built-in mics are mono; default to one input channel so live input works out of the box
|
|
||||||
// (CoreAudio can't satisfy more input channels than the device provides). Raise in the UI.
|
|
||||||
private static let inputChannels: Int = 1
|
|
||||||
private static let numAudioBuses: Int = 256
|
|
||||||
|
|
||||||
// MARK: - Window geometry constants
|
|
||||||
|
|
||||||
private static let windowWidth: CGFloat = 1_100
|
|
||||||
private static let windowHeight: CGFloat = 640
|
|
||||||
|
|
||||||
// MARK: - Owned objects
|
|
||||||
|
|
||||||
private let coreDriver: CoreAudioDriver
|
|
||||||
private let controller: ShoeGazeDemoController
|
|
||||||
private let window: LyrebirdWindow
|
|
||||||
|
|
||||||
/// The Mute menu item, retained so `validateMenuItem(_:)` can update its checkmark.
|
|
||||||
private var muteMenuItem: NSMenuItem?
|
|
||||||
|
|
||||||
// MARK: - Init
|
|
||||||
|
|
||||||
override init() {
|
|
||||||
let coreDriver: CoreAudioDriver = CoreAudioDriver()
|
|
||||||
let engine: SynthesisEngine = SynthesisEngine(
|
|
||||||
blockSize: AppDelegate.blockSize,
|
|
||||||
sampleRate: AppDelegate.sampleRate,
|
|
||||||
numOutputChannels: AppDelegate.outputChannels,
|
|
||||||
numInputChannels: AppDelegate.inputChannels,
|
|
||||||
numAudioBuses: AppDelegate.numAudioBuses,
|
|
||||||
driver: coreDriver
|
|
||||||
)
|
|
||||||
|
|
||||||
self.coreDriver = coreDriver
|
|
||||||
self.controller = ShoeGazeDemoController(engine: engine)
|
|
||||||
self.window = LyrebirdWindow(
|
|
||||||
title: "ShoeGaze — Lyrebird Guitar Pedalboard",
|
|
||||||
width: AppDelegate.windowWidth,
|
|
||||||
height: AppDelegate.windowHeight
|
|
||||||
)
|
|
||||||
super.init()
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - NSApplicationDelegate
|
|
||||||
|
|
||||||
func applicationDidFinishLaunching(_ notification: Notification) {
|
|
||||||
installMainMenu()
|
|
||||||
let demoController: ShoeGazeDemoController = controller
|
|
||||||
let driver: CoreAudioDriver = coreDriver
|
|
||||||
window.open {
|
|
||||||
DemoRootView(controller: demoController, hardwareSampleRate: { driver.deviceSampleRate })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
|
||||||
true
|
|
||||||
}
|
|
||||||
|
|
||||||
func applicationWillTerminate(_ notification: Notification) {
|
|
||||||
controller.stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Main menu
|
|
||||||
|
|
||||||
/// Builds the app's menu bar: an application menu (About / Hide / Quit ⌘Q) and an
|
|
||||||
/// Audio menu (Mute ⌘M). Standard items route through the responder chain to
|
|
||||||
/// `NSApplication`; Mute targets this delegate.
|
|
||||||
private func installMainMenu() {
|
|
||||||
let appName: String = ProcessInfo.processInfo.processName
|
|
||||||
let mainMenu: NSMenu = NSMenu()
|
|
||||||
|
|
||||||
// Application menu.
|
|
||||||
let appMenuItem: NSMenuItem = NSMenuItem()
|
|
||||||
mainMenu.addItem(appMenuItem)
|
|
||||||
let appMenu: NSMenu = NSMenu()
|
|
||||||
appMenuItem.submenu = appMenu
|
|
||||||
appMenu.addItem(
|
|
||||||
withTitle: "About \(appName)",
|
|
||||||
action: #selector(NSApplication.orderFrontStandardAboutPanel(_:)),
|
|
||||||
keyEquivalent: ""
|
|
||||||
)
|
|
||||||
appMenu.addItem(NSMenuItem.separator())
|
|
||||||
appMenu.addItem(
|
|
||||||
withTitle: "Hide \(appName)",
|
|
||||||
action: #selector(NSApplication.hide(_:)),
|
|
||||||
keyEquivalent: "h"
|
|
||||||
)
|
|
||||||
appMenu.addItem(NSMenuItem.separator())
|
|
||||||
appMenu.addItem(
|
|
||||||
withTitle: "Quit \(appName)",
|
|
||||||
action: #selector(NSApplication.terminate(_:)),
|
|
||||||
keyEquivalent: "q"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Audio menu.
|
|
||||||
let audioMenuItem: NSMenuItem = NSMenuItem()
|
|
||||||
mainMenu.addItem(audioMenuItem)
|
|
||||||
let audioMenu: NSMenu = NSMenu(title: "Audio")
|
|
||||||
audioMenuItem.submenu = audioMenu
|
|
||||||
let mute: NSMenuItem = NSMenuItem(
|
|
||||||
title: "Mute",
|
|
||||||
action: #selector(toggleMute(_:)),
|
|
||||||
keyEquivalent: "m"
|
|
||||||
)
|
|
||||||
mute.target = self
|
|
||||||
audioMenu.addItem(mute)
|
|
||||||
muteMenuItem = mute
|
|
||||||
|
|
||||||
NSApplication.shared.mainMenu = mainMenu
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Toggles audio output (mute). Bound to the Audio ▸ Mute menu item (⌘M).
|
|
||||||
@objc private func toggleMute(_ sender: Any?) {
|
|
||||||
controller.toggleMute()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Shows a checkmark on the Mute item while audio is silenced (engine not running).
|
|
||||||
func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
|
|
||||||
if menuItem == muteMenuItem {
|
|
||||||
menuItem.state = controller.isRunning ? .off : .on
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"images" : [
|
|
||||||
{"size":"16x16","idiom":"mac","filename":"icon_16x16.png","scale":"1x"},
|
|
||||||
{"size":"16x16","idiom":"mac","filename":"icon_16x16@2x.png","scale":"2x"},
|
|
||||||
{"size":"32x32","idiom":"mac","filename":"icon_32x32.png","scale":"1x"},
|
|
||||||
{"size":"32x32","idiom":"mac","filename":"icon_32x32@2x.png","scale":"2x"},
|
|
||||||
{"size":"128x128","idiom":"mac","filename":"icon_128x128.png","scale":"1x"},
|
|
||||||
{"size":"128x128","idiom":"mac","filename":"icon_128x128@2x.png","scale":"2x"},
|
|
||||||
{"size":"256x256","idiom":"mac","filename":"icon_256x256.png","scale":"1x"},
|
|
||||||
{"size":"256x256","idiom":"mac","filename":"icon_256x256@2x.png","scale":"2x"},
|
|
||||||
{"size":"512x512","idiom":"mac","filename":"icon_512x512.png","scale":"1x"},
|
|
||||||
{"size":"512x512","idiom":"mac","filename":"icon_512x512@2x.png","scale":"2x"}
|
|
||||||
],
|
|
||||||
"info" : {"author":"xcode","version":1}
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 782 B |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 345 KiB |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 345 KiB |
|
Before Width: | Height: | Size: 1.2 MiB |
@@ -1 +0,0 @@
|
|||||||
{ "info" : {"author":"xcode","version":1} }
|
|
||||||
@@ -1,303 +0,0 @@
|
|||||||
// DemoRootView.swift
|
|
||||||
// Lyrebird
|
|
||||||
//
|
|
||||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
#if os(macOS)
|
|
||||||
import SwiftUI
|
|
||||||
import LyrebirdSynth
|
|
||||||
import LyrebirdUI
|
|
||||||
import LyrebirdShoeGaze
|
|
||||||
import LyrebirdShoeGazeUI
|
|
||||||
|
|
||||||
/// Root view for the ShoeGaze demo window.
|
|
||||||
///
|
|
||||||
/// Presents a top toolbar with a mode picker, an input-source toggle, and a Start/Stop
|
|
||||||
/// transport button, followed by a content area that switches between four showcase
|
|
||||||
/// modes as the user selects them.
|
|
||||||
///
|
|
||||||
/// Because `ShoeGazeDemoController` is `@Observable`, SwiftUI re-renders this view and
|
|
||||||
/// all its children whenever `controller.mode`, `controller.shoeGaze.boards`,
|
|
||||||
/// `controller.router`, `controller.parallelSection`, or `controller.isRunning` change —
|
|
||||||
/// including after a ``ShoeGazeDemoController/rebuild()`` that replaces `shoeGaze`.
|
|
||||||
///
|
|
||||||
/// ## Mode showcases
|
|
||||||
///
|
|
||||||
/// - `.boards` → `ShoeGazeView` — two boards, eight pedals, master gain per board.
|
|
||||||
/// - `.editor` → `BoardEditorView` — board + FlowLayout pedal area + version snapshots.
|
|
||||||
/// - `.parallel` → `ParallelSectionView` — splitter, two branch rows, merger (via board).
|
|
||||||
/// - `.router` → `ChainRouterView` — dual-board chain router with splitter + master.
|
|
||||||
/// - `.stereo` → `StereoSplitSectionView` — stereo split with the four route modes.
|
|
||||||
struct DemoRootView: View {
|
|
||||||
|
|
||||||
// MARK: - Layout constants
|
|
||||||
|
|
||||||
private static let toolbarSpacing: CGFloat = 10
|
|
||||||
private static let toolbarPadding: CGFloat = 12
|
|
||||||
private static let contentPadding: CGFloat = 16
|
|
||||||
private static let windowMinWidth: CGFloat = 1_100
|
|
||||||
private static let windowMinHeight: CGFloat = 640
|
|
||||||
/// Dark stage-floor background (warm almost-black).
|
|
||||||
private static let backgroundRed: Double = 0.08
|
|
||||||
private static let backgroundGreen: Double = 0.07
|
|
||||||
private static let backgroundBlue: Double = 0.06
|
|
||||||
private static let dividerOpacity: Double = 0.15
|
|
||||||
|
|
||||||
// MARK: - Properties
|
|
||||||
|
|
||||||
private let controller: ShoeGazeDemoController
|
|
||||||
private let hardwareSampleRate: () -> Double?
|
|
||||||
|
|
||||||
/// Bumped on each transport press so the buttons re-read `controller.isRunning`
|
|
||||||
/// (which derives from the non-observable engine).
|
|
||||||
@State private var transportTick: Bool = false
|
|
||||||
|
|
||||||
// MARK: - Init
|
|
||||||
|
|
||||||
/// Creates the root demo view bound to the given controller.
|
|
||||||
///
|
|
||||||
/// - Parameters:
|
|
||||||
/// - controller: The `ShoeGazeDemoController` that owns the engine, active `ShoeGaze`
|
|
||||||
/// session, and current mode. All toolbar actions dispatch through this.
|
|
||||||
/// - hardwareSampleRate: Returns the actual hardware sample rate (or `nil`), for the engine-
|
|
||||||
/// config mismatch warning. Defaults to `nil`.
|
|
||||||
init(
|
|
||||||
controller: ShoeGazeDemoController,
|
|
||||||
hardwareSampleRate: @escaping () -> Double? = { nil }
|
|
||||||
) {
|
|
||||||
self.controller = controller
|
|
||||||
self.hardwareSampleRate = hardwareSampleRate
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Body
|
|
||||||
|
|
||||||
var body: some View {
|
|
||||||
VStack(spacing: 0) {
|
|
||||||
toolbar
|
|
||||||
Divider()
|
|
||||||
.overlay(Color.white.opacity(DemoRootView.dividerOpacity))
|
|
||||||
contentArea
|
|
||||||
.padding(DemoRootView.contentPadding)
|
|
||||||
Divider()
|
|
||||||
.overlay(Color.white.opacity(DemoRootView.dividerOpacity))
|
|
||||||
ShoeGazeScopeView(shoeGaze: controller.shoeGaze)
|
|
||||||
.padding(DemoRootView.contentPadding)
|
|
||||||
}
|
|
||||||
.frame(
|
|
||||||
minWidth: DemoRootView.windowMinWidth,
|
|
||||||
minHeight: DemoRootView.windowMinHeight
|
|
||||||
)
|
|
||||||
.background(
|
|
||||||
Color(
|
|
||||||
red: DemoRootView.backgroundRed,
|
|
||||||
green: DemoRootView.backgroundGreen,
|
|
||||||
blue: DemoRootView.backgroundBlue
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.alert(
|
|
||||||
"Microphone Access Needed",
|
|
||||||
isPresented: Binding(
|
|
||||||
get: { controller.microphoneAccessDenied },
|
|
||||||
set: { controller.microphoneAccessDenied = $0 }
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
Button("OK", role: .cancel) { }
|
|
||||||
} message: {
|
|
||||||
Text("Live input needs microphone access. Enable it in System Settings › Privacy & "
|
|
||||||
+ "Security › Microphone, then select the input again.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Toolbar
|
|
||||||
|
|
||||||
/// Top toolbar: mode picker, input-source picker, transport, and CPU meter.
|
|
||||||
private var toolbar: some View {
|
|
||||||
HStack(spacing: DemoRootView.toolbarSpacing) {
|
|
||||||
modePicker
|
|
||||||
Spacer()
|
|
||||||
inputSourcePicker
|
|
||||||
// In Boards mode the pedalboard view (`ShoeGazeView`) supplies its own
|
|
||||||
// Start/Stop, so the board starts only when its own button is pressed. The
|
|
||||||
// other modes have no in-content transport, so show it here for them.
|
|
||||||
if controller.mode != .boards {
|
|
||||||
transportButtons
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.padding(DemoRootView.toolbarPadding)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Segmented picker for `DemoMode`.
|
|
||||||
///
|
|
||||||
/// The selection binding's setter delegates to `controller.select(_:)` rather than
|
|
||||||
/// writing a `@State` directly, so the controller handles the mode switch and rebuild.
|
|
||||||
private var modePicker: some View {
|
|
||||||
let modeBinding: Binding<DemoMode> = Binding(
|
|
||||||
get: { controller.mode },
|
|
||||||
set: { controller.select($0) }
|
|
||||||
)
|
|
||||||
return Picker("Mode", selection: modeBinding) {
|
|
||||||
ForEach(DemoMode.allCases) { demoMode in
|
|
||||||
Text(demoMode.title).tag(demoMode)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.pickerStyle(.segmented)
|
|
||||||
.frame(maxWidth: 380)
|
|
||||||
.foregroundStyle(Color.white)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A `Binding<Int>` mapping the input Picker tag to `InputSource`.
|
|
||||||
///
|
|
||||||
/// Tag `-1` = `.testLoop`; tags `0 ..< numInputChannels` = `.liveInput(channel:)`.
|
|
||||||
/// Setting the binding calls `controller.setInputSource(_:)`.
|
|
||||||
private var inputSourceBinding: Binding<Int> {
|
|
||||||
Binding(
|
|
||||||
get: {
|
|
||||||
switch controller.inputSource {
|
|
||||||
case .testLoop:
|
|
||||||
return -1
|
|
||||||
case .liveInput(let channel):
|
|
||||||
return channel
|
|
||||||
}
|
|
||||||
},
|
|
||||||
set: { newValue in
|
|
||||||
if newValue == -1 {
|
|
||||||
controller.setInputSource(.testLoop)
|
|
||||||
} else {
|
|
||||||
controller.setInputSource(.liveInput(channel: newValue))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Picker listing "Test Loop" and one option per available hardware input channel.
|
|
||||||
///
|
|
||||||
/// When `engine.numInputChannels == 0` only "Test Loop" is shown; the live options
|
|
||||||
/// are omitted so the picker never offers channels that do not exist.
|
|
||||||
private var inputSourcePicker: some View {
|
|
||||||
HStack(spacing: DemoRootView.toolbarSpacing) {
|
|
||||||
Text("Input:")
|
|
||||||
.font(.subheadline)
|
|
||||||
.foregroundStyle(Color.white.opacity(0.65))
|
|
||||||
Picker("Input", selection: inputSourceBinding) {
|
|
||||||
Text("Test Loop").tag(-1)
|
|
||||||
ForEach(Array(0..<max(0, controller.engine.numInputChannels)), id: \.self) { channel in
|
|
||||||
Text("In \(channel)").tag(channel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.pickerStyle(.menu)
|
|
||||||
.foregroundStyle(Color.white)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Engine configuration + transport (sample rate, ins/outs, Start/Stop, mismatch alert).
|
|
||||||
private var transportButtons: some View {
|
|
||||||
EngineConfigView(
|
|
||||||
shoeGaze: controller.shoeGaze,
|
|
||||||
hardwareSampleRate: hardwareSampleRate,
|
|
||||||
applyConfig: { rate, inputs, outputs in
|
|
||||||
try controller.reconfigure(
|
|
||||||
sampleRate: rate,
|
|
||||||
inputChannels: inputs,
|
|
||||||
outputChannels: outputs
|
|
||||||
)
|
|
||||||
},
|
|
||||||
onConfigApplied: { transportTick.toggle() }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Content area
|
|
||||||
|
|
||||||
/// The main content area switches view based on the active mode.
|
|
||||||
@ViewBuilder
|
|
||||||
private var contentArea: some View {
|
|
||||||
switch controller.mode {
|
|
||||||
case .boards:
|
|
||||||
ShoeGazeView(shoeGaze: controller.shoeGaze, hardwareSampleRate: hardwareSampleRate)
|
|
||||||
|
|
||||||
case .editor:
|
|
||||||
editorContent
|
|
||||||
|
|
||||||
case .parallel:
|
|
||||||
parallelContent
|
|
||||||
|
|
||||||
case .router:
|
|
||||||
routerContent
|
|
||||||
|
|
||||||
case .stereo:
|
|
||||||
stereoContent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `.editor` content: `BoardEditorView` bound to the first board in the session.
|
|
||||||
///
|
|
||||||
/// Shows a placeholder when the board list is unexpectedly empty (e.g. if
|
|
||||||
/// `buildEditor()` failed silently).
|
|
||||||
@ViewBuilder
|
|
||||||
private var editorContent: some View {
|
|
||||||
if controller.shoeGaze.boards.isEmpty {
|
|
||||||
Text("No editor board available.")
|
|
||||||
.foregroundStyle(Color.white.opacity(0.55))
|
|
||||||
} else {
|
|
||||||
BoardEditorView(
|
|
||||||
shoeGaze: controller.shoeGaze,
|
|
||||||
boardIndex: 0,
|
|
||||||
versionStore: controller.versionStore
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `.parallel` content: the full board view (shows pre/post-split pedals) stacked
|
|
||||||
/// above `ParallelSectionView` which exposes the splitter mode picker and branch rows.
|
|
||||||
@ViewBuilder
|
|
||||||
private var parallelContent: some View {
|
|
||||||
if let section: ParallelSection = controller.parallelSection,
|
|
||||||
!controller.shoeGaze.boards.isEmpty {
|
|
||||||
let board: PedalBoard = controller.shoeGaze.boards[0]
|
|
||||||
ScrollView(.vertical, showsIndicators: true) {
|
|
||||||
VStack(alignment: .leading, spacing: 20) {
|
|
||||||
PedalBoardView(board: board)
|
|
||||||
ParallelSectionView(section: section)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Text("Parallel section unavailable.")
|
|
||||||
.foregroundStyle(Color.white.opacity(0.55))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `.stereo` content: the full board view (shows the pre-split pedal) stacked above a
|
|
||||||
/// width badge and `StereoSplitSectionView` (route picker + L/R branch rows).
|
|
||||||
@ViewBuilder
|
|
||||||
private var stereoContent: some View {
|
|
||||||
if let section: StereoSplitSection = controller.stereoSection,
|
|
||||||
let board: PedalBoard = controller.shoeGaze.boards.first {
|
|
||||||
ScrollView(.vertical, showsIndicators: true) {
|
|
||||||
VStack(alignment: .leading, spacing: 20) {
|
|
||||||
HStack(spacing: 10) {
|
|
||||||
PedalBoardView(board: board)
|
|
||||||
StereoWidthBadge(width: board.width)
|
|
||||||
}
|
|
||||||
StereoSplitSectionView(section: section)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Text("Stereo split unavailable.")
|
|
||||||
.foregroundStyle(Color.white.opacity(0.55))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `.router` content: `ChainRouterView` bound to the live `ChainRouter`.
|
|
||||||
@ViewBuilder
|
|
||||||
private var routerContent: some View {
|
|
||||||
if let chainRouter: ChainRouter = controller.router {
|
|
||||||
ScrollView(.vertical, showsIndicators: true) {
|
|
||||||
ChainRouterView(router: chainRouter)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Text("Chain router unavailable.")
|
|
||||||
.foregroundStyle(Color.white.opacity(0.55))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>CFBundleExecutable</key>
|
|
||||||
<string>$(EXECUTABLE_NAME)</string>
|
|
||||||
<key>CFBundleIdentifier</key>
|
|
||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
||||||
<key>CFBundleInfoDictionaryVersion</key>
|
|
||||||
<string>6.0</string>
|
|
||||||
<key>CFBundleName</key>
|
|
||||||
<string>$(PRODUCT_NAME)</string>
|
|
||||||
<key>CFBundlePackageType</key>
|
|
||||||
<string>APPL</string>
|
|
||||||
<key>CFBundleShortVersionString</key>
|
|
||||||
<string>1.0</string>
|
|
||||||
<key>CFBundleVersion</key>
|
|
||||||
<string>1</string>
|
|
||||||
<key>LSApplicationCategoryType</key>
|
|
||||||
<string>public.app-category.music</string>
|
|
||||||
<key>LSMinimumSystemVersion</key>
|
|
||||||
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
|
|
||||||
<key>NSHighResolutionCapable</key>
|
|
||||||
<true/>
|
|
||||||
<key>NSHumanReadableCopyright</key>
|
|
||||||
<string>Copyright © 2026 realizedsound. All rights reserved.</string>
|
|
||||||
<key>NSMicrophoneUsageDescription</key>
|
|
||||||
<string>ShoeGazeDemo can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode.</string>
|
|
||||||
<key>NSPrincipalClass</key>
|
|
||||||
<string>NSApplication</string>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>com.apple.security.device.audio-input</key>
|
|
||||||
<true/>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
||||||
@@ -1,371 +0,0 @@
|
|||||||
// ShoeGazeDemoController.swift
|
|
||||||
// Lyrebird
|
|
||||||
//
|
|
||||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
#if os(macOS)
|
|
||||||
import Observation
|
|
||||||
import LyrebirdSynth
|
|
||||||
import LyrebirdUI
|
|
||||||
import LyrebirdShoeGaze
|
|
||||||
|
|
||||||
// MARK: - DemoMode
|
|
||||||
|
|
||||||
/// The active showcase mode displayed in the demo window.
|
|
||||||
///
|
|
||||||
/// Each case corresponds to one full-window showcase of a distinct ShoeGaze feature.
|
|
||||||
/// Switching modes tears down the current audio graph and rebuilds it fresh.
|
|
||||||
enum DemoMode: String, CaseIterable, Identifiable {
|
|
||||||
|
|
||||||
/// Two full boards, each with four pedals (Board 1: Overdrive → Delay → Reverb → Modulation;
|
|
||||||
/// Board 2: Fuzz → Tremolo → Phaser → Compressor).
|
|
||||||
case boards = "Boards"
|
|
||||||
|
|
||||||
/// A single board inside `BoardEditorView` with preset version snapshots pre-populated.
|
|
||||||
case editor = "Editor"
|
|
||||||
|
|
||||||
/// A single board with a ``ParallelSection`` (Overdrive → split → Delay|Fuzz → merge → Reverb).
|
|
||||||
case parallel = "Parallel"
|
|
||||||
|
|
||||||
/// A ``ChainRouter`` that splits one input across two independent boards (A: Overdrive + Delay;
|
|
||||||
/// B: Fuzz + Reverb) and recombines them through a shared master stage.
|
|
||||||
case router = "Router"
|
|
||||||
|
|
||||||
/// A board with a ``StereoSplitSection`` (Overdrive → splitStereo(Delay | PingPong) →
|
|
||||||
/// collectStereo) showcasing the four ``StereoRoute`` modes and stereo output.
|
|
||||||
case stereo = "Stereo"
|
|
||||||
|
|
||||||
var id: String { rawValue }
|
|
||||||
|
|
||||||
/// Short human-readable title used in the mode picker.
|
|
||||||
var title: String {
|
|
||||||
switch self {
|
|
||||||
case .boards: return "Boards"
|
|
||||||
case .editor: return "Editor"
|
|
||||||
case .parallel: return "Parallel"
|
|
||||||
case .router: return "Router"
|
|
||||||
case .stereo: return "Stereo"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - ShoeGazeDemoController
|
|
||||||
|
|
||||||
/// Main-actor observable controller that owns the engine and active ShoeGaze session.
|
|
||||||
///
|
|
||||||
/// A single `ShoeGaze` instance plus optional `router` / `parallelSection` hold the
|
|
||||||
/// current showcase. Switching modes via ``select(_:)`` or changing the input source via
|
|
||||||
/// ``setInputSource(_:)`` calls ``rebuild()`` which:
|
|
||||||
///
|
|
||||||
/// 1. Stops the engine if it is running.
|
|
||||||
/// 2. Calls `shoeGaze.teardown()` to remove all nodes and release all buses.
|
|
||||||
/// 3. Replaces `shoeGaze` with a fresh instance.
|
|
||||||
/// 4. Builds the new mode-specific graph.
|
|
||||||
/// 5. Restarts the engine if it was running before the rebuild.
|
|
||||||
///
|
|
||||||
/// This guarantees the engine never holds stale references across mode switches.
|
|
||||||
@MainActor
|
|
||||||
@Observable
|
|
||||||
final class ShoeGazeDemoController {
|
|
||||||
|
|
||||||
// MARK: - Public state
|
|
||||||
|
|
||||||
/// The synthesis engine. Callers must not call `engine.start()` or `engine.stop()`
|
|
||||||
/// directly — use ``start()`` and ``stop()`` so `isRunning` stays consistent.
|
|
||||||
let engine: SynthesisEngine
|
|
||||||
|
|
||||||
/// The active ShoeGaze session. Replaced on every ``rebuild()`` call.
|
|
||||||
private(set) var shoeGaze: ShoeGaze
|
|
||||||
|
|
||||||
/// Non-nil only in `.router` mode, after ``buildRouter()`` succeeds.
|
|
||||||
private(set) var router: ChainRouter?
|
|
||||||
|
|
||||||
/// Non-nil only in `.parallel` mode, after ``buildParallel()`` succeeds.
|
|
||||||
private(set) var parallelSection: ParallelSection?
|
|
||||||
|
|
||||||
/// Non-nil only in `.stereo` mode, after ``buildStereo()`` succeeds.
|
|
||||||
private(set) var stereoSection: StereoSplitSection?
|
|
||||||
|
|
||||||
/// Stores named board snapshots for the `.editor` showcase.
|
|
||||||
let versionStore: BoardVersionStore = BoardVersionStore()
|
|
||||||
|
|
||||||
/// Currently selected showcase mode.
|
|
||||||
private(set) var mode: DemoMode = .boards
|
|
||||||
|
|
||||||
/// Current input source policy.
|
|
||||||
private(set) var inputSource: InputSource = .testLoop
|
|
||||||
|
|
||||||
/// `true` while the engine is running. Derived from the engine (the single source
|
|
||||||
/// of truth) so it stays correct regardless of which control starts/stops it.
|
|
||||||
var isRunning: Bool { engine.isRunning }
|
|
||||||
|
|
||||||
// MARK: - Init
|
|
||||||
|
|
||||||
/// Creates a controller, builds the default `.boards` showcase, and does NOT start the engine.
|
|
||||||
///
|
|
||||||
/// - Parameter engine: A pre-configured `SynthesisEngine` owned by the caller. The
|
|
||||||
/// engine must not be running when this initialiser is called.
|
|
||||||
init(engine: SynthesisEngine) {
|
|
||||||
self.engine = engine
|
|
||||||
self.shoeGaze = ShoeGaze(engine: engine, inputSource: .testLoop)
|
|
||||||
buildBoards()
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Mode selection
|
|
||||||
|
|
||||||
/// Switches to the given mode if different from the current one, triggering a full rebuild.
|
|
||||||
///
|
|
||||||
/// - Parameter newMode: The showcase to activate.
|
|
||||||
func select(_ newMode: DemoMode) {
|
|
||||||
guard newMode != mode else { return }
|
|
||||||
mode = newMode
|
|
||||||
rebuild()
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Input source
|
|
||||||
|
|
||||||
/// Changes the input source policy and triggers a full rebuild.
|
|
||||||
///
|
|
||||||
/// Live input requires microphone authorisation first — without it macOS feeds the AUHAL input
|
|
||||||
/// silent zeros. The request is asynchronous, so `.liveInput` is applied only once the grant
|
|
||||||
/// resolves; a denial falls back to the test loop.
|
|
||||||
///
|
|
||||||
/// - Parameter source: `.testLoop` for the built-in test signal or `.liveInput(channel:)`
|
|
||||||
/// for hardware microphone/instrument input on the given channel.
|
|
||||||
func setInputSource(_ source: InputSource) {
|
|
||||||
guard case .liveInput = source else {
|
|
||||||
applyInputSource(source)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
MicrophonePermission.request { [weak self] granted in
|
|
||||||
if !granted { self?.microphoneAccessDenied = true }
|
|
||||||
self?.applyInputSource(granted ? source : .testLoop)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Set when live input is requested but microphone access is denied/restricted. The UI observes
|
|
||||||
/// this and presents an alert, then clears it.
|
|
||||||
var microphoneAccessDenied: Bool = false
|
|
||||||
|
|
||||||
/// Applies an input-source change and triggers a full rebuild.
|
|
||||||
private func applyInputSource(_ source: InputSource) {
|
|
||||||
inputSource = source
|
|
||||||
rebuild()
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Transport
|
|
||||||
|
|
||||||
/// Starts the engine. Updates ``isRunning`` on success; prints on failure.
|
|
||||||
func start() {
|
|
||||||
do {
|
|
||||||
try engine.start()
|
|
||||||
} catch {
|
|
||||||
print("[ShoeGazeDemoController] engine.start() failed: \(error)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Stops the engine and updates ``isRunning``.
|
|
||||||
func stop() {
|
|
||||||
engine.stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Toggles audio output on/off (mute). Muting silences output by stopping the engine;
|
|
||||||
/// unmuting restarts it. `isRunning == false` is the "muted" (silent) state.
|
|
||||||
func toggleMute() {
|
|
||||||
if isRunning {
|
|
||||||
stop()
|
|
||||||
} else {
|
|
||||||
start()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Engine reconfiguration
|
|
||||||
|
|
||||||
/// Applies new engine settings (while stopped) and rebuilds the current mode so the showcase
|
|
||||||
/// is reconstructed at the new sample rate / channel counts. Used by the engine-config UI.
|
|
||||||
///
|
|
||||||
/// Tears the session down BEFORE reconfiguring — changing channel counts re-partitions the bus
|
|
||||||
/// allocator, which would invalidate rig buses still allocated under the old layout.
|
|
||||||
///
|
|
||||||
/// - Throws: `SynthesisEngineConfigError` if the engine is running or a value is invalid.
|
|
||||||
func reconfigure(sampleRate: Double, inputChannels: Int, outputChannels: Int) throws {
|
|
||||||
let wasRunning: Bool = isRunning
|
|
||||||
if wasRunning { stop() }
|
|
||||||
|
|
||||||
tearDownSession()
|
|
||||||
try engine.setSampleRate(sampleRate)
|
|
||||||
try engine.setNumOutputChannels(outputChannels)
|
|
||||||
try engine.setNumInputChannels(inputChannels)
|
|
||||||
// A live-input source past the new channel count would make rebuild fail; fall back.
|
|
||||||
if case .liveInput(let channel) = inputSource, channel >= inputChannels {
|
|
||||||
inputSource = .testLoop
|
|
||||||
}
|
|
||||||
buildSession()
|
|
||||||
// `buildSession()` creates a fresh `ShoeGaze`, whose `init` installs the scope tap for the
|
|
||||||
// new channel layout — no explicit `installScopeTap()` needed here.
|
|
||||||
|
|
||||||
if wasRunning { start() }
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Rebuild
|
|
||||||
|
|
||||||
/// Tears down the current session and rebuilds the active mode.
|
|
||||||
///
|
|
||||||
/// The engine is stopped before teardown and restarted afterward if it was running,
|
|
||||||
/// satisfying the remove-before-release invariant documented on `ShoeGaze.teardown()`.
|
|
||||||
private func rebuild() {
|
|
||||||
let wasRunning: Bool = isRunning
|
|
||||||
if wasRunning { stop() }
|
|
||||||
tearDownSession()
|
|
||||||
buildSession()
|
|
||||||
if wasRunning { start() }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Removes the current session's nodes and clears split/router references.
|
|
||||||
private func tearDownSession() {
|
|
||||||
shoeGaze.teardown()
|
|
||||||
router = nil
|
|
||||||
parallelSection = nil
|
|
||||||
stereoSection = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Creates a fresh session and builds the active mode's graph.
|
|
||||||
private func buildSession() {
|
|
||||||
shoeGaze = ShoeGaze(engine: engine, inputSource: inputSource)
|
|
||||||
switch mode {
|
|
||||||
case .boards: buildBoards()
|
|
||||||
case .editor: buildEditor()
|
|
||||||
case .parallel: buildParallel()
|
|
||||||
case .router: buildRouter()
|
|
||||||
case .stereo: buildStereo()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Mode builders
|
|
||||||
|
|
||||||
/// `.boards` — three full boards covering all twelve pedal types.
|
|
||||||
///
|
|
||||||
/// Board 1: Overdrive → Delay → Reverb → Modulation
|
|
||||||
/// Board 2: Fuzz → Tremolo → Phaser → Compressor
|
|
||||||
/// Board 3: Mutant → Auto-Wah → Feedback Delay → Multi-Tap Delay
|
|
||||||
private func buildBoards() {
|
|
||||||
do {
|
|
||||||
let board1: PedalBoard = try shoeGaze.addBoard()
|
|
||||||
board1.label = "Board 1"
|
|
||||||
try board1.add(OverdrivePedal())
|
|
||||||
try board1.add(DelayPedal())
|
|
||||||
try board1.add(ReverbPedal())
|
|
||||||
try board1.add(ModulationPedal())
|
|
||||||
try shoeGaze.finalizeBoard(board1)
|
|
||||||
|
|
||||||
let board2: PedalBoard = try shoeGaze.addBoard()
|
|
||||||
board2.label = "Board 2"
|
|
||||||
try board2.add(FuzzPedal())
|
|
||||||
try board2.add(TremoloPedal())
|
|
||||||
try board2.add(PhaserPedal())
|
|
||||||
try board2.add(CompressorPedal())
|
|
||||||
try shoeGaze.finalizeBoard(board2)
|
|
||||||
|
|
||||||
let board3: PedalBoard = try shoeGaze.addBoard()
|
|
||||||
board3.label = "Board 3"
|
|
||||||
try board3.add(MutantPedal())
|
|
||||||
try board3.add(AutoWahPedal())
|
|
||||||
try board3.add(FeedbackDelayPedal())
|
|
||||||
try board3.add(MultiTapDelayPedal())
|
|
||||||
try shoeGaze.finalizeBoard(board3)
|
|
||||||
} catch {
|
|
||||||
print("[ShoeGazeDemoController] buildBoards failed: \(error)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `.editor` — one board inside `BoardEditorView` with two pre-captured versions.
|
|
||||||
///
|
|
||||||
/// The pre-populated version entries ("Crunch" and "Clean Shimmer") ensure the
|
|
||||||
/// Versions menu is not empty when the showcase first appears.
|
|
||||||
private func buildEditor() {
|
|
||||||
do {
|
|
||||||
let board: PedalBoard = try shoeGaze.addBoard()
|
|
||||||
board.label = "Editor Board"
|
|
||||||
try board.add(OverdrivePedal())
|
|
||||||
try board.add(FuzzPedal())
|
|
||||||
try board.add(DelayPedal())
|
|
||||||
try board.add(ReverbPedal())
|
|
||||||
try shoeGaze.finalizeBoard(board)
|
|
||||||
|
|
||||||
// Pre-populate two named snapshots so the Versions menu is immediately useful.
|
|
||||||
versionStore.capture(board, name: "Crunch")
|
|
||||||
versionStore.capture(board, name: "Clean Shimmer")
|
|
||||||
} catch {
|
|
||||||
print("[ShoeGazeDemoController] buildEditor failed: \(error)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `.parallel` — Overdrive → split(Delay | Fuzz) → merge → Reverb.
|
|
||||||
///
|
|
||||||
/// Stores the `ParallelSection` in `parallelSection` so `DemoRootView` can display
|
|
||||||
/// `ParallelSectionView`.
|
|
||||||
private func buildParallel() {
|
|
||||||
do {
|
|
||||||
let board: PedalBoard = try shoeGaze.addBoard()
|
|
||||||
board.label = "Parallel Board"
|
|
||||||
try board.add(OverdrivePedal())
|
|
||||||
|
|
||||||
let section: ParallelSection = try board.split()
|
|
||||||
try section.branchA.add(DelayPedal())
|
|
||||||
try section.branchB.add(FuzzPedal())
|
|
||||||
try board.merge(section)
|
|
||||||
|
|
||||||
try board.add(ReverbPedal())
|
|
||||||
try shoeGaze.finalizeBoard(board)
|
|
||||||
|
|
||||||
parallelSection = section
|
|
||||||
} catch {
|
|
||||||
print("[ShoeGazeDemoController] buildParallel failed: \(error)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `.router` — ChainRouter with two independent chains: A (Overdrive + Delay),
|
|
||||||
/// B (Fuzz + Reverb), merged through a shared master stage.
|
|
||||||
///
|
|
||||||
/// Stores the `ChainRouter` in `router` so `DemoRootView` can display
|
|
||||||
/// `ChainRouterView`.
|
|
||||||
private func buildRouter() {
|
|
||||||
do {
|
|
||||||
let r: ChainRouter = try shoeGaze.makeChainRouter()
|
|
||||||
try r.addToA(OverdrivePedal())
|
|
||||||
try r.addToA(DelayPedal())
|
|
||||||
try r.addToB(FuzzPedal())
|
|
||||||
try r.addToB(ReverbPedal())
|
|
||||||
try r.finalize()
|
|
||||||
router = r
|
|
||||||
} catch {
|
|
||||||
print("[ShoeGazeDemoController] buildRouter failed: \(error)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `.stereo` — Overdrive → splitStereo(left: Delay | right: Ping-Pong) → collectStereo.
|
|
||||||
///
|
|
||||||
/// Demonstrates the stereo split mechanism: a mono signal fanned into two independently
|
|
||||||
/// authored chains that become the left and right output channels, with the four
|
|
||||||
/// ``StereoRoute`` modes (stereo / left / right / bypass) selectable live. Stores the
|
|
||||||
/// `StereoSplitSection` so `DemoRootView` can display `StereoSplitSectionView`.
|
|
||||||
private func buildStereo() {
|
|
||||||
do {
|
|
||||||
let board: PedalBoard = try shoeGaze.addBoard()
|
|
||||||
board.label = "Stereo Board"
|
|
||||||
try board.add(OverdrivePedal())
|
|
||||||
|
|
||||||
let section: StereoSplitSection = try board.splitStereo()
|
|
||||||
try section.left.add(DelayPedal())
|
|
||||||
try section.right.add(PingPongDelayPedal())
|
|
||||||
try board.collectStereo(section)
|
|
||||||
|
|
||||||
try shoeGaze.finalizeBoard(board)
|
|
||||||
stereoSection = section
|
|
||||||
} catch {
|
|
||||||
print("[ShoeGazeDemoController] buildStereo failed: \(error)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
// main.swift
|
|
||||||
// Lyrebird
|
|
||||||
//
|
|
||||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
#if os(macOS)
|
|
||||||
import AppKit
|
|
||||||
|
|
||||||
// Program entry runs on the main thread; assert main-actor isolation for the
|
|
||||||
// AppKit bootstrap rather than hopping asynchronously. `AppDelegate.init` builds
|
|
||||||
// `@MainActor` synthesizers and UI.
|
|
||||||
MainActor.assumeIsolated {
|
|
||||||
let app: NSApplication = NSApplication.shared
|
|
||||||
let delegate: AppDelegate = AppDelegate()
|
|
||||||
app.setActivationPolicy(.regular)
|
|
||||||
app.delegate = delegate
|
|
||||||
app.activate(ignoringOtherApps: true)
|
|
||||||
app.run()
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
// The ShoeGaze demo is a macOS AppKit application and has no iOS entry point.
|
|
||||||
print("ShoeGazeDemo runs on macOS only.")
|
|
||||||
#endif
|
|
||||||
@@ -1,387 +0,0 @@
|
|||||||
// !$*UTF8*$!
|
|
||||||
{
|
|
||||||
archiveVersion = 1;
|
|
||||||
classes = {
|
|
||||||
};
|
|
||||||
objectVersion = 60;
|
|
||||||
objects = {
|
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
|
||||||
C3C000000000000000000009 /* ShoeGazeiOSDemoApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C000000000000000000007 /* ShoeGazeiOSDemoApp.swift */; };
|
|
||||||
C3C00000000000000000000A /* ShoeGazeiOSDemoAppModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3C000000000000000000008 /* ShoeGazeiOSDemoAppModel.swift */; };
|
|
||||||
C3C00000000000000000000B /* LyrebirdShoeGaze in Frameworks */ = {isa = PBXBuildFile; productRef = C3C00000000000000000001A /* LyrebirdShoeGaze */; };
|
|
||||||
C3C00000000000000000000C /* LyrebirdShoeGazeUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3C00000000000000000001B /* LyrebirdShoeGazeUI */; };
|
|
||||||
C3C00000000000000000000D /* LyrebirdUI in Frameworks */ = {isa = PBXBuildFile; productRef = C3C00000000000000000001C /* LyrebirdUI */; };
|
|
||||||
C3C00000000000000000001D /* Lyrebird in Frameworks */ = {isa = PBXBuildFile; productRef = C3C00000000000000000001E /* Lyrebird */; };
|
|
||||||
C3C000000000000000000031 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C3C000000000000000000030 /* Assets.xcassets */; };
|
|
||||||
/* End PBXBuildFile section */
|
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
|
||||||
C3C000000000000000000004 /* ShoeGazeiOSDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ShoeGazeiOSDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
|
||||||
C3C000000000000000000006 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
|
||||||
C3C000000000000000000007 /* ShoeGazeiOSDemoApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoeGazeiOSDemoApp.swift; sourceTree = "<group>"; };
|
|
||||||
C3C000000000000000000008 /* ShoeGazeiOSDemoAppModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoeGazeiOSDemoAppModel.swift; sourceTree = "<group>"; };
|
|
||||||
C3C000000000000000000030 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
|
||||||
/* End PBXFileReference section */
|
|
||||||
|
|
||||||
/* Begin PBXFrameworksBuildPhase section */
|
|
||||||
C3C00000000000000000000F /* Frameworks */ = {
|
|
||||||
isa = PBXFrameworksBuildPhase;
|
|
||||||
buildActionMask = 2147483647;
|
|
||||||
files = (
|
|
||||||
C3C00000000000000000000B /* LyrebirdShoeGaze in Frameworks */,
|
|
||||||
C3C00000000000000000000C /* LyrebirdShoeGazeUI in Frameworks */,
|
|
||||||
C3C00000000000000000000D /* LyrebirdUI in Frameworks */,
|
|
||||||
C3C00000000000000000001D /* Lyrebird in Frameworks */,
|
|
||||||
);
|
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
|
||||||
};
|
|
||||||
/* End PBXFrameworksBuildPhase section */
|
|
||||||
|
|
||||||
/* Begin PBXGroup section */
|
|
||||||
C3C000000000000000000002 = {
|
|
||||||
isa = PBXGroup;
|
|
||||||
children = (
|
|
||||||
C3C000000000000000000005 /* ShoeGazeiOSDemo */,
|
|
||||||
C3C000000000000000000003 /* Products */,
|
|
||||||
);
|
|
||||||
sourceTree = "<group>";
|
|
||||||
};
|
|
||||||
C3C000000000000000000003 /* Products */ = {
|
|
||||||
isa = PBXGroup;
|
|
||||||
children = (
|
|
||||||
C3C000000000000000000004 /* ShoeGazeiOSDemo.app */,
|
|
||||||
);
|
|
||||||
name = Products;
|
|
||||||
sourceTree = "<group>";
|
|
||||||
};
|
|
||||||
C3C000000000000000000005 /* ShoeGazeiOSDemo */ = {
|
|
||||||
isa = PBXGroup;
|
|
||||||
children = (
|
|
||||||
C3C000000000000000000007 /* ShoeGazeiOSDemoApp.swift */,
|
|
||||||
C3C000000000000000000008 /* ShoeGazeiOSDemoAppModel.swift */,
|
|
||||||
C3C000000000000000000030 /* Assets.xcassets */,
|
|
||||||
C3C000000000000000000006 /* Info.plist */,
|
|
||||||
);
|
|
||||||
path = ShoeGazeiOSDemo;
|
|
||||||
sourceTree = "<group>";
|
|
||||||
};
|
|
||||||
/* End PBXGroup section */
|
|
||||||
|
|
||||||
/* Begin PBXNativeTarget section */
|
|
||||||
C3C000000000000000000011 /* ShoeGazeiOSDemo */ = {
|
|
||||||
isa = PBXNativeTarget;
|
|
||||||
buildConfigurationList = C3C000000000000000000012 /* Build configuration list for PBXNativeTarget "ShoeGazeiOSDemo" */;
|
|
||||||
buildPhases = (
|
|
||||||
C3C00000000000000000000E /* Sources */,
|
|
||||||
C3C00000000000000000000F /* Frameworks */,
|
|
||||||
C3C000000000000000000010 /* Resources */,
|
|
||||||
);
|
|
||||||
buildRules = (
|
|
||||||
);
|
|
||||||
dependencies = (
|
|
||||||
);
|
|
||||||
name = ShoeGazeiOSDemo;
|
|
||||||
packageProductDependencies = (
|
|
||||||
C3C00000000000000000001A /* LyrebirdShoeGaze */,
|
|
||||||
C3C00000000000000000001B /* LyrebirdShoeGazeUI */,
|
|
||||||
C3C00000000000000000001C /* LyrebirdUI */,
|
|
||||||
C3C00000000000000000001E /* Lyrebird */,
|
|
||||||
);
|
|
||||||
productName = ShoeGazeiOSDemo;
|
|
||||||
productReference = C3C000000000000000000004 /* ShoeGazeiOSDemo.app */;
|
|
||||||
productType = "com.apple.product-type.application";
|
|
||||||
};
|
|
||||||
/* End PBXNativeTarget section */
|
|
||||||
|
|
||||||
/* Begin PBXProject section */
|
|
||||||
C3C000000000000000000001 /* Project object */ = {
|
|
||||||
isa = PBXProject;
|
|
||||||
attributes = {
|
|
||||||
BuildIndependentTargetsInParallel = 1;
|
|
||||||
LastSwiftUpdateCheck = 1600;
|
|
||||||
LastUpgradeCheck = 2620;
|
|
||||||
TargetAttributes = {
|
|
||||||
C3C000000000000000000011 = {
|
|
||||||
CreatedOnToolsVersion = 16.0;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
buildConfigurationList = C3C000000000000000000015 /* Build configuration list for PBXProject "ShoeGazeiOSDemo" */;
|
|
||||||
compatibilityVersion = "Xcode 14.0";
|
|
||||||
developmentRegion = en;
|
|
||||||
hasScannedForEncodings = 0;
|
|
||||||
knownRegions = (
|
|
||||||
en,
|
|
||||||
Base,
|
|
||||||
);
|
|
||||||
mainGroup = C3C000000000000000000002;
|
|
||||||
packageReferences = (
|
|
||||||
C3C000000000000000000018 /* XCLocalSwiftPackageReference ".." */,
|
|
||||||
C3C000000000000000000019 /* XCRemoteSwiftPackageReference "Lyrebird" */,
|
|
||||||
);
|
|
||||||
productRefGroup = C3C000000000000000000003 /* Products */;
|
|
||||||
projectDirPath = "";
|
|
||||||
projectRoot = "";
|
|
||||||
targets = (
|
|
||||||
C3C000000000000000000011 /* ShoeGazeiOSDemo */,
|
|
||||||
);
|
|
||||||
};
|
|
||||||
/* End PBXProject section */
|
|
||||||
|
|
||||||
/* Begin PBXResourcesBuildPhase section */
|
|
||||||
C3C000000000000000000010 /* Resources */ = {
|
|
||||||
isa = PBXResourcesBuildPhase;
|
|
||||||
buildActionMask = 2147483647;
|
|
||||||
files = (
|
|
||||||
C3C000000000000000000031 /* Assets.xcassets in Resources */,
|
|
||||||
);
|
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
|
||||||
};
|
|
||||||
/* End PBXResourcesBuildPhase section */
|
|
||||||
|
|
||||||
/* Begin PBXSourcesBuildPhase section */
|
|
||||||
C3C00000000000000000000E /* Sources */ = {
|
|
||||||
isa = PBXSourcesBuildPhase;
|
|
||||||
buildActionMask = 2147483647;
|
|
||||||
files = (
|
|
||||||
C3C000000000000000000009 /* ShoeGazeiOSDemoApp.swift in Sources */,
|
|
||||||
C3C00000000000000000000A /* ShoeGazeiOSDemoAppModel.swift in Sources */,
|
|
||||||
);
|
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
|
||||||
};
|
|
||||||
/* End PBXSourcesBuildPhase section */
|
|
||||||
|
|
||||||
/* Begin XCBuildConfiguration section */
|
|
||||||
C3C000000000000000000013 /* Debug */ = {
|
|
||||||
isa = XCBuildConfiguration;
|
|
||||||
buildSettings = {
|
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
|
||||||
CODE_SIGNING_REQUIRED = NO;
|
|
||||||
CODE_SIGN_STYLE = Automatic;
|
|
||||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
|
||||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
|
||||||
INFOPLIST_FILE = ShoeGazeiOSDemo/Info.plist;
|
|
||||||
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.music";
|
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
|
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
|
||||||
"$(inherited)",
|
|
||||||
"@executable_path/Frameworks",
|
|
||||||
);
|
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeiOSDemo;
|
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
|
||||||
SDKROOT = iphoneos;
|
|
||||||
SUPPORTS_MACCATALYST = NO;
|
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
|
||||||
SWIFT_VERSION = 6.0;
|
|
||||||
TARGETED_DEVICE_FAMILY = 2;
|
|
||||||
};
|
|
||||||
name = Debug;
|
|
||||||
};
|
|
||||||
C3C000000000000000000014 /* Release */ = {
|
|
||||||
isa = XCBuildConfiguration;
|
|
||||||
buildSettings = {
|
|
||||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
|
||||||
CODE_SIGNING_REQUIRED = NO;
|
|
||||||
CODE_SIGN_STYLE = Automatic;
|
|
||||||
DEVELOPMENT_TEAM = HE5VJFE9E4;
|
|
||||||
INFOPLIST_FILE = ShoeGazeiOSDemo/Info.plist;
|
|
||||||
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.music";
|
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
|
|
||||||
LD_RUNPATH_SEARCH_PATHS = (
|
|
||||||
"$(inherited)",
|
|
||||||
"@executable_path/Frameworks",
|
|
||||||
);
|
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = net.realizedsound.ShoeGazeiOSDemo;
|
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
|
||||||
SDKROOT = iphoneos;
|
|
||||||
SUPPORTS_MACCATALYST = NO;
|
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
|
||||||
SWIFT_VERSION = 6.0;
|
|
||||||
TARGETED_DEVICE_FAMILY = 2;
|
|
||||||
};
|
|
||||||
name = Release;
|
|
||||||
};
|
|
||||||
C3C000000000000000000016 /* Debug */ = {
|
|
||||||
isa = XCBuildConfiguration;
|
|
||||||
buildSettings = {
|
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
|
||||||
CLANG_ANALYZER_NONNULL = YES;
|
|
||||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
|
||||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
|
||||||
CLANG_ENABLE_MODULES = YES;
|
|
||||||
CLANG_ENABLE_OBJC_ARC = YES;
|
|
||||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
|
||||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
|
||||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_COMMA = YES;
|
|
||||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
|
||||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
|
||||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
|
||||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
|
||||||
CLANG_WARN_EMPTY_BODY = YES;
|
|
||||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
|
||||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
|
||||||
CLANG_WARN_INT_CONVERSION = YES;
|
|
||||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
|
||||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
|
||||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
|
||||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
|
||||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
|
||||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
|
||||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
|
||||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
|
||||||
COPY_PHASE_STRIP = NO;
|
|
||||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
|
||||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
|
||||||
ENABLE_TESTABILITY = YES;
|
|
||||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
|
||||||
GCC_C_LANGUAGE_STANDARD = gnu17;
|
|
||||||
GCC_DYNAMIC_NO_PIC = NO;
|
|
||||||
GCC_NO_COMMON_BLOCKS = YES;
|
|
||||||
GCC_OPTIMIZATION_LEVEL = 0;
|
|
||||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
|
||||||
"DEBUG=1",
|
|
||||||
"$(inherited)",
|
|
||||||
);
|
|
||||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
|
||||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
|
||||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
|
||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
|
|
||||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
|
||||||
MTL_FAST_MATH = YES;
|
|
||||||
ONLY_ACTIVE_ARCH = YES;
|
|
||||||
SDKROOT = iphoneos;
|
|
||||||
STRING_CATALOG_GENERATE_SYMBOLS = YES;
|
|
||||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
|
||||||
};
|
|
||||||
name = Debug;
|
|
||||||
};
|
|
||||||
C3C000000000000000000017 /* Release */ = {
|
|
||||||
isa = XCBuildConfiguration;
|
|
||||||
buildSettings = {
|
|
||||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
|
||||||
CLANG_ANALYZER_NONNULL = YES;
|
|
||||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
|
||||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
|
||||||
CLANG_ENABLE_MODULES = YES;
|
|
||||||
CLANG_ENABLE_OBJC_ARC = YES;
|
|
||||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
|
||||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
|
||||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_COMMA = YES;
|
|
||||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
|
||||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
|
||||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
|
||||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
|
||||||
CLANG_WARN_EMPTY_BODY = YES;
|
|
||||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
|
||||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
|
||||||
CLANG_WARN_INT_CONVERSION = YES;
|
|
||||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
|
||||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
|
||||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
|
||||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
|
||||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
|
||||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
|
||||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
|
||||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
|
||||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
|
||||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
|
||||||
COPY_PHASE_STRIP = NO;
|
|
||||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
|
||||||
ENABLE_NS_ASSERTIONS = NO;
|
|
||||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
|
||||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
|
||||||
GCC_C_LANGUAGE_STANDARD = gnu17;
|
|
||||||
GCC_NO_COMMON_BLOCKS = YES;
|
|
||||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
|
||||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
|
||||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
|
||||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
|
||||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
|
||||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
|
||||||
IPHONEOS_DEPLOYMENT_TARGET = 18.0;
|
|
||||||
MTL_ENABLE_DEBUG_INFO = NO;
|
|
||||||
MTL_FAST_MATH = YES;
|
|
||||||
SDKROOT = iphoneos;
|
|
||||||
STRING_CATALOG_GENERATE_SYMBOLS = YES;
|
|
||||||
SWIFT_COMPILATION_MODE = wholemodule;
|
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-O";
|
|
||||||
};
|
|
||||||
name = Release;
|
|
||||||
};
|
|
||||||
/* End XCBuildConfiguration section */
|
|
||||||
|
|
||||||
/* Begin XCConfigurationList section */
|
|
||||||
C3C000000000000000000012 /* Build configuration list for PBXNativeTarget "ShoeGazeiOSDemo" */ = {
|
|
||||||
isa = XCConfigurationList;
|
|
||||||
buildConfigurations = (
|
|
||||||
C3C000000000000000000013 /* Debug */,
|
|
||||||
C3C000000000000000000014 /* Release */,
|
|
||||||
);
|
|
||||||
defaultConfigurationIsVisible = 0;
|
|
||||||
defaultConfigurationName = Release;
|
|
||||||
};
|
|
||||||
C3C000000000000000000015 /* Build configuration list for PBXProject "ShoeGazeiOSDemo" */ = {
|
|
||||||
isa = XCConfigurationList;
|
|
||||||
buildConfigurations = (
|
|
||||||
C3C000000000000000000016 /* Debug */,
|
|
||||||
C3C000000000000000000017 /* Release */,
|
|
||||||
);
|
|
||||||
defaultConfigurationIsVisible = 0;
|
|
||||||
defaultConfigurationName = Release;
|
|
||||||
};
|
|
||||||
/* End XCConfigurationList section */
|
|
||||||
|
|
||||||
/* Begin XCLocalSwiftPackageReference section */
|
|
||||||
C3C000000000000000000018 /* XCLocalSwiftPackageReference ".." */ = {
|
|
||||||
isa = XCLocalSwiftPackageReference;
|
|
||||||
relativePath = ..;
|
|
||||||
};
|
|
||||||
/* End XCLocalSwiftPackageReference section */
|
|
||||||
|
|
||||||
/* Begin XCRemoteSwiftPackageReference section */
|
|
||||||
C3C000000000000000000019 /* XCRemoteSwiftPackageReference "Lyrebird" */ = {
|
|
||||||
isa = XCRemoteSwiftPackageReference;
|
|
||||||
repositoryURL = "https://realizedsound.mooo.com/josh/Lyrebird";
|
|
||||||
requirement = {
|
|
||||||
kind = upToNextMajorVersion;
|
|
||||||
minimumVersion = 1.2.0;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
/* End XCRemoteSwiftPackageReference section */
|
|
||||||
|
|
||||||
/* Begin XCSwiftPackageProductDependency section */
|
|
||||||
C3C00000000000000000001A /* LyrebirdShoeGaze */ = {
|
|
||||||
isa = XCSwiftPackageProductDependency;
|
|
||||||
package = C3C000000000000000000018 /* XCLocalSwiftPackageReference ".." */;
|
|
||||||
productName = LyrebirdShoeGaze;
|
|
||||||
};
|
|
||||||
C3C00000000000000000001B /* LyrebirdShoeGazeUI */ = {
|
|
||||||
isa = XCSwiftPackageProductDependency;
|
|
||||||
package = C3C000000000000000000018 /* XCLocalSwiftPackageReference ".." */;
|
|
||||||
productName = LyrebirdShoeGazeUI;
|
|
||||||
};
|
|
||||||
C3C00000000000000000001C /* LyrebirdUI */ = {
|
|
||||||
isa = XCSwiftPackageProductDependency;
|
|
||||||
package = C3C000000000000000000019 /* XCRemoteSwiftPackageReference "Lyrebird" */;
|
|
||||||
productName = LyrebirdUI;
|
|
||||||
};
|
|
||||||
C3C00000000000000000001E /* Lyrebird */ = {
|
|
||||||
isa = XCSwiftPackageProductDependency;
|
|
||||||
package = C3C000000000000000000019 /* XCRemoteSwiftPackageReference "Lyrebird" */;
|
|
||||||
productName = Lyrebird;
|
|
||||||
};
|
|
||||||
/* End XCSwiftPackageProductDependency section */
|
|
||||||
};
|
|
||||||
rootObject = C3C000000000000000000001 /* Project object */;
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
{
|
|
||||||
"originHash" : "cfdd71f4b32d744c862bbe26a8265d75aa9e906275b0fb1b63575b7d68be1b6a",
|
|
||||||
"pins" : [
|
|
||||||
{
|
|
||||||
"identity" : "linenoise-swift",
|
|
||||||
"kind" : "remoteSourceControl",
|
|
||||||
"location" : "https://github.com/andybest/linenoise-swift",
|
|
||||||
"state" : {
|
|
||||||
"revision" : "afc897c02b030af7333105c4fedcd843a8339238",
|
|
||||||
"version" : "0.0.3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"identity" : "lyrebird",
|
|
||||||
"kind" : "remoteSourceControl",
|
|
||||||
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
|
|
||||||
"state" : {
|
|
||||||
"revision" : "032b7c39d351eba4029e8399e1ab1ee201e8bb5c",
|
|
||||||
"version" : "1.2.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"identity" : "nimble",
|
|
||||||
"kind" : "remoteSourceControl",
|
|
||||||
"location" : "https://github.com/Quick/Nimble.git",
|
|
||||||
"state" : {
|
|
||||||
"revision" : "e9d769113660769a4d9dd3afb855562c0b7ae7b0",
|
|
||||||
"version" : "7.3.4"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version" : 3
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<Scheme
|
|
||||||
LastUpgradeVersion = "2620"
|
|
||||||
version = "1.7">
|
|
||||||
<BuildAction
|
|
||||||
parallelizeBuildables = "YES"
|
|
||||||
buildImplicitDependencies = "YES"
|
|
||||||
buildArchitectures = "Automatic">
|
|
||||||
<BuildActionEntries>
|
|
||||||
<BuildActionEntry
|
|
||||||
buildForTesting = "YES"
|
|
||||||
buildForRunning = "YES"
|
|
||||||
buildForProfiling = "YES"
|
|
||||||
buildForArchiving = "YES"
|
|
||||||
buildForAnalyzing = "YES">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "C3C000000000000000000011"
|
|
||||||
BuildableName = "ShoeGazeiOSDemo.app"
|
|
||||||
BlueprintName = "ShoeGazeiOSDemo"
|
|
||||||
ReferencedContainer = "container:ShoeGazeiOSDemo.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildActionEntry>
|
|
||||||
</BuildActionEntries>
|
|
||||||
</BuildAction>
|
|
||||||
<TestAction
|
|
||||||
buildConfiguration = "Debug"
|
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
|
||||||
shouldAutocreateTestPlan = "YES">
|
|
||||||
</TestAction>
|
|
||||||
<LaunchAction
|
|
||||||
buildConfiguration = "Debug"
|
|
||||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
|
||||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
|
||||||
launchStyle = "0"
|
|
||||||
useCustomWorkingDirectory = "NO"
|
|
||||||
ignoresPersistentStateOnLaunch = "NO"
|
|
||||||
debugDocumentVersioning = "YES"
|
|
||||||
debugServiceExtension = "internal"
|
|
||||||
allowLocationSimulation = "YES">
|
|
||||||
<BuildableProductRunnable
|
|
||||||
runnableDebuggingMode = "0">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "C3C000000000000000000011"
|
|
||||||
BuildableName = "ShoeGazeiOSDemo.app"
|
|
||||||
BlueprintName = "ShoeGazeiOSDemo"
|
|
||||||
ReferencedContainer = "container:ShoeGazeiOSDemo.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildableProductRunnable>
|
|
||||||
</LaunchAction>
|
|
||||||
<ProfileAction
|
|
||||||
buildConfiguration = "Release"
|
|
||||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
|
||||||
savedToolIdentifier = ""
|
|
||||||
useCustomWorkingDirectory = "NO"
|
|
||||||
debugDocumentVersioning = "YES">
|
|
||||||
<BuildableProductRunnable
|
|
||||||
runnableDebuggingMode = "0">
|
|
||||||
<BuildableReference
|
|
||||||
BuildableIdentifier = "primary"
|
|
||||||
BlueprintIdentifier = "C3C000000000000000000011"
|
|
||||||
BuildableName = "ShoeGazeiOSDemo.app"
|
|
||||||
BlueprintName = "ShoeGazeiOSDemo"
|
|
||||||
ReferencedContainer = "container:ShoeGazeiOSDemo.xcodeproj">
|
|
||||||
</BuildableReference>
|
|
||||||
</BuildableProductRunnable>
|
|
||||||
</ProfileAction>
|
|
||||||
<AnalyzeAction
|
|
||||||
buildConfiguration = "Debug">
|
|
||||||
</AnalyzeAction>
|
|
||||||
<ArchiveAction
|
|
||||||
buildConfiguration = "Release"
|
|
||||||
revealArchiveInOrganizer = "YES">
|
|
||||||
</ArchiveAction>
|
|
||||||
</Scheme>
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
{
|
|
||||||
"images" : [
|
|
||||||
{"filename":"icon_1024.png","idiom":"universal","platform":"ios","size":"1024x1024"}
|
|
||||||
],
|
|
||||||
"info" : {"author":"xcode","version":1}
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 402 KiB |
@@ -1 +0,0 @@
|
|||||||
{ "info" : {"author":"xcode","version":1} }
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
||||||
<plist version="1.0">
|
|
||||||
<dict>
|
|
||||||
<key>CFBundleExecutable</key>
|
|
||||||
<string>$(EXECUTABLE_NAME)</string>
|
|
||||||
<key>CFBundleIdentifier</key>
|
|
||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
||||||
<key>CFBundleInfoDictionaryVersion</key>
|
|
||||||
<string>6.0</string>
|
|
||||||
<key>CFBundleName</key>
|
|
||||||
<string>$(PRODUCT_NAME)</string>
|
|
||||||
<key>CFBundlePackageType</key>
|
|
||||||
<string>APPL</string>
|
|
||||||
<key>CFBundleShortVersionString</key>
|
|
||||||
<string>1.0</string>
|
|
||||||
<key>CFBundleVersion</key>
|
|
||||||
<string>1</string>
|
|
||||||
<key>LSRequiresIPhoneOS</key>
|
|
||||||
<true/>
|
|
||||||
<key>NSHumanReadableCopyright</key>
|
|
||||||
<string>Copyright © 2026 realizedsound. All rights reserved.</string>
|
|
||||||
<key>NSMicrophoneUsageDescription</key>
|
|
||||||
<string>ShoeGazeiOSDemo can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode.</string>
|
|
||||||
<key>UIApplicationSceneManifest</key>
|
|
||||||
<dict>
|
|
||||||
<key>UIApplicationSupportsMultipleScenes</key>
|
|
||||||
<false/>
|
|
||||||
</dict>
|
|
||||||
<key>UILaunchScreen</key>
|
|
||||||
<dict/>
|
|
||||||
<key>UIRequiresFullScreen</key>
|
|
||||||
<true/>
|
|
||||||
<key>UISupportedInterfaceOrientations</key>
|
|
||||||
<array>
|
|
||||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
|
||||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
|
||||||
</array>
|
|
||||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
|
||||||
<array>
|
|
||||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
|
||||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
|
||||||
</array>
|
|
||||||
</dict>
|
|
||||||
</plist>
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
// ShoeGazeiOSDemoApp.swift
|
|
||||||
// Lyrebird
|
|
||||||
//
|
|
||||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
import SwiftUI
|
|
||||||
import LyrebirdShoeGazeUI
|
|
||||||
|
|
||||||
/// iOS entry point for the ShoeGaze in-repo demo.
|
|
||||||
///
|
|
||||||
/// Holds the `ShoeGazeiOSDemoAppModel` as `@State` so it is created once and
|
|
||||||
/// owned for the lifetime of the app. The audio engine is **not** started
|
|
||||||
/// automatically — the user presses Start in the pedalboard (`ShoeGazeView`) to
|
|
||||||
/// begin audio. The engine is stopped when the view disappears.
|
|
||||||
@main
|
|
||||||
struct ShoeGazeiOSDemoApp: App {
|
|
||||||
|
|
||||||
@State private var model: ShoeGazeiOSDemoAppModel = ShoeGazeiOSDemoAppModel()
|
|
||||||
|
|
||||||
var body: some Scene {
|
|
||||||
WindowGroup {
|
|
||||||
NavigationStack {
|
|
||||||
ScrollView {
|
|
||||||
ShoeGazeView(shoeGaze: model.shoeGaze, hardwareSampleRate: { model.hardwareSampleRate })
|
|
||||||
.padding(.horizontal, 12)
|
|
||||||
}
|
|
||||||
.navigationTitle("ShoeGaze")
|
|
||||||
}
|
|
||||||
.onDisappear { model.stop() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,103 +0,0 @@
|
|||||||
// ShoeGazeiOSDemoAppModel.swift
|
|
||||||
// Lyrebird
|
|
||||||
//
|
|
||||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
||||||
// SPDX-License-Identifier: MIT
|
|
||||||
|
|
||||||
import AVFoundation
|
|
||||||
import Observation
|
|
||||||
import LyrebirdSynth
|
|
||||||
import LyrebirdShoeGaze
|
|
||||||
|
|
||||||
/// Observable model that owns the `SynthesisEngine` and `ShoeGaze` session for
|
|
||||||
/// the ShoeGaze iOS demo.
|
|
||||||
///
|
|
||||||
/// The engine is not started automatically — the pedalboard's Start button
|
|
||||||
/// (`ShoeGazeView`) drives `engine.start()`. `stop()` is called from `.onDisappear`
|
|
||||||
/// to release audio resources when the view goes away.
|
|
||||||
///
|
|
||||||
/// `AVAudioSession` is activated at init so the hardware sample rate is known
|
|
||||||
/// before the engine is constructed — iOS devices typically lock to 48 000 Hz
|
|
||||||
/// regardless of the preferred rate, and querying the session after activation
|
|
||||||
/// avoids pitch and timing errors.
|
|
||||||
///
|
|
||||||
/// The default board (Overdrive → Delay → Reverb → Modulation) uses `.testLoop`
|
|
||||||
/// as the input source, so no microphone permission is required to run the demo.
|
|
||||||
/// Switch to `.liveInput(channel: 0)` and set `numInputChannels: 1` in the
|
|
||||||
/// engine init to route hardware microphone or instrument input through the board.
|
|
||||||
@Observable
|
|
||||||
@MainActor
|
|
||||||
final class ShoeGazeiOSDemoAppModel {
|
|
||||||
|
|
||||||
// MARK: - Engine configuration constants
|
|
||||||
|
|
||||||
private static let blockSize: Int = 512
|
|
||||||
private static let outputChannels: Int = 2
|
|
||||||
private static let numAudioBuses: Int = 256
|
|
||||||
|
|
||||||
// MARK: - Owned objects
|
|
||||||
|
|
||||||
/// The active ShoeGaze pedalboard session.
|
|
||||||
private(set) var shoeGaze: ShoeGaze
|
|
||||||
|
|
||||||
private let engine: SynthesisEngine
|
|
||||||
private let iosDriver: iOSAudioDriver
|
|
||||||
|
|
||||||
/// The sample rate the audio session actually committed to (for the config mismatch warning).
|
|
||||||
var hardwareSampleRate: Double? { iosDriver.sessionSampleRate }
|
|
||||||
|
|
||||||
// MARK: - Init
|
|
||||||
|
|
||||||
init() {
|
|
||||||
// Activate the session before querying `sampleRate` so the hardware rate
|
|
||||||
// is reported correctly (iOS locks to 48 000 Hz on most devices).
|
|
||||||
let session: AVAudioSession = AVAudioSession.sharedInstance()
|
|
||||||
try? session.setCategory(.playAndRecord,
|
|
||||||
mode: .default,
|
|
||||||
options: [.defaultToSpeaker, .allowBluetoothHFP])
|
|
||||||
try? session.setActive(true)
|
|
||||||
let sampleRate: Double = session.sampleRate
|
|
||||||
|
|
||||||
let driver: iOSAudioDriver = iOSAudioDriver()
|
|
||||||
let eng: SynthesisEngine = SynthesisEngine(
|
|
||||||
blockSize: ShoeGazeiOSDemoAppModel.blockSize,
|
|
||||||
sampleRate: sampleRate,
|
|
||||||
numOutputChannels: ShoeGazeiOSDemoAppModel.outputChannels,
|
|
||||||
numInputChannels: 0,
|
|
||||||
numAudioBuses: ShoeGazeiOSDemoAppModel.numAudioBuses,
|
|
||||||
driver: driver
|
|
||||||
)
|
|
||||||
self.iosDriver = driver
|
|
||||||
self.engine = eng
|
|
||||||
self.shoeGaze = ShoeGaze(engine: eng)
|
|
||||||
|
|
||||||
do {
|
|
||||||
let board: PedalBoard = try shoeGaze.addBoard()
|
|
||||||
board.label = "Demo Board"
|
|
||||||
try board.add(OverdrivePedal())
|
|
||||||
try board.add(DelayPedal())
|
|
||||||
try board.add(ReverbPedal())
|
|
||||||
try board.add(ModulationPedal())
|
|
||||||
try shoeGaze.finalizeBoard(board)
|
|
||||||
} catch {
|
|
||||||
print("[ShoeGazeiOSDemo] board build failed: \(error)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Transport
|
|
||||||
|
|
||||||
/// Starts the audio engine. Not called automatically — the pedalboard's Start
|
|
||||||
/// button drives `engine.start()`; this is here for callers that want to start it.
|
|
||||||
func start() {
|
|
||||||
do {
|
|
||||||
try engine.start()
|
|
||||||
} catch {
|
|
||||||
print("[ShoeGazeiOSDemo] engine.start() failed: \(error)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Stops the audio engine. Call from `.onDisappear`.
|
|
||||||
func stop() {
|
|
||||||
engine.stop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"originHash" : "b8327204b102b429067129b94b6ba77dcfa78570af3b9d11cae4d7eb252e388c",
|
"originHash" : "8bbfcc5441e68d57cefd08aed960cbac3875af1e0f8b1d2d3fbdd4dadc0ac18c",
|
||||||
"pins" : [
|
"pins" : [
|
||||||
{
|
{
|
||||||
"identity" : "linenoise-swift",
|
"identity" : "linenoise-swift",
|
||||||
@@ -15,8 +15,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
|
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "032b7c39d351eba4029e8399e1ab1ee201e8bb5c",
|
"revision" : "c058493a9853695c441895a12e9f4a5dbc7295b0",
|
||||||
"version" : "1.2.0"
|
"version" : "1.2.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,8 +11,9 @@
|
|||||||
// double-registration. The dynamic-product dance used by `LiveCompile/` is only
|
// double-registration. The dynamic-product dance used by `LiveCompile/` is only
|
||||||
// required for runtime dylib hot-swap, which ShoeGaze does not do.
|
// required for runtime dylib hot-swap, which ShoeGaze does not do.
|
||||||
//
|
//
|
||||||
// The demo app lives at Demo/ShoeGazeDemo.xcodeproj — open ShoeGaze.xcworkspace
|
// The apps live at Demo/ShoeGazeBuilder.xcodeproj (macOS) and
|
||||||
// in Xcode and run the ShoeGazeDemo scheme to build it.
|
// Demo/ShoeGazeBuilderiOS.xcodeproj (iPad) — open ShoeGaze.xcworkspace in Xcode
|
||||||
|
// and run the matching scheme to build them.
|
||||||
import PackageDescription
|
import PackageDescription
|
||||||
|
|
||||||
let package = Package(
|
let package = Package(
|
||||||
@@ -23,7 +24,7 @@ let package = Package(
|
|||||||
.library(name: "LyrebirdShoeGazeUI", targets: ["LyrebirdShoeGazeUI"]),
|
.library(name: "LyrebirdShoeGazeUI", targets: ["LyrebirdShoeGazeUI"]),
|
||||||
],
|
],
|
||||||
dependencies: [
|
dependencies: [
|
||||||
.package(url: "https://realizedsound.mooo.com/josh/Lyrebird", from: "1.2.0"),
|
.package(url: "https://realizedsound.mooo.com/josh/Lyrebird", from: "1.2.3"),
|
||||||
],
|
],
|
||||||
targets: [
|
targets: [
|
||||||
// The core target depends on LyrebirdUI as well as the synthesis core:
|
// The core target depends on LyrebirdUI as well as the synthesis core:
|
||||||
@@ -51,6 +52,7 @@ let package = Package(
|
|||||||
name: "LyrebirdShoeGazeTests",
|
name: "LyrebirdShoeGazeTests",
|
||||||
dependencies: [
|
dependencies: [
|
||||||
"LyrebirdShoeGaze",
|
"LyrebirdShoeGaze",
|
||||||
|
"LyrebirdShoeGazeUI",
|
||||||
.product(name: "Lyrebird", package: "Lyrebird"),
|
.product(name: "Lyrebird", package: "Lyrebird"),
|
||||||
.product(name: "LyrebirdUI", package: "Lyrebird"),
|
.product(name: "LyrebirdUI", package: "Lyrebird"),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -105,12 +105,11 @@ struct ContentView: View {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Demo apps
|
## Apps
|
||||||
|
|
||||||
Open `ShoeGaze.xcworkspace` in Xcode and run a scheme from `Demo/`:
|
Open `ShoeGaze.xcworkspace` in Xcode and run a scheme from `Demo/`:
|
||||||
|
|
||||||
- **ShoeGazeBuilder** (macOS) / **ShoeGazeBuilderiOS** (iPad) — the full palette + board builder.
|
- **ShoeGazeBuilder** (macOS) / **ShoeGazeBuilderiOS** (iPad) — the full palette + board builder.
|
||||||
- **ShoeGazeDemo** / **ShoeGazeiOSDemo** — a minimal player view.
|
|
||||||
|
|
||||||
## Screenshots
|
## Screenshots
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,88 @@
|
|||||||
# Releases
|
# Releases
|
||||||
|
## ShoeGaze 2.1.0
|
||||||
|
|
||||||
|
Tempo comes to the pedals. Delay times and LFO rates can lock to note divisions of the
|
||||||
|
live tempo — shown with real music-notation glyphs and following the tempo as it
|
||||||
|
changes — plus a directly-editable BPM, longer delays, and per-control MIDI/key mapping
|
||||||
|
badges on every pedal.
|
||||||
|
|
||||||
|
### Highlights
|
||||||
|
- **Tempo-synced parameters** — lock a delay time or a modulation rate to a note value
|
||||||
|
(whole → sixteenth, dotted, triplet); it follows tap tempo, the stepper, the BPM
|
||||||
|
field, and MIDI. Delay, Feedback Delay, Ping-Pong, Reverse, and Multi-Tap (per tap);
|
||||||
|
Tremolo, Vibrato, Chorus, Flanger, Phaser, Modulation.
|
||||||
|
- **Notation glyphs** — the picker draws real note glyphs (augmentation dot for dotted
|
||||||
|
values, a bracketed "3" over triplets) instead of text.
|
||||||
|
- **Editable BPM** — type a tempo directly (integer, 30–300); the stepper and tap still
|
||||||
|
work, and synced pedals follow immediately.
|
||||||
|
- **Longer delays** — maximum delay time raised to 5 s so slow synced values fit.
|
||||||
|
- **Control mapping badges** — every pedal shows the PC (footswitch), CC (expression),
|
||||||
|
or KEY (letter key) binding on each control, with a legend above the board.
|
||||||
|
- **CC respects tempo sync** — a CC bound to a synced parameter is ignored while synced
|
||||||
|
(the tempo drives it) and resumes control once the parameter is set back to Free.
|
||||||
|
|
||||||
|
### Compatibility
|
||||||
|
Additive persistence — older rigs load unchanged (every parameter defaults to free),
|
||||||
|
and 2.1 rigs open in older builds with the tempo-sync state ignored.
|
||||||
|
|
||||||
|
## ShoeGaze 2.0.0
|
||||||
|
|
||||||
|
Major release. Performance-focused: a visual metronome, a real rig mute with
|
||||||
|
keyboard control, and rigs that remember their tempo, input, and I/O — plus a
|
||||||
|
saveable set-list order for hands-free switching between rigs live. The version
|
||||||
|
jumps to 2.0.0 to align ShoeGaze's numbering with the wider project family.
|
||||||
|
|
||||||
|
### Highlights
|
||||||
|
- **Visual metronome** — a horizontal playhead eases wall-to-wall each beat so you
|
||||||
|
can anticipate the downbeat, replacing the old flashing LED.
|
||||||
|
- **Rig Mute (⌘Z)** — hard-silences the whole rig; distinct from Bypass Rig (dry passthrough).
|
||||||
|
- **Keyboard shortcuts** — ⌘1–⌘9 switch/solo boards, ⌘⇧1–⌘⇧0 load set-list rigs 1–10,
|
||||||
|
⌘Z mutes. macOS menus + iOS/iPadOS hardware keyboards.
|
||||||
|
- **Set lists** — reorder rigs by drag or Move Up/Down; the order saves, travels with
|
||||||
|
an exported archive, and drives the ⌘⇧ slots.
|
||||||
|
- **Per-rig memory** — tempo, input selection, and engine I/O now persist with a rig.
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- Archive import no longer collides set-list positions with existing rigs.
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
- The ShoeGazeDemo / ShoeGazeiOSDemo apps — only the ShoeGazeBuilder (macOS) and
|
||||||
|
ShoeGazeBuilderiOS (iPad) apps remain.
|
||||||
|
|
||||||
|
**Compatibility:** rig persistence is additive — older rigs load unchanged, and 2.0.0
|
||||||
|
rigs still open in older builds. The bump reflects feature scope + version alignment,
|
||||||
|
not a format break.
|
||||||
|
|
||||||
|
## 1.5.0 — 2026-07-04
|
||||||
|
|
||||||
|
### New Looper pedal (catalog now 36)
|
||||||
|
- **Multitrack looper** with a smart Loop footswitch (record → overdub → play), up to four
|
||||||
|
tracks (A/B/C/D), per-track mute via the track dots, undo, reverse, and a timeline view.
|
||||||
|
- **Beat-quantized transport** with a **Sync / Free** mode toggle; stop and cue-stop honour the
|
||||||
|
loop boundary in Sync. Clean-through and a Playback balance let the dry signal pass while
|
||||||
|
looped layers play back.
|
||||||
|
- **MIDI-mappable** transport (record/play/stop), per-track A/B/C/D taps, and the Sync toggle.
|
||||||
|
- Stomp-style **Reset** button that also fires on engine stop and rig teardown; `effect()` is
|
||||||
|
idempotent across graph rebuilds, and the multitrack engine is RT-safe (findings from review
|
||||||
|
addressed, with regression coverage for record-after-reset).
|
||||||
|
|
||||||
|
### iPad / iOS layout rework
|
||||||
|
- **Canvas-first compact layout** — composition panels move into sheets so the pedal canvas
|
||||||
|
fills the screen; the sheet-based layout is now used at every size class (no forced min width).
|
||||||
|
- **Header compaction** — performance controls sit inline right of the title; rig controls group
|
||||||
|
with Tempo/Tuner; the scope drops to a full-width strip below the rows in portrait. Fixes
|
||||||
|
Tempo/Tuner truncation, Mute-toggle expansion, mixer overflow into the CPU meters, and portrait
|
||||||
|
clipping/centering.
|
||||||
|
- **Add-Pedal sheet** is a scrollable list with a fixed header and type filter at a stable size;
|
||||||
|
fixed compact sheets that failed to present (one sheet per view node).
|
||||||
|
|
||||||
|
### Dependency
|
||||||
|
- Bumped to **Lyrebird 1.2.3**. Lyrebird now ships framework-neutral project templates only —
|
||||||
|
its ShoeGaze-specific CLI scaffolding was removed, since ShoeGaze lives in this standalone repo.
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
- A transport-only **Start** no longer reverts Settings configuration (external-review fix).
|
||||||
|
- Dropped a stale doc and a dead `looperTimeline` property.
|
||||||
|
|
||||||
## 1.4.0 — 2026-07-01
|
## 1.4.0 — 2026-07-01
|
||||||
|
|
||||||
|
|||||||
@@ -4,12 +4,6 @@
|
|||||||
<FileRef
|
<FileRef
|
||||||
location = "group:.">
|
location = "group:.">
|
||||||
</FileRef>
|
</FileRef>
|
||||||
<FileRef
|
|
||||||
location = "group:Demo/ShoeGazeDemo.xcodeproj">
|
|
||||||
</FileRef>
|
|
||||||
<FileRef
|
|
||||||
location = "group:Demo/ShoeGazeiOSDemo.xcodeproj">
|
|
||||||
</FileRef>
|
|
||||||
<FileRef
|
<FileRef
|
||||||
location = "group:Demo/ShoeGazeBuilder.xcodeproj">
|
location = "group:Demo/ShoeGazeBuilder.xcodeproj">
|
||||||
</FileRef>
|
</FileRef>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"originHash" : "bf2bd285202c1d5cb51cc77815e3eb9675170cb3bef2db60c355d2222c555750",
|
"originHash" : "39c6a5f1535f779ef8a83b5ea2ab6f965ee3b28ad8419b94679e422a92f75603",
|
||||||
"pins" : [
|
"pins" : [
|
||||||
{
|
{
|
||||||
"identity" : "linenoise-swift",
|
"identity" : "linenoise-swift",
|
||||||
@@ -15,8 +15,8 @@
|
|||||||
"kind" : "remoteSourceControl",
|
"kind" : "remoteSourceControl",
|
||||||
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
|
"location" : "https://realizedsound.mooo.com/josh/Lyrebird",
|
||||||
"state" : {
|
"state" : {
|
||||||
"revision" : "032b7c39d351eba4029e8399e1ab1ee201e8bb5c",
|
"revision" : "c058493a9853695c441895a12e9f4a5dbc7295b0",
|
||||||
"version" : "1.2.0"
|
"version" : "1.2.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,6 +22,46 @@ public enum InputSource: Equatable {
|
|||||||
case liveInput(channel: Int)
|
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
|
/// Validates a `.liveInput` channel against the engine and returns the engine audio-bus
|
||||||
/// index of that hardware input channel.
|
/// index of that hardware input channel.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -0,0 +1,153 @@
|
|||||||
|
// LegacyMIDIMap.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
/// Decoder for the **pre-UUID** `MIDIMap` format, which addressed pedals and boards by chain
|
||||||
|
/// position (`boardIndex` / `pedalIndex`) rather than by stable id.
|
||||||
|
///
|
||||||
|
/// Used only on load: `ShoeGazeState.init(from:)` tries the current id-based `MIDIMap` first and,
|
||||||
|
/// if that fails, decodes this legacy shape and calls ``migrated(boards:)`` to convert each
|
||||||
|
/// positional binding to the id of the pedal/board now sitting at that position. Because the saved
|
||||||
|
/// positions are stable, this reconstructs correct id-bindings on every load — even though the ids
|
||||||
|
/// themselves are freshly assigned to a legacy rig each time it is decoded.
|
||||||
|
///
|
||||||
|
/// Bindings whose indices fall outside the loaded rig are dropped.
|
||||||
|
struct LegacyMIDIMap: Codable {
|
||||||
|
|
||||||
|
var switches: [LegacySwitchBinding]
|
||||||
|
var ccs: [LegacyCCBinding]
|
||||||
|
|
||||||
|
enum LegacyAction: Codable {
|
||||||
|
case rigBypass
|
||||||
|
case rigMute
|
||||||
|
case allBoards
|
||||||
|
case boardSolo(boardIndex: Int)
|
||||||
|
case boardAudible(boardIndex: Int)
|
||||||
|
case boardBypass(boardIndex: Int)
|
||||||
|
case pedalBypass(boardIndex: Int, pedalIndex: Int)
|
||||||
|
case pedalAction(boardIndex: Int, pedalIndex: Int, kind: MIDIMap.PedalActionKind)
|
||||||
|
case tunerToggle
|
||||||
|
case tapTempo
|
||||||
|
}
|
||||||
|
|
||||||
|
enum LegacyCCTarget: Codable {
|
||||||
|
case pedalControl(
|
||||||
|
boardIndex: Int,
|
||||||
|
pedalIndex: Int,
|
||||||
|
controlIndex: Int,
|
||||||
|
pedalNameHint: String?,
|
||||||
|
controlLabelHint: String?
|
||||||
|
)
|
||||||
|
case boardLevel(boardIndex: Int, boardLabelHint: String?)
|
||||||
|
case rigVolume
|
||||||
|
}
|
||||||
|
|
||||||
|
struct LegacySwitchBinding: Codable {
|
||||||
|
var program: UInt8
|
||||||
|
var channel: UInt8?
|
||||||
|
var action: LegacyAction
|
||||||
|
var displayNameHint: String?
|
||||||
|
}
|
||||||
|
|
||||||
|
struct LegacyCCBinding: Codable {
|
||||||
|
var controller: UInt8
|
||||||
|
var channel: UInt8?
|
||||||
|
var target: LegacyCCTarget
|
||||||
|
var inverted: Bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Migration
|
||||||
|
|
||||||
|
/// Converts this positional map to the current id-based ``MIDIMap`` using the ids of the pedals
|
||||||
|
/// and boards in `boards` (whose ids were freshly assigned when the rig was decoded). Bindings
|
||||||
|
/// addressing an out-of-range board/pedal are dropped.
|
||||||
|
func migrated(boards: [BoardState]) -> MIDIMap {
|
||||||
|
func boardID(_ index: Int) -> UUID? {
|
||||||
|
guard index >= 0, index < boards.count else { return nil }
|
||||||
|
return boards[index].id
|
||||||
|
}
|
||||||
|
func pedalID(_ boardIndex: Int, _ pedalIndex: Int) -> UUID? {
|
||||||
|
guard boardIndex >= 0, boardIndex < boards.count else { return nil }
|
||||||
|
let pedals: [PedalState] = boards[boardIndex].pedals
|
||||||
|
guard pedalIndex >= 0, pedalIndex < pedals.count else { return nil }
|
||||||
|
return pedals[pedalIndex].id
|
||||||
|
}
|
||||||
|
|
||||||
|
let migratedSwitches: [MIDIMap.SwitchBinding] = switches.compactMap { binding in
|
||||||
|
guard let action: MIDIMap.Action = migrate(binding.action, boardID: boardID, pedalID: pedalID) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return MIDIMap.SwitchBinding(
|
||||||
|
program: binding.program,
|
||||||
|
channel: binding.channel,
|
||||||
|
action: action,
|
||||||
|
displayNameHint: binding.displayNameHint
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
let migratedCCs: [MIDIMap.CCBinding] = ccs.compactMap { binding in
|
||||||
|
guard let target: MIDIMap.CCTarget = migrate(binding.target, boardID: boardID, pedalID: pedalID) else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return MIDIMap.CCBinding(
|
||||||
|
controller: binding.controller,
|
||||||
|
channel: binding.channel,
|
||||||
|
target: target,
|
||||||
|
inverted: binding.inverted
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return MIDIMap(switches: migratedSwitches, ccs: migratedCCs)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func migrate(
|
||||||
|
_ action: LegacyAction,
|
||||||
|
boardID: (Int) -> UUID?,
|
||||||
|
pedalID: (Int, Int) -> UUID?
|
||||||
|
) -> MIDIMap.Action? {
|
||||||
|
switch action {
|
||||||
|
case .rigBypass: return .rigBypass
|
||||||
|
case .rigMute: return .rigMute
|
||||||
|
case .allBoards: return .allBoards
|
||||||
|
case .tunerToggle: return .tunerToggle
|
||||||
|
case .tapTempo: return .tapTempo
|
||||||
|
case .boardSolo(let b):
|
||||||
|
guard let id: UUID = boardID(b) else { return nil }
|
||||||
|
return .boardSolo(boardID: id)
|
||||||
|
case .boardAudible(let b):
|
||||||
|
guard let id: UUID = boardID(b) else { return nil }
|
||||||
|
return .boardAudible(boardID: id)
|
||||||
|
case .boardBypass(let b):
|
||||||
|
guard let id: UUID = boardID(b) else { return nil }
|
||||||
|
return .boardBypass(boardID: id)
|
||||||
|
case .pedalBypass(let b, let p):
|
||||||
|
guard let id: UUID = pedalID(b, p) else { return nil }
|
||||||
|
return .pedalBypass(pedalID: id)
|
||||||
|
case .pedalAction(let b, let p, let kind):
|
||||||
|
guard let id: UUID = pedalID(b, p) else { return nil }
|
||||||
|
return .pedalAction(pedalID: id, kind: kind)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func migrate(
|
||||||
|
_ target: LegacyCCTarget,
|
||||||
|
boardID: (Int) -> UUID?,
|
||||||
|
pedalID: (Int, Int) -> UUID?
|
||||||
|
) -> MIDIMap.CCTarget? {
|
||||||
|
switch target {
|
||||||
|
case .rigVolume:
|
||||||
|
return .rigVolume
|
||||||
|
case .pedalControl(let b, let p, let controlIndex, let nameHint, let labelHint):
|
||||||
|
guard let id: UUID = pedalID(b, p) else { return nil }
|
||||||
|
return .pedalControl(pedalID: id, controlIndex: controlIndex,
|
||||||
|
pedalNameHint: nameHint, controlLabelHint: labelHint)
|
||||||
|
case .boardLevel(let b, let labelHint):
|
||||||
|
guard let id: UUID = boardID(b) else { return nil }
|
||||||
|
return .boardLevel(boardID: id, boardLabelHint: labelHint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,6 +38,8 @@ public final class MIDIController {
|
|||||||
case cc(MIDIMap.CCTarget)
|
case cc(MIDIMap.CCTarget)
|
||||||
/// A toggle action awaiting a Program Change.
|
/// A toggle action awaiting a Program Change.
|
||||||
case action(MIDIMap.Action)
|
case action(MIDIMap.Action)
|
||||||
|
/// A toggle action awaiting a computer key press.
|
||||||
|
case key(MIDIMap.Action)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The control currently armed for Learn, or `nil` when not learning. Observable so the UI can
|
/// The control currently armed for Learn, or `nil` when not learning. Observable so the UI can
|
||||||
@@ -248,6 +250,14 @@ public final class MIDIController {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
guard let resolved: ResolvedCC = resolveCC(binding.target) else { continue }
|
guard let resolved: ResolvedCC = resolveCC(binding.target) else { continue }
|
||||||
|
// A parameter locked to a note division is driven by the tempo; a CC write would be
|
||||||
|
// overwritten on the next tempo change, so ignore it here. The binding stays intact and
|
||||||
|
// resumes control the moment the parameter is set back to Free.
|
||||||
|
if case let .pedalControl(pedalID, _, _, _) = binding.target,
|
||||||
|
let pedal: Pedal = pedal(id: pedalID),
|
||||||
|
pedal.isNodeTempoSynced(resolved.node) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
let mapped: Double = resolved.range.lowerBound
|
let mapped: Double = resolved.range.lowerBound
|
||||||
+ norm * (resolved.range.upperBound - resolved.range.lowerBound)
|
+ norm * (resolved.range.upperBound - resolved.range.lowerBound)
|
||||||
resolved.node.update(mapped)
|
resolved.node.update(mapped)
|
||||||
@@ -266,26 +276,22 @@ public final class MIDIController {
|
|||||||
/// address is out of range or a captured display-name hint no longer matches (stale binding).
|
/// address is out of range or a captured display-name hint no longer matches (stale binding).
|
||||||
private func resolveCC(_ target: MIDIMap.CCTarget) -> ResolvedCC? {
|
private func resolveCC(_ target: MIDIMap.CCTarget) -> ResolvedCC? {
|
||||||
switch target {
|
switch target {
|
||||||
case let .pedalControl(boardIndex, pedalIndex, controlIndex, nameHint, labelHint):
|
case let .pedalControl(pedalID, controlIndex, _, _):
|
||||||
guard let pedal: Pedal = pedal(boardIndex: boardIndex, pedalIndex: pedalIndex) else { return nil }
|
guard let pedal: Pedal = pedal(id: pedalID) else { return nil }
|
||||||
let controls: [PedalControl] = pedal.ccMappableControls
|
let controls: [PedalControl] = pedal.ccMappableControls
|
||||||
guard controlIndex >= 0, controlIndex < controls.count else { return nil }
|
guard controlIndex >= 0, controlIndex < controls.count else { return nil }
|
||||||
let control: PedalControl = controls[controlIndex]
|
let control: PedalControl = controls[controlIndex]
|
||||||
if let nameHint: String = nameHint, nameHint != pedal.displayName { return nil }
|
|
||||||
if let labelHint: String = labelHint, labelHint != control.label { return nil }
|
|
||||||
let hinted: MIDIMap.CCTarget = .pedalControl(
|
let hinted: MIDIMap.CCTarget = .pedalControl(
|
||||||
boardIndex: boardIndex,
|
pedalID: pedalID,
|
||||||
pedalIndex: pedalIndex,
|
|
||||||
controlIndex: controlIndex,
|
controlIndex: controlIndex,
|
||||||
pedalNameHint: pedal.displayName,
|
pedalNameHint: pedal.displayName,
|
||||||
controlLabelHint: control.label
|
controlLabelHint: control.label
|
||||||
)
|
)
|
||||||
return ResolvedCC(node: control.node, range: control.range, hinted: hinted)
|
return ResolvedCC(node: control.node, range: control.range, hinted: hinted)
|
||||||
case let .boardLevel(boardIndex, labelHint):
|
case let .boardLevel(boardID, _):
|
||||||
guard let board: PedalBoard = board(at: boardIndex),
|
guard let board: PedalBoard = board(id: boardID),
|
||||||
let node: UIParamNode = board.masterGainNode else { return nil }
|
let node: UIParamNode = board.masterGainNode else { return nil }
|
||||||
if let labelHint: String = labelHint, labelHint != board.label { return nil }
|
let hinted: MIDIMap.CCTarget = .boardLevel(boardID: boardID, boardLabelHint: board.label)
|
||||||
let hinted: MIDIMap.CCTarget = .boardLevel(boardIndex: boardIndex, boardLabelHint: board.label)
|
|
||||||
return ResolvedCC(node: node, range: boardLevelRange, hinted: hinted)
|
return ResolvedCC(node: node, range: boardLevelRange, hinted: hinted)
|
||||||
case .rigVolume:
|
case .rigVolume:
|
||||||
// Applied via `ShoeGaze.setRigVolume` (fans out to every board), not a single node.
|
// Applied via `ShoeGaze.setRigVolume` (fans out to every board), not a single node.
|
||||||
@@ -340,14 +346,14 @@ public final class MIDIController {
|
|||||||
guard let shoeGaze: ShoeGaze = shoeGaze, let map: MIDIMap = shoeGaze.midiMap else { return }
|
guard let shoeGaze: ShoeGaze = shoeGaze, let map: MIDIMap = shoeGaze.midiMap else { return }
|
||||||
for binding: MIDIMap.SwitchBinding in map.switches where binding.program == program {
|
for binding: MIDIMap.SwitchBinding in map.switches where binding.program == program {
|
||||||
if let boundChannel: UInt8 = binding.channel, boundChannel != channel { continue }
|
if let boundChannel: UInt8 = binding.channel, boundChannel != channel { continue }
|
||||||
perform(binding.action, hint: binding.displayNameHint)
|
perform(binding.action)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executes a toggle action by reading the live rig state and flipping it. Boolean actions latch;
|
/// Executes a toggle action by reading the live rig state and flipping it. Boolean actions latch;
|
||||||
/// `boardSolo` is exclusive (radio). Stale bindings (chain edited under the positional address)
|
/// `boardSolo` is exclusive (radio). Pedals/boards resolve by UUID, so a binding whose target no
|
||||||
/// are skipped via bounds + display-name checks.
|
/// longer exists (removed pedal/board) simply no-ops.
|
||||||
private func perform(_ action: MIDIMap.Action, hint: String?) {
|
private func perform(_ action: MIDIMap.Action) {
|
||||||
guard let shoeGaze: ShoeGaze = shoeGaze else { return }
|
guard let shoeGaze: ShoeGaze = shoeGaze else { return }
|
||||||
switch action {
|
switch action {
|
||||||
case .rigBypass:
|
case .rigBypass:
|
||||||
@@ -357,58 +363,172 @@ public final class MIDIController {
|
|||||||
case .allBoards:
|
case .allBoards:
|
||||||
// One-shot: cancel any solo and bring every board back up.
|
// One-shot: cancel any solo and bring every board back up.
|
||||||
shoeGaze.selectAllBoards(crossfadeSeconds: boardActionCrossfade)
|
shoeGaze.selectAllBoards(crossfadeSeconds: boardActionCrossfade)
|
||||||
case .boardSolo(let boardIndex):
|
case .boardSolo(let boardID):
|
||||||
guard let board: PedalBoard = board(at: boardIndex), matchesBoard(board, hint) else { return }
|
guard let board: PedalBoard = board(id: boardID) else { return }
|
||||||
shoeGaze.soloBoard(board, crossfadeSeconds: boardActionCrossfade)
|
shoeGaze.soloBoard(board, crossfadeSeconds: boardActionCrossfade)
|
||||||
case .boardAudible(let boardIndex):
|
case .boardAudible(let boardID):
|
||||||
guard let board: PedalBoard = board(at: boardIndex), matchesBoard(board, hint) else { return }
|
guard let board: PedalBoard = board(id: boardID) else { return }
|
||||||
shoeGaze.setBoard(board, audible: !shoeGaze.isBoardAudible(board),
|
shoeGaze.setBoard(board, audible: !shoeGaze.isBoardAudible(board),
|
||||||
crossfadeSeconds: boardActionCrossfade)
|
crossfadeSeconds: boardActionCrossfade)
|
||||||
case .boardBypass(let boardIndex):
|
case .boardBypass(let boardID):
|
||||||
guard let board: PedalBoard = board(at: boardIndex), matchesBoard(board, hint) else { return }
|
guard let board: PedalBoard = board(id: boardID) else { return }
|
||||||
shoeGaze.setBoard(board, bypassed: !shoeGaze.isBoardBypassed(board))
|
shoeGaze.setBoard(board, bypassed: !shoeGaze.isBoardBypassed(board))
|
||||||
case .pedalBypass(let boardIndex, let pedalIndex):
|
case .pedalBypass(let pedalID):
|
||||||
guard let pedal: Pedal = pedal(boardIndex: boardIndex, pedalIndex: pedalIndex) else { return }
|
guard let pedal: Pedal = pedal(id: pedalID) else { return }
|
||||||
if let hint: String = hint, hint != pedal.displayName { return }
|
|
||||||
let engagedThreshold: Double = 0.5
|
let engagedThreshold: Double = 0.5
|
||||||
let node: UIParamNode = pedal.$bypass
|
let node: UIParamNode = pedal.$bypass
|
||||||
node.update(node.value < engagedThreshold ? 1.0 : 0.0)
|
node.update(node.value < engagedThreshold ? 1.0 : 0.0)
|
||||||
|
case .pedalAction(let pedalID, let kind):
|
||||||
|
guard let pedal: Pedal = pedal(id: pedalID) else { return }
|
||||||
|
performPedalAction(kind, on: pedal)
|
||||||
|
case .tunerToggle:
|
||||||
|
shoeGaze.toggleTunerEngaged()
|
||||||
|
case .tapTempo:
|
||||||
|
shoeGaze.tapTempo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A display-name hint for an action, captured at learn time for stale-binding detection.
|
/// Dispatches a pedal-specific momentary action. New `PedalActionKind` cases add a
|
||||||
|
/// branch here once the pedal type they target exists.
|
||||||
|
private func performPedalAction(_ kind: MIDIMap.PedalActionKind, on pedal: Pedal) {
|
||||||
|
let toggleThreshold: Double = 0.5
|
||||||
|
switch kind {
|
||||||
|
case .looperRecordStop:
|
||||||
|
// The smart Loop footswitch drives record / set-end / overdub / play by state.
|
||||||
|
(pedal as? LooperPedal)?.pressLoop()
|
||||||
|
case .looperOverdubToggle:
|
||||||
|
// Overdub is toggled by the same Loop press once a loop is playing.
|
||||||
|
(pedal as? LooperPedal)?.pressLoop()
|
||||||
|
case .looperLoopToggle:
|
||||||
|
guard let looper: LooperPedal = pedal as? LooperPedal else { return }
|
||||||
|
let node: UIParamNode = looper.$loopOn
|
||||||
|
node.update(node.value < toggleThreshold ? 1.0 : 0.0)
|
||||||
|
case .looperReset:
|
||||||
|
(pedal as? LooperPedal)?.resetLoop()
|
||||||
|
case .looperStop:
|
||||||
|
(pedal as? LooperPedal)?.stopPlayback()
|
||||||
|
case .looperCueStop:
|
||||||
|
(pedal as? LooperPedal)?.toggleStopAtLoopEnd()
|
||||||
|
case .looperReverse:
|
||||||
|
(pedal as? LooperPedal)?.toggleReverse()
|
||||||
|
case .looperSyncToggle:
|
||||||
|
(pedal as? LooperPedal)?.cycleSyncMode()
|
||||||
|
case .looperTrack(let index):
|
||||||
|
(pedal as? LooperPedal)?.tapTrack(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A display-name hint for an action, captured at learn time for the mapping-sheet UI label.
|
||||||
|
/// Not used for resolution (bindings resolve by UUID) — purely a human-readable snapshot.
|
||||||
private func hint(for action: MIDIMap.Action) -> String? {
|
private func hint(for action: MIDIMap.Action) -> String? {
|
||||||
switch action {
|
switch action {
|
||||||
case .rigBypass, .rigMute, .allBoards:
|
case .rigBypass, .rigMute, .allBoards:
|
||||||
return nil
|
return nil
|
||||||
case .boardSolo(let index), .boardAudible(let index), .boardBypass(let index):
|
case .boardSolo(let boardID), .boardAudible(let boardID), .boardBypass(let boardID):
|
||||||
return board(at: index)?.label
|
return board(id: boardID)?.label
|
||||||
case .pedalBypass(let boardIndex, let pedalIndex):
|
case .pedalBypass(let pedalID), .pedalAction(let pedalID, _):
|
||||||
return pedal(boardIndex: boardIndex, pedalIndex: pedalIndex)?.displayName
|
return pedal(id: pedalID)?.displayName
|
||||||
}
|
case .tunerToggle, .tapTempo:
|
||||||
}
|
|
||||||
|
|
||||||
/// `true` when a board still matches its captured hint (or no hint was captured).
|
|
||||||
private func matchesBoard(_ board: PedalBoard, _ hint: String?) -> Bool {
|
|
||||||
guard let hint: String = hint else { return true }
|
|
||||||
return board.label == hint
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Resolves a board by index, or `nil` if out of range.
|
|
||||||
private func board(at index: Int) -> PedalBoard? {
|
|
||||||
guard let shoeGaze: ShoeGaze = shoeGaze, index >= 0, index < shoeGaze.boards.count else {
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return shoeGaze.boards[index]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolves a pedal by board + pedal index, or `nil` if either index is out of range.
|
/// Resolves a board by its stable id, or `nil` if no board in the rig has that id.
|
||||||
private func pedal(boardIndex: Int, pedalIndex: Int) -> Pedal? {
|
private func board(id: UUID) -> PedalBoard? {
|
||||||
guard let shoeGaze: ShoeGaze = shoeGaze,
|
shoeGaze?.boards.first { $0.id == id }
|
||||||
boardIndex >= 0, boardIndex < shoeGaze.boards.count else { return nil }
|
}
|
||||||
let board: PedalBoard = shoeGaze.boards[boardIndex]
|
|
||||||
guard pedalIndex >= 0, pedalIndex < board.pedals.count else { return nil }
|
/// Resolves a pedal by its stable id across all boards' linear pedal chains, or `nil` if no
|
||||||
return board.pedals[pedalIndex]
|
/// pedal in the rig has that id.
|
||||||
|
private func pedal(id: UUID) -> Pedal? {
|
||||||
|
guard let shoeGaze: ShoeGaze = shoeGaze else { return nil }
|
||||||
|
for board: PedalBoard in shoeGaze.boards {
|
||||||
|
if let match: Pedal = board.pedals.first(where: { $0.id == id }) { return match }
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Key learn + apply
|
||||||
|
|
||||||
|
/// Arms MIDI Learn for a toggle action awaiting a key: the next ingested key press binds to it.
|
||||||
|
public func armKeyLearn(_ action: MIDIMap.Action) {
|
||||||
|
learnTarget = .key(action)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The key binding currently assigned to an action, or `nil` if unbound.
|
||||||
|
public func keyBinding(for action: MIDIMap.Action) -> MIDIMap.KeyBinding? {
|
||||||
|
shoeGaze?.midiMap?.keys.first { $0.action == action }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes any key binding assigned to an action.
|
||||||
|
public func clearKeyBinding(for action: MIDIMap.Action) {
|
||||||
|
guard let shoeGaze: ShoeGaze = shoeGaze, var map: MIDIMap = shoeGaze.midiMap else { return }
|
||||||
|
let before: Int = map.keys.count
|
||||||
|
map.keys.removeAll { $0.action == action }
|
||||||
|
guard map.keys.count != before else { return }
|
||||||
|
shoeGaze.midiMap = map
|
||||||
|
onMapChanged?()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Normalizes a raw key string to the single lowercased character used for storage and matching,
|
||||||
|
/// or `nil` when the input is not exactly one letter or digit. Restricting to alphanumerics keeps
|
||||||
|
/// non-printing keys (Return, Tab, Escape, arrows — all single `Character`s) from being learned
|
||||||
|
/// and then silently swallowed app-wide.
|
||||||
|
private func normalizedKey(_ raw: String) -> String? {
|
||||||
|
let lowered: String = raw.lowercased()
|
||||||
|
guard lowered.count == 1, let character: Character = lowered.first, character.isASCII,
|
||||||
|
character.isLetter || character.isNumber else { return nil }
|
||||||
|
return lowered
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Routes a computer key press: captures a binding when armed for key Learn, otherwise performs
|
||||||
|
/// every action bound to that key + modifier combination. Returns `true` when the press was
|
||||||
|
/// consumed (learned or matched a binding) so the caller can swallow the event; `false` lets it
|
||||||
|
/// fall through.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - rawKey: The pressed key; normalized to a single lowercased character.
|
||||||
|
/// - modifiers: The modifier keys held with the press. `a` and `⇧a` bind independently.
|
||||||
|
@discardableResult
|
||||||
|
public func ingestKey(_ rawKey: String, modifiers: MIDIMap.KeyModifiers = []) -> Bool {
|
||||||
|
guard let key: String = normalizedKey(rawKey) else { return false }
|
||||||
|
if case .key(let action) = learnTarget {
|
||||||
|
captureKey(key: key, modifiers: modifiers, action: action)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return applyKey(key, modifiers: modifiers)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Captures a learned key binding for the armed action and clears the Learn state. One binding
|
||||||
|
/// per action — re-learning replaces it — but a single key may drive multiple actions (a scene),
|
||||||
|
/// so we do not steal by key.
|
||||||
|
private func captureKey(key: String, modifiers: MIDIMap.KeyModifiers, action: MIDIMap.Action) {
|
||||||
|
learnTarget = nil
|
||||||
|
guard let shoeGaze: ShoeGaze = shoeGaze else { return }
|
||||||
|
let binding: MIDIMap.KeyBinding = MIDIMap.KeyBinding(
|
||||||
|
key: key,
|
||||||
|
modifiers: modifiers,
|
||||||
|
action: action,
|
||||||
|
displayNameHint: hint(for: action)
|
||||||
|
)
|
||||||
|
var map: MIDIMap = shoeGaze.midiMap ?? MIDIMap.empty
|
||||||
|
map.keys.removeAll { $0.action == action }
|
||||||
|
map.keys.append(binding)
|
||||||
|
shoeGaze.midiMap = map
|
||||||
|
onMapChanged?()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Performs every action bound to a key + modifier combination. Returns `true` when at least one
|
||||||
|
/// binding matched (key and modifiers both equal).
|
||||||
|
private func applyKey(_ key: String, modifiers: MIDIMap.KeyModifiers) -> Bool {
|
||||||
|
guard let shoeGaze: ShoeGaze = shoeGaze, let map: MIDIMap = shoeGaze.midiMap else { return false }
|
||||||
|
var matched: Bool = false
|
||||||
|
for binding: MIDIMap.KeyBinding in map.keys
|
||||||
|
where binding.key == key && binding.modifiers == modifiers {
|
||||||
|
perform(binding.action)
|
||||||
|
matched = true
|
||||||
|
}
|
||||||
|
return matched
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Device detection
|
// MARK: - Device detection
|
||||||
|
|||||||
@@ -4,13 +4,18 @@
|
|||||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
/// A per-rig map of MIDI foot-controller bindings — which Program Change toggles which control, and
|
/// A per-rig map of MIDI foot-controller bindings — which Program Change toggles which control, and
|
||||||
/// which Control Change drives which pedal knob.
|
/// which Control Change drives which pedal knob.
|
||||||
///
|
///
|
||||||
/// Stored inside the rig (embedded in `ShoeGazeState`) so it travels with a saved rig. Controls are
|
/// Stored inside the rig (embedded in `ShoeGazeState`) so it travels with a saved rig. Pedals and
|
||||||
/// addressed **positionally** (board index, pedal index, knob index) since boards and pedals have no
|
/// boards are addressed by **stable UUID** (`Pedal.id` / `PedalBoard.id`, persisted in
|
||||||
/// stable identity; the `*Hint` fields carry the resolved display name at learn time so a binding
|
/// `PedalState`/`BoardState`), so a binding follows its pedal/board through insert, remove, move,
|
||||||
/// that no longer matches (chain edited) can be detected and skipped rather than mis-fire.
|
/// and reorder edits with no reindexing — the id survives the capture → rebuild round-trip. A
|
||||||
|
/// binding whose target no longer exists simply stops resolving (inert). The `*Hint` fields carry
|
||||||
|
/// the display name at learn time, for UI labels only (not resolution). Control-within-pedal is
|
||||||
|
/// still indexed into `Pedal.ccMappableControls`, which is stable for a given pedal type.
|
||||||
public struct MIDIMap: Codable, Equatable, Sendable {
|
public struct MIDIMap: Codable, Equatable, Sendable {
|
||||||
|
|
||||||
/// Program-Change → action bindings (footswitch toggles). Populated in the switch phase.
|
/// Program-Change → action bindings (footswitch toggles). Populated in the switch phase.
|
||||||
@@ -19,6 +24,10 @@ public struct MIDIMap: Codable, Equatable, Sendable {
|
|||||||
/// Control-Change → pedal-knob bindings (expression pedals).
|
/// Control-Change → pedal-knob bindings (expression pedals).
|
||||||
public var ccs: [CCBinding]
|
public var ccs: [CCBinding]
|
||||||
|
|
||||||
|
/// Computer letter/digit key → action bindings. Same toggle ``Action`` set as ``switches`` —
|
||||||
|
/// a key press is a software footswitch — but keys never drive continuous CC targets.
|
||||||
|
public var keys: [KeyBinding]
|
||||||
|
|
||||||
/// An empty map (no bindings).
|
/// An empty map (no bindings).
|
||||||
public static let empty: MIDIMap = MIDIMap()
|
public static let empty: MIDIMap = MIDIMap()
|
||||||
|
|
||||||
@@ -27,12 +36,32 @@ public struct MIDIMap: Codable, Equatable, Sendable {
|
|||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - switches: Program-Change bindings. Defaults to empty.
|
/// - switches: Program-Change bindings. Defaults to empty.
|
||||||
/// - ccs: Control-Change bindings. Defaults to empty.
|
/// - ccs: Control-Change bindings. Defaults to empty.
|
||||||
|
/// - keys: Letter-key bindings. Defaults to empty.
|
||||||
public init(
|
public init(
|
||||||
switches: [SwitchBinding] = [],
|
switches: [SwitchBinding] = [],
|
||||||
ccs: [CCBinding] = []
|
ccs: [CCBinding] = [],
|
||||||
|
keys: [KeyBinding] = []
|
||||||
) {
|
) {
|
||||||
self.switches = switches
|
self.switches = switches
|
||||||
self.ccs = ccs
|
self.ccs = ccs
|
||||||
|
self.keys = keys
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case switches
|
||||||
|
case ccs
|
||||||
|
case keys
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Decodes a map, tolerating an absent `keys` list so a rig saved before keyboard mapping
|
||||||
|
/// existed still decodes with its `switches` / `ccs` intact (synthesized Codable would fail
|
||||||
|
/// the whole map on the missing key, silently dropping the MIDI bindings too). `encode(to:)`
|
||||||
|
/// stays synthesized and always writes `keys` (empty when there are none).
|
||||||
|
public init(from decoder: Decoder) throws {
|
||||||
|
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
self.switches = try container.decode([SwitchBinding].self, forKey: .switches)
|
||||||
|
self.ccs = try container.decode([CCBinding].self, forKey: .ccs)
|
||||||
|
self.keys = try container.decodeIfPresent([KeyBinding].self, forKey: .keys) ?? []
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Action
|
// MARK: - Action
|
||||||
@@ -45,10 +74,44 @@ public struct MIDIMap: Codable, Equatable, Sendable {
|
|||||||
case rigMute
|
case rigMute
|
||||||
/// Cancels any solo and makes every board audible again (the "All" button).
|
/// Cancels any solo and makes every board audible again (the "All" button).
|
||||||
case allBoards
|
case allBoards
|
||||||
case boardSolo(boardIndex: Int)
|
case boardSolo(boardID: UUID)
|
||||||
case boardAudible(boardIndex: Int)
|
case boardAudible(boardID: UUID)
|
||||||
case boardBypass(boardIndex: Int)
|
case boardBypass(boardID: UUID)
|
||||||
case pedalBypass(boardIndex: Int, pedalIndex: Int)
|
case pedalBypass(pedalID: UUID)
|
||||||
|
/// A pedal-specific momentary action beyond generic bypass (e.g. a looper's
|
||||||
|
/// record/stop or reset footswitch). `kind` is opaque to `MIDIMap` — `MIDIController`
|
||||||
|
/// resolves the target pedal (by id) and dispatches on `kind` itself.
|
||||||
|
case pedalAction(pedalID: UUID, kind: PedalActionKind)
|
||||||
|
/// Toggles the rig-level tuner on/off.
|
||||||
|
case tunerToggle
|
||||||
|
/// Registers one tap-tempo press (see `ShoeGaze.tapTempo()`).
|
||||||
|
case tapTempo
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A pedal-specific momentary action addressable by ``Action/pedalAction(pedalID:kind:)``.
|
||||||
|
/// New pedals with more than a simple bypass toggle add cases here.
|
||||||
|
public enum PedalActionKind: Codable, Equatable, Sendable {
|
||||||
|
/// Looper: presses the smart Loop footswitch (record → set end → overdub → play by
|
||||||
|
/// state) — same as ``looperOverdubToggle``; both dispatch to `LooperPedal.pressLoop()`.
|
||||||
|
// TODO: collapse looperRecordStop / looperOverdubToggle into one case (both call pressLoop).
|
||||||
|
case looperRecordStop
|
||||||
|
/// Looper: presses the smart Loop footswitch (toggles overdub once a loop is playing).
|
||||||
|
case looperOverdubToggle
|
||||||
|
/// Looper: flips `loopOn` (loop mute) between `0` and `1`.
|
||||||
|
case looperLoopToggle
|
||||||
|
/// Looper: reset — clears all tracks and returns to the clear state.
|
||||||
|
case looperReset
|
||||||
|
/// Looper: immediately stops playback (`LooperPedal.stopPlayback()`).
|
||||||
|
case looperStop
|
||||||
|
/// Looper: arms / cancels a stop at the loop end (`LooperPedal.toggleStopAtLoopEnd()`).
|
||||||
|
case looperCueStop
|
||||||
|
/// Looper: flips playback direction (`LooperPedal.toggleReverse()`).
|
||||||
|
case looperReverse
|
||||||
|
/// Looper: cycles the Sync/Free transport mode (`LooperPedal.cycleSyncMode()`).
|
||||||
|
case looperSyncToggle
|
||||||
|
/// Looper: taps track `index` (0 = A) — selects it, or mutes it if already selected and
|
||||||
|
/// recorded (`LooperPedal.tapTrack(_:)`), matching the A/B/C/D dots.
|
||||||
|
case looperTrack(index: Int)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Switch binding
|
// MARK: - Switch binding
|
||||||
@@ -88,6 +151,86 @@ public struct MIDIMap: Codable, Equatable, Sendable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Key modifiers
|
||||||
|
|
||||||
|
/// The modifier keys that qualify a ``KeyBinding``, so `a` and `⇧a` (and `⌃a`, `⌥a`) are
|
||||||
|
/// distinct triggers. Shift is a modifier here rather than being folded into the key's case,
|
||||||
|
/// which keeps the base key a single lowercased character on every platform. Command is
|
||||||
|
/// deliberately absent — it is reserved for the app's menu keyboard shortcuts.
|
||||||
|
public struct KeyModifiers: OptionSet, Codable, Equatable, Hashable, Sendable {
|
||||||
|
|
||||||
|
public let rawValue: Int
|
||||||
|
|
||||||
|
public init(rawValue: Int) {
|
||||||
|
self.rawValue = rawValue
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The Shift key (`⇧`).
|
||||||
|
public static let shift: KeyModifiers = KeyModifiers(rawValue: 1 << 0)
|
||||||
|
/// The Control key (`⌃`).
|
||||||
|
public static let control: KeyModifiers = KeyModifiers(rawValue: 1 << 1)
|
||||||
|
/// The Option key (`⌥`).
|
||||||
|
public static let option: KeyModifiers = KeyModifiers(rawValue: 1 << 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Key binding
|
||||||
|
|
||||||
|
/// A computer letter/digit key bound to a toggle ``Action``. Fires on key-down when no text
|
||||||
|
/// field is focused; the same latch semantics as a footswitch (booleans flip in software,
|
||||||
|
/// `boardSolo` is exclusive). `key` is a single lowercased character; ``modifiers`` distinguish
|
||||||
|
/// `a` from `⇧a`, `⌃a`, and `⌥a`.
|
||||||
|
public struct KeyBinding: Codable, Equatable, Sendable {
|
||||||
|
|
||||||
|
/// The bound key as a single lowercased character (e.g. `"b"`, `"3"`).
|
||||||
|
public var key: String
|
||||||
|
|
||||||
|
/// The modifier keys held with ``key``. Empty for an unmodified press.
|
||||||
|
public var modifiers: KeyModifiers
|
||||||
|
|
||||||
|
/// The control to toggle.
|
||||||
|
public var action: Action
|
||||||
|
|
||||||
|
/// The resolved control's display name at learn time, for stale-binding detection.
|
||||||
|
public var displayNameHint: String?
|
||||||
|
|
||||||
|
/// Creates a key binding.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - key: The bound key, normalized to a single lowercased character.
|
||||||
|
/// - modifiers: The qualifying modifier keys. Defaults to none.
|
||||||
|
/// - action: The toggle action to perform.
|
||||||
|
/// - displayNameHint: Resolved control name at learn time. Defaults to `nil`.
|
||||||
|
public init(
|
||||||
|
key: String,
|
||||||
|
modifiers: KeyModifiers = [],
|
||||||
|
action: Action,
|
||||||
|
displayNameHint: String? = nil
|
||||||
|
) {
|
||||||
|
self.key = key
|
||||||
|
self.modifiers = modifiers
|
||||||
|
self.action = action
|
||||||
|
self.displayNameHint = displayNameHint
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case key
|
||||||
|
case modifiers
|
||||||
|
case action
|
||||||
|
case displayNameHint
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Decodes a key binding, defaulting `modifiers` to none when absent so a binding saved
|
||||||
|
/// before modifiers existed still decodes (unmodified, as it was learned). `encode(to:)`
|
||||||
|
/// stays synthesized.
|
||||||
|
public init(from decoder: Decoder) throws {
|
||||||
|
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
self.key = try container.decode(String.self, forKey: .key)
|
||||||
|
self.modifiers = try container.decodeIfPresent(KeyModifiers.self, forKey: .modifiers) ?? []
|
||||||
|
self.action = try container.decode(Action.self, forKey: .action)
|
||||||
|
self.displayNameHint = try container.decodeIfPresent(String.self, forKey: .displayNameHint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - CC target
|
// MARK: - CC target
|
||||||
|
|
||||||
/// A continuous control an expression pedal can drive — either a specific pedal control (a knob
|
/// A continuous control an expression pedal can drive — either a specific pedal control (a knob
|
||||||
@@ -98,15 +241,14 @@ public struct MIDIMap: Codable, Equatable, Sendable {
|
|||||||
|
|
||||||
/// A knob or slider on a pedal, indexed into `pedal.ccMappableControls`.
|
/// A knob or slider on a pedal, indexed into `pedal.ccMappableControls`.
|
||||||
case pedalControl(
|
case pedalControl(
|
||||||
boardIndex: Int,
|
pedalID: UUID,
|
||||||
pedalIndex: Int,
|
|
||||||
controlIndex: Int,
|
controlIndex: Int,
|
||||||
pedalNameHint: String?,
|
pedalNameHint: String?,
|
||||||
controlLabelHint: String?
|
controlLabelHint: String?
|
||||||
)
|
)
|
||||||
|
|
||||||
/// A board's master output level (the board fader).
|
/// A board's master output level (the board fader).
|
||||||
case boardLevel(boardIndex: Int, boardLabelHint: String?)
|
case boardLevel(boardID: UUID, boardLabelHint: String?)
|
||||||
|
|
||||||
/// The rig-wide output volume (applies to the whole rig).
|
/// The rig-wide output volume (applies to the whole rig).
|
||||||
case rigVolume
|
case rigVolume
|
||||||
@@ -115,8 +257,8 @@ public struct MIDIMap: Codable, Equatable, Sendable {
|
|||||||
/// find and replace a binding regardless of the name captured at learn time).
|
/// find and replace a binding regardless of the name captured at learn time).
|
||||||
public func addresses(_ other: CCTarget) -> Bool {
|
public func addresses(_ other: CCTarget) -> Bool {
|
||||||
switch (self, other) {
|
switch (self, other) {
|
||||||
case let (.pedalControl(b1, p1, c1, _, _), .pedalControl(b2, p2, c2, _, _)):
|
case let (.pedalControl(p1, c1, _, _), .pedalControl(p2, c2, _, _)):
|
||||||
return b1 == b2 && p1 == p2 && c1 == c2
|
return p1 == p2 && c1 == c2
|
||||||
case let (.boardLevel(b1, _), .boardLevel(b2, _)):
|
case let (.boardLevel(b1, _), .boardLevel(b2, _)):
|
||||||
return b1 == b2
|
return b1 == b2
|
||||||
case (.rigVolume, .rigVolume):
|
case (.rigVolume, .rigVolume):
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Foundation
|
||||||
import LyrebirdSynth
|
import LyrebirdSynth
|
||||||
import LyrebirdUI
|
import LyrebirdUI
|
||||||
|
|
||||||
@@ -59,8 +60,37 @@ open class Pedal: SynthesizerBase {
|
|||||||
/// safe 48 kHz fallback.
|
/// safe 48 kHz fallback.
|
||||||
public var sampleRate: Double = 48000.0
|
public var sampleRate: Double = 48000.0
|
||||||
|
|
||||||
|
// MARK: - Tempo / engine (injected)
|
||||||
|
|
||||||
|
/// Shared tempo clock, injected by `PedalBoard.add(_:)` for tempo-aware pedals (the
|
||||||
|
/// looper's beat-quantized transport). `nil` for pedals added to a board that was
|
||||||
|
/// created without a clock (e.g. a bare parallel sub-board). Weak: the clock is owned
|
||||||
|
/// by `ShoeGaze` and outlives every pedal.
|
||||||
|
public internal(set) weak var clock: LyrebirdClock?
|
||||||
|
|
||||||
|
/// The engine that owns this pedal's nodes, injected by `PedalBoard.add(_:)`. Needed by
|
||||||
|
/// tempo-aware pedals to start a `LyrebirdRoutine` that waits on beat boundaries. Weak:
|
||||||
|
/// the engine owns the node tree, not the reverse.
|
||||||
|
public internal(set) weak var hostEngine: SynthesisEngine?
|
||||||
|
|
||||||
|
// MARK: - Tempo sync
|
||||||
|
|
||||||
|
/// Sync state per tempo-syncable parameter, keyed by ``TempoSyncableParam/key``. A missing
|
||||||
|
/// key means ``TempoSync/free``. Persisted in ``PedalState`` and restored on rig load.
|
||||||
|
public internal(set) var tempoSync: [String: TempoSync] = [:]
|
||||||
|
|
||||||
|
/// Observable signal bumped on every ``tempoSync`` change so a SwiftUI badge re-renders when the
|
||||||
|
/// sync state changes through any path (the picker, a preset load, or a lightweight recall).
|
||||||
|
public let tempoSyncRevision: TempoSyncRevision = TempoSyncRevision()
|
||||||
|
|
||||||
// MARK: - Identity / routing
|
// MARK: - Identity / routing
|
||||||
|
|
||||||
|
/// Stable identity for this pedal instance, persisted in ``PedalState`` and used by MIDI
|
||||||
|
/// bindings to address the pedal by id rather than by chain position. Defaults to a fresh
|
||||||
|
/// `UUID` for a newly-created pedal; a rebuild from a saved rig restores the saved id
|
||||||
|
/// (`board.add(_:)` / preset apply sets it), so a pedal keeps its identity across edits.
|
||||||
|
public internal(set) var id: UUID = UUID()
|
||||||
|
|
||||||
/// Human-readable name for the pedal (e.g. "Overdrive", "Delay").
|
/// Human-readable name for the pedal (e.g. "Overdrive", "Delay").
|
||||||
public let displayName: String
|
public let displayName: String
|
||||||
|
|
||||||
@@ -87,6 +117,31 @@ open class Pedal: SynthesizerBase {
|
|||||||
/// Override in a widener or stereo-native subclass.
|
/// Override in a widener or stereo-native subclass.
|
||||||
open var channelKind: PedalChannelKind { .mono }
|
open var channelKind: PedalChannelKind { .mono }
|
||||||
|
|
||||||
|
/// Whether the UI shows the common wet/dry `Mix` control for this pedal. Defaults to `true`.
|
||||||
|
/// A pedal that manages its own dry/wet balance internally (e.g. the looper, where the clean
|
||||||
|
/// signal always passes through) overrides this to `false` so the confusing Mix knob is hidden
|
||||||
|
/// and `mix` stays at its fully-wet default.
|
||||||
|
open var showsMixControl: Bool { true }
|
||||||
|
|
||||||
|
/// Called on the main thread when the audio engine is stopped by the user (via
|
||||||
|
/// `ShoeGaze.stopEngine()`), not during a transient stop-around-rebuild. Stateful pedals
|
||||||
|
/// (e.g. the looper) override this to return to a clean state. Default: no-op.
|
||||||
|
open func engineDidStop() {}
|
||||||
|
|
||||||
|
/// Called on the main thread just before the rig is torn down (rig load / clear / input-source
|
||||||
|
/// change), while the pedal is still live. Stateful pedals override this to stop any background
|
||||||
|
/// work and return to a clean state before their instance is discarded. Default: no-op.
|
||||||
|
///
|
||||||
|
/// - Important: Fired from `ShoeGaze.teardown()`, which — like all node-removal paths — must
|
||||||
|
/// run with the engine already stopped. An override that clears buffers or stops RT-adjacent
|
||||||
|
/// work relies on that precondition; do not call `teardown()` with the engine running.
|
||||||
|
open func rigWillTeardown() {}
|
||||||
|
|
||||||
|
/// Number of standard enclosure widths this pedal's card occupies in the UI. Defaults
|
||||||
|
/// to `1`. A control-dense pedal (e.g. the looper) overrides to `2` for a wider card.
|
||||||
|
/// The UI multiplies its base enclosure width by this factor; `1` is the normal stompbox.
|
||||||
|
open var widthUnits: Int { 1 }
|
||||||
|
|
||||||
/// `true` when the board has placed this pedal in a stereo (width-2) region.
|
/// `true` when the board has placed this pedal in a stereo (width-2) region.
|
||||||
public var isStereo: Bool { outputBusRight != nil }
|
public var isStereo: Bool { outputBusRight != nil }
|
||||||
|
|
||||||
@@ -177,6 +232,24 @@ open class Pedal: SynthesizerBase {
|
|||||||
[]
|
[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Effect-specific transport controls, rendered as a row directly below the knobs — above
|
||||||
|
/// ``effectButtons``. Use for the persistent state toggles and transport stops that read as
|
||||||
|
/// a group distinct from the momentary "do it now" actions (e.g. a looper's Loop / Stop /
|
||||||
|
/// Cue Stop / Reverse). Defaults to empty; a pedal with none simply skips the row.
|
||||||
|
open var effectTransportButtons: [PedalButton] {
|
||||||
|
[]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Effect-specific action buttons for this pedal, rendered as a row of stomp-style
|
||||||
|
/// buttons beneath the transport row.
|
||||||
|
///
|
||||||
|
/// Override in subclasses to publish momentary actions (e.g. "Record / Stop", "Reset")
|
||||||
|
/// that need a non-RT side effect beyond writing a single parameter value — see
|
||||||
|
/// ``PedalButton``. Defaults to empty.
|
||||||
|
open var effectButtons: [PedalButton] {
|
||||||
|
[]
|
||||||
|
}
|
||||||
|
|
||||||
/// All knobs a generic UI should render for this pedal: effect-specific knobs
|
/// All knobs a generic UI should render for this pedal: effect-specific knobs
|
||||||
/// first, then the common `mix` and `level` knobs. The `bypass` parameter is
|
/// first, then the common `mix` and `level` knobs. The `bypass` parameter is
|
||||||
/// surfaced separately as a header toggle, not as a knob.
|
/// surfaced separately as a header toggle, not as a knob.
|
||||||
@@ -203,6 +276,60 @@ open class Pedal: SynthesizerBase {
|
|||||||
return knobControls + sliderControls
|
return knobControls + sliderControls
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Tempo sync
|
||||||
|
|
||||||
|
/// Parameters this pedal exposes to tempo sync (delay times, LFO rates). Empty by default —
|
||||||
|
/// override in subclasses whose time- or rate-based parameters can lock to the tempo.
|
||||||
|
///
|
||||||
|
/// Each descriptor's ``TempoSyncableParam/key`` must be unique within the pedal and stable
|
||||||
|
/// across versions (it is the persistence key). Order is the order the sync controls appear.
|
||||||
|
open var tempoSyncableParams: [TempoSyncableParam] {
|
||||||
|
[]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Recomputes and writes every parameter currently locked to a note division, from the shared
|
||||||
|
/// clock's tempo. Main-thread only — writing a `@UIParam` is the same path as a knob turn.
|
||||||
|
///
|
||||||
|
/// A no-op when no clock is injected. Free parameters are left untouched. A synced value that
|
||||||
|
/// falls outside the parameter's range (a long division past a delay's maximum time) is clamped.
|
||||||
|
/// Called by `ShoeGaze` whenever the tempo changes and whenever a parameter's sync state changes.
|
||||||
|
public func applyTempoSync() {
|
||||||
|
guard let clock: LyrebirdClock = clock else { return }
|
||||||
|
let bpm: Double = clock.bpm
|
||||||
|
guard bpm > 0 else { return }
|
||||||
|
for param: TempoSyncableParam in tempoSyncableParams {
|
||||||
|
guard case .division(let division) = tempoSync[param.key] ?? .free else { continue }
|
||||||
|
param.node.update(param.value(for: division, bpm: bpm).value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets one parameter's sync state and immediately recomputes it. Pass ``TempoSync/free`` to
|
||||||
|
/// return the parameter to knob control (its value stays at the last synced number until the
|
||||||
|
/// knob moves it), or `.division(_:)` to lock it to a note value of the live tempo.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - sync: The new sync state.
|
||||||
|
/// - key: The ``TempoSyncableParam/key`` of the parameter to update.
|
||||||
|
public func setSync(_ sync: TempoSync, for key: String) {
|
||||||
|
tempoSync[key] = sync
|
||||||
|
tempoSyncRevision.bump()
|
||||||
|
applyTempoSync()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether `node` backs a tempo-syncable parameter currently locked to a note division.
|
||||||
|
///
|
||||||
|
/// Used by MIDI to leave a synced parameter alone: its value is derived from the tempo, so a CC
|
||||||
|
/// write would be immediately overwritten on the next tempo change. Matches by node identity, so
|
||||||
|
/// it stays correct regardless of control ordering. Returns `false` for a free or non-syncable node.
|
||||||
|
public func isNodeTempoSynced(_ node: UIParamNode) -> Bool {
|
||||||
|
for param: TempoSyncableParam in tempoSyncableParams where param.node === node {
|
||||||
|
if case .division = tempoSync[param.key] ?? .free {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Subclass hook
|
// MARK: - Subclass hook
|
||||||
|
|
||||||
/// Returns the processed (wet) mono signal for this pedal.
|
/// Returns the processed (wet) mono signal for this pedal.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Foundation
|
||||||
import LyrebirdSynth
|
import LyrebirdSynth
|
||||||
import LyrebirdUI
|
import LyrebirdUI
|
||||||
|
|
||||||
@@ -59,6 +60,10 @@ public final class PedalBoard {
|
|||||||
|
|
||||||
private let engine: SynthesisEngine
|
private let engine: SynthesisEngine
|
||||||
|
|
||||||
|
/// Shared tempo clock, forwarded to each pedal in `add(_:)` so tempo-aware pedals (the
|
||||||
|
/// looper) can quantize to beats. `nil` for boards created without one.
|
||||||
|
private let clock: LyrebirdClock?
|
||||||
|
|
||||||
/// The bus that feeds the first pedal in the chain.
|
/// The bus that feeds the first pedal in the chain.
|
||||||
public let headBus: AudioBus
|
public let headBus: AudioBus
|
||||||
|
|
||||||
@@ -89,6 +94,11 @@ public final class PedalBoard {
|
|||||||
/// call chains the first pedal after this node automatically (no `after:` arg needed).
|
/// call chains the first pedal after this node automatically (no `after:` arg needed).
|
||||||
public internal(set) var headInputNode: (any Synthesizer)?
|
public internal(set) var headInputNode: (any Synthesizer)?
|
||||||
|
|
||||||
|
/// Stable identity for this board, persisted in ``BoardState`` and used by MIDI bindings to
|
||||||
|
/// address the board by id rather than by position. Defaults to a fresh `UUID`; a rebuild from
|
||||||
|
/// a saved rig restores the saved id, so a board keeps its identity across edits and reorders.
|
||||||
|
public internal(set) var id: UUID = UUID()
|
||||||
|
|
||||||
/// Display label for the board, shown in the UI. Defaults to `"Board"`; `ShoeGaze`
|
/// Display label for the board, shown in the UI. Defaults to `"Board"`; `ShoeGaze`
|
||||||
/// assigns a numbered label (`"Board 1"`, `"Board 2"`, …) when it creates the board.
|
/// assigns a numbered label (`"Board 1"`, `"Board 2"`, …) when it creates the board.
|
||||||
public var label: String = "Board"
|
public var label: String = "Board"
|
||||||
@@ -153,9 +163,13 @@ public final class PedalBoard {
|
|||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - engine: The `SynthesisEngine` that will own the pedal nodes.
|
/// - engine: The `SynthesisEngine` that will own the pedal nodes.
|
||||||
|
/// - clock: Shared tempo clock forwarded to tempo-aware pedals (the looper) for
|
||||||
|
/// beat-quantized transport. Optional; `nil` disables quantization for pedals on
|
||||||
|
/// this board.
|
||||||
/// - Throws: `BusAllocatorError.noFreeBus` if no mono audio bus is available.
|
/// - Throws: `BusAllocatorError.noFreeBus` if no mono audio bus is available.
|
||||||
public init(engine: SynthesisEngine) throws {
|
public init(engine: SynthesisEngine, clock: LyrebirdClock? = nil) throws {
|
||||||
self.engine = engine
|
self.engine = engine
|
||||||
|
self.clock = clock
|
||||||
let head: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
let head: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
self.headBus = head
|
self.headBus = head
|
||||||
self.outputBus = head
|
self.outputBus = head
|
||||||
@@ -196,6 +210,8 @@ public final class PedalBoard {
|
|||||||
/// - `EngineAddError` if the engine rejects the add (e.g. queue full, double-add).
|
/// - `EngineAddError` if the engine rejects the add (e.g. queue full, double-add).
|
||||||
public func add(_ pedal: Pedal, after predecessor: (any Synthesizer)? = nil) throws {
|
public func add(_ pedal: Pedal, after predecessor: (any Synthesizer)? = nil) throws {
|
||||||
pedal.sampleRate = engine.sampleRate
|
pedal.sampleRate = engine.sampleRate
|
||||||
|
pedal.hostEngine = engine
|
||||||
|
pedal.clock = clock
|
||||||
|
|
||||||
// Each arm configures the pedal's buses, inserts it, advances the tail, and only then
|
// Each arm configures the pedal's buses, inserts it, advances the tail, and only then
|
||||||
// records it in `pedals` — so a pedal is never tracked unless it was fully wired and
|
// records it in `pedals` — so a pedal is never tracked unless it was fully wired and
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
// PedalButton.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// A UI-agnostic description of one pedal button — a momentary action trigger or a
|
||||||
|
/// node-bound toggle, rendered as a stomp-style button.
|
||||||
|
///
|
||||||
|
/// Where ``PedalSwitch`` describes a multi-position segmented control, `PedalButton`
|
||||||
|
/// describes a single button in one of two styles:
|
||||||
|
/// - `.momentary`: runs a closure on each press (e.g. "Record / Stop", "Reset"). Use this
|
||||||
|
/// whenever pressing the button must also perform a non-RT side effect (clearing a
|
||||||
|
/// buffer, requesting a recorder reset) beyond writing a single parameter value.
|
||||||
|
/// - `.toggle`: flips a bound ``UIParamNode`` between `0` and `1` on each press, with no
|
||||||
|
/// side effect required — appropriate only when the live audio graph itself reads the
|
||||||
|
/// node continuously (so toggling the raw value is sufficient).
|
||||||
|
///
|
||||||
|
/// A `Pedal` publishes an array of these via ``Pedal/effectButtons`` so a generic
|
||||||
|
/// pedalboard UI can render a footswitch-style button per action without knowing the
|
||||||
|
/// concrete pedal type.
|
||||||
|
public struct PedalButton {
|
||||||
|
|
||||||
|
/// Style of button behavior, mirroring `ParameterButton.Style` in `LyrebirdUI`.
|
||||||
|
public enum Style: Equatable {
|
||||||
|
/// Executes `action` on each press.
|
||||||
|
case momentary
|
||||||
|
/// Flips `node` between `0` and `1` on each press.
|
||||||
|
case toggle
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Short label shown on the button (e.g. "Record", "Reset").
|
||||||
|
public let label: String
|
||||||
|
|
||||||
|
/// Button behavior style.
|
||||||
|
public let style: Style
|
||||||
|
|
||||||
|
/// The live parameter node this button toggles. Non-`nil` only for `.toggle` style.
|
||||||
|
public let node: UIParamNode?
|
||||||
|
|
||||||
|
/// The action run on each press. Non-`nil` only for `.momentary` style.
|
||||||
|
public let action: (() -> Void)?
|
||||||
|
|
||||||
|
/// Optional LED-indicator node for a `.momentary` button. When non-`nil`, the button is
|
||||||
|
/// drawn in the same LED + footswitch style as a `.toggle` button, with the LED lit while
|
||||||
|
/// this node reads `≥ 0.5` — letting a momentary action reflect a persistent state (e.g. a
|
||||||
|
/// looper's Stop lit while stopped, Cue Stop lit while armed). `nil` renders a plain button.
|
||||||
|
public let indicator: UIParamNode?
|
||||||
|
|
||||||
|
/// Optional live caption describing what the *next* press does, polled by the UI. When set,
|
||||||
|
/// the button shows this instead of the static `label` — letting a state-driven control (the
|
||||||
|
/// looper's Loop footswitch) read "Record" → "Set End" → "Overdub" → "Play" as the state
|
||||||
|
/// changes. `nil` shows the static `label`.
|
||||||
|
public let dynamicLabel: (() -> String)?
|
||||||
|
|
||||||
|
/// Creates a momentary action button.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - label: Short label shown on the button.
|
||||||
|
/// - indicator: Optional state node driving an LED (see ``indicator``). Defaults to `nil`
|
||||||
|
/// for a plain button.
|
||||||
|
/// - dynamicLabel: Optional live caption describing the next press (see ``dynamicLabel``).
|
||||||
|
/// - action: Closure run on each press.
|
||||||
|
public init(
|
||||||
|
label: String,
|
||||||
|
indicator: UIParamNode? = nil,
|
||||||
|
dynamicLabel: (() -> String)? = nil,
|
||||||
|
action: @escaping () -> Void
|
||||||
|
) {
|
||||||
|
self.label = label
|
||||||
|
self.style = .momentary
|
||||||
|
self.node = nil
|
||||||
|
self.action = action
|
||||||
|
self.indicator = indicator
|
||||||
|
self.dynamicLabel = dynamicLabel
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a toggle button bound to a `UIParamNode`.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - label: Short label shown on the button.
|
||||||
|
/// - node: The `UIParamNode` projected value of an `@UIParam` property
|
||||||
|
/// (`pedal.$loopOn`, `pedal.$reverse`, …).
|
||||||
|
/// - dynamicLabel: Optional live caption describing the next press (see ``dynamicLabel``).
|
||||||
|
public init(label: String, node: UIParamNode, dynamicLabel: (() -> String)? = nil) {
|
||||||
|
self.label = label
|
||||||
|
self.style = .toggle
|
||||||
|
self.node = node
|
||||||
|
self.action = nil
|
||||||
|
self.indicator = nil
|
||||||
|
self.dynamicLabel = dynamicLabel
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,6 +49,11 @@ public struct PedalSwitch {
|
|||||||
/// three-state switch. Must contain at least two options.
|
/// three-state switch. Must contain at least two options.
|
||||||
public let options: [Option]
|
public let options: [Option]
|
||||||
|
|
||||||
|
/// `true` when this switch controls a tempo-synced behaviour (e.g. the looper's
|
||||||
|
/// Sync-to-Tempo mode). A generic UI can disable such switches — and the host can force them
|
||||||
|
/// to their first (off) option — while the tempo indicator is turned off. Defaults to `false`.
|
||||||
|
public let tempoDependent: Bool
|
||||||
|
|
||||||
/// Creates a switch descriptor.
|
/// Creates a switch descriptor.
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
@@ -56,14 +61,28 @@ public struct PedalSwitch {
|
|||||||
/// - node: The `UIParamNode` projected value of an `@UIParam` property
|
/// - node: The `UIParamNode` projected value of an `@UIParam` property
|
||||||
/// (`pedal.$mode`, `pedal.$direction`, …).
|
/// (`pedal.$mode`, `pedal.$direction`, …).
|
||||||
/// - options: Ordered switch positions, left to right. At least two.
|
/// - options: Ordered switch positions, left to right. At least two.
|
||||||
|
/// - tempoDependent: `true` if the switch depends on the tempo/clock. Defaults to `false`.
|
||||||
public init(
|
public init(
|
||||||
label: String,
|
label: String,
|
||||||
node: UIParamNode,
|
node: UIParamNode,
|
||||||
options: [Option]
|
options: [Option],
|
||||||
|
tempoDependent: Bool = false
|
||||||
) {
|
) {
|
||||||
precondition(options.count >= 2, "PedalSwitch requires at least two options")
|
precondition(options.count >= 2, "PedalSwitch requires at least two options")
|
||||||
self.label = label
|
self.label = label
|
||||||
self.node = node
|
self.node = node
|
||||||
self.options = options
|
self.options = options
|
||||||
|
self.tempoDependent = tempoDependent
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The value of the next option after the one nearest `current`, wrapping to the first — so a
|
||||||
|
/// momentary trigger (e.g. a MIDI switch) can oscillate through the positions on each press.
|
||||||
|
public func nextValue(after current: Double) -> Double {
|
||||||
|
guard !options.isEmpty else { return current }
|
||||||
|
let currentIndex: Int = options.indices.min(by: {
|
||||||
|
abs(options[$0].value - current) < abs(options[$1].value - current)
|
||||||
|
}) ?? 0
|
||||||
|
let nextIndex: Int = (currentIndex + 1) % options.count
|
||||||
|
return options[nextIndex].value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,4 +93,7 @@ public extension PedalType {
|
|||||||
static let octaveSplitter = PedalType("Octave Splitter")
|
static let octaveSplitter = PedalType("Octave Splitter")
|
||||||
static let bassOctaver = PedalType("Bass Octaver")
|
static let bassOctaver = PedalType("Bass Octaver")
|
||||||
static let harmonizer = PedalType("Harmonizer")
|
static let harmonizer = PedalType("Harmonizer")
|
||||||
|
|
||||||
|
// Looper
|
||||||
|
static let looper = PedalType("Looper")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,12 @@ public final class ChorusPedal: Pedal {
|
|||||||
private let rateRange: ClosedRange<Double> = 0.05 ... 6.0
|
private let rateRange: ClosedRange<Double> = 0.05 ... 6.0
|
||||||
private let depthRange: ClosedRange<Double> = 0.0005 ... 0.008
|
private let depthRange: ClosedRange<Double> = 0.0005 ... 0.008
|
||||||
|
|
||||||
|
public override var tempoSyncableParams: [TempoSyncableParam] {
|
||||||
|
[
|
||||||
|
TempoSyncableParam(key: "rate", label: "Rate", node: $rate, kind: .rate, range: rateRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
public override var effectKnobs: [PedalKnob] {
|
public override var effectKnobs: [PedalKnob] {
|
||||||
[
|
[
|
||||||
PedalKnob(label: "Rate", node: $rate, range: rateRange),
|
PedalKnob(label: "Rate", node: $rate, range: rateRange),
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import LyrebirdUI
|
|||||||
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - time: Delay time in seconds. Range `[0.01, 1.5]`. Defaults to `0.25`.
|
/// - time: Delay time in seconds. Range `[0.01, 5.0]`. Defaults to `0.25`.
|
||||||
/// - feedback: Feedback amount expressed as decay time in seconds — the time
|
/// - feedback: Feedback amount expressed as decay time in seconds — the time
|
||||||
/// for echoes to fall to `targetAmp` (−60 dB). Longer values produce more
|
/// for echoes to fall to `targetAmp` (−60 dB). Longer values produce more
|
||||||
/// repeats. Range `[0.05, 6.0]` seconds. Defaults to `1.0`.
|
/// repeats. Range `[0.05, 6.0]` seconds. Defaults to `1.0`.
|
||||||
@@ -35,7 +35,7 @@ public final class DelayPedal: Pedal {
|
|||||||
|
|
||||||
// MARK: - Parameters
|
// MARK: - Parameters
|
||||||
|
|
||||||
/// Delay time in seconds. Range [0.01, 1.5].
|
/// Delay time in seconds. Range [0.01, 5.0].
|
||||||
@UIParam public var time: Double = 0.25
|
@UIParam public var time: Double = 0.25
|
||||||
|
|
||||||
/// Feedback decay time in seconds (time to reach −60 dB amplitude).
|
/// Feedback decay time in seconds (time to reach −60 dB amplitude).
|
||||||
@@ -44,7 +44,7 @@ public final class DelayPedal: Pedal {
|
|||||||
// MARK: - Constants
|
// MARK: - Constants
|
||||||
|
|
||||||
/// Maximum supported delay time in seconds. Sizes the delay line buffer at init.
|
/// Maximum supported delay time in seconds. Sizes the delay line buffer at init.
|
||||||
private let maxDelayTime: Double = 1.5
|
private let maxDelayTime: Double = 5.0
|
||||||
|
|
||||||
/// Amplitude target for the `decayTime` calculation (−60 dB).
|
/// Amplitude target for the `decayTime` calculation (−60 dB).
|
||||||
private let targetAmp: Double = 0.001
|
private let targetAmp: Double = 0.001
|
||||||
@@ -55,7 +55,7 @@ public final class DelayPedal: Pedal {
|
|||||||
// MARK: - UI knobs
|
// MARK: - UI knobs
|
||||||
|
|
||||||
/// Delay-time knob range in seconds.
|
/// Delay-time knob range in seconds.
|
||||||
private let timeRange: ClosedRange<Double> = 0.01 ... 1.5
|
private let timeRange: ClosedRange<Double> = 0.01 ... 5.0
|
||||||
|
|
||||||
/// Feedback (decay-time) knob range in seconds.
|
/// Feedback (decay-time) knob range in seconds.
|
||||||
private let feedbackRange: ClosedRange<Double> = 0.05 ... 6.0
|
private let feedbackRange: ClosedRange<Double> = 0.05 ... 6.0
|
||||||
@@ -86,6 +86,12 @@ public final class DelayPedal: Pedal {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override var tempoSyncableParams: [TempoSyncableParam] {
|
||||||
|
[
|
||||||
|
TempoSyncableParam(key: "time", label: "Time", node: $time, kind: .time, range: timeRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Effect
|
// MARK: - Effect
|
||||||
|
|
||||||
/// Applies a feedback delay line. Returns the pure wet (delayed) signal.
|
/// Applies a feedback delay line. Returns the pure wet (delayed) signal.
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public final class FeedbackDelayPedal: Pedal {
|
|||||||
// MARK: - Constants
|
// MARK: - Constants
|
||||||
|
|
||||||
/// Maximum supported delay time in seconds. Sizes the delay-line buffer at init.
|
/// Maximum supported delay time in seconds. Sizes the delay-line buffer at init.
|
||||||
private let maxDelayTime: Double = 1.5
|
private let maxDelayTime: Double = 5.0
|
||||||
|
|
||||||
/// Amplitude target for the `decayTime` calculation (−60 dB).
|
/// Amplitude target for the `decayTime` calculation (−60 dB).
|
||||||
private let targetAmp: Double = 0.001
|
private let targetAmp: Double = 0.001
|
||||||
@@ -58,12 +58,18 @@ public final class FeedbackDelayPedal: Pedal {
|
|||||||
|
|
||||||
// MARK: - Ranges
|
// MARK: - Ranges
|
||||||
|
|
||||||
private let timeRange: ClosedRange<Double> = 0.02 ... 1.5
|
private let timeRange: ClosedRange<Double> = 0.02 ... 5.0
|
||||||
private let feedbackRange: ClosedRange<Double> = 0.1 ... 8.0
|
private let feedbackRange: ClosedRange<Double> = 0.1 ... 8.0
|
||||||
private let toneRange: ClosedRange<Double> = 500.0 ... 8000.0
|
private let toneRange: ClosedRange<Double> = 500.0 ... 8000.0
|
||||||
|
|
||||||
// MARK: - Knobs
|
// MARK: - Knobs
|
||||||
|
|
||||||
|
public override var tempoSyncableParams: [TempoSyncableParam] {
|
||||||
|
[
|
||||||
|
TempoSyncableParam(key: "time", label: "Time", node: $time, kind: .time, range: timeRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
public override var effectKnobs: [PedalKnob] {
|
public override var effectKnobs: [PedalKnob] {
|
||||||
[
|
[
|
||||||
PedalKnob(label: "Time", node: $time, range: timeRange),
|
PedalKnob(label: "Time", node: $time, range: timeRange),
|
||||||
|
|||||||
@@ -57,6 +57,12 @@ public final class FlangerPedal: Pedal {
|
|||||||
|
|
||||||
// MARK: - Knobs
|
// MARK: - Knobs
|
||||||
|
|
||||||
|
public override var tempoSyncableParams: [TempoSyncableParam] {
|
||||||
|
[
|
||||||
|
TempoSyncableParam(key: "rate", label: "Rate", node: $rate, kind: .rate, range: rateRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
public override var effectKnobs: [PedalKnob] {
|
public override var effectKnobs: [PedalKnob] {
|
||||||
[
|
[
|
||||||
PedalKnob(label: "Rate", node: $rate, range: rateRange),
|
PedalKnob(label: "Rate", node: $rate, range: rateRange),
|
||||||
|
|||||||
@@ -0,0 +1,869 @@
|
|||||||
|
// LooperPedal.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import LyrebirdSynth
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// A synchronized multitrack loop pedal. Track A's first take defines the master loop length;
|
||||||
|
/// tracks B–D are overdub layers recorded onto the same grid. All recorded tracks play at once,
|
||||||
|
/// summed to one output and locked in phase. When the board supplies a tempo ``LyrebirdClock``
|
||||||
|
/// the master take is beat-quantized so every loop is a whole number of beats long.
|
||||||
|
///
|
||||||
|
/// ## The Loop footswitch drives the transport by state
|
||||||
|
/// - **Clear** (nothing recorded; only track A selectable): press → record A; press → set the
|
||||||
|
/// loop end (quantized) and drop into overdub on A when it wraps; press → end overdub, keep
|
||||||
|
/// playing; further presses toggle overdub ↔ play on the selected track.
|
||||||
|
/// - **Playing, track B–D selected**: press toggles overdub on that track, aligned to A's
|
||||||
|
/// play-head. Recording an empty track is just overdub onto silence.
|
||||||
|
/// - Selecting another track ends any overdub on the previous one (it drops to playback). A
|
||||||
|
/// newly-selected track records nothing until Loop is pressed.
|
||||||
|
/// - **Stopped** (via Stop / Cue Stop): press → resume all tracks; next press → toggle overdub.
|
||||||
|
///
|
||||||
|
/// > Note: Overdub records forward-in-time, so it cannot be engaged while playback is reversed
|
||||||
|
/// > (the write head would drift against the backward-reading play-head). Engaging overdub is
|
||||||
|
/// > blocked while `reverse` is on.
|
||||||
|
///
|
||||||
|
/// ## Audio graph (built once in `effect(_:)`)
|
||||||
|
/// One `PlayBuffer` per track, all summed; one always-running overdub `RecordBuffer` per track
|
||||||
|
/// whose `recLevel` is gated so only the selected, overdubbing track layers new input; a
|
||||||
|
/// non-looping master recorder for track A's length-defining take. The overdub recorders run
|
||||||
|
/// continuously while playing (reset to the top at play-start) so their write head stays locked
|
||||||
|
/// to the shared play-head — overdub can be toggled on any track without drifting out of phase.
|
||||||
|
public final class LooperPedal: Pedal {
|
||||||
|
|
||||||
|
/// One-line description shown in the picker and info panel.
|
||||||
|
public override var summary: String {
|
||||||
|
"Multitrack looper: record track A, then layer synced overdubs on tracks B–D."
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Triple-width card: the looper spreads its timeline, knobs, and transport grid across three
|
||||||
|
/// columns so the tall pedal fits the canvas without scrolling.
|
||||||
|
public override var widthUnits: Int { 3 }
|
||||||
|
|
||||||
|
/// The looper always passes the clean signal through and adds the loop on top (see `effect`),
|
||||||
|
/// so the wet/dry Mix knob is meaningless — hide it and keep `mix` fully wet.
|
||||||
|
public override var showsMixControl: Bool { false }
|
||||||
|
|
||||||
|
// MARK: - Knobs
|
||||||
|
|
||||||
|
/// Fade time constant, in seconds, for the loop on/off mute and the record→play handoff.
|
||||||
|
@UIParam public var crossfadeTime: Double = LooperPedal.defaultCrossfadeTime
|
||||||
|
|
||||||
|
/// Loop playback gain, in dB.
|
||||||
|
@UIParam public var playbackLevel: Double = 0.0
|
||||||
|
|
||||||
|
/// Overdub input gain, in dB.
|
||||||
|
@UIParam public var overdubLevel: Double = 0.0
|
||||||
|
|
||||||
|
/// Retained level of existing loop content on each overdub pass, `[0, 1]`. `1.0` keeps prior
|
||||||
|
/// layers indefinitely; lower values fade them for a decaying feedback loop.
|
||||||
|
@UIParam public var feedback: Double = 1.0
|
||||||
|
|
||||||
|
// MARK: - Switches
|
||||||
|
|
||||||
|
/// Total loop mute. `0` = muted, `1` = audible. Smoothed by `crossfadeTime`.
|
||||||
|
@UIParam public var loopOn: Double = 1.0
|
||||||
|
|
||||||
|
/// Playback direction. `0` = forward, `1` = reverse. Read as `1 − 2·reverse`.
|
||||||
|
@UIParam public var reverse: Double = 0.0
|
||||||
|
|
||||||
|
/// Transport sync mode. `1` = beat-quantized (record start / loop close snap to the next
|
||||||
|
/// beat via the shared clock); `0` = freeform (immediate, loop length is whatever you play).
|
||||||
|
/// Persisted with the rig. Default `1`.
|
||||||
|
@UIParam public var syncToBeat: Double = 1.0
|
||||||
|
|
||||||
|
// MARK: - Internal live state (read by the audio graph / UI LEDs)
|
||||||
|
|
||||||
|
/// `1` while the loop bank is playing, else `0`. Gates the whole player sum and the overdub
|
||||||
|
/// recorders' `run`.
|
||||||
|
@UIParam public var isPlaying: Double = 0.0
|
||||||
|
|
||||||
|
/// Play-head reset trigger for every player. Pulsed `0 → 1` at play-start so all tracks
|
||||||
|
/// start phase-aligned to frame 0.
|
||||||
|
@UIParam public var playTrigger: Double = 0.0
|
||||||
|
|
||||||
|
/// LED state for the Stop footswitch: `1` while stopped, else `0`.
|
||||||
|
@UIParam public var stoppedIndicator: Double = 0.0
|
||||||
|
|
||||||
|
/// LED state for the Cue Stop footswitch: `1` while a stop-at-loop-end is armed.
|
||||||
|
@UIParam public var cueStopArmed: Double = 0.0
|
||||||
|
|
||||||
|
/// LED state for the Loop footswitch: `1` while overdubbing a track.
|
||||||
|
@UIParam public var overdubIndicator: Double = 0.0
|
||||||
|
|
||||||
|
/// LED state for the Reset footswitch: `1` whenever there is something to reset (any state
|
||||||
|
/// other than clear). Kept in sync by `phase`'s `didSet`.
|
||||||
|
@UIParam public var resetIndicator: Double = 0.0
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
/// Number of loop tracks (A–D).
|
||||||
|
public static let trackCount: Int = 4
|
||||||
|
|
||||||
|
/// Maximum recordable master length, in seconds (each track allocates a buffer this long, so
|
||||||
|
/// per-instance memory is roughly `trackCount × maxDurationSeconds × sampleRate × 8 bytes`).
|
||||||
|
private static let maxDurationSeconds: Double = 60.0
|
||||||
|
|
||||||
|
private static let defaultCrossfadeTime: Double = 0.05
|
||||||
|
private static let reverseRateSpan: Double = 2.0
|
||||||
|
private static let forwardRate: Double = 1.0
|
||||||
|
private static let minimumLoopFrames: Int = 1
|
||||||
|
|
||||||
|
private let crossfadeTimeRange: ClosedRange<Double> = 0.0 ... 2.0
|
||||||
|
private let levelRangeDb: ClosedRange<Double> = -24.0 ... 12.0
|
||||||
|
private let feedbackRange: ClosedRange<Double> = 0.0 ... 1.0
|
||||||
|
|
||||||
|
// MARK: - Buffers + generators
|
||||||
|
|
||||||
|
private var buffers: [LyrebirdBuffer] = []
|
||||||
|
private var players: [PlayBuffer.Audio] = []
|
||||||
|
private var overdubRecorders: [RecordBuffer.Audio] = []
|
||||||
|
private var overdubGates: [ParameterNode] = []
|
||||||
|
|
||||||
|
/// Per-track playback mute gate (`1` = audible, `0` = muted), smoothed by `crossfadeTime` and
|
||||||
|
/// multiplied into each track's player so a recorded track can be silenced.
|
||||||
|
private var muteGates: [ParameterNode] = []
|
||||||
|
|
||||||
|
/// Per-track mute state (`true` = muted).
|
||||||
|
private var trackMuted: [Bool] = []
|
||||||
|
|
||||||
|
/// Non-looping recorder for track A's length-defining first take.
|
||||||
|
private var masterRecorder: RecordBuffer.Audio?
|
||||||
|
|
||||||
|
// MARK: - Transport state
|
||||||
|
|
||||||
|
private enum Phase {
|
||||||
|
case clear
|
||||||
|
case armedRecord
|
||||||
|
case recordingMaster
|
||||||
|
case armedClose
|
||||||
|
case playing
|
||||||
|
case stopped
|
||||||
|
}
|
||||||
|
|
||||||
|
private var phase: Phase = .clear {
|
||||||
|
didSet { resetIndicator = phase == .clear ? 0.0 : 1.0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The track the Loop footswitch records / overdubs into (`0` = A).
|
||||||
|
private var selectedTrack: Int = 0
|
||||||
|
|
||||||
|
/// The track currently overdubbing, or `nil` when just playing.
|
||||||
|
private var overdubbingTrack: Int?
|
||||||
|
|
||||||
|
/// `true` once a track holds recorded material.
|
||||||
|
private var trackHasContent: [Bool] = []
|
||||||
|
|
||||||
|
/// Master loop length in frames (`0` until track A is closed).
|
||||||
|
private var masterLength: Int = 0
|
||||||
|
|
||||||
|
/// Master loop length in whole beats (`0` unless beat-quantized).
|
||||||
|
private var masterBeats: Double = 0.0
|
||||||
|
|
||||||
|
/// Sample time at which the master take began recording, and at which playback last (re)started.
|
||||||
|
private var recordStartSample: SampleTime = 0
|
||||||
|
private var playStartSample: SampleTime = 0
|
||||||
|
|
||||||
|
/// Play-head position tracking that survives direction changes. `playHeadAnchor01` is the
|
||||||
|
/// normalised play-head fraction at the last anchor event (playback start or a reverse flip);
|
||||||
|
/// `playHeadAnchorSample` is the engine sample at that event. Between events the position is
|
||||||
|
/// `anchor01 + direction · (elapsed / masterLength)`, wrapped into `[0, 1)`. This mirrors the
|
||||||
|
/// actual `PlayBuffer` play-head — which reverses smoothly from its live phase — instead of the
|
||||||
|
/// old `1 − forward` reflection that jumped the read-out to the mirror point on every reverse.
|
||||||
|
private var playHeadAnchor01: Double = 0.0
|
||||||
|
private var playHeadAnchorSample: SampleTime = 0
|
||||||
|
|
||||||
|
private var transportRoutine: LyrebirdRoutine?
|
||||||
|
private var stopRoutine: LyrebirdRoutine?
|
||||||
|
private var reverseRoutine: LyrebirdRoutine?
|
||||||
|
|
||||||
|
/// Generation guard for a beat-deferred reverse. Separate from `transportGeneration` so
|
||||||
|
/// scheduling a reverse never invalidates a pending record/close (and vice versa).
|
||||||
|
private(set) var reverseGeneration: Int = 0
|
||||||
|
|
||||||
|
/// Transient notice shown in place of the state description for `noticeDuration` seconds.
|
||||||
|
private var noticeText: String?
|
||||||
|
private var noticeExpiry: Date?
|
||||||
|
private static let noticeDuration: TimeInterval = 4.0
|
||||||
|
|
||||||
|
/// Monotonic action generation guarding deferred beat/stop callbacks (see the single-track
|
||||||
|
/// history — `LyrebirdRoutine.stop()` cannot recall an already-enqueued main-thread hop).
|
||||||
|
private(set) var transportGeneration: Int = 0
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
/// Creates a looper pedal.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - inputBus: Audio bus to read the dry input from. Defaults to `0`; set by the board.
|
||||||
|
/// - outputBus: Audio bus to write the output to. Defaults to `0`; set by the board.
|
||||||
|
public init(inputBus: Int = 0, outputBus: Int = 0) {
|
||||||
|
super.init(name: "Looper", inputBus: inputBus, outputBus: outputBus, initialMix: 1.0)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Knobs / buttons
|
||||||
|
|
||||||
|
public override var effectKnobs: [PedalKnob] {
|
||||||
|
[
|
||||||
|
PedalKnob(label: "Crossfade", node: $crossfadeTime, range: crossfadeTimeRange),
|
||||||
|
PedalKnob(label: "Playback", node: $playbackLevel, range: levelRangeDb),
|
||||||
|
PedalKnob(label: "Overdub", node: $overdubLevel, range: levelRangeDb),
|
||||||
|
PedalKnob(label: "Feedback", node: $feedback, range: feedbackRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Beat-sync vs freeform transport mode, as a two-position segmented switch below the knobs.
|
||||||
|
public override var effectSwitches: [PedalSwitch] {
|
||||||
|
[
|
||||||
|
PedalSwitch(
|
||||||
|
label: "Sync to Tempo",
|
||||||
|
node: $syncToBeat,
|
||||||
|
options: [
|
||||||
|
PedalSwitch.Option(title: "Free", value: 0.0),
|
||||||
|
PedalSwitch.Option(title: "Sync", value: 1.0),
|
||||||
|
],
|
||||||
|
tempoDependent: true
|
||||||
|
),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Transport row: the smart Loop footswitch, the two stops, direction, and reset.
|
||||||
|
public override var effectTransportButtons: [PedalButton] {
|
||||||
|
[
|
||||||
|
PedalButton(label: "Loop", indicator: $overdubIndicator,
|
||||||
|
dynamicLabel: { [weak self] in self?.loopButtonCaption ?? "Loop" }) { [weak self] in self?.pressLoop() },
|
||||||
|
PedalButton(label: "Stop", indicator: $stoppedIndicator,
|
||||||
|
dynamicLabel: { [weak self] in self?.stopButtonCaption ?? "Stop" }) { [weak self] in self?.stopPlayback() },
|
||||||
|
PedalButton(label: "Cue Stop", indicator: $cueStopArmed,
|
||||||
|
dynamicLabel: { [weak self] in self?.cueStopButtonCaption ?? "Cue Stop" }) { [weak self] in self?.toggleStopAtLoopEnd() },
|
||||||
|
PedalButton(label: "Reverse", indicator: $reverse,
|
||||||
|
dynamicLabel: { [weak self] in self?.reverseButtonCaption ?? "Reverse" }) { [weak self] in self?.toggleReverse() },
|
||||||
|
PedalButton(label: "Reset", indicator: $resetIndicator) { [weak self] in self?.resetLoop() },
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - UI read-outs
|
||||||
|
|
||||||
|
/// Publicly-observable transport phase for the state indicator, LEDs, and timeline.
|
||||||
|
public var transportState: LooperTransportState {
|
||||||
|
switch phase {
|
||||||
|
case .clear: return .clear
|
||||||
|
case .armedRecord: return .armedRecord
|
||||||
|
case .recordingMaster: return .recordingMaster
|
||||||
|
case .armedClose: return .armedClose
|
||||||
|
case .playing: return .playing
|
||||||
|
case .stopped: return .stopped
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Index of the selected track, `0 ..< trackCount`.
|
||||||
|
public var selectedTrackIndex: Int { selectedTrack }
|
||||||
|
|
||||||
|
/// The track currently overdubbing, or `nil`.
|
||||||
|
public var overdubbingTrackIndex: Int? { overdubbingTrack }
|
||||||
|
|
||||||
|
/// `true` if track `index` holds recorded material.
|
||||||
|
public func trackHasContent(_ index: Int) -> Bool {
|
||||||
|
index >= 0 && index < trackHasContent.count && trackHasContent[index]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Per-track generator array counts — internal only so a test can verify a graph rebuild
|
||||||
|
/// (`effect()` re-run) doesn't accumulate them. All four should equal `trackCount`.
|
||||||
|
var trackGeneratorCountsForTesting: (buffers: Int, players: Int, overdub: Int, gates: Int) {
|
||||||
|
(buffers.count, players.count, overdubRecorders.count, overdubGates.count)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `true` while a stop-at-loop-end is armed.
|
||||||
|
public var isStopAtLoopEndArmed: Bool { cueStopArmed >= 0.5 }
|
||||||
|
|
||||||
|
/// Master loop length in frames (`0` until track A is closed).
|
||||||
|
public var loopFrameCount: Int { masterLength }
|
||||||
|
|
||||||
|
/// Master loop length in seconds.
|
||||||
|
public var loopLengthSeconds: Double { Double(masterLength) / sampleRate }
|
||||||
|
|
||||||
|
/// Master loop length in whole beats (`0` unless beat-quantized).
|
||||||
|
public var loopLengthBeats: Double { masterBeats }
|
||||||
|
|
||||||
|
/// Normalised play-head position in `[0, 1)` while playing, else `nil`. Shared by all tracks.
|
||||||
|
public func playbackPosition01() -> Double? {
|
||||||
|
guard phase == .playing, masterLength > 0, let engine: SynthesisEngine = hostEngine else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return playHeadFraction(at: engine.currentTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The normalised play-head fraction in `[0, 1)` at engine sample `sample`, integrating the
|
||||||
|
/// signed distance travelled since the last anchor (playback start or reverse flip). Reversal
|
||||||
|
/// simply changes the sign of the accumulation from the current position — no jump.
|
||||||
|
func playHeadFraction(at sample: SampleTime) -> Double {
|
||||||
|
guard masterLength > 0 else { return 0.0 }
|
||||||
|
let direction: Double = reverse >= 0.5 ? -1.0 : 1.0
|
||||||
|
let elapsed: Double = Double(sample - playHeadAnchorSample)
|
||||||
|
let raw: Double = playHeadAnchor01 + direction * elapsed / Double(masterLength)
|
||||||
|
var frac: Double = raw.truncatingRemainder(dividingBy: 1.0)
|
||||||
|
if frac < 0 { frac += 1.0 }
|
||||||
|
return frac
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Caption for the Loop footswitch describing what the *next* press does.
|
||||||
|
public var loopButtonCaption: String {
|
||||||
|
switch phase {
|
||||||
|
case .clear: return "Record"
|
||||||
|
case .armedRecord: return "Recording"
|
||||||
|
case .recordingMaster: return "Set End"
|
||||||
|
case .armedClose: return "Closing"
|
||||||
|
case .stopped: return "Play"
|
||||||
|
case .playing:
|
||||||
|
if overdubbingTrack == selectedTrack { return "Play" }
|
||||||
|
return trackHasContent(selectedTrack) ? "Overdub" : "Record"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Caption for the Stop footswitch (what the next press does).
|
||||||
|
public var stopButtonCaption: String { phase == .stopped ? "Stopped" : "Stop" }
|
||||||
|
|
||||||
|
/// Caption for the Cue Stop footswitch.
|
||||||
|
public var cueStopButtonCaption: String { isStopAtLoopEndArmed ? "Cancel" : "Cue Stop" }
|
||||||
|
|
||||||
|
/// Caption for the Reverse footswitch (the direction the next press switches to).
|
||||||
|
public var reverseButtonCaption: String { reverse >= 0.5 ? "Forward" : "Reverse" }
|
||||||
|
|
||||||
|
/// One-line description of what the pedal is doing now, for the state indicator. A transient
|
||||||
|
/// notice (e.g. the engine-stop reset) takes precedence for a few seconds.
|
||||||
|
public var stateDescription: String {
|
||||||
|
if let notice: String = noticeText, let expiry: Date = noticeExpiry, Date() < expiry {
|
||||||
|
return notice
|
||||||
|
}
|
||||||
|
let armedSuffix: String = isStopAtLoopEndArmed ? " · stop at end" : ""
|
||||||
|
switch phase {
|
||||||
|
case .clear: return "Empty — record track A"
|
||||||
|
case .armedRecord: return "Waiting for beat…"
|
||||||
|
case .recordingMaster: return "Recording A"
|
||||||
|
case .armedClose: return "Closing loop…"
|
||||||
|
case .stopped: return "Stopped"
|
||||||
|
case .playing:
|
||||||
|
if let track: Int = overdubbingTrack {
|
||||||
|
return "Overdubbing \(LooperPedal.trackLabel(track))" + armedSuffix
|
||||||
|
}
|
||||||
|
return "Playing" + armedSuffix
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The letter for a track index (0 → "A").
|
||||||
|
public static func trackLabel(_ index: Int) -> String {
|
||||||
|
let letters: [String] = ["A", "B", "C", "D", "E", "F", "G", "H"]
|
||||||
|
return letters.indices.contains(index) ? letters[index] : "?"
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Effect
|
||||||
|
|
||||||
|
public override func effect(_ dry: any ValidGeneratorInput) -> any ValidGeneratorInput {
|
||||||
|
// `effect()` runs from `build()`, which the engine re-invokes via `rebuildGraph()` on
|
||||||
|
// EVERY add — including the re-adds that a board edit (reorder, insert/remove a neighbour,
|
||||||
|
// toggle a split) performs on this same instance. Start from a clean slate so the per-track
|
||||||
|
// generator arrays don't accumulate across rebuilds, and so stale transport state doesn't
|
||||||
|
// outlive the freshly re-allocated (empty) buffers built below.
|
||||||
|
resetForRebuild()
|
||||||
|
|
||||||
|
let maxFrames: Int = Int(LooperPedal.maxDurationSeconds * sampleRate)
|
||||||
|
let playbackRate: any ValidGeneratorInput =
|
||||||
|
LooperPedal.forwardRate - LooperPedal.reverseRateSpan * $reverse
|
||||||
|
let unity: Double = 1.0
|
||||||
|
|
||||||
|
for _: Int in 0 ..< LooperPedal.trackCount {
|
||||||
|
let buffer: LyrebirdBuffer = LyrebirdBuffer(count: maxFrames, channelCount: 1)
|
||||||
|
buffers.append(buffer)
|
||||||
|
|
||||||
|
let gate: ParameterNode = ParameterNode(0.0)
|
||||||
|
overdubGates.append(gate)
|
||||||
|
|
||||||
|
let muteGate: ParameterNode = ParameterNode(1.0) // 1 = audible
|
||||||
|
muteGates.append(muteGate)
|
||||||
|
|
||||||
|
let overdub: RecordBuffer.Audio = RecordBuffer.Audio(
|
||||||
|
input: dry,
|
||||||
|
buffer: buffer,
|
||||||
|
loop: true,
|
||||||
|
doneAction: .nothing
|
||||||
|
)
|
||||||
|
// Always running while playing; its write head stays locked to the shared play-head.
|
||||||
|
// `recLevel` is zero unless this track is the one being overdubbed; `preLevel` is 1
|
||||||
|
// (identity — keep existing content) except while overdubbing, when it is `feedback`.
|
||||||
|
overdub.$run.source = $isPlaying
|
||||||
|
overdub.$recLevel.source = gate * DbAmp.Control($overdubLevel)
|
||||||
|
overdub.$preLevel.source = (unity - gate) + gate * $feedback
|
||||||
|
overdubRecorders.append(overdub)
|
||||||
|
|
||||||
|
let player: PlayBuffer.Audio = PlayBuffer.Audio(
|
||||||
|
buffer: buffer,
|
||||||
|
loop: true,
|
||||||
|
interpolation: .cubic,
|
||||||
|
rate: playbackRate,
|
||||||
|
trigger: $playTrigger,
|
||||||
|
mul: DbAmp.Control($playbackLevel)
|
||||||
|
)
|
||||||
|
players.append(player)
|
||||||
|
}
|
||||||
|
|
||||||
|
let master: RecordBuffer.Audio = RecordBuffer.Audio(
|
||||||
|
input: dry,
|
||||||
|
buffer: buffers[0],
|
||||||
|
loop: false,
|
||||||
|
doneAction: .nothing
|
||||||
|
)
|
||||||
|
master.run = 0.0
|
||||||
|
masterRecorder = master
|
||||||
|
|
||||||
|
trackHasContent = [Bool](repeating: false, count: LooperPedal.trackCount)
|
||||||
|
trackMuted = [Bool](repeating: false, count: LooperPedal.trackCount)
|
||||||
|
|
||||||
|
// Loop bank audible only while playing and not muted; smoothed to avoid clicks.
|
||||||
|
let combinedGate: any ValidGeneratorInput = $isPlaying * $loopOn
|
||||||
|
let smoothedGate: Lag.Control = Lag.Control(input: combinedGate, time: $crossfadeTime)
|
||||||
|
|
||||||
|
// Sum all track players, each scaled by its smoothed per-track mute gate. Empty buffers
|
||||||
|
// contribute silence. Each player is already scaled by the `Playback` level, so `Playback`
|
||||||
|
// sets the loop amount against the live signal below.
|
||||||
|
var loopSum: any ValidGeneratorInput =
|
||||||
|
players[0] * Lag.Control(input: muteGates[0], time: $crossfadeTime)
|
||||||
|
for i: Int in 1 ..< players.count {
|
||||||
|
loopSum = loopSum + players[i] * Lag.Control(input: muteGates[i], time: $crossfadeTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The clean (dry) signal always passes through at full level; the loop bank is added on
|
||||||
|
// top, gated by play/mute. `Playback` controls the looped-vs-live balance.
|
||||||
|
return dry + (loopSum * smoothedGate)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Loop footswitch
|
||||||
|
|
||||||
|
/// The smart transport press. Behaviour depends on the current phase and selected track.
|
||||||
|
public func pressLoop() {
|
||||||
|
switch phase {
|
||||||
|
case .clear: armMasterRecording()
|
||||||
|
case .recordingMaster: armCloseMaster()
|
||||||
|
case .playing: toggleOverdubSelected()
|
||||||
|
case .stopped: resumePlayback()
|
||||||
|
case .armedRecord, .armedClose:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Handles a tap on a track dot: selects the track, or — when it is already the selected track
|
||||||
|
/// and holds recorded material — toggles its mute. So a first tap focuses a track (to overdub
|
||||||
|
/// or record it), and a second tap on that same recorded track mutes/unmutes it.
|
||||||
|
public func tapTrack(_ index: Int) {
|
||||||
|
guard index >= 0, index < LooperPedal.trackCount, !buffers.isEmpty else { return }
|
||||||
|
if index == selectedTrack, trackHasContent(index) {
|
||||||
|
toggleTrackMute(index)
|
||||||
|
} else {
|
||||||
|
selectTrack(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `true` if track `index` is currently muted.
|
||||||
|
public func isTrackMuted(_ index: Int) -> Bool {
|
||||||
|
index >= 0 && index < trackMuted.count && trackMuted[index]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Toggles a recorded track's playback mute (smoothed via `crossfadeTime`).
|
||||||
|
private func toggleTrackMute(_ index: Int) {
|
||||||
|
guard trackMuted.indices.contains(index), muteGates.indices.contains(index) else { return }
|
||||||
|
trackMuted[index].toggle()
|
||||||
|
muteGates[index].value = trackMuted[index] ? 0.0 : 1.0
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Selects the active track (the one Loop records / overdubs into). Only track A is selectable
|
||||||
|
/// while clear. Selecting a new track ends any overdub on the previous one (it drops to
|
||||||
|
/// playback); the new track records nothing until Loop.
|
||||||
|
public func selectTrack(_ index: Int) {
|
||||||
|
guard index >= 0, index < LooperPedal.trackCount, index != selectedTrack, !buffers.isEmpty else { return }
|
||||||
|
switch phase {
|
||||||
|
case .clear:
|
||||||
|
return // only track A while clear
|
||||||
|
case .armedRecord, .recordingMaster, .armedClose:
|
||||||
|
return // not mid master-record
|
||||||
|
case .playing, .stopped:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
overdubbingTrack = nil // selecting elsewhere ends the current overdub
|
||||||
|
selectedTrack = index
|
||||||
|
updateOverdubGates()
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Stops / reset
|
||||||
|
|
||||||
|
/// Advances the Sync mode through its options (Free ↔ Sync), wrapping — so a MIDI switch can
|
||||||
|
/// oscillate through the positions on each press, matching the segmented control.
|
||||||
|
public func cycleSyncMode() {
|
||||||
|
guard let sync: PedalSwitch = effectSwitches.first(where: { $0.node === $syncToBeat }) else { return }
|
||||||
|
syncToBeat = sync.nextValue(after: syncToBeat)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Flips playback direction from the current play-head position. In Sync mode the flip is
|
||||||
|
/// deferred to the next beat; in Free mode (or with no clock/engine, or when not playing) it
|
||||||
|
/// applies immediately. Engaging reverse ends any active overdub, since overdub records
|
||||||
|
/// forward-in-time and can't follow a backward-reading play-head (see the class doc).
|
||||||
|
public func toggleReverse() {
|
||||||
|
reverseRoutine?.stop()
|
||||||
|
reverseRoutine = nil
|
||||||
|
|
||||||
|
// Not playing: no live play-head to reverse — just flip the direction for the next start.
|
||||||
|
guard phase == .playing else {
|
||||||
|
applyReverse(at: hostEngine?.currentTime ?? playHeadAnchorSample)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
reverseGeneration += 1
|
||||||
|
let generation: Int = reverseGeneration
|
||||||
|
|
||||||
|
// Free mode, or no clock/engine to schedule against → reverse immediately from here.
|
||||||
|
guard syncToBeat >= 0.5, let clock: LyrebirdClock = clock, let engine: SynthesisEngine = hostEngine else {
|
||||||
|
applyReverse(at: hostEngine?.currentTime ?? playHeadAnchorSample)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sync mode: reverse on the next beat, from wherever the play-head is at that beat.
|
||||||
|
let target: SampleTime = clock.nextBeat()
|
||||||
|
let routine: LyrebirdRoutine = LyrebirdRoutine { [weak self] ctx in
|
||||||
|
try ctx.waitUntil(sampleTime: target)
|
||||||
|
DispatchQueue.main.async { self?.applyDeferredReverse(generation: generation, at: target) }
|
||||||
|
}
|
||||||
|
reverseRoutine = routine
|
||||||
|
routine.start(engine: engine)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Applies a beat-deferred reverse once its target beat is reached, unless superseded by a
|
||||||
|
/// newer reverse press or a transport change.
|
||||||
|
func applyDeferredReverse(generation: Int, at beatSample: SampleTime) {
|
||||||
|
guard generation == reverseGeneration, phase == .playing else { return }
|
||||||
|
reverseRoutine = nil
|
||||||
|
applyReverse(at: beatSample)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Flips the playback direction, re-anchoring the position read-out to the current play-head so
|
||||||
|
/// it continues smoothly in the new direction. `sample` is the point the flip takes effect.
|
||||||
|
func applyReverse(at sample: SampleTime) {
|
||||||
|
let engagingReverse: Bool = reverse < 0.5
|
||||||
|
// Re-anchor at the current play-head fraction *before* flipping, so the new-direction
|
||||||
|
// accumulation starts from where we actually are.
|
||||||
|
playHeadAnchor01 = playHeadFraction(at: sample)
|
||||||
|
playHeadAnchorSample = sample
|
||||||
|
reverse = engagingReverse ? 1.0 : 0.0
|
||||||
|
if engagingReverse, overdubbingTrack != nil {
|
||||||
|
overdubbingTrack = nil
|
||||||
|
updateOverdubGates()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Immediately halts playback of all tracks; recorded content is retained (resume via Loop).
|
||||||
|
public func stopPlayback() {
|
||||||
|
guard phase == .playing else { return }
|
||||||
|
transportGeneration += 1
|
||||||
|
stopRoutine?.stop()
|
||||||
|
stopRoutine = nil
|
||||||
|
reverseRoutine?.stop()
|
||||||
|
reverseRoutine = nil
|
||||||
|
cueStopArmed = 0.0
|
||||||
|
overdubbingTrack = nil
|
||||||
|
updateOverdubGates()
|
||||||
|
isPlaying = 0.0
|
||||||
|
playTrigger = 0.0 // rearm the play-head reset edge
|
||||||
|
stoppedIndicator = 1.0
|
||||||
|
phase = .stopped
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Arms (or cancels) a stop that fires when the loop next reaches its end. No-op unless
|
||||||
|
/// playing. With no engine to schedule against, stops now.
|
||||||
|
public func toggleStopAtLoopEnd() {
|
||||||
|
if isStopAtLoopEndArmed {
|
||||||
|
stopRoutine?.stop()
|
||||||
|
stopRoutine = nil
|
||||||
|
cueStopArmed = 0.0
|
||||||
|
transportGeneration += 1
|
||||||
|
return
|
||||||
|
}
|
||||||
|
guard phase == .playing, masterLength > 0 else { return }
|
||||||
|
transportGeneration += 1
|
||||||
|
let generation: Int = transportGeneration
|
||||||
|
guard let engine: SynthesisEngine = hostEngine else {
|
||||||
|
stopPlayback()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let frames: SampleTime = SampleTime(masterLength)
|
||||||
|
let elapsed: SampleTime = max(0, engine.currentTime - playStartSample)
|
||||||
|
let boundary: SampleTime = playStartSample + (elapsed / frames + 1) * frames
|
||||||
|
cueStopArmed = 1.0
|
||||||
|
stopRoutine?.stop()
|
||||||
|
let routine: LyrebirdRoutine = LyrebirdRoutine { [weak self] ctx in
|
||||||
|
try ctx.waitUntil(sampleTime: boundary)
|
||||||
|
DispatchQueue.main.async { self?.applyStopAtLoopEnd(generation: generation) }
|
||||||
|
}
|
||||||
|
stopRoutine = routine
|
||||||
|
routine.start(engine: engine)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Applies an armed "stop at end" once the boundary is reached, unless superseded.
|
||||||
|
func applyStopAtLoopEnd(generation: Int) {
|
||||||
|
guard generation == transportGeneration, phase == .playing else { return }
|
||||||
|
cueStopArmed = 0.0
|
||||||
|
overdubbingTrack = nil
|
||||||
|
updateOverdubGates()
|
||||||
|
isPlaying = 0.0
|
||||||
|
playTrigger = 0.0
|
||||||
|
stoppedIndicator = 1.0
|
||||||
|
phase = .stopped
|
||||||
|
}
|
||||||
|
|
||||||
|
/// When the engine is stopped by the user, drop any recorded loop and return to the clear
|
||||||
|
/// state — a stopped engine can't keep a loop running, and resuming into a half-recorded take
|
||||||
|
/// is confusing. Posts a notice to the message log and briefly on the pedal's own card.
|
||||||
|
public override func engineDidStop() {
|
||||||
|
resetAndNotify("engine stopped")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The rig is being torn down (load / clear / input-source change) — reset before this looper
|
||||||
|
/// instance is discarded, stopping any background routines cleanly and logging a notice.
|
||||||
|
public override func rigWillTeardown() {
|
||||||
|
resetAndNotify("rig changed")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns to the clear state and posts a notice (message log + briefly on the pedal card),
|
||||||
|
/// unless already clear. Shared by ``engineDidStop()`` and ``rigWillTeardown()``.
|
||||||
|
private func resetAndNotify(_ reason: String) {
|
||||||
|
guard phase != .clear else { return }
|
||||||
|
resetLoop()
|
||||||
|
let message: String = "Looper reset — \(reason)."
|
||||||
|
noticeText = message
|
||||||
|
noticeExpiry = Date().addingTimeInterval(LooperPedal.noticeDuration)
|
||||||
|
LyrebirdMessageCenter.shared.info(message, source: displayName)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the pedal to the clear state: all tracks cleared, track A selected, length reset.
|
||||||
|
/// If sound is playing it acts as an immediate stop-and-clear.
|
||||||
|
public func resetLoop() {
|
||||||
|
transportRoutine?.stop()
|
||||||
|
transportRoutine = nil
|
||||||
|
stopRoutine?.stop()
|
||||||
|
stopRoutine = nil
|
||||||
|
reverseRoutine?.stop()
|
||||||
|
reverseRoutine = nil
|
||||||
|
transportGeneration += 1
|
||||||
|
|
||||||
|
// Gate the recorders off (they run off `$isPlaying`) and stop the master BEFORE clearing,
|
||||||
|
// so the only overlap with `clear()` is at most the one RT block already in flight.
|
||||||
|
isPlaying = 0.0
|
||||||
|
masterRecorder?.run = 0.0
|
||||||
|
masterRecorder?.requestReset()
|
||||||
|
for recorder: RecordBuffer.Audio in overdubRecorders {
|
||||||
|
recorder.requestReset()
|
||||||
|
}
|
||||||
|
// `clear()` zeroes the buffers on the main thread. `isPlaying = 0` above stops the
|
||||||
|
// recorders from the next block on, so `clear()` can overlap only the single in-flight
|
||||||
|
// RT block; that overlap is benign because `LyrebirdBuffer.clear()` (`vDSP_vclrD`) and
|
||||||
|
// the recorder both write whole 8-byte-aligned `Double` slots — no torn value — and the
|
||||||
|
// buffer is being zeroed anyway. Deferring the clear would instead race a fast
|
||||||
|
// reset→re-record, so it runs immediately.
|
||||||
|
for buffer: LyrebirdBuffer in buffers {
|
||||||
|
buffer.clear()
|
||||||
|
buffer.setLoopLength(buffer.count)
|
||||||
|
}
|
||||||
|
for i: Int in trackHasContent.indices {
|
||||||
|
trackHasContent[i] = false
|
||||||
|
}
|
||||||
|
for i: Int in trackMuted.indices {
|
||||||
|
trackMuted[i] = false
|
||||||
|
}
|
||||||
|
for gate: ParameterNode in muteGates {
|
||||||
|
gate.value = 1.0
|
||||||
|
}
|
||||||
|
selectedTrack = 0
|
||||||
|
overdubbingTrack = nil
|
||||||
|
masterLength = 0
|
||||||
|
masterBeats = 0.0
|
||||||
|
loopOn = 1.0
|
||||||
|
reverse = 0.0 // clean slate: forward playback
|
||||||
|
playTrigger = 0.0
|
||||||
|
stoppedIndicator = 0.0
|
||||||
|
cueStopArmed = 0.0
|
||||||
|
// Drop any lingering transient notice so it can't mask the fresh state indicator.
|
||||||
|
noticeText = nil
|
||||||
|
noticeExpiry = nil
|
||||||
|
updateOverdubGates()
|
||||||
|
phase = .clear
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Transport helpers
|
||||||
|
|
||||||
|
/// Clears the per-track generator arrays and returns transport state to clear, so a graph
|
||||||
|
/// rebuild (`build()` re-run) starts fresh instead of doubling the arrays or leaving state
|
||||||
|
/// that references the discarded buffers. Called at the top of ``effect(_:)``.
|
||||||
|
private func resetForRebuild() {
|
||||||
|
transportRoutine?.stop()
|
||||||
|
transportRoutine = nil
|
||||||
|
stopRoutine?.stop()
|
||||||
|
stopRoutine = nil
|
||||||
|
reverseRoutine?.stop()
|
||||||
|
reverseRoutine = nil
|
||||||
|
buffers.removeAll()
|
||||||
|
players.removeAll()
|
||||||
|
overdubRecorders.removeAll()
|
||||||
|
overdubGates.removeAll()
|
||||||
|
muteGates.removeAll()
|
||||||
|
masterRecorder = nil
|
||||||
|
trackHasContent = []
|
||||||
|
trackMuted = []
|
||||||
|
selectedTrack = 0
|
||||||
|
overdubbingTrack = nil
|
||||||
|
masterLength = 0
|
||||||
|
masterBeats = 0.0
|
||||||
|
isPlaying = 0.0
|
||||||
|
loopOn = 1.0
|
||||||
|
reverse = 0.0
|
||||||
|
playTrigger = 0.0
|
||||||
|
stoppedIndicator = 0.0
|
||||||
|
cueStopArmed = 0.0
|
||||||
|
overdubIndicator = 0.0
|
||||||
|
noticeText = nil
|
||||||
|
noticeExpiry = nil
|
||||||
|
phase = .clear
|
||||||
|
}
|
||||||
|
|
||||||
|
private func updateOverdubGates() {
|
||||||
|
for i: Int in overdubGates.indices {
|
||||||
|
overdubGates[i].value = (overdubbingTrack == i) ? 1.0 : 0.0
|
||||||
|
}
|
||||||
|
overdubIndicator = overdubbingTrack != nil ? 1.0 : 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
private func toggleOverdubSelected() {
|
||||||
|
if overdubbingTrack == selectedTrack {
|
||||||
|
overdubbingTrack = nil
|
||||||
|
} else {
|
||||||
|
// Overdub records forward-in-time; a reversed player reads backward, so engaging
|
||||||
|
// overdub while reversed would write out of alignment with what's heard. Block it.
|
||||||
|
guard reverse < 0.5 else { return }
|
||||||
|
overdubbingTrack = selectedTrack
|
||||||
|
if trackHasContent.indices.contains(selectedTrack) { trackHasContent[selectedTrack] = true }
|
||||||
|
}
|
||||||
|
updateOverdubGates()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// (Re)starts playback of all tracks from the top, optionally overdubbing `overdubTrack`.
|
||||||
|
///
|
||||||
|
/// The recorder write heads (`requestReset`) and the player play-heads (`playTrigger` rising
|
||||||
|
/// edge) are both reset **synchronously here** so they take effect on the same next audio
|
||||||
|
/// block — keeping overdub writes phase-locked to playback. `playTrigger` is zeroed on every
|
||||||
|
/// stop so each start is a clean `0 → 1` edge.
|
||||||
|
private func startPlayback(overdubTrack: Int?, at sample: SampleTime) {
|
||||||
|
for recorder: RecordBuffer.Audio in overdubRecorders {
|
||||||
|
recorder.requestReset() // realign every write head to the top
|
||||||
|
}
|
||||||
|
playStartSample = sample
|
||||||
|
// Play head resets to the top (frame 0) via the playTrigger edge below; anchor the
|
||||||
|
// position read-out there so direction changes accumulate from a known origin.
|
||||||
|
playHeadAnchor01 = 0.0
|
||||||
|
playHeadAnchorSample = sample
|
||||||
|
isPlaying = 1.0
|
||||||
|
stoppedIndicator = 0.0
|
||||||
|
overdubbingTrack = overdubTrack
|
||||||
|
if let track: Int = overdubTrack, trackHasContent.indices.contains(track) {
|
||||||
|
trackHasContent[track] = true
|
||||||
|
}
|
||||||
|
updateOverdubGates()
|
||||||
|
playTrigger = 1.0 // rising edge, same block as the resets
|
||||||
|
phase = .playing
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Resumes playback of all active tracks from a stopped state.
|
||||||
|
private func resumePlayback() {
|
||||||
|
guard phase == .stopped, masterLength > 0 else { return }
|
||||||
|
transportGeneration += 1
|
||||||
|
startPlayback(overdubTrack: nil, at: hostEngine?.currentTime ?? 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
enum QuantizedAction: Sendable {
|
||||||
|
case beginMaster
|
||||||
|
case closeMaster
|
||||||
|
}
|
||||||
|
|
||||||
|
private func armMasterRecording() {
|
||||||
|
selectedTrack = 0 // only track A in the clear state
|
||||||
|
updateOverdubGates()
|
||||||
|
phase = .armedRecord
|
||||||
|
runQuantized(.beginMaster)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func armCloseMaster() {
|
||||||
|
phase = .armedClose
|
||||||
|
runQuantized(.closeMaster)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func runQuantized(_ action: QuantizedAction) {
|
||||||
|
transportGeneration += 1
|
||||||
|
let generation: Int = transportGeneration
|
||||||
|
// Freeform (Sync off) or no clock/engine → apply immediately, un-quantized.
|
||||||
|
guard syncToBeat >= 0.5, let clock: LyrebirdClock = clock, let engine: SynthesisEngine = hostEngine else {
|
||||||
|
applyQuantizedTransport(action, generation: generation, at: nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
transportRoutine?.stop()
|
||||||
|
let target: SampleTime = clock.nextBeat()
|
||||||
|
let routine: LyrebirdRoutine = LyrebirdRoutine { [weak self] ctx in
|
||||||
|
try ctx.waitUntil(sampleTime: target)
|
||||||
|
DispatchQueue.main.async { self?.applyQuantizedTransport(action, generation: generation, at: target) }
|
||||||
|
}
|
||||||
|
transportRoutine = routine
|
||||||
|
routine.start(engine: engine)
|
||||||
|
}
|
||||||
|
|
||||||
|
func applyQuantizedTransport(_ action: QuantizedAction, generation: Int, at beatSample: SampleTime?) {
|
||||||
|
guard generation == transportGeneration else { return }
|
||||||
|
switch action {
|
||||||
|
case .beginMaster: beginMasterRecording(at: beatSample)
|
||||||
|
case .closeMaster: closeMasterAndPlay(at: beatSample)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func beginMasterRecording(at beatSample: SampleTime?) {
|
||||||
|
guard phase == .armedRecord, let master: RecordBuffer.Audio = masterRecorder else { return }
|
||||||
|
recordStartSample = beatSample ?? (hostEngine?.currentTime ?? 0)
|
||||||
|
master.run = 1.0
|
||||||
|
phase = .recordingMaster
|
||||||
|
}
|
||||||
|
|
||||||
|
func closeMasterAndPlay(at beatSample: SampleTime?) {
|
||||||
|
guard phase == .armedClose, let master: RecordBuffer.Audio = masterRecorder, !buffers.isEmpty else { return }
|
||||||
|
master.run = 0.0
|
||||||
|
|
||||||
|
let closeSample: SampleTime = beatSample ?? (hostEngine?.currentTime ?? 0)
|
||||||
|
if let clock: LyrebirdClock = clock, beatSample != nil {
|
||||||
|
let spanFrames: Int = Int(closeSample - recordStartSample)
|
||||||
|
masterLength = max(LooperPedal.minimumLoopFrames, spanFrames)
|
||||||
|
masterBeats = beatsForSpan(frames: masterLength, clock: clock)
|
||||||
|
} else {
|
||||||
|
masterLength = max(LooperPedal.minimumLoopFrames, master.recordedFrameCount)
|
||||||
|
masterBeats = 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
for buffer: LyrebirdBuffer in buffers {
|
||||||
|
buffer.setLoopLength(masterLength)
|
||||||
|
}
|
||||||
|
if trackHasContent.indices.contains(0) { trackHasContent[0] = true }
|
||||||
|
// Auto-drop into overdub on track A as it wraps to the top (unless reversed — overdub
|
||||||
|
// can't follow reverse playback, so just play).
|
||||||
|
startPlayback(overdubTrack: reverse < 0.5 ? 0 : nil, at: closeSample)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whole-beat length of a `frames`-long span at the clock's current tempo (UI read-out only).
|
||||||
|
func beatsForSpan(frames: Int, clock: LyrebirdClock) -> Double {
|
||||||
|
let samplesPerBeat: Double = Double(clock.sampleTime(beat: 1.0) - clock.sampleTime(beat: 0.0))
|
||||||
|
guard samplesPerBeat > 0 else { return 0.0 }
|
||||||
|
return (Double(frames) / samplesPerBeat).rounded()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// LooperTransportState.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
/// Publicly-observable transport phase of the multitrack ``LooperPedal``, surfaced for the UI
|
||||||
|
/// so it can colour the state indicator, animate the "waiting for the next beat" armed states,
|
||||||
|
/// and drive the loop timeline.
|
||||||
|
///
|
||||||
|
/// The pedal is a synchronized multitrack looper: track A's first take defines the master loop
|
||||||
|
/// length, and tracks B–D are overdub layers recorded onto the same grid, all playing at once.
|
||||||
|
public enum LooperTransportState: Sendable, Equatable {
|
||||||
|
|
||||||
|
/// No material recorded on any track. Only track A can be selected; press Loop to record it.
|
||||||
|
case clear
|
||||||
|
|
||||||
|
/// A Loop press has been made in the clear state and the pedal is waiting for the next beat
|
||||||
|
/// to start recording track A.
|
||||||
|
case armedRecord
|
||||||
|
|
||||||
|
/// Recording track A's first take, which defines the master loop length.
|
||||||
|
case recordingMaster
|
||||||
|
|
||||||
|
/// A Loop press closed the master take and the pedal is waiting for the next beat to set the
|
||||||
|
/// loop end.
|
||||||
|
case armedClose
|
||||||
|
|
||||||
|
/// Looping playback of all recorded tracks. The selected track may be overdubbing.
|
||||||
|
case playing
|
||||||
|
|
||||||
|
/// Playback paused by a stop, with recorded material still loaded (ready to resume).
|
||||||
|
case stopped
|
||||||
|
}
|
||||||
@@ -90,6 +90,12 @@ public final class ModulationPedal: Pedal {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override var tempoSyncableParams: [TempoSyncableParam] {
|
||||||
|
[
|
||||||
|
TempoSyncableParam(key: "rate", label: "Rate", node: $rate, kind: .rate, range: rateRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
public override var effectKnobs: [PedalKnob] {
|
public override var effectKnobs: [PedalKnob] {
|
||||||
[
|
[
|
||||||
PedalKnob(label: "Rate", node: $rate, range: rateRange),
|
PedalKnob(label: "Rate", node: $rate, range: rateRange),
|
||||||
|
|||||||
@@ -58,18 +58,26 @@ public final class MultiTapDelayPedal: Pedal {
|
|||||||
// MARK: - Constants
|
// MARK: - Constants
|
||||||
|
|
||||||
/// Maximum supported per-tap delay time in seconds. Sizes each delay-line buffer at init.
|
/// Maximum supported per-tap delay time in seconds. Sizes each delay-line buffer at init.
|
||||||
private let maxDelayTime: Double = 1.0
|
private let maxDelayTime: Double = 5.0
|
||||||
|
|
||||||
/// Partial wet/dry blend so the dry note and its taps coexist.
|
/// Partial wet/dry blend so the dry note and its taps coexist.
|
||||||
private static let defaultMix: Double = 0.4
|
private static let defaultMix: Double = 0.4
|
||||||
|
|
||||||
// MARK: - Ranges
|
// MARK: - Ranges
|
||||||
|
|
||||||
private let timeRange: ClosedRange<Double> = 0.01 ... 1.0
|
private let timeRange: ClosedRange<Double> = 0.01 ... 5.0
|
||||||
private let volRange: ClosedRange<Double> = 0.0 ... 1.0
|
private let volRange: ClosedRange<Double> = 0.0 ... 1.0
|
||||||
|
|
||||||
// MARK: - Knobs
|
// MARK: - Knobs
|
||||||
|
|
||||||
|
public override var tempoSyncableParams: [TempoSyncableParam] {
|
||||||
|
[
|
||||||
|
TempoSyncableParam(key: "time1", label: "Time 1", node: $time1, kind: .time, range: timeRange),
|
||||||
|
TempoSyncableParam(key: "time2", label: "Time 2", node: $time2, kind: .time, range: timeRange),
|
||||||
|
TempoSyncableParam(key: "time3", label: "Time 3", node: $time3, kind: .time, range: timeRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
/// Two rows of three: the three tap times, then the three tap volumes.
|
/// Two rows of three: the three tap times, then the three tap volumes.
|
||||||
public override var effectKnobs: [PedalKnob] {
|
public override var effectKnobs: [PedalKnob] {
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -68,6 +68,12 @@ public final class PhaserPedal: Pedal {
|
|||||||
/// Feedback knob range (all-pass feedback gain).
|
/// Feedback knob range (all-pass feedback gain).
|
||||||
private let feedbackRange: ClosedRange<Double> = 0.0 ... 0.9
|
private let feedbackRange: ClosedRange<Double> = 0.0 ... 0.9
|
||||||
|
|
||||||
|
public override var tempoSyncableParams: [TempoSyncableParam] {
|
||||||
|
[
|
||||||
|
TempoSyncableParam(key: "rate", label: "Rate", node: $rate, kind: .rate, range: rateRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
public override var effectKnobs: [PedalKnob] {
|
public override var effectKnobs: [PedalKnob] {
|
||||||
[
|
[
|
||||||
PedalKnob(label: "Rate", node: $rate, range: rateRange),
|
PedalKnob(label: "Rate", node: $rate, range: rateRange),
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import LyrebirdUI
|
|||||||
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
/// Inherits `mix`, `bypass`, and `level` from `Pedal`, plus:
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - time: Delay time per tap in seconds. Range `[0.05, 1.0]`. Defaults to `0.3`.
|
/// - time: Delay time per tap in seconds. Range `[0.05, 5.0]`. Defaults to `0.3`.
|
||||||
/// - feedback: Feedback as decay time in seconds (time for echoes to fall to −60 dB).
|
/// - feedback: Feedback as decay time in seconds (time for echoes to fall to −60 dB).
|
||||||
/// Range `[0.05, 6.0]`. Defaults to `1.2`.
|
/// Range `[0.05, 6.0]`. Defaults to `1.2`.
|
||||||
public final class PingPongDelayPedal: Pedal {
|
public final class PingPongDelayPedal: Pedal {
|
||||||
@@ -44,7 +44,7 @@ public final class PingPongDelayPedal: Pedal {
|
|||||||
|
|
||||||
// MARK: - Parameters
|
// MARK: - Parameters
|
||||||
|
|
||||||
/// Delay time per tap in seconds. Range [0.05, 1.0].
|
/// Delay time per tap in seconds. Range [0.05, 5.0].
|
||||||
@UIParam public var time: Double = 0.3
|
@UIParam public var time: Double = 0.3
|
||||||
|
|
||||||
/// Feedback decay time in seconds (time to reach −60 dB amplitude). Range [0.05, 6.0].
|
/// Feedback decay time in seconds (time to reach −60 dB amplitude). Range [0.05, 6.0].
|
||||||
@@ -53,7 +53,7 @@ public final class PingPongDelayPedal: Pedal {
|
|||||||
// MARK: - Constants
|
// MARK: - Constants
|
||||||
|
|
||||||
/// Maximum supported delay time in seconds. Sizes both delay lines at init.
|
/// Maximum supported delay time in seconds. Sizes both delay lines at init.
|
||||||
private let maxDelayTime: Double = 1.0
|
private let maxDelayTime: Double = 5.0
|
||||||
|
|
||||||
/// Amplitude target for the `decayTime` calculation (−60 dB).
|
/// Amplitude target for the `decayTime` calculation (−60 dB).
|
||||||
private let targetAmp: Double = 0.001
|
private let targetAmp: Double = 0.001
|
||||||
@@ -67,7 +67,7 @@ public final class PingPongDelayPedal: Pedal {
|
|||||||
// MARK: - UI knobs
|
// MARK: - UI knobs
|
||||||
|
|
||||||
/// Delay-time knob range in seconds.
|
/// Delay-time knob range in seconds.
|
||||||
private let timeRange: ClosedRange<Double> = 0.05 ... 1.0
|
private let timeRange: ClosedRange<Double> = 0.05 ... 5.0
|
||||||
|
|
||||||
/// Feedback (decay-time) knob range in seconds.
|
/// Feedback (decay-time) knob range in seconds.
|
||||||
private let feedbackRange: ClosedRange<Double> = 0.05 ... 6.0
|
private let feedbackRange: ClosedRange<Double> = 0.05 ... 6.0
|
||||||
@@ -96,6 +96,12 @@ public final class PingPongDelayPedal: Pedal {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override var tempoSyncableParams: [TempoSyncableParam] {
|
||||||
|
[
|
||||||
|
TempoSyncableParam(key: "time", label: "Time", node: $time, kind: .time, range: timeRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
public override var effectKnobs: [PedalKnob] {
|
public override var effectKnobs: [PedalKnob] {
|
||||||
[
|
[
|
||||||
PedalKnob(label: "Time", node: $time, range: timeRange),
|
PedalKnob(label: "Time", node: $time, range: timeRange),
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import LyrebirdUI
|
|||||||
/// so the pedal's `Mix` knob sets the wet/dry blend.
|
/// so the pedal's `Mix` knob sets the wet/dry blend.
|
||||||
///
|
///
|
||||||
/// ## Knobs
|
/// ## Knobs
|
||||||
/// - `time`: Reverse segment length in seconds. Range `[0.05, 2.0]`.
|
/// - `time`: Reverse segment length in seconds. Range `[0.05, 5.0]`.
|
||||||
/// - `feedback`: Reverse-trail feedback. Range `[0, 0.95]`.
|
/// - `feedback`: Reverse-trail feedback. Range `[0, 0.95]`.
|
||||||
public final class ReverseDelayPedal: Pedal {
|
public final class ReverseDelayPedal: Pedal {
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ public final class ReverseDelayPedal: Pedal {
|
|||||||
|
|
||||||
// MARK: - Parameters
|
// MARK: - Parameters
|
||||||
|
|
||||||
/// Reverse segment length in seconds. Range [0.05, 2.0].
|
/// Reverse segment length in seconds. Range [0.05, 5.0].
|
||||||
@UIParam public var time: Double = 0.5
|
@UIParam public var time: Double = 0.5
|
||||||
|
|
||||||
/// Reverse-trail feedback. Range [0, 0.95].
|
/// Reverse-trail feedback. Range [0, 0.95].
|
||||||
@@ -38,15 +38,21 @@ public final class ReverseDelayPedal: Pedal {
|
|||||||
private static let defaultMix: Double = 0.5
|
private static let defaultMix: Double = 0.5
|
||||||
|
|
||||||
/// Maximum segment length the buffers are allocated for, in seconds.
|
/// Maximum segment length the buffers are allocated for, in seconds.
|
||||||
private let maxDelayTime: Double = 2.0
|
private let maxDelayTime: Double = 5.0
|
||||||
|
|
||||||
// MARK: - Ranges
|
// MARK: - Ranges
|
||||||
|
|
||||||
private let timeRange: ClosedRange<Double> = 0.05 ... 2.0
|
private let timeRange: ClosedRange<Double> = 0.05 ... 5.0
|
||||||
private let feedbackRange: ClosedRange<Double> = 0.0 ... 0.95
|
private let feedbackRange: ClosedRange<Double> = 0.0 ... 0.95
|
||||||
|
|
||||||
// MARK: - Knobs
|
// MARK: - Knobs
|
||||||
|
|
||||||
|
public override var tempoSyncableParams: [TempoSyncableParam] {
|
||||||
|
[
|
||||||
|
TempoSyncableParam(key: "time", label: "Time", node: $time, kind: .time, range: timeRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
public override var effectKnobs: [PedalKnob] {
|
public override var effectKnobs: [PedalKnob] {
|
||||||
[
|
[
|
||||||
PedalKnob(label: "Time", node: $time, range: timeRange),
|
PedalKnob(label: "Time", node: $time, range: timeRange),
|
||||||
|
|||||||
@@ -63,6 +63,12 @@ public final class TremoloPedal: Pedal {
|
|||||||
/// Depth knob range (modulation fraction).
|
/// Depth knob range (modulation fraction).
|
||||||
private let depthRange: ClosedRange<Double> = 0.0 ... 1.0
|
private let depthRange: ClosedRange<Double> = 0.0 ... 1.0
|
||||||
|
|
||||||
|
public override var tempoSyncableParams: [TempoSyncableParam] {
|
||||||
|
[
|
||||||
|
TempoSyncableParam(key: "rate", label: "Rate", node: $rate, kind: .rate, range: rateRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
public override var effectKnobs: [PedalKnob] {
|
public override var effectKnobs: [PedalKnob] {
|
||||||
[
|
[
|
||||||
PedalKnob(label: "Rate", node: $rate, range: rateRange),
|
PedalKnob(label: "Rate", node: $rate, range: rateRange),
|
||||||
|
|||||||
@@ -50,6 +50,12 @@ public final class VibratoPedal: Pedal {
|
|||||||
|
|
||||||
// MARK: - Knobs
|
// MARK: - Knobs
|
||||||
|
|
||||||
|
public override var tempoSyncableParams: [TempoSyncableParam] {
|
||||||
|
[
|
||||||
|
TempoSyncableParam(key: "rate", label: "Rate", node: $rate, kind: .rate, range: rateRange),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
public override var effectKnobs: [PedalKnob] {
|
public override var effectKnobs: [PedalKnob] {
|
||||||
[
|
[
|
||||||
PedalKnob(label: "Rate", node: $rate, range: rateRange),
|
PedalKnob(label: "Rate", node: $rate, range: rateRange),
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
/// Serialisable snapshot of one `PedalBoard`'s label and full signal-chain topology.
|
/// Serialisable snapshot of one `PedalBoard`'s label and full signal-chain topology.
|
||||||
///
|
///
|
||||||
/// `label` is the board's display name. `segments` captures the chain in signal-flow order:
|
/// `label` is the board's display name. `segments` captures the chain in signal-flow order:
|
||||||
@@ -18,6 +20,11 @@
|
|||||||
/// subset (the whole chain for boards with no split regions) for callers that only need it.
|
/// subset (the whole chain for boards with no split regions) for callers that only need it.
|
||||||
public struct BoardState: Codable, Equatable {
|
public struct BoardState: Codable, Equatable {
|
||||||
|
|
||||||
|
/// Stable per-board identity, persisted so MIDI bindings can address a board by id rather
|
||||||
|
/// than by position. Survives capture → rebuild round-trips. Legacy presets without an id
|
||||||
|
/// decode to a fresh `UUID()`.
|
||||||
|
public let id: UUID
|
||||||
|
|
||||||
/// The board's display label (e.g. `"Board 1"`).
|
/// The board's display label (e.g. `"Board 1"`).
|
||||||
public let label: String
|
public let label: String
|
||||||
|
|
||||||
@@ -39,9 +46,11 @@ public struct BoardState: Codable, Equatable {
|
|||||||
/// - label: The board's display label.
|
/// - label: The board's display label.
|
||||||
/// - segments: Ordered signal-chain segments.
|
/// - segments: Ordered signal-chain segments.
|
||||||
public init(
|
public init(
|
||||||
|
id: UUID = UUID(),
|
||||||
label: String,
|
label: String,
|
||||||
segments: [BoardSegmentState]
|
segments: [BoardSegmentState]
|
||||||
) {
|
) {
|
||||||
|
self.id = id
|
||||||
self.label = label
|
self.label = label
|
||||||
self.segments = segments
|
self.segments = segments
|
||||||
}
|
}
|
||||||
@@ -55,14 +64,17 @@ public struct BoardState: Codable, Equatable {
|
|||||||
/// - label: The board's display label.
|
/// - label: The board's display label.
|
||||||
/// - pedals: Ordered list of pedal state snapshots.
|
/// - pedals: Ordered list of pedal state snapshots.
|
||||||
public init(
|
public init(
|
||||||
|
id: UUID = UUID(),
|
||||||
label: String,
|
label: String,
|
||||||
pedals: [PedalState]
|
pedals: [PedalState]
|
||||||
) {
|
) {
|
||||||
|
self.id = id
|
||||||
self.label = label
|
self.label = label
|
||||||
self.segments = pedals.map { BoardSegmentState.pedal($0) }
|
self.segments = pedals.map { BoardSegmentState.pedal($0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case id
|
||||||
case label
|
case label
|
||||||
case segments
|
case segments
|
||||||
case pedals
|
case pedals
|
||||||
@@ -72,6 +84,7 @@ public struct BoardState: Codable, Equatable {
|
|||||||
/// wrapping each entry as a `.pedal` segment.
|
/// wrapping each entry as a `.pedal` segment.
|
||||||
public init(from decoder: any Decoder) throws {
|
public init(from decoder: any Decoder) throws {
|
||||||
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
|
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
self.id = try container.decodeIfPresent(UUID.self, forKey: .id) ?? UUID()
|
||||||
self.label = try container.decode(String.self, forKey: .label)
|
self.label = try container.decode(String.self, forKey: .label)
|
||||||
if let decodedSegments: [BoardSegmentState] =
|
if let decodedSegments: [BoardSegmentState] =
|
||||||
try container.decodeIfPresent([BoardSegmentState].self, forKey: .segments) {
|
try container.decodeIfPresent([BoardSegmentState].self, forKey: .segments) {
|
||||||
@@ -94,6 +107,7 @@ public struct BoardState: Codable, Equatable {
|
|||||||
/// Encodes the snapshot using the current `segments` representation.
|
/// Encodes the snapshot using the current `segments` representation.
|
||||||
public func encode(to encoder: any Encoder) throws {
|
public func encode(to encoder: any Encoder) throws {
|
||||||
var container: KeyedEncodingContainer<CodingKeys> = encoder.container(keyedBy: CodingKeys.self)
|
var container: KeyedEncodingContainer<CodingKeys> = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(id, forKey: .id)
|
||||||
try container.encode(label, forKey: .label)
|
try container.encode(label, forKey: .label)
|
||||||
try container.encode(segments, forKey: .segments)
|
try container.encode(segments, forKey: .segments)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,12 +21,14 @@ extension Pedal {
|
|||||||
let sliderValues: [Double] = effectSliders.map { $0.node.value }
|
let sliderValues: [Double] = effectSliders.map { $0.node.value }
|
||||||
let selectorValues: [Double] = effectSelectors.map { $0.node.value }
|
let selectorValues: [Double] = effectSelectors.map { $0.node.value }
|
||||||
return PedalState(
|
return PedalState(
|
||||||
|
id: id,
|
||||||
type: displayName,
|
type: displayName,
|
||||||
knobValues: values,
|
knobValues: values,
|
||||||
switchValues: switchValues,
|
switchValues: switchValues,
|
||||||
sliderValues: sliderValues,
|
sliderValues: sliderValues,
|
||||||
selectorValues: selectorValues,
|
selectorValues: selectorValues,
|
||||||
bypass: bypass
|
bypass: bypass,
|
||||||
|
tempoSync: tempoSync.isEmpty ? nil : tempoSync
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,6 +46,9 @@ extension Pedal {
|
|||||||
/// against `displayName` — the caller is responsible for matching types before
|
/// against `displayName` — the caller is responsible for matching types before
|
||||||
/// calling this method.
|
/// calling this method.
|
||||||
public func applyState(_ state: PedalState) {
|
public func applyState(_ state: PedalState) {
|
||||||
|
// Restore the saved identity so the pedal keeps its id across rebuilds; MIDI bindings
|
||||||
|
// address pedals by this id.
|
||||||
|
id = state.id
|
||||||
for (knob, value) in zip(knobs, state.knobValues) {
|
for (knob, value) in zip(knobs, state.knobValues) {
|
||||||
knob.node.update(value)
|
knob.node.update(value)
|
||||||
}
|
}
|
||||||
@@ -57,5 +62,9 @@ extension Pedal {
|
|||||||
selector.node.update(value)
|
selector.node.update(value)
|
||||||
}
|
}
|
||||||
bypass = state.bypass
|
bypass = state.bypass
|
||||||
|
// Restore tempo-sync state. The synced values themselves are recomputed from the rig's
|
||||||
|
// tempo by `ShoeGaze` after the rebuild, so no clock is required here.
|
||||||
|
tempoSync = state.tempoSync ?? [:]
|
||||||
|
tempoSyncRevision.bump()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,6 +45,6 @@ extension PedalBoard {
|
|||||||
return BoardSegmentState.mergeToMono
|
return BoardSegmentState.mergeToMono
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return BoardState(label: label, segments: segmentStates)
|
return BoardState(id: id, label: label, segments: segmentStates)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ public enum PedalRegistry {
|
|||||||
"Bitcrusher": { BitcrusherPedal() },
|
"Bitcrusher": { BitcrusherPedal() },
|
||||||
"Granulator": { GranulatorPedal() },
|
"Granulator": { GranulatorPedal() },
|
||||||
"Auto Granulator": { AutoGranulatorPedal() },
|
"Auto Granulator": { AutoGranulatorPedal() },
|
||||||
|
"Looper": { LooperPedal() },
|
||||||
]
|
]
|
||||||
|
|
||||||
/// Returns a new `Pedal` instance for the given type string, or `nil` if the type
|
/// Returns a new `Pedal` instance for the given type string, or `nil` if the type
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
/// Serialisable snapshot of one pedal's parameter values.
|
/// Serialisable snapshot of one pedal's parameter values.
|
||||||
///
|
///
|
||||||
/// `type` stores the pedal's `displayName` and is used by `PedalRegistry` to
|
/// `type` stores the pedal's `displayName` and is used by `PedalRegistry` to
|
||||||
@@ -16,6 +18,12 @@
|
|||||||
/// knobs at their current value.
|
/// knobs at their current value.
|
||||||
public struct PedalState: Codable, Equatable {
|
public struct PedalState: Codable, Equatable {
|
||||||
|
|
||||||
|
/// Stable per-pedal identity, persisted so MIDI bindings can address a pedal by id rather
|
||||||
|
/// than by chain position. Survives capture → rebuild round-trips (an edit rebuilds the board
|
||||||
|
/// from captured segments, carrying each pedal's id forward). Legacy presets without an id
|
||||||
|
/// decode to a fresh `UUID()`.
|
||||||
|
public let id: UUID
|
||||||
|
|
||||||
/// The pedal's `displayName` — used as a factory key by `PedalRegistry`.
|
/// The pedal's `displayName` — used as a factory key by `PedalRegistry`.
|
||||||
public let type: String
|
public let type: String
|
||||||
|
|
||||||
@@ -37,6 +45,11 @@ public struct PedalState: Codable, Equatable {
|
|||||||
/// Bypass parameter value. `0.0` = engaged, `1.0` = bypassed.
|
/// Bypass parameter value. `0.0` = engaged, `1.0` = bypassed.
|
||||||
public let bypass: Double
|
public let bypass: Double
|
||||||
|
|
||||||
|
/// Tempo-sync state per syncable parameter, keyed by ``TempoSyncableParam/key``. `nil` for a
|
||||||
|
/// pedal with no synced parameters, and for presets saved before tempo sync existed — both
|
||||||
|
/// decode to "all parameters free".
|
||||||
|
public let tempoSync: [String: TempoSync]?
|
||||||
|
|
||||||
/// Creates a pedal state snapshot.
|
/// Creates a pedal state snapshot.
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
@@ -46,40 +59,49 @@ public struct PedalState: Codable, Equatable {
|
|||||||
/// - sliderValues: Current slider values in `Pedal.effectSliders` order. Defaults to empty.
|
/// - sliderValues: Current slider values in `Pedal.effectSliders` order. Defaults to empty.
|
||||||
/// - selectorValues: Current selector values in `Pedal.effectSelectors` order. Defaults to empty.
|
/// - selectorValues: Current selector values in `Pedal.effectSelectors` order. Defaults to empty.
|
||||||
/// - bypass: Bypass parameter value (`0.0` = engaged, `1.0` = bypassed).
|
/// - bypass: Bypass parameter value (`0.0` = engaged, `1.0` = bypassed).
|
||||||
|
/// - tempoSync: Tempo-sync state per syncable parameter, or `nil` for none. Defaults to `nil`.
|
||||||
public init(
|
public init(
|
||||||
|
id: UUID = UUID(),
|
||||||
type: String,
|
type: String,
|
||||||
knobValues: [Double],
|
knobValues: [Double],
|
||||||
switchValues: [Double] = [],
|
switchValues: [Double] = [],
|
||||||
sliderValues: [Double] = [],
|
sliderValues: [Double] = [],
|
||||||
selectorValues: [Double] = [],
|
selectorValues: [Double] = [],
|
||||||
bypass: Double
|
bypass: Double,
|
||||||
|
tempoSync: [String: TempoSync]? = nil
|
||||||
) {
|
) {
|
||||||
|
self.id = id
|
||||||
self.type = type
|
self.type = type
|
||||||
self.knobValues = knobValues
|
self.knobValues = knobValues
|
||||||
self.switchValues = switchValues
|
self.switchValues = switchValues
|
||||||
self.sliderValues = sliderValues
|
self.sliderValues = sliderValues
|
||||||
self.selectorValues = selectorValues
|
self.selectorValues = selectorValues
|
||||||
self.bypass = bypass
|
self.bypass = bypass
|
||||||
|
self.tempoSync = tempoSync
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
case id
|
||||||
case type
|
case type
|
||||||
case knobValues
|
case knobValues
|
||||||
case switchValues
|
case switchValues
|
||||||
case sliderValues
|
case sliderValues
|
||||||
case selectorValues
|
case selectorValues
|
||||||
case bypass
|
case bypass
|
||||||
|
case tempoSync
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decodes a snapshot, tolerating presets saved before `switchValues` / `sliderValues` /
|
/// Decodes a snapshot, tolerating presets saved before `switchValues` / `sliderValues` /
|
||||||
/// `selectorValues` existed by defaulting the missing keys to an empty array.
|
/// `selectorValues` / `tempoSync` existed by defaulting the missing keys.
|
||||||
public init(from decoder: any Decoder) throws {
|
public init(from decoder: any Decoder) throws {
|
||||||
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
|
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
|
self.id = try container.decodeIfPresent(UUID.self, forKey: .id) ?? UUID()
|
||||||
self.type = try container.decode(String.self, forKey: .type)
|
self.type = try container.decode(String.self, forKey: .type)
|
||||||
self.knobValues = try container.decode([Double].self, forKey: .knobValues)
|
self.knobValues = try container.decode([Double].self, forKey: .knobValues)
|
||||||
self.switchValues = try container.decodeIfPresent([Double].self, forKey: .switchValues) ?? []
|
self.switchValues = try container.decodeIfPresent([Double].self, forKey: .switchValues) ?? []
|
||||||
self.sliderValues = try container.decodeIfPresent([Double].self, forKey: .sliderValues) ?? []
|
self.sliderValues = try container.decodeIfPresent([Double].self, forKey: .sliderValues) ?? []
|
||||||
self.selectorValues = try container.decodeIfPresent([Double].self, forKey: .selectorValues) ?? []
|
self.selectorValues = try container.decodeIfPresent([Double].self, forKey: .selectorValues) ?? []
|
||||||
self.bypass = try container.decode(Double.self, forKey: .bypass)
|
self.bypass = try container.decode(Double.self, forKey: .bypass)
|
||||||
|
self.tempoSync = try container.decodeIfPresent([String: TempoSync].self, forKey: .tempoSync)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,14 @@ public struct RigEntry: Codable, Identifiable, Equatable {
|
|||||||
/// The full rig snapshot — every board, segment, and pedal parameter.
|
/// The full rig snapshot — every board, segment, and pedal parameter.
|
||||||
public let state: ShoeGazeState
|
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.
|
/// Creates a rig library entry.
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
@@ -51,11 +59,13 @@ public struct RigEntry: Codable, Identifiable, Equatable {
|
|||||||
/// - savedAt: Save timestamp. Defaults to `Date()` (now). Rounded to the nearest
|
/// - savedAt: Save timestamp. Defaults to `Date()` (now). Rounded to the nearest
|
||||||
/// whole second so persistence round-trips are lossless.
|
/// whole second so persistence round-trips are lossless.
|
||||||
/// - state: The ``ShoeGazeState`` rig snapshot to store.
|
/// - state: The ``ShoeGazeState`` rig snapshot to store.
|
||||||
|
/// - sortIndex: Manual set-list position, or `nil` when unplaced. Defaults to `nil`.
|
||||||
public init(
|
public init(
|
||||||
id: UUID = UUID(),
|
id: UUID = UUID(),
|
||||||
name: String,
|
name: String,
|
||||||
savedAt: Date = Date(),
|
savedAt: Date = Date(),
|
||||||
state: ShoeGazeState
|
state: ShoeGazeState,
|
||||||
|
sortIndex: Int? = nil
|
||||||
) {
|
) {
|
||||||
self.id = id
|
self.id = id
|
||||||
self.name = name
|
self.name = name
|
||||||
@@ -64,6 +74,16 @@ public struct RigEntry: Codable, Identifiable, Equatable {
|
|||||||
// disk round-trip.
|
// disk round-trip.
|
||||||
self.savedAt = Date(timeIntervalSince1970: savedAt.timeIntervalSince1970.rounded())
|
self.savedAt = Date(timeIntervalSince1970: savedAt.timeIntervalSince1970.rounded())
|
||||||
self.state = state
|
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
|
/// 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,
|
name: String,
|
||||||
date: Date = Date()
|
date: Date = Date()
|
||||||
) -> RigEntry {
|
) -> 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
|
/// 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,
|
to name: String,
|
||||||
date: Date = Date()
|
date: Date = Date()
|
||||||
) -> RigEntry {
|
) -> 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
|
/// asynchronously on a background queue and only logs on failure — call
|
||||||
/// ``flushPendingWrites()`` to wait for it (e.g. in tests or at app termination).
|
/// ``flushPendingWrites()`` to wait for it (e.g. in tests or at app termination).
|
||||||
public func save(_ entry: RigEntry) throws {
|
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
|
// 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.
|
// update the in-memory list immediately and push the disk write to the background queue.
|
||||||
let data: Data = try encode(entry)
|
let data: Data = try encode(placed)
|
||||||
let target: URL = fileURL(for: entry)
|
let target: URL = fileURL(for: placed)
|
||||||
let directory: URL = self.directory
|
let directory: URL = self.directory
|
||||||
let id: UUID = entry.id
|
let id: UUID = placed.id
|
||||||
let coordinated: Bool = isICloud
|
let coordinated: Bool = isICloud
|
||||||
upsert(entry)
|
upsert(placed)
|
||||||
ioQueue.async {
|
ioQueue.async {
|
||||||
// Remove any prior file for this id first (a rename changes the name-prefixed filename).
|
// 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),
|
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.
|
/// Deletes `entry` from memory immediately and removes its file on the background queue.
|
||||||
///
|
///
|
||||||
/// - Parameter entry: The rig entry to remove.
|
/// - Parameter entry: The rig entry to remove.
|
||||||
@@ -328,10 +412,13 @@ public final class RigLibraryStore {
|
|||||||
let existingIDs: Set<UUID> = Set(entries.map(\.id))
|
let existingIDs: Set<UUID> = Set(entries.map(\.id))
|
||||||
var added: Int = 0
|
var added: Int = 0
|
||||||
for entry: RigEntry in imported {
|
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)
|
let toSave: RigEntry = existingIDs.contains(entry.id)
|
||||||
? entry.duplicated(name: entry.name, date: entry.savedAt)
|
? entry.duplicated(name: entry.name, date: entry.savedAt)
|
||||||
: entry
|
: entry.reordered(to: nil)
|
||||||
try save(toSave)
|
try save(toSave)
|
||||||
added += 1
|
added += 1
|
||||||
}
|
}
|
||||||
@@ -549,14 +636,31 @@ public final class RigLibraryStore {
|
|||||||
entries = RigLibraryStore.sorted(next)
|
entries = RigLibraryStore.sorted(next)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sorts entries by name (case-insensitive), then most-recently-saved first, then id for a
|
/// Sorts entries by manual set-list position first (placed entries, ascending), then — for
|
||||||
/// fully deterministic order.
|
/// 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] {
|
private static func sorted(_ entries: [RigEntry]) -> [RigEntry] {
|
||||||
entries.sorted { lhs, rhs in
|
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)
|
let byName: ComparisonResult = lhs.name.localizedCaseInsensitiveCompare(rhs.name)
|
||||||
if byName != .orderedSame { return byName == .orderedAscending }
|
if byName != .orderedSame { return byName == .orderedAscending }
|
||||||
if lhs.savedAt != rhs.savedAt { return lhs.savedAt > rhs.savedAt }
|
if lhs.savedAt != rhs.savedAt { return lhs.savedAt > rhs.savedAt }
|
||||||
return lhs.id.uuidString < rhs.id.uuidString
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,9 +17,19 @@ public enum RigStore {
|
|||||||
private static let folderName: String = "ShoeGaze"
|
private static let folderName: String = "ShoeGaze"
|
||||||
private static let fileName: String = "autosave-rig.json"
|
private static let fileName: String = "autosave-rig.json"
|
||||||
|
|
||||||
|
/// Test-only override for ``autosaveURL``. When non-`nil`, all autosave reads/writes use this
|
||||||
|
/// path instead of the real Application Support location — so a test suite never overwrites or
|
||||||
|
/// deletes the user's actual autosaved rig. Production code leaves this `nil`.
|
||||||
|
///
|
||||||
|
/// - Important: Any test that calls `save`/`restore`/`clear` **must** set this to a temporary
|
||||||
|
/// file first (and reset it after), or it will clobber the running app's autosave.
|
||||||
|
public static var autosaveURLOverride: URL?
|
||||||
|
|
||||||
/// Location of the autosave file, creating the containing folder if needed. `nil` if the
|
/// Location of the autosave file, creating the containing folder if needed. `nil` if the
|
||||||
/// Application Support directory can't be resolved.
|
/// Application Support directory can't be resolved. Returns ``autosaveURLOverride`` verbatim
|
||||||
|
/// when set (tests).
|
||||||
public static var autosaveURL: URL? {
|
public static var autosaveURL: URL? {
|
||||||
|
if let override: URL = autosaveURLOverride { return override }
|
||||||
let fileManager: FileManager = FileManager.default
|
let fileManager: FileManager = FileManager.default
|
||||||
guard let base: URL = try? fileManager.url(
|
guard let base: URL = try? fileManager.url(
|
||||||
for: .applicationSupportDirectory,
|
for: .applicationSupportDirectory,
|
||||||
|
|||||||
@@ -60,6 +60,35 @@ extension ShoeGaze {
|
|||||||
try rebuildAllBoards(from: snapshot)
|
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.
|
/// Default samples-per-frame captured by the scope tap.
|
||||||
public static let defaultScopeBufferSize: Int = 2_048
|
public static let defaultScopeBufferSize: Int = 2_048
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,15 @@ extension ShoeGaze {
|
|||||||
/// - Returns: A `ShoeGazeState` reflecting the current rig.
|
/// - Returns: A `ShoeGazeState` reflecting the current rig.
|
||||||
public func captureState() -> ShoeGazeState {
|
public func captureState() -> ShoeGazeState {
|
||||||
let boardStates: [BoardState] = boards.map { $0.captureState() }
|
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.
|
/// Captures the current rig as a named ``RigEntry`` suitable for the rig library.
|
||||||
@@ -93,11 +101,45 @@ extension ShoeGaze {
|
|||||||
throw PresetError.unsupportedVersion(state.version)
|
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()
|
teardown()
|
||||||
try rebuildAllBoards(from: state)
|
try rebuildAllBoards(from: state)
|
||||||
// Restore the rig's MIDI bindings after the boards exist, so a MIDIController re-reading the
|
// Restore the rig's MIDI bindings after the boards exist, so a MIDIController re-reading the
|
||||||
// map resolves against the freshly rebuilt boards.
|
// map resolves against the freshly rebuilt boards.
|
||||||
midiMap = state.midiMap
|
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)
|
||||||
|
}
|
||||||
|
// Bring restored tempo-synced parameters in line with the loaded tempo. `setTempoEnabled`
|
||||||
|
// already re-syncs when it runs and is enabled, but an older rig with no saved
|
||||||
|
// `tempoEnabled` skips that path — recompute unconditionally so synced values are correct.
|
||||||
|
if tempoEnabled {
|
||||||
|
applyTempoSyncToAllPedals()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rebuilds every board from a snapshot with all-or-nothing semantics.
|
/// Rebuilds every board from a snapshot with all-or-nothing semantics.
|
||||||
@@ -115,6 +157,7 @@ extension ShoeGaze {
|
|||||||
do {
|
do {
|
||||||
for boardState: BoardState in snapshot.boards {
|
for boardState: BoardState in snapshot.boards {
|
||||||
let board: PedalBoard = try addBoard()
|
let board: PedalBoard = try addBoard()
|
||||||
|
board.id = boardState.id
|
||||||
board.label = boardState.label
|
board.label = boardState.label
|
||||||
try rebuildSegments(boardState.segments, into: board)
|
try rebuildSegments(boardState.segments, into: board)
|
||||||
try finalizeBoard(board)
|
try finalizeBoard(board)
|
||||||
@@ -260,9 +303,14 @@ extension ShoeGaze {
|
|||||||
// can be restored. May be nil when `board` is unmanaged (not in `boards`).
|
// can be restored. May be nil when `board` is unmanaged (not in `boards`).
|
||||||
let oldIndex: Int? = boards.firstIndex(where: { $0 === board })
|
let oldIndex: Int? = boards.firstIndex(where: { $0 === board })
|
||||||
|
|
||||||
|
// MIDI bindings address pedals/boards by UUID (persisted in PedalState/BoardState and
|
||||||
|
// carried through capture → rebuild), so a rebuild needs no binding reconciliation — the
|
||||||
|
// pedal keeps its id, and its binding resolves to it regardless of chain position.
|
||||||
|
|
||||||
// Build the new board FIRST so that any failure leaves the old board intact.
|
// Build the new board FIRST so that any failure leaves the old board intact.
|
||||||
let newBoard: PedalBoard = try addBoard()
|
let newBoard: PedalBoard = try addBoard()
|
||||||
do {
|
do {
|
||||||
|
newBoard.id = state.id
|
||||||
newBoard.label = state.label
|
newBoard.label = state.label
|
||||||
try rebuildSegments(state.segments, into: newBoard)
|
try rebuildSegments(state.segments, into: newBoard)
|
||||||
try finalizeBoard(newBoard)
|
try finalizeBoard(newBoard)
|
||||||
@@ -304,6 +352,12 @@ extension ShoeGaze {
|
|||||||
for (board, boardState) in zip(boards, state.boards) {
|
for (board, boardState) in zip(boards, state.boards) {
|
||||||
applySegmentParams(boardState.segments, to: board.orderedSegments)
|
applySegmentParams(boardState.segments, to: board.orderedSegments)
|
||||||
}
|
}
|
||||||
|
// A recall restores each pedal's tempo-sync state but not its derived values (no clock is
|
||||||
|
// consulted in `Pedal.applyState`), so recompute them against the rig's current tempo —
|
||||||
|
// mirroring the full `loadRig(from:)` path.
|
||||||
|
if tempoEnabled {
|
||||||
|
applyTempoSyncToAllPedals()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Positionally applies segment parameter snapshots to live board segments, including
|
/// Positionally applies segment parameter snapshots to live board segments, including
|
||||||
|
|||||||
@@ -34,37 +34,100 @@ public struct ShoeGazeState: Codable, Equatable {
|
|||||||
/// version bump is required for this additive field.
|
/// version bump is required for this additive field.
|
||||||
public let midiMap: MIDIMap?
|
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.
|
/// Creates a rig state snapshot.
|
||||||
///
|
///
|
||||||
/// - Parameters:
|
/// - Parameters:
|
||||||
/// - version: Preset format version. Defaults to `presetFormatVersion`.
|
/// - version: Preset format version. Defaults to `presetFormatVersion`.
|
||||||
/// - boards: Ordered list of board state snapshots.
|
/// - boards: Ordered list of board state snapshots.
|
||||||
/// - midiMap: The rig's MIDI bindings, or `nil` when there are none. Defaults to `nil`.
|
/// - 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(
|
public init(
|
||||||
version: Int = presetFormatVersion,
|
version: Int = presetFormatVersion,
|
||||||
boards: [BoardState],
|
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.version = version
|
||||||
self.boards = boards
|
self.boards = boards
|
||||||
self.midiMap = midiMap
|
self.midiMap = midiMap
|
||||||
|
self.bpm = bpm
|
||||||
|
self.tempoEnabled = tempoEnabled
|
||||||
|
self.inputSource = inputSource
|
||||||
|
self.numInputChannels = numInputChannels
|
||||||
|
self.numOutputChannels = numOutputChannels
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case version
|
case version
|
||||||
case boards
|
case boards
|
||||||
case midiMap
|
case midiMap
|
||||||
|
case bpm
|
||||||
|
case tempoEnabled
|
||||||
|
case inputSource
|
||||||
|
case numInputChannels
|
||||||
|
case numOutputChannels
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Decodes a rig snapshot, tolerating an absent OR malformed `midiMap`.
|
/// Decodes a rig snapshot, tolerating an absent, malformed, OR legacy-format `midiMap`.
|
||||||
///
|
///
|
||||||
/// The MIDI map is decoded with `try?` so a binding format that this build can't read (e.g. an
|
/// The MIDI map is decoded in three tiers: (1) the current id-based ``MIDIMap``; (2) failing
|
||||||
/// autosave written by an older schema) drops just the bindings — which are re-learnable —
|
/// that, the pre-UUID positional ``LegacyMIDIMap``, migrated to id-based via the boards'
|
||||||
/// rather than throwing and losing the entire rig. `version` and `boards` still decode strictly.
|
/// freshly-decoded ids so old rigs keep their bindings; (3) failing both (absent or unreadable),
|
||||||
|
/// `nil` — dropping just the bindings, which are re-learnable, rather than losing the whole rig.
|
||||||
|
/// `version` and `boards` still decode strictly.
|
||||||
public init(from decoder: Decoder) throws {
|
public init(from decoder: Decoder) throws {
|
||||||
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
|
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
self.version = try container.decode(Int.self, forKey: .version)
|
self.version = try container.decode(Int.self, forKey: .version)
|
||||||
self.boards = try container.decode([BoardState].self, forKey: .boards)
|
let decodedBoards: [BoardState] = try container.decode([BoardState].self, forKey: .boards)
|
||||||
self.midiMap = try? container.decodeIfPresent(MIDIMap.self, forKey: .midiMap) ?? nil
|
self.boards = decodedBoards
|
||||||
|
|
||||||
|
if !container.contains(.midiMap) {
|
||||||
|
self.midiMap = nil
|
||||||
|
} else if let current: MIDIMap = try? container.decode(MIDIMap.self, forKey: .midiMap) {
|
||||||
|
self.midiMap = current
|
||||||
|
} else if let legacy: LegacyMIDIMap = try? container.decode(LegacyMIDIMap.self, forKey: .midiMap) {
|
||||||
|
// Pre-UUID positional map: convert each binding to the id now at that position.
|
||||||
|
self.midiMap = legacy.migrated(boards: decodedBoards)
|
||||||
|
} 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,7 +172,10 @@ extension ShoeGaze {
|
|||||||
/// incorrect bus; the output track is still written.
|
/// incorrect bus; the output track is still written.
|
||||||
/// - `.testLoop` → `boards.first?.headBus.index` (the first board's head bus). Returns `nil`
|
/// - `.testLoop` → `boards.first?.headBus.index` (the first board's head bus). Returns `nil`
|
||||||
/// if there are no boards; the input track is skipped and a note is printed.
|
/// if there are no boards; the input track is skipped and a note is printed.
|
||||||
private func resolvedInputBusIndex() -> Int? {
|
/// Exposed `internal` (not `private`) so other rig-level features that need the clean
|
||||||
|
/// pre-effects input signal — e.g. `ShoeGaze+Tuner.swift` — can reuse this resolution
|
||||||
|
/// instead of duplicating the `.liveInput`/`.testLoop` switch.
|
||||||
|
internal func resolvedInputBusIndex() -> Int? {
|
||||||
switch inputSource {
|
switch inputSource {
|
||||||
case .liveInput(let channel):
|
case .liveInput(let channel):
|
||||||
do {
|
do {
|
||||||
|
|||||||
@@ -104,6 +104,9 @@ public final class ChainRouter {
|
|||||||
|
|
||||||
private let engine: SynthesisEngine
|
private let engine: SynthesisEngine
|
||||||
|
|
||||||
|
/// Shared tempo clock, forwarded to both sub-boards so tempo-aware pedals quantize to beats.
|
||||||
|
private let clock: LyrebirdClock?
|
||||||
|
|
||||||
/// The shared input source (either a `TestLoopSource` or `HardwareInputPassThrough`).
|
/// The shared input source (either a `TestLoopSource` or `HardwareInputPassThrough`).
|
||||||
private let source: any Synthesizer
|
private let source: any Synthesizer
|
||||||
|
|
||||||
@@ -152,9 +155,11 @@ public final class ChainRouter {
|
|||||||
/// - `EngineAddError` if the engine rejects any node insertion.
|
/// - `EngineAddError` if the engine rejects any node insertion.
|
||||||
public init(
|
public init(
|
||||||
engine: SynthesisEngine,
|
engine: SynthesisEngine,
|
||||||
inputSource: InputSource = .testLoop
|
inputSource: InputSource = .testLoop,
|
||||||
|
clock: LyrebirdClock? = nil
|
||||||
) throws {
|
) throws {
|
||||||
self.engine = engine
|
self.engine = engine
|
||||||
|
self.clock = clock
|
||||||
|
|
||||||
// Step 1 — allocate the shared input bus.
|
// Step 1 — allocate the shared input bus.
|
||||||
let inputBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
let inputBus: AudioBus = try engine.busAllocator.allocateAudioBus(channelCount: 1)
|
||||||
@@ -186,8 +191,8 @@ public final class ChainRouter {
|
|||||||
self.source = addedSource
|
self.source = addedSource
|
||||||
|
|
||||||
// Step 3 — create both boards (each allocates its own head bus).
|
// Step 3 — create both boards (each allocates its own head bus).
|
||||||
let createdBoardA: PedalBoard = try PedalBoard(engine: engine)
|
let createdBoardA: PedalBoard = try PedalBoard(engine: engine, clock: clock)
|
||||||
let createdBoardB: PedalBoard = try PedalBoard(engine: engine)
|
let createdBoardB: PedalBoard = try PedalBoard(engine: engine, clock: clock)
|
||||||
self.boardA = createdBoardA
|
self.boardA = createdBoardA
|
||||||
self.boardB = createdBoardB
|
self.boardB = createdBoardB
|
||||||
|
|
||||||
|
|||||||
@@ -60,6 +60,11 @@ public final class ShoeGaze {
|
|||||||
/// The engine that owns all nodes.
|
/// The engine that owns all nodes.
|
||||||
public let engine: SynthesisEngine
|
public let engine: SynthesisEngine
|
||||||
|
|
||||||
|
/// Shared tempo clock for the tempo indicator / tap-tempo and any future
|
||||||
|
/// tempo-synced features. Default `120` BPM. `reconfigureEngine(_:)` rebuilds boards
|
||||||
|
/// against the same `engine` instance, so this clock stays valid across reconfigures.
|
||||||
|
public let clock: LyrebirdClock
|
||||||
|
|
||||||
/// All boards managed by this instance.
|
/// All boards managed by this instance.
|
||||||
public private(set) var boards: [PedalBoard] = []
|
public private(set) var boards: [PedalBoard] = []
|
||||||
|
|
||||||
@@ -96,6 +101,79 @@ public final class ShoeGaze {
|
|||||||
/// (same module, different file) can mutate it.
|
/// (same module, different file) can mutate it.
|
||||||
internal var recordTaps: [RecordTap] = []
|
internal var recordTaps: [RecordTap] = []
|
||||||
|
|
||||||
|
// MARK: - Tuner state
|
||||||
|
|
||||||
|
/// `true` while the tuner is engaged (between `engageTuner()` and `disengageTuner()`).
|
||||||
|
public internal(set) var tunerEngaged: Bool = false
|
||||||
|
|
||||||
|
/// Whether ``ShoeGaze/engageTuner()`` also mutes the rig output for the duration.
|
||||||
|
/// Defaults to `true`. Read and applied only at engage time — toggling this while
|
||||||
|
/// already engaged takes effect on the next engage/disengage cycle.
|
||||||
|
public var tunerMutesRig: Bool = true
|
||||||
|
|
||||||
|
/// The active `TunerTap`, or `nil` while disengaged. `internal` so
|
||||||
|
/// `ShoeGaze+Tuner.swift` (same module, different file) can mutate it.
|
||||||
|
internal var tunerTap: TunerTap?
|
||||||
|
|
||||||
|
/// The scratch control bus allocated for `tunerTap`'s unread passthrough output,
|
||||||
|
/// released on disengage.
|
||||||
|
internal var tunerScratchControlBus: ControlBus?
|
||||||
|
|
||||||
|
/// `rigMuted`'s value at the moment `engageTuner()` muted the rig, so
|
||||||
|
/// `disengageTuner()` can restore it rather than always unmuting.
|
||||||
|
internal var tunerRestoreMuteOnDisengage: Bool = false
|
||||||
|
|
||||||
|
// MARK: - Tempo state
|
||||||
|
|
||||||
|
/// `true` when the tempo indicator (BPM readout / TAP / beat LED) is shown and tempo-synced
|
||||||
|
/// features are available. Toggle with ``setTempoEnabled(_:)``; when turned off, every
|
||||||
|
/// tempo-dependent pedal switch (e.g. the looper's Sync-to-Tempo mode) is forced to its
|
||||||
|
/// first (off) position so nothing keeps quantizing to a hidden clock.
|
||||||
|
public private(set) var tempoEnabled: Bool = true
|
||||||
|
|
||||||
|
/// Timestamps of recent `tapTempo()` calls, oldest first. `internal` so
|
||||||
|
/// `ShoeGaze+Tempo.swift` (same module, different file) can mutate it.
|
||||||
|
internal var tapTimestamps: [Date] = []
|
||||||
|
|
||||||
|
/// Shows or hides the tempo indicator and, when hiding, deactivates every tempo-synced
|
||||||
|
/// control by forcing each ``PedalSwitch/tempoDependent`` switch to its first option.
|
||||||
|
public func setTempoEnabled(_ enabled: Bool) {
|
||||||
|
tempoEnabled = enabled
|
||||||
|
guard !enabled else {
|
||||||
|
// Re-enabling: bring every tempo-synced parameter back in line with the current tempo.
|
||||||
|
applyTempoSyncToAllPedals()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for pedal: Pedal in allPedals() {
|
||||||
|
for pedalSwitch: PedalSwitch in pedal.effectSwitches where pedalSwitch.tempoDependent {
|
||||||
|
if let off: PedalSwitch.Option = pedalSwitch.options.first {
|
||||||
|
pedalSwitch.node.update(off.value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the shared clock's tempo and recomputes every tempo-synced pedal parameter to match.
|
||||||
|
/// Route **all** BPM changes (stepper, tap tempo, MIDI) through here so synced delay times and
|
||||||
|
/// LFO rates follow the tempo. Recompute is skipped while tempo is disabled.
|
||||||
|
///
|
||||||
|
/// - Parameter bpm: The new tempo in beats per minute. A non-positive value is ignored (the
|
||||||
|
/// clock requires a positive tempo); callers that also want an upper bound clamp before calling.
|
||||||
|
public func setBpm(_ bpm: Double) {
|
||||||
|
guard bpm > 0 else { return }
|
||||||
|
clock.bpm = bpm
|
||||||
|
guard tempoEnabled else { return }
|
||||||
|
applyTempoSyncToAllPedals()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Recomputes every tempo-synced parameter on every live pedal from the current tempo.
|
||||||
|
/// `internal` so the preset-restore path (`ShoeGaze+Preset.swift`) can re-sync after a rig load.
|
||||||
|
internal func applyTempoSyncToAllPedals() {
|
||||||
|
for pedal: Pedal in allPedals() {
|
||||||
|
pedal.applyTempoSync()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Scope state
|
// MARK: - Scope state
|
||||||
|
|
||||||
/// Scope tap over the hardware input + output buses, feeding the debug scope view.
|
/// Scope tap over the hardware input + output buses, feeding the debug scope view.
|
||||||
@@ -139,11 +217,58 @@ public final class ShoeGaze {
|
|||||||
) {
|
) {
|
||||||
self.engine = engine
|
self.engine = engine
|
||||||
self.inputSource = inputSource
|
self.inputSource = inputSource
|
||||||
|
clock = LyrebirdClock(engine: engine, bpm: ShoeGaze.defaultTempoBpm)
|
||||||
installScopeTap()
|
installScopeTap()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Board management
|
// MARK: - Board management
|
||||||
|
|
||||||
|
/// Stops the audio engine as a deliberate user action: notifies every pedal via
|
||||||
|
/// ``Pedal/engineDidStop()`` (so stateful pedals like the looper return to a clean state and
|
||||||
|
/// post a notice) and then stops the engine. Use this for the user-facing Stop control — not
|
||||||
|
/// for transient stop-around-rebuild sequences, which call `engine.stop()` directly so
|
||||||
|
/// pedals keep their state across the restart.
|
||||||
|
public func stopEngine() {
|
||||||
|
for pedal: Pedal in allPedals() {
|
||||||
|
pedal.engineDidStop()
|
||||||
|
}
|
||||||
|
engine.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Every live `Pedal` across all main boards and chain-router branches.
|
||||||
|
private func allPedals() -> [Pedal] {
|
||||||
|
var result: [Pedal] = []
|
||||||
|
for board: PedalBoard in boards {
|
||||||
|
result.append(contentsOf: pedals(in: board))
|
||||||
|
}
|
||||||
|
for router: ChainRouter in routers {
|
||||||
|
result.append(contentsOf: pedals(in: router.boardA))
|
||||||
|
result.append(contentsOf: pedals(in: router.boardB))
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Every live `Pedal` in one board, including pedals inside its parallel and stereo-split
|
||||||
|
/// branch sections (branch pedals live in their section objects, not as top-level segments).
|
||||||
|
private func pedals(in board: PedalBoard) -> [Pedal] {
|
||||||
|
var result: [Pedal] = []
|
||||||
|
for segment: BoardSegment in board.orderedSegments {
|
||||||
|
switch segment {
|
||||||
|
case .pedal(let pedal):
|
||||||
|
result.append(pedal)
|
||||||
|
case .parallel(let section):
|
||||||
|
result.append(contentsOf: section.branchA.pedals)
|
||||||
|
result.append(contentsOf: section.branchB.pedals)
|
||||||
|
case .stereoSplit(let section), .stereoUnzip(let section):
|
||||||
|
result.append(contentsOf: section.left.pedals)
|
||||||
|
result.append(contentsOf: section.right.pedals)
|
||||||
|
case .mergeToMono:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
/// Allocates a new `PedalBoard` connected to the engine, wires the input source,
|
/// Allocates a new `PedalBoard` connected to the engine, wires the input source,
|
||||||
/// and returns the board ready for pedals to be added via `board.add(_:)`.
|
/// and returns the board ready for pedals to be added via `board.add(_:)`.
|
||||||
///
|
///
|
||||||
@@ -162,7 +287,7 @@ public final class ShoeGaze {
|
|||||||
/// - `EngineAddError` if the engine rejects a node insertion.
|
/// - `EngineAddError` if the engine rejects a node insertion.
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func addBoard() throws -> PedalBoard {
|
public func addBoard() throws -> PedalBoard {
|
||||||
let board: PedalBoard = try PedalBoard(engine: engine)
|
let board: PedalBoard = try PedalBoard(engine: engine, clock: clock)
|
||||||
board.label = "Board \(boards.count + 1)"
|
board.label = "Board \(boards.count + 1)"
|
||||||
|
|
||||||
// Route the input source to the board head bus.
|
// Route the input source to the board head bus.
|
||||||
@@ -463,6 +588,10 @@ public final class ShoeGaze {
|
|||||||
/// Removes a single board and its associated input source and output master from
|
/// Removes a single board and its associated input source and output master from
|
||||||
/// the engine, then releases the board's buses. The other boards are unaffected.
|
/// the engine, then releases the board's buses. The other boards are unaffected.
|
||||||
///
|
///
|
||||||
|
/// > Note: MIDI bindings address boards/pedals by UUID, so a removed board's bindings simply
|
||||||
|
/// > stop resolving (inert, and invisible in the mapping UI since there is no board/pedal to
|
||||||
|
/// > list) — no binding maintenance is needed here.
|
||||||
|
///
|
||||||
/// - Important: Same async-removal caveat as ``teardown()`` — call with the engine
|
/// - Important: Same async-removal caveat as ``teardown()`` — call with the engine
|
||||||
/// stopped, or accept up to one block of glitch on a still-running engine.
|
/// stopped, or accept up to one block of glitch on a still-running engine.
|
||||||
///
|
///
|
||||||
@@ -548,7 +677,7 @@ public final class ShoeGaze {
|
|||||||
/// - `EngineAddError` if the engine rejects any node insertion.
|
/// - `EngineAddError` if the engine rejects any node insertion.
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func makeChainRouter() throws -> ChainRouter {
|
public func makeChainRouter() throws -> ChainRouter {
|
||||||
let router: ChainRouter = try ChainRouter(engine: engine, inputSource: inputSource)
|
let router: ChainRouter = try ChainRouter(engine: engine, inputSource: inputSource, clock: clock)
|
||||||
routers.append(router)
|
routers.append(router)
|
||||||
return router
|
return router
|
||||||
}
|
}
|
||||||
@@ -601,6 +730,13 @@ public final class ShoeGaze {
|
|||||||
// board buses they reference are released.
|
// board buses they reference are released.
|
||||||
stopRecording()
|
stopRecording()
|
||||||
|
|
||||||
|
// Notify pedals the rig is being torn down (rig load / clear / input-source change), so
|
||||||
|
// stateful pedals like the looper stop their background routines cleanly and post a
|
||||||
|
// notice before their instances are discarded.
|
||||||
|
for pedal: Pedal in allPedals() {
|
||||||
|
pedal.rigWillTeardown()
|
||||||
|
}
|
||||||
|
|
||||||
// Step 1: Remove all engine nodes that write to board buses.
|
// Step 1: Remove all engine nodes that write to board buses.
|
||||||
// Order within this step does not matter; all must finish before bus release.
|
// Order within this step does not matter; all must finish before bus release.
|
||||||
for tap: TestLoopTap in testLoopTaps {
|
for tap: TestLoopTap in testLoopTaps {
|
||||||
|
|||||||
@@ -0,0 +1,74 @@
|
|||||||
|
// NoteDivision.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
/// A rhythmic note value, expressed as a fraction of a bar and measured in quarter-note beats.
|
||||||
|
///
|
||||||
|
/// Used to lock a tempo-syncable pedal parameter (a delay time, an LFO rate) to the shared
|
||||||
|
/// ``ShoeGaze/clock``. The synced period in seconds is `(60 / bpm) * beats`; a delay time uses
|
||||||
|
/// that period directly, an LFO rate uses its inverse (one cycle per division).
|
||||||
|
///
|
||||||
|
/// Cases are ordered longest-first so a stepped selector reads top-to-bottom from slow to fast.
|
||||||
|
public enum NoteDivision: String, Codable, CaseIterable, Sendable {
|
||||||
|
|
||||||
|
/// Whole note — four quarter-note beats.
|
||||||
|
case whole
|
||||||
|
/// Dotted half note — three beats.
|
||||||
|
case dottedHalf
|
||||||
|
/// Half note — two beats.
|
||||||
|
case half
|
||||||
|
/// Dotted quarter note — one and a half beats.
|
||||||
|
case dottedQuarter
|
||||||
|
/// Quarter note — one beat.
|
||||||
|
case quarter
|
||||||
|
/// Dotted eighth note — three-quarters of a beat.
|
||||||
|
case dottedEighth
|
||||||
|
/// Quarter-note triplet — two-thirds of a beat.
|
||||||
|
case quarterTriplet
|
||||||
|
/// Eighth note — half a beat.
|
||||||
|
case eighth
|
||||||
|
/// Eighth-note triplet — one-third of a beat.
|
||||||
|
case eighthTriplet
|
||||||
|
/// Sixteenth note — a quarter of a beat.
|
||||||
|
case sixteenth
|
||||||
|
/// Sixteenth-note triplet — one-sixth of a beat.
|
||||||
|
case sixteenthTriplet
|
||||||
|
|
||||||
|
/// Length of this division in quarter-note beats (a quarter note is `1`).
|
||||||
|
public var beats: Double {
|
||||||
|
switch self {
|
||||||
|
case .whole: return 4.0
|
||||||
|
case .dottedHalf: return 3.0
|
||||||
|
case .half: return 2.0
|
||||||
|
case .dottedQuarter: return 1.5
|
||||||
|
case .quarter: return 1.0
|
||||||
|
case .quarterTriplet: return 2.0 / 3.0
|
||||||
|
case .dottedEighth: return 0.75
|
||||||
|
case .eighth: return 0.5
|
||||||
|
case .eighthTriplet: return 1.0 / 3.0
|
||||||
|
case .sixteenth: return 0.25
|
||||||
|
case .sixteenthTriplet: return 1.0 / 6.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Short label for a selector stop (e.g. `"1/4"`, `"1/8."`, `"1/8T"`).
|
||||||
|
public var label: String {
|
||||||
|
switch self {
|
||||||
|
case .whole: return "1/1"
|
||||||
|
case .dottedHalf: return "1/2."
|
||||||
|
case .half: return "1/2"
|
||||||
|
case .dottedQuarter: return "1/4."
|
||||||
|
case .quarter: return "1/4"
|
||||||
|
case .quarterTriplet: return "1/4T"
|
||||||
|
case .dottedEighth: return "1/8."
|
||||||
|
case .eighth: return "1/8"
|
||||||
|
case .eighthTriplet: return "1/8T"
|
||||||
|
case .sixteenth: return "1/16"
|
||||||
|
case .sixteenthTriplet: return "1/16T"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
// ShoeGaze+Tempo.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
// MARK: - ShoeGaze + Tempo
|
||||||
|
|
||||||
|
extension ShoeGaze {
|
||||||
|
|
||||||
|
/// Default tempo, in BPM, for a newly-created ``ShoeGaze/clock``.
|
||||||
|
public static let defaultTempoBpm: Double = 120.0
|
||||||
|
|
||||||
|
// MARK: - Tap tempo
|
||||||
|
|
||||||
|
/// Minimum plausible interval between taps, in seconds — guards against a double-tap
|
||||||
|
/// or debounce glitch registering as an implausibly fast tempo (`60 / minTapInterval`
|
||||||
|
/// ≈ 300 BPM cap).
|
||||||
|
private static let minTapInterval: TimeInterval = 0.2
|
||||||
|
|
||||||
|
/// Maximum interval since the last tap before the tap history resets — a pause this
|
||||||
|
/// long means the user is starting a new tap-tempo sequence, not continuing one.
|
||||||
|
private static let tapTimeoutInterval: TimeInterval = 2.0
|
||||||
|
|
||||||
|
/// Number of most-recent inter-tap intervals averaged into the computed tempo.
|
||||||
|
private static let tapHistoryCount: Int = 4
|
||||||
|
|
||||||
|
/// Registers one tap-tempo press. Call this each time the user taps (mouse click,
|
||||||
|
/// screen tap, or MIDI trigger). Averages the last few inter-tap intervals and sets
|
||||||
|
/// ``ShoeGaze/clock``'s `bpm` once at least two taps have landed within
|
||||||
|
/// `tapTimeoutInterval` of each other. A pause longer than `tapTimeoutInterval`
|
||||||
|
/// discards prior taps and starts a fresh sequence.
|
||||||
|
public func tapTempo() {
|
||||||
|
let now: Date = Date()
|
||||||
|
if let last: Date = tapTimestamps.last, now.timeIntervalSince(last) > ShoeGaze.tapTimeoutInterval {
|
||||||
|
tapTimestamps.removeAll()
|
||||||
|
}
|
||||||
|
tapTimestamps.append(now)
|
||||||
|
if tapTimestamps.count > ShoeGaze.tapHistoryCount + 1 {
|
||||||
|
tapTimestamps.removeFirst(tapTimestamps.count - (ShoeGaze.tapHistoryCount + 1))
|
||||||
|
}
|
||||||
|
guard tapTimestamps.count >= 2 else { return }
|
||||||
|
|
||||||
|
let intervals: [TimeInterval] = zip(tapTimestamps, tapTimestamps.dropFirst())
|
||||||
|
.map { $1.timeIntervalSince($0) }
|
||||||
|
.filter { $0 >= ShoeGaze.minTapInterval }
|
||||||
|
guard !intervals.isEmpty else { return }
|
||||||
|
|
||||||
|
let averageInterval: TimeInterval = intervals.reduce(0, +) / Double(intervals.count)
|
||||||
|
let secondsPerMinute: Double = 60.0
|
||||||
|
setBpm(secondsPerMinute / averageInterval)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// TempoSync.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
/// Sync state of one tempo-syncable pedal parameter.
|
||||||
|
///
|
||||||
|
/// `.free` leaves the parameter at its stored absolute value (seconds or Hz), controlled by the
|
||||||
|
/// knob as usual. `.division` locks it to a ``NoteDivision`` of the shared ``ShoeGaze/clock`` —
|
||||||
|
/// the value is derived from the current tempo and rewritten whenever the tempo or the division
|
||||||
|
/// changes.
|
||||||
|
public enum TempoSync: Codable, Equatable, Sendable {
|
||||||
|
|
||||||
|
/// Absolute value, knob-controlled. The default for every parameter.
|
||||||
|
case free
|
||||||
|
|
||||||
|
/// Locked to a note division of the live tempo.
|
||||||
|
case division(NoteDivision)
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
// TempoSyncRevision.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Observation
|
||||||
|
|
||||||
|
/// An observable revision counter bumped whenever a pedal's ``Pedal/tempoSync`` state changes.
|
||||||
|
///
|
||||||
|
/// ``Pedal/tempoSync`` is a plain dictionary, not observable, so a SwiftUI view showing the sync
|
||||||
|
/// state (the note-division badge) needs a signal to re-render when the state changes through any
|
||||||
|
/// path — the knob's own picker, a preset load, or a lightweight recall. Reading ``value`` inside a
|
||||||
|
/// view body subscribes it; ``Pedal/setSync(_:for:)`` and `Pedal.applyState(_:)` bump it.
|
||||||
|
@Observable
|
||||||
|
public final class TempoSyncRevision {
|
||||||
|
|
||||||
|
/// Incremented on every ``Pedal/tempoSync`` mutation. Its magnitude is meaningless — only the
|
||||||
|
/// change matters, as an invalidation signal for observing views.
|
||||||
|
public internal(set) var value: Int = 0
|
||||||
|
|
||||||
|
/// Creates a revision counter starting at zero.
|
||||||
|
public init() {}
|
||||||
|
|
||||||
|
/// Bumps the counter, invalidating any view observing ``value``.
|
||||||
|
func bump() {
|
||||||
|
value &+= 1
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
// TempoSyncableParam.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdUI
|
||||||
|
|
||||||
|
/// Descriptor for one pedal parameter that can be locked to the tempo.
|
||||||
|
///
|
||||||
|
/// A ``Pedal`` publishes an array of these (via ``Pedal/tempoSyncableParams``) so the shared
|
||||||
|
/// tempo-sync machinery can recompute and rewrite each synced parameter without knowing the
|
||||||
|
/// concrete pedal type. The stable ``key`` doubles as the persistence key in ``PedalState``.
|
||||||
|
public struct TempoSyncableParam {
|
||||||
|
|
||||||
|
/// How the synced period maps onto the parameter's value.
|
||||||
|
public enum Kind {
|
||||||
|
/// A duration in seconds — the value is the synced period `T` directly (delay time).
|
||||||
|
case time
|
||||||
|
/// A frequency in Hz — the value is `1 / T` (one LFO cycle per division).
|
||||||
|
case rate
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Stable identifier for this parameter within its pedal (e.g. `"time"`, `"time1"`, `"rate"`).
|
||||||
|
/// Used as the ``TempoSync`` dictionary key and the persistence key, so it must never change.
|
||||||
|
public let key: String
|
||||||
|
|
||||||
|
/// Short display label, matching the parameter's knob label.
|
||||||
|
public let label: String
|
||||||
|
|
||||||
|
/// The live parameter node the synced value is written to.
|
||||||
|
public let node: UIParamNode
|
||||||
|
|
||||||
|
/// Whether the value is a duration (`.time`) or a frequency (`.rate`, inverse of the period).
|
||||||
|
public let kind: Kind
|
||||||
|
|
||||||
|
/// Inclusive value range the parameter accepts, in its own units. A synced value outside this
|
||||||
|
/// range is clamped (a long division can exceed a delay's maximum buffered time).
|
||||||
|
public let range: ClosedRange<Double>
|
||||||
|
|
||||||
|
/// Creates a tempo-syncable parameter descriptor.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - key: Stable identifier and persistence key. Must be unique within the pedal and stable
|
||||||
|
/// across versions.
|
||||||
|
/// - label: Short display label, matching the knob label.
|
||||||
|
/// - node: The live parameter node (`pedal.$time`, `pedal.$rate`, …).
|
||||||
|
/// - kind: `.time` for a duration, `.rate` for a frequency (inverse of the period).
|
||||||
|
/// - range: Inclusive value range in the parameter's units; the synced value is clamped to it.
|
||||||
|
public init(
|
||||||
|
key: String,
|
||||||
|
label: String,
|
||||||
|
node: UIParamNode,
|
||||||
|
kind: Kind,
|
||||||
|
range: ClosedRange<Double>
|
||||||
|
) {
|
||||||
|
self.key = key
|
||||||
|
self.label = label
|
||||||
|
self.node = node
|
||||||
|
self.kind = kind
|
||||||
|
self.range = range
|
||||||
|
}
|
||||||
|
|
||||||
|
private static let secondsPerMinute: Double = 60.0
|
||||||
|
|
||||||
|
/// The unclamped parameter value for `division` at `bpm`. For `.time` this is the note's period
|
||||||
|
/// in seconds; for `.rate` it is `1 / period` in Hz (one LFO cycle per division).
|
||||||
|
public func rawValue(for division: NoteDivision, bpm: Double) -> Double {
|
||||||
|
let period: Double = (TempoSyncableParam.secondsPerMinute / bpm) * division.beats
|
||||||
|
switch kind {
|
||||||
|
case .time:
|
||||||
|
return period
|
||||||
|
case .rate:
|
||||||
|
return period > 0 ? 1.0 / period : range.upperBound
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The value actually written for `division` at `bpm`, plus whether it had to be clamped to the
|
||||||
|
/// parameter's range. A clamped result means the division can't be represented accurately at this
|
||||||
|
/// tempo (e.g. a whole note longer than the maximum delay time) — the UI disables/flags it.
|
||||||
|
public func value(for division: NoteDivision, bpm: Double) -> (value: Double, clamped: Bool) {
|
||||||
|
let raw: Double = rawValue(for: division, bpm: bpm)
|
||||||
|
let clampedValue: Double = min(max(raw, range.lowerBound), range.upperBound)
|
||||||
|
return (clampedValue, clampedValue != raw)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
// ShoeGaze+Tuner.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import LyrebirdSynth
|
||||||
|
|
||||||
|
// MARK: - ShoeGaze + Tuner
|
||||||
|
|
||||||
|
extension ShoeGaze {
|
||||||
|
|
||||||
|
// MARK: - Engage / disengage
|
||||||
|
|
||||||
|
/// Engages the tuner: taps the clean pre-effects input and, if ``tunerMutesRig`` is on,
|
||||||
|
/// mutes the rig output for the duration (restoring the prior mute state on disengage).
|
||||||
|
///
|
||||||
|
/// A no-op if already engaged. Prints a note and does nothing if no input bus can be
|
||||||
|
/// resolved (mirrors `startRecording()`'s tolerant `.liveInput`/`.testLoop` fallback).
|
||||||
|
public func engageTuner() {
|
||||||
|
guard !tunerEngaged else { return }
|
||||||
|
guard let busIndex: Int = resolvedInputBusIndex() else {
|
||||||
|
print("[ShoeGaze] engageTuner: no input bus available — tuner not engaged.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
do {
|
||||||
|
// The scratch control bus is allocated once and kept for the session's
|
||||||
|
// lifetime rather than released on every disengage: `engine.remove(_:)` only
|
||||||
|
// enqueues the tap's removal for the next render block, so releasing (and
|
||||||
|
// thus making reallocatable) the bus synchronously here would race a
|
||||||
|
// not-yet-dequeued write from the outgoing tap.
|
||||||
|
let scratchBus: ControlBus
|
||||||
|
if let existing: ControlBus = tunerScratchControlBus {
|
||||||
|
scratchBus = existing
|
||||||
|
} else {
|
||||||
|
scratchBus = try engine.busAllocator.allocateControlBus()
|
||||||
|
tunerScratchControlBus = scratchBus
|
||||||
|
}
|
||||||
|
let tap: TunerTap = TunerTap(inputBusIndex: busIndex, scratchControlBus: scratchBus)
|
||||||
|
try engine.add(tap, position: .after(engine.mainGroup))
|
||||||
|
tunerTap = tap
|
||||||
|
} catch {
|
||||||
|
print("[ShoeGaze] engageTuner: could not add tuner tap. (\(error))")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if tunerMutesRig {
|
||||||
|
tunerRestoreMuteOnDisengage = rigMuted
|
||||||
|
setRigMuted(true)
|
||||||
|
}
|
||||||
|
tunerEngaged = true
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Disengages the tuner and removes its tap. Restores the rig's prior mute state if
|
||||||
|
/// ``engageTuner()`` muted it.
|
||||||
|
///
|
||||||
|
/// The scratch control bus is intentionally NOT released here — see the comment in
|
||||||
|
/// ``engageTuner()``.
|
||||||
|
public func disengageTuner() {
|
||||||
|
guard tunerEngaged else { return }
|
||||||
|
if let tap: TunerTap = tunerTap {
|
||||||
|
_ = engine.remove(tap)
|
||||||
|
}
|
||||||
|
tunerTap = nil
|
||||||
|
|
||||||
|
if tunerMutesRig {
|
||||||
|
setRigMuted(tunerRestoreMuteOnDisengage)
|
||||||
|
}
|
||||||
|
tunerEngaged = false
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Flips ``tunerEngaged`` — convenience for a single stomp-style toggle/MIDI action.
|
||||||
|
public func toggleTunerEngaged() {
|
||||||
|
if tunerEngaged {
|
||||||
|
disengageTuner()
|
||||||
|
} else {
|
||||||
|
engageTuner()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Live pitch read
|
||||||
|
|
||||||
|
/// The most recently detected pitch, in Hz, or `nil` while the tuner is not engaged.
|
||||||
|
/// Safe to poll from a SwiftUI `.task` loop on the main thread.
|
||||||
|
public var currentPitchHz: Double? {
|
||||||
|
guard tunerEngaged else { return nil }
|
||||||
|
return tunerTap?.pitchCapture?.detectedFrequencyHz
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The YIN tracking confidence in `[0, 1]` for the current pitch, or `nil` while the
|
||||||
|
/// tuner is not engaged. `1.0` = certain, `0.0` = no stable pitch. The UI latches its
|
||||||
|
/// display when this drops below its threshold (e.g. during a note attack/restrike).
|
||||||
|
public var currentPitchConfidence: Double? {
|
||||||
|
guard tunerEngaged else { return nil }
|
||||||
|
return tunerTap?.pitchCapture?.detectedConfidence
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
// TunerPitchCapture.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
import Synchronization
|
||||||
|
|
||||||
|
/// Wraps a YIN `FreqTracker` and atomically snapshots its per-block frequency **and
|
||||||
|
/// confidence** into plain `Double`s readable from any thread — the same RT-writes/non-RT-
|
||||||
|
/// polls contract as `ParameterNode`'s atomic value storage, sized down to two scalars.
|
||||||
|
///
|
||||||
|
/// YIN (via `FreqTracker`) is far steadier than zero-crossing detection on a plucked/
|
||||||
|
/// harmonic-rich guitar signal, and its confidence output lets the UI latch the last stable
|
||||||
|
/// reading through low-confidence transients (note attacks, restrikes) instead of ramping
|
||||||
|
/// toward the new pitch. No smoothing is applied here — the raw YIN estimate is stable
|
||||||
|
/// enough, and any smoothing would re-introduce the ramp-on-restrike the latch is meant to
|
||||||
|
/// avoid.
|
||||||
|
///
|
||||||
|
/// Bypasses the `ControlGenerator` sub-block ramp path (matching `SendTrigger.Control`'s
|
||||||
|
/// convention for side-effecting analysis generators).
|
||||||
|
final class TunerPitchCapture: GeneratorBase, ControlGenerator {
|
||||||
|
var previousOutputValue: Double = 0.0
|
||||||
|
|
||||||
|
/// Input decimation factor for the YIN tracker. Lowers the effective analysis rate so a
|
||||||
|
/// fixed 512-sample window reaches down to the low guitar / bass range. At 48 kHz, 8×
|
||||||
|
/// gives an effective 6 kHz rate → ~23 Hz detection floor. The caller (`TunerTap`) must
|
||||||
|
/// band-limit the input below the decimated Nyquist (`sampleRate / 16`) first.
|
||||||
|
static let decimation: Int = 8
|
||||||
|
|
||||||
|
/// YIN analysis window, in decimated samples (512 is `FreqTracker`'s RT-safe maximum).
|
||||||
|
private static let fftSize: Int = 512
|
||||||
|
|
||||||
|
/// Minimum tracked frequency in Hz — below standard bass E1 (≈41 Hz) for headroom.
|
||||||
|
private static let minFreqHz: Double = 38.0
|
||||||
|
|
||||||
|
/// Maximum tracked frequency in Hz — above guitar high-E (E4 ≈330 Hz) with room for
|
||||||
|
/// upper strings / light bends, and well below the decimated Nyquist.
|
||||||
|
private static let maxFreqHz: Double = 660.0
|
||||||
|
|
||||||
|
private let tracker: FreqTracker
|
||||||
|
private let _hzBits: Atomic<UInt64>
|
||||||
|
private let _confidenceBits: Atomic<UInt64>
|
||||||
|
|
||||||
|
/// The most recent tracked frequency, in Hz. Safe to read from any thread.
|
||||||
|
var detectedFrequencyHz: Double {
|
||||||
|
Double(bitPattern: _hzBits.load(ordering: .acquiring))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The most recent tracking confidence in `[0, 1]`. Safe to read from any thread.
|
||||||
|
var detectedConfidence: Double {
|
||||||
|
Double(bitPattern: _confidenceBits.load(ordering: .acquiring))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// - Parameter input: Signal to analyse for pitch — must already be band-limited below
|
||||||
|
/// the decimated Nyquist (see `TunerTap`, which applies the anti-alias lowpass).
|
||||||
|
init(input: any ValidGeneratorInput) {
|
||||||
|
let resolvedInput: any ValidGeneratorInput = input._resolvedInput()
|
||||||
|
tracker = FreqTracker(
|
||||||
|
in: resolvedInput,
|
||||||
|
fftSize: TunerPitchCapture.fftSize,
|
||||||
|
minFreq: TunerPitchCapture.minFreqHz,
|
||||||
|
maxFreq: TunerPitchCapture.maxFreqHz,
|
||||||
|
decimation: TunerPitchCapture.decimation
|
||||||
|
)
|
||||||
|
_hzBits = Atomic(Double(0.0).bitPattern)
|
||||||
|
_confidenceBits = Atomic(Double(0.0).bitPattern)
|
||||||
|
super.init()
|
||||||
|
_setupSubBlockBuffer()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bypass sub-block loop — one capture per audio block. `FreqTracker` processes the full
|
||||||
|
// block internally (per-sample ring fill + periodic YIN hops).
|
||||||
|
func calculatedSamples(
|
||||||
|
graph: SynthGraph,
|
||||||
|
count: Int
|
||||||
|
) -> [[Double]] {
|
||||||
|
_calculatedSamplesBlockRate(graph: graph, count: count)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _computeSamples(
|
||||||
|
graph: SynthGraph,
|
||||||
|
count: Int
|
||||||
|
) -> [[Double]] {
|
||||||
|
_checkCount(count)
|
||||||
|
// `_checkCount` only bounds the top; guard the empty block so the `count - 1` last-sample
|
||||||
|
// reads below can't index `-1` (engine blockSize is ≥1 today, so this is defensive).
|
||||||
|
guard count > 0 else { return _result }
|
||||||
|
// FreqTracker is a two-channel AudioGenerator: channel 0 = Hz, channel 1 = confidence.
|
||||||
|
// Both rows are fully populated for `count` samples.
|
||||||
|
let trackerBlock: [[Double]] = tracker.calculatedSamples(graph: graph, count: count)
|
||||||
|
let hz: Double = trackerBlock[0][count - 1]
|
||||||
|
let confidence: Double = trackerBlock[1][count - 1]
|
||||||
|
_hzBits.store(hz.bitPattern, ordering: .releasing)
|
||||||
|
_confidenceBits.store(confidence.bitPattern, ordering: .releasing)
|
||||||
|
previousOutputValue = hz
|
||||||
|
for i: Int in 0..<count {
|
||||||
|
_result[0][i] = trackerBlock[0][i]
|
||||||
|
}
|
||||||
|
return _result
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
// TunerTap.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import LyrebirdSynth
|
||||||
|
|
||||||
|
/// An internal synthesizer that taps the clean pre-effects input bus and runs a
|
||||||
|
/// `TunerPitchCapture` on it, so `ShoeGaze` can poll the current detected pitch from the
|
||||||
|
/// main thread while the tuner is engaged.
|
||||||
|
///
|
||||||
|
/// Mirrors `RecordTap`'s shape: reads one bus via `input(bus:)`, wires an analysis generator,
|
||||||
|
/// and writes to a dedicated scratch `ControlBus` purely so the engine evaluates it every
|
||||||
|
/// block — nothing downstream reads that bus.
|
||||||
|
final class TunerTap: SynthesizerBase {
|
||||||
|
|
||||||
|
/// Anti-alias lowpass cutoff, in Hz, ahead of the decimating YIN tracker. Must sit below
|
||||||
|
/// the decimated Nyquist (`sampleRate / (2 × decimation)`; ≈3 kHz at 48 kHz / 8×) so
|
||||||
|
/// decimation doesn't fold high harmonics back into the analysis band. `1200` Hz clears
|
||||||
|
/// every guitar/bass fundamental (highest is E4 ≈330 Hz) and their first harmonics — which
|
||||||
|
/// help YIN lock — while giving solid anti-alias margin.
|
||||||
|
private static let lowpassCutoffHz: Double = 1200.0
|
||||||
|
|
||||||
|
/// Butterworth Q (maximally flat, no resonant peak) for the anti-alias lowpass.
|
||||||
|
private static let lowpassQ: Double = 0.707
|
||||||
|
|
||||||
|
/// Index of the input bus to analyse.
|
||||||
|
private let inputBusIndex: Int
|
||||||
|
|
||||||
|
/// Scratch control bus the capture generator's passthrough writes to. Unread by anything
|
||||||
|
/// else — its only purpose is to give the engine a reason to evaluate the generator.
|
||||||
|
private let scratchControlBus: ControlBus
|
||||||
|
|
||||||
|
/// The pitch-capture generator created during `build()`. `nil` until `build()` has run.
|
||||||
|
private(set) var pitchCapture: TunerPitchCapture?
|
||||||
|
|
||||||
|
/// Creates a tuner tap.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - inputBusIndex: Audio bus to analyse.
|
||||||
|
/// - scratchControlBus: A control bus reserved for this tap's unread passthrough output.
|
||||||
|
init(inputBusIndex: Int, scratchControlBus: ControlBus) {
|
||||||
|
self.inputBusIndex = inputBusIndex
|
||||||
|
self.scratchControlBus = scratchControlBus
|
||||||
|
super.init()
|
||||||
|
}
|
||||||
|
|
||||||
|
override func build() {
|
||||||
|
let source: In.Audio = input(bus: inputBusIndex)
|
||||||
|
let filtered: RBJLowPass.Audio = RBJLowPass.Audio(
|
||||||
|
input: source,
|
||||||
|
freq: TunerTap.lowpassCutoffHz,
|
||||||
|
q: TunerTap.lowpassQ
|
||||||
|
)
|
||||||
|
let capture: TunerPitchCapture = TunerPitchCapture(input: filtered)
|
||||||
|
pitchCapture = capture
|
||||||
|
output(bus: scratchControlBus, source: capture)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -41,7 +41,9 @@ public struct BoardBarView: View {
|
|||||||
// MARK: - Layout constants
|
// MARK: - Layout constants
|
||||||
|
|
||||||
private static let barSpacing: CGFloat = 10
|
private static let barSpacing: CGFloat = 10
|
||||||
private static let barHeight: CGFloat = 92
|
// Tall enough for the control column's three rows of (iOS-chunky) segmented picker + sliders +
|
||||||
|
// bordered mute button, so it doesn't overflow into the CPU meters below.
|
||||||
|
private static let barHeight: CGFloat = 110
|
||||||
private static let cellSpacing: CGFloat = 8
|
private static let cellSpacing: CGFloat = 8
|
||||||
private static let cellWidth: CGFloat = 104
|
private static let cellWidth: CGFloat = 104
|
||||||
private static let cellInnerSpacing: CGFloat = 5
|
private static let cellInnerSpacing: CGFloat = 5
|
||||||
@@ -56,6 +58,9 @@ public struct BoardBarView: View {
|
|||||||
private static let ledDimBrightness: Double = 0.16
|
private static let ledDimBrightness: Double = 0.16
|
||||||
private static let ledRimOpacity: Double = 0.30
|
private static let ledRimOpacity: Double = 0.30
|
||||||
private static let soloButtonSize: CGFloat = 22
|
private static let soloButtonSize: CGFloat = 22
|
||||||
|
/// Fixed size for the rig mute glyph so the slash / wave states don't shift the volume row.
|
||||||
|
private static let muteIconWidth: CGFloat = 16
|
||||||
|
private static let muteIconHeight: CGFloat = 16
|
||||||
private static let editingBorderWidth: CGFloat = 2
|
private static let editingBorderWidth: CGFloat = 2
|
||||||
private static let idleBorderOpacity: Double = 0.18
|
private static let idleBorderOpacity: Double = 0.18
|
||||||
private static let cellBackgroundBrightness: Double = 0.14
|
private static let cellBackgroundBrightness: Double = 0.14
|
||||||
@@ -71,6 +76,7 @@ public struct BoardBarView: View {
|
|||||||
@Binding private var editingBoardIndex: Int
|
@Binding private var editingBoardIndex: Int
|
||||||
@Binding private var crossfadeSeconds: Double
|
@Binding private var crossfadeSeconds: Double
|
||||||
private let onAddBoard: () -> Void
|
private let onAddBoard: () -> Void
|
||||||
|
private let onClearBoards: (() -> Void)?
|
||||||
|
|
||||||
@State private var mode: PlayMode = .solo
|
@State private var mode: PlayMode = .solo
|
||||||
|
|
||||||
@@ -84,16 +90,20 @@ public struct BoardBarView: View {
|
|||||||
/// tap writes this).
|
/// tap writes this).
|
||||||
/// - crossfadeSeconds: Crossfade duration applied to every board switch / toggle.
|
/// - crossfadeSeconds: Crossfade duration applied to every board switch / toggle.
|
||||||
/// - onAddBoard: Called when the trailing **+** button is tapped.
|
/// - onAddBoard: Called when the trailing **+** button is tapped.
|
||||||
|
/// - onClearBoards: Called when the trailing **Clear** button is tapped. When `nil`
|
||||||
|
/// (the default) no Clear button is shown.
|
||||||
public init(
|
public init(
|
||||||
shoeGaze: ShoeGaze,
|
shoeGaze: ShoeGaze,
|
||||||
editingBoardIndex: Binding<Int>,
|
editingBoardIndex: Binding<Int>,
|
||||||
crossfadeSeconds: Binding<Double>,
|
crossfadeSeconds: Binding<Double>,
|
||||||
onAddBoard: @escaping () -> Void
|
onAddBoard: @escaping () -> Void,
|
||||||
|
onClearBoards: (() -> Void)? = nil
|
||||||
) {
|
) {
|
||||||
self.shoeGaze = shoeGaze
|
self.shoeGaze = shoeGaze
|
||||||
self._editingBoardIndex = editingBoardIndex
|
self._editingBoardIndex = editingBoardIndex
|
||||||
self._crossfadeSeconds = crossfadeSeconds
|
self._crossfadeSeconds = crossfadeSeconds
|
||||||
self.onAddBoard = onAddBoard
|
self.onAddBoard = onAddBoard
|
||||||
|
self.onClearBoards = onClearBoards
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Body
|
// MARK: - Body
|
||||||
@@ -109,6 +119,11 @@ public struct BoardBarView: View {
|
|||||||
boardCell(index: pair.offset, board: pair.element)
|
boardCell(index: pair.offset, board: pair.element)
|
||||||
}
|
}
|
||||||
addButton
|
addButton
|
||||||
|
if let onClearBoards: () -> Void = onClearBoards {
|
||||||
|
Button("Clear") { onClearBoards() }
|
||||||
|
.buttonStyle(.bordered).tint(.red)
|
||||||
|
.help("Remove all boards in the current rig (with the option to save first)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.frame(height: BoardBarView.barHeight)
|
.frame(height: BoardBarView.barHeight)
|
||||||
}
|
}
|
||||||
@@ -175,7 +190,10 @@ public struct BoardBarView: View {
|
|||||||
Button {
|
Button {
|
||||||
shoeGaze.toggleRigMuted()
|
shoeGaze.toggleRigMuted()
|
||||||
} label: {
|
} label: {
|
||||||
|
// Fixed width: the slash / wave glyphs differ in width, which would otherwise
|
||||||
|
// shift the whole volume row a few pixels when toggling mute.
|
||||||
Image(systemName: shoeGaze.rigMuted ? "speaker.slash.fill" : "speaker.wave.2.fill")
|
Image(systemName: shoeGaze.rigMuted ? "speaker.slash.fill" : "speaker.wave.2.fill")
|
||||||
|
.frame(width: BoardBarView.muteIconWidth, height: BoardBarView.muteIconHeight)
|
||||||
}
|
}
|
||||||
.buttonStyle(.bordered)
|
.buttonStyle(.bordered)
|
||||||
.tint(shoeGaze.rigMuted ? .red : .orange)
|
.tint(shoeGaze.rigMuted ? .red : .orange)
|
||||||
|
|||||||
@@ -0,0 +1,251 @@
|
|||||||
|
// ControlMappingStrip.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
/// The rig's current control map, injected into the board view tree so each ``PedalView`` can draw
|
||||||
|
/// its own mapping strip without every call site having to thread the map through. `nil` when the
|
||||||
|
/// rig has no bindings. Set once high in the builder (`builderColumn`) from the observable
|
||||||
|
/// `ShoeGaze.midiMap`, so learning or clearing a binding updates every strip live.
|
||||||
|
private struct ControlMappingMapKey: EnvironmentKey {
|
||||||
|
static let defaultValue: MIDIMap? = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
extension EnvironmentValues {
|
||||||
|
/// The rig's control map for in-context mapping badges, or `nil` when unset / empty.
|
||||||
|
var controlMappingMap: MIDIMap? {
|
||||||
|
get { self[ControlMappingMapKey.self] }
|
||||||
|
set { self[ControlMappingMapKey.self] = newValue }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The kind of trigger a mapping badge represents, and its colour.
|
||||||
|
enum MappingBadgeKind {
|
||||||
|
case programChange
|
||||||
|
case controlChange
|
||||||
|
case key
|
||||||
|
|
||||||
|
/// The badge fill colour (matches the mapping-sheet chip colours).
|
||||||
|
var fill: Color {
|
||||||
|
switch self {
|
||||||
|
case .programChange: return MappingBadge.pcFill
|
||||||
|
case .controlChange: return MappingBadge.ccFill
|
||||||
|
case .key: return MappingBadge.keyFill
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One coloured pill — e.g. `CC11`, `PC3`, `⇧B` — marking a control's binding.
|
||||||
|
struct MappingBadge: View {
|
||||||
|
|
||||||
|
static let pcFill: Color = Color(red: 0.11, green: 0.37, blue: 0.65)
|
||||||
|
static let ccFill: Color = Color(red: 0.33, green: 0.29, blue: 0.72)
|
||||||
|
static let keyFill: Color = Color(red: 0.73, green: 0.46, blue: 0.09)
|
||||||
|
|
||||||
|
private static let fontSize: CGFloat = 9
|
||||||
|
private static let paddingH: CGFloat = 5
|
||||||
|
private static let paddingV: CGFloat = 1
|
||||||
|
private static let cornerRadius: CGFloat = 4
|
||||||
|
|
||||||
|
private let kind: MappingBadgeKind
|
||||||
|
private let text: String
|
||||||
|
|
||||||
|
/// Creates a mapping badge.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - kind: The trigger kind (drives the fill colour).
|
||||||
|
/// - text: The badge label (e.g. `"CC11"`, `"PC3"`, `"⇧B"`).
|
||||||
|
init(kind: MappingBadgeKind, text: String) {
|
||||||
|
self.kind = kind
|
||||||
|
self.text = text
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Text(text)
|
||||||
|
.font(.system(size: MappingBadge.fontSize, weight: .medium))
|
||||||
|
.foregroundStyle(Color.white)
|
||||||
|
.padding(.horizontal, MappingBadge.paddingH)
|
||||||
|
.padding(.vertical, MappingBadge.paddingV)
|
||||||
|
.background(
|
||||||
|
RoundedRectangle(cornerRadius: MappingBadge.cornerRadius)
|
||||||
|
.fill(kind.fill)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A one-line legend keying the badge colours (`PC` footswitch, `CC` expression, `KEY` letter key),
|
||||||
|
/// shown once above the board canvas.
|
||||||
|
struct ControlMappingLegend: View {
|
||||||
|
|
||||||
|
private static let itemSpacing: CGFloat = 10
|
||||||
|
private static let pairSpacing: CGFloat = 5
|
||||||
|
private static let fontSize: CGFloat = 11
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
HStack(spacing: ControlMappingLegend.itemSpacing) {
|
||||||
|
legendItem(kind: .programChange, badge: "PC", caption: "footswitch")
|
||||||
|
legendItem(kind: .controlChange, badge: "CC", caption: "expression")
|
||||||
|
legendItem(kind: .key, badge: "KEY", caption: "letter key")
|
||||||
|
}
|
||||||
|
.foregroundStyle(Color.white.opacity(0.55))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func legendItem(kind: MappingBadgeKind, badge: String, caption: String) -> some View {
|
||||||
|
HStack(spacing: ControlMappingLegend.pairSpacing) {
|
||||||
|
MappingBadge(kind: kind, text: badge)
|
||||||
|
Text(caption)
|
||||||
|
.font(.system(size: ControlMappingLegend.fontSize))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One row of a pedal's mapping strip: a control label and the badges bound to it.
|
||||||
|
struct PedalMappingRow: Identifiable {
|
||||||
|
let id: String
|
||||||
|
let label: String
|
||||||
|
let badges: [PedalMappingBadge]
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A single badge within a ``PedalMappingRow``.
|
||||||
|
struct PedalMappingBadge: Identifiable {
|
||||||
|
let id: String
|
||||||
|
let kind: MappingBadgeKind
|
||||||
|
let text: String
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The per-pedal mapping strip: a compact footer listing this pedal's mapped controls and the
|
||||||
|
/// footswitch / expression / key bindings driving them. Renders nothing when the pedal has no
|
||||||
|
/// mappings, so unmapped pedals gain no height.
|
||||||
|
struct PedalMappingStrip: View {
|
||||||
|
|
||||||
|
private static let rowSpacing: CGFloat = 3
|
||||||
|
private static let labelFontSize: CGFloat = 10
|
||||||
|
private static let badgeSpacing: CGFloat = 4
|
||||||
|
private static let topPadding: CGFloat = 6
|
||||||
|
private static let dividerOpacity: Double = 0.18
|
||||||
|
|
||||||
|
private let rows: [PedalMappingRow]
|
||||||
|
|
||||||
|
/// Creates a mapping strip for a pedal against the current map.
|
||||||
|
///
|
||||||
|
/// - Parameters:
|
||||||
|
/// - pedal: The pedal whose bindings are listed.
|
||||||
|
/// - map: The rig's control map, or `nil` when there are no bindings.
|
||||||
|
init(pedal: Pedal, map: MIDIMap?) {
|
||||||
|
self.rows = PedalMappingStrip.rows(for: pedal, in: map)
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if rows.isEmpty {
|
||||||
|
EmptyView()
|
||||||
|
} else {
|
||||||
|
VStack(spacing: PedalMappingStrip.rowSpacing) {
|
||||||
|
Divider().overlay(Color.white.opacity(PedalMappingStrip.dividerOpacity))
|
||||||
|
ForEach(rows) { row in
|
||||||
|
HStack(spacing: PedalMappingStrip.badgeSpacing) {
|
||||||
|
Text(row.label)
|
||||||
|
.font(.system(size: PedalMappingStrip.labelFontSize))
|
||||||
|
.foregroundStyle(Color.white.opacity(0.6))
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
ForEach(row.badges) { badge in
|
||||||
|
MappingBadge(kind: badge.kind, text: badge.text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.top, PedalMappingStrip.topPadding)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Row assembly
|
||||||
|
|
||||||
|
/// Builds the strip rows for a pedal from the map: one row per mapped CC control, one for a
|
||||||
|
/// mapped bypass (footswitch + key), and one per mapped looper transport action.
|
||||||
|
static func rows(for pedal: Pedal, in map: MIDIMap?) -> [PedalMappingRow] {
|
||||||
|
guard let map: MIDIMap = map else { return [] }
|
||||||
|
let pedalID: UUID = pedal.id
|
||||||
|
var rows: [PedalMappingRow] = []
|
||||||
|
|
||||||
|
// Continuous controls driven by an expression pedal (CC).
|
||||||
|
for controlPair: (offset: Int, element: PedalControl) in pedal.ccMappableControls.enumerated() {
|
||||||
|
let target: MIDIMap.CCTarget = .pedalControl(
|
||||||
|
pedalID: pedalID, controlIndex: controlPair.offset,
|
||||||
|
pedalNameHint: nil, controlLabelHint: nil)
|
||||||
|
guard let cc: MIDIMap.CCBinding = map.ccs.first(where: { $0.target.addresses(target) })
|
||||||
|
else { continue }
|
||||||
|
rows.append(PedalMappingRow(
|
||||||
|
id: "cc-\(controlPair.offset)",
|
||||||
|
label: controlPair.element.label,
|
||||||
|
badges: [PedalMappingBadge(id: "cc", kind: .controlChange, text: "CC\(cc.controller)")]))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bypass — a footswitch and/or a key.
|
||||||
|
let bypassBadges: [PedalMappingBadge] = badges(for: .pedalBypass(pedalID: pedalID), in: map)
|
||||||
|
if bypassBadges.isEmpty == false {
|
||||||
|
rows.append(PedalMappingRow(id: "bypass", label: "Bypass", badges: bypassBadges))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Looper transport actions.
|
||||||
|
if pedal is LooperPedal {
|
||||||
|
for kind: MIDIMap.PedalActionKind in loopedActionOrder {
|
||||||
|
let action: MIDIMap.Action = .pedalAction(pedalID: pedalID, kind: kind)
|
||||||
|
let actionBadges: [PedalMappingBadge] = badges(for: action, in: map)
|
||||||
|
if actionBadges.isEmpty { continue }
|
||||||
|
rows.append(PedalMappingRow(
|
||||||
|
id: "la-\(looperActionName(kind))",
|
||||||
|
label: looperActionName(kind),
|
||||||
|
badges: actionBadges))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rows
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The footswitch (PC) and key badges bound to a toggle action, in that order.
|
||||||
|
private static func badges(for action: MIDIMap.Action, in map: MIDIMap) -> [PedalMappingBadge] {
|
||||||
|
var badges: [PedalMappingBadge] = []
|
||||||
|
if let pc: MIDIMap.SwitchBinding = map.switches.first(where: { $0.action == action }) {
|
||||||
|
badges.append(PedalMappingBadge(id: "pc", kind: .programChange, text: "PC\(pc.program)"))
|
||||||
|
}
|
||||||
|
if let key: MIDIMap.KeyBinding = map.keys.first(where: { $0.action == action }) {
|
||||||
|
badges.append(PedalMappingBadge(id: "key", kind: .key, text: keyLabel(key)))
|
||||||
|
}
|
||||||
|
return badges
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A key binding formatted with modifier glyphs (macOS order: control, option, shift).
|
||||||
|
private static func keyLabel(_ binding: MIDIMap.KeyBinding) -> String {
|
||||||
|
var prefix: String = ""
|
||||||
|
if binding.modifiers.contains(.control) { prefix += "⌃" }
|
||||||
|
if binding.modifiers.contains(.option) { prefix += "⌥" }
|
||||||
|
if binding.modifiers.contains(.shift) { prefix += "⇧" }
|
||||||
|
return prefix + binding.key.uppercased()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The looper transport actions in the order they appear in the mapping sheet.
|
||||||
|
private static let loopedActionOrder: [MIDIMap.PedalActionKind] = [
|
||||||
|
.looperRecordStop, .looperOverdubToggle, .looperLoopToggle, .looperStop,
|
||||||
|
.looperCueStop, .looperReverse, .looperSyncToggle, .looperReset,
|
||||||
|
.looperTrack(index: 0), .looperTrack(index: 1),
|
||||||
|
.looperTrack(index: 2), .looperTrack(index: 3),
|
||||||
|
]
|
||||||
|
|
||||||
|
/// A short user-facing name for a looper transport action.
|
||||||
|
private static func looperActionName(_ kind: MIDIMap.PedalActionKind) -> String {
|
||||||
|
switch kind {
|
||||||
|
case .looperRecordStop: return "Record"
|
||||||
|
case .looperOverdubToggle: return "Overdub"
|
||||||
|
case .looperLoopToggle: return "Loop"
|
||||||
|
case .looperStop: return "Stop"
|
||||||
|
case .looperCueStop: return "Cue Stop"
|
||||||
|
case .looperReverse: return "Reverse"
|
||||||
|
case .looperSyncToggle: return "Sync"
|
||||||
|
case .looperReset: return "Reset"
|
||||||
|
case .looperTrack(let index): return "Track \(LooperPedal.trackLabel(index))"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,6 +42,10 @@ public struct EngineConfigView: View {
|
|||||||
private let hardwareSampleRate: () -> Double?
|
private let hardwareSampleRate: () -> Double?
|
||||||
private let applyConfig: ((Double, Int, Int) throws -> Void)?
|
private let applyConfig: ((Double, Int, Int) throws -> Void)?
|
||||||
private let onConfigApplied: () -> Void
|
private let onConfigApplied: () -> Void
|
||||||
|
/// When `true`, renders only the Start/Stop transport button (the sample-rate / channel-count
|
||||||
|
/// controls are hidden). Used by the compact (iPhone / narrow iPad) layout, which keeps the
|
||||||
|
/// transport on screen and moves the config controls into a Settings sheet.
|
||||||
|
private let transportOnly: Bool
|
||||||
|
|
||||||
@State private var pendingSampleRate: Double
|
@State private var pendingSampleRate: Double
|
||||||
@State private var pendingInputs: Int
|
@State private var pendingInputs: Int
|
||||||
@@ -63,12 +67,14 @@ public struct EngineConfigView: View {
|
|||||||
shoeGaze: ShoeGaze,
|
shoeGaze: ShoeGaze,
|
||||||
hardwareSampleRate: @escaping () -> Double? = { nil },
|
hardwareSampleRate: @escaping () -> Double? = { nil },
|
||||||
applyConfig: ((Double, Int, Int) throws -> Void)? = nil,
|
applyConfig: ((Double, Int, Int) throws -> Void)? = nil,
|
||||||
onConfigApplied: @escaping () -> Void = { }
|
onConfigApplied: @escaping () -> Void = { },
|
||||||
|
transportOnly: Bool = false
|
||||||
) {
|
) {
|
||||||
self.shoeGaze = shoeGaze
|
self.shoeGaze = shoeGaze
|
||||||
self.hardwareSampleRate = hardwareSampleRate
|
self.hardwareSampleRate = hardwareSampleRate
|
||||||
self.applyConfig = applyConfig
|
self.applyConfig = applyConfig
|
||||||
self.onConfigApplied = onConfigApplied
|
self.onConfigApplied = onConfigApplied
|
||||||
|
self.transportOnly = transportOnly
|
||||||
_pendingSampleRate = State(initialValue: shoeGaze.engine.sampleRate)
|
_pendingSampleRate = State(initialValue: shoeGaze.engine.sampleRate)
|
||||||
_pendingInputs = State(initialValue: shoeGaze.engine.numInputChannels)
|
_pendingInputs = State(initialValue: shoeGaze.engine.numInputChannels)
|
||||||
_pendingOutputs = State(initialValue: shoeGaze.engine.numOutputChannels)
|
_pendingOutputs = State(initialValue: shoeGaze.engine.numOutputChannels)
|
||||||
@@ -78,35 +84,36 @@ public struct EngineConfigView: View {
|
|||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
_ = transportTick
|
_ = transportTick
|
||||||
let isRunning: Bool = shoeGaze.engine.isRunning
|
return Group {
|
||||||
return HStack(spacing: EngineConfigView.rowSpacing) {
|
if transportOnly {
|
||||||
label("Rate")
|
transportButton
|
||||||
Picker("Rate", selection: $pendingSampleRate) {
|
} else {
|
||||||
ForEach(EngineConfigView.standardRates, id: \.self) { rate in
|
HStack(spacing: EngineConfigView.rowSpacing) {
|
||||||
Text("\(Int(rate)) Hz").tag(rate)
|
label("Rate")
|
||||||
|
Picker("Rate", selection: $pendingSampleRate) {
|
||||||
|
ForEach(EngineConfigView.standardRates, id: \.self) { rate in
|
||||||
|
Text("\(Int(rate)) Hz").tag(rate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.labelsHidden()
|
||||||
|
.pickerStyle(.menu)
|
||||||
|
.disabled(shoeGaze.engine.isRunning)
|
||||||
|
|
||||||
|
Stepper(value: $pendingInputs, in: 0...EngineConfigView.maxInputs) {
|
||||||
|
Text("In: \(pendingInputs)").foregroundStyle(Color.white)
|
||||||
|
}
|
||||||
|
.disabled(shoeGaze.engine.isRunning)
|
||||||
|
.fixedSize()
|
||||||
|
|
||||||
|
Stepper(value: $pendingOutputs, in: 1...EngineConfigView.maxOutputs) {
|
||||||
|
Text("Out: \(pendingOutputs)").foregroundStyle(Color.white)
|
||||||
|
}
|
||||||
|
.disabled(shoeGaze.engine.isRunning)
|
||||||
|
.fixedSize()
|
||||||
|
|
||||||
|
transportButton
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.labelsHidden()
|
|
||||||
.pickerStyle(.menu)
|
|
||||||
.disabled(isRunning)
|
|
||||||
|
|
||||||
Stepper(value: $pendingInputs, in: 0...EngineConfigView.maxInputs) {
|
|
||||||
Text("In: \(pendingInputs)").foregroundStyle(Color.white)
|
|
||||||
}
|
|
||||||
.disabled(isRunning)
|
|
||||||
.fixedSize()
|
|
||||||
|
|
||||||
Stepper(value: $pendingOutputs, in: 1...EngineConfigView.maxOutputs) {
|
|
||||||
Text("Out: \(pendingOutputs)").foregroundStyle(Color.white)
|
|
||||||
}
|
|
||||||
.disabled(isRunning)
|
|
||||||
.fixedSize()
|
|
||||||
|
|
||||||
Button(isRunning ? "Stop" : "Start") {
|
|
||||||
if isRunning { stopEngine() } else { startEngine() }
|
|
||||||
}
|
|
||||||
.buttonStyle(.borderedProminent)
|
|
||||||
.tint(isRunning ? .red : .green)
|
|
||||||
}
|
}
|
||||||
.alert(alertTitle, isPresented: $showAlert) {
|
.alert(alertTitle, isPresented: $showAlert) {
|
||||||
Button("OK", role: .cancel) { }
|
Button("OK", role: .cancel) { }
|
||||||
@@ -131,6 +138,16 @@ public struct EngineConfigView: View {
|
|||||||
.onChange(of: pendingSampleRate) { applyConfigWhileStopped() }
|
.onChange(of: pendingSampleRate) { applyConfigWhileStopped() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The Start / Stop transport button, shared by the full and transport-only layouts.
|
||||||
|
private var transportButton: some View {
|
||||||
|
let isRunning: Bool = shoeGaze.engine.isRunning
|
||||||
|
return Button(isRunning ? "Stop" : "Start") {
|
||||||
|
if isRunning { stopEngine() } else { startEngine() }
|
||||||
|
}
|
||||||
|
.buttonStyle(.borderedProminent)
|
||||||
|
.tint(isRunning ? .red : .green)
|
||||||
|
}
|
||||||
|
|
||||||
/// Reconfigures the stopped engine with the pending values and notifies the host so views that
|
/// Reconfigures the stopped engine with the pending values and notifies the host so views that
|
||||||
/// read non-observable engine state refresh. No-op while the engine is running.
|
/// read non-observable engine state refresh. No-op while the engine is running.
|
||||||
private func applyConfigWhileStopped() {
|
private func applyConfigWhileStopped() {
|
||||||
@@ -161,14 +178,20 @@ public struct EngineConfigView: View {
|
|||||||
|
|
||||||
private func startEngine() {
|
private func startEngine() {
|
||||||
do {
|
do {
|
||||||
if let applyConfig: (Double, Int, Int) throws -> Void = applyConfig {
|
// Transport-only mode does not own the config controls — the engine is already
|
||||||
try applyConfig(pendingSampleRate, pendingInputs, pendingOutputs)
|
// configured (via the full instance's live apply, or the init defaults). Re-applying
|
||||||
} else {
|
// this instance's cached pending state here would revert edits made in the Settings
|
||||||
try shoeGaze.reconfigureEngine(
|
// sheet, so skip the reconfigure and just start.
|
||||||
sampleRate: pendingSampleRate,
|
if !transportOnly {
|
||||||
inputChannels: pendingInputs,
|
if let applyConfig: (Double, Int, Int) throws -> Void = applyConfig {
|
||||||
outputChannels: pendingOutputs
|
try applyConfig(pendingSampleRate, pendingInputs, pendingOutputs)
|
||||||
)
|
} else {
|
||||||
|
try shoeGaze.reconfigureEngine(
|
||||||
|
sampleRate: pendingSampleRate,
|
||||||
|
inputChannels: pendingInputs,
|
||||||
|
outputChannels: pendingOutputs
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
try shoeGaze.engine.start()
|
try shoeGaze.engine.start()
|
||||||
} catch {
|
} catch {
|
||||||
@@ -190,7 +213,7 @@ public struct EngineConfigView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func stopEngine() {
|
private func stopEngine() {
|
||||||
shoeGaze.engine.stop()
|
shoeGaze.stopEngine()
|
||||||
transportTick.toggle()
|
transportTick.toggle()
|
||||||
onConfigApplied()
|
onConfigApplied()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,23 @@ public struct HelpView: View {
|
|||||||
"Bypass Rig compares your sound with and without the whole pedalboard.",
|
"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(
|
topicSection(
|
||||||
icon: "waveform",
|
icon: "waveform",
|
||||||
title: "Choosing an Input",
|
title: "Choosing an Input",
|
||||||
@@ -64,6 +81,37 @@ public struct HelpView: View {
|
|||||||
+ "crossfade time; each board has S (solo) and B (bypass).",
|
+ "crossfade time; each board has S (solo) and B (bypass).",
|
||||||
"The Rigs sidebar lists saved rigs, with New, Save, Save As, Duplicate, Rename, "
|
"The Rigs sidebar lists saved rigs, with New, Save, Save As, Duplicate, Rename, "
|
||||||
+ "Delete, and Erase All.",
|
+ "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(
|
||||||
|
icon: "repeat",
|
||||||
|
title: "The Looper Pedal",
|
||||||
|
intro: "The Looper records a phrase and plays it back in a loop, with up to four "
|
||||||
|
+ "overdub tracks (A–D). The big Record button is a smart footswitch whose job "
|
||||||
|
+ "changes with the looper's state.",
|
||||||
|
steps: [
|
||||||
|
"Record (smart footswitch): first press records track A; press again to set the "
|
||||||
|
+ "loop end and start playback (auto-overdubbing A); while playing it toggles "
|
||||||
|
+ "overdub on the selected track.",
|
||||||
|
"Free vs Sync to Tempo: Free loops are whatever length you play, captured instantly. "
|
||||||
|
+ "Sync quantizes record-start and loop-close to the beat clock — so every loop is "
|
||||||
|
+ "a whole number of beats. Sync needs the Tempo indicator On; it is disabled while "
|
||||||
|
+ "tempo is off.",
|
||||||
|
"Knobs: Playback sets loop level against your live signal; Overdub sets the record "
|
||||||
|
+ "level of new overdubs; Feedback sets how much existing audio survives each pass "
|
||||||
|
+ "(1.0 = keep forever); Crossfade smooths loop mute/unmute so it doesn't click.",
|
||||||
|
"Reverse flips playback direction from the current position (in Sync it waits for the "
|
||||||
|
+ "next beat). Stop halts now; Cue Stop arms a stop at the next loop end (press again "
|
||||||
|
+ "to cancel); Reset clears every track back to empty.",
|
||||||
|
"Tracks A–D: tap a dot to select the track Record overdubs into; tap a selected, "
|
||||||
|
+ "recorded track again to mute or unmute it.",
|
||||||
|
"MIDI: Record, Stop, Cue Stop, Reverse, Sync, Reset, and each Track A–D map as "
|
||||||
|
+ "footswitch (Program Change) or key actions in MIDI / Control Mapping; the "
|
||||||
|
+ "Crossfade / Playback / Overdub / Feedback knobs sweep from an expression pedal "
|
||||||
|
+ "like any pedal knob.",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
topicSection(
|
topicSection(
|
||||||
@@ -89,13 +137,19 @@ public struct HelpView: View {
|
|||||||
)
|
)
|
||||||
topicSection(
|
topicSection(
|
||||||
icon: "pianokeys",
|
icon: "pianokeys",
|
||||||
title: "MIDI Control",
|
title: "MIDI / Control",
|
||||||
intro: "Map a MIDI foot controller (e.g. a Behringer FCB1010) for hands-free control.",
|
intro: "Map a MIDI foot controller (e.g. a Behringer FCB1010) or your computer keyboard for "
|
||||||
|
+ "hands-free control.",
|
||||||
steps: [
|
steps: [
|
||||||
"The keys icon in the top bar lights green when a device is connected. Tap it to open MIDI Mapping.",
|
"The keys icon in the top bar lights green when a device is connected. Tap it to open "
|
||||||
"Switches (Program Change): footswitches toggle Rig Bypass, All Boards, and each board's "
|
+ "MIDI / Control Mapping.",
|
||||||
+ "Solo / Audible / Bypass or a pedal's bypass. Tap Learn, then press the footswitch. "
|
"Switches: footswitches and letter keys toggle Rig Bypass, All Boards, and each board's "
|
||||||
+ "One switch can drive several actions at once — a scene.",
|
+ "Solo / Audible / Bypass or a pedal's bypass. Tap PC then press a footswitch, or Key "
|
||||||
|
+ "then press a key. One switch or key can drive several actions at once — a scene.",
|
||||||
|
"Keys fire only when you're not typing — while a text field (like a rig name) is focused, "
|
||||||
|
+ "letters go to the field, not to your mappings.",
|
||||||
|
"Hold Shift, Control, or Option while learning to bind a modified key — a and ⇧a are "
|
||||||
|
+ "separate triggers. Command is reserved for the menu shortcuts.",
|
||||||
"Expression (Control Change): an expression pedal sweeps any pedal knob or slider, or a "
|
"Expression (Control Change): an expression pedal sweeps any pedal knob or slider, or a "
|
||||||
+ "board's Level. Tap Learn, then move the pedal. Invert reverses the sweep — map one "
|
+ "board's Level. Tap Learn, then move the pedal. Invert reverses the sweep — map one "
|
||||||
+ "CC to two controls and invert one for a crossfade.",
|
+ "CC to two controls and invert one for a crossfade.",
|
||||||
|
|||||||
@@ -0,0 +1,239 @@
|
|||||||
|
// LooperTimelineView.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
/// The looper's loop timeline: a transport-state badge, tappable A–D track dots, a loop-length
|
||||||
|
/// read-out, a sweeping play-head track, and a one-line state indicator describing what the
|
||||||
|
/// pedal is doing. Rendered inside the double-width ``PedalView`` for a `LooperPedal`.
|
||||||
|
///
|
||||||
|
/// `LooperPedal`'s transport state is plain (non-`@Observable`) RT-adjacent data, so this view
|
||||||
|
/// polls it on a `.task` loop — the same convention as `TempoView`'s clock read-out.
|
||||||
|
struct LooperTimelineView: View {
|
||||||
|
|
||||||
|
// MARK: - Constants
|
||||||
|
|
||||||
|
private static let trackHeight: CGFloat = 16
|
||||||
|
private static let trackCornerRadius: CGFloat = 4
|
||||||
|
private static let playheadWidth: CGFloat = 2
|
||||||
|
private static let sectionSpacing: CGFloat = 6
|
||||||
|
private static let labelFontSize: CGFloat = 11
|
||||||
|
private static let trackBrightness: Double = 0.14
|
||||||
|
private static let trackBorderOpacity: Double = 0.35
|
||||||
|
private static let filledOpacity: Double = 0.22
|
||||||
|
private static let pollIntervalNanoseconds: UInt64 = 33_000_000 // ~30 Hz
|
||||||
|
private static let ledDiameter: CGFloat = 9
|
||||||
|
private static let badgeInnerSpacing: CGFloat = 4
|
||||||
|
private static let lengthLabelOpacity: Double = 0.75
|
||||||
|
private static let borderLineWidth: CGFloat = 1
|
||||||
|
private static let dotSpacing: CGFloat = 4
|
||||||
|
private static let dotDiameter: CGFloat = 18
|
||||||
|
private static let dotLabelFontSize: CGFloat = 10
|
||||||
|
private static let dotBrightness: Double = 0.16
|
||||||
|
private static let selectedDotBrightness: Double = 0.32
|
||||||
|
private static let dotFilledOpacity: Double = 0.55
|
||||||
|
private static let dotEmptyOpacity: Double = 0.45
|
||||||
|
private static let activeRingWidth: CGFloat = 1.5
|
||||||
|
private static let mutedDotOpacity: Double = 0.4
|
||||||
|
private static let muteSlashOpacity: Double = 0.9
|
||||||
|
private static let muteSlashWidth: CGFloat = 1.5
|
||||||
|
private static let indicatorFontSize: CGFloat = 11
|
||||||
|
private static let indicatorOpacity: Double = 0.85
|
||||||
|
private static let overdubRingColor: Color = Color.red
|
||||||
|
private static let dotLabels: [String] = ["A", "B", "C", "D", "E", "F", "G", "H"]
|
||||||
|
|
||||||
|
// MARK: - Properties
|
||||||
|
|
||||||
|
private let pedal: LooperPedal
|
||||||
|
|
||||||
|
@State private var position: Double?
|
||||||
|
@State private var state: LooperTransportState = .clear
|
||||||
|
@State private var lengthSeconds: Double = 0.0
|
||||||
|
@State private var lengthBeats: Double = 0.0
|
||||||
|
@State private var selectedTrack: Int = 0
|
||||||
|
@State private var overdubbingTrack: Int?
|
||||||
|
@State private var trackContent: [Bool] = Array(repeating: false, count: LooperPedal.trackCount)
|
||||||
|
@State private var trackMuted: [Bool] = Array(repeating: false, count: LooperPedal.trackCount)
|
||||||
|
@State private var stopArmed: Bool = false
|
||||||
|
@State private var stateDescription: String = ""
|
||||||
|
|
||||||
|
init(pedal: LooperPedal) {
|
||||||
|
self.pedal = pedal
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Body
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VStack(spacing: LooperTimelineView.sectionSpacing) {
|
||||||
|
HStack(spacing: LooperTimelineView.sectionSpacing) {
|
||||||
|
stateBadge
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
trackDots
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
lengthLabel
|
||||||
|
}
|
||||||
|
track
|
||||||
|
stateIndicator
|
||||||
|
}
|
||||||
|
// Key the poll on the pedal instance: if a rig load / rebuild swaps in a new LooperPedal,
|
||||||
|
// `.task` alone would keep polling the old (captured) instance and freeze. Restart on change.
|
||||||
|
.task(id: ObjectIdentifier(pedal)) {
|
||||||
|
while !Task.isCancelled {
|
||||||
|
position = pedal.playbackPosition01()
|
||||||
|
state = pedal.transportState
|
||||||
|
lengthSeconds = pedal.loopLengthSeconds
|
||||||
|
lengthBeats = pedal.loopLengthBeats
|
||||||
|
selectedTrack = pedal.selectedTrackIndex
|
||||||
|
overdubbingTrack = pedal.overdubbingTrackIndex
|
||||||
|
trackContent = (0 ..< LooperPedal.trackCount).map { pedal.trackHasContent($0) }
|
||||||
|
trackMuted = (0 ..< LooperPedal.trackCount).map { pedal.isTrackMuted($0) }
|
||||||
|
stopArmed = pedal.isStopAtLoopEndArmed
|
||||||
|
stateDescription = pedal.stateDescription
|
||||||
|
try? await Task.sleep(nanoseconds: LooperTimelineView.pollIntervalNanoseconds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Subviews
|
||||||
|
|
||||||
|
/// One tappable labelled dot per track: filled when it holds a loop, white-ringed when
|
||||||
|
/// selected, red-ringed while overdubbing, dimmed with a slash when muted. Tapping selects the
|
||||||
|
/// track; tapping the already-selected recorded track mutes/unmutes it.
|
||||||
|
private var trackDots: some View {
|
||||||
|
HStack(spacing: LooperTimelineView.dotSpacing) {
|
||||||
|
ForEach(0 ..< LooperPedal.trackCount, id: \.self) { index in
|
||||||
|
let isSelected: Bool = index == selectedTrack
|
||||||
|
let isOverdub: Bool = index == overdubbingTrack
|
||||||
|
let hasContent: Bool = index < trackContent.count && trackContent[index]
|
||||||
|
let isMuted: Bool = index < trackMuted.count && trackMuted[index]
|
||||||
|
Button {
|
||||||
|
pedal.tapTrack(index)
|
||||||
|
} label: {
|
||||||
|
Text(LooperTimelineView.dotLabels[index])
|
||||||
|
.font(.system(size: LooperTimelineView.dotLabelFontSize, weight: .bold, design: .monospaced))
|
||||||
|
// Selected (or recorded) tracks show a bright letter; other empty tracks dim.
|
||||||
|
.foregroundStyle((hasContent || isSelected) ? Color.white : Color.white.opacity(LooperTimelineView.dotEmptyOpacity))
|
||||||
|
.frame(width: LooperTimelineView.dotDiameter, height: LooperTimelineView.dotDiameter)
|
||||||
|
.background(
|
||||||
|
Circle().fill(hasContent ? Color.green.opacity(LooperTimelineView.dotFilledOpacity)
|
||||||
|
: (isSelected ? Color(white: LooperTimelineView.selectedDotBrightness)
|
||||||
|
: Color(white: LooperTimelineView.dotBrightness)))
|
||||||
|
)
|
||||||
|
.overlay(muteSlash(isMuted))
|
||||||
|
.overlay(
|
||||||
|
Circle().stroke(isOverdub ? LooperTimelineView.overdubRingColor
|
||||||
|
: (isSelected ? Color.white : Color.clear),
|
||||||
|
lineWidth: LooperTimelineView.activeRingWidth)
|
||||||
|
)
|
||||||
|
.opacity(isMuted ? LooperTimelineView.mutedDotOpacity : 1.0)
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A diagonal slash drawn over a muted track's dot.
|
||||||
|
@ViewBuilder
|
||||||
|
private func muteSlash(_ muted: Bool) -> some View {
|
||||||
|
if muted {
|
||||||
|
GeometryReader { geometry in
|
||||||
|
Path { path in
|
||||||
|
path.move(to: CGPoint(x: 0, y: geometry.size.height))
|
||||||
|
path.addLine(to: CGPoint(x: geometry.size.width, y: 0))
|
||||||
|
}
|
||||||
|
.stroke(Color.white.opacity(LooperTimelineView.muteSlashOpacity),
|
||||||
|
lineWidth: LooperTimelineView.muteSlashWidth)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var stateBadge: some View {
|
||||||
|
HStack(spacing: LooperTimelineView.badgeInnerSpacing) {
|
||||||
|
Circle()
|
||||||
|
.fill(stateColor)
|
||||||
|
.frame(width: LooperTimelineView.ledDiameter, height: LooperTimelineView.ledDiameter)
|
||||||
|
Text(stateText)
|
||||||
|
.font(.system(size: LooperTimelineView.labelFontSize, weight: .semibold, design: .monospaced))
|
||||||
|
.foregroundStyle(Color.white)
|
||||||
|
if stopArmed {
|
||||||
|
Text("→END")
|
||||||
|
.font(.system(size: LooperTimelineView.labelFontSize, weight: .semibold, design: .monospaced))
|
||||||
|
.foregroundStyle(Color.orange)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var lengthLabel: some View {
|
||||||
|
Text(lengthText)
|
||||||
|
.font(.system(size: LooperTimelineView.labelFontSize, design: .monospaced))
|
||||||
|
.foregroundStyle(Color.white.opacity(LooperTimelineView.lengthLabelOpacity))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One-line description of what the pedal is doing now — replaces the old action-button row.
|
||||||
|
private var stateIndicator: some View {
|
||||||
|
Text(stateDescription)
|
||||||
|
.font(.system(size: LooperTimelineView.indicatorFontSize, weight: .medium))
|
||||||
|
.foregroundStyle(Color.white.opacity(LooperTimelineView.indicatorOpacity))
|
||||||
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
|
}
|
||||||
|
|
||||||
|
private var track: some View {
|
||||||
|
GeometryReader { geometry in
|
||||||
|
let width: CGFloat = geometry.size.width
|
||||||
|
let pos: CGFloat = CGFloat(position ?? 0.0)
|
||||||
|
ZStack(alignment: .leading) {
|
||||||
|
RoundedRectangle(cornerRadius: LooperTimelineView.trackCornerRadius)
|
||||||
|
.fill(Color(white: LooperTimelineView.trackBrightness))
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: LooperTimelineView.trackCornerRadius)
|
||||||
|
.stroke(Color.white.opacity(LooperTimelineView.trackBorderOpacity),
|
||||||
|
lineWidth: LooperTimelineView.borderLineWidth)
|
||||||
|
)
|
||||||
|
if position != nil {
|
||||||
|
RoundedRectangle(cornerRadius: LooperTimelineView.trackCornerRadius)
|
||||||
|
.fill(Color.white.opacity(LooperTimelineView.filledOpacity))
|
||||||
|
.frame(width: max(0, pos * width))
|
||||||
|
Rectangle()
|
||||||
|
.fill(Color.white)
|
||||||
|
.frame(width: LooperTimelineView.playheadWidth)
|
||||||
|
.offset(x: min(max(0, pos * width), width - LooperTimelineView.playheadWidth))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(height: LooperTimelineView.trackHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - State mapping
|
||||||
|
|
||||||
|
private var stateColor: Color {
|
||||||
|
switch state {
|
||||||
|
case .clear: return Color(white: 0.3)
|
||||||
|
case .armedRecord, .armedClose: return Color.orange
|
||||||
|
case .recordingMaster: return Color.red
|
||||||
|
case .playing: return Color.green
|
||||||
|
case .stopped: return Color.orange
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var stateText: String {
|
||||||
|
switch state {
|
||||||
|
case .clear: return "CLEAR"
|
||||||
|
case .armedRecord: return "ARM"
|
||||||
|
case .recordingMaster: return "REC"
|
||||||
|
case .armedClose: return "END"
|
||||||
|
case .playing: return "PLAY"
|
||||||
|
case .stopped: return "STOP"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private var lengthText: String {
|
||||||
|
guard lengthSeconds > 0 else { return "--" }
|
||||||
|
let seconds: String = String(format: "%.2fs", lengthSeconds)
|
||||||
|
guard lengthBeats > 0 else { return seconds }
|
||||||
|
return seconds + " · \(Int(lengthBeats)) beat" + (lengthBeats == 1 ? "" : "s")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ public struct MIDIMappingSheet: View {
|
|||||||
private static let sheetMinWidth: CGFloat = 460
|
private static let sheetMinWidth: CGFloat = 460
|
||||||
private static let sheetMinHeight: CGFloat = 520
|
private static let sheetMinHeight: CGFloat = 520
|
||||||
private static let rowVerticalPadding: CGFloat = 2
|
private static let rowVerticalPadding: CGFloat = 2
|
||||||
|
private static let switchRowControlSpacing: CGFloat = 8
|
||||||
|
|
||||||
// MARK: - Inputs
|
// MARK: - Inputs
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ public struct MIDIMappingSheet: View {
|
|||||||
switchesSection
|
switchesSection
|
||||||
expressionSection
|
expressionSection
|
||||||
}
|
}
|
||||||
.navigationTitle("MIDI Mapping")
|
.navigationTitle("MIDI / Control Mapping")
|
||||||
.toolbar {
|
.toolbar {
|
||||||
ToolbarItem(placement: .confirmationAction) {
|
ToolbarItem(placement: .confirmationAction) {
|
||||||
Button("Done") {
|
Button("Done") {
|
||||||
@@ -102,23 +103,44 @@ public struct MIDIMappingSheet: View {
|
|||||||
SwitchRowModel(id: "sw-mute", action: .rigMute, label: "Rig Mute"),
|
SwitchRowModel(id: "sw-mute", action: .rigMute, label: "Rig Mute"),
|
||||||
SwitchRowModel(id: "sw-all", action: .allBoards, label: "All Boards On"),
|
SwitchRowModel(id: "sw-all", action: .allBoards, label: "All Boards On"),
|
||||||
]
|
]
|
||||||
for boardPair: (offset: Int, element: PedalBoard) in shoeGaze.boards.enumerated() {
|
for board: PedalBoard in shoeGaze.boards {
|
||||||
let boardIndex: Int = boardPair.offset
|
let boardID: UUID = board.id
|
||||||
let board: PedalBoard = boardPair.element
|
rows.append(SwitchRowModel(id: "sw-solo-\(boardID)",
|
||||||
rows.append(SwitchRowModel(id: "sw-solo-\(boardIndex)",
|
action: .boardSolo(boardID: boardID),
|
||||||
action: .boardSolo(boardIndex: boardIndex),
|
|
||||||
label: "\(board.label) · Solo"))
|
label: "\(board.label) · Solo"))
|
||||||
rows.append(SwitchRowModel(id: "sw-aud-\(boardIndex)",
|
rows.append(SwitchRowModel(id: "sw-aud-\(boardID)",
|
||||||
action: .boardAudible(boardIndex: boardIndex),
|
action: .boardAudible(boardID: boardID),
|
||||||
label: "\(board.label) · Audible"))
|
label: "\(board.label) · Audible"))
|
||||||
rows.append(SwitchRowModel(id: "sw-byp-\(boardIndex)",
|
rows.append(SwitchRowModel(id: "sw-byp-\(boardID)",
|
||||||
action: .boardBypass(boardIndex: boardIndex),
|
action: .boardBypass(boardID: boardID),
|
||||||
label: "\(board.label) · Bypass"))
|
label: "\(board.label) · Bypass"))
|
||||||
for pedalPair: (offset: Int, element: Pedal) in board.pedals.enumerated() {
|
for pedal: Pedal in board.pedals {
|
||||||
rows.append(SwitchRowModel(
|
rows.append(SwitchRowModel(
|
||||||
id: "sw-pb-\(boardIndex)-\(pedalPair.offset)",
|
id: "sw-pb-\(pedal.id)",
|
||||||
action: .pedalBypass(boardIndex: boardIndex, pedalIndex: pedalPair.offset),
|
action: .pedalBypass(pedalID: pedal.id),
|
||||||
label: "\(board.label) · \(pedalPair.element.displayName) · Bypass"))
|
label: "\(board.label) · \(pedal.displayName) · Bypass"))
|
||||||
|
// Loopers expose their transport footswitches as mappable switch actions.
|
||||||
|
if pedal is LooperPedal {
|
||||||
|
var looperActions: [(String, String, MIDIMap.PedalActionKind)] = [
|
||||||
|
("rec", "Record", .looperRecordStop),
|
||||||
|
("stop", "Stop", .looperStop),
|
||||||
|
("cue", "Cue Stop", .looperCueStop),
|
||||||
|
("rev", "Reverse", .looperReverse),
|
||||||
|
("sync", "Sync", .looperSyncToggle),
|
||||||
|
("reset", "Reset", .looperReset),
|
||||||
|
]
|
||||||
|
// A/B/C/D track taps (select / mute), matching the timeline dots.
|
||||||
|
for i: Int in 0 ..< LooperPedal.trackCount {
|
||||||
|
let letter: String = LooperPedal.trackLabel(i)
|
||||||
|
looperActions.append(("track\(letter)", "Track \(letter)", .looperTrack(index: i)))
|
||||||
|
}
|
||||||
|
for (slug, name, kind): (String, String, MIDIMap.PedalActionKind) in looperActions {
|
||||||
|
rows.append(SwitchRowModel(
|
||||||
|
id: "sw-la-\(slug)-\(pedal.id)",
|
||||||
|
action: .pedalAction(pedalID: pedal.id, kind: kind),
|
||||||
|
label: "\(board.label) · \(pedal.displayName) · \(name)"))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return rows
|
return rows
|
||||||
@@ -128,23 +150,18 @@ public struct MIDIMappingSheet: View {
|
|||||||
var rows: [CCRowModel] = [
|
var rows: [CCRowModel] = [
|
||||||
CCRowModel(id: "cc-rigvol", target: .rigVolume, label: "Rig · Volume"),
|
CCRowModel(id: "cc-rigvol", target: .rigVolume, label: "Rig · Volume"),
|
||||||
]
|
]
|
||||||
for boardPair: (offset: Int, element: PedalBoard) in shoeGaze.boards.enumerated() {
|
for board: PedalBoard in shoeGaze.boards {
|
||||||
let boardIndex: Int = boardPair.offset
|
|
||||||
let board: PedalBoard = boardPair.element
|
|
||||||
// Board master level (the board fader).
|
// Board master level (the board fader).
|
||||||
rows.append(CCRowModel(
|
rows.append(CCRowModel(
|
||||||
id: "cc-blvl-\(boardIndex)",
|
id: "cc-blvl-\(board.id)",
|
||||||
target: .boardLevel(boardIndex: boardIndex, boardLabelHint: nil),
|
target: .boardLevel(boardID: board.id, boardLabelHint: nil),
|
||||||
label: "\(board.label) · Level"))
|
label: "\(board.label) · Level"))
|
||||||
for pedalPair: (offset: Int, element: Pedal) in board.pedals.enumerated() {
|
for pedal: Pedal in board.pedals {
|
||||||
let pedalIndex: Int = pedalPair.offset
|
|
||||||
let pedal: Pedal = pedalPair.element
|
|
||||||
for controlPair: (offset: Int, element: PedalControl) in pedal.ccMappableControls.enumerated() {
|
for controlPair: (offset: Int, element: PedalControl) in pedal.ccMappableControls.enumerated() {
|
||||||
rows.append(CCRowModel(
|
rows.append(CCRowModel(
|
||||||
id: "cc-\(boardIndex)-\(pedalIndex)-\(controlPair.offset)",
|
id: "cc-\(pedal.id)-\(controlPair.offset)",
|
||||||
target: .pedalControl(
|
target: .pedalControl(
|
||||||
boardIndex: boardIndex,
|
pedalID: pedal.id,
|
||||||
pedalIndex: pedalIndex,
|
|
||||||
controlIndex: controlPair.offset,
|
controlIndex: controlPair.offset,
|
||||||
pedalNameHint: nil,
|
pedalNameHint: nil,
|
||||||
controlLabelHint: nil),
|
controlLabelHint: nil),
|
||||||
@@ -158,30 +175,37 @@ public struct MIDIMappingSheet: View {
|
|||||||
// MARK: - Switches (Program Change)
|
// MARK: - Switches (Program Change)
|
||||||
|
|
||||||
private var switchesSection: some View {
|
private var switchesSection: some View {
|
||||||
Section("Switches (Program Change)") {
|
Section("Switches (footswitch / key)") {
|
||||||
ForEach(switchRowModels) { row in
|
ForEach(switchRowModels) { row in
|
||||||
switchRow(row)
|
switchRow(row)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A switch row carries two independent trigger sources for one toggle action: a MIDI Program
|
||||||
|
/// Change (footswitch) and a computer key. Each has its own learn / clear; the detail line
|
||||||
|
/// summarises whichever are bound, or the "Listening…" prompt for the armed source.
|
||||||
private func switchRow(_ row: SwitchRowModel) -> some View {
|
private func switchRow(_ row: SwitchRowModel) -> some View {
|
||||||
let isArmed: Bool = controller.learnTarget == .action(row.action)
|
let isArmedPC: Bool = controller.learnTarget == .action(row.action)
|
||||||
let binding: MIDIMap.SwitchBinding? = controller.switchBinding(for: row.action)
|
let isArmedKey: Bool = controller.learnTarget == .key(row.action)
|
||||||
return HStack {
|
let pcBinding: MIDIMap.SwitchBinding? = controller.switchBinding(for: row.action)
|
||||||
|
let keyBinding: MIDIMap.KeyBinding? = controller.keyBinding(for: row.action)
|
||||||
|
let isArmed: Bool = isArmedPC || isArmedKey
|
||||||
|
return HStack(spacing: MIDIMappingSheet.switchRowControlSpacing) {
|
||||||
VStack(alignment: .leading, spacing: 1) {
|
VStack(alignment: .leading, spacing: 1) {
|
||||||
Text(row.label)
|
Text(row.label)
|
||||||
Text(switchBindingLabel(isArmed: isArmed, binding: binding))
|
Text(switchBindingLabel(isArmedPC: isArmedPC, isArmedKey: isArmedKey,
|
||||||
|
pc: pcBinding, key: keyBinding))
|
||||||
.font(.caption)
|
.font(.caption)
|
||||||
.foregroundStyle(isArmed ? Color.orange : .secondary)
|
.foregroundStyle(isArmed ? Color.orange : .secondary)
|
||||||
}
|
}
|
||||||
Spacer()
|
Spacer()
|
||||||
if binding != nil {
|
if pcBinding != nil {
|
||||||
Button("Clear") { controller.clearSwitchBinding(for: row.action) }
|
Button("Clear PC") { controller.clearSwitchBinding(for: row.action) }
|
||||||
.buttonStyle(.borderless)
|
.buttonStyle(.borderless)
|
||||||
}
|
}
|
||||||
Button(isArmed ? "Cancel" : "Learn") {
|
Button(isArmedPC ? "Cancel" : "PC") {
|
||||||
if isArmed {
|
if isArmedPC {
|
||||||
controller.cancelLearn()
|
controller.cancelLearn()
|
||||||
} else {
|
} else {
|
||||||
controller.armSwitchLearn(row.action)
|
controller.armSwitchLearn(row.action)
|
||||||
@@ -189,15 +213,50 @@ public struct MIDIMappingSheet: View {
|
|||||||
}
|
}
|
||||||
.buttonStyle(.bordered)
|
.buttonStyle(.bordered)
|
||||||
.tint(.orange)
|
.tint(.orange)
|
||||||
|
if keyBinding != nil {
|
||||||
|
Button("Clear Key") { controller.clearKeyBinding(for: row.action) }
|
||||||
|
.buttonStyle(.borderless)
|
||||||
|
}
|
||||||
|
Button(isArmedKey ? "Cancel" : "Key") {
|
||||||
|
if isArmedKey {
|
||||||
|
controller.cancelLearn()
|
||||||
|
} else {
|
||||||
|
controller.armKeyLearn(row.action)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.buttonStyle(.bordered)
|
||||||
|
.tint(.orange)
|
||||||
}
|
}
|
||||||
.padding(.vertical, MIDIMappingSheet.rowVerticalPadding)
|
.padding(.vertical, MIDIMappingSheet.rowVerticalPadding)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func switchBindingLabel(isArmed: Bool, binding: MIDIMap.SwitchBinding?) -> String {
|
private func switchBindingLabel(
|
||||||
if isArmed { return "Listening — press a footswitch…" }
|
isArmedPC: Bool,
|
||||||
guard let binding: MIDIMap.SwitchBinding = binding else { return "Unassigned" }
|
isArmedKey: Bool,
|
||||||
let channelText: String = binding.channel.map { " · ch \($0 + 1)" } ?? ""
|
pc: MIDIMap.SwitchBinding?,
|
||||||
return "PC \(binding.program)\(channelText)"
|
key: MIDIMap.KeyBinding?
|
||||||
|
) -> String {
|
||||||
|
if isArmedPC { return "Listening — press a footswitch…" }
|
||||||
|
if isArmedKey { return "Listening — press a key…" }
|
||||||
|
var parts: [String] = []
|
||||||
|
if let pc: MIDIMap.SwitchBinding = pc {
|
||||||
|
let channelText: String = pc.channel.map { " · ch \($0 + 1)" } ?? ""
|
||||||
|
parts.append("PC \(pc.program)\(channelText)")
|
||||||
|
}
|
||||||
|
if let key: MIDIMap.KeyBinding = key {
|
||||||
|
parts.append("Key \(keyLabel(key))")
|
||||||
|
}
|
||||||
|
return parts.isEmpty ? "Unassigned" : parts.joined(separator: " · ")
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A key binding formatted with its modifier glyphs, e.g. `A`, `⇧A`, `⌃A` (macOS modifier order:
|
||||||
|
/// control, option, shift).
|
||||||
|
private func keyLabel(_ binding: MIDIMap.KeyBinding) -> String {
|
||||||
|
var prefix: String = ""
|
||||||
|
if binding.modifiers.contains(.control) { prefix += "⌃" }
|
||||||
|
if binding.modifiers.contains(.option) { prefix += "⌥" }
|
||||||
|
if binding.modifiers.contains(.shift) { prefix += "⇧" }
|
||||||
|
return prefix + binding.key.uppercased()
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Expression (CC)
|
// MARK: - Expression (CC)
|
||||||
|
|||||||
@@ -0,0 +1,244 @@
|
|||||||
|
// NoteGlyphView.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
// MARK: - Notation spec
|
||||||
|
|
||||||
|
/// The notation elements that make up one ``NoteDivision`` glyph. Derived purely from the division;
|
||||||
|
/// consumed by ``NoteGlyphView`` to draw the note.
|
||||||
|
private struct NoteGlyphSpec {
|
||||||
|
|
||||||
|
/// `true` for a solid notehead (quarter and shorter), `false` for an open ring (whole, half).
|
||||||
|
let filledHead: Bool
|
||||||
|
/// `true` when the note has a vertical stem (everything except the whole note).
|
||||||
|
let hasStem: Bool
|
||||||
|
/// Number of flags on the stem (`0` = quarter/half, `1` = eighth, `2` = sixteenth).
|
||||||
|
let flags: Int
|
||||||
|
/// `true` for a dotted value — adds an augmentation dot right of the head.
|
||||||
|
let dotted: Bool
|
||||||
|
/// `true` for a triplet — adds a bracket with a "3" above the note.
|
||||||
|
let triplet: Bool
|
||||||
|
|
||||||
|
init(_ division: NoteDivision) {
|
||||||
|
switch division {
|
||||||
|
case .whole:
|
||||||
|
self.init(filledHead: false, hasStem: false, flags: 0, dotted: false, triplet: false)
|
||||||
|
case .dottedHalf:
|
||||||
|
self.init(filledHead: false, hasStem: true, flags: 0, dotted: true, triplet: false)
|
||||||
|
case .half:
|
||||||
|
self.init(filledHead: false, hasStem: true, flags: 0, dotted: false, triplet: false)
|
||||||
|
case .dottedQuarter:
|
||||||
|
self.init(filledHead: true, hasStem: true, flags: 0, dotted: true, triplet: false)
|
||||||
|
case .quarter:
|
||||||
|
self.init(filledHead: true, hasStem: true, flags: 0, dotted: false, triplet: false)
|
||||||
|
case .dottedEighth:
|
||||||
|
self.init(filledHead: true, hasStem: true, flags: 1, dotted: true, triplet: false)
|
||||||
|
case .quarterTriplet:
|
||||||
|
self.init(filledHead: true, hasStem: true, flags: 0, dotted: false, triplet: true)
|
||||||
|
case .eighth:
|
||||||
|
self.init(filledHead: true, hasStem: true, flags: 1, dotted: false, triplet: false)
|
||||||
|
case .eighthTriplet:
|
||||||
|
self.init(filledHead: true, hasStem: true, flags: 1, dotted: false, triplet: true)
|
||||||
|
case .sixteenth:
|
||||||
|
self.init(filledHead: true, hasStem: true, flags: 2, dotted: false, triplet: false)
|
||||||
|
case .sixteenthTriplet:
|
||||||
|
self.init(filledHead: true, hasStem: true, flags: 2, dotted: false, triplet: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private init(filledHead: Bool, hasStem: Bool, flags: Int, dotted: Bool, triplet: Bool) {
|
||||||
|
self.filledHead = filledHead
|
||||||
|
self.hasStem = hasStem
|
||||||
|
self.flags = flags
|
||||||
|
self.dotted = dotted
|
||||||
|
self.triplet = triplet
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - NoteGlyphView
|
||||||
|
|
||||||
|
/// Draws a single music-notation glyph for a ``NoteDivision`` — notehead, stem, flags, an
|
||||||
|
/// augmentation dot for dotted values, and a bracketed "3" for triplets — with `Canvas`.
|
||||||
|
///
|
||||||
|
/// Drawn in solid black so the rasterized image can be used as a **template** in a menu (only the
|
||||||
|
/// alpha channel matters; the system tints it to the menu's foreground colour). See
|
||||||
|
/// ``NoteGlyphImageCache``.
|
||||||
|
struct NoteGlyphView: View {
|
||||||
|
|
||||||
|
// Logical drawing box. The note sits in the lower portion; the triplet bracket uses the top,
|
||||||
|
// which is left clear on every glyph so the note baseline stays consistent across the menu.
|
||||||
|
private static let boxWidth: CGFloat = 18
|
||||||
|
private static let boxHeight: CGFloat = 26
|
||||||
|
|
||||||
|
// Notehead.
|
||||||
|
private static let headCenterX: CGFloat = 6.5
|
||||||
|
private static let headCenterY: CGFloat = 19.0
|
||||||
|
private static let headRadiusX: CGFloat = 4.3
|
||||||
|
private static let headRadiusY: CGFloat = 3.0
|
||||||
|
private static let wholeHeadRadiusX: CGFloat = 5.0
|
||||||
|
private static let openHeadLineWidth: CGFloat = 1.5
|
||||||
|
|
||||||
|
// Stem.
|
||||||
|
private static let stemLineWidth: CGFloat = 1.3
|
||||||
|
private static let stemTopY: CGFloat = 8.0
|
||||||
|
|
||||||
|
// Flags.
|
||||||
|
private static let flagLineWidth: CGFloat = 1.5
|
||||||
|
private static let flagSpread: CGFloat = 5.5
|
||||||
|
private static let flagDrop: CGFloat = 6.0
|
||||||
|
private static let flagGap: CGFloat = 3.5
|
||||||
|
|
||||||
|
// Augmentation dot — pushed clear of the notehead's right edge.
|
||||||
|
private static let dotRadius: CGFloat = 1.5
|
||||||
|
private static let dotGap: CGFloat = 3.8
|
||||||
|
|
||||||
|
// Triplet bracket + numeral. The "3" is centred in the bracket gap; `bracketTopY` leaves room
|
||||||
|
// above it so the numeral is never clipped by the raster bounds.
|
||||||
|
private static let bracketTopY: CGFloat = 4.0
|
||||||
|
private static let bracketTickHeight: CGFloat = 2.0
|
||||||
|
private static let bracketInsetX: CGFloat = 1.5
|
||||||
|
private static let bracketLineWidth: CGFloat = 1.0
|
||||||
|
private static let bracketNumberGap: CGFloat = 3.0
|
||||||
|
private static let bracketNumberSize: CGFloat = 6.0
|
||||||
|
|
||||||
|
let division: NoteDivision
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Canvas { context, size in
|
||||||
|
let scaleX: CGFloat = size.width / NoteGlyphView.boxWidth
|
||||||
|
let scaleY: CGFloat = size.height / NoteGlyphView.boxHeight
|
||||||
|
let s: CGFloat = min(scaleX, scaleY)
|
||||||
|
context.scaleBy(x: s, y: s)
|
||||||
|
draw(NoteGlyphSpec(division), in: &context)
|
||||||
|
}
|
||||||
|
.frame(width: NoteGlyphView.boxWidth, height: NoteGlyphView.boxHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func draw(_ spec: NoteGlyphSpec, in context: inout GraphicsContext) {
|
||||||
|
let ink: GraphicsContext.Shading = .color(.black)
|
||||||
|
|
||||||
|
// Stem — draw before the head so the head overlaps its lower end cleanly.
|
||||||
|
let stemX: CGFloat = NoteGlyphView.headCenterX + NoteGlyphView.headRadiusX - 0.3
|
||||||
|
if spec.hasStem {
|
||||||
|
var stem: Path = Path()
|
||||||
|
stem.move(to: CGPoint(x: stemX, y: NoteGlyphView.headCenterY))
|
||||||
|
stem.addLine(to: CGPoint(x: stemX, y: NoteGlyphView.stemTopY))
|
||||||
|
context.stroke(stem, with: ink, lineWidth: NoteGlyphView.stemLineWidth)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flags — hooks off the top of the stem, one per flag, stacked downward.
|
||||||
|
for flagIndex: Int in 0 ..< spec.flags {
|
||||||
|
let startY: CGFloat = NoteGlyphView.stemTopY + CGFloat(flagIndex) * NoteGlyphView.flagGap
|
||||||
|
var flag: Path = Path()
|
||||||
|
flag.move(to: CGPoint(x: stemX, y: startY))
|
||||||
|
flag.addQuadCurve(
|
||||||
|
to: CGPoint(x: stemX + NoteGlyphView.flagSpread, y: startY + NoteGlyphView.flagDrop),
|
||||||
|
control: CGPoint(x: stemX + NoteGlyphView.flagSpread, y: startY)
|
||||||
|
)
|
||||||
|
context.stroke(flag, with: ink, lineWidth: NoteGlyphView.flagLineWidth)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notehead.
|
||||||
|
let headRadiusX: CGFloat = spec.hasStem ? NoteGlyphView.headRadiusX : NoteGlyphView.wholeHeadRadiusX
|
||||||
|
let headRect: CGRect = CGRect(
|
||||||
|
x: NoteGlyphView.headCenterX - headRadiusX,
|
||||||
|
y: NoteGlyphView.headCenterY - NoteGlyphView.headRadiusY,
|
||||||
|
width: headRadiusX * 2,
|
||||||
|
height: NoteGlyphView.headRadiusY * 2
|
||||||
|
)
|
||||||
|
let headPath: Path = Path(ellipseIn: headRect)
|
||||||
|
if spec.filledHead {
|
||||||
|
context.fill(headPath, with: ink)
|
||||||
|
} else {
|
||||||
|
context.stroke(headPath, with: ink, lineWidth: NoteGlyphView.openHeadLineWidth)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Augmentation dot, right of the head.
|
||||||
|
if spec.dotted {
|
||||||
|
let dotX: CGFloat = NoteGlyphView.headCenterX + headRadiusX + NoteGlyphView.dotGap
|
||||||
|
let dotRect: CGRect = CGRect(
|
||||||
|
x: dotX - NoteGlyphView.dotRadius,
|
||||||
|
y: NoteGlyphView.headCenterY - NoteGlyphView.dotRadius,
|
||||||
|
width: NoteGlyphView.dotRadius * 2,
|
||||||
|
height: NoteGlyphView.dotRadius * 2
|
||||||
|
)
|
||||||
|
context.fill(Path(ellipseIn: dotRect), with: ink)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Triplet bracket with a centred "3".
|
||||||
|
if spec.triplet {
|
||||||
|
drawTripletBracket(in: &context, ink: ink)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func drawTripletBracket(in context: inout GraphicsContext, ink: GraphicsContext.Shading) {
|
||||||
|
let leftX: CGFloat = NoteGlyphView.bracketInsetX
|
||||||
|
let rightX: CGFloat = NoteGlyphView.boxWidth - NoteGlyphView.bracketInsetX
|
||||||
|
let midX: CGFloat = (leftX + rightX) / 2
|
||||||
|
let topY: CGFloat = NoteGlyphView.bracketTopY
|
||||||
|
let tickBottomY: CGFloat = topY + NoteGlyphView.bracketTickHeight
|
||||||
|
let gap: CGFloat = NoteGlyphView.bracketNumberGap
|
||||||
|
|
||||||
|
var bracket: Path = Path()
|
||||||
|
// Left tick down, then horizontal to the number gap.
|
||||||
|
bracket.move(to: CGPoint(x: leftX, y: tickBottomY))
|
||||||
|
bracket.addLine(to: CGPoint(x: leftX, y: topY))
|
||||||
|
bracket.addLine(to: CGPoint(x: midX - gap, y: topY))
|
||||||
|
// Right side: horizontal from the gap out to the right tick, then down.
|
||||||
|
bracket.move(to: CGPoint(x: midX + gap, y: topY))
|
||||||
|
bracket.addLine(to: CGPoint(x: rightX, y: topY))
|
||||||
|
bracket.addLine(to: CGPoint(x: rightX, y: tickBottomY))
|
||||||
|
context.stroke(bracket, with: ink, lineWidth: NoteGlyphView.bracketLineWidth)
|
||||||
|
|
||||||
|
let numeral: GraphicsContext.ResolvedText = context.resolve(
|
||||||
|
Text("3")
|
||||||
|
.font(.system(size: NoteGlyphView.bracketNumberSize, weight: .semibold, design: .rounded))
|
||||||
|
.foregroundColor(.black)
|
||||||
|
)
|
||||||
|
context.draw(numeral, at: CGPoint(x: midX, y: topY), anchor: .center)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Rasterization cache
|
||||||
|
|
||||||
|
/// Renders each ``NoteDivision`` glyph to a template `Image` once and caches it, so the tempo-sync
|
||||||
|
/// menu can show notation icons without re-rasterizing on every render. Template images tint to the
|
||||||
|
/// menu's foreground colour automatically.
|
||||||
|
@MainActor
|
||||||
|
enum NoteGlyphImageCache {
|
||||||
|
|
||||||
|
private static let renderScale: CGFloat = 3.0
|
||||||
|
private static var cache: [NoteDivision: Image] = [:]
|
||||||
|
|
||||||
|
/// The cached notation glyph for `division`, rendered on first request.
|
||||||
|
static func image(for division: NoteDivision) -> Image {
|
||||||
|
if let existing: Image = cache[division] {
|
||||||
|
return existing
|
||||||
|
}
|
||||||
|
let rendered: Image = render(division)
|
||||||
|
cache[division] = rendered
|
||||||
|
return rendered
|
||||||
|
}
|
||||||
|
|
||||||
|
private static func render(_ division: NoteDivision) -> Image {
|
||||||
|
let renderer: ImageRenderer = ImageRenderer(content: NoteGlyphView(division: division))
|
||||||
|
renderer.scale = renderScale
|
||||||
|
#if os(macOS)
|
||||||
|
if let nsImage = renderer.nsImage {
|
||||||
|
nsImage.isTemplate = true
|
||||||
|
return Image(nsImage: nsImage)
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if let uiImage = renderer.uiImage {
|
||||||
|
return Image(uiImage: uiImage.withRenderingMode(.alwaysTemplate))
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// Fallback to the division's text label if rasterization ever fails.
|
||||||
|
return Image(systemName: "music.note")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
// PedalButtonView.swift
|
||||||
|
// Lyrebird
|
||||||
|
//
|
||||||
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
import LyrebirdUI
|
||||||
|
import LyrebirdShoeGaze
|
||||||
|
|
||||||
|
// MARK: - PedalButtonView
|
||||||
|
|
||||||
|
/// A stomp-style action button rendered from a ``PedalButton`` descriptor.
|
||||||
|
///
|
||||||
|
/// `.momentary` renders a plain `ParameterButton`. `.toggle` renders the same LED +
|
||||||
|
/// footswitch look as the pedal's own bypass control (`PedalView`'s `LEDIndicator` /
|
||||||
|
/// `FootswitchButton`), with a caption label beneath — so a looper's Overdub/Loop toggles
|
||||||
|
/// read as stomp switches with state, not a segmented picker.
|
||||||
|
///
|
||||||
|
/// ## Usage
|
||||||
|
/// ```swift
|
||||||
|
/// PedalButtonView(pedalButton)
|
||||||
|
/// ```
|
||||||
|
public struct PedalButtonView: View {
|
||||||
|
|
||||||
|
private static let toggleOnThreshold: Double = 0.5
|
||||||
|
private static let sectionSpacing: CGFloat = 6
|
||||||
|
private static let captionFontSize: CGFloat = 11
|
||||||
|
|
||||||
|
private let pedalButton: PedalButton
|
||||||
|
|
||||||
|
/// Creates a button view from a descriptor.
|
||||||
|
///
|
||||||
|
/// - Parameter pedalButton: The button to render.
|
||||||
|
public init(_ pedalButton: PedalButton) {
|
||||||
|
self.pedalButton = pedalButton
|
||||||
|
}
|
||||||
|
|
||||||
|
public var body: some View {
|
||||||
|
switch pedalButton.style {
|
||||||
|
case .momentary:
|
||||||
|
if let indicator: UIParamNode = pedalButton.indicator {
|
||||||
|
// LED + footswitch, same look as a toggle, but the press runs an action and the
|
||||||
|
// LED reflects a separate state node (e.g. Stop lit while stopped). Reading
|
||||||
|
// `indicator.value` registers this view for @Observable re-render.
|
||||||
|
let isOn: Bool = indicator.value >= PedalButtonView.toggleOnThreshold
|
||||||
|
VStack(spacing: PedalButtonView.sectionSpacing) {
|
||||||
|
LEDIndicator(isOn: isOn)
|
||||||
|
FootswitchButton(action: pedalButton.action ?? {})
|
||||||
|
caption
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ParameterButton(pedalButton.label, action: pedalButton.action ?? {})
|
||||||
|
}
|
||||||
|
case .toggle:
|
||||||
|
if let node: UIParamNode = pedalButton.node {
|
||||||
|
// Reading `node.value` registers this view for @Observable re-render.
|
||||||
|
let isOn: Bool = node.value >= PedalButtonView.toggleOnThreshold
|
||||||
|
VStack(spacing: PedalButtonView.sectionSpacing) {
|
||||||
|
LEDIndicator(isOn: isOn)
|
||||||
|
FootswitchButton(node: node)
|
||||||
|
caption
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The button caption — a live "what the next press does" label when the descriptor supplies
|
||||||
|
/// a `dynamicLabel`, otherwise the static label.
|
||||||
|
@ViewBuilder
|
||||||
|
private var caption: some View {
|
||||||
|
if let provider: () -> String = pedalButton.dynamicLabel {
|
||||||
|
DynamicCaption(provider: provider, fallback: pedalButton.label)
|
||||||
|
.font(.system(size: PedalButtonView.captionFontSize))
|
||||||
|
.foregroundStyle(Color.white)
|
||||||
|
} else {
|
||||||
|
Text(pedalButton.label)
|
||||||
|
.font(.system(size: PedalButtonView.captionFontSize))
|
||||||
|
.foregroundStyle(Color.white)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - DynamicCaption
|
||||||
|
|
||||||
|
/// A caption that polls a text provider (RT-adjacent pedal state that isn't `@Observable`), on
|
||||||
|
/// the same `.task` cadence as the looper timeline, so a state-driven button label stays current.
|
||||||
|
private struct DynamicCaption: View {
|
||||||
|
|
||||||
|
private static let pollIntervalNanoseconds: UInt64 = 33_000_000 // ~30 Hz
|
||||||
|
|
||||||
|
let provider: () -> String
|
||||||
|
let fallback: String
|
||||||
|
|
||||||
|
@State private var text: String = ""
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
Text(text.isEmpty ? fallback : text)
|
||||||
|
.task {
|
||||||
|
while !Task.isCancelled {
|
||||||
|
text = provider()
|
||||||
|
try? await Task.sleep(nanoseconds: DynamicCaption.pollIntervalNanoseconds)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ import SwiftUI
|
|||||||
/// A presentation grouping for pedals in the palette — used to colour-code the picker cards and to
|
/// A presentation grouping for pedals in the palette — used to colour-code the picker cards and to
|
||||||
/// drive the "filter by type" menu. Purely a UI concern: the mapping from a pedal's `displayName`
|
/// drive the "filter by type" menu. Purely a UI concern: the mapping from a pedal's `displayName`
|
||||||
/// to its category lives here, keyed by name like ``PedalPaletteView``'s preferred order.
|
/// to its category lives here, keyed by name like ``PedalPaletteView``'s preferred order.
|
||||||
enum PedalCategory: String, CaseIterable, Identifiable {
|
public enum PedalCategory: String, CaseIterable, Identifiable, Sendable {
|
||||||
case gain = "Gain"
|
case gain = "Gain"
|
||||||
case dynamics = "Dynamics"
|
case dynamics = "Dynamics"
|
||||||
case filter = "EQ & Filter"
|
case filter = "EQ & Filter"
|
||||||
@@ -19,7 +19,7 @@ enum PedalCategory: String, CaseIterable, Identifiable {
|
|||||||
case reverb = "Reverb"
|
case reverb = "Reverb"
|
||||||
case texture = "Texture"
|
case texture = "Texture"
|
||||||
|
|
||||||
var id: String { rawValue }
|
public var id: String { rawValue }
|
||||||
|
|
||||||
/// Accent colour used to tint the palette card and the filter chip.
|
/// Accent colour used to tint the palette card and the filter chip.
|
||||||
var color: Color {
|
var color: Color {
|
||||||
|
|||||||
@@ -83,9 +83,25 @@ public struct PedalPaletteView: View {
|
|||||||
private let onAdd: (String) -> Void
|
private let onAdd: (String) -> Void
|
||||||
private let onRouting: (RoutingAction) -> Void
|
private let onRouting: (RoutingAction) -> Void
|
||||||
private let axis: Axis
|
private let axis: Axis
|
||||||
|
private let showsFilterMenu: Bool
|
||||||
|
|
||||||
/// Active type filter; `nil` shows all pedals.
|
/// Active type filter when the palette owns it; `nil` shows all pedals. Ignored when an
|
||||||
@State private var filter: PedalCategory?
|
/// `externalFilter` binding is supplied (the host hoists the filter into its own header).
|
||||||
|
@State private var internalFilter: PedalCategory?
|
||||||
|
private let externalFilter: Binding<PedalCategory?>?
|
||||||
|
|
||||||
|
/// The live filter, from the host binding if provided, else the palette's own state.
|
||||||
|
private var activeFilter: PedalCategory? {
|
||||||
|
externalFilter?.wrappedValue ?? internalFilter
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setFilter(_ category: PedalCategory?) {
|
||||||
|
if let externalFilter: Binding<PedalCategory?> = externalFilter {
|
||||||
|
externalFilter.wrappedValue = category
|
||||||
|
} else {
|
||||||
|
internalFilter = category
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Init
|
// MARK: - Init
|
||||||
|
|
||||||
@@ -95,15 +111,23 @@ public struct PedalPaletteView: View {
|
|||||||
/// - axis: `.vertical` (default) lays the catalog out as a full-width column for a sidebar;
|
/// - axis: `.vertical` (default) lays the catalog out as a full-width column for a sidebar;
|
||||||
/// `.horizontal` lays it out as a fixed-width-card row for a horizontal scroller. The host
|
/// `.horizontal` lays it out as a fixed-width-card row for a horizontal scroller. The host
|
||||||
/// wraps the view in a `ScrollView` of the matching axis.
|
/// wraps the view in a `ScrollView` of the matching axis.
|
||||||
|
/// - filter: Optional external binding for the type filter, so a host (e.g. a sheet) can put
|
||||||
|
/// the filter control in its own fixed header. When `nil` the palette manages its own filter.
|
||||||
|
/// - showsFilterMenu: Whether to draw the built-in filter menu inline. Pass `false` when the
|
||||||
|
/// host renders its own filter control. Defaults to `true`.
|
||||||
/// - onAdd: Invoked with a pedal's `displayName` when its row is tapped (append to main chain).
|
/// - onAdd: Invoked with a pedal's `displayName` when its row is tapped (append to main chain).
|
||||||
/// Rows are also `.draggable` carrying `"add:<displayName>"` for drop-onto-lane targeting.
|
/// Rows are also `.draggable` carrying `"add:<displayName>"` for drop-onto-lane targeting.
|
||||||
/// - onRouting: Invoked when a routing row is tapped. Defaults to a no-op.
|
/// - onRouting: Invoked when a routing row is tapped. Defaults to a no-op.
|
||||||
public init(
|
public init(
|
||||||
axis: Axis = .vertical,
|
axis: Axis = .vertical,
|
||||||
|
filter: Binding<PedalCategory?>? = nil,
|
||||||
|
showsFilterMenu: Bool = true,
|
||||||
onAdd: @escaping (String) -> Void,
|
onAdd: @escaping (String) -> Void,
|
||||||
onRouting: @escaping (RoutingAction) -> Void = { _ in }
|
onRouting: @escaping (RoutingAction) -> Void = { _ in }
|
||||||
) {
|
) {
|
||||||
self.axis = axis
|
self.axis = axis
|
||||||
|
self.externalFilter = filter
|
||||||
|
self.showsFilterMenu = showsFilterMenu
|
||||||
self.onAdd = onAdd
|
self.onAdd = onAdd
|
||||||
self.onRouting = onRouting
|
self.onRouting = onRouting
|
||||||
}
|
}
|
||||||
@@ -120,7 +144,7 @@ public struct PedalPaletteView: View {
|
|||||||
|
|
||||||
/// Pedal names after applying the active type filter.
|
/// Pedal names after applying the active type filter.
|
||||||
private var visiblePedalNames: [String] {
|
private var visiblePedalNames: [String] {
|
||||||
guard let filter: PedalCategory = filter else { return orderedPedalNames }
|
guard let filter: PedalCategory = activeFilter else { return orderedPedalNames }
|
||||||
return orderedPedalNames.filter { PedalCategory.category(for: $0) == filter }
|
return orderedPedalNames.filter { PedalCategory.category(for: $0) == filter }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +175,7 @@ public struct PedalPaletteView: View {
|
|||||||
HStack {
|
HStack {
|
||||||
sectionTitle("PEDALS")
|
sectionTitle("PEDALS")
|
||||||
Spacer(minLength: 0)
|
Spacer(minLength: 0)
|
||||||
filterMenu
|
if showsFilterMenu { filterMenu }
|
||||||
}
|
}
|
||||||
ForEach(visiblePedalNames, id: \.self) { name in
|
ForEach(visiblePedalNames, id: \.self) { name in
|
||||||
pedalRow(name)
|
pedalRow(name)
|
||||||
@@ -174,7 +198,7 @@ public struct PedalPaletteView: View {
|
|||||||
HStack(alignment: .top, spacing: PedalPaletteView.sectionSpacing) {
|
HStack(alignment: .top, spacing: PedalPaletteView.sectionSpacing) {
|
||||||
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
|
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
|
||||||
sectionTitle("PEDALS")
|
sectionTitle("PEDALS")
|
||||||
filterMenu
|
if showsFilterMenu { filterMenu }
|
||||||
}
|
}
|
||||||
ForEach(groupedVisiblePedals, id: \.category) { group in
|
ForEach(groupedVisiblePedals, id: \.category) { group in
|
||||||
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
|
VStack(alignment: .leading, spacing: PedalPaletteView.rowSpacing) {
|
||||||
@@ -215,18 +239,18 @@ public struct PedalPaletteView: View {
|
|||||||
/// "Filter by type" menu — defaults to **All** (no filtering).
|
/// "Filter by type" menu — defaults to **All** (no filtering).
|
||||||
private var filterMenu: some View {
|
private var filterMenu: some View {
|
||||||
Menu {
|
Menu {
|
||||||
Button("All Types") { filter = nil }
|
Button("All Types") { setFilter(nil) }
|
||||||
Divider()
|
Divider()
|
||||||
ForEach(PedalCategory.allCases) { category in
|
ForEach(PedalCategory.allCases) { category in
|
||||||
Button(category.rawValue) { filter = category }
|
Button(category.rawValue) { setFilter(category) }
|
||||||
}
|
}
|
||||||
} label: {
|
} label: {
|
||||||
HStack(spacing: 3) {
|
HStack(spacing: 3) {
|
||||||
Image(systemName: "line.3.horizontal.decrease.circle")
|
Image(systemName: "line.3.horizontal.decrease.circle")
|
||||||
Text(filter?.rawValue ?? "All").lineLimit(1)
|
Text(activeFilter?.rawValue ?? "All").lineLimit(1)
|
||||||
}
|
}
|
||||||
.font(.system(size: PedalPaletteView.titleFontSize))
|
.font(.system(size: PedalPaletteView.titleFontSize))
|
||||||
.foregroundStyle((filter?.color ?? Color.white).opacity(0.9))
|
.foregroundStyle((activeFilter?.color ?? Color.white).opacity(0.9))
|
||||||
}
|
}
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
.menuStyle(.borderlessButton)
|
.menuStyle(.borderlessButton)
|
||||||
|
|||||||
@@ -43,10 +43,15 @@ public struct PedalSwitchView: View {
|
|||||||
private static let borderLineWidth: CGFloat = 1
|
private static let borderLineWidth: CGFloat = 1
|
||||||
private static let activeTextBrightness: Double = 0.12
|
private static let activeTextBrightness: Double = 0.12
|
||||||
|
|
||||||
|
/// Opacity applied to a tempo-dependent switch while the tempo indicator is turned off.
|
||||||
|
private static let tempoDisabledOpacity: Double = 0.4
|
||||||
|
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
|
|
||||||
private let pedalSwitch: PedalSwitch
|
private let pedalSwitch: PedalSwitch
|
||||||
|
|
||||||
|
@Environment(\.shoeGazeTempoEnabled) private var tempoEnabled: Bool
|
||||||
|
|
||||||
// MARK: - Init
|
// MARK: - Init
|
||||||
|
|
||||||
/// Creates a segmented switch view.
|
/// Creates a segmented switch view.
|
||||||
@@ -62,6 +67,8 @@ public struct PedalSwitchView: View {
|
|||||||
// Reading `node.value` registers this view for @Observable re-render on change.
|
// Reading `node.value` registers this view for @Observable re-render on change.
|
||||||
let current: Double = pedalSwitch.node.value
|
let current: Double = pedalSwitch.node.value
|
||||||
let selectedIndex: Int = nearestIndex(to: current)
|
let selectedIndex: Int = nearestIndex(to: current)
|
||||||
|
// A tempo-synced switch is inert while the tempo indicator is turned off.
|
||||||
|
let inert: Bool = pedalSwitch.tempoDependent && !tempoEnabled
|
||||||
|
|
||||||
VStack(spacing: PedalSwitchView.labelSpacing) {
|
VStack(spacing: PedalSwitchView.labelSpacing) {
|
||||||
HStack(spacing: PedalSwitchView.segmentSpacing) {
|
HStack(spacing: PedalSwitchView.segmentSpacing) {
|
||||||
@@ -77,10 +84,12 @@ public struct PedalSwitchView: View {
|
|||||||
lineWidth: PedalSwitchView.borderLineWidth)
|
lineWidth: PedalSwitchView.borderLineWidth)
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(pedalSwitch.label)
|
Text(inert ? "\(pedalSwitch.label) (tempo off)" : pedalSwitch.label)
|
||||||
.font(.system(size: PedalSwitchView.captionFontSize))
|
.font(.system(size: PedalSwitchView.captionFontSize))
|
||||||
.foregroundStyle(Color.white)
|
.foregroundStyle(Color.white)
|
||||||
}
|
}
|
||||||
|
.disabled(inert)
|
||||||
|
.opacity(inert ? PedalSwitchView.tempoDisabledOpacity : 1.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Subviews
|
// MARK: - Subviews
|
||||||
|
|||||||
@@ -90,9 +90,11 @@ private struct ScrewDot: View {
|
|||||||
|
|
||||||
/// A small circular LED that glows green when the effect is engaged.
|
/// A small circular LED that glows green when the effect is engaged.
|
||||||
///
|
///
|
||||||
/// Bypass polarity: `0` = engaged (effect ON), `1` = bypassed.
|
/// A small round LED, lit green when `isOn` and dark otherwise. Polarity-agnostic — the
|
||||||
/// The LED is lit when `bypassValue < 0.5`.
|
/// caller decides what `isOn` means for its own control (e.g. bypass's `value < 0.5`, or a
|
||||||
private struct LEDIndicator: View {
|
/// plain toggle's `value >= 0.5`). `internal` (not `private`) so other views in this module
|
||||||
|
/// (e.g. `PedalButtonView`) can reuse the same stompbox LED look.
|
||||||
|
struct LEDIndicator: View {
|
||||||
|
|
||||||
private static let diameter: CGFloat = 10
|
private static let diameter: CGFloat = 10
|
||||||
private static let glowRadius: CGFloat = 6
|
private static let glowRadius: CGFloat = 6
|
||||||
@@ -101,13 +103,11 @@ private struct LEDIndicator: View {
|
|||||||
private static let dimBrightness: Double = 0.15
|
private static let dimBrightness: Double = 0.15
|
||||||
private static let rimStrokeOpacity: Double = 0.30
|
private static let rimStrokeOpacity: Double = 0.30
|
||||||
|
|
||||||
let bypassValue: Double
|
let isOn: Bool
|
||||||
|
|
||||||
private var isEngaged: Bool { bypassValue < 0.5 }
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
if isEngaged {
|
if isOn {
|
||||||
Circle()
|
Circle()
|
||||||
.fill(Color.green.opacity(LEDIndicator.glowOpacity))
|
.fill(Color.green.opacity(LEDIndicator.glowOpacity))
|
||||||
.frame(
|
.frame(
|
||||||
@@ -117,7 +117,7 @@ private struct LEDIndicator: View {
|
|||||||
.blur(radius: LEDIndicator.glowRadius / 2)
|
.blur(radius: LEDIndicator.glowRadius / 2)
|
||||||
}
|
}
|
||||||
Circle()
|
Circle()
|
||||||
.fill(isEngaged ? Color.green : Color(white: LEDIndicator.dimBrightness))
|
.fill(isOn ? Color.green : Color(white: LEDIndicator.dimBrightness))
|
||||||
.frame(width: LEDIndicator.diameter, height: LEDIndicator.diameter)
|
.frame(width: LEDIndicator.diameter, height: LEDIndicator.diameter)
|
||||||
.overlay(
|
.overlay(
|
||||||
Circle()
|
Circle()
|
||||||
@@ -132,8 +132,11 @@ private struct LEDIndicator: View {
|
|||||||
|
|
||||||
// MARK: - Footswitch
|
// MARK: - Footswitch
|
||||||
|
|
||||||
/// A round footswitch-style button that toggles bypass on/off.
|
/// A round footswitch-style button. Either flips a bound `UIParamNode` between `0` and `1`
|
||||||
private struct FootswitchButton: View {
|
/// (toggle) or runs an arbitrary action (momentary) — both render the identical stompbox look.
|
||||||
|
/// `internal` (not `private`) so other views in this module (e.g. `PedalButtonView`) can reuse
|
||||||
|
/// it for non-bypass toggles and momentary stomp actions.
|
||||||
|
struct FootswitchButton: View {
|
||||||
|
|
||||||
private static let diameter: CGFloat = 44
|
private static let diameter: CGFloat = 44
|
||||||
private static let strokeWidth: CGFloat = 2.5
|
private static let strokeWidth: CGFloat = 2.5
|
||||||
@@ -142,14 +145,23 @@ private struct FootswitchButton: View {
|
|||||||
private static let ringBrightness: Double = 0.50
|
private static let ringBrightness: Double = 0.50
|
||||||
private static let innerFillBrightness: Double = 0.25
|
private static let innerFillBrightness: Double = 0.25
|
||||||
|
|
||||||
let node: UIParamNode
|
private let action: () -> Void
|
||||||
|
|
||||||
|
/// Flips `node` between `0` and `1` on each press.
|
||||||
|
init(node: UIParamNode) {
|
||||||
|
self.action = {
|
||||||
|
let engaged: Bool = node.value < 0.5
|
||||||
|
node.update(engaged ? 1.0 : 0.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Runs `action` on each press (momentary).
|
||||||
|
init(action: @escaping () -> Void) {
|
||||||
|
self.action = action
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Button(action: {
|
Button(action: action) {
|
||||||
let engaged: Bool = node.value < 0.5
|
|
||||||
// Toggle: engaged (0) → bypassed (1) and vice-versa.
|
|
||||||
node.update(engaged ? 1.0 : 0.0)
|
|
||||||
}) {
|
|
||||||
ZStack {
|
ZStack {
|
||||||
Circle()
|
Circle()
|
||||||
.fill(Color(white: FootswitchButton.outerFillBrightness))
|
.fill(Color(white: FootswitchButton.outerFillBrightness))
|
||||||
@@ -168,6 +180,189 @@ private struct FootswitchButton: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Tempo-sync knob
|
||||||
|
|
||||||
|
/// A knob that can be locked to a note division of the live tempo.
|
||||||
|
///
|
||||||
|
/// When free, it is an ordinary ``ParameterKnob``. A compact menu below the dial lets the user
|
||||||
|
/// pick `Free` or a ``NoteDivision``; once a division is chosen the knob is driven by the tempo
|
||||||
|
/// (its dial shows the derived value but is disabled, since the number is computed). The menu is
|
||||||
|
/// shown only while tempo is enabled — the enclosing view gates on `shoeGazeTempoEnabled`.
|
||||||
|
struct TempoSyncKnobView: View {
|
||||||
|
|
||||||
|
private static let cellSpacing: CGFloat = 4
|
||||||
|
private static let syncedDialOpacity: Double = 0.55
|
||||||
|
private static let menuFontSize: CGFloat = 10
|
||||||
|
private static let labelGlyphSpacing: CGFloat = 3
|
||||||
|
private static let warningIconSize: CGFloat = 8
|
||||||
|
/// Height of the glyph in the collapsed menu button, and of the whole menu row, so the row is the
|
||||||
|
/// same height whether it shows the "Free" text or a note glyph — the pedal card never grows.
|
||||||
|
private static let labelGlyphHeight: CGFloat = 18
|
||||||
|
private static let menuRowHeight: CGFloat = 20
|
||||||
|
private static let freeKey: String = "free"
|
||||||
|
|
||||||
|
// Division-picker popover: a height-capped scroll list the system keeps on-screen (it flips
|
||||||
|
// above the button near the bottom edge) rather than a native menu that can run off-screen.
|
||||||
|
private static let pickerMaxHeight: CGFloat = 260
|
||||||
|
private static let pickerGlyphHeight: CGFloat = 22
|
||||||
|
private static let pickerRowSpacing: CGFloat = 2
|
||||||
|
private static let pickerPadding: CGFloat = 8
|
||||||
|
private static let pickerRowMinWidth: CGFloat = 84
|
||||||
|
private static let checkmarkFontSize: CGFloat = 11
|
||||||
|
|
||||||
|
let pedal: Pedal
|
||||||
|
let knob: PedalKnob
|
||||||
|
let param: TempoSyncableParam
|
||||||
|
|
||||||
|
/// Presentation flag for the division-picker popover.
|
||||||
|
@State private var showDivisionPicker: Bool = false
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
// Observe the pedal's sync-revision so the badge refreshes when `tempoSync` changes through
|
||||||
|
// any path — this view's picker, a preset load, or a lightweight recall.
|
||||||
|
let _ = pedal.tempoSyncRevision.value
|
||||||
|
let currentKey: String = keyForCurrentSync()
|
||||||
|
let isSynced: Bool = currentKey != TempoSyncKnobView.freeKey
|
||||||
|
let currentBpm: Double? = pedal.clock?.bpm
|
||||||
|
// Reading the live parameter value subscribes this view to Observation, so a tempo change
|
||||||
|
// (which rewrites the node via `applyTempoSync`) re-renders the clamp warning without polling.
|
||||||
|
let liveValue: Double = param.node.value
|
||||||
|
let activeDivision: NoteDivision? = NoteDivision(rawValue: currentKey)
|
||||||
|
let activeClamped: Bool = {
|
||||||
|
_ = liveValue
|
||||||
|
guard isSynced, let bpm: Double = currentBpm, let division: NoteDivision = activeDivision else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return param.value(for: division, bpm: bpm).clamped
|
||||||
|
}()
|
||||||
|
|
||||||
|
VStack(spacing: TempoSyncKnobView.cellSpacing) {
|
||||||
|
ParameterKnob(knob.label, node: knob.node, range: knob.range)
|
||||||
|
.foregroundStyle(Color.white)
|
||||||
|
.disabled(isSynced)
|
||||||
|
.opacity(isSynced ? TempoSyncKnobView.syncedDialOpacity : 1.0)
|
||||||
|
|
||||||
|
Button {
|
||||||
|
showDivisionPicker = true
|
||||||
|
} label: {
|
||||||
|
HStack(spacing: TempoSyncKnobView.labelGlyphSpacing) {
|
||||||
|
if isSynced, let division: NoteDivision = activeDivision {
|
||||||
|
NoteGlyphImageCache.image(for: division)
|
||||||
|
.resizable()
|
||||||
|
.scaledToFit()
|
||||||
|
.frame(height: TempoSyncKnobView.labelGlyphHeight)
|
||||||
|
.accessibilityLabel(Text(labelForKey(currentKey)))
|
||||||
|
} else {
|
||||||
|
Text("Free")
|
||||||
|
.font(.system(size: TempoSyncKnobView.menuFontSize, weight: .semibold, design: .rounded))
|
||||||
|
}
|
||||||
|
if activeClamped {
|
||||||
|
Image(systemName: "exclamationmark.triangle.fill")
|
||||||
|
.font(.system(size: TempoSyncKnobView.warningIconSize))
|
||||||
|
}
|
||||||
|
Image(systemName: "chevron.down")
|
||||||
|
.font(.system(size: TempoSyncKnobView.warningIconSize))
|
||||||
|
.opacity(0.6)
|
||||||
|
}
|
||||||
|
.frame(height: TempoSyncKnobView.menuRowHeight)
|
||||||
|
.foregroundStyle(activeClamped ? Color.orange : Color.white.opacity(isSynced ? 1.0 : 0.65))
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.fixedSize()
|
||||||
|
.help(activeClamped
|
||||||
|
? "This note can't be represented at the current tempo — \(knob.label) is clamped to its limit."
|
||||||
|
: "Sync \(knob.label) to the tempo, or set it freely")
|
||||||
|
.popover(isPresented: $showDivisionPicker) {
|
||||||
|
divisionPicker
|
||||||
|
.presentationCompactAdaptation(.popover)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Height-capped, scrollable list of `Free` + every note division. Presented as a popover so the
|
||||||
|
/// system keeps it on-screen (flipping above the button near the bottom edge) and it scrolls when
|
||||||
|
/// taller than ``pickerMaxHeight`` — unlike a native menu, which ran off the bottom on iOS.
|
||||||
|
private var divisionPicker: some View {
|
||||||
|
let currentBpm: Double? = pedal.clock?.bpm
|
||||||
|
let currentKey: String = keyForCurrentSync()
|
||||||
|
return ScrollView {
|
||||||
|
VStack(alignment: .leading, spacing: TempoSyncKnobView.pickerRowSpacing) {
|
||||||
|
pickerRow(
|
||||||
|
key: TempoSyncKnobView.freeKey,
|
||||||
|
glyph: nil,
|
||||||
|
disabled: false,
|
||||||
|
selected: currentKey == TempoSyncKnobView.freeKey
|
||||||
|
)
|
||||||
|
ForEach(NoteDivision.allCases, id: \.self) { division in
|
||||||
|
// A division whose value clamps at the current tempo (e.g. a note longer than the
|
||||||
|
// maximum delay time) can't be represented accurately, so it is shown but disabled.
|
||||||
|
let unavailable: Bool = currentBpm.map { param.value(for: division, bpm: $0).clamped } ?? false
|
||||||
|
pickerRow(
|
||||||
|
key: division.rawValue,
|
||||||
|
glyph: division,
|
||||||
|
disabled: unavailable,
|
||||||
|
selected: currentKey == division.rawValue
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(TempoSyncKnobView.pickerPadding)
|
||||||
|
}
|
||||||
|
.frame(maxHeight: TempoSyncKnobView.pickerMaxHeight)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// One selectable row in ``divisionPicker`` — a note glyph (or "Free" text), a trailing checkmark
|
||||||
|
/// when it is the current selection, and a disabled state for divisions that clamp at this tempo.
|
||||||
|
@ViewBuilder
|
||||||
|
private func pickerRow(key: String, glyph: NoteDivision?, disabled: Bool, selected: Bool) -> some View {
|
||||||
|
Button {
|
||||||
|
select(key)
|
||||||
|
showDivisionPicker = false
|
||||||
|
} label: {
|
||||||
|
HStack(spacing: TempoSyncKnobView.labelGlyphSpacing) {
|
||||||
|
if let glyph: NoteDivision = glyph {
|
||||||
|
NoteGlyphImageCache.image(for: glyph)
|
||||||
|
.resizable()
|
||||||
|
.scaledToFit()
|
||||||
|
.frame(height: TempoSyncKnobView.pickerGlyphHeight)
|
||||||
|
} else {
|
||||||
|
Text("Free")
|
||||||
|
.font(.system(size: TempoSyncKnobView.menuFontSize, weight: .semibold, design: .rounded))
|
||||||
|
}
|
||||||
|
Spacer(minLength: TempoSyncKnobView.labelGlyphSpacing)
|
||||||
|
if selected {
|
||||||
|
Image(systemName: "checkmark")
|
||||||
|
.font(.system(size: TempoSyncKnobView.checkmarkFontSize, weight: .semibold))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.frame(minWidth: TempoSyncKnobView.pickerRowMinWidth, alignment: .leading)
|
||||||
|
.contentShape(Rectangle())
|
||||||
|
}
|
||||||
|
.buttonStyle(.plain)
|
||||||
|
.disabled(disabled)
|
||||||
|
.accessibilityLabel(Text(glyph?.label ?? "Free"))
|
||||||
|
}
|
||||||
|
|
||||||
|
private func keyForCurrentSync() -> String {
|
||||||
|
if case .division(let division) = pedal.tempoSync[param.key] ?? .free {
|
||||||
|
return division.rawValue
|
||||||
|
}
|
||||||
|
return TempoSyncKnobView.freeKey
|
||||||
|
}
|
||||||
|
|
||||||
|
private func labelForKey(_ key: String) -> String {
|
||||||
|
key == TempoSyncKnobView.freeKey ? "Free" : (NoteDivision(rawValue: key)?.label ?? key)
|
||||||
|
}
|
||||||
|
|
||||||
|
private func select(_ key: String) {
|
||||||
|
// `setSync` bumps `pedal.tempoSyncRevision`, which this view observes — no local flag needed.
|
||||||
|
if key == TempoSyncKnobView.freeKey {
|
||||||
|
pedal.setSync(.free, for: param.key)
|
||||||
|
} else if let division: NoteDivision = NoteDivision(rawValue: key) {
|
||||||
|
pedal.setSync(.division(division), for: param.key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - PedalView
|
// MARK: - PedalView
|
||||||
|
|
||||||
/// A stompbox-style enclosure view that renders all controls for a single `Pedal`.
|
/// A stompbox-style enclosure view that renders all controls for a single `Pedal`.
|
||||||
@@ -205,6 +400,8 @@ public struct PedalView: View {
|
|||||||
private static let enclosurePadding: CGFloat = 14
|
private static let enclosurePadding: CGFloat = 14
|
||||||
private static let screwInset: CGFloat = 6
|
private static let screwInset: CGFloat = 6
|
||||||
private static let knobColumnCount: Int = 3
|
private static let knobColumnCount: Int = 3
|
||||||
|
/// Knob columns for a double-width pedal card (fits a four-knob effect bank on one row).
|
||||||
|
private static let wideKnobColumnCount: Int = 4
|
||||||
private static let knobSpacing: CGFloat = 10
|
private static let knobSpacing: CGFloat = 10
|
||||||
/// Horizontal gap between knobs within a row. Wider than `knobSpacing` so centred
|
/// Horizontal gap between knobs within a row. Wider than `knobSpacing` so centred
|
||||||
/// rows keep a comfortable, touch-friendly gap between adjacent knobs.
|
/// rows keep a comfortable, touch-friendly gap between adjacent knobs.
|
||||||
@@ -227,6 +424,10 @@ public struct PedalView: View {
|
|||||||
private static let shadowOpacity: Double = 0.60
|
private static let shadowOpacity: Double = 0.60
|
||||||
private static let enclosureGradientDarkFraction: Double = 0.30
|
private static let enclosureGradientDarkFraction: Double = 0.30
|
||||||
private static let bypassSectionSpacing: CGFloat = 6
|
private static let bypassSectionSpacing: CGFloat = 6
|
||||||
|
/// Gap between the looper's three content columns.
|
||||||
|
private static let looperColumnSpacing: CGFloat = 18
|
||||||
|
/// Fixed width of the looper's left (timeline) column.
|
||||||
|
private static let looperTimelineColumnWidth: CGFloat = 200
|
||||||
/// Half the screw-dot size — used to centre screws on the corner position.
|
/// Half the screw-dot size — used to centre screws on the corner position.
|
||||||
private static let screwHalfSize: CGFloat = 4
|
private static let screwHalfSize: CGFloat = 4
|
||||||
private static let namePlateBackgroundOpacity: Double = 0.35
|
private static let namePlateBackgroundOpacity: Double = 0.35
|
||||||
@@ -248,6 +449,13 @@ public struct PedalView: View {
|
|||||||
/// Presentation flag for the pedal info panel (description + control ranges).
|
/// Presentation flag for the pedal info panel (description + control ranges).
|
||||||
@State private var showInfo: Bool = false
|
@State private var showInfo: Bool = false
|
||||||
|
|
||||||
|
/// The rig's control map, injected by the builder so the pedal can draw a mapping strip. `nil`
|
||||||
|
/// when the rig has no bindings (or in contexts that don't set it) — the strip renders nothing.
|
||||||
|
@Environment(\.controlMappingMap) private var controlMappingMap: MIDIMap?
|
||||||
|
|
||||||
|
/// Mirrors ``ShoeGaze/tempoEnabled`` so tempo-sync knob affordances hide when tempo is off.
|
||||||
|
@Environment(\.shoeGazeTempoEnabled) private var tempoEnabled: Bool
|
||||||
|
|
||||||
// MARK: - Init
|
// MARK: - Init
|
||||||
|
|
||||||
/// Creates a stompbox pedal view for the given pedal.
|
/// Creates a stompbox pedal view for the given pedal.
|
||||||
@@ -288,15 +496,14 @@ public struct PedalView: View {
|
|||||||
lineWidth: PedalView.innerHighlightLineWidth)
|
lineWidth: PedalView.innerHighlightLineWidth)
|
||||||
.padding(PedalView.innerHighlightPadding)
|
.padding(PedalView.innerHighlightPadding)
|
||||||
|
|
||||||
// Content stack
|
// Content stack — the looper uses a wide, columnar layout to stay short; every other
|
||||||
VStack(spacing: PedalView.sectionSpacing) {
|
// pedal uses the default single-column section stack.
|
||||||
namePlate
|
Group {
|
||||||
knobGrid
|
if let looper: LooperPedal = pedal as? LooperPedal {
|
||||||
selectorRow
|
looperColumnarContent(looper)
|
||||||
switchRow
|
} else {
|
||||||
sliderBank(sliders)
|
defaultContent(sliders: sliders)
|
||||||
Spacer(minLength: 0)
|
}
|
||||||
bottomControls
|
|
||||||
}
|
}
|
||||||
.padding(PedalView.enclosurePadding)
|
.padding(PedalView.enclosurePadding)
|
||||||
|
|
||||||
@@ -321,6 +528,138 @@ public struct PedalView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Content layouts
|
||||||
|
|
||||||
|
/// The default single-column section stack used by every pedal except the looper.
|
||||||
|
private func defaultContent(sliders: [PedalSlider]) -> some View {
|
||||||
|
VStack(spacing: PedalView.sectionSpacing) {
|
||||||
|
namePlate
|
||||||
|
knobGrid
|
||||||
|
selectorRow
|
||||||
|
switchRow
|
||||||
|
// Keyed on the pedal instance so the buttons' live captions (which poll the pedal
|
||||||
|
// via `.task`) re-subscribe when a rig load / rebuild swaps in a new pedal instance.
|
||||||
|
transportButtonRow
|
||||||
|
.id(ObjectIdentifier(pedal))
|
||||||
|
buttonRow
|
||||||
|
sliderBank(sliders)
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
bottomControls
|
||||||
|
PedalMappingStrip(pedal: pedal, map: controlMappingMap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Wide, three-column layout for the looper: the loop timeline on the left, the effect knobs
|
||||||
|
/// over the Free/Sync switch in the centre, and the transport footswitch grid (with bypass) on
|
||||||
|
/// the right. Laying the sections side-by-side keeps the tall pedal short enough to fit the
|
||||||
|
/// canvas without scrolling. Requires the looper's `widthUnits` to be wide enough (3×).
|
||||||
|
private func looperColumnarContent(_ looper: LooperPedal) -> some View {
|
||||||
|
VStack(spacing: PedalView.sectionSpacing) {
|
||||||
|
namePlate
|
||||||
|
HStack(alignment: .top, spacing: PedalView.looperColumnSpacing) {
|
||||||
|
// Left column: timeline, then the Free/Sync switch, then the Reset footswitch.
|
||||||
|
VStack(spacing: PedalView.sectionSpacing) {
|
||||||
|
LooperTimelineView(pedal: looper)
|
||||||
|
switchRow
|
||||||
|
looperResetCell
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
}
|
||||||
|
.frame(width: PedalView.looperTimelineColumnWidth)
|
||||||
|
|
||||||
|
// Centre column: the four effect knobs (2×2), with the Level + Bypass footer at the
|
||||||
|
// bottom. The Mix slot is reserved (empty) so Bypass stays horizontally centred,
|
||||||
|
// matching a normal pedal's footer.
|
||||||
|
VStack(spacing: PedalView.sectionSpacing) {
|
||||||
|
looperEffectKnobs(columns: 2)
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
looperFooter
|
||||||
|
}
|
||||||
|
|
||||||
|
// Right column: the transport footswitches (minus Reset) in a 2×2 grid.
|
||||||
|
looperTransportGrid(columns: 2)
|
||||||
|
.id(ObjectIdentifier(pedal))
|
||||||
|
}
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
PedalMappingStrip(pedal: pedal, map: controlMappingMap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The looper's effect knobs (everything except the trailing `Mix` / `Level`) laid out in
|
||||||
|
/// rows of `columns`.
|
||||||
|
private func looperEffectKnobs(columns: Int) -> some View {
|
||||||
|
let knobs: [PedalKnob] = Array(pedal.knobs.dropLast(2))
|
||||||
|
let rows: [[PedalKnob]] = stride(from: 0, to: knobs.count, by: columns).map { start in
|
||||||
|
Array(knobs[start ..< min(start + columns, knobs.count)])
|
||||||
|
}
|
||||||
|
return VStack(spacing: PedalView.knobSpacing) {
|
||||||
|
ForEach(Array(rows.enumerated()), id: \.offset) { rowPair in
|
||||||
|
HStack(spacing: PedalView.knobRowItemSpacing) {
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
ForEach(Array(rowPair.element.enumerated()), id: \.offset) { knobPair in
|
||||||
|
let knob: PedalKnob = knobPair.element
|
||||||
|
ParameterKnob(knob.label, node: knob.node, range: knob.range)
|
||||||
|
.foregroundStyle(Color.white)
|
||||||
|
}
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Preferred grid order for the looper's transport footswitches (row-major), so the 2×2 grid
|
||||||
|
/// reads Record / Reverse over Stop / Cue Stop. Buttons not listed keep their original order
|
||||||
|
/// and follow. Matched by label to stay robust if the descriptor order changes.
|
||||||
|
private static let looperTransportOrder: [String] = ["Loop", "Reverse", "Stop", "Cue Stop"]
|
||||||
|
|
||||||
|
/// The looper's transport footswitches — everything except the trailing Reset (which sits in
|
||||||
|
/// the left column) — laid out in rows of `columns` in ``looperTransportOrder``.
|
||||||
|
private func looperTransportGrid(columns: Int) -> some View {
|
||||||
|
let buttons: [PedalButton] = Array(pedal.effectTransportButtons.dropLast())
|
||||||
|
let ordered: [PedalButton] =
|
||||||
|
PedalView.looperTransportOrder.compactMap { label in buttons.first { $0.label == label } }
|
||||||
|
+ buttons.filter { !PedalView.looperTransportOrder.contains($0.label) }
|
||||||
|
let rows: [[PedalButton]] = stride(from: 0, to: ordered.count, by: columns).map { start in
|
||||||
|
Array(ordered[start ..< min(start + columns, ordered.count)])
|
||||||
|
}
|
||||||
|
return VStack(spacing: PedalView.knobSpacing) {
|
||||||
|
ForEach(Array(rows.enumerated()), id: \.offset) { rowPair in
|
||||||
|
HStack(alignment: .top, spacing: PedalView.knobRowItemSpacing) {
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
ForEach(Array(rowPair.element.enumerated()), id: \.offset) { pair in
|
||||||
|
PedalButtonView(pair.element)
|
||||||
|
}
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The looper's footer: Level on the left, Bypass in the centre, and an empty third where a
|
||||||
|
/// normal pedal's Mix knob would sit — so Bypass stays horizontally centred in the column.
|
||||||
|
private var looperFooter: some View {
|
||||||
|
HStack(spacing: 0) {
|
||||||
|
levelControl
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
bypassControl
|
||||||
|
.frame(maxWidth: .infinity)
|
||||||
|
Color.clear
|
||||||
|
.frame(maxWidth: .infinity, maxHeight: 0) // reserved Mix slot
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The Reset footswitch (the trailing transport button), centred — sits at the bottom of the
|
||||||
|
/// looper's left (timeline) column.
|
||||||
|
@ViewBuilder
|
||||||
|
private var looperResetCell: some View {
|
||||||
|
if let reset: PedalButton = pedal.effectTransportButtons.last {
|
||||||
|
HStack(spacing: 0) {
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
PedalButtonView(reset)
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Subviews
|
// MARK: - Subviews
|
||||||
|
|
||||||
/// Capsule name plate near the top of the enclosure.
|
/// Capsule name plate near the top of the enclosure.
|
||||||
@@ -354,32 +693,33 @@ public struct PedalView: View {
|
|||||||
/// `Level` on the left, `Mix` on the right — leaving more room for the effect controls
|
/// `Level` on the left, `Mix` on the right — leaving more room for the effect controls
|
||||||
/// at the top and giving every pedal a symmetric footer.
|
/// at the top and giving every pedal a symmetric footer.
|
||||||
private var knobGrid: some View {
|
private var knobGrid: some View {
|
||||||
|
// Wide (double-width) pedals fit four knobs across, so a four-knob effect bank (e.g.
|
||||||
|
// the looper's Crossfade / Playback / Overdub / Feedback) sits on one row.
|
||||||
|
let columns: Int = pedal.widthUnits >= 2 ? PedalView.wideKnobColumnCount : PedalView.knobColumnCount
|
||||||
let knobs: [PedalKnob] = Array(pedal.knobs.dropLast(2))
|
let knobs: [PedalKnob] = Array(pedal.knobs.dropLast(2))
|
||||||
let rows: [[PedalKnob]] = stride(
|
let rows: [[PedalKnob]] = stride(
|
||||||
from: 0,
|
from: 0,
|
||||||
to: knobs.count,
|
to: knobs.count,
|
||||||
by: PedalView.knobColumnCount
|
by: columns
|
||||||
).map { startIndex in
|
).map { startIndex in
|
||||||
Array(knobs[startIndex ..< min(startIndex + PedalView.knobColumnCount, knobs.count)])
|
Array(knobs[startIndex ..< min(startIndex + columns, knobs.count)])
|
||||||
}
|
}
|
||||||
|
|
||||||
return VStack(spacing: PedalView.knobSpacing) {
|
return VStack(spacing: PedalView.knobSpacing) {
|
||||||
ForEach(Array(rows.enumerated()), id: \.offset) { rowPair in
|
ForEach(Array(rows.enumerated()), id: \.offset) { rowPair in
|
||||||
let row: [PedalKnob] = rowPair.element
|
let row: [PedalKnob] = rowPair.element
|
||||||
// Centre each row: a short row (one or two knobs) sits centred in the
|
// Centre each row: a short row sits centred in the enclosure rather than
|
||||||
// enclosure rather than left-aligned. Symmetric spacers also centre a full
|
// left-aligned. A full row keeps the tight spacing so it fits the enclosure;
|
||||||
// three-knob row, so every row stays horizontally centred.
|
|
||||||
// A full three-knob row keeps the tight spacing so it fits the enclosure;
|
|
||||||
// shorter centred rows use a wider, touch-friendly gap.
|
// shorter centred rows use a wider, touch-friendly gap.
|
||||||
let rowItemSpacing: CGFloat = row.count >= PedalView.knobColumnCount
|
let rowItemSpacing: CGFloat = row.count >= columns
|
||||||
? PedalView.knobSpacing
|
? PedalView.knobSpacing
|
||||||
: PedalView.knobRowItemSpacing
|
: PedalView.knobRowItemSpacing
|
||||||
HStack(spacing: rowItemSpacing) {
|
// Top-align so every dial pins to the row's top edge — a tempo-sync cell grows taller
|
||||||
|
// below the dial (glyph menu, warning) without dragging its neighbours' dials down.
|
||||||
|
HStack(alignment: .top, spacing: rowItemSpacing) {
|
||||||
Spacer(minLength: 0)
|
Spacer(minLength: 0)
|
||||||
ForEach(Array(row.enumerated()), id: \.offset) { knobPair in
|
ForEach(Array(row.enumerated()), id: \.offset) { knobPair in
|
||||||
let knob: PedalKnob = knobPair.element
|
knobCell(knobPair.element)
|
||||||
ParameterKnob(knob.label, node: knob.node, range: knob.range)
|
|
||||||
.foregroundStyle(Color.white)
|
|
||||||
}
|
}
|
||||||
Spacer(minLength: 0)
|
Spacer(minLength: 0)
|
||||||
}
|
}
|
||||||
@@ -387,6 +727,25 @@ public struct PedalView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Renders one effect knob — a tempo-sync knob when the parameter is syncable and tempo is
|
||||||
|
/// enabled, otherwise a plain ``ParameterKnob``. Syncable knobs are matched by node identity
|
||||||
|
/// against `pedal.tempoSyncableParams`.
|
||||||
|
@ViewBuilder
|
||||||
|
private func knobCell(_ knob: PedalKnob) -> some View {
|
||||||
|
if tempoEnabled, let param: TempoSyncableParam = syncableParam(for: knob) {
|
||||||
|
TempoSyncKnobView(pedal: pedal, knob: knob, param: param)
|
||||||
|
} else {
|
||||||
|
ParameterKnob(knob.label, node: knob.node, range: knob.range)
|
||||||
|
.foregroundStyle(Color.white)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The tempo-syncable descriptor whose parameter node backs `knob`, or `nil` if the knob is
|
||||||
|
/// not syncable. Matched by `UIParamNode` identity so it is robust to label changes.
|
||||||
|
private func syncableParam(for knob: PedalKnob) -> TempoSyncableParam? {
|
||||||
|
pedal.tempoSyncableParams.first { $0.node === knob.node }
|
||||||
|
}
|
||||||
|
|
||||||
/// Row of stepped selector knobs drawn from `pedal.effectSelectors`, beneath the knob grid.
|
/// Row of stepped selector knobs drawn from `pedal.effectSelectors`, beneath the knob grid.
|
||||||
/// Renders nothing when the pedal publishes no selectors.
|
/// Renders nothing when the pedal publishes no selectors.
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
@@ -417,6 +776,40 @@ public struct PedalView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Transport-control row drawn from `pedal.effectTransportButtons`, placed directly below
|
||||||
|
/// the knobs so persistent state toggles and transport stops (e.g. the looper's Loop /
|
||||||
|
/// Stop / Cue Stop / Reverse) sit apart from the momentary actions. Renders nothing when
|
||||||
|
/// the pedal publishes no transport buttons.
|
||||||
|
@ViewBuilder
|
||||||
|
private var transportButtonRow: some View {
|
||||||
|
let buttons: [PedalButton] = pedal.effectTransportButtons
|
||||||
|
if !buttons.isEmpty {
|
||||||
|
HStack(alignment: .top, spacing: PedalView.knobRowItemSpacing) {
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
ForEach(Array(buttons.enumerated()), id: \.offset) { pair in
|
||||||
|
PedalButtonView(pair.element)
|
||||||
|
}
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Row of momentary stomp-style action buttons drawn from `pedal.effectButtons`, beneath
|
||||||
|
/// the transport row. Renders nothing when the pedal publishes no buttons.
|
||||||
|
@ViewBuilder
|
||||||
|
private var buttonRow: some View {
|
||||||
|
let buttons: [PedalButton] = pedal.effectButtons
|
||||||
|
if !buttons.isEmpty {
|
||||||
|
HStack(spacing: PedalView.knobRowItemSpacing) {
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
ForEach(Array(buttons.enumerated()), id: \.offset) { pair in
|
||||||
|
PedalButtonView(pair.element)
|
||||||
|
}
|
||||||
|
Spacer(minLength: 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Row of vertical faders drawn from `pedal.effectSliders`, beneath the switch row.
|
/// Row of vertical faders drawn from `pedal.effectSliders`, beneath the switch row.
|
||||||
/// Renders nothing when the pedal publishes no sliders.
|
/// Renders nothing when the pedal publishes no sliders.
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
@@ -431,16 +824,19 @@ public struct PedalView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Enclosure width — the base stompbox width, widened to fit a wide vertical-fader bank
|
/// Enclosure width — the base stompbox width scaled by the pedal's `widthUnits`
|
||||||
/// (e.g. a multi-band graphic EQ) so its faders are never clipped.
|
/// (a control-dense pedal such as the looper asks for a double-width card), widened
|
||||||
|
/// further to fit a wide vertical-fader bank (e.g. a multi-band graphic EQ) so its
|
||||||
|
/// faders are never clipped.
|
||||||
private func enclosureWidth(for sliders: [PedalSlider]) -> CGFloat {
|
private func enclosureWidth(for sliders: [PedalSlider]) -> CGFloat {
|
||||||
|
let unitWidth: CGFloat = PedalView.enclosureWidth * CGFloat(max(1, pedal.widthUnits))
|
||||||
let sliderCount: Int = sliders.count
|
let sliderCount: Int = sliders.count
|
||||||
guard sliderCount > 0 else { return PedalView.enclosureWidth }
|
guard sliderCount > 0 else { return unitWidth }
|
||||||
let bankContentWidth: CGFloat =
|
let bankContentWidth: CGFloat =
|
||||||
CGFloat(sliderCount) * PedalView.sliderBankItemWidth
|
CGFloat(sliderCount) * PedalView.sliderBankItemWidth
|
||||||
+ CGFloat(max(0, sliderCount - 1)) * PedalView.sliderBankSpacing
|
+ CGFloat(max(0, sliderCount - 1)) * PedalView.sliderBankSpacing
|
||||||
let needed: CGFloat = bankContentWidth + 2 * PedalView.enclosurePadding
|
let needed: CGFloat = bankContentWidth + 2 * PedalView.enclosurePadding
|
||||||
return max(PedalView.enclosureWidth, needed)
|
return max(unitWidth, needed)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bottom control row: the `Level` knob, the bypass switch, and the `Mix` knob,
|
/// Bottom control row: the `Level` knob, the bypass switch, and the `Mix` knob,
|
||||||
@@ -464,10 +860,11 @@ public struct PedalView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The `Mix` knob — the second-to-last entry of `pedal.knobs` — placed right of the
|
/// The `Mix` knob — the second-to-last entry of `pedal.knobs` — placed right of the
|
||||||
/// bypass switch to mirror `Level`.
|
/// bypass switch to mirror `Level`. Hidden for pedals that manage their own dry/wet balance
|
||||||
|
/// (``Pedal/showsMixControl``), e.g. the looper.
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private var mixControl: some View {
|
private var mixControl: some View {
|
||||||
if let mix: PedalKnob = pedal.knobs.dropLast().last {
|
if pedal.showsMixControl, let mix: PedalKnob = pedal.knobs.dropLast().last {
|
||||||
ParameterKnob(mix.label, node: mix.node, range: mix.range)
|
ParameterKnob(mix.label, node: mix.node, range: mix.range)
|
||||||
.foregroundStyle(Color.white)
|
.foregroundStyle(Color.white)
|
||||||
}
|
}
|
||||||
@@ -479,9 +876,10 @@ public struct PedalView: View {
|
|||||||
// re-renders whenever the bypass parameter changes on the main thread
|
// re-renders whenever the bypass parameter changes on the main thread
|
||||||
// (UIParamNode is @Observable).
|
// (UIParamNode is @Observable).
|
||||||
let bypassValue: Double = pedal.$bypass.value
|
let bypassValue: Double = pedal.$bypass.value
|
||||||
|
let engagedThreshold: Double = 0.5
|
||||||
|
|
||||||
return VStack(spacing: PedalView.bypassSectionSpacing) {
|
return VStack(spacing: PedalView.bypassSectionSpacing) {
|
||||||
LEDIndicator(bypassValue: bypassValue)
|
LEDIndicator(isOn: bypassValue < engagedThreshold)
|
||||||
FootswitchButton(node: pedal.$bypass)
|
FootswitchButton(node: pedal.$bypass)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,4 +16,8 @@ public extension Notification.Name {
|
|||||||
|
|
||||||
/// Create a new, named, empty rig and make it current.
|
/// Create a new, named, empty rig and make it current.
|
||||||
static let shoeGazeNewRig: Notification.Name = Notification.Name("net.realizedsound.shoegaze.newRig")
|
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")
|
||||||
}
|
}
|
||||||
|
|||||||