libretro.drivers.midi.generator

MidiDriver implementation that streams events produced by a generator function.

See also

MidiDriver

The protocol this driver implements.

Classes

GeneratorMidiDriver

A MidiDriver that streams input bytes from a generator function.

MidiWrite

A record of a MIDI write event from the core.

class GeneratorMidiDriver[source]

Bases: MidiDriver

A MidiDriver that streams input bytes from a generator function.

Output bytes are appended to an in-memory buffer accessible through output so tests can assert on what the core sent.

See also

MidiDriver

The protocol this class implements.

__init__(generator=None)[source]

Initialize the driver with an optional MIDI input source.

Parameters:

generator (Callable[[], Iterator[int | None]] | None) – A callable returning an iterator of MIDI input bytes (or None for “no byte this poll”), or None to disable MIDI input entirely.

property input_enabled

Whether MIDI input is currently enabled.

property output_enabled

Whether MIDI output is currently enabled.

property output

The buffered MidiWrite events produced by the core, in send order.

read()[source]

Read the next MIDI byte from the input stream.

Return type:

int | None

Returns:

The next byte (0–255), or None if no input is available.

See also

retro_midi_read_t

The C function pointer type whose signature this method implements.

write(byte, delta_time)[source]

Append a single MIDI byte to the output stream.

Parameters:
  • byte (int) – The MIDI byte (0–255) to write.

  • delta_time (int) – Time since the previous byte in microseconds.

Return type:

bool

Returns:

True if the byte was buffered for output.

See also

retro_midi_write_t

The C function pointer type whose signature this method implements.

classmethod __new__(*args, **kwargs)
flush()[source]

Send all buffered output bytes to the underlying MIDI device.

Return type:

bool

Returns:

True if the buffer was flushed successfully.

See also

retro_midi_flush_t

The C function pointer type whose signature this method implements.

class MidiWrite[source]

Bases: NamedTuple

A record of a MIDI write event from the core.

byte

Alias for field number 0

delta_time

Alias for field number 1

key in self

Return bool(key in self).

self[key]

Return self[key].

__init__()
iter(self)

Implement iter(self).

len(self)

Return len(self).

static __new__(_cls, byte, delta_time)

Create new instance of MidiWrite(byte, delta_time)

count(value, /)

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.