Cotton code
64 lines · 2.4 KB · SwiftRaw
// Where the player stands with a track, as a face draws it (`TrackPlay`), and// how loud it sounds (`TrackLevel`).import Foundation/// Where the player stands with one track, as its face draws it: whether the/// player holds this track, plays it, is still fetching it, how far it is/// and how long, and what went wrong. On a card that holds several songs (a/// playlist's tape, its `songs` entries) it is where the player stands with/// the one of them it holds: which (`song`), and how far into it and how/// long. The app fills it from its player (CottonUI's `DeckTrackPlaying`;/// Loom's `SpecimenPlayer`); a card the player holds nothing of is `still`.public struct TrackPlay: Equatable, Sendable {    public enum Fault: Equatable, Sendable {        /// Its file could not be fetched.        case unavailable        /// Its file is there but does not play.        case unplayable    }    public var held: Bool    public var playing: Bool    public var loading: Bool    public var elapsed: TimeInterval    public var duration: TimeInterval    public var fault: Fault?    /// On a card of several songs, the place in its songs of the one the    /// player holds (from 0); nil on a card of one track, and while it holds    /// none of them.    public var song: Int?    /// How loud the sound is in each channel at this moment, as the player    /// meters it; nil where it meters none (a hi-fi's needles rest).    public var level: TrackLevel?    public init(        held: Bool = false, playing: Bool = false, loading: Bool = false, elapsed: TimeInterval = 0,        duration: TimeInterval = 0, fault: Fault? = nil, song: Int? = nil, level: TrackLevel? = nil    ) {        self.held = held        self.playing = playing        self.loading = loading        self.elapsed = elapsed        self.duration = duration        self.fault = fault        self.song = song        self.level = level    }    /// Not the track the player holds.    public static let still = TrackPlay()}/// How loud the sound is in its two channels, each nought (silence) to one/// (the loudest the meters read), as the player meters it some twenty times/// a second.public struct TrackLevel: Equatable, Sendable {    public var left: Double    public var right: Double    public init(left: Double, right: Double) {        self.left = left        self.right = right    }}