// The VOICE NOTE face (image 12): the title typed at the top, the sound as a// row of ink strokes with a dark play button at its middle and the length// under it, the recorded date in the hand, then the transcript's first lines// typed out and fading into a handwritten "continued". The strokes are the// recording's own loudness, handed in by whoever holds its bytes; silence is// a dotted line. Every word is the core's (`FaceRead`).//// A MEETING is drawn on this face (its card's kind, 7f4a5f0fb; house// references 95 and 96) in the house's dress: its title typed heavy, the// day and hour it was held written large by hand under it, its length typed// under that, who spoke on little paper pills (`subtitle`: the core's list// of names, the first few and how many more), its state stamped while it is// still being turned into text (`state`), then the first of the pages its// card turns to (`card.pages`: what was said, the decisions, the transcript;// `DeckCardFill`) typed open-leaded, the turned card's foot saying "continued →". No// loudness is held for the deck, as for every meeting, so no strokes; and// no play button — playing is the fan's Play.importCottonPaperimportCottonValuesimportSwiftUIenumAudioFaceKnobs {staticlet inset: CGFloat = 22staticlet titleSize: CGFloat = 16staticlet titleTop: CGFloat = 52staticlet waveHeight: CGFloat = 40staticlet waveTop: CGFloat = 34staticlet play: CGFloat = 43staticlet stroke: CGFloat = 1.3staticlet strokeStep: CGFloat = 4.6/// A peak below this is drawn as a dot: the quiet between words.staticlet quiet: Float = 0.08staticlet lengthSize: CGFloat = 11.5staticlet dateHand: CGFloat = 14.5staticlet transcriptSize: CGFloat = 11.8staticlet transcriptLeading: CGFloat = 6staticlet transcriptLines = 5staticlet continuedHand: CGFloat = 15staticlet speakersSize: CGFloat = 12.5staticlet stampSize: CGFloat = 12staticlet stampTurn: Double = -7// The meeting's dress.staticlet meetingInset = EdgeInsets(top: 30, leading: 30, bottom: 34, trailing: 28)staticlet meetingTitle: CGFloat = 25staticlet meetingDateHand: CGFloat = 24staticlet meetingLength: CGFloat = 14staticlet meetingSpeakers = 4staticlet meetingPreview: CGFloat = 14staticlet meetingLeading: CGFloat = 10staticlet meetingLines = 7staticlet meetingGap: CGFloat = 14}publicstructAudioFace: View { @Environment(\.theme) privatevar themelet card: DeckCard/// The recording's loudness across its length, each 0...1.let peaks: [Float]var play: () -> Void = {}/// Words to type where the transcript goes when the card names none/// (a meeting's first page).var preview: String?/// The preview is a Markdown column's words: set, never typed with marks.var previewMarkdown = false/// The pages its card turns to after it (`card.pages`), each a column's/// words under its label (`FaceTurns`).var pages: [CardPage] = []/// The page shown first: 0, the face (a gallery's specimen of a page).var opened = 0publicinit(card: DeckCard, peaks: [Float], play: @escaping () -> Void = {}, preview: String? = nil, previewMarkdown: Bool = false, pages: [CardPage] = [], opened: Int = 0) {self.card = cardself.peaks = peaksself.play = playself.preview = previewself.previewMarkdown = previewMarkdownself.pages = pagesself.opened = opened }publicvar body: someView {FaceTurns(pages: pages, opened: opened) {if peaks.isEmpty { meeting } else { voiceNote } } .onCardPaper(AudioFaceCatalogue.stock.laid(card.pace)) }/// A meeting's card: no loudness held, so no strokes and no play button.privatevar meeting: someView { VStack(alignment: .leading, spacing: 0) {iflet title = card.text("title") {HeavyType(words: title, size: AudioFaceKnobs.meetingTitle) .lineLimit(3) .minimumScaleFactor(0.75) .accessibilityIdentifier("deck-title") .facePart(.title) }iflet date = card.text("date") {Text(HandRun.tail(date)) .font(CottonFonts.hand(AudioFaceKnobs.meetingDateHand)) .lineLimit(1) .minimumScaleFactor(0.6) .faceInk(.ink) .padding(.top, AudioFaceKnobs.meetingGap / 2) .accessibilityIdentifier("face-date") .facePart(.when) }iflet length = card.text("length") {Text(length) .font(CottonFonts.type(AudioFaceKnobs.meetingLength)) .lineLimit(1) .faceInk(.ink) .padding(.top, AudioFaceKnobs.meetingGap / 2) .accessibilityIdentifier("face-length") }let speakers = card.words("subtitle")if !speakers.isEmpty {let shown = speakers.prefix(AudioFaceKnobs.meetingSpeakers)ChipWrap(spacing: 8) {ForEach(Array(shown.enumerated()), id: \.offset) { _, speaker inPaperChip(words: speaker, round: true) }if speakers.count > shown.count {PaperChip(words: ShellLines.line("cards", "people.more", ["n": "\(speakers.count - shown.count)"]), round: true) } } .padding(.top, AudioFaceKnobs.meetingGap) .accessibilityElement(children: .combine) .accessibilityIdentifier("face-speakers") .facePart(.subtitle) }iflet state = card.text("state") {RubberStamp(words: state.uppercased(), size: AudioFaceKnobs.stampSize, turn: AudioFaceKnobs.stampTurn) .padding(.top, AudioFaceKnobs.meetingGap + 4) .padding(.leading, 4) .facePart(.state) }iflet said = card.text("body") ?? preview {Text(previewMarkdown ? FaceMarkdown.set(said, theme: theme) : AttributedString(said)) .font(CottonFonts.type(AudioFaceKnobs.meetingPreview)) .lineSpacing(AudioFaceKnobs.meetingLeading) .lineLimit(AudioFaceKnobs.meetingLines) .truncationMode(.tail) .faceInk(.ink) .fixedSize(horizontal: false, vertical: true) .padding(.top, AudioFaceKnobs.meetingGap + 6) .facePart(.body) }Spacer(minLength: 0) } .padding(AudioFaceKnobs.meetingInset) .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) }/// A voice note's card: its strokes, the play button at their middle.privatevar voiceNote: someView { VStack(alignment: .leading, spacing: 0) {iflet title = card.text("title") {Text(title) .font(CottonFonts.type(AudioFaceKnobs.titleSize)) .lineLimit(2) .faceInk(.ink) .padding(.top, AudioFaceKnobs.titleTop) .accessibilityAddTraits(.isHeader) .facePart(.title) }iflet speakers = card.text("subtitle") {Text(speakers) .font(CottonFonts.type(AudioFaceKnobs.speakersSize)) .lineLimit(2) .faceInk(.pencil) .padding(.top, 6) .accessibilityIdentifier("face-speakers") .facePart(.subtitle) }InkWaveform(peaks: peaks, gap: AudioFaceKnobs.play + 14) .frame(height: AudioFaceKnobs.waveHeight) .overlay {Button(action: play) { PlayDisc(size: AudioFaceKnobs.play) } .buttonStyle(MotionButtonStyle()) .accessibilityLabel(card.text("title") ?? "") .facePart(.play) } .padding(.top, AudioFaceKnobs.waveTop)iflet length = card.text("length") {Text(length) .font(CottonFonts.type(AudioFaceKnobs.lengthSize)) .faceInk(.ink) .frame(maxWidth: .infinity) .padding(.top, 12) }iflet date = card.text("date") {Text(date) .font(CottonFonts.hand(AudioFaceKnobs.dateHand)) .faceInk(.pencil) .padding(.top, 16) .facePart(.when) }iflet state = card.text("state") {RubberStamp(words: state.uppercased(), size: AudioFaceKnobs.stampSize, turn: AudioFaceKnobs.stampTurn) .padding(.top, 18) .padding(.leading, 4) .facePart(.state) }iflet transcript = card.text("body") ?? preview {Text(previewMarkdown ? FaceMarkdown.set(transcript, theme: theme) : AttributedString(transcript)) .font(CottonFonts.type(AudioFaceKnobs.transcriptSize)) .lineSpacing(AudioFaceKnobs.transcriptLeading) .lineLimit(AudioFaceKnobs.transcriptLines) .truncationMode(.tail) .faceInk(.ink) .fixedSize(horizontal: false, vertical: true) .padding(.top, 22) .facePart(.body)Text(ShellLines.line("cards", "audio.continued")) .font(CottonFonts.hand(AudioFaceKnobs.continuedHand)) .faceInk(.pencil) .opacity(0.75) .padding(.top, 10) }Spacer(minLength: 0) } .padding(.horizontal, AudioFaceKnobs.inset) .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) }}/// The recording drawn in ink: a stroke per step, as tall as that stretch is/// loud; a dot where it is quiet; a gap at the middle for the play button.structInkWaveform: View {let peaks: [Float]let gap: CGFloat @Environment(\.theme) privatevar themevar body: someView {Canvas { context, size inlet step = AudioFaceKnobs.strokeSteplet count = Int(size.width / step)guard count > 0, !peaks.isEmpty else { return }let mid = size.width / 2var strokes = Path()var dots = Path()for index in0..<count {let x = CGFloat(index) * step + step / 2if abs(x - mid) < gap / 2 { continue }let peak = peaks[min(peaks.count - 1, index * peaks.count / count)]if peak < AudioFaceKnobs.quiet { dots.addEllipse(in: CGRect(x: x - 1, y: size.height / 2 - 1, width: 2, height: 2)) } else {let half = max(2, CGFloat(peak) * size.height / 2) strokes.move(to: CGPoint(x: x, y: size.height / 2 - half)) strokes.addLine(to: CGPoint(x: x, y: size.height / 2 + half)) } }let ink = theme.print(.pencil) context.stroke(strokes, with: .color(ink), style: StrokeStyle(lineWidth: AudioFaceKnobs.stroke, lineCap: .round)) context.fill(dots, with: .color(ink)) } .blendMode(theme.printBlend) .accessibilityHidden(true) }}/// The audio face, by the kind's name, and the cards it is reviewed in: no/// loudness is held for a card, so no strokes; the pages it turns to after/// it, the first fading out on its face.publicenumAudioFaceCatalogue {publicstaticlet stock: FaceStock = .framedpublicstaticlet ground: FaceGround = .paperpublicstaticlet face = Face(id: "audio", specimens: [Specimen("shelf", shelf.reading { $0.pages = [CardPage(label: "Transcript", text: "Invented: a shallow teak shelf above the counter.")] })]) { card, _, _ inAudioFace(card: card, peaks: [], preview: card.pages.first?.text, previewMarkdown: card.pages.first?.markdown == true, pages: card.pages) }publicstaticlet shelf = DeckCard(face: .audio, fields: ["title": .text("Idea for the kitchen shelf"),"length": .text("1:18"),"date": .text("Tue 21 Oct, 7:40 am"),"body": .text("So I was thinking we could get a shallow shelf above the counter, maybe in teak, to keep the everyday things like chai, mugs and the coffee jar. It should be around 90 cm, not too deep, and the brackets should be the plain black ones from the hardware shop on 12th Main."), ])/// An invented recording's loudness: quiet at the ends, speech between.publicstaticlet shelfPeaks: [Float] = (0..<120).map { index inlet t = Float(index) / 119guard t > 0.08, t < 0.92else { return0.02 }let speech = abs(sin(Float(index) * 0.9) * 0.55 + sin(Float(index) * 0.37) * 0.35)return min(1, 0.18 + speech) }}