1893576718
Headline: MIDI control for a Behringer FCB1010 (four phases). - MIDIController (Lyrebird MIDI client): connection indicator via source polling, background-queue->main-actor hop, MIDI Learn. - Volume and Wah pedals (Wah reuses the SVF bandpass sweep, driven by pedal position instead of an envelope follower). - CC -> any pedal knob (0-127 mapped across the knob range). - Program Change -> pedal/board/rig toggles: software latch for booleans, exclusive radio for board solo. Positional addressing with display-name hints; stale/out-of-range bindings are skipped, not fired. - Per-rig MIDIMap embedded in ShoeGazeState as an optional field (old rigs decode to nil; no preset version bump). Central MIDI Mapping sheet with Learn/Clear per control. Also included (same working branch): - Full board bypass and rig bypass (dry passthrough via cascaded crossfades in BoardOutputMaster), with UI toggles. - Horizontal pedal picker grouped by category in filter order. - Drag a palette pedal onto a chain card to insert before it (ShoeGaze.insertPedal); tap still appends. - iOS: guard macOS-only .menuStyle(.borderlessButton) to silence the _UIReparentingView warning; iCloud-unavailable alert; keep the device awake while audio runs. Tests: 24 added (Volume/Wah, MIDIMap Codable incl. legacy decode, CC and PC controller behavior, insert/bypass API). Full suite green; macOS and iOS app targets build. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
65 lines
2.4 KiB
Swift
65 lines
2.4 KiB
Swift
// MIDIIndicatorView.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import SwiftUI
|
|
import LyrebirdShoeGaze
|
|
|
|
/// A compact transport-row indicator showing whether a MIDI device is connected.
|
|
///
|
|
/// Green when at least one input source is present, gray otherwise; a badge shows the count when
|
|
/// more than one device is connected. Tapping invokes `onTap` (the host presents the MIDI mapping
|
|
/// sheet). Observes the `@Observable` ``MIDIController`` so it refreshes automatically as devices
|
|
/// connect and disconnect.
|
|
public struct MIDIIndicatorView: View {
|
|
|
|
// MARK: - Constants
|
|
|
|
private static let iconSize: CGFloat = 13
|
|
private static let spacing: CGFloat = 3
|
|
private static let badgeFontSize: CGFloat = 10
|
|
private static let disconnectedOpacity: Double = 0.5
|
|
|
|
// MARK: - Inputs
|
|
|
|
private let controller: MIDIController
|
|
private let onTap: () -> Void
|
|
|
|
/// Creates a MIDI connection indicator.
|
|
///
|
|
/// - Parameters:
|
|
/// - controller: The MIDI controller whose connection state is displayed.
|
|
/// - onTap: Invoked when the indicator is tapped (present the MIDI mapping sheet). Defaults to
|
|
/// a no-op.
|
|
public init(controller: MIDIController, onTap: @escaping () -> Void = {}) {
|
|
self.controller = controller
|
|
self.onTap = onTap
|
|
}
|
|
|
|
// MARK: - Body
|
|
|
|
public var body: some View {
|
|
let connected: Bool = controller.isConnected
|
|
return Button(action: onTap) {
|
|
HStack(spacing: MIDIIndicatorView.spacing) {
|
|
Image(systemName: connected ? "pianokeys" : "pianokeys.inverse")
|
|
.font(.system(size: MIDIIndicatorView.iconSize))
|
|
.foregroundStyle(connected
|
|
? Color.green
|
|
: Color.white.opacity(MIDIIndicatorView.disconnectedOpacity))
|
|
if controller.connectedDeviceNames.count > 1 {
|
|
Text("\(controller.connectedDeviceNames.count)")
|
|
.font(.system(size: MIDIIndicatorView.badgeFontSize, weight: .semibold).monospacedDigit())
|
|
.foregroundStyle(Color.green)
|
|
}
|
|
}
|
|
}
|
|
.buttonStyle(.plain)
|
|
.help(connected
|
|
? "MIDI connected: \(controller.connectedDeviceNames.joined(separator: ", "))"
|
|
: "No MIDI device detected")
|
|
}
|
|
}
|