matchmaker.io

class matchmaker.io.midi.MidiStream(processor: Processor | None = None, file_path: str | None = None, polling_period: float | None = 0.01, port: BaseInput | str | None = None, queue: RECVQueue = None, init_time: float | None = None, return_midi_messages: bool = False, mediator: CeusMediator | None = None, virtual_port: bool = False)[source]

Bases: Stream

A class to process input MIDI stream in real time

Parameters

portmido.ports.BaseInput

Input MIDI port

queueRECVQueue

Queue to store processed MIDI input

init_timeOptional[float]

The initial time. If none given, the initial time will be set to the starting time of the thread.

return_midi_messages: bool

Return MIDI messages in addition to the processed features.

mediatorCeusMediator or None

A Mediator instance to filter input MIDI. This is useful for certain older instruments, like the Bösendorfer CEUS, which do not distinguish between notes played by a human, and notes sent from a different process (e.g., an accompaniment system)

__init__(processor: Processor | None = None, file_path: str | None = None, polling_period: float | None = 0.01, port: BaseInput | str | None = None, queue: RECVQueue = None, init_time: float | None = None, return_midi_messages: bool = False, mediator: CeusMediator | None = None, virtual_port: bool = False)[source]

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is a list or tuple of arguments for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

start_listening()[source]

Start listening to midi input (open input port and get starting time)

stop_listening()[source]

Stop listening to MIDI input

class matchmaker.io.audio.AudioStream(processor: Processor = None, file_path: str | None = None, sample_rate: int = 44100, hop_length: int = 1470, queue: RECVQueue | None = None, device_name_or_index: str | int | None = None, wait: bool = False, target_sr: int = 44100)[source]

Bases: Stream

A class to process an audio stream in real-time.

Parameters

processorOptional[Processor]

The processor for the features. If None, defaults to ChromagramProcessor.

file_pathOptional[str]

If given, the audio stream will be simulated using the given file as an input instead.

sample_rateint

Sample rate of the audio stream.

hop_lengthint

Hop length of the audio stream.

queueRECVQueue

Queue to store the processed audio.

device_name_or_indexOptional[Union[str, int]]

Name or index of the audio device to be used. Ignored if file_path is given.

Notes

Frame caching: each call to _process_feature prepends self.cache_size samples from the previous frame so that FFT windows wider than hop_length (e.g. SKF’s RawSpectrumProcessor with n_fft=512) have enough context. The cache size is auto-discovered at construction:

  • If processor exposes an n_fft attribute, cache_size = n_fft - hop_length.

  • Otherwise cache_size = hop_length (one previous hop).

The first frame is zero-padded by cache_size samples.

__init__(processor: Processor = None, file_path: str | None = None, sample_rate: int = 44100, hop_length: int = 1470, queue: RECVQueue | None = None, device_name_or_index: str | int | None = None, wait: bool = False, target_sr: int = 44100)[source]

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is a list or tuple of arguments for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

run_offline() None[source]

Process audio file in offline mode.

This method simulates real-time processing by reading chunks from an audio file at regular intervals. The processing speed can be controlled using the wait parameter.

Note

The audio file is processed in chunks of size hop_length, and features are extracted for each chunk.

run_online() None[source]

Process audio in real-time from input device.

This method sets up and starts real-time audio processing from the specified input device. It initializes the PyAudio interface and opens an audio stream with the configured parameters.

Note

The audio is processed in chunks of size hop_length, and features are extracted in real-time.

start_listening() None[source]

Set listen to True and sets initial time

stop_listening() None[source]

Stop listening to the audio stream.

This method stops the audio stream and cleans up resources. For real-time mode, it stops and closes the audio stream, and terminates the audio interface.