Plush

Midi#

PlushEngine · Type index

Namespace: PlushEngine

Every connected MIDI keyboard (or other MIDI input), read like the keyboard and gamepad: held keys, press and release edges that last one simulation step, the velocity a key was struck with, controllers (the sustain pedal is 64) and pitch bend. All devices and channels are merged. Keys are notes: Midi.WasPressed("C-5") is middle C. Reading MIDI never plays anything; play the note yourself (Scene.PlaySound(Piano, press.Note.Louder(...))) so a game decides what a key does. Devices plugged in while the game runs are picked up within a second.

public static class Midi

Usage and examples

Members: Controller · Devices · Enabled · Events · IsConnected · IsDown · PitchBend · Presses · Status · Sustain · Velocity · VelocityDb · WasPressed · WasReleased

Controller#

public static float Controller(int number);

A controller's value 0 to 1 (64 sustain pedal, 1 mod wheel, 7 volume, 11 expression).

Devices#

public static IReadOnlyList<string> Devices { get; }

Initial value: []

The connected inputs' names.

Enabled#

public static bool Enabled { get; set; }

Initial value: Environment.GetEnvironmentVariable("PLUSH_NO_MIDI") == null

Hosts and tests: when false no device is opened (also set by PLUSH_NO_MIDI).

Events#

public static IReadOnlyList<MidiNoteEvent> Events { get; }

Keys pressed and released during this step, in the order they were played.

IsConnected#

public static bool IsConnected { get; }

True while at least one MIDI input is connected.

IsDown#

public static bool IsDown(Note note);

True while the key is held.

PitchBend#

public static float PitchBend { get; }

The pitch wheel, -1 (down) to 1 (up); 0 at rest.

Presses#

public static IReadOnlyList<MidiNoteEvent> Presses { get; }

Only the presses of Events.

Status#

public static string Status { get; }

Initial value: ""

Why MIDI is not available, or empty when it is (no devices is not an error).

Sustain#

public static bool Sustain { get; }

True while the sustain pedal is down.

Velocity#

public static int Velocity(Note note);

The velocity (1 to 127) the held key was struck with, or 0 when it is up.

VelocityDb#

public static float VelocityDb(int velocity);

A note as a volume change for its velocity: velocity 127 is 0 dB and the level falls with the velocity squared, as a piano does (64 is about -12 dB).

WasPressed#

public static bool WasPressed(Note note);

True during the step a key went down (a key struck twice in one step counts once here; see Presses).

WasReleased#

public static bool WasReleased(Note note);

True during the step a key came up.

MidiNoteEvent · Note

Source#