Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoteEventSequence totalDuration calculation #29

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Sources/AudioKitEX/Sequencing/Sequence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ public struct NoteEventSequence: Equatable {
channel: MIDIChannel = 0,
position: Double,
duration: Double) {
totalDuration += duration

let noteEndTime = position + duration
totalDuration = max(totalDuration, noteEndTime)

var newNote = SequenceNote()

newNote.noteOn.status = noteOnByte
Expand Down
9 changes: 5 additions & 4 deletions Sources/AudioKitEX/Sequencing/SequencerTrack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ open class SequencerTrack {
/// Sequence on this track
public var sequence = NoteEventSequence() {
willSet {
if newValue.totalDuration >= length {
Log("Warning: Note event sequence duration exceeds the bounds of the sequencer track")
length = newValue.totalDuration + 0.01
Log("Track length set to \(length) beats")
if newValue.totalDuration != 0.0 && newValue.totalDuration > length {
Log("Warning: Note event sequence duration exceeds the bounds of the sequencer track")
/// extend the length to accomodate the new notes
length = newValue.totalDuration
Log("Track length set to \(length) beats")
}
}
didSet { updateSequence() }
Expand Down