Skip to content

Commit

Permalink
Issue #99: MIKMIDISequencer now respects MIKMIDITrack's offset proper…
Browse files Browse the repository at this point in the history
…ty (for non-tempo tracks).
  • Loading branch information
Andrew Madsen committed Mar 8, 2016
1 parent f05760c commit 7c28b0c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Source/MIKMIDINoteEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) Float32 duration;

/**
* The time stamp at the end of the notes duration.
* The time stamp at the end of the notes duration. This is simply the event's timeStamp + duration.
*/
@property (nonatomic, readonly) MusicTimeStamp endTimeStamp;

Expand Down
15 changes: 14 additions & 1 deletion Source/MIKMIDISequencer.m
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,20 @@ - (void)processSequenceStartingFromMIDITimeStamp:(MIDITimeStamp)fromMIDITimeStam
NSArray *tracksToPlay = soloTracks.count != 0 ? soloTracks : nonMutedTracks;

for (MIKMIDITrack *track in tracksToPlay) {
NSArray *events = [track eventsFromTimeStamp:MAX(fromMusicTimeStamp - playbackOffset, 0) toTimeStamp:toMusicTimeStamp - playbackOffset];
MusicTimeStamp startTimeStamp = MAX(fromMusicTimeStamp - playbackOffset - track.offset, 0);
MusicTimeStamp endTimeStamp = toMusicTimeStamp - playbackOffset - track.offset;
NSArray *events = [track eventsFromTimeStamp:startTimeStamp toTimeStamp:endTimeStamp];
if (track.offset != 0) {
// Shift events by offset
NSMutableArray *shiftedEvents = [NSMutableArray array];
for (MIKMIDIEvent *event in events) {
MIKMutableMIDIEvent *shiftedEvent = [event mutableCopy];
shiftedEvent.timeStamp += track.offset;
[shiftedEvents addObject:shiftedEvent];
}
events = shiftedEvents;
}

id<MIKMIDICommandScheduler> destination = events.count ? [self commandSchedulerForTrack:track] : nil; // only get the destination if there's events so we don't create a destination endpoint if not needed
for (MIKMIDIEvent *event in events) {
NSNumber *timeStampKey = @(event.timeStamp + playbackOffset);
Expand Down

0 comments on commit 7c28b0c

Please sign in to comment.