c# 如何使用 Windows.Devices.Midi 将 MIDI 消息发送到内置的 Microsoft GS Wavetable Synth?
c# How do I send MIDI messages to the built in Microsoft GS Wavetable Synth using Windows.Devices.Midi?
我正在尝试在 Windows 通用应用程序中使用 C# 将 MIDI 消息发送到 Windows 10 上的内置 Microsoft GS Wavetable Synth。但是,检索 IMidiOutPort 对象的代码(outputPort = await MidiOutPort.FromIdAsync(outputDevice.Id);
) 始终 returns 为空。如何将 MIDI 消息发送到内置合成器?
对 MidiInPort 使用类似的代码可以完美地与外部 MIDI 键盘配合使用。不幸的是,键盘没有 MIDI,否则我会尝试发送给它以尝试缩小可能性。
附带说明一下,创建 MidiSynthesizer (MidiSynthesizer synth = await MidiSynthesizer.CreateAsync();
) 的代码也 returns null。
using System;
using Windows.Devices.Enumeration;
using Windows.Devices.Midi;
using Windows.UI.Xaml.Controls;
namespace HelloMidi
{
public sealed partial class MainPage : Page
{
IMidiOutPort outputPort;
DeviceInformation outputDevice;
DeviceInformationCollection outputDevices;
public MainPage()
{
this.InitializeComponent();
Connect();
}
public async void Connect()
{
outputDevices = await DeviceInformation.FindAllAsync(MidiOutPort.GetDeviceSelector());
outputList.DisplayMemberPath = "Name";
outputList.ItemsSource = outputDevices;
outputList.SelectionMode = SelectionMode.Single;
outputList.SelectionChanged += OutputList_SelectionChanged;
}
private async void OutputList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (outputPort != null)
outputPort.Dispose();
if (e.AddedItems.Count > 0)
outputDevice = (DeviceInformation)e.AddedItems[0];
if (outputDevice != null)
outputPort = await MidiOutPort.FromIdAsync(outputDevice.Id);
if (outputPort != null)
outputPort.SendMessage(new MidiStartMessage());
}
}
}
我遇到了同样的问题。但我注意到通用应用程序示例中的 MIDI 应用程序有效。我在 .csproj 文件中发现了一个差异,特别是有一个对 "Microsoft General MIDI DLS for Universal Windows Apps" 的引用。添加此引用后,我能够将输出发送到波表合成器。
在 Windows 开发中心 MIDI article
中有说明
Using the built-in Windows General MIDI synth
When you enumerate output MIDI devices using the technique described above, your app will discover a MIDI device called "Microsoft GS Wavetable Synth". This is a built-in General MIDI synthesizer that you can play from your app. However, attempting to create a MIDI outport to this device will fail unless you have included the SDK extension for the built-in synth in your project.
To include the General MIDI Synth SDK extension in your app project
- In Solution Explorer, under your project, right-click References and select Add reference...
- Expand the Universal Windows node.
- Select Extensions.
- From the list of extensions, select Microsoft General MIDI DLS for Universal Windows Apps.
- NOTE If there are multiple versions of the extension, be sure to select the version that matches the target for your app. You can see which SDK version your app is targeting on the Application tab of the project Properties.
我正在尝试在 Windows 通用应用程序中使用 C# 将 MIDI 消息发送到 Windows 10 上的内置 Microsoft GS Wavetable Synth。但是,检索 IMidiOutPort 对象的代码(outputPort = await MidiOutPort.FromIdAsync(outputDevice.Id);
) 始终 returns 为空。如何将 MIDI 消息发送到内置合成器?
对 MidiInPort 使用类似的代码可以完美地与外部 MIDI 键盘配合使用。不幸的是,键盘没有 MIDI,否则我会尝试发送给它以尝试缩小可能性。
附带说明一下,创建 MidiSynthesizer (MidiSynthesizer synth = await MidiSynthesizer.CreateAsync();
) 的代码也 returns null。
using System;
using Windows.Devices.Enumeration;
using Windows.Devices.Midi;
using Windows.UI.Xaml.Controls;
namespace HelloMidi
{
public sealed partial class MainPage : Page
{
IMidiOutPort outputPort;
DeviceInformation outputDevice;
DeviceInformationCollection outputDevices;
public MainPage()
{
this.InitializeComponent();
Connect();
}
public async void Connect()
{
outputDevices = await DeviceInformation.FindAllAsync(MidiOutPort.GetDeviceSelector());
outputList.DisplayMemberPath = "Name";
outputList.ItemsSource = outputDevices;
outputList.SelectionMode = SelectionMode.Single;
outputList.SelectionChanged += OutputList_SelectionChanged;
}
private async void OutputList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (outputPort != null)
outputPort.Dispose();
if (e.AddedItems.Count > 0)
outputDevice = (DeviceInformation)e.AddedItems[0];
if (outputDevice != null)
outputPort = await MidiOutPort.FromIdAsync(outputDevice.Id);
if (outputPort != null)
outputPort.SendMessage(new MidiStartMessage());
}
}
}
我遇到了同样的问题。但我注意到通用应用程序示例中的 MIDI 应用程序有效。我在 .csproj 文件中发现了一个差异,特别是有一个对 "Microsoft General MIDI DLS for Universal Windows Apps" 的引用。添加此引用后,我能够将输出发送到波表合成器。
在 Windows 开发中心 MIDI article
中有说明Using the built-in Windows General MIDI synth
When you enumerate output MIDI devices using the technique described above, your app will discover a MIDI device called "Microsoft GS Wavetable Synth". This is a built-in General MIDI synthesizer that you can play from your app. However, attempting to create a MIDI outport to this device will fail unless you have included the SDK extension for the built-in synth in your project.
To include the General MIDI Synth SDK extension in your app project
- In Solution Explorer, under your project, right-click References and select Add reference...
- Expand the Universal Windows node.
- Select Extensions.
- From the list of extensions, select Microsoft General MIDI DLS for Universal Windows Apps.
- NOTE If there are multiple versions of the extension, be sure to select the version that matches the target for your app. You can see which SDK version your app is targeting on the Application tab of the project Properties.