from collections.abc import Callable from types import ModuleType from ..messages import BaseMessage from ..ports import BaseInput, BaseIOPort, BaseOutput, IOPort DEFAULT_BACKEND: str = "mido.backends.rtmidi" class Backend: """ Wrapper for backend module. A backend module implements classes for input and output ports for a specific MIDI library. The Backend object wraps around the object and provides convenient 'open_*()' and 'get_*_names()' functions. """ name: str api: str | None use_environ: bool def __init__( self, name: str | None = ..., api: str | None = ..., load: bool = False, use_environ: bool = True ) -> None: ... @property def module(self) -> ModuleType: """A reference module implementing the backend. This will always be a valid reference to a module. Accessing this property will load the module. Use .loaded to check if the module is loaded. """ @property def loaded(self) -> bool: """Return True if the module is loaded.""" def load(self) -> None: """Load the module. Does nothing if the module is already loaded. This function will be called if you access the 'module' property.""" def open_input( self, name: str | None = ..., virtual: bool = False, callback: Callable[[BaseMessage], object] | None = ..., **kwargs: object, ) -> BaseInput: """Open an input port. If the environment variable MIDO_DEFAULT_INPUT is set, it will override the default port. virtual=False Passing True opens a new port that other applications can connect to. Raises IOError if not supported by the backend. callback=None A callback function to be called when a new message arrives. The function should take one argument (the message). Raises IOError if not supported by the backend. """ def open_output( self, name: str | None = ..., virtual: bool = False, autoreset: bool = False, **kwargs: object ) -> BaseOutput: """Open an output port. If the environment variable MIDO_DEFAULT_OUTPUT is set, it will override the default port. virtual=False Passing True opens a new port that other applications can connect to. Raises IOError if not supported by the backend. autoreset=False Automatically send all_notes_off and reset_all_controllers on all channels. This is the same as calling `port.reset()`. """ def open_ioport[TIn: BaseInput = BaseInput, TOut: BaseOutput = BaseOutput]( self, name: str | None = ..., virtual: bool = False, callback: Callable[[BaseMessage], object] | None = ..., autoreset: bool = False, **kwargs: object, ) -> BaseIOPort | IOPort[TIn, TOut]: """Open a port for input and output. If the environment variable MIDO_DEFAULT_IOPORT is set, it will override the default port. virtual=False Passing True opens a new port that other applications can connect to. Raises IOError if not supported by the backend. callback=None A callback function to be called when a new message arrives. The function should take one argument (the message). Raises IOError if not supported by the backend. autoreset=False Automatically send all_notes_off and reset_all_controllers on all channels. This is the same as calling `port.reset()`. """ def get_input_names(self, **kwargs: object) -> list[str]: """Return a list of all input port names.""" def get_output_names(self, **kwargs: object) -> list[str]: """Return a list of all output port names.""" def get_ioport_names(self, **kwargs: object) -> list[str]: """Return a list of all I/O port names."""