Austin Austin - 25 days ago 6
C# Question

c# How do I send MIDI messages to the built in Microsoft GS Wavetable Synth using Windows.Devices.Midi?

I'm trying to use C# in a Windows Universal Application to send MIDI messages to the built in Microsoft GS Wavetable Synth on Windows 10. However, the code to retrieve the IMidiOutPort object (

outputPort = await MidiOutPort.FromIdAsync(outputDevice.Id);
) always returns null. How can I send MIDI messages to the built in synthesizer?

Using similar code for MidiInPort works perfectly with an external MIDI keyboard. Unfortunately, the keyboard does not have MIDI in, otherwise I'd try sending to it to try to narrow down the possibilities.

On a side note, the code to create a MidiSynthesizer (
MidiSynthesizer synth = await MidiSynthesizer.CreateAsync();
) also 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());
}
}
}

Answer

I was having the same problem. But I noticed that the MIDI app from the universal app samples worked. I discovered a difference in the .csproj file, and in particular there was a reference to the "Microsoft General MIDI DLS for Universal Windows Apps". After adding this reference, I was able to send output to the Wavetable Synth.

There are instructions in the Windows Dev Center 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

  1. In Solution Explorer, under your project, right-click References and select Add reference...
  2. Expand the Universal Windows node.
  3. Select Extensions.
  4. From the list of extensions, select Microsoft General MIDI DLS for Universal Windows Apps.
  5. 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.