Advice from the Lizard:
Performance at Swan Hall:
Music.swift
Nice quests but Ode to Joy it's headshot :D
Code Block let notes: [Note] = [Note.quarter(.a4), .quarter(.b4), .quarter(.c4)]
Performance at Swan Hall:
Code Block language func performance(owner: Assessable) { let toneOutput = ToneOutput() let qPitches:[Pitch] = [.e3, .e3, .f3, .g3, .g3, .f3, .e3, .d3, .c3, .c3, .d3, .e3, .e3, .d3] let hPitches:[Pitch] = [.d3] let notes: [Note] = qPitches.map{Note.quarter($0)} + hPitches.map{Note.half($0)} var pitches = [Pitch]() for note in notes { pitches.append(contentsOf: note.subdivide()) } var index = 0 let interval = TimeInterval(Note.shortestSupportedNoteLength * 0.5) Timer.scheduledTimer(withTimeInterval: interval, repeats: true) { timer in guard index < pitches.count else { toneOutput.stopTones() timer.invalidate() owner.endPerformance() return } toneOutput.play(tone: Tone(pitch: pitches[index].frequency, volume: 0.3)) index += 1 } owner.endPerformance() }
Music.swift
Code Block language public enum Note : NoteProtocol { case quarter(Pitch) case half(Pitch) /// Play this Note through a ToneOutput public var tone: Tone { switch self { case .quarter(let pitch): return Tone(pitch: pitch.frequency, volume: 0.3) case .half(let pitch): return Tone(pitch: pitch.frequency, volume: 0.3) } } /// The duration of this Note as a multiple of quarter notes, e.g., a half note would equal 2.0, an eight note public var length: Float { switch self { case .quarter(_): return 1.0 case .half(_): return 2.0 } } /// Length of the smallest Note supported public static var shortestSupportedNoteLength: Float { return Note.quarter(.a4).length } /// Subdivide into a series pitches, according to the shortest supported note public func subdivide() -> [Pitch] { switch self { case .quarter(let pitch): return [pitch] case .half(let pitch): return [pitch, pitch] } } }
Nice quests but Ode to Joy it's headshot :D