Created
July 1, 2016 16:17
-
-
Save armadsen/0164408942aaa30e5cf2599bdcbe8b88 to your computer and use it in GitHub Desktop.
Quick (untested) example of getting bar-beat time for a particular timestamp in an MIKMIDISequence.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface MIKMIDISequence (BarBeatTime) | |
- (CABarBeatTime)barBeatTimeForTimeStamp:(MusicTimeStamp)timeStamp error:(NSError **)error; | |
@end | |
@implementation MIKMIDISequence (BarBeatTime) | |
- (CABarBeatTime)barBeatTimeForTimeStamp:(MusicTimeStamp)timeStamp error:(NSError **)error | |
{ | |
error = error ?: &(NSError *__autoreleasing){ nil }; | |
UInt32 timeResolution = 0; | |
UInt32 propertyLength = 0; | |
OSStatus err = MusicTrackGetProperty(self.tempoTrack.musicTrack, | |
kSequenceTrackProperty_TimeResolution, | |
NULL, | |
&propertyLength); | |
if (err != noErr) { | |
*error = [NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil]; | |
return (CABarBeatTime){0}; | |
} | |
err = MusicTrackGetProperty(self.tempoTrack.musicTrack, | |
kSequenceTrackProperty_TimeResolution, | |
&timeResolution, | |
&propertyLength); | |
if (err != noErr) { | |
*error = [NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil]; | |
return (CABarBeatTime){0}; | |
} | |
CABarBeatTime barBeatTime = {0}; | |
err = MusicSequenceBeatsToBarBeatTime(self.musicSequence, timeStamp, timeResolution, &barBeatTime); | |
if (err != noErr) { | |
*error = [NSError errorWithDomain:NSOSStatusErrorDomain code:err userInfo:nil]; | |
return (CABarBeatTime){0}; | |
} | |
return barBeatTime; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment