diff --git a/Demo/ShoeGazeBuilder/AppDelegate.swift b/Demo/ShoeGazeBuilder/AppDelegate.swift index 0df0109..176e08a 100644 --- a/Demo/ShoeGazeBuilder/AppDelegate.swift +++ b/Demo/ShoeGazeBuilder/AppDelegate.swift @@ -6,6 +6,7 @@ #if os(macOS) import AppKit +import UniformTypeIdentifiers import LyrebirdSynth import LyrebirdUI import LyrebirdShoeGaze @@ -50,6 +51,13 @@ final class AppDelegate: NSObject, NSApplicationDelegate { private let shoeGaze: ShoeGaze private let window: LyrebirdWindow + /// Transport menu items, retained so `validateMenuItem(_:)` can enable/disable them. + private var startMenuItem: NSMenuItem? + private var stopMenuItem: NSMenuItem? + + /// Default file name offered by the Save panel. + private static let defaultRigFileName: String = "ShoeGazeRig" + // MARK: - Init override init() { @@ -152,7 +160,99 @@ final class AppDelegate: NSObject, NSApplicationDelegate { keyEquivalent: "q" ) + // File menu — rig save / load. + let fileMenuItem: NSMenuItem = NSMenuItem() + mainMenu.addItem(fileMenuItem) + let fileMenu: NSMenu = NSMenu(title: "File") + fileMenuItem.submenu = fileMenu + addItem(to: fileMenu, title: "Save Rig…", action: #selector(saveRigAction(_:)), key: "s") + addItem(to: fileMenu, title: "Load Rig…", action: #selector(loadRigAction(_:)), key: "o") + + // Board menu — add board + transport. + let boardMenuItem: NSMenuItem = NSMenuItem() + mainMenu.addItem(boardMenuItem) + let boardMenu: NSMenu = NSMenu(title: "Board") + boardMenuItem.submenu = boardMenu + addItem(to: boardMenu, title: "Add Board", action: #selector(addBoardAction(_:)), key: "b") + boardMenu.addItem(NSMenuItem.separator()) + startMenuItem = addItem(to: boardMenu, title: "Start", action: #selector(startAction(_:)), key: "r") + stopMenuItem = addItem(to: boardMenu, title: "Stop", action: #selector(stopAction(_:)), key: ".") + NSApplication.shared.mainMenu = mainMenu } + + /// Adds a menu item targeting this delegate and returns it. + @discardableResult + private func addItem( + to menu: NSMenu, + title: String, + action: Selector, + key: String + ) -> NSMenuItem { + let item: NSMenuItem = NSMenuItem(title: title, action: action, keyEquivalent: key) + item.target = self + menu.addItem(item) + return item + } + + // MARK: - Menu actions + + @objc private func saveRigAction(_ sender: Any?) { + let panel: NSSavePanel = NSSavePanel() + panel.allowedContentTypes = [.json] + panel.nameFieldStringValue = "\(AppDelegate.defaultRigFileName).json" + panel.canCreateDirectories = true + let session: ShoeGaze = shoeGaze + panel.begin { response in + guard response == .OK, let url: URL = panel.url else { return } + do { try session.saveRig(to: url) } + catch { print("[ShoeGazeBuilder] saveRig failed: \(error)") } + } + } + + @objc private func loadRigAction(_ sender: Any?) { + let panel: NSOpenPanel = NSOpenPanel() + panel.allowedContentTypes = [.json] + panel.canChooseDirectories = false + panel.allowsMultipleSelection = false + let session: ShoeGaze = shoeGaze + let activeEngine: SynthesisEngine = engine + panel.begin { response in + guard response == .OK, let url: URL = panel.url else { return } + // loadRig rebuilds the graph; stop the engine around it and restart if it was running. + let wasRunning: Bool = activeEngine.isRunning + if wasRunning { activeEngine.stop() } + do { try session.loadRig(from: url) } + catch { print("[ShoeGazeBuilder] loadRig failed: \(error)") } + if wasRunning { try? activeEngine.start() } + } + } + + @objc private func addBoardAction(_ sender: Any?) { + var created: PedalBoard? + do { + let board: PedalBoard = try shoeGaze.addBoard() + created = board + try shoeGaze.finalizeBoard(board) + } catch { + if let board: PedalBoard = created { shoeGaze.removeBoard(board) } + print("[ShoeGazeBuilder] addBoard failed: \(error)") + } + } + + @objc private func startAction(_ sender: Any?) { + do { try engine.start() } + catch { print("[ShoeGazeBuilder] engine.start() failed: \(error)") } + } + + @objc private func stopAction(_ sender: Any?) { + engine.stop() + } + + func validateMenuItem(_ menuItem: NSMenuItem) -> Bool { + if menuItem == startMenuItem { return !engine.isRunning } + if menuItem == stopMenuItem { return engine.isRunning } + return true + } } #endif diff --git a/Demo/ShoeGazeBuilder/Info.plist b/Demo/ShoeGazeBuilder/Info.plist index 6734627..40ba3db 100644 --- a/Demo/ShoeGazeBuilder/Info.plist +++ b/Demo/ShoeGazeBuilder/Info.plist @@ -23,7 +23,7 @@ NSHighResolutionCapable NSHumanReadableCopyright - Copyright © 2026 Realized Sound. All rights reserved. + Copyright © 2026 realizedsound. All rights reserved. NSMicrophoneUsageDescription ShoeGaze Builder can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode. NSPrincipalClass diff --git a/Demo/ShoeGazeBuilderiOS/Info.plist b/Demo/ShoeGazeBuilderiOS/Info.plist index 6a23071..bd68f12 100644 --- a/Demo/ShoeGazeBuilderiOS/Info.plist +++ b/Demo/ShoeGazeBuilderiOS/Info.plist @@ -19,7 +19,7 @@ LSRequiresIPhoneOS NSHumanReadableCopyright - Copyright © 2026 Realized Sound. All rights reserved. + Copyright © 2026 realizedsound. All rights reserved. NSMicrophoneUsageDescription ShoeGaze Builder can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode. UIApplicationSceneManifest diff --git a/Demo/ShoeGazeDemo/Info.plist b/Demo/ShoeGazeDemo/Info.plist index 356ee7d..d23e0ba 100644 --- a/Demo/ShoeGazeDemo/Info.plist +++ b/Demo/ShoeGazeDemo/Info.plist @@ -23,7 +23,7 @@ NSHighResolutionCapable NSHumanReadableCopyright - Copyright © 2026 Realized Sound. All rights reserved. + Copyright © 2026 realizedsound. All rights reserved. NSMicrophoneUsageDescription ShoeGazeDemo can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode. NSPrincipalClass diff --git a/Demo/ShoeGazeiOSDemo/Info.plist b/Demo/ShoeGazeiOSDemo/Info.plist index dfec45c..15affdb 100644 --- a/Demo/ShoeGazeiOSDemo/Info.plist +++ b/Demo/ShoeGazeiOSDemo/Info.plist @@ -19,7 +19,7 @@ LSRequiresIPhoneOS NSHumanReadableCopyright - Copyright © 2026 Realized Sound. All rights reserved. + Copyright © 2026 realizedsound. All rights reserved. NSMicrophoneUsageDescription ShoeGazeiOSDemo can route a hardware input channel through your pedalboard. Enable microphone access to use Live Input mode. UIApplicationSceneManifest diff --git a/Sources/LyrebirdShoeGazeUI/ShoeGazeBuilderView.swift b/Sources/LyrebirdShoeGazeUI/ShoeGazeBuilderView.swift index b8104a6..a697b20 100644 --- a/Sources/LyrebirdShoeGazeUI/ShoeGazeBuilderView.swift +++ b/Sources/LyrebirdShoeGazeUI/ShoeGazeBuilderView.swift @@ -60,10 +60,12 @@ public struct ShoeGazeBuilderView: View { /// Bumped on transport/edit actions to force a re-read of `engine.isRunning`. @State private var transportTick: Bool = false - /// iOS file-dialog presentation flags + the document to export. + #if !os(macOS) + /// iOS file-dialog presentation flags + the document to export. (macOS uses the File menu.) @State private var showImporter: Bool = false @State private var showExporter: Bool = false @State private var exportDocument: RigFileDocument = RigFileDocument(data: Data()) + #endif // MARK: - Init @@ -176,10 +178,14 @@ public struct ShoeGazeBuilderView: View { Spacer() + // On macOS, Save/Load live in the app's File menu (see the app shell's AppDelegate); + // on iOS they stay in-view, driven by fileExporter/fileImporter. + #if !os(macOS) Button("Save…") { saveAction() } .buttonStyle(.bordered).tint(.blue) Button("Load…") { loadAction() } .buttonStyle(.bordered).tint(.blue) + #endif } } @@ -290,42 +296,23 @@ public struct ShoeGazeBuilderView: View { transportTick.toggle() } - // MARK: - Save / Load + // MARK: - Save / Load (iOS) + // On macOS, Save/Load are driven from the app's File menu (the app shell owns the + // NSSavePanel/NSOpenPanel and calls `shoeGaze.saveRig`/`loadRig` directly). On iOS they are + // in-view, presenting `fileExporter`/`fileImporter`. + #if !os(macOS) private func saveAction() { - #if os(macOS) - let panel: NSSavePanel = NSSavePanel() - panel.allowedContentTypes = [.json] - panel.nameFieldStringValue = "\(ShoeGazeBuilderView.defaultRigFileName).json" - panel.canCreateDirectories = true - panel.begin { response in - guard response == .OK, let url: URL = panel.url else { return } - do { try shoeGaze.saveRig(to: url) } - catch { print("[ShoeGazeBuilderView] saveRig failed: \(error)") } - } - #else do { exportDocument = RigFileDocument(data: try shoeGaze.rigData()) showExporter = true } catch { print("[ShoeGazeBuilderView] rigData failed: \(error)") } - #endif } private func loadAction() { - #if os(macOS) - let panel: NSOpenPanel = NSOpenPanel() - panel.allowedContentTypes = [.json] - panel.canChooseDirectories = false - panel.allowsMultipleSelection = false - panel.begin { response in - guard response == .OK, let url: URL = panel.url else { return } - loadRig(from: url) - } - #else showImporter = true - #endif } /// Loads a rig from a URL, stopping/restarting the engine around the rebuild and resetting the @@ -343,7 +330,6 @@ public struct ShoeGazeBuilderView: View { transportTick.toggle() } - #if !os(macOS) private func handleImport(_ result: Result) { switch result { case .success(let url):