// The ALBUM as ONE RECORD RESTING ON A TRAY (the owner's go, 7 Nov 2026, after// the hi-fi albums picture he chose, `music9-worlds/hifi-albums`; one tray// only, never the stacked three: the deck turns cards, it does not stack// them): a clear acrylic tray round an inset satin base, lying on the// music's black tolex (`FaceGround.tolex`) which shows through its lip, its// record in the faint round well, its own short square-cut ARM on a square// pivot block at the upper right, the hi-fi's red// jewel at the lower right, and along its foot a STRIP: the album's cover// cropped to it, a cream panel at its left typed with the title and the// artist, the tray's rail over its lower edge.//// The cream LABEL is typed with the album's title in the serif and its// artist in italic under it; while the album plays, the time played and the// time left of the song it holds either side of the spindle. At rest the arm// lies off the record; while the album plays it sits on the outer groove and// sweeps inward with the album's place — the songs before the one held and// how far into it, over the whole album, the needle's distance from the// record's centre running straight from the outer groove to the run-out — as// the turntable's arm does over a song. Paused it lifts a few degrees back.//// THE TILT: composed square-on, the whole tray is then tilted away as one// piece about its lower edge (`AlbumTrayFaceKnobs.tilt`), seen from above// as the picture has it.//// THE SAME TRAY is the song's face and the player's (`SongTrayFace.swift`,// `song.tray`, `TrayKind.song`): Round 11's 7-inch in the same well, the// label typing the song and its artist, the strip its album's cover; on// Listening the held song's, its record turning while it plays.//// PAINTED (`Media.xcassets`, `scripts/import-music-materials.py tray`, Round// 23's `music23-acrylic-tray` over Round 21's placements): the tray, its// shadow, the clear rail, the arm and its shadow, and Round 21's blank strip// card, each laid where its `layout.json` places it// in the tray's 1200 x 1600 box, scaled by the drawn width over it; the// record, the label, the 7-inch and its label, the spindle and the jewel are// Round 11's. The label is laid larger than the layout's (350 for the// 12-inch), as the turntable's is, filling the record inside its run-out// groove so its words read on a phone; its words keep the layout's places// and sizes, scaled with it. The cream panel is live, not painted.//// THE PARTS, tagged (`facePart`): the record is `play` — on the album a tap// plays the album from its first song (the player's `start`), and while the// album is held plays or pauses it; the strip, carrying the title, is// `title`. Nothing else: the album's card keeps to play and its title.//// Every word is the card's: `title`, `subtitle` (the artist), the songs'// lengths (`songs`, as the sleeve's back reads them) and its picture the// album's cover (`photo`).importCottonPaperimportCottonValuesimportSwiftUIenumAlbumTrayFaceKnobs {// THE TRAY'S BOX every placement is in, in the paintings' pixels// (`layout.json`): the face draws the tray as large as its room lets,// `fill` of its width, or of its height as the tilted tray stands, as// the sleeve fills its card (no cap: the tray fills the card, as the// picture has it), and every place below is scaled by the drawn width// over it.staticlet box = CGSize(width: 1200, height: 1600)staticlet fill: CGFloat = 0.92/// THE TILT (owner, 7 Nov 2026: the tray seen as in his picture, from/// above, tilted away, its top edge further; the perspective Round 23's/// tilted proof's, its eye 4000 of the box's 1600 away): the tray is composed/// square-on and the whole composition then turned this many degrees/// about its lower edge, the strip near its full size and the record/// foreshortened, under this perspective; its record turns and its arm/// sweeps inside it, its words tilt with it. Reduce Motion changes/// nothing about it.staticlet tilt: Double = 30staticlet perspective: CGFloat = 0.4/// The share of its height the tilted tray stands, seen: its top edge/// turned back by the tilt and drawn nearer the vanishing point by the/// perspective (SwiftUI's: the eye a box's longest side over the/// perspective away), the box's height being its longest side.staticvar tilted: CGFloat {let r = tilt * .pi / 180return CGFloat(cos(r) / (1 + Double(perspective) * sin(r))) }/// The whole drawing the face fits to its room: the tray (its shadow/// spills past it, as a shadow does). Nothing is drawn under the tray:/// its acrylic lip lets the ground show through.staticlet whole = CGRect(x: 0, y: 0, width: 1200, height: 1600)staticlet shadow = CGRect(x: -72, y: -72, width: 1344, height: 1744)staticlet centre = CGPoint(x: 600, y: 590)staticlet spindle = CGRect(x: 580, y: 570, width: 40, height: 40)// THE RECORDS in the well, both about the centre: the 12-inch at the// layout's `recordRect`, the 7-inch at its `song.tray.recordRect`.staticlet twelve = CGRect(x: 115, y: 105, width: 970, height: 970)staticlet seven = CGRect(x: 317, y: 307, width: 566, height: 566)// THE LABELS, laid larger than the layout's (350, 192), their painted// rounds inside each record's run-out groove; the painted round's share// of each painting's side (`label-blank`'s 439 of 900, the single's// whole 340).staticlet twelveLabel: CGFloat = 448staticlet sevenLabel: CGFloat = 276staticlet twelveRound: CGFloat = 439 / 900staticlet sevenRound: CGFloat = 0.5// THE LABEL'S WORDS, in the layout's label pixels (its 350 side) about// the label's centre, as `labelLiveText` places them: the title in the// serif above the spindle, the artist in italic under it, the times// either side of the spindle below it; each line's room inside the// label's text circle (`outerRadius` 146).staticlet labelLayout: CGFloat = 350staticlet title = (y: CGFloat(-86), size: CGFloat(35), width: CGFloat(236))staticlet artist = (y: CGFloat(-42), size: CGFloat(27), width: CGFloat(270))staticlet times = (y: CGFloat(59), x: CGFloat(76), size: CGFloat(24), width: CGFloat(100))/// The least a label's line is taken down to before it is cut.staticlet labelLeast: CGFloat = 0.5// THE ARM, rigid on its pivot: its painting laid as painted, at the outer// groove (`tray-arm.png`'s rect), its pivot and its needle in that// painting (`sourcePivot`, `sourceStylus`); its shadow's rect, centred on// it, and where the lamp throws it, down and lifted.staticlet arm = CGRect(x: 893, y: 107, width: 263, height: 843)staticlet armShadow = CGRect(x: 869, y: 83, width: 311, height: 891)staticlet sourcePivot = CGPoint(x: 187.26027397260276, y: 73.21917808219177)staticlet sourceStylus = CGPoint(x: 35.71232876712329, y: 813.2191780821918)staticvar pivot: CGPoint { CGPoint(x: arm.minX + sourcePivot.x, y: arm.minY + sourcePivot.y) }staticvar stylus: CGPoint { CGPoint(x: arm.minX + sourceStylus.x, y: arm.minY + sourceStylus.y) }staticlet shadowDown = CGSize(width: 5, height: 8)staticlet shadowLifted = CGSize(width: 22, height: 30)/// The run-out grooves: the 12-inch's and the 7-inch's (its outer/// groove, the arm's sweep's start, is `sevenOuter`; the 12-inch's is/// where the arm is painted).staticlet twelveInner: Double = 220staticlet sevenOuter: Double = 270staticlet sevenInner: Double = 140/// The arm at rest, in degrees clockwise from the outer groove: back off/// the record, upright beside it; lifted, a few degrees back from where/// it plays; the ease of a move between them.staticlet rest: Double = -10staticlet lift: Double = 3staticlet ease: Double = 0.45/// Where a finger finds the arm: a band this wide along its shaft.staticlet armReach: CGFloat = 110staticlet armSlop: CGFloat = 4// THE JEWEL (`jewelRect`), its stone the hi-fi's.staticlet jewelCentre = CGPoint(x: 1097, y: 1142)staticlet jewelStone: CGFloat = 34// THE STRIP: its blank card, the art's rect inside its cream rule, the// cream panel at its left, the words' inset in the panel and their// sizes (`stripFonts`); the rail laid over its lower edge.staticlet strip = CGRect(x: 52, y: 1227, width: 1096, height: 256)staticlet art = CGRect(x: 66, y: 1241, width: 1068, height: 228)staticlet panel = CGRect(x: 66, y: 1241, width: 390, height: 228)staticlet panelInset: CGFloat = 27staticlet stripTitle: CGFloat = 42staticlet stripArtist: CGFloat = 28staticlet stripGap: CGFloat = 8staticlet ledge = CGRect(x: 88, y: 1456, width: 1024, height: 26)/// Beside the record on the player: `previous` left of its centre,/// `next` right of it, over the tray above the strip, under the record/// and the arm.staticlet previous = CGRect(x: 0, y: 0, width: 600, height: 1227)staticlet next = CGRect(x: 600, y: 0, width: 600, height: 1227)}/// Which record the tray carries: the album's 12-inch, or the song's 7-inch/// (on the Songs deck and on Listening's player).publicenumTrayKind: Sendable, Hashable {case albumcase songvar record: CGRect { self == .album ? AlbumTrayFaceKnobs.twelve : AlbumTrayFaceKnobs.seven }var recordPainting: String { self == .album ? "record" : "single-record" }var labelPainting: String { self == .album ? "label-blank" : "single-label-blank" }var labelSide: CGFloat { self == .album ? AlbumTrayFaceKnobs.twelveLabel : AlbumTrayFaceKnobs.sevenLabel }var labelRound: CGFloat { self == .album ? AlbumTrayFaceKnobs.twelveRound : AlbumTrayFaceKnobs.sevenRound }var identifier: String { self == .album ? "album-tray" : "song-tray" }/// The record's outer groove and run-out, from its centre.var grooves: (outer: Double, inner: Double) {switchself {case .album: (TrayDeck.painted, AlbumTrayFaceKnobs.twelveInner)case .song: (AlbumTrayFaceKnobs.sevenOuter, AlbumTrayFaceKnobs.sevenInner) } }}/// What the tray reads off its card and its player.publicenumTrayDeck {/// The needle's distance from the centre as the arm is painted: the/// 12-inch's outer groove.staticvar painted: Double {let knobs = AlbumTrayFaceKnobs.selfreturnDouble(hypot(knobs.stylus.x - knobs.centre.x, knobs.stylus.y - knobs.centre.y)) }/// The share of the whole the arm stands at: on an album, the songs/// before the one held and how far into it over the album's length (its/// songs' lengths, `songs`); on a song, or an album whose songs' lengths/// are not known, how far into the song over its length. Nought while/// it holds none.publicstaticfunc share(_ play: TrackPlay, songs: [TimeInterval] = []) -> Double {guard play.held else { return0 }let whole = songs.reduce(0, +)iflet at = play.song, songs.indices.contains(at), whole > 0 {let into = min(max(0, play.elapsed.isFinite ? play.elapsed : 0), songs[at])return min(1, max(0, (songs[..<at].reduce(0, +) + into) / whole)) }guard play.duration > 0, play.elapsed.isFinite else { return0 }return min(1, max(0, play.elapsed / play.duration)) }/// The arm's angle at `share` of the record, in degrees clockwise from/// where it is painted: the needle's distance from the centre running/// straight from the record's outer groove at nought to its run-out at/// one, the rigid arm turned round its pivot to meet it.publicstaticfunc arm(_ share: Double, on kind: TrayKind) -> Double {let grooves = kind.grooveslet held = min(1, max(0, share))return opening(painted) - opening(grooves.outer + (grooves.inner - grooves.outer) * held) }/// The arm as it stands: at rest off the record while it holds none of/// the card; lifted a few degrees back while paused; else at its share.publicstaticfunc arm(_ play: TrackPlay, songs: [TimeInterval] = [], on kind: TrayKind) -> Double {guard play.held else { returnAlbumTrayFaceKnobs.rest }let playing = HifiDeck.state(play) == .playingreturn arm(share(play, songs: songs), on: kind) - (playing ? 0 : AlbumTrayFaceKnobs.lift) }/// Where the needle lies with the arm turned `degrees` clockwise from/// where it is painted.publicstaticfunc needle(_ degrees: Double) -> CGPoint {let knobs = AlbumTrayFaceKnobs.selflet x = Double(knobs.stylus.x - knobs.pivot.x), y = Double(knobs.stylus.y - knobs.pivot.y)let r = degrees * .pi / 180return CGPoint(x: Double(knobs.pivot.x) + x * cos(r) - y * sin(r), y: Double(knobs.pivot.y) + x * sin(r) + y * cos(r)) }/// The share of the song the arm at `degrees` stands at, on `kind`'s/// record: its needle's groove, outer nought, run-out one.publicstaticfunc share(atArm degrees: Double, on kind: TrayKind) -> Double {let knobs = AlbumTrayFaceKnobs.selflet at = needle(degrees)let radius = hypot(Double(at.x - knobs.centre.x), Double(at.y - knobs.centre.y))let grooves = kind.groovesreturn min(1, max(0, (grooves.outer - radius) / (grooves.outer - grooves.inner))) }/// Where a turn of the arm by `degrees` from `elapsed` of a song/// `length` long seeks to: its sweep is the whole song, held to it.publicstaticfunc turned(_ elapsed: TimeInterval, by degrees: Double, of length: TimeInterval, on kind: TrayKind) -> TimeInterval {guard length > 0else { return0 }let from = arm(min(1, max(0, elapsed / length)), on: kind)let to = min(arm(1, on: kind), max(arm(0, on: kind), from + degrees))return share(atArm: to, on: kind) * length }/// The angle at the pivot between the needle and the record's centre,/// the needle at `radius` from the centre: the law of cosines over the/// arm's length and the pivot's distance from the centre.staticfunc opening(_ radius: Double) -> Double {let knobs = AlbumTrayFaceKnobs.selflet arm = hypot(Double(knobs.stylus.x - knobs.pivot.x), Double(knobs.stylus.y - knobs.pivot.y))let apart = hypot(Double(knobs.centre.x - knobs.pivot.x), Double(knobs.centre.y - knobs.pivot.y))let cosine = (arm * arm + apart * apart - radius * radius) / (2 * arm * apart)return acos(min(1, max(-1, cosine))) * 180 / .pi }/// The label's two lines: the title, and under it the artist (a player/// card's `artist`, else the card's `subtitle`).publicstaticfunc label(_ card: DeckCard) -> [String] { [card.text("title"), card.text("artist") ?? card.text("subtitle")].compactMap { $0 } }/// The strip's two lines: the album's title and its artist — on the/// player, the held song's album (`album`) and its artist; else the/// card's own title and artist.publicstaticfunc strip(_ card: DeckCard, player: Bool) -> [String] {let artist = card.text("artist") ?? card.text("subtitle")let title = player ? card.text("album") ?? card.text("title") : card.text("title")return [title, artist].compactMap { $0 } }/// The times either side of the spindle while it holds the card: the/// time played and the time left of the song held; none at rest, or/// while the song's length is unknown.publicstaticfunc times(_ play: TrackPlay) -> [String] {guard play.held, play.duration > 0else { return [] }// Left from the whole seconds played, so the clocks add up.return [TrackClock.said(play.elapsed), TrackClock.left(play.elapsed.rounded(.down), of: play.duration)] }/// An album's songs' lengths, in its order (`songs`).publicstaticfunc songs(_ card: DeckCard) -> [TimeInterval] { card.entries("songs").map { max(0, $0["duration"]?.number ?? 0) } }}/// The tray: the album's 12-inch, or the song's 7-inch and, on Listening,/// the player's.publicstructTrayFace: View {let card: DeckCard/// The album's cover, laid along the strip; nil lays the strip's blank.var cover: FacePicture?var play: TrackPlay = .stillvar toggle: (() -> Void)?var seek: (TimeInterval) -> Void = { _ in }/// Plays the album from its song at this place (the album's tap).var start: ((Int) -> Void)?let kind: TrayKind/// Where a drag of the arm has the song, until the finger lifts. @State privatevar scrubbing: TimeInterval?/// Where the record turns on from (`TurntableDeck.turn`). @State privatevar phase: Double = 0 @Environment(\.accessibilityReduceMotion) privatevar reduceMotionpublicinit( card: DeckCard, cover: FacePicture?, play: TrackPlay = .still, toggle: (() -> Void)? = nil, seek: @escaping (TimeInterval) -> Void = { _ in }, start: ((Int) -> Void)? = nil, kind: TrayKind ) {self.card = cardself.cover = coverself.play = playself.toggle = toggleself.seek = seekself.start = startself.kind = kind }/// The song's tray holding its song is the player: its record turns, its/// arm scrubs and beside it are previous and next.privatevar player: Bool { kind == .song && play.held }/// Where it stands, a drag of the arm put in for the time played.privatevar standing: TrackPlay {var standing = playiflet scrubbing { standing.elapsed = scrubbing }return standing }publicvar body: someView {let knobs = AlbumTrayFaceKnobs.selflet whole = knobs.wholeGeometryReader { room inlet width = knobs.fill * min(room.size.width, room.size.height * whole.width / (whole.height * knobs.tilted))let s = width / whole.width ZStack(alignment: .topLeading) {if player { beside(s) }TrayPainted(name: "tray-shadow").placed(knobs.shadow, s)TrayPainted(name: "tray").placed(CGRect(origin: .zero, size: knobs.box), s) record(s)TrayPainted(name: "spindle").placed(knobs.spindle, s) arm(s) jewel(s) strip(s)TrayPainted(name: "tray-ledge").placed(knobs.ledge, s) } .frame(width: knobs.box.width * s, height: knobs.box.height * s, alignment: .topLeading) .offset(x: -whole.minX * s, y: -whole.minY * s) .frame(width: width, height: whole.height * s, alignment: .topLeading) .rotation3DEffect(.degrees(knobs.tilt), axis: (x: 1, y: 0, z: 0), anchor: .bottom, perspective: knobs.perspective)// Its foot where the tilted tray, seen, stands in the middle. .offset(y: -whole.height * s * (1 - knobs.tilted) / 2) .frame(width: room.size.width, height: room.size.height) .accessibilityElement(children: .contain) .accessibilityIdentifier(kind.identifier) } .onChange(of: HifiDeck.state(play)) { was, now inif was == .paused, now == .playing { phase = TurntableDeck.resumed(play.elapsed, phase: phase) } } .onChange(of: play.elapsed) { was, now in phase = TurntableDeck.phase(phase, from: was, to: now) } }// MARK: The record/// The record and its label, typed with the card's words and the times;/// on the player turning while it plays. A tap on it plays.privatefunc record(_ s: CGFloat) -> someView {let rect = kind.recordlet playing = HifiDeck.state(play) == .playinglet turn = player ? TurntableDeck.turn(play.elapsed, playing: playing, phase: phase, reduceMotion: reduceMotion) : 0let side = rect.width * slet label = kind.labelSide * sreturn ZStack {TrayPainted(name: kind.recordPainting).frame(width: side, height: side)TrayPainted(name: kind.labelPainting).frame(width: label, height: label) words(label: label) } .frame(width: side, height: side) .rotationEffect(.degrees(turn)) .animation(player && !reduceMotion ? (playing ? .linear(duration: SongTurntableFaceKnobs.glide) : .easeOut(duration: SongTurntableFaceKnobs.coast)) : nil, value: turn) .allowsHitTesting(false) .overlay {Circle() .fill(Color.clear) .contentShape(Circle()) .modifier(TrayTap(action: tapped)) .accessibilityElement(children: .ignore) .accessibilityLabel(ShellLines.line("faces", playing ? "media.pause" : "media.play")) .accessibilityValue(MusicWhole.joined(TrayDeck.label(card)) ?? "") .accessibilityAddTraits(.isButton) .accessibilityIdentifier("tray-record") .facePart(.play) } .at(rect, s) }/// What a tap on the record does that the face does itself: held, it/// plays or pauses; an album not held plays from its first song. A song/// not held is the deck's to play (its `play` part); nil leaves the tap/// to it.privatevar tapped: (() -> Void)? {if play.held, let toggle { return toggle }if kind == .album, let start { return { start(0) } }returnnil }/// The label's words in the layout's places, scaled with the label: the/// title above the spindle, the artist under it, the times either side/// below it.privatefunc words(label: CGFloat) -> someView {let knobs = AlbumTrayFaceKnobs.selflet k = label / knobs.labelLayoutlet centre = label / 2let lines = TrayDeck.label(card)let times = TrayDeck.times(standing)return ZStack {iflet title = lines.first {Text(title) .font(CottonFonts.serif(knobs.title.size * k)) .lineLimit(1) .minimumScaleFactor(knobs.labelLeast) .frame(width: knobs.title.width * k) .position(x: centre, y: centre + knobs.title.y * k) }if lines.count > 1 {Text(lines[1]) .font(CottonFonts.cap(knobs.artist.size * k)) .lineLimit(1) .minimumScaleFactor(knobs.labelLeast) .frame(width: knobs.artist.width * k) .position(x: centre, y: centre + knobs.artist.y * k) }ForEach(Array(times.enumerated()), id: \.offset) { at, time inText(time) .font(CottonFonts.type(knobs.times.size * k)) .monospacedDigit() .lineLimit(1) .fixedSize() .frame(width: knobs.times.width * k) .position(x: centre + (at == 0 ? -knobs.times.x : knobs.times.x) * k, y: centre + knobs.times.y * k) } } .foregroundStyle(MusicMaterial.labelInk.colour) .frame(width: label, height: label) .accessibilityHidden(true) }// MARK: The arm and the jewel/// The arm on its pivot: at rest off the record, on its groove while it/// holds the card, lifted while paused, its shadow under it; on the/// player dragged along its arc it seeks.privatefunc arm(_ s: CGFloat) -> someView {let knobs = AlbumTrayFaceKnobs.selflet songs = kind == .album ? TrayDeck.songs(card) : []let angle = TrayDeck.arm(standing, songs: songs, on: kind)let lifted = !play.held || HifiDeck.state(play) == .pausedlet throwBy = lifted ? knobs.shadowLifted : knobs.shadowDownlet length = HifiDeck.length(play, card)let scrubs = player && length > 0let anchor = { (rect: CGRect) inUnitPoint(x: (knobs.pivot.x - rect.minX) / rect.width, y: (knobs.pivot.y - rect.minY) / rect.height) }let motion: Animation? = reduceMotion ? nil : .easeInOut(duration: knobs.ease)return ZStack(alignment: .topLeading) {TrayPainted(name: "tray-arm-shadow") .frame(width: knobs.armShadow.width * s, height: knobs.armShadow.height * s) .rotationEffect(.degrees(angle), anchor: anchor(knobs.armShadow)) .offset(x: throwBy.width * s, y: throwBy.height * s) .animation(motion, value: lifted) .at(knobs.armShadow, s)TrayArm( angle: angle, anchor: anchor(knobs.arm), size: CGSize(width: knobs.arm.width * s, height: knobs.arm.height * s), pivot: CGPoint(x: knobs.pivot.x * s, y: knobs.pivot.y * s), s: s, scrubs: scrubs, turn: { degrees in scrubbing = TrayDeck.turned(scrubbing ?? play.elapsed, by: degrees, of: length, on: kind) }, lifted: {iflet scrubbing { seek(scrubbing) } scrubbing = nil }) .animation(motion, value: lifted) .accessibilityElement(children: .ignore) .accessibilityLabel(ShellLines.line("faces", "tray.position")) .accessibilityValue(scrubs ? TrackClock.said(standing.elapsed) : "") .accessibilityAdjustableAction { direction inguard scrubs else { return }let by = TrayDeck.arm(1, on: kind) / 20 seek(TrayDeck.turned(play.elapsed, by: direction == .increment ? by : -by, of: length, on: kind)) } .accessibilityIdentifier("tray-arm") .modifier(TrayScrub(scrubs: scrubs)) .at(knobs.arm, s) } .coordinateSpace(.named(TrayArm.space)) }/// The hi-fi's red jewel, lit while it plays.privatefunc jewel(_ s: CGFloat) -> someView {let knobs = AlbumTrayFaceKnobs.selflet lit = HifiDeck.state(play) == .playinglet painting = lit ? SongHifiFaceKnobs.jewelOn : SongHifiFaceKnobs.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)returnTrayPainted(name: lit ? "hifi-jewel-on" : "hifi-jewel-off").placed(drawn, s) }// MARK: Beside the record, and the strip/// Beside the record on the player: a tap left of its centre the/// previous song, right of it the next — the shell's acts.privatefunc beside(_ s: CGFloat) -> someView {let knobs = AlbumTrayFaceKnobs.selfreturn ZStack(alignment: .topLeading) {Color.clear .contentShape(Rectangle()) .frame(width: knobs.previous.width * s, height: knobs.previous.height * s) .accessibilityElement() .accessibilityLabel(ShellLines.line("faces", "tray.previous")) .accessibilityAddTraits(.isButton) .accessibilityIdentifier("tray-previous") .facePart(.previous) .at(knobs.previous, s)Color.clear .contentShape(Rectangle()) .frame(width: knobs.next.width * s, height: knobs.next.height * s) .accessibilityElement() .accessibilityLabel(ShellLines.line("faces", "tray.next")) .accessibilityAddTraits(.isButton) .accessibilityIdentifier("tray-next") .facePart(.next) .at(knobs.next, s) } }/// The strip along the tray's foot: its blank card, the cover cropped to/// it where there is one, the cream panel at its left typed with the/// title and the artist; the title's part.privatefunc strip(_ s: CGFloat) -> someView {let knobs = AlbumTrayFaceKnobs.selflet lines = TrayDeck.strip(card, player: player)return ZStack(alignment: .topLeading) {TrayPainted(name: "strip-blank").placed(knobs.strip, s)iflet cover { cover .frame(width: knobs.art.width * s, height: knobs.art.height * s) .clipped() .allowsHitTesting(false) .accessibilityHidden(true) .at(knobs.art, s) }Rectangle() .fill(MusicMaterial.panel.colour) .allowsHitTesting(false) .placed(knobs.panel, s) VStack(alignment: .leading, spacing: knobs.stripGap * s) {iflet title = lines.first {Text(title) .font(CottonFonts.serif(knobs.stripTitle * s)) .lineLimit(2) .minimumScaleFactor(0.6) .accessibilityAddTraits(.isHeader) .accessibilityIdentifier("deck-title") }if lines.count > 1 {Text(lines[1]) .font(CottonFonts.cap(knobs.stripArtist * s)) .lineLimit(1) .minimumScaleFactor(0.6) .accessibilityIdentifier("face-byline") } } .foregroundStyle(MusicMaterial.labelInk.colour) .padding(.horizontal, knobs.panelInset * s) .frame(width: knobs.panel.width * s, height: knobs.panel.height * s, alignment: .leading) .contentShape(Rectangle()) .accessibilityElement(children: .contain) .accessibilityIdentifier("tray-strip") .facePart(.title) .at(knobs.panel, s) } }}/// The record's tap the face keeps on itself, where it has one; none leaves/// the tap to the deck's part.privatestructTrayTap: ViewModifier {let action: (() -> Void)?func body(content: Content) -> someView {iflet action { content.onTapGesture(perform: action).accessibilityAction { action() } } else { content } }}/// The arm is the player's scrub part; elsewhere it is no part.privatestructTrayScrub: ViewModifier {let scrubs: Boolfunc body(content: Content) -> someView {if scrubs { content.facePart(.scrub) } else { content } }}/// The arm turned to `angle` round its pivot; where it scrubs, a finger/// dragging along its arc turns it by the angle swept round the pivot.privatestructTrayArm: View {staticlet space = "tray"let angle: Doublelet anchor: UnitPointlet size: CGSize/// The pivot in the tray's space, in points.let pivot: CGPointlet s: CGFloatlet scrubs: Boollet turn: (_ degrees: Double) -> Voidlet lifted: () -> Void @State privatevar last: Double?var body: someView {if scrubs {TrayPainted(name: "tray-arm") .frame(width: size.width, height: size.height) .contentShape(TrayArmLine(scale: size.width / AlbumTrayFaceKnobs.arm.width)) .rotationEffect(.degrees(angle), anchor: anchor) .gesture(DragGesture(minimumDistance: AlbumTrayFaceKnobs.armSlop * s, coordinateSpace: .named(Self.space)) .onChanged { touch inlet now = HifiDeck.angle(of: touch.location, round: pivot)iflet last { turn(HifiDeck.turn(from: last, to: now)) } last = now } .onEnded { _ in last = nil lifted() }) } else {TrayPainted(name: "tray-arm") .frame(width: size.width, height: size.height) .rotationEffect(.degrees(angle), anchor: anchor) .allowsHitTesting(false) } }}/// Where a finger finds the arm: a band along its rod, pivot to needle.privatestructTrayArmLine: Shape {let scale: CGFloatfunc path(in rect: CGRect) -> Path {let knobs = AlbumTrayFaceKnobs.selfvar line = Path() line.addLines([knobs.sourcePivot, knobs.sourceStylus].map { CGPoint(x: $0.x * scale, y: $0.y * scale) })return line.strokedPath(StrokeStyle(lineWidth: knobs.armReach * scale, lineCap: .round)) }}/// One of the tray's paintings, stretched to its frame; nothing where the/// build carries no pictures. A painting takes no tap: the parts do.privatestructTrayPainted: View {let name: Stringvar body: someView {iflet image = CottonMedia.image(name) { image.resizable().interpolation(.high).allowsHitTesting(false).accessibilityHidden(true) } }}privateextensionView {/// This view laid at `rect` of the tray's box, in its pixels, scaled by `s`.func placed(_ rect: CGRect, _ s: CGFloat) -> someView { frame(width: rect.width * s, height: rect.height * s).offset(x: rect.minX * s, y: rect.minY * s) }/// This view moved to `rect`'s corner, scaled by `s`: 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 album's tray, beside its sleeve, and the albums it is reviewed in:/// the sleeve's invented albums. Under the player the app installs/// (`faceTrackPlayer`), else at rest; the playing specimen names the/// player's word it is reviewed under.publicenumAlbumTrayFaceCatalogue {publicstaticlet stock: FaceStock = .ownpublicstaticlet ground: FaceGround = .tolexpublicstaticlet face = Face(id: "album.tray", specimens: [Specimen("at rest", ferry, picture: "cover-night-ferry"),Specimen("playing", ferry, picture: "cover-night-ferry", play: TrackPlay(held: true, playing: true, elapsed: 134, duration: 242, song: 0)),Specimen("no cover", common),Specimen("largest", largest), ]) { card, picture, _ inTrackPlaying(card: card) { player inTrayFace(card: card, cover: picture, play: player.play, toggle: player.toggle, seek: player.seek, start: player.start, kind: .album) } }/// The sleeve's Night Ferry, its cover kept, worn on the tray.publicstaticlet ferry = worn(AlbumSleeveFaceCatalogue.ferry)/// No cover kept: the strip's blank.publicstaticlet common = worn(AlbumSleeveFaceCatalogue.common)/// The longest words, drawn at every text size Loom has, the largest/// among them: a print on an object scales with the object.publicstaticlet largest = worn(AlbumSleeveFaceCatalogue.largest)staticfunc worn(_ album: DeckCard) -> DeckCard {var card = album card.face = "album.tray"return card }}