有人可以提供示例代码,说明如何在一个Performance中,一个MusicPort,加载和播放两个midis(midi 1中的频道0-15并使用另一个频道组播放midi 2&0 39的?)我尝试过在音乐端口上分配PChannelBlock并在分段上设置SetPChannel,但它只播放第一个midi片刻,之后才播放第二个。我找不到任何例子,而且不幸的是我不能为我工作。
基本上在我的测试中我做了(某些步骤被跳过,但是默认)
端口是Microsoft Synthesizer
HRESULT hr = S_OK;
DMUS_PORTPARAMS portParams;
ZeroMemory(&portParams, sizeof(DMUS_PORTPARAMS));
portParams.dwSize = sizeof(DMUS_PORTPARAMS);
portParams.dwChannelGroups = 2;
portParams.dwValidParams = DMUS_PORTPARAMS_CHANNELGROUPS;
if (midiPort.dwFlags & DMUS_PC_AUDIOPATH)
portParams.dwFeatures = DMUS_PORT_FEATURE_AUDIOPATH;
portParams.dwEffectFlags = DMUS_EFFECT_REVERB;
if (FAILED(hr = mMusic8->CreatePort(midiPort.guidPort, &portParams, &mMusicPort, NULL)))
return hr;
...
if (FAILED(hr = mPerformance->AddPort(mMusicPort)))
return hr;
if (FAILED(hr = mPerformance->AssignPChannelBlock(0, mMusicPort, 1)))
return hr;
if (FAILED(hr = mPerformance->AssignPChannelBlock(1, mMusicPort, 2)))
return hr;
...
// chan1 is DWORD array 0 to 0xF
mSegment1->SetPChannelsUsed(0x10, chan1);
// chan2 is DWORD array 10 to 0x1F
mSegment2->SetPChannelsUsed(0x10, chan2);
if (FAILED(hr = mSegment1->SetParam(GUID_StandardMIDIFile, 0xFFFFFFFF, 0, 0, NULL)))
return hr;
if (FAILED(hr = mSegment1->Download(mPerformance)))
return hr;
if (FAILED(hr = mSegment2->SetParam(GUID_StandardMIDIFile, 0xFFFFFFFF, 0, 0, NULL)))
return hr;
if (FAILED(hr = mSegment2->Download(mPerformance)))
return hr;
...
if (FAILED(hr = mPerformance->PlaySegment(mSegment1, 0, 0, &segmentState1)))
return hr;
if (FAILED(hr = mPerformance->PlaySegment(mSegment2, 0, 0, &segmentState2)))
return hr;
...