Reputation: 1443
I'm 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's working well, I would say very well, but I do not want to use the internal clock.
How can I use the external midi clock?
Or maybe I can somehow move the playing cursor with a clock.
Upvotes: 3
Views: 505
Reputation: 5257
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 the sync mode
UInt32 tSyncMode = kCAClockSyncMode_MIDIClockTransport;
size = sizeof(tSyncMode);
err = CAClockSetProperty(mtcClockRef, kCAClockProperty_SyncMode, size, &tSyncMode);
then set the clock to use the midi end point
err = CAClockSetProperty(mtcClockRef, kCAClockProperty_SyncSource, sizeof(endpointRef), endpointRef);
There's some reference code VVMIDINode here - > https://github.com/mrRay/vvopensource/blob/master/VVMIDI/FrameworkSrc/VVMIDINode.h
Upvotes: 1