Color legend plain property method event
Finds MIDI input devices, connects to one, and tracks the notes held on it, bringing what Windows reports to the game thread.
A static class, in the namespace BorrowedTorch.MonoInput.Inputs.Midi. It starts watching for devices the first time your code touches it, and wants Dispose when the game ends. What Windows reports on its own threads waits in a queue until Update, so its events are raised on the game thread. The MIDI page shows it in context, with code.
Names are colored by what they are: a property, a method or an event; values and fields keep the plain color.
Properties
ActiveNotes →
ActiveInputs<NoteStatus> · Static, read-only. Every note that isn’t idle, in the order they were first pressed: a live view, the same object for the whole run. Empty after Dispose.
Devices →
IReadOnlyList<MidiDeviceInfo> · Static, read-only. The MIDI input devices Windows knows of, as of the last Update: empty until the first updates after the manager starts. A new list each time the devices change, so a list you hold doesn’t change under you; reading it doesn’t allocate.
Disposed →
bool · Static, read-only. Dispose has run: the manager does nothing more, for the rest of the process.
SelectedDevice →
MidiDeviceInfo · Static, read-only. The device notes come from, or null. Set when OnDeviceSelected is raised: after a connection, when the device is removed, and by Dispose.
Methods
Dispose() →
Dispose() · Static. Shuts MIDI down: sets SelectedDevice to null and raises OnDeviceSelected one last time, removes every handler of both events, empties ActiveNotes without an Up update, closes the device and stops watching for devices. Later calls do nothing, and the manager can’t be started again.
TryConnectToMidiDevice() →
TryConnectToMidiDevice(string deviceId) · Static. Returns a Task. Closes the device connected before, at once, then opens this one in the background. The outcome comes at a later Update, through OnDeviceSelected: the device, or null when it couldn’t be opened. The task ends before that, so don’t read SelectedDevice right after awaiting it. Only the latest call reports. Doesn’t throw for a device that can’t be opened, and does nothing after Dispose.
| Parameter | Type | Description |
|---|---|---|
deviceId |
string |
The Id of one of Devices. |
Update() →
Update() · Static. Takes in what Windows reported since the update before: device changes first, raising OnDevicesChanged, then connection outcomes, raising OnDeviceSelected, then notes in the order they came; then moves every note one step. Call it once per frame. Does nothing after Dispose.
Events
OnDevicesChanged →
Action · Static. Devices changed: a device appeared or was removed. Raised from Update; when the selected device was removed, OnDeviceSelected comes first.
OnDeviceSelected →
Action<MidiDeviceInfo> · Static. SelectedDevice was set, and the handler gets it: the device after a connection, null when the connection failed, when the device was removed, and in Dispose. Raised from Update, or from Dispose.