IOS MusicSequence & MusicPlayer for external midi sync
I am using MusicPlayer to play notes in MusicSequence:
NewMusicSequence(&sequence);
MusicSequenceFileLoad(sequence, (__bridge CFURLRef) midiFileURL, 0, 0);
// Set the endpoint of the sequence to be our virtual endpoint
MusicSequenceSetMIDIEndpoint(sequence, virtualEndpoint);
// Create a new music player
MusicPlayer p;
// Initialise the music player
NewMusicPlayer(&p);
// Load the sequence into the music player
MusicPlayerSetSequence(self.player, sequence);
// Called to do some MusicPlayer setup. This just
// reduces latency when MusicPlayerStart is called
MusicPlayerPreroll(self.player);
-(void)play {
MusicPlayerStart(self.player);
}
It works well, I would say very well, but I don't want to use the internal clock.
How can I use an external midi clock?
Or maybe I can somehow move the game cursor with the clock.
+3
source to share
1 answer
You can use MusicSequenceSetMIDIEndpoint (sequence, endpointRef);
then create a midi clock
CAClockRef mtcClockRef;
OSStatus err;
err = CAClockNew(0, &mtcClockRef);
if (err != noErr) {
NSLog(@"\t\terror %ld at CAClockNew()", err);
}
else {
CAClockTimebase timebase = kCAClockTimebase_HostTime;
UInt32 size = 0;
size = sizeof(timebase);
err = CAClockSetProperty(mtcClockRef, kCAClockProperty_InternalTimebase, size, &timebase);
if (err)
NSLog(@"Error setting clock timebase");
set sync mode
UInt32 tSyncMode = kCAClockSyncMode_MIDIClockTransport;
size = sizeof(tSyncMode);
err = CAClockSetProperty(mtcClockRef, kCAClockProperty_SyncMode, size, &tSyncMode);
then set the clock to use the midi endpoint
err = CAClockSetProperty(mtcClockRef, kCAClockProperty_SyncSource, sizeof(endpointRef), endpointRef);
There is VVMIDINode link code here -> https://github.com/mrRay/vvopensource/blob/master/VVMIDI/FrameworkSrc/VVMIDINode.h
+1
source to share