Rich
Rich

Reputation: 7795

Play a MIDI file in Windows Store app

I need to play a MIDI file from a Windows Store app. (i.e. the app itself should generate sound in software—I don't want to output MIDI to a hardware device.)

I was hoping for some simple API/library where I can just pass in the location of the file and possibly a sound font, and call a "play" function, but I have been unable to find such a thing. e.g. FluidSynth looks like it will do just this, but it doesn't have a version for Windows Store apps.

Microsoft recently introduced a new Windows Runtime API for MIDI, but this does not include any code for dealing with MIDI files.

The open source library NAudio does apparently include code for reading MIDI files, so I think what I need to implement is something that opens the file with NAudio, reads in/parses the MIDI events, and then plays them back through the Microsoft GS Wavetable Synth software device via the new MIDI preview API (implementing my own scheduling so messages are sent at the correct time).

Update: Microsoft's sample code for enumerating MIDI ports lists the USB MIDI devices while they are attached, but with no USB devices attached it reports "No MIDI ports".

N.B. The sample code enumerates ports by passing the return value of MidiOutPort::GetDeviceSelector into the DeviceInformation::FindAllAsync method. This should, as far as I can see, list all available MIDI devices.

However, on the same computer a Microsoft synth is found in Desktop apps e.g. via DirectMusic's EnumPort method.

Does this mean there is no default software synth available to Windows Store apps? Do I also need to implement my own synth?

Update 2: I've now found some comments from Microsoft staff members confirming that the WindowsPreview MIDI API does not support the default software synthesizer.

Will this work? Is it the correct approach? Is there a simpler method/API/third-party library I've missed?

Update 3: It looks like the WinRT version of NAudio doesn't include the MIDI functionality, so it seems I'll be building both the MIDI sequencer and the synth from scratch. (Perhaps using NAudio within the synth implementation.)

Upvotes: 3

Views: 856

Answers (1)

Kevin Walsh
Kevin Walsh

Reputation: 114

This is an aging question, but for the sake of completeness I wanted to answer the part about available synths. Microsoft has surfaced the Microsoft General Midi Wave Table Synth to store apps via a nuget package. It works great with the new Midi API's in UWP. You might also want to check out Leslie Sanford's C# Midi Library for a good starting point for a basic sequencer. It uses the Win32 MM libraries via P/Invoke but it would be simple enough to retrofit the new Midi Api's.

Upvotes: 2

Related Questions