MidiOutPort.FromIdAsync(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
為指定的裝置建立 MidiOutPort 物件。
public:
static IAsyncOperation<IMidiOutPort ^> ^ FromIdAsync(Platform::String ^ deviceId);
/// [Windows.Foundation.Metadata.RemoteAsync]
static IAsyncOperation<IMidiOutPort> FromIdAsync(winrt::hstring const& deviceId);
[Windows.Foundation.Metadata.RemoteAsync]
public static IAsyncOperation<IMidiOutPort> FromIdAsync(string deviceId);
function fromIdAsync(deviceId)
Public Shared Function FromIdAsync (deviceId As String) As IAsyncOperation(Of IMidiOutPort)
參數
- deviceId
-
String
Platform::String
winrt::hstring
裝置識別碼,可藉由列舉系統 Windows.Devices.Enumeration.DeviceInformation.FindAllAsync上的裝置來取得。
傳回
非同步作業。 完成時, IAsyncOperation.GetResults 會傳回 MidiOutPort 物件。
- 屬性
範例
// Opens the default MIDI output device.
private async Task<IMidiOutPort> OpenDefaultMidiOut()
{
IMidiOutPort midiOut = null;
string midiOutQueryString = MidiOutPort.GetDeviceSelector();
DeviceInformationCollection midiOutDevices = await DeviceInformation.FindAllAsync(midiOutQueryString);
int selectedMidiDevice = 0;
if (0 == midiOutDevices.Count)
{
Debug.WriteLine("No Midi output devices");
return null;
}
// If there are > 1 MIDI out devices, pick the first non-integrated one.
else if (2 <= midiOutDevices.Count)
{
for (int midiDeviceIdx = 0; midiDeviceIdx < midiOutDevices.Count; midiDeviceIdx++)
{
if (false == MidiSynthesizer.IsSynthesizer(midiOutDevices[midiDeviceIdx]))
{
selectedMidiDevice = midiDeviceIdx;
break;
}
}
}
midiOut = await MidiOutPort.FromIdAsync(midiOutDevices[selectedMidiDevice].Id);
return midiOut;
}
// Opens the default MIDI output device.
winrt::Windows::Foundation::IAsyncOperation<IMidiOutPort> OpenDefaultMidiOut()
{
IMidiOutPort midiOut{ nullptr };
winrt::hstring midiOutQueryString{ MidiOutPort::GetDeviceSelector() };
DeviceInformationCollection midiOutDevices{ co_await DeviceInformation::FindAllAsync(midiOutQueryString) };
uint32_t selectedMidiDevice{ 0 };
if (0 == midiOutDevices.Size())
{
// No Midi output devices.
co_return midiOut;
}
// If there are > 1 MIDI out devices, pick the first non-integrated one.
else if (2 <= midiOutDevices.Size())
{
for (uint32_t midiDeviceIdx = 0; midiDeviceIdx < midiOutDevices.Size(); midiDeviceIdx++)
{
if (false == MidiSynthesizer::IsSynthesizer(midiOutDevices.GetAt(midiDeviceIdx)))
{
selectedMidiDevice = midiDeviceIdx;
break;
}
}
}
midiOut = co_await MidiOutPort::FromIdAsync(midiOutDevices.GetAt(selectedMidiDevice).Id());
co_return midiOut;
}
備註
若要列舉系統上的 MidiOutPort 物件,請將 GetDeviceSelector 所提供的查詢字串傳遞至 Windows.Devices.Enumeration.DeviceInformation.FindAllAsync。
嘗試建立 MidiInPort 的建議時間是在任何類型的應用程式啟用或使用者互動上。 如果 MidiInPort 上的函式呼叫失敗,或從 MidiInPort 收到的訊息無效,請勿嘗試立即重新建立埠。