Boards sheet, ⌘1–9 switching, unified player bar, input persistence
Boards sheet (BoardsSheetView): rename, drag-reorder, swipe-delete, plus per-board enable/solo/level and a Solo/Blend + crossfade header. Opened from a "Boards…" button in the builder; presented with medium/large detents on iOS. Makes ShoeGaze.moveBoard public to back the reorder. Keyboard switching: hidden ⌘1…⌘9 buttons in the builder solo (live-switch to) the matching board and select it as the edit target. Unified player: ShoeGazeView drops its bespoke Active picker + crossfade field and hosts the shared BoardBarView, matching the builder. Input persistence: the builder saves the input choice (test loop vs live channel) to UserDefaults and restores it on appear. With no saved choice it defaults to live input when the mic is already authorised and an input channel exists, else stays on the test loop. The iOS builder now opens one input channel so live input is actually available there. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -48,6 +48,12 @@ public struct ShoeGazeBuilderView: View {
|
||||
private static let backgroundGreen: Double = 0.07
|
||||
private static let backgroundBlue: Double = 0.06
|
||||
private static let testLoopTag: Int = -1
|
||||
/// UserDefaults key persisting the last input selection (`-1` = test loop, `>= 0` = channel).
|
||||
private static let inputSelectionDefaultsKey: String = "ShoeGaze.inputSelection"
|
||||
/// Maximum crossfade duration honoured by board-switch keyboard shortcuts.
|
||||
private static let maxCrossfadeSeconds: Double = 10.0
|
||||
/// Highest board reachable via a ⌘-number switch shortcut.
|
||||
private static let maxBoardShortcuts: Int = 9
|
||||
private static let defaultRigFileName: String = "ShoeGazeRig"
|
||||
private static let recordDotSize: CGFloat = 9
|
||||
private static let folderLabelOpacity: Double = 0.55
|
||||
@@ -69,6 +75,12 @@ public struct ShoeGazeBuilderView: View {
|
||||
/// Shown when live input is selected but microphone access is denied/restricted.
|
||||
@State private var showMicDeniedAlert: Bool = false
|
||||
|
||||
/// Guards the one-time input-source restore in `.onAppear`.
|
||||
@State private var didRestoreInput: Bool = false
|
||||
|
||||
/// Presentation flag for the board-manager sheet (rename / reorder / delete).
|
||||
@State private var showBoardsSheet: Bool = false
|
||||
|
||||
#if !os(macOS)
|
||||
/// iOS file-dialog presentation flags + the document to export. (macOS uses the File menu.)
|
||||
@State private var showImporter: Bool = false
|
||||
@@ -133,6 +145,17 @@ public struct ShoeGazeBuilderView: View {
|
||||
blue: ShoeGazeBuilderView.backgroundBlue
|
||||
)
|
||||
)
|
||||
.background(boardSwitchShortcuts)
|
||||
.onAppear { restoreInputSelection() }
|
||||
.sheet(isPresented: $showBoardsSheet) {
|
||||
BoardsSheetView(
|
||||
shoeGaze: shoeGaze,
|
||||
editingBoardIndex: $selectedBoardIndex,
|
||||
crossfadeSeconds: $crossfadeSeconds,
|
||||
onAddBoard: { addBoard() }
|
||||
)
|
||||
.presentationDetents([.medium, .large])
|
||||
}
|
||||
.alert("Microphone Access Needed", isPresented: $showMicDeniedAlert) {
|
||||
Button("OK", role: .cancel) { }
|
||||
} message: {
|
||||
@@ -204,6 +227,10 @@ public struct ShoeGazeBuilderView: View {
|
||||
.pickerStyle(.menu)
|
||||
.foregroundStyle(Color.white)
|
||||
|
||||
Button("Boards…") { showBoardsSheet = true }
|
||||
.buttonStyle(.bordered).tint(.orange)
|
||||
.help("Rename, reorder, or delete boards")
|
||||
|
||||
Spacer()
|
||||
|
||||
// On macOS, Save/Load live in the app's File menu (see the app shell's AppDelegate);
|
||||
@@ -331,6 +358,7 @@ public struct ShoeGazeBuilderView: View {
|
||||
if wasRunning { shoeGaze.engine.stop() }
|
||||
do {
|
||||
try shoeGaze.setInputSource(source)
|
||||
persistInputSelection(source)
|
||||
} catch {
|
||||
print("[ShoeGazeBuilderView] setInputSource failed: \(error)")
|
||||
}
|
||||
@@ -340,6 +368,65 @@ public struct ShoeGazeBuilderView: View {
|
||||
transportTick.toggle()
|
||||
}
|
||||
|
||||
// MARK: - Input persistence
|
||||
|
||||
/// Saves the current input choice so it is restored on the next launch.
|
||||
private func persistInputSelection(_ source: InputSource) {
|
||||
let value: Int
|
||||
switch source {
|
||||
case .testLoop:
|
||||
value = ShoeGazeBuilderView.testLoopTag
|
||||
case .liveInput(let channel):
|
||||
value = channel
|
||||
}
|
||||
UserDefaults.standard.set(value, forKey: ShoeGazeBuilderView.inputSelectionDefaultsKey)
|
||||
}
|
||||
|
||||
/// Restores the saved input choice once on appear. With no saved choice, defaults to live
|
||||
/// input when the microphone is already authorised and the engine has an input channel —
|
||||
/// otherwise stays on the test loop. A saved live channel that no longer fits the engine, or
|
||||
/// a since-revoked permission, falls back to the test loop via `switchInput(to:)`.
|
||||
private func restoreInputSelection() {
|
||||
guard !didRestoreInput else { return }
|
||||
didRestoreInput = true
|
||||
|
||||
let defaults: UserDefaults = UserDefaults.standard
|
||||
if defaults.object(forKey: ShoeGazeBuilderView.inputSelectionDefaultsKey) != nil {
|
||||
let stored: Int = defaults.integer(forKey: ShoeGazeBuilderView.inputSelectionDefaultsKey)
|
||||
if stored >= 0, stored < shoeGaze.engine.numInputChannels {
|
||||
switchInput(to: .liveInput(channel: stored))
|
||||
}
|
||||
// A test-loop choice (or an out-of-range channel) leaves the default test loop.
|
||||
} else if MicrophonePermission.isAuthorized, shoeGaze.engine.numInputChannels > 0 {
|
||||
// First launch with no saved choice but mic already granted → default to live input.
|
||||
switchInput(to: .liveInput(channel: 0))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Board-switch shortcuts
|
||||
|
||||
/// Hidden ⌘1…⌘9 buttons that solo (live-switch to) the matching board and select it as the
|
||||
/// edit target. Kept at zero opacity so the shortcuts stay active without showing chrome.
|
||||
private var boardSwitchShortcuts: some View {
|
||||
ZStack {
|
||||
ForEach(0 ..< min(ShoeGazeBuilderView.maxBoardShortcuts, shoeGaze.boards.count), id: \.self) { index in
|
||||
Button("") { switchToBoard(index) }
|
||||
.keyboardShortcut(KeyEquivalent(Character("\(index + 1)")), modifiers: .command)
|
||||
}
|
||||
}
|
||||
.opacity(0)
|
||||
.frame(width: 0, height: 0)
|
||||
.accessibilityHidden(true)
|
||||
}
|
||||
|
||||
/// Solos board `index` (a live amp-channel-style switch) and makes it the edit target.
|
||||
private func switchToBoard(_ index: Int) {
|
||||
guard index < shoeGaze.boards.count else { return }
|
||||
selectedBoardIndex = index
|
||||
let seconds: Double = min(max(crossfadeSeconds, 0.0), ShoeGazeBuilderView.maxCrossfadeSeconds)
|
||||
shoeGaze.soloBoard(shoeGaze.boards[index], crossfadeSeconds: seconds)
|
||||
}
|
||||
|
||||
// MARK: - Save / Load (iOS)
|
||||
|
||||
// On macOS, Save/Load are driven from the app's File menu (the app shell owns the
|
||||
|
||||
Reference in New Issue
Block a user