// The SONG PLAYING as a GUITAR-AMP HEAD (the owner's go, 4 Nov 2026; the dark // room's picture `marshall-player`, its proof `music12-faces/composite-amp`): // the third player face of Music's Listening deck, beside the hi-fi and the // turntable, drawn for the playing song's card, a bare object standing on the // music's black tolex (`FaceGround.tolex`). The cabinet's cream panel carries // the song's name in a script hand on its top band and "ARTIST · ALBUM" in // small cream capitals on its black strip; under them the big brass knob is // the clock, turned from nought to the song's end across its tick arc, the // time played at the arc's top, the time left right of it, "0:00" and the // song's length at its ends; two small knobs either side, VOLUME and TONE // typed under them; the orange jewel lit while it plays. Behind the grille // cloth the record turns at 33⅓ while it plays, the album's cover cropped // round on it, else its typed blank label. The playing album's sleeve leans // against the wall upper left, as the hi-fi's does. // // PAINTED (`Media.xcassets`, `scripts/import-music-materials.py`): the frame // (its panel's and grille's apertures cut through it), the cream panel, the // tick arc, the big knob, the small knob (laid twice), the grille cloth (its // weave's gaps alpha), the jewel lit and dark, the shadow, the record and its // blank label, and the sleeve's frame, blank and shadow, each laid where the // materials' `layout.json` places it in the amp's 1135 x 1090 box, scaled by // the drawn width over 1135. The face draws live only what the data decides: // every word and figure, the knobs' and the record's angles, and which jewel // is laid. // // THE PLAYER (`faceTrackPlayer`) says how far into the song it is: PLAYING // the jewel is lit and the record turns with the time played; PAUSED, or // holding none of the song, the jewel is dark and the record stands. Reduce // Motion stands the record still and steps the knob from painted tick to // painted tick. Nothing here keeps time. // // THE CONTROLS, tagged (`facePart`): the big knob is `scrub` — turned round // its centre it seeks, the knob and the times following the turn, the player // moved there when the finger lifts; the jewel and the panel's centre are // `play`, a tap plays or pauses; the grille's left third is `previous` and // its right third `next`, which the shell runs; the song's name is `title`, // "artist · album" `subtitle`, the sleeve `picture`. // // Every word is the card's (`title`, `artist`, `album`, its length in seconds // `duration`, the device's `volume` nought to one where it carries one), the // player's or a line. import CottonPaper import CottonValues import SwiftUI enum SongAmpFaceKnobs { // THE AMP BOX every placement is in, in the paintings' pixels // (`layout.json`'s `objects.amp`): the face draws it its own width, // never wider than `widest`, the sleeve leaning above it, and every place // below is scaled by the drawn width over it. static let box = CGSize(width: 1135, height: 1090) static let widest: CGFloat = 340 /// The whole drawing, the sleeve above the cabinet and the shadow under /// it: what the face fits to its room. static let whole = CGRect(x: 0, y: -420, width: 1135, height: 1602) static let shadow = CGRect(x: -80, y: -68, width: 1295, height: 1250) static let panel = CGRect(x: 57, y: 72, width: 1020, height: 505) static let grille = CGRect(x: 57, y: 638, width: 1020, height: 390) // THE RECORD behind the grille cloth, and its label, about one centre, // seen only through the grille's aperture (`recordAndLabelClip`). The // record is painted with its label's round cut out (191 of its 570 // pixels' reach), the label with its spindle hole (29 of 450); a cover // is laid the label's size, the record's inner rim framing it. static let record = CGRect(x: 115, y: 430, width: 900, height: 900) static let label = CGRect(x: 403, y: 718, width: 324, height: 324) static let clip = CGRect(x: 70, y: 650, width: 990, height: 365) static let hole: CGFloat = 29.0 / 900 /// The record's turn while it plays: 33⅓ turns a minute, in degrees a /// second. static let turnRate: Double = 360 * (100.0 / 3) / 60 /// The veil over a cover, as the single's, so it sits back behind the /// cloth like the painted label. static let veil: Double = 0.3 // THE BLANK LABEL'S WORDS, in the amp box about the label's centre // (565, 880), clear of the spindle hole (`labelTextCircle`, 139 out, // 18 in): the name above it, the artist and the album below. static let labelTitle = CGRect(x: 450, y: 770, width: 230, height: 80) static let labelTitleSize: CGFloat = 44 static let labelLines = [CGRect(x: 470, y: 912, width: 190, height: 30), CGRect(x: 480, y: 944, width: 170, height: 30)] static let labelLineSize: CGFloat = 20 // THE PANEL'S WORDS: the song's name in the hand on the top band, one // line at its size, else a step or two smaller, else two lines over the // whole band; "artist · album" in spaced capitals on the black strip. static let title = CGRect(x: 115, y: 100, width: 905, height: 70) static let titleBand = CGRect(x: 115, y: 82, width: 905, height: 100) static let titleSize: CGFloat = 86 static let titleSteps: [CGFloat] = [1, 0.84, 0.7] static let titleTwoLines: CGFloat = 0.5 static let byline = CGRect(x: 120, y: 190, width: 895, height: 55) static let bylineSize: CGFloat = 26 static let bylineTracking: CGFloat = 0.14 // THE BIG KNOB AND ITS ARC, about one centre: the knob's sweep, nought // to the song's end, in degrees from upright (`knobSweep`); and the // painted ticks it steps between under Reduce Motion, measured off // `amp-ticks` round its centre. static let bigKnob = CGRect(x: 442, y: 325, width: 250, height: 250) static let bigKnobCentre = CGPoint(x: 567, y: 450) static let ticks = CGRect(x: 357, y: 240, width: 420, height: 210) static let sweep = (start: -90.0, end: 90.0) static let tickAngles: [Double] = [ -90, -80.2, -71.5, -62.8, -54.3, -46.4, -38.5, -30, -22.5, -14.8, -7.1, 0, 7.1, 14.8, 22.5, 30, 38.5, 46.4, 54.3, 62.8, 71.5, 80.2, 90, ] /// The times: played at the arc's top, left right of it, nought and /// the length at the arc's ends (each `ends` wide about its point). static let elapsed = CGRect(x: 502, y: 267, width: 130, height: 45) static let remaining = CGRect(x: 705, y: 290, width: 140, height: 40) static let start = CGPoint(x: 335, y: 490) static let end = CGPoint(x: 800, y: 490) static let ends = CGSize(width: 140, height: 44) static let elapsedSize: CGFloat = 36 static let timeSize: CGFloat = 30 // THE SMALL KNOBS, VOLUME left and TONE right, their words typed under // them about `volumePoint` and `tonePoint`; volume's sweep, nought to // full, from seven o'clock to five, and tone's one standing angle. static let smallKnobs = [CGRect(x: 140, y: 375, width: 120, height: 120), CGRect(x: 870, y: 375, width: 120, height: 120)] static let smallWords = [CGPoint(x: 200, y: 510), CGPoint(x: 930, y: 510)] static let smallWordsBox = CGSize(width: 160, height: 30) static let smallWordsSize: CGFloat = 20 static let volumeSweep = (start: -150.0, end: 150.0) static let tone: Double = 30 // THE JEWEL, lit and dark painted to one bezel centre in one box. static let jewel = CGRect(x: 925, y: 265, width: 70, height: 70) /// The jewel's touch reaches this far round its centre. static let jewelTouch: CGFloat = 60 /// The panel's centre a tap plays or pauses: below the black strip, /// between the small knobs, the big knob over it. static let panelCentre = CGRect(x: 280, y: 250, width: 575, height: 325) // THE SLEEVE leaning on the wall upper left: its painted box set so its // cover's aperture stands where the proof lays the cover // (`sampleCoverRect`, 75, −360, 330 square), the aperture and the // shadow in its painting's pixels, how far it leans and the blank's // typeset words, as the hi-fi's. static let sleevePainted: CGFloat = 1130 static let cover = CGRect(x: 82, y: 84, width: 964, height: 964) static let sleeve = CGRect(x: 47, y: -389, width: 387, height: 387) static let sleeveShadow = CGRect(x: -80, y: -80, width: 1290, height: 1290) static let lean: Double = -4 static let blankWords = CGRect(x: 170, y: 250, width: 790, height: 520) static let blankTitleSize: CGFloat = 104 static let blankArtistSize: CGFloat = 64 } /// What the amp reads off its card and its player. public enum AmpHead { /// The amp's standing: as the hi-fi's, by the player's word alone. public static func state(_ play: TrackPlay) -> HifiDeck.State { HifiDeck.state(play) } /// The big knob's angle, in degrees clockwise from upright: from its /// start at nought to its end at the song's length; under Reduce Motion /// the painted tick at or before it. public static func knob(_ elapsed: TimeInterval, of length: TimeInterval, stepped: Bool = false) -> Double { let sweep = SongAmpFaceKnobs.sweep let share = length > 0 && elapsed.isFinite ? min(1, max(0, elapsed / length)) : 0 let angle = sweep.start + (sweep.end - sweep.start) * share guard stepped else { return angle } return SongAmpFaceKnobs.tickAngles.last { $0 <= angle + 1e-9 } ?? sweep.start } /// Where a turn of `degrees` from `elapsed` seeks to: the knob's sweep /// is the whole song, held to it. public static func turned(_ elapsed: TimeInterval, by degrees: Double, of length: TimeInterval) -> TimeInterval { let sweep = SongAmpFaceKnobs.sweep return min(length, max(0, elapsed + degrees / (sweep.end - sweep.start) * length)) } /// Whether the record turns: while it plays, never under Reduce Motion. public static func turning(_ play: TrackPlay, reduceMotion: Bool) -> Bool { !reduceMotion && state(play) == .playing } /// The record's angle, in degrees: 33⅓ turns a minute of the time /// played, standing where it stopped when paused; upright under Reduce /// Motion. public static func record(_ elapsed: TimeInterval, reduceMotion: Bool) -> Double { guard !reduceMotion, elapsed.isFinite else { return 0 } return (max(0, elapsed) * SongAmpFaceKnobs.turnRate).truncatingRemainder(dividingBy: 360) } /// The volume knob's angle: the card's `volume`, nought to one, across /// its sweep; at seven o'clock, its start, where the card carries none. public static func volume(_ card: DeckCard) -> Double { let sweep = SongAmpFaceKnobs.volumeSweep guard let level = card.fields["volume"]?.number, level.isFinite else { return sweep.start } return sweep.start + (sweep.end - sweep.start) * min(1, max(0, level)) } /// The strip's words: the artist and the album joined as the cards /// join words, in capitals. public static func byline(_ card: DeckCard) -> String? { HifiDeck.byline(card)?.uppercased() } /// The blank label's lines under the hole: the artist, then the album. public static func labelLines(_ card: DeckCard) -> [String] { [card.text("artist"), card.text("album")].compactMap { $0 } } } public struct SongAmpFace: View { let card: DeckCard /// The playing album's cover; nil lays the label's and the sleeve's /// typed blanks. var cover: Cover? var play: TrackPlay = .still var toggle: (() -> Void)? var seek: (TimeInterval) -> Void = { _ in } /// Where a turn of the knob has the song, until the finger lifts. @State private var scrubbing: TimeInterval? @Environment(\.accessibilityReduceMotion) private var reduceMotion public init( card: DeckCard, cover: Cover?, play: TrackPlay = .still, toggle: (() -> Void)? = nil, seek: @escaping (TimeInterval) -> Void = { _ in } ) { self.card = card self.cover = cover self.play = play self.toggle = toggle self.seek = seek } public var body: some View { let knobs = SongAmpFaceKnobs.self let state = AmpHead.state(play) let length = HifiDeck.length(play, card) let elapsed = play.held ? (scrubbing ?? play.elapsed) : 0 GeometryReader { room in let width = min(room.size.width, knobs.widest, room.size.height * knobs.whole.width / knobs.whole.height) let s = width / knobs.whole.width ZStack(alignment: .topLeading) { AmpPainted(name: "amp-shadow").placed(knobs.shadow, s) record(elapsed: play.held ? play.elapsed : 0, s: s) AmpPainted(name: "amp-grille").placed(knobs.grille, s) grilleParts(s) AmpPainted(name: "amp-panel").placed(knobs.panel, s) panelCentre(s) AmpPainted(name: "amp-frame").placed(CGRect(origin: .zero, size: knobs.box), s) AmpPainted(name: "amp-ticks").placed(knobs.ticks, s) knob(elapsed: elapsed, length: length, s: s) smallKnobs(s) jewel(state: state, s: s) words(s) times(elapsed: elapsed, length: length, s: s) leaningSleeve(s) } .frame(width: knobs.box.width * s, height: knobs.box.height * s, alignment: .topLeading) .offset(y: -knobs.whole.minY * s) .frame(width: width, height: knobs.whole.height * s, alignment: .topLeading) .frame(width: room.size.width, height: room.size.height) .accessibilityElement(children: .contain) .accessibilityIdentifier("song-amp") } } // MARK: The record behind the cloth /// The record and its label, or the cover cropped round where its label /// is, turned by the time played, seen only through the grille. private func record(elapsed: TimeInterval, s: CGFloat) -> some View { let knobs = SongAmpFaceKnobs.self let side = knobs.record.width * s let label = knobs.label.width * s return ZStack { Group { if let cover { cover .frame(width: label, height: label) .clipShape(Circle()) Circle().fill(Color.black.opacity(knobs.veil)).frame(width: label, height: label) } else { AmpPainted(name: "label-blank").frame(width: label, height: label) labelWords(s) } } Circle() .fill(MusicMaterial.window.colour) .frame(width: knobs.hole * knobs.label.width * 2 * s, height: knobs.hole * knobs.label.width * 2 * s) AmpPainted(name: "record") } .frame(width: side, height: side) .rotationEffect(.degrees(AmpHead.record(elapsed, reduceMotion: reduceMotion))) .offset(x: (knobs.record.minX - knobs.clip.minX) * s, y: (knobs.record.minY - knobs.clip.minY) * s) .frame(width: knobs.clip.width * s, height: knobs.clip.height * s, alignment: .topLeading) .clipped() .allowsHitTesting(false) .accessibilityHidden(true) .offset(x: knobs.clip.minX * s, y: knobs.clip.minY * s) } /// The blank label's words, about its centre: the name in the hand /// above the hole, the artist and the album typed below. private func labelWords(_ s: CGFloat) -> some View { let knobs = SongAmpFaceKnobs.self let origin = CGPoint(x: knobs.record.minX, y: knobs.record.minY) let inRecord = { (rect: CGRect) in rect.offsetBy(dx: -origin.x, dy: -origin.y) } let lines = AmpHead.labelLines(card) return ZStack(alignment: .topLeading) { if let title = card.text("title") { Text(title) .font(CottonFonts.brand(CottonFonts.signatureFace, knobs.labelTitleSize * s, fallback: .regular)) .lineLimit(1) .minimumScaleFactor(0.5) .placed(inRecord(knobs.labelTitle), s) } ForEach(Array(zip(lines, knobs.labelLines)), id: \.1.minY) { line, rect in Text(line) .font(CottonFonts.brand(CottonFonts.typeFace, knobs.labelLineSize * s, fallback: .regular)) .lineLimit(1) .minimumScaleFactor(0.6) .placed(inRecord(rect), s) } } .foregroundStyle(MusicMaterial.labelInk.colour) .frame(width: knobs.record.width * s, height: knobs.record.height * s, alignment: .topLeading) } /// The grille's thirds: a tap on the left the previous song, on the /// right the next — the shell's acts. private func grilleParts(_ s: CGFloat) -> some View { let knobs = SongAmpFaceKnobs.self let third = CGRect(x: knobs.grille.minX, y: knobs.grille.minY, width: knobs.grille.width / 3, height: knobs.grille.height) return ZStack(alignment: .topLeading) { Color.clear .contentShape(Rectangle()) .frame(width: third.width * s, height: third.height * s) .accessibilityElement() .accessibilityLabel(ShellLines.line("faces", "hifi.previous")) .accessibilityAddTraits(.isButton) .accessibilityIdentifier("amp-previous") .facePart(.previous) .at(third, s) Color.clear .contentShape(Rectangle()) .frame(width: third.width * s, height: third.height * s) .accessibilityElement() .accessibilityLabel(ShellLines.line("faces", "hifi.next")) .accessibilityAddTraits(.isButton) .accessibilityIdentifier("amp-next") .facePart(.next) .at(third.offsetBy(dx: third.width * 2, dy: 0), s) } } /// The panel's centre, under the big knob: a tap plays or pauses. private func panelCentre(_ s: CGFloat) -> some View { let rect = SongAmpFaceKnobs.panelCentre return Color.clear .contentShape(Rectangle()) .frame(width: rect.width * s, height: rect.height * s) .onTapGesture { toggle?() } .accessibilityHidden(true) .facePart(.play) .at(rect, s) } // MARK: The panel's words /// The song's name in the hand on the top band, "ARTIST · ALBUM" in /// cream on the black strip. private func words(_ s: CGFloat) -> some View { let knobs = SongAmpFaceKnobs.self return ZStack(alignment: .topLeading) { if let title = card.text("title") { AmpTitle(words: title, s: s) .foregroundStyle(MusicMaterial.print.colour) .frame(width: knobs.titleBand.width * s, height: knobs.titleBand.height * s) .accessibilityElement() .accessibilityLabel(title) .accessibilityAddTraits(.isHeader) .accessibilityIdentifier("deck-title") .facePart(.title) .at(knobs.titleBand, s) } if let byline = AmpHead.byline(card) { Text(byline) .font(CottonFonts.serif(knobs.bylineSize * s)) .tracking(knobs.bylineTracking * knobs.bylineSize * s) .lineLimit(1) .minimumScaleFactor(0.6) .foregroundStyle(MusicMaterial.engraving.colour) .frame(width: knobs.byline.width * s, height: knobs.byline.height * s) .accessibilityIdentifier("face-byline") .facePart(.subtitle) .at(knobs.byline, s) } } } // MARK: The knobs, the times and the jewel /// The big brass knob at the share played, turned round its centre to /// seek: the knob and the times follow the turn, the player moves when /// the finger lifts. private func knob(elapsed: TimeInterval, length: TimeInterval, s: CGFloat) -> some View { let knobs = SongAmpFaceKnobs.self let turns = play.held && length > 0 return AmpKnob( angle: AmpHead.knob(elapsed, of: length, stepped: reduceMotion), side: knobs.bigKnob.width * s, turn: { degrees in guard turns else { return } scrubbing = AmpHead.turned(scrubbing ?? play.elapsed, by: degrees, of: length) }, lifted: { if let scrubbing { seek(scrubbing) } scrubbing = nil }) .accessibilityElement(children: .ignore) .accessibilityLabel(ShellLines.line("faces", "hifi.position")) .accessibilityValue(turns ? TrackClock.said(elapsed) : "") .accessibilityAdjustableAction { direction in guard turns else { return } let by = (knobs.sweep.end - knobs.sweep.start) / 20 seek(AmpHead.turned(play.elapsed, by: direction == .increment ? by : -by, of: length)) } .accessibilityIdentifier("amp-knob") .facePart(.scrub) .at(knobs.bigKnob, s) } /// The two small knobs, volume at the card's level and tone standing, /// their words typed under them. private func smallKnobs(_ s: CGFloat) -> some View { let knobs = SongAmpFaceKnobs.self let angles = [AmpHead.volume(card), knobs.tone] let names = ["amp.volume", "amp.tone"] return ZStack(alignment: .topLeading) { ForEach(0..<2, id: \.self) { at in AmpPainted(name: "amp-knob-small") .frame(width: knobs.smallKnobs[at].width * s, height: knobs.smallKnobs[at].height * s) .rotationEffect(.degrees(angles[at])) .at(knobs.smallKnobs[at], s) let point = knobs.smallWords[at] Text(ShellLines.line("faces", names[at])) .font(CottonFonts.brand(CottonFonts.typeFace, knobs.smallWordsSize * s, fallback: .regular)) .lineLimit(1) .fixedSize() .foregroundStyle(MusicMaterial.print.colour) .placed(CGRect( x: point.x - knobs.smallWordsBox.width / 2, y: point.y - knobs.smallWordsBox.height / 2, width: knobs.smallWordsBox.width, height: knobs.smallWordsBox.height), s) } } .allowsHitTesting(false) .accessibilityHidden(true) } /// The time played at the arc's top, the time left right of it, and /// nought and the song's length at the arc's ends. private func times(elapsed: TimeInterval, length: TimeInterval, s: CGFloat) -> some View { let knobs = SongAmpFaceKnobs.self let about = { (point: CGPoint) in CGRect(x: point.x - knobs.ends.width / 2, y: point.y - knobs.ends.height / 2, width: knobs.ends.width, height: knobs.ends.height) } return ZStack(alignment: .topLeading) { Text(TrackClock.said(elapsed)) .font(CottonFonts.serif(knobs.elapsedSize * s).italic()) .accessibilityIdentifier("amp-elapsed") .placed(knobs.elapsed, s) if length > 0 { // Left from the whole seconds played, so the two clocks // always add up to the song's length. Text(TrackClock.left(elapsed.rounded(.down), of: length)) .accessibilityIdentifier("amp-remaining") .placed(knobs.remaining, s) Text(TrackClock.said(0)) .placed(about(knobs.start), s) Text(TrackClock.said(length)) .accessibilityIdentifier("amp-length") .placed(about(knobs.end), s) } } .font(CottonFonts.serif(knobs.timeSize * s).italic()) .monospacedDigit() .lineLimit(1) .foregroundStyle(MusicMaterial.print.colour) .allowsHitTesting(false) .accessibilityHidden(true) } /// The orange jewel: lit while it plays, dark otherwise; a tap plays or /// pauses. private func jewel(state: HifiDeck.State, s: CGFloat) -> some View { let knobs = SongAmpFaceKnobs.self let lit = state == .playing let touch = CGRect(x: knobs.jewel.midX - knobs.jewelTouch, y: knobs.jewel.midY - knobs.jewelTouch, width: knobs.jewelTouch * 2, height: knobs.jewelTouch * 2) return ZStack(alignment: .topLeading) { AmpPainted(name: lit ? "amp-jewel-on" : "amp-jewel-off").placed(knobs.jewel, s) Color.clear .contentShape(Circle()) .frame(width: touch.width * s, height: touch.height * s) .onTapGesture { toggle?() } .accessibilityElement(children: .ignore) .accessibilityLabel(ShellLines.line("faces", lit ? "media.pause" : "media.play")) .accessibilityValue(card.text("title") ?? "") .accessibilityAddTraits(.isButton) .accessibilityAction { toggle?() } .accessibilityIdentifier("amp-jewel") .facePart(.play) .at(touch, s) } } // MARK: The sleeve /// The playing album's sleeve, leaning against the wall upper left: its /// shadow, its cover (else the typeset blank) and its frame. private func leaningSleeve(_ s: CGFloat) -> some View { let knobs = SongAmpFaceKnobs.self let k = knobs.sleeve.width / knobs.sleevePainted let inSleeve = { (rect: CGRect) in CGRect(x: rect.minX * k, y: rect.minY * k, width: rect.width * k, height: rect.height * k) } return ZStack(alignment: .topLeading) { AmpPainted(name: "sleeve-shadow").placed(inSleeve(knobs.sleeveShadow), s) Group { if let cover { cover.frame(width: knobs.cover.width * k * s, height: knobs.cover.height * k * s).clipped() } else { blank(k: k, s: s) } } .frame(width: knobs.cover.width * k * s, height: knobs.cover.height * k * s) .at(inSleeve(knobs.cover), s) AmpPainted(name: "sleeve-front").placed(CGRect(x: 0, y: 0, width: knobs.sleeve.width, height: knobs.sleeve.height), s) } .frame(width: knobs.sleeve.width * s, height: knobs.sleeve.height * s, alignment: .topLeading) .rotationEffect(.degrees(knobs.lean), anchor: .bottom) .accessibilityElement() .accessibilityLabel(MusicWhole.joined([card.text("album"), card.text("artist")]) ?? "") .accessibilityIdentifier("amp-sleeve") .facePart(.picture) .at(knobs.sleeve, s) } /// The sleeve's blank stock, the album and its artist typeset on it. private func blank(k: CGFloat, s: CGFloat) -> some View { let knobs = SongAmpFaceKnobs.self let words = knobs.blankWords return ZStack(alignment: .topLeading) { AmpPainted(name: "sleeve-blank") VStack(spacing: 18 * k * s) { if let album = card.text("album") { Text(album) .font(CottonFonts.serif(knobs.blankTitleSize * k * s)) .multilineTextAlignment(.center) .lineLimit(3) .minimumScaleFactor(0.5) } if let artist = card.text("artist") { Text(artist) .font(CottonFonts.serif(knobs.blankArtistSize * k * s)) .italic() .lineLimit(1) .minimumScaleFactor(0.5) } } .foregroundStyle(MusicMaterial.engraving.colour) .frame(width: words.width * k * s, height: words.height * k * s) .offset(x: words.minX * k * s, y: words.minY * k * s) } } } /// The song's name in the hand: one line at its size, else a step smaller, /// else two lines smaller still, shrinking before it wraps. private struct AmpTitle: View { let words: String let s: CGFloat var body: some View { let knobs = SongAmpFaceKnobs.self ViewThatFits(in: .horizontal) { ForEach(knobs.titleSteps, id: \.self) { step in line(knobs.titleSize * step).lineLimit(1).fixedSize() } line(knobs.titleSize * knobs.titleTwoLines) .lineLimit(2) .minimumScaleFactor(0.7) .multilineTextAlignment(.center) } } private func line(_ size: CGFloat) -> Text { Text(words).font(CottonFonts.brand(CottonFonts.signatureFace, size * s, fallback: .regular)) } } /// The big brass knob turned to `angle` round its centre; a finger turning /// round the centre turns it by the angle swept. private struct AmpKnob: View { let angle: Double let side: CGFloat let turn: (_ degrees: Double) -> Void let lifted: () -> Void @State private var last: Double? var body: some View { let centre = CGPoint(x: side / 2, y: side / 2) AmpPainted(name: "amp-knob-big") .frame(width: side, height: side) .rotationEffect(.degrees(angle)) .contentShape(Circle()) .gesture( DragGesture(minimumDistance: 0) .onChanged { touch in let now = HifiDeck.angle(of: touch.location, round: centre) if let last { turn(HifiDeck.turn(from: last, to: now)) } last = now } .onEnded { _ in last = nil lifted() }) } } /// One of the amp's paintings, stretched to its frame; nothing where the /// build carries no pictures. private struct AmpPainted: View { let name: String var body: some View { if let image = CottonMedia.image(name) { image.resizable().interpolation(.high).accessibilityHidden(true) } } } private extension View { /// This view laid at `rect` of the amp box, in its pixels, scaled by `s`. func placed(_ rect: CGRect, _ s: CGFloat, alignment: Alignment = .center) -> some View { frame(width: rect.width * s, height: rect.height * s, alignment: alignment) .offset(x: rect.minX * s, y: rect.minY * s) } /// This view moved to `rect`'s corner of the amp box: last, after a part /// is tagged (`facePart`), so the region the deck reads for it is where /// it is drawn. func at(_ rect: CGRect, _ s: CGFloat) -> some View { offset(x: rect.minX * s, y: rect.minY * s) } } /// The amp face, and the songs it is reviewed playing. Under the player the /// app installs (`faceTrackPlayer`), else paused; each specimen names the /// player's word it is reviewed under (`Specimen.play`). public enum SongAmpFaceCatalogue { public static let stock: FaceStock = .own public static let ground: FaceGround = .tolex public static let face = Face(id: "song.amp", specimens: [ Specimen("playing", harbour, picture: "poster-ferry", play: TrackPlay(held: true, playing: true, elapsed: 134, duration: 242)), Specimen("paused", harbour, picture: "poster-ferry", play: TrackPlay(held: true, playing: false, elapsed: 134, duration: 242)), Specimen("no cover", harbour, play: TrackPlay(held: true, playing: true, elapsed: 61, duration: 242)), Specimen("long title", lanterns, play: TrackPlay(held: true, playing: true, elapsed: 312, duration: 403)), ]) { card, picture, _ in TrackPlaying(card: card) { player in SongAmpFace(card: card, cover: picture, play: player.play, toggle: player.toggle, seek: player.seek) } } /// An invented song off an invented album, 4:02 long, the device's /// volume at seven tenths. public static let harbour = DeckCard(face: .songAmp, fields: [ "title": .text("Harbour Lights"), "artist": .text("The Low Tide"), "album": .text("Night Ferry"), "duration": .number(242), "volume": .number(0.7), ]) /// A long song name and a long album, no volume carried. public static let lanterns = DeckCard(face: .songAmp, fields: [ "title": .text("The Slow Train Home Through Sixteen Lanterns"), "artist": .text("Mara Vance"), "album": .text("Sixteen Lanterns and the Blue Hour Sessions"), "duration": .number(403), ]) }