jvconnected.interfaces.midi.aioport
- class jvconnected.interfaces.midi.aioport.BasePort(*args, **kwargs)[source]
Bases:
Dispatcher
Async wrapper for
mido.ports
- Parameters
name (str) – The port name
- stopped
- Type
- Property running: bool = False
Current run state
running
is apydispatch.Property
object.
- EXECUTOR: ClassVar[concurrent.futures.ThreadPoolExecutor] = None
A
concurrent.futures.ThreadPoolExecutor
to use in therun_in_executor()
method for all instances of allBasePort
subclasses
- Property name: str = None
The port name
name
is apydispatch.Property
object.
- static get_executor() concurrent.futures.ThreadPoolExecutor [source]
Get or create the
EXECUTOR
instance to use in therun_in_executor()
method
- async run_in_executor(fn: Callable) Any [source]
Call the given function in the
EXECUTOR
instance usingasyncio.loop.run_in_executor()
and return the resultThis method is used to create and manipulate all
mido
ports to avoid blocking, threaded operations
- class jvconnected.interfaces.midi.aioport.InputPort(*args, **kwargs)[source]
Bases:
BasePort
Async wrapper around
mido.ports.BaseInput
- queue
Message queue for the port
- Type
- async receive(timeout: Optional[Number] = None) Optional[Message] [source]
Wait for an incoming message
- Parameters
timeout (float, optional) – Time to wait for a message. if
None
, wait until an item is available- Returns
An instance of
mido.Message
. If timeout was provided and no message was retrieved,None
will be returned.- Return type
Optional[Message]
- async receive_many(block: bool = True, timeout: Optional[Number] = None) Optional[Union[bool, Tuple[Message]]] [source]
Gather any/all available messages
- Parameters
block (bool, optional) – If
True
,wait_for_msg()
is used initially to wait for the first available message. IfFalse
, only check for queued messages and return immediately if none exist. Default isTrue
timeout (float, optional) – If block is
True
the timeout argument to pass to thewait_for_msg()
method
- Returns
If no messages were available (either block was
False
or the timeout was reached),None
is returned.- Return type
- async wait_for_msg(timeout: Optional[Number] = None) bool [source]
Wait until a message is available
- async queue_get(timeout: Optional[Number] = None) Any [source]
Convenience method for
get()
on thequeue
- Parameters
timeout (float, optional) – Time to wait for an item on the queue. if
None
, wait until an item is available
- async queue_iter_get() AsyncGenerator[Message, None] [source]
Iterate over any/all messages available on the queue
- task_done()[source]
Convenience method for
queue
task_done()
- class jvconnected.interfaces.midi.aioport.OutputPort(*args, **kwargs)[source]
Bases:
BasePort
Async wrapper around
mido.ports.BaseOutput
- queue
Message queue for the port. Since the output port operates in a separate thread, this is a thread-based queue (not async)
- Type
- async open() bool [source]
Open the midi port
- Returns
True
if the port was successfully opened- Return type
- async send(msg: Message)[source]
Send a message
The message will be placed on the
queue
and sent from a separate thread- Parameters
msg (Message) – The
mido.Message
to send