From ac8142bae4cbac6b45b5f206d439151389d1e799 Mon Sep 17 00:00:00 2001 From: Chris Flesner Date: Thu, 17 Mar 2016 17:27:18 -0500 Subject: [PATCH] Added maximumLookAheadInterval property to MIKMIDISequencer --- Source/MIKMIDISequencer.h | 9 +++++++++ Source/MIKMIDISequencer.m | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Source/MIKMIDISequencer.h b/Source/MIKMIDISequencer.h index 470a27d0..790212d3 100644 --- a/Source/MIKMIDISequencer.h +++ b/Source/MIKMIDISequencer.h @@ -414,6 +414,15 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly) MIDITimeStamp latestScheduledMIDITimeStamp; + +/** + * The maximum amount the sequencer will look ahead to schedule MIDI events. (0.05 to 1s). + * + * The default of 0.1s should suffice for most uses. You may however, need a longer time + * if your sequencer needs to playback on iOS while the device is locked. + */ +@property (nonatomic) NSTimeInterval maximumLookAheadInterval; + #pragma mark - Deprecated /** diff --git a/Source/MIKMIDISequencer.m b/Source/MIKMIDISequencer.m index 06a40b0e..91a21a43 100644 --- a/Source/MIKMIDISequencer.m +++ b/Source/MIKMIDISequencer.m @@ -115,6 +115,7 @@ - (instancetype)initWithSequence:(MIKMIDISequence *)sequence _createSynthsIfNeeded = YES; _processingQueueKey = &_processingQueueKey; _processingQueueContext = &_processingQueueContext; + _maximumLookAheadInterval = 0.1; } return self; } @@ -275,7 +276,7 @@ - (void)stopWithDispatchToProcessingQueue:(BOOL)dispatchToProcessingQueue - (void)processSequenceStartingFromMIDITimeStamp:(MIDITimeStamp)fromMIDITimeStamp { - MIDITimeStamp toMIDITimeStamp = MIKMIDIGetCurrentTimeStamp() + MIKMIDIClockMIDITimeStampsPerTimeInterval(0.1); + MIDITimeStamp toMIDITimeStamp = MIKMIDIGetCurrentTimeStamp() + MIKMIDIClockMIDITimeStampsPerTimeInterval(self.maximumLookAheadInterval); if (toMIDITimeStamp < fromMIDITimeStamp) return; MIKMIDIClock *clock = self.clock; @@ -820,6 +821,11 @@ - (void)setSequence:(MIKMIDISequence *)sequence } } +- (void)setMaximumLookAheadInterval:(NSTimeInterval)maximumLookAheadInterval +{ + _maximumLookAheadInterval = MIN(MAX(maximumLookAheadInterval, 0.05), 1.0); +} + #pragma mark - Deprecated - (void)setDestinationEndpoint:(MIKMIDIDestinationEndpoint *)endpoint forTrack:(MIKMIDITrack *)track