@@ -15,19 +15,19 @@ open class Sequencer {
1515 /// Overall playback speed
1616 open var tempo : BPM {
1717 get { return tracks. first? . tempo ?? 0 }
18- set { for track in tracks { track . tempo = newValue } }
18+ set { tracks. forEach { $0 . tempo = newValue } }
1919 }
2020
2121 /// Length in beats
2222 open var length : Double {
2323 get { return tracks. max ( by: { $0. length > $1. length } ) ? . length ?? 0 }
24- set { for track in tracks { track . length = newValue } }
24+ set { tracks. forEach { $0 . length = newValue } }
2525 }
2626
2727 /// Whether or not looping is enabled
2828 open var loopEnabled : Bool {
2929 get { return tracks. first? . loopEnabled ?? false }
30- set { for track in tracks { track . loopEnabled = newValue } }
30+ set { tracks. forEach { $0 . loopEnabled = newValue } }
3131 }
3232
3333 /// Is the sequencer currently playing
@@ -63,27 +63,27 @@ open class Sequencer {
6363
6464 /// Start playback of the track from the current position (like unpause)
6565 public func play( ) {
66- for track in tracks { track . play ( ) }
66+ tracks. forEach { $0 . play ( ) }
6767 }
6868
6969 /// Start the playback of the track from the beginning
7070 public func playFromStart( ) {
71- for track in tracks { track . playFromStart ( ) }
71+ tracks. forEach { $0 . playFromStart ( ) }
7272 }
7373
7474 /// Start playback after a certain number of beats
7575 public func playAfterDelay( beats: Double ) {
76- for track in tracks { track . playAfterDelay ( beats: beats) }
76+ tracks. forEach { $0 . playAfterDelay ( beats: beats) }
7777 }
7878
7979 /// Stop playback
8080 public func stop( ) {
81- for track in tracks { track . stop ( ) }
81+ tracks. forEach { $0 . stop ( ) }
8282 }
8383
8484 /// Rewind playback
8585 public func rewind( ) {
86- for track in tracks { track . rewind ( ) }
86+ tracks. forEach { $0 . rewind ( ) }
8787 }
8888
8989 /// Load MIDI data from a file URL
@@ -117,14 +117,15 @@ open class Sequencer {
117117 length = tracks. max ( by: { $0. length > $1. length } ) ? . length ?? 0
118118 }
119119
120- /// Add a MIDI note to the track
120+ /// Add a MIDI noteOn and noteOff to the track
121121 /// - Parameters:
122122 /// - noteNumber: MIDI Note number to add
123123 /// - velocity: Velocity of the note
124124 /// - channel: Channel to place the note on
125125 /// - position: Location in beats of the new note
126126 /// - duration: Duration in beats of the new note
127127 /// - trackIndex: Which track to add the note to
128+ @available ( * , deprecated, message: " Access track directly for editing - sequencer.tracks[i].add(...) " )
128129 public func add( noteNumber: MIDINoteNumber ,
129130 velocity: MIDIVelocity = 127 ,
130131 channel: MIDIChannel = 0 ,
@@ -147,6 +148,7 @@ open class Sequencer {
147148 /// - event: Event to add
148149 /// - position: Location in time in beats to add the event at
149150 /// - trackIndex: Which track to add the event
151+ @available ( * , deprecated, message: " Access track directly for editing - sequencer.tracks[i].add(...) " )
150152 public func add( event: MIDIEvent , position: Double , trackIndex: Int = 0 ) {
151153 guard tracks. count > trackIndex, trackIndex >= 0 else {
152154 Log ( " Track index \( trackIndex) out of range (sequencer has \( tracks. count) tracks) " )
@@ -157,9 +159,7 @@ open class Sequencer {
157159
158160 /// Remove all notes
159161 public func clear( ) {
160- for track in tracks {
161- track. clear ( )
162- }
162+ tracks. forEach { $0. clear ( ) }
163163 }
164164
165165 /// Move to a new time in the playback
@@ -183,7 +183,7 @@ open class Sequencer {
183183 /// Add track associated with a node
184184 /// - Parameter node: Node to create the track for
185185 /// - Returns: Track associated with the given node
186- public func addTrack( for node: Node ) -> SequencerTrack {
186+ @ discardableResult public func addTrack( for node: Node ) -> SequencerTrack {
187187 let track = SequencerTrack ( targetNode: node)
188188 tracks. append ( track)
189189 return track
0 commit comments