我正在使用MusicDeviceMIDIEvent创建MIDI声音,它非常好,我使用了一些我创建的aupreset文件。每种仪器一个。
我的代码基本上是来自apple的示例:LoadPresetDemo。我所用的只是:
- (void)loadPreset:(id)sender instrumentName:(const char *)instrumentName {
NSString *presetURL1 = [NSString stringWithCString:instrumentName encoding:NSUTF8StringEncoding];
NSString *path = [[NSBundle mainBundle] pathForResource:presetURL1 ofType:@"aupreset"];
NSURL *presetURL = [[NSURL alloc] initFileURLWithPath: path];
if (presetURL) {
NSLog(@"Attempting to load preset '%@'\n", [presetURL description]);
}
else {
NSLog(@"COULD NOT GET PRESET PATH!");
}
[self loadSynthFromPresetURL: presetURL];
}
要加载我的aupreset文件,请:
- (void) noteOn:(id)sender midiNumber:(int)midiNumber {
UInt32 noteNum = midiNumber;
UInt32 onVelocity = 127;
UInt32 noteCommand = kMIDIMessage_NoteOn << 4 | 0;
OSStatus result = noErr;
require_noerr (result = MusicDeviceMIDIEvent (self.samplerUnit, noteCommand, noteNum, onVelocity, 0), logTheError);
logTheError:
if (result != noErr) NSLog (@"Unable to start playing the low note. Error code: %d '%.4s'\n", (int) result, (const char *)&result);
}
播放先前加载的aupreset的音符,并且:
- (void) noteOff:(id)sender midiNumber:(int)midiNumber
当我希望它停止时。
现在我想同时播放每个乐器的一个音符。这样做最简单的方法是什么?