- Master recording (MasterSink ring + writer thread) and the sample recorder - CoreMIDI in/out: sound module, clock send/follow, virtual "Sizzle" ports; platform-free parser/module/clock in core (midi_test) - Hardware keyboard and gamepads via GameController; rebindable keyboard, gamepad and MIDI CC actions; per-parameter MIDI learn - Colour themes (.szt), project bundles (.szgz), backup & restore; ZIP in core with zlib (zip_test against jar and unzip) - Persistent app settings; audio pauses in the background unless sound module Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
68 lines
2.6 KiB
Swift
68 lines
2.6 KiB
Swift
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||
|
||
import Combine
|
||
import SwiftUI
|
||
|
||
/// The app's UI state around the open song (SizzleSession): the iOS counterpart
|
||
/// of the Android app's AppViewModel. Screens read the song through `session`
|
||
/// and re-render when `revision` changes; transport state is polled at display
|
||
/// rate while playing.
|
||
@MainActor
|
||
final class AppModel: ObservableObject {
|
||
enum Tab: Int, CaseIterable { case tracker, mix, toolbox, setup }
|
||
|
||
let session = SizzleSession.shared
|
||
/// The app's instance (the snapshot tool makes its own).
|
||
static let main = AppModel()
|
||
|
||
/// Bumped whenever the song changes (any edit, load, transport change).
|
||
@Published private(set) var revision = 0
|
||
@Published var tab: Tab = .tracker
|
||
|
||
// Transport, polled ~30×/s.
|
||
@Published private(set) var isPlaying = false
|
||
@Published private(set) var currentLine = 0
|
||
@Published private(set) var currentBeat = 0
|
||
|
||
// Tracker cursor (Android: cursorLine / cursorTrack / column).
|
||
enum Column: Int { case note, velocity, channel }
|
||
@Published var cursorTrack = 0
|
||
@Published var cursorLine = 0
|
||
@Published var cursorColumn: Column = .note
|
||
|
||
// On-screen keyboard (Android: kbdChannel / kbdOctave / kbdVelocity).
|
||
// Channel and octave persist (AppSettings), like Android's.
|
||
@Published var kbdChannel = AppSettings.shared.kbdChannel { didSet { AppSettings.shared.kbdChannel = kbdChannel } }
|
||
@Published var kbdOctave = AppSettings.shared.kbdOctave { didSet { AppSettings.shared.kbdOctave = kbdOctave } }
|
||
@Published var kbdVelocity = 127
|
||
|
||
/// The toolbox slot whose editor is open, if any.
|
||
@Published var editingSlot: Int?
|
||
|
||
private var observer: NSObjectProtocol?
|
||
private var timer: Timer?
|
||
|
||
init() {
|
||
observer = NotificationCenter.default.addObserver(forName: .SizzleSessionDidChange, object: nil, queue: .main) { [weak self] _ in
|
||
Task { @MainActor in self?.revision += 1 }
|
||
}
|
||
timer = Timer.scheduledTimer(withTimeInterval: 1.0 / 30, repeats: true) { [weak self] _ in
|
||
Task { @MainActor in self?.pollTransport() }
|
||
}
|
||
}
|
||
|
||
private func pollTransport() {
|
||
let playing = session.isPlaying
|
||
if playing != isPlaying { isPlaying = playing }
|
||
if playing {
|
||
let line = session.currentLine, beat = session.currentBeat
|
||
if line != currentLine { currentLine = line }
|
||
if beat != currentBeat { currentBeat = beat }
|
||
}
|
||
}
|
||
|
||
func playPause() { session.isPlaying ? session.pause() : session.play() }
|
||
func stop() { session.stop() }
|
||
}
|