Skip to content

Daniel127/RtMidi.Net

Repository files navigation

Status

Quality Gate Lines of Code Bugs Coverage Maintainability Rating

Branch Build Deployment
main Build Build Status Nuget package
develop Build Build Status N/A

What is it?

This project is a .NET wrapper for the RtMidi project.

I have created it to use it in an own project in RaspberryPi with a very basic utility as it is the reading of the notes, nevertheless I have done it thinking of being able to use all the options of the MIDI protocol, although I have not come to test them all.

If you find any error or have any improvement do not hesitate to make a PR.

How to use?

To connect to a device you can use the MidiInputClient and MidiOutputClient classes, MidiManager has useful methods to know the environment.

There is a project (WorkerTest) to test the key reading but it really receives any kind of MIDI message so don't hesitate to extend it if you need it.

If you subscribe to the OnMessageReceived event of the MidiInputClient don't forget to use ActivateMessageReceivedEvent for this event to work, this is because RtMidi includes a queue to store the events and later you can read the events with GetMessage, if you need to stop reading the events in real time you can use DeactivateMessageReceivedEvent to deactivate the event.

uint devicePort = 0;
var device = MidiManager.GetDeviceInfo(devicePort, RtMidi.Net.Enums.MidiDeviceType.Input);
MidiInputClient midiInputClient = new MidiInputClient(device);
midiInputClient.OnMessageReceived += MidiClient_OnMessageReceived;
midiInputClient.ActivateMessageReceivedEvent();
midiInputClient.Open();

//...wait or do something...

midiInputClient.Close();
midiInputClient.Dispose();