0

在这里训练的 MIDI 菜鸟...我一直在使用 MusicPlayer/MusicSequence/MusicTrack 在运行 iOS 的设备上播放 MIDI 音符。音符弹得很好。我正在努力改变正在演奏的乐器。据我所知,这是如何做到的:

-(void) setInstrument:(MIDIInstruments) program channel:(int) channel MusicTrack:(MusicTrack*) track time:(float) time {
    if(channel < 0 || channel > 15 || program >=MIDI_INSTRUMENT_COUNT || time < 0) {
        return;
    }

    MIDIChannelMessage programChange = { ((UInt8)0xC) << 4 | ((UInt8)channel), ((UInt8)program), 0, 0};

    OSStatus result = MusicTrackNewMIDIChannelEvent(*track, time, &programChange);
    if(result != noErr) {
        [NSException raise:@"Set Instrument" format:@"Failed to set instrument error: %@", [NSError errorWithDomain:NSOSStatusErrorDomain code:result userInfo:nil]];
    }
}

在这种情况下,通道为 0 或 1,我在有效乐器枚举范围内尝试了几种乐器,时间为 0.0,MusicTrack 有效,并且有约 30 秒的音符事件。设置通道事件的调用传回 noErr。我被难住了……有人吗?

4

1 回答 1

0

我在其他帖子中读到过,我可以使用音乐播放器和朋友生成 midi。它提供程序更改。所以,我认为它是受支持的。在用尽了所有的理论之后,我转向了AUGraph。我添加了一个我在网上找到的 *.sf2 文件,实例化了AUGraph, two AudioUnits, aMidiEndpointRef和 a MidiClientRef; 根据本教程

MusicDeviceMIDIEvent正是在端点回调中,我不得不在samplerUnit似乎允许程序更改的情况下打开和关闭笔记。而之前我只是将音符事件加载到 aMusicTrack并播放/停止MusicPlayer.

于 2013-12-08T01:11:45.593 回答