MIDIEventLoop class¶
-
class
MIDIEventLoop(port)¶ The event loop that watches for
Chords orSequences and other children ofNoteListand calls the event handlers. Uses callbacks if the backend supports it. Otherwise an internal loop will need to be started withstart()andstop().Parameters: port (str or
midoport) –midoport. Default is “default”, which gets the 1st port frommido.get_input_names(). Also accepts strings as returned formmido.get_input_names().Raises: - RunTimeError – When using the default port and but
mido.get_input_names()doesn’t return any ports. - TypeError – When something besides a
midoport orstris passed to theportparameter.
-
down_notes¶
setof notes that are currently down. Used to determine when aChordis being pressed.-
recent_notes¶
dequeof the last n notes, n is theSequence.maxlen()class attribute.-
chord_handlers¶
dictofChords mapped to a list of of handler functions.-
sequence_handlers¶
dictofSequences mapped to a list of handler functions.-
port¶
midoport being used-
running_handler_threads¶
A
listof the current running handlers threads.-
on_notes(notes_obj)¶
Decorator function similar to
add_handler(). Function is spawned in a new thread.Parameters: notes_obj – NoteListor child class. If a string is passed, will try to resolve to aChordsimilar to the output ofChord.identify()-
add_handler(func, notes_obj)¶
Create a new event handler that runs the function when a
notes_objis pressedParameters: - func (function) – Function to call when the chord is detected. Will be spawned in a new daemon thread.
- notes_obj –
NoteListor child class. If a string is passed, will try to resolve to aChordsimilar to the output ofChord.identify()
-
clear_handlers(notes_obj=None)¶
Clear
chord_handlersand/orsequence_handlersfor a givennotes_obj. Default is to clear all handlers ifnotes_objis not specified.Parameters: notes_obj – Default None.NoteListor child class. If a string is passed, will try to resolve to aChordsimilar to the output ofChord.identify()-
start(blocking=False)¶
Only required when backend doesn’t support callbacks. Start the main loop, used to process MIDI and trigger event handlers. Loop can be stopped with
stop(). Warns when called while using a backend that supports callbacks.Parameters: blocking (bool) – Default false. If true, will block until a handler calls stop()on theMIDIEventLoopobject.-
stop()¶
Only required when backend doesn’t support callbacks. Stop the main loop. Loop can be restarted with
start()after being stopped. Warns when called while using a backend that supports callbacks.-
static
_resolve_notes_obj(notes_obj)¶
Typically called when another function needs to make sure a
notes_objis legal, e.g. when using it as a parameter.Parameters: notes_obj – Default None.NoteListor child class. If a string is passed, will try to resolve to aChordsimilar to the output ofChord.identify()Returns: notes_obj Return type: Chord or Sequence Raises: AssertionError – When something besides a ChordorSequenceorstris passed to it.- RunTimeError – When using the default port and but