// 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.importCottonPaperimportCottonValuesimportSwiftUIenumSongAmpFaceKnobs {// 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.staticlet box = CGSize(width: 1135, height: 1090)staticlet widest: CGFloat = 340/// The whole drawing, the sleeve above the cabinet and the shadow under/// it: what the face fits to its room.staticlet whole = CGRect(x: 0, y: -420, width: 1135, height: 1602)staticlet shadow = CGRect(x: -80, y: -68, width: 1295, height: 1250)staticlet panel = CGRect(x: 57, y: 72, width: 1020, height: 505)staticlet 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.staticlet record = CGRect(x: 115, y: 430, width: 900, height: 900)staticlet label = CGRect(x: 403, y: 718, width: 324, height: 324)staticlet clip = CGRect(x: 70, y: 650, width: 990, height: 365)staticlet hole: CGFloat = 29.0 / 900/// The record's turn while it plays: 33⅓ turns a minute, in degrees a/// second.staticlet 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.staticlet 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.staticlet labelTitle = CGRect(x: 450, y: 770, width: 230, height: 80)staticlet labelTitleSize: CGFloat = 44staticlet labelLines = [CGRect(x: 470, y: 912, width: 190, height: 30), CGRect(x: 480, y: 944, width: 170, height: 30)]staticlet 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.staticlet title = CGRect(x: 115, y: 100, width: 905, height: 70)staticlet titleBand = CGRect(x: 115, y: 82, width: 905, height: 100)staticlet titleSize: CGFloat = 86staticlet titleSteps: [CGFloat] = [1, 0.84, 0.7]staticlet titleTwoLines: CGFloat = 0.5staticlet byline = CGRect(x: 120, y: 190, width: 895, height: 55)staticlet bylineSize: CGFloat = 26staticlet 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.staticlet bigKnob = CGRect(x: 442, y: 325, width: 250, height: 250)staticlet bigKnobCentre = CGPoint(x: 567, y: 450)staticlet ticks = CGRect(x: 357, y: 240, width: 420, height: 210)staticlet sweep = (start: -90.0, end: 90.0)staticlet 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).staticlet elapsed = CGRect(x: 502, y: 267, width: 130, height: 45)staticlet remaining = CGRect(x: 705, y: 290, width: 140, height: 40)staticlet start = CGPoint(x: 335, y: 490)staticlet end = CGPoint(x: 800, y: 490)staticlet ends = CGSize(width: 140, height: 44)staticlet elapsedSize: CGFloat = 36staticlet 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.staticlet smallKnobs = [CGRect(x: 140, y: 375, width: 120, height: 120), CGRect(x: 870, y: 375, width: 120, height: 120)]staticlet smallWords = [CGPoint(x: 200, y: 510), CGPoint(x: 930, y: 510)]staticlet smallWordsBox = CGSize(width: 160, height: 30)staticlet smallWordsSize: CGFloat = 20staticlet volumeSweep = (start: -150.0, end: 150.0)staticlet tone: Double = 30// THE JEWEL, lit and dark painted to one bezel centre in one box.staticlet jewel = CGRect(x: 925, y: 265, width: 70, height: 70)/// The jewel's touch reaches this far round its centre.staticlet 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.staticlet 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.staticlet sleevePainted: CGFloat = 1130staticlet cover = CGRect(x: 82, y: 84, width: 964, height: 964)staticlet sleeve = CGRect(x: 47, y: -389, width: 387, height: 387)staticlet sleeveShadow = CGRect(x: -80, y: -80, width: 1290, height: 1290)staticlet lean: Double = -4staticlet blankWords = CGRect(x: 170, y: 250, width: 790, height: 520)staticlet blankTitleSize: CGFloat = 104staticlet blankArtistSize: CGFloat = 64}/// What the amp reads off its card and its player.publicenumAmpHead {/// The amp's standing: as the hi-fi's, by the player's word alone.publicstaticfunc 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.publicstaticfunc knob(_ elapsed: TimeInterval, of length: TimeInterval, stepped: Bool = false) -> Double {let sweep = SongAmpFaceKnobs.sweeplet share = length > 0 && elapsed.isFinite ? min(1, max(0, elapsed / length)) : 0let angle = sweep.start + (sweep.end - sweep.start) * shareguard stepped else { return angle }returnSongAmpFaceKnobs.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.publicstaticfunc turned(_ elapsed: TimeInterval, by degrees: Double, of length: TimeInterval) -> TimeInterval {let sweep = SongAmpFaceKnobs.sweepreturn min(length, max(0, elapsed + degrees / (sweep.end - sweep.start) * length)) }/// Whether the record turns: while it plays, never under Reduce Motion.publicstaticfunc 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.publicstaticfunc record(_ elapsed: TimeInterval, reduceMotion: Bool) -> Double {guard !reduceMotion, elapsed.isFinite else { return0 }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.publicstaticfunc volume(_ card: DeckCard) -> Double {let sweep = SongAmpFaceKnobs.volumeSweepguardlet 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.publicstaticfunc byline(_ card: DeckCard) -> String? {HifiDeck.byline(card)?.uppercased() }/// The blank label's lines under the hole: the artist, then the album.publicstaticfunc labelLines(_ card: DeckCard) -> [String] { [card.text("artist"), card.text("album")].compactMap { $0 } }}publicstructSongAmpFace<Cover: View>: 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 = .stillvar toggle: (() -> Void)?var seek: (TimeInterval) -> Void = { _ in }/// Where a turn of the knob has the song, until the finger lifts. @State privatevar scrubbing: TimeInterval? @Environment(\.accessibilityReduceMotion) privatevar reduceMotionpublicinit( card: DeckCard, cover: Cover?, play: TrackPlay = .still, toggle: (() -> Void)? = nil, seek: @escaping (TimeInterval) -> Void = { _ in } ) {self.card = cardself.cover = coverself.play = playself.toggle = toggleself.seek = seek }publicvar body: someView {let knobs = SongAmpFaceKnobs.selflet state = AmpHead.state(play)let length = HifiDeck.length(play, card)let elapsed = play.held ? (scrubbing ?? play.elapsed) : 0GeometryReader { room inlet 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.privatefunc record(elapsed: TimeInterval, s: CGFloat) -> someView {let knobs = SongAmpFaceKnobs.selflet side = knobs.record.width * slet label = knobs.label.width * sreturn ZStack {Group {iflet 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.privatefunc labelWords(_ s: CGFloat) -> someView {let knobs = SongAmpFaceKnobs.selflet 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) {iflet 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 inText(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.privatefunc grilleParts(_ s: CGFloat) -> someView {let knobs = SongAmpFaceKnobs.selflet 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.privatefunc panelCentre(_ s: CGFloat) -> someView {let rect = SongAmpFaceKnobs.panelCentrereturnColor.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.privatefunc words(_ s: CGFloat) -> someView {let knobs = SongAmpFaceKnobs.selfreturn ZStack(alignment: .topLeading) {iflet 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) }iflet 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.privatefunc knob(elapsed: TimeInterval, length: TimeInterval, s: CGFloat) -> someView {let knobs = SongAmpFaceKnobs.selflet turns = play.held && length > 0returnAmpKnob( angle: AmpHead.knob(elapsed, of: length, stepped: reduceMotion), side: knobs.bigKnob.width * s, turn: { degrees inguard turns else { return } scrubbing = AmpHead.turned(scrubbing ?? play.elapsed, by: degrees, of: length) }, lifted: {iflet scrubbing { seek(scrubbing) } scrubbing = nil }) .accessibilityElement(children: .ignore) .accessibilityLabel(ShellLines.line("faces", "hifi.position")) .accessibilityValue(turns ? TrackClock.said(elapsed) : "") .accessibilityAdjustableAction { direction inguard 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.privatefunc smallKnobs(_ s: CGFloat) -> someView {let knobs = SongAmpFaceKnobs.selflet angles = [AmpHead.volume(card), knobs.tone]let names = ["amp.volume", "amp.tone"]return ZStack(alignment: .topLeading) {ForEach(0..<2, id: \.self) { at inAmpPainted(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.privatefunc times(elapsed: TimeInterval, length: TimeInterval, s: CGFloat) -> someView {let knobs = SongAmpFaceKnobs.selflet 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.privatefunc jewel(state: HifiDeck.State, s: CGFloat) -> someView {let knobs = SongAmpFaceKnobs.selflet lit = state == .playinglet 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.privatefunc leaningSleeve(_ s: CGFloat) -> someView {let knobs = SongAmpFaceKnobs.selflet k = knobs.sleeve.width / knobs.sleevePaintedlet 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 {iflet 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.privatefunc blank(k: CGFloat, s: CGFloat) -> someView {let knobs = SongAmpFaceKnobs.selflet words = knobs.blankWordsreturn ZStack(alignment: .topLeading) {AmpPainted(name: "sleeve-blank") VStack(spacing: 18 * k * s) {iflet album = card.text("album") {Text(album) .font(CottonFonts.serif(knobs.blankTitleSize * k * s)) .multilineTextAlignment(.center) .lineLimit(3) .minimumScaleFactor(0.5) }iflet 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.privatestructAmpTitle: View {let words: Stringlet s: CGFloatvar body: someView {let knobs = SongAmpFaceKnobs.selfViewThatFits(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) } }privatefunc 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.privatestructAmpKnob: View {let angle: Doublelet side: CGFloatlet turn: (_ degrees: Double) -> Voidlet lifted: () -> Void @State privatevar last: Double?var body: someView {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 inlet now = HifiDeck.angle(of: touch.location, round: centre)iflet 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.privatestructAmpPainted: View {let name: Stringvar body: someView {iflet image = CottonMedia.image(name) { image.resizable().interpolation(.high).accessibilityHidden(true) } }}privateextensionView {/// This view laid at `rect` of the amp box, in its pixels, scaled by `s`.func placed(_ rect: CGRect, _ s: CGFloat, alignment: Alignment = .center) -> someView { 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) -> someView { 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`).publicenumSongAmpFaceCatalogue {publicstaticlet stock: FaceStock = .ownpublicstaticlet ground: FaceGround = .tolexpublicstaticlet 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, _ inTrackPlaying(card: card) { player inSongAmpFace(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.publicstaticlet 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.publicstaticlet 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), ])}