Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick (untested) example of getting bar-beat time for a particular timestamp in an MIKMIDISequence.
@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
You can’t perform that action at this time.