commit current state

This commit is contained in:
2026-06-22 15:40:23 -07:00
parent e36dc3a527
commit c6f567535b
14 changed files with 431 additions and 101 deletions
+12 -21
View File
@@ -27,7 +27,10 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
private static let blockSize: Int = 512
private static let sampleRate: Double = 48_000.0
private static let outputChannels: Int = 2
private static let inputChannels: Int = 2
// Built-in mics are mono; default to one input channel so live input works out of the box.
// CoreAudio can't satisfy a request for more input channels than the device provides, which
// leaves live input silent. Users with multi-input interfaces can raise this in the UI.
private static let inputChannels: Int = 1
private static let numAudioBuses: Int = 256
// MARK: - Window geometry constants
@@ -47,14 +50,11 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
// MARK: - Owned objects
private let coreDriver: CoreAudioDriver
private let engine: SynthesisEngine
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?
/// Record toggle item, retained so `validateMenuItem(_:)` can flip its title + enabled state.
private var recordMenuItem: NSMenuItem?
@@ -64,14 +64,16 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
// 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: CoreAudioDriver()
driver: coreDriver
)
self.coreDriver = coreDriver
self.engine = engine
self.shoeGaze = ShoeGaze(engine: engine)
self.window = LyrebirdWindow(
@@ -102,8 +104,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
installMainMenu()
let session: ShoeGaze = shoeGaze
let driver: CoreAudioDriver = coreDriver
window.open {
ShoeGazeBuilderView(shoeGaze: session)
ShoeGazeBuilderView(shoeGaze: session, hardwareSampleRate: { driver.deviceSampleRate })
}
anchorWindowLeft()
}
@@ -176,10 +179,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
mainMenu.addItem(boardMenuItem)
let boardMenu: NSMenu = NSMenu(title: "Board")
boardMenuItem.submenu = boardMenu
// 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.
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: ".")
// Record menu — choose an output folder, then toggle recording.
let recordMenuItem: NSMenuItem = NSMenuItem()
@@ -262,15 +264,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}
}
@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()
}
@objc private func chooseRecordingFolderAction(_ sender: Any?) {
let panel: NSOpenPanel = NSOpenPanel()
panel.canChooseDirectories = true
@@ -299,8 +292,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
}
func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
if menuItem == startMenuItem { return !engine.isRunning }
if menuItem == stopMenuItem { return engine.isRunning }
if menuItem == recordMenuItem {
menuItem.title = shoeGaze.isRecording ? "Stop Recording" : "Start Recording"
// Can always stop; can only start once a folder has been chosen.
@@ -23,7 +23,10 @@ struct ShoeGazeBuilderiOSApp: App {
var body: some Scene {
WindowGroup {
NavigationStack {
ShoeGazeBuilderView(shoeGaze: model.shoeGaze)
ShoeGazeBuilderView(
shoeGaze: model.shoeGaze,
hardwareSampleRate: { model.hardwareSampleRate }
)
.navigationTitle("ShoeGaze Builder")
.navigationBarTitleDisplayMode(.inline)
}
@@ -33,6 +33,10 @@ final class ShoeGazeBuilderiOSAppModel {
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
@@ -50,14 +54,16 @@ final class ShoeGazeBuilderiOSAppModel {
}
let sampleRate: Double = session.sampleRate
let driver: iOSAudioDriver = iOSAudioDriver()
let eng: SynthesisEngine = SynthesisEngine(
blockSize: ShoeGazeBuilderiOSAppModel.blockSize,
sampleRate: sampleRate,
numOutputChannels: ShoeGazeBuilderiOSAppModel.outputChannels,
numInputChannels: 0,
numAudioBuses: ShoeGazeBuilderiOSAppModel.numAudioBuses,
driver: iOSAudioDriver()
driver: driver
)
self.iosDriver = driver
self.engine = eng
self.shoeGaze = ShoeGaze(engine: eng)
+9 -3
View File
@@ -27,7 +27,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
private static let blockSize: Int = 512
private static let sampleRate: Double = 48_000.0
private static let outputChannels: Int = 2
private static let inputChannels: Int = 6
// 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
@@ -37,6 +39,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
// MARK: - Owned objects
private let coreDriver: CoreAudioDriver
private let controller: ShoeGazeDemoController
private let window: LyrebirdWindow
@@ -46,15 +49,17 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
// 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: CoreAudioDriver()
driver: coreDriver
)
self.coreDriver = coreDriver
self.controller = ShoeGazeDemoController(engine: engine)
self.window = LyrebirdWindow(
title: "ShoeGaze — Lyrebird Guitar Pedalboard",
@@ -69,8 +74,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
installMainMenu()
let demoController: ShoeGazeDemoController = controller
let driver: CoreAudioDriver = coreDriver
window.open {
DemoRootView(controller: demoController)
DemoRootView(controller: demoController, hardwareSampleRate: { driver.deviceSampleRate })
}
}
+26 -27
View File
@@ -47,6 +47,7 @@ struct DemoRootView: View {
// 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).
@@ -56,10 +57,17 @@ struct DemoRootView: View {
/// Creates the root demo view bound to the given controller.
///
/// - Parameter controller: The `ShoeGazeDemoController` that owns the engine, active
/// `ShoeGaze` session, and current mode. All toolbar actions dispatch through this.
init(controller: ShoeGazeDemoController) {
/// - 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
@@ -157,7 +165,7 @@ struct DemoRootView: View {
.foregroundStyle(Color.white.opacity(0.65))
Picker("Input", selection: inputSourceBinding) {
Text("Test Loop").tag(-1)
ForEach(0..<controller.engine.numInputChannels, id: \.self) { channel in
ForEach(Array(0..<max(0, controller.engine.numInputChannels)), id: \.self) { channel in
Text("In \(channel)").tag(channel)
}
}
@@ -166,29 +174,20 @@ struct DemoRootView: View {
}
}
/// Start and Stop transport buttons.
/// Engine configuration + transport (sample rate, ins/outs, Start/Stop, mismatch alert).
private var transportButtons: some View {
// `controller.isRunning` derives from the engine; toggling the tick on press
// re-evaluates this view so the buttons reflect the change immediately.
_ = transportTick
let isRunning: Bool = controller.isRunning
return HStack(spacing: DemoRootView.toolbarSpacing) {
Button("Start") {
controller.start()
transportTick.toggle()
}
.buttonStyle(.borderedProminent)
.tint(.green)
.disabled(isRunning)
Button("Stop") {
controller.stop()
transportTick.toggle()
}
.buttonStyle(.bordered)
.tint(.red)
.disabled(!isRunning)
}
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
@@ -198,7 +197,7 @@ struct DemoRootView: View {
private var contentArea: some View {
switch controller.mode {
case .boards:
ShoeGazeView(shoeGaze: controller.shoeGaze)
ShoeGazeView(shoeGaze: controller.shoeGaze, hardwareSampleRate: hardwareSampleRate)
case .editor:
editorContent
+35 -3
View File
@@ -160,6 +160,32 @@ final class ShoeGazeDemoController {
}
}
// 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()
if wasRunning { start() }
}
// MARK: - Rebuild
/// Tears down the current session and rebuilds the active mode.
@@ -169,14 +195,22 @@ final class ShoeGazeDemoController {
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()
@@ -184,8 +218,6 @@ final class ShoeGazeDemoController {
case .router: buildRouter()
case .stereo: buildStereo()
}
if wasRunning { start() }
}
// MARK: - Mode builders
@@ -0,0 +1,33 @@
{
"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
}
@@ -22,7 +22,7 @@ struct ShoeGazeiOSDemoApp: App {
WindowGroup {
NavigationStack {
ScrollView {
ShoeGazeView(shoeGaze: model.shoeGaze)
ShoeGazeView(shoeGaze: model.shoeGaze, hardwareSampleRate: { model.hardwareSampleRate })
.padding(.horizontal, 12)
}
.navigationTitle("ShoeGaze")
@@ -41,6 +41,10 @@ final class ShoeGazeiOSDemoAppModel {
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
@@ -54,14 +58,16 @@ final class ShoeGazeiOSDemoAppModel {
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: iOSAudioDriver()
driver: driver
)
self.iosDriver = driver
self.engine = eng
self.shoeGaze = ShoeGaze(engine: eng)