diff --git a/Sources/AudioKitEX/Sequencing/Sequence.swift b/Sources/AudioKitEX/Sequencing/Sequence.swift index 3f65690..3c9a640 100644 --- a/Sources/AudioKitEX/Sequencing/Sequence.swift +++ b/Sources/AudioKitEX/Sequencing/Sequence.swift @@ -87,7 +87,7 @@ public struct NoteEventSequence: Equatable { channel: MIDIChannel = 0, position: Double, duration: Double) { - totalDuration += duration + totalDuration = max(totalDuration, position + duration) // Compare latest note position and duration to current totalDuration. var newNote = SequenceNote() newNote.noteOn.status = noteOnByte diff --git a/Tests/AudioKitEXTests/SequencerTrackTests.swift b/Tests/AudioKitEXTests/SequencerTrackTests.swift index 97f14dc..d3548e4 100644 --- a/Tests/AudioKitEXTests/SequencerTrackTests.swift +++ b/Tests/AudioKitEXTests/SequencerTrackTests.swift @@ -124,11 +124,24 @@ class SequencerTrackTests: XCTestCase { let track = SequencerTrack(targetNode: sampler) engine.output = sampler + track.add(noteNumber: 60, position: 0.0, duration: 1.0) + track.add(noteNumber: 60, position: 0.0, duration: 1.0) + track.add(noteNumber: 60, position: 0.0, duration: 1.0) + track.add(noteNumber: 60, position: 0.0, duration: 1.0) + + XCTAssertEqual(track.length, 4, "Track length shouldn't be extended with chord duration less than existing track length") + track.add(noteNumber: 60, position: 0.0, duration: 1.0) track.add(noteNumber: 60, position: 1.0, duration: 1.0) track.add(noteNumber: 60, position: 2.0, duration: 1.0) track.add(noteNumber: 60, position: 3.0, duration: 1.0) + XCTAssertEqual(track.length, 4.01, "Track length should be extended with note event position + duration greater or equal to existing track length") + + track.add(noteNumber: 60, position: 1.0, duration: 5.0) + + XCTAssertEqual(track.length, 6.01, "Track length should be extended with note event position + duration greater or equal to existing track length") + track.playFromStart() XCTAssertTrue(track.isPlaying) let audio = engine.startTest(totalDuration: 5.0) diff --git a/Tests/AudioKitEXTests/ValidatedMD5s.swift b/Tests/AudioKitEXTests/ValidatedMD5s.swift index 839f663..50c5351 100644 --- a/Tests/AudioKitEXTests/ValidatedMD5s.swift +++ b/Tests/AudioKitEXTests/ValidatedMD5s.swift @@ -21,7 +21,7 @@ let validatedMD5s: [String: String] = [ "-[SequencerTrackTests testLoop]": "3a7ebced69ddc6669932f4ee48dabe2b", "-[SequencerTrackTests testOneShot]": "3fbf53f1139a831b3e1a284140c8a53c", "-[SequencerTrackTests testTempo]": "1eb7efc6ea54eafbe616dfa8e1a3ef36", - "-[SequencerTrackTests testNoteBounds]": "6679c7b949d28130549c6a1eb4ceaf59", + "-[SequencerTrackTests testNoteBounds]": "f3b3935e30380367c15652c0a76a8a57", "-[DryWetMixerTests testBalance0]": "789c1e77803a4f9d10063eb60ca03cea", "-[DryWetMixerTests testBalance1]": "3932bc5d49cbefd4a9dd587d16f4b81c", "-[DryWetMixerTests testDefault]": "45a639729d8698a28f134bbe4ccc9d6c",