Ported from the Android tabs by parallel agents (each screen with its own SizzleSession category); slot editors use the card editor with a preset library; songs load/save in the Android project format. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
149 lines
6.5 KiB
Swift
149 lines
6.5 KiB
Swift
// SPDX-FileCopyrightText: 2026 Reactorcoremeltdown
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
import SwiftUI
|
|
|
|
/// The first tab (Android's TrackerScreen.kt): the transport toolbar and pattern
|
|
/// grid over the arrangement roll (or the punch-in keyboard) in portrait, 1.7 : 1;
|
|
/// in landscape the toolbar runs across the top and the grid sits beside the
|
|
/// lower half (1.4 : 1, or 1 : 1.3 with the keyboard, which needs the width).
|
|
struct TrackerScreen: View {
|
|
@EnvironmentObject var app: AppModel
|
|
// TrackerBody only stores references, so the playhead lines AppModel publishes
|
|
// re-run this body but not TrackerBody's: only the grid and roll redraw.
|
|
var body: some View { TrackerBody(app: app, state: TrackerState.shared) }
|
|
}
|
|
|
|
private struct TrackerBody: View {
|
|
let app: AppModel
|
|
@ObservedObject var state: TrackerState
|
|
@StateObject private var mirror: TrackerMirror
|
|
|
|
init(app: AppModel, state: TrackerState) {
|
|
self.app = app
|
|
self.state = state
|
|
_mirror = StateObject(wrappedValue: TrackerMirror(app))
|
|
}
|
|
|
|
var body: some View {
|
|
GeometryReader { geo in
|
|
let landscape = geo.size.width > geo.size.height
|
|
if landscape { self.landscape(geo.size) } else { portrait(geo.size) }
|
|
}
|
|
.background(TK.background)
|
|
}
|
|
|
|
private func portrait(_ size: CGSize) -> some View {
|
|
let upper = (size.height - 2) * 1.7 / 2.7
|
|
return VStack(spacing: 0) {
|
|
VStack(spacing: 0) {
|
|
TransportToolbar(app: app, state: state, mirror: mirror, landscape: false)
|
|
PatternGridView(app: app, state: state)
|
|
}
|
|
.frame(height: upper)
|
|
TK.accent.frame(height: 2)
|
|
lower.frame(maxHeight: .infinity)
|
|
}
|
|
}
|
|
|
|
private func landscape(_ size: CGSize) -> some View {
|
|
let gridWeight: CGFloat = state.punchInMode ? 1 : 1.4
|
|
let lowerWeight: CGFloat = state.punchInMode ? 1.3 : 1
|
|
let gridW = (size.width - 2) * gridWeight / (gridWeight + lowerWeight)
|
|
return VStack(spacing: 0) {
|
|
TransportToolbar(app: app, state: state, mirror: mirror, landscape: true)
|
|
TK.accent.frame(height: 2)
|
|
HStack(spacing: 0) {
|
|
PatternGridView(app: app, state: state).frame(width: gridW)
|
|
TK.accent.frame(width: 2)
|
|
lower.frame(maxWidth: .infinity)
|
|
}
|
|
.frame(maxHeight: .infinity)
|
|
}
|
|
}
|
|
|
|
@ViewBuilder private var lower: some View {
|
|
if state.punchInMode {
|
|
PunchKeyboard(app: app, state: state, mirror: mirror)
|
|
} else {
|
|
ArrangementRollView(app: app, state: state, mirror: mirror)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// Transport, pattern and edit controls: three justified rows in portrait, two in
|
|
/// landscape (pattern and edit groups share a row).
|
|
private struct TransportToolbar: View {
|
|
let app: AppModel
|
|
@ObservedObject var state: TrackerState
|
|
@ObservedObject var mirror: TrackerMirror
|
|
let landscape: Bool
|
|
|
|
var body: some View {
|
|
let _ = mirror.revision
|
|
VStack(spacing: 6) {
|
|
TKJustifiedRow(items: transportItems)
|
|
if landscape {
|
|
TKJustifiedRow(items: patternItems + editItems)
|
|
} else {
|
|
TKJustifiedRow(items: patternItems)
|
|
TKJustifiedRow(items: editItems)
|
|
}
|
|
}
|
|
.padding(6)
|
|
.background(TK.surface)
|
|
}
|
|
|
|
/// STOP, PLAY/PAUSE, tempo (-, readout = tap tempo, +), signature.
|
|
private var transportItems: [AnyView] {
|
|
let s = SizzleSession.shared
|
|
let playing = mirror.isPlaying
|
|
return [
|
|
AnyView(TKButton(label: "⧉ STOP") { state.stop() }),
|
|
AnyView(TKButton(label: playing ? "❚❚ PAUSE" : "▶ PLAY", active: playing, width: 112) { state.playPause() }),
|
|
AnyView(HStack(spacing: 0) {
|
|
TKRepeatButton(label: "-") { state.setTempo(SizzleSession.shared.tempo - 1) }
|
|
Text("\(Int(s.tempo)) BPM").font(Theme.mono(12)).foregroundColor(TK.text).lineLimit(1)
|
|
.frame(width: 72).padding(.vertical, 6)
|
|
.contentShape(Rectangle())
|
|
.onTapGesture { state.tapTempo() }
|
|
TKRepeatButton(label: "+") { state.setTempo(SizzleSession.shared.tempo + 1) }
|
|
}),
|
|
AnyView(TKDropdown("SIG", options: Array(SizzleSession.signatureLabels.indices), selected: s.signature,
|
|
optionLabel: { SizzleSession.signatureLabels[$0] }) { state.setSignature(app, $0) }),
|
|
]
|
|
}
|
|
|
|
/// Active block, pattern length, scale, root.
|
|
private var patternItems: [AnyView] {
|
|
let s = SizzleSession.shared
|
|
let length = s.length(ofPattern: s.activePattern)
|
|
let lengths = s.lengthOptions.map { $0.intValue }
|
|
let names = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
|
|
return [
|
|
AnyView(TKDropdown("BLK", options: Array(0..<8), selected: s.activePattern,
|
|
optionLabel: { "\($0 + 1)" }) { state.setActiveBlock(app, $0) }),
|
|
AnyView(TKDropdown("LEN", options: lengths.contains(length) ? lengths : lengths + [length],
|
|
selected: length) { state.setPatternLength(app, $0) }),
|
|
AnyView(TKDropdown("SCALE", options: Array(SizzleSession.scaleLabels.indices), selected: s.scale,
|
|
optionLabel: { SizzleSession.scaleLabels[$0] }) { SizzleSession.shared.scale = $0 }),
|
|
AnyView(TKDropdown("ROOT", options: Array(0..<12), selected: s.rootNote,
|
|
optionLabel: { names[$0] }) { SizzleSession.shared.rootNote = $0 }),
|
|
]
|
|
}
|
|
|
|
/// SEL, cut ✂, copy ⧉, paste ▤, delete ✕, note-off, skip step, KBD.
|
|
private var editItems: [AnyView] {
|
|
[
|
|
AnyView(TKButton(label: "SEL", active: state.selectMode) { state.toggleSelectMode(app) }),
|
|
AnyView(TKButton(label: "✂") { state.cutSelection(app) }),
|
|
AnyView(TKButton(label: "⧉") { state.copySelection(app) }),
|
|
AnyView(TKButton(label: "▤", active: state.canPaste) { state.pasteClipboard(app) }),
|
|
AnyView(TKButton(label: "✕") { state.deleteAndAdvance(app) }),
|
|
AnyView(TKButton(label: "OFF ===") { state.noteOffFocused(app) }),
|
|
AnyView(TKDropdown("SKIP", options: [0, 1, 2, 4, 8], selected: state.skipStep) { state.skipStep = $0 }),
|
|
AnyView(TKButton(label: "⌨ KBD", active: state.punchInMode) { state.punchInMode.toggle() }),
|
|
]
|
|
}
|
|
}
|