0.38.0 (72): Bluetooth LE MIDI controllers in Settings (Android and iOS)
- Android: BleMidi scans for the BLE MIDI service, connects through MidiManager.openBluetoothDevice, remembers and reconnects controllers; Settings › MIDI inputs › Bluetooth MIDI (Scan / Connect / Disconnect / Forget) - iOS: the system Bluetooth MIDI panel from Setup › MIDI Sync, connected controllers remembered and reconnected at launch via CoreBluetooth Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
2bc5cb1cbb
commit
4d9e2328cb
@@ -148,6 +148,8 @@ struct MidiSyncCard: View {
|
||||
SizzleMidi.shared.setSourceKey(src.key, enabled: on)
|
||||
}
|
||||
}
|
||||
SetupDivider()
|
||||
BluetoothMidiSection()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,3 +197,35 @@ struct BackupCard: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Bluetooth LE MIDI controllers (the Android app's Bluetooth MIDI list): the
|
||||
/// system panel finds and connects them; connected ones join the MIDI inputs
|
||||
/// above and are remembered, to reconnect at every launch until forgotten.
|
||||
struct BluetoothMidiSection: View {
|
||||
@ObservedObject var ble = BluetoothMidi.shared
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text("Bluetooth MIDI").font(.system(size: 15, weight: .medium)).foregroundColor(Theme.text)
|
||||
Text("Find Bluetooth LE MIDI controllers and connect them. Connected ones are listed with the " +
|
||||
"MIDI inputs and reconnect at every launch.")
|
||||
.font(.system(size: 12)).foregroundColor(Theme.dim).fixedSize(horizontal: false, vertical: true)
|
||||
}
|
||||
Spacer()
|
||||
SetupButton(title: "Find controllers", icon: "antenna.radiowaves.left.and.right") {
|
||||
BluetoothMidiPanel.present { ble.panelClosed() }
|
||||
}
|
||||
}
|
||||
ForEach(ble.remembered.sorted { $0.value < $1.value }, id: \.key) { id, name in
|
||||
HStack {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(name).font(.system(size: 15)).foregroundColor(Theme.text)
|
||||
Text("Remembered — reconnects at launch").font(.system(size: 12)).foregroundColor(Theme.dim)
|
||||
}
|
||||
Spacer()
|
||||
SetupButton(title: "Forget") { ble.forget(id) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import SwiftUI
|
||||
|
||||
#if canImport(UIKit)
|
||||
import AVKit
|
||||
import CoreAudioKit
|
||||
import UIKit
|
||||
|
||||
enum ShareSheet {
|
||||
@@ -119,8 +120,42 @@ struct AudioRouteView: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// The system's Bluetooth MIDI panel (find, connect, disconnect BLE MIDI
|
||||
/// controllers) in a sheet with Done; [done] runs however it closes.
|
||||
enum BluetoothMidiPanel {
|
||||
@MainActor static func present(done: @escaping () -> Void) {
|
||||
let scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
|
||||
let scene = scenes.first { $0.activationState == .foregroundActive } ?? scenes.first
|
||||
var top = scene?.windows.first { $0.isKeyWindow }?.rootViewController
|
||||
while let p = top?.presentedViewController { top = p }
|
||||
guard let host = top else { return }
|
||||
let panel = CABTMIDICentralViewController()
|
||||
let nav = UINavigationController(rootViewController: panel)
|
||||
let closer = Closer(done)
|
||||
panel.navigationItem.rightBarButtonItem = UIBarButtonItem(systemItem: .done, primaryAction: UIAction { [weak nav] _ in
|
||||
nav?.dismiss(animated: true) { closer.fire() }
|
||||
})
|
||||
nav.modalPresentationStyle = .formSheet
|
||||
nav.presentationController?.delegate = closer
|
||||
objc_setAssociatedObject(nav, &Closer.key, closer, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
||||
host.present(nav, animated: true)
|
||||
}
|
||||
|
||||
private final class Closer: NSObject, UIAdaptivePresentationControllerDelegate {
|
||||
static var key = 0
|
||||
private var done: (() -> Void)?
|
||||
init(_ done: @escaping () -> Void) { self.done = done }
|
||||
func fire() { done?(); done = nil }
|
||||
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) { fire() }
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
enum BluetoothMidiPanel {
|
||||
@MainActor static func present(done: @escaping () -> Void) { done() }
|
||||
}
|
||||
|
||||
struct AudioRouteView: View {
|
||||
var body: some View {
|
||||
Text("Output: Speaker\nInput: Microphone").font(.system(size: 14)).foregroundColor(Theme.text)
|
||||
|
||||
Reference in New Issue
Block a user