2014-09-26 32 views
3

我使用MusicPlayer弹奏音符这MusicSequenceIOS MusicSequence&MusicPlayer外部MIDI时钟同步

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); 
} 

它的工作好,我要说的很不错,但我不希望使用内部时钟。我怎样才能使用外部MIDI时钟?或者,也许我可以以某种方式移动光标与时钟。

回答

1

您可以使用MusicSequenceSetMIDIEndpoint(sequence,endpointRef);

然后创建一个MIDI时钟

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"); 

设置同步模式

UInt32 tSyncMode = kCAClockSyncMode_MIDIClockTransport; 
       size = sizeof(tSyncMode); 
       err = CAClockSetProperty(mtcClockRef, kCAClockProperty_SyncMode, size, &tSyncMode); 

然后将时钟设置使用MIDI终点

err = CAClockSetProperty(mtcClockRef, kCAClockProperty_SyncSource, sizeof(endpointRef), endpointRef); 

这里有一定的参考代码VVMIDINode - >https://github.com/mrRay/vvopensource/blob/master/VVMIDI/FrameworkSrc/VVMIDINode.h

+0

显然CAClock目前不支持iOS(截至8.3) – 2015-05-23 00:51:25