// The SONG PLAYING as a BLACK HI-FI DECK (the owner's go, 4 Nov 2026; the dark// room's pictures `listening-hifi`, `listening-hifi-paused`): the player face// of Music's Listening deck, drawn for the playing song's card, a bare object// standing on the music's black tolex (`FaceGround.tolex`) with no paper and// no rule of the deck's. Two cream level meters behind the plate's windows,// their needles live; the song's name in spaced capitals and "artist ·// album" under it in cream; the red jewel lit while it plays; the time played// above the brass knob, the knob turned by it from nought to the song's end// round its tick ring, "0:00" and the song's length at the ring's ends and// the time left below. The playing album's sleeve leans against the wall// above the deck, upper left, its cover in it, else its typeset blank.//// PAINTED (`Media.xcassets`, `scripts/import-music-materials.py`): the plate,// its shadow, the meter card (laid twice), the needle (laid twice), the knob,// its tick ring, the jewel lit and dark, and the sleeve's frame, blank and// shadow are pictures cut from wordless paintings, each laid where the// materials' `layout.json` places it in the deck's 1135 x 1015 box, scaled by// the drawn width over 1135 — save the knob and its ring, drawn smaller than// the layout's about the same centre, as the picture has them: at the// layout's size the ring's top runs through the song's words and the jewel.// The face draws live only what the data decides: every word and figure, the// needles' and the knob's angles, and which jewel is laid.//// THE PLAYER (`faceTrackPlayer`) says how far into the song it is and how// loud it sounds (`TrackPlay.level`, each channel nought to one): PLAYING the// jewel is lit and each needle stands at its channel's level, nought to one// read as −40 to +3 dB on the painted scale (`SongHifiFaceKnobs.marks`),// eased between the player's readings; PAUSED, or holding none of the song,// the jewel is dark and the needles rest at −40. Reduce Motion steps them.// Nothing here keeps time.//// THE CONTROLS, tagged (`facePart`): the 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 is `play`, a tap plays or// pauses; the meters' plate is `previous` left of its centre and `next`// right of it, which the shell runs; the song's name is `title`, the sleeve// `picture`.//// Every word is the card's (`title`, `artist`, `album`, its length in seconds// `duration`), the player's or a line.importCottonPaperimportCottonValuesimportSwiftUIenumSongHifiFaceKnobs {// THE DECK BOX every placement is in, in the paintings' pixels// (`layout.json`): 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: 1015)staticlet widest: CGFloat = 340/// The whole drawing, the sleeve above the deck and the shadow under/// it: what the face fits to its room.staticlet whole = CGRect(x: 0, y: -380, width: 1135, height: 1475)staticlet shadow = CGRect(x: -80, y: -80, width: 1295, height: 1175)staticlet meterInserts = [CGRect(x: 71, y: 75, width: 471, height: 202), CGRect(x: 590, y: 75, width: 471, height: 202)]staticlet meterWindows = [CGRect(x: 75, y: 80, width: 463, height: 190), CGRect(x: 594, y: 80, width: 463, height: 190)]// THE METERS: each needle's pivot, its painted pivot and the length// from it to its tip; and the painted scale's marks, measured off// `hifi-meter` as the layout lays it — each figure's decibels, the// angle (clockwise from upright, round the pivot) of its long tick and// how far from the pivot that tick ends. Between marks the needle's// angle runs straight.staticlet pivots = [CGPoint(x: 307, y: 326), CGPoint(x: 826, y: 326)]staticlet needleSize = CGSize(width: 70, height: 375)staticlet needlePivot = CGPoint(x: 35, y: 343)staticlet needleTip: CGFloat = 6staticlet needleLength: CGFloat = 231staticlet marks: [(decibels: Double, angle: Double, reach: CGFloat)] = [ (-40, -55.5, 249), (-30, -34.6, 231), (-20, -21.9, 230), (-10, 0, 224), (0, 21.3, 229), (3, 48.6, 252), ]/// The level nought reads as the lowest mark, one as the highest.staticvar quietest: Double { marks[0].decibels }staticvar loudest: Double { marks[marks.count - 1].decibels }/// A figure stands this far past its tick's end, never higher than/// `figureCeiling` under its window's top.staticlet figureLift: CGFloat = 4staticlet figureCeiling: CGFloat = 1staticlet figureSize: CGFloat = 19/// The width a figure, and a letter, is centred in.staticlet figureBox: CGFloat = 80staticlet letterBox: CGFloat = 120/// "dB" and the channel's letter, centred under the pivot's line.staticlet decibelsCentre: CGFloat = 186staticlet channelCentre: CGFloat = 234staticlet decibelsSize: CGFloat = 22staticlet channelSize: CGFloat = 30/// The needles ease between the player's readings, which come some/// twenty times a second.staticlet ease: Double = 1.0 / 20// THE PLATE'S WORDS: the song's name over "artist · album", stood on// the block's foot; the name one line at its size, else a size or two// smaller, else two lines smaller still.staticlet words = CGRect(x: 160, y: 280, width: 815, height: 122)staticlet titleSize: CGFloat = 50staticlet titleSteps: [CGFloat] = [1, 0.86, 0.74]staticlet titleTwoLines: CGFloat = 0.6staticlet titleTracking: CGFloat = 0.16staticlet bylineSize: CGFloat = 30staticlet bylineTracking: CGFloat = 0.08staticlet wordsGap: CGFloat = 6// THE JEWEL: its centre and the lit stone's width; each painting's// stone (its opaque core, in its own pixels), so the stone is the same// size lit and dark and the lit halo spills round it.staticlet jewelCentre = CGPoint(x: 567, y: 422)staticlet jewelStone: CGFloat = 42staticlet jewelOn = (size: CGSize(width: 193, height: 194), stone: CGRect(x: 25, y: 30, width: 143, height: 141))staticlet jewelOff = (size: CGSize(width: 161, height: 167), stone: CGRect(x: 13, y: 10, width: 138, height: 147))/// The jewel's touch reaches this far round its centre.staticlet jewelTouch: CGFloat = 70// THE KNOB AND ITS RING, about one centre: the knob's sweep, nought to// the song's end, in degrees from upright; the ring's ends.staticlet knobCentre = CGPoint(x: 567, y: 730)staticlet knob: CGFloat = 376staticlet ticks: CGFloat = 518/// The ring's painting's pixels, and how far from its centre its ends'/// ticks reach in them.staticlet ticksPainted: CGFloat = 700staticlet ringEndReach: CGFloat = 326staticlet sweep = (start: -135.0, end: 135.0)/// The times: played above the ring's top, left under the knob, and/// nought and the length beside the ring's ends, `endGap` clear of them.staticlet elapsed = CGRect(x: 467, y: 440, width: 200, height: 40)staticlet remaining = CGRect(x: 467, y: 940, width: 200, height: 44)staticlet endGap: CGFloat = 14staticlet endDrop: CGFloat = 6staticlet ends = CGSize(width: 180, height: 44)staticlet timeSize: CGFloat = 32// THE SLEEVE leaning above the deck, upper left (`coverAboveRect`): its// painted box, its cover's aperture and its shadow in that box, how far// it leans and the blank's typeset words.staticlet sleeve = CGRect(x: 140, y: -340, width: 360, height: 360)staticlet sleevePainted: CGFloat = 1130staticlet cover = CGRect(x: 82, y: 84, width: 964, height: 964)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/// The meters' plate, the band above the song's name, `previous` left/// of the deck's centre and `next` right of it.staticlet metersPlate = CGRect(x: 0, y: 0, width: 1135, height: 290)}/// What the hi-fi reads off its card and its player.publicenumHifiDeck {/// How the deck stands.publicenumState: Equatable, Sendable {/// It plays the song: the jewel lit, the needles at the levels.case playing/// It holds the song paused, or holds none of it: the jewel dark,/// the needles at rest.case paused }publicstaticfunc state(_ play: TrackPlay) -> State { play.held && (play.playing || play.loading) ? .playing : .paused }/// The song's length: the player's where it knows one, else the card's.publicstaticfunc length(_ play: TrackPlay, _ card: DeckCard) -> TimeInterval { play.held && play.duration > 0 ? play.duration : max(0, card.fields["duration"]?.number ?? 0) }/// The knob's angle, in degrees clockwise from upright: from its start/// at nought to its end at the song's length.publicstaticfunc knob(_ elapsed: TimeInterval, of length: TimeInterval) -> Double {let sweep = SongHifiFaceKnobs.sweeplet share = length > 0 && elapsed.isFinite ? min(1, max(0, elapsed / length)) : 0return sweep.start + (sweep.end - sweep.start) * share }/// The decibels a level of nought to one reads on the painted scale.publicstaticfunc decibels(_ level: Double) -> Double {let knobs = SongHifiFaceKnobs.selfreturn knobs.quietest + (knobs.loudest - knobs.quietest) * min(1, max(0, level.isFinite ? level : 0)) }/// The needle's angle for `decibels`, in degrees clockwise from/// upright: straight between the painted marks either side.publicstaticfunc needle(_ decibels: Double) -> Double {let marks = SongHifiFaceKnobs.markslet reading = min(marks[marks.count - 1].decibels, max(marks[0].decibels, decibels))for (low, high) in zip(marks, marks.dropFirst()) where reading <= high.decibels {let share = (reading - low.decibels) / (high.decibels - low.decibels)return low.angle + (high.angle - low.angle) * share }return marks[marks.count - 1].angle }/// Each needle's angle, left then right: at the player's levels while/// it plays, at rest (the lowest mark) otherwise.publicstaticfunc needles(_ play: TrackPlay) -> [Double] {let rest = needle(SongHifiFaceKnobs.quietest)guard state(play) == .playing, let level = play.level else { return [rest, rest] }return [needle(decibels(level.left)), needle(decibels(level.right))] }/// The figure printed over a mark: "−40", "0", "+3".publicstaticfunc figure(_ decibels: Double) -> String {let n = String(Int(abs(decibels).rounded()))if decibels < 0 { returnShellLines.line("faces", "hifi.below", ["n": n]) }if decibels > 0 { returnShellLines.line("faces", "hifi.above", ["n": n]) }return n }/// The line under the song's name: its artist and its album, joined as/// the cards join words.publicstaticfunc byline(_ card: DeckCard) -> String? {MusicWhole.joined([card.text("artist"), card.text("album")]) }/// The angle of `point` round `pivot`, in degrees clockwise from upright.staticfunc angle(of point: CGPoint, round pivot: CGPoint) -> Double { atan2(Double(point.x - pivot.x), Double(pivot.y - point.y)) * 180 / .pi }/// The turn from one angle to the next, the short way round.staticfunc turn(from: Double, to: Double) -> Double {var by = (to - from).truncatingRemainder(dividingBy: 360)if by > 180 { by -= 360 }if by <= -180 { by += 360 }return by }/// 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 = SongHifiFaceKnobs.sweepreturn min(length, max(0, elapsed + degrees / (sweep.end - sweep.start) * length)) }}publicstructSongHifiFace<Cover: View>: View {let card: DeckCard/// The playing album's cover; nil lays the sleeve's typeset blank.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 = SongHifiFaceKnobs.selflet state = HifiDeck.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) {HifiPainted(name: "hifi-shadow").placed(knobs.shadow, s)ForEach(0..<2, id: \.self) { channel inHifiPainted(name: "hifi-meter").placed(knobs.meterInserts[channel], s) meterPrint(channel, s: s) } needles(state: state, s: s)HifiPainted(name: "hifi-plate").placed(CGRect(origin: .zero, size: knobs.box), s) metersPlate(s) words(s)HifiPainted(name: "hifi-ticks").placed(square(knobs.knobCentre, knobs.ticks), s) knob(elapsed: elapsed, length: length, s: s) times(elapsed: elapsed, length: length, s: s) jewel(state: state, 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-hifi") } }privatefunc square(_ centre: CGPoint, _ side: CGFloat) -> CGRect { CGRect(x: centre.x - side / 2, y: centre.y - side / 2, width: side, height: side) }// MARK: The meters/// What is printed on a meter's card: each mark's figure over its tick,/// "dB", and the channel's letter.privatefunc meterPrint(_ channel: Int, s: CGFloat) -> someView {let knobs = SongHifiFaceKnobs.selflet pivot = knobs.pivots[channel]let window = knobs.meterWindows[channel]let ink = MusicMaterial.print.colourreturn ZStack(alignment: .topLeading) {ForEach(knobs.marks.indices, id: \.self) { at inlet mark = knobs.marks[at]let radians = mark.angle * .pi / 180let reach = mark.reach + knobs.figureLift + knobs.figureSize / 2let x = pivot.x + reach * CGFloat(sin(radians))let y = max(window.minY + knobs.figureCeiling + knobs.figureSize / 2, pivot.y - reach * CGFloat(cos(radians)))Text(HifiDeck.figure(mark.decibels)) .font(CottonFonts.serif(knobs.figureSize * s)) .monospacedDigit() .lineLimit(1) .fixedSize() .foregroundStyle(ink) .frame(width: knobs.figureBox * s, height: knobs.figureSize * 1.4 * s) .offset(x: (x - knobs.figureBox / 2) * s, y: (y - knobs.figureSize * 0.7) * s) }Text(ShellLines.line("faces", "hifi.decibels")) .font(CottonFonts.serif(knobs.decibelsSize * s)) .lineLimit(1) .fixedSize() .foregroundStyle(ink) .frame(width: knobs.letterBox * s, height: knobs.decibelsSize * 1.4 * s) .offset(x: (pivot.x - knobs.letterBox / 2) * s, y: (knobs.decibelsCentre - knobs.decibelsSize * 0.7) * s)Text(ShellLines.line("faces", channel == 0 ? "hifi.left" : "hifi.right")) .font(CottonFonts.serif(knobs.channelSize * s)) .lineLimit(1) .fixedSize() .foregroundStyle(ink) .frame(width: knobs.letterBox * s, height: knobs.channelSize * 1.4 * s) .offset(x: (pivot.x - knobs.letterBox / 2) * s, y: (knobs.channelCentre - knobs.channelSize * 0.7) * s) } .accessibilityHidden(true) }/// The two needles at the player's levels, under the plate, whose/// windows show only their upper runs.privatefunc needles(state: HifiDeck.State, s: CGFloat) -> someView {let knobs = SongHifiFaceKnobs.selflet angles = HifiDeck.needles(play)let scale = knobs.needleLength / (knobs.needlePivot.y - knobs.needleTip)let size = CGSize(width: knobs.needleSize.width * scale, height: knobs.needleSize.height * scale)let anchor = UnitPoint(x: knobs.needlePivot.x / knobs.needleSize.width, y: knobs.needlePivot.y / knobs.needleSize.height)return ZStack(alignment: .topLeading) {ForEach(0..<2, id: \.self) { channel inlet pivot = knobs.pivots[channel]HifiPainted(name: "hifi-needle") .frame(width: size.width * s, height: size.height * s) .rotationEffect(.degrees(angles[channel]), anchor: anchor) .animation(reduceMotion ? nil : .easeOut(duration: knobs.ease), value: angles[channel]) .offset(x: (pivot.x - knobs.needlePivot.x * scale) * s, y: (pivot.y - knobs.needlePivot.y * scale) * s) } } .accessibilityHidden(true) }/// The meters' plate: a tap left of the deck's centre the previous/// song, right of it the next — the shell's acts.privatefunc metersPlate(_ s: CGFloat) -> someView {let knobs = SongHifiFaceKnobs.selflet half = CGRect(x: knobs.metersPlate.minX, y: knobs.metersPlate.minY, width: knobs.metersPlate.width / 2, height: knobs.metersPlate.height)return ZStack(alignment: .topLeading) {Color.clear .contentShape(Rectangle()) .frame(width: half.width * s, height: half.height * s) .accessibilityElement() .accessibilityLabel(ShellLines.line("faces", "hifi.previous")) .accessibilityAddTraits(.isButton) .accessibilityIdentifier("hifi-previous") .facePart(.previous) .at(half, s)Color.clear .contentShape(Rectangle()) .frame(width: half.width * s, height: half.height * s) .accessibilityElement() .accessibilityLabel(ShellLines.line("faces", "hifi.next")) .accessibilityAddTraits(.isButton) .accessibilityIdentifier("hifi-next") .facePart(.next) .at(half.offsetBy(dx: half.width, dy: 0), s) } }// MARK: The plate's words/// The song's name in spaced capitals over "artist · album", in cream.privatefunc words(_ s: CGFloat) -> someView {let knobs = SongHifiFaceKnobs.selflet ink = MusicMaterial.engraving.colourreturn VStack(spacing: knobs.wordsGap * s) {iflet title = card.text("title") {HifiTitle(words: title.uppercased(), s: s) .foregroundStyle(ink) .accessibilityElement() .accessibilityLabel(title) .accessibilityAddTraits(.isHeader) .accessibilityIdentifier("deck-title") .facePart(.title) }iflet byline = HifiDeck.byline(card) {Text(byline) .font(CottonFonts.serif(knobs.bylineSize * s)) .tracking(knobs.bylineTracking * knobs.bylineSize * s) .lineLimit(1) .minimumScaleFactor(0.6) .foregroundStyle(ink) .accessibilityIdentifier("face-byline") .facePart(.subtitle) } } .frame(width: knobs.words.width * s, height: knobs.words.height * s, alignment: .bottom) .at(knobs.words, s) }// MARK: The knob, its times and the jewel/// The 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 = SongHifiFaceKnobs.selflet frame = square(knobs.knobCentre, knobs.knob)let turns = play.held && length > 0returnHifiKnob( angle: HifiDeck.knob(elapsed, of: length), side: knobs.knob * s, turn: { degrees inguard turns else { return } scrubbing = HifiDeck.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(HifiDeck.turned(play.elapsed, by: direction == .increment ? by : -by, of: length)) } .accessibilityIdentifier("hifi-knob") .facePart(.scrub) .at(frame, s) }/// The time played above the ring, the time left under the knob, and/// nought and the song's length beside the ring's ends.privatefunc times(elapsed: TimeInterval, length: TimeInterval, s: CGFloat) -> someView {let knobs = SongHifiFaceKnobs.selflet reach = knobs.ringEndReach * knobs.ticks / knobs.ticksPaintedlet end = knobs.knobCentre.y + reach * CGFloat(cos(Double.pi / 4)) + knobs.endDroplet startX = knobs.knobCentre.x - reach * CGFloat(sin(Double.pi / 4)) - knobs.endGaplet endX = knobs.knobCentre.x + reach * CGFloat(sin(Double.pi / 4)) + knobs.endGapreturn ZStack(alignment: .topLeading) {Text(TrackClock.said(elapsed)) .accessibilityIdentifier("hifi-elapsed") .placed(knobs.elapsed, s)if length > 0 {Text(TrackClock.said(0)) .placed(CGRect(x: startX - knobs.ends.width, y: end - knobs.ends.height / 2, width: knobs.ends.width, height: knobs.ends.height), s, alignment: .trailing)Text(TrackClock.said(length)) .accessibilityIdentifier("hifi-length") .placed(CGRect(x: endX, y: end - knobs.ends.height / 2, width: knobs.ends.width, height: knobs.ends.height), s, alignment: .leading)// 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("hifi-remaining") .placed(knobs.remaining, s) } } .font(CottonFonts.serif(knobs.timeSize * s)) .monospacedDigit() .lineLimit(1) .foregroundStyle(MusicMaterial.engraving.colour) .accessibilityHidden(true) }/// The red jewel: lit while it plays, dark otherwise; a tap plays or/// pauses.privatefunc jewel(state: HifiDeck.State, s: CGFloat) -> someView {let knobs = SongHifiFaceKnobs.selflet lit = state == .playinglet painting = lit ? knobs.jewelOn : knobs.jewelOfflet scale = knobs.jewelStone / painting.stone.widthlet drawn = CGRect( x: knobs.jewelCentre.x - painting.stone.midX * scale, y: knobs.jewelCentre.y - painting.stone.midY * scale, width: painting.size.width * scale, height: painting.size.height * scale)let touch = square(knobs.jewelCentre, knobs.jewelTouch * 2)return ZStack(alignment: .topLeading) {HifiPainted(name: lit ? "hifi-jewel-on" : "hifi-jewel-off").placed(drawn, 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("hifi-jewel") .facePart(.play) .at(touch, s) } }// MARK: The sleeve/// The playing album's sleeve, leaning against the wall above the deck:/// its shadow, its cover (else the typeset blank) and its frame.privatefunc leaningSleeve(_ s: CGFloat) -> someView {let knobs = SongHifiFaceKnobs.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) {HifiPainted(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)HifiPainted(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("hifi-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 = SongHifiFaceKnobs.selflet words = knobs.blankWordsreturn ZStack(alignment: .topLeading) {HifiPainted(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 spaced capitals: one line at its size, else a step/// smaller, else two lines smaller still, shrinking before it wraps.privatestructHifiTitle: View {let words: Stringlet s: CGFloatvar body: someView {let knobs = SongHifiFaceKnobs.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.brandHeadingFace, size * s, fallback: .semibold)) .tracking(SongHifiFaceKnobs.titleTracking * size * s) }}/// The brass knob turned to `angle` round its centre; a finger turning/// round the centre turns it by the angle swept.privatestructHifiKnob: 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)HifiPainted(name: "hifi-knob") .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 deck's paintings, stretched to its frame; nothing where the/// build carries no pictures.privatestructHifiPainted: 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 deck 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 deck 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 hi-fi 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`).publicenumSongHifiFaceCatalogue {publicstaticlet stock: FaceStock = .ownpublicstaticlet ground: FaceGround = .tolexpublicstaticlet face = Face(id: "song.hifi", 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 inSongHifiFace(card: card, cover: picture, play: player.play, toggle: player.toggle, seek: player.seek) } }/// An invented song off an invented album, 4:02 long.publicstaticlet harbour = DeckCard(face: .songHifi, fields: ["title": .text("Harbour Lights"),"artist": .text("The Low Tide"),"album": .text("Night Ferry"),"duration": .number(242), ])/// A long song name and a long album.publicstaticlet lanterns = DeckCard(face: .songHifi, 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), ])}