keyboard_input

Keyboard input.

Let’s play live with either a MIDI keyboard or our QWERTY keyboard.

Invoke with:

josephine@laptop:~/supriya$ python -m examples.keyboard_input --help
usage: python -m examples.keyboard_input [-h] (--list-midi-inputs |
                                         --use-midi PORT_NUMBER |
                                         --use-qwerty)

Play notes via your QWERTY or MIDI keyboards

options:
  -h, --help            show this help message and exit
  --list-midi-inputs    list available MIDI inputs
  --use-midi PORT_NUMBER
                        play via MIDI keyboard
  --use-qwerty          play via QWERTY keyboard

… to see complete options.

See the example documentation for a complete explanation.

class InputHandler

Bases: object

Base class for input handlers.

listen(callback: Callable[[NoteOn | NoteOff], None]) → Generator[None, None, None]
class MidiHandler(port: int)

Bases: InputHandler

A MIDI input handler.

handle(callback: Callable[[NoteOn | NoteOff], None], message: tuple[int, int, int], delta: float, user_data: Any) → None

Handle a MIDI input event.

listen(callback: Callable[[NoteOn | NoteOff], None]) → Generator[None, None, None]

Context manager for listening to MIDI input events.

class NoteOff(note_number: int)

Bases: object

A note off event.

class NoteOn(note_number: int, velocity: int)

Bases: object

A note on event.

class PolyphonyManager(server: Context, notes: dict[int, ~supriya.contexts.entities.Synth]=<factory>, synthdef: SynthDef = <SynthDef: supriya:default>, target_node: Node | None = None, add_action: AddAction = AddAction.ADD_TO_HEAD)

Bases: object

A polyphony manager.

Translates NoteOn or NoteOff events into actions against a Context.

free_all() → None

Free all currently playing Synth instances.

perform(event: NoteOn | NoteOff) → None

Perform a NoteOn or NoteOff event.

class QwertyHandler(octave: int = 5, presses_to_note_numbers: dict[str, int]=<factory>)

Bases: InputHandler

A QWERTY input handler.

listen(callback: Callable[[NoteOn | NoteOff], None]) → Generator[None, None, None]

Context manager for listening to QWERTY input events.

on_press(callback: Callable[[NoteOn | NoteOff], None], key: Key | KeyCode | None) → None

Handle a QWERTY key press.

on_release(callback: Callable[[NoteOn | NoteOff], None], key: Key | KeyCode | None) → None

Handle a QWERTY key release.

static qwerty_key_to_pitch_number(key: str) → int | None

Translate a QWERTY key event into a pitch number.

main(args: list[str] | None = None) → None

The example entry-point function.

parse_args(args: list[str] | None = None) → Namespace

Parse CLI arguments.

run(input_handler: InputHandler) → None

Run the script.