Keyboard¶
- class pico_synth_sandbox.keyboard.DebouncerKey(io_or_predicate, invert: bool = False)[source]¶
Bases:
KeyAn abstract layer to debouncer sensor input to use physical key objects with the
pico_synth_sandbox.keyboard.Keyboardclass.- Parameters:
io_or_predicate (ROValueIO | Callable[[], bool]) – The input pin or arbitrary predicate to debounce
- Int invert:
Whether or not to invert the state of the input. When invert is False, the signal is active-high. When it is True, the signal is active-low. Defaults to False.
- NONE: int = 0¶
Indicates that the key hasn’t been activated in any way
- Type:
int
- PRESS: int = 1¶
Indicates that the key has been pressed
- Type:
int
- RELEASE: int = 2¶
Indicates that the key has been released
- Type:
int
- check() int[source]¶
Updates the input pin or arbitraary predicate with basic debouncing and returns the current key state.
- Returns:
Key state constant
- Return type:
int
- get_velocity() float¶
Get the current velocity (0.0-1.0). Typically hard-coded at 1.0.
- Returns:
Key velocity
- Return type:
float
- class pico_synth_sandbox.keyboard.Key[source]¶
Bases:
objectAn abstract layer to use physical key objects with the
pico_synth_sandbox.keyboard.Keyboardclass.- NONE: int = 0¶
Indicates that the key hasn’t been activated in any way
- Type:
int
- PRESS: int = 1¶
Indicates that the key has been pressed
- Type:
int
- RELEASE: int = 2¶
Indicates that the key has been released
- Type:
int
- class pico_synth_sandbox.keyboard.Keyboard(keys: list[pico_synth_sandbox.keyboard.Key] = [], max_voices: int = 1, root: int = None)[source]¶
Bases:
TaskManage notes, voice allocation, arpeggiator assignment, sustain, and relevant callbacks using this class. The default note allocation mode is defined by the KEYBOARD_MODE variable in settings.toml.
- Parameters:
keys (list) – A list of
pico_synth_sandbox.keyboard.Keyobjects used to include physical key inputs as notes during the update routine.max_voices (int) – The maximum number of voices/notes to be played at once.
root (int) – Set the base note number of the physical key inputs. If left as None, the KEYBOARD_ROOT settings.toml value will be used instead.
- MODE_HIGH = 0¶
When the keyboard is set as this mode, it will prioritize the highest note value.
- Type:
int
- MODE_LAST = 2¶
When the keyboard is set as this mode, it will prioritize notes by the order in when they were played/appended.
- Type:
int
- MODE_LOW = 1¶
When the keyboard is set as this mode, it will prioritize the lowest note value.
- Type:
int
- NUM_MODES = 3¶
The number of available keyboard note allocation modes.
- Type:
int
- append(notenum: int | Note, velocity: float = 1.0, keynum: int = None, update: bool = True)[source]¶
Add a note to the keyboard buffer. Useful when working with MIDI input or another note source. Any previous notes with the same notenum value will be removed automatically.
- Parameters:
notenum (int|:class:pico_synth_sandbox.keyboard.Note) – The number of the note. Can be defined by MIDI notes, a designated sample index, etc. When using MODE_HIGH or MODE_LOW, the value of this parameter will affect the order. A
pico_synth_sandbox.keyboard.Noteobject can be used instead of providing notenum, velocity, and keynum parameters directly.velocity (float) – The velocity of the note from 0.0 through 1.0.
keynum (int) – An additional index reference typically used to associate the note with a physical
pico_synth_sandbox.keyboard.Keyobject. Not required for use of the keyboard.update (bool) – Whether or not to update the keyboard logic and potentially trigger any associated callbacks.
- get(count: int = None) list[pico_synth_sandbox.keyboard.Note][source]¶
Retrieve a set of active notes according to the keyboard mode setting (MODE_HIGH, MODE_LOW, or MODE_LAST).
- Parameters:
count (int) – The number of notes to return. If left undefined, the max voices setting of the keyboard object will be used instead.
- Returns:
list of pico_synth_sandbox.keyboard.Note objects
- Return type:
- get_active_voices() list[pico_synth_sandbox.keyboard.Voice][source]¶
Get all keyboard voices that are “active”, have been assigned a note. The voices will automatically be sorted by the time they were last assigned a note from oldest to newest.
- Returns:
all active voices
- Return type:
- get_inactive_voices() list[pico_synth_sandbox.keyboard.Voice][source]¶
Get all keyboard voices that are “inactive”, do not currently have a note assigned. The voices will automatically be sorted by the time they were last assigned a note from oldest to newest.
- Returns:
all inactive voices
- Return type:
- get_max_voices() int[source]¶
Return the maximum number of voices used by this keyboard to allocate notes.
- Returns:
max voices
- Return type:
int
- get_mode() int[source]¶
Get the current note allocation mode of this object.
- Returns:
keyboard mode
- Return type:
int
- get_notes(include_sustained: bool = True) list[pico_synth_sandbox.keyboard.Note][source]¶
Get all active
pico_synth_sandbox.keyboard.Noteobjects within the keyboard object.- Parameters:
include_sustained (bool) – If set as True, any sustained notes will be included in the returned value.
- Returns:
list of note objects
- Return type:
- get_sustain() bool[source]¶
Get the current sustain state of the keyboard.
- Returns:
sustain
- Return type:
bool
- get_voices() list[pico_synth_sandbox.keyboard.Voice][source]¶
Get all
pico_synth_sandbox.keyboard.Voiceobjects used by thepico_synth_sandbox.keyboard.Keyboardobject.- Returns:
list of voice objects
- Return type:
- has_active_voice() bool[source]¶
Checks to see if any voice is currently “active”, has been assigned a note.
- Returns:
whether or not at least one voice is active
- Return type:
bool
- has_inactive_voices() bool[source]¶
Checks to see if any voice is currently “inactive”, has not been assigned a note.
- Returns:
whether or not at least one voice is inactive
- Return type:
bool
- has_note(notenum: int | Note, include_sustained: bool = True) bool[source]¶
Check whether the keyboard has an active note.
- Parameters:
notenum (int|:class:pico_synth_sandbox.keyboard.Note) – The MIDI note value or
pico_synth_sandbox.keyboard.Noteto check for.include_sustained (bool) – If set as True, any sustained notes (if sustain is active) will be included in the check.
- Returns:
has note
- Return type:
bool
- has_notes(include_sustained: bool = True) bool[source]¶
Check whether the keyboard has any active notes.
- Parameters:
include_sustained (bool) – If set as True, any sustained notes (if sustain is active) will be included in the check.
- Returns:
has notes
- Return type:
bool
- remove(notenum: int | Note, update: bool = True, remove_sustained: bool = False)[source]¶
Remove a note from the keyboard buffer. Useful when working with MIDI input or another note source. If the note is found (and the keyboard isn’t being sustained or remove_sustained is set as True), the release callback will trigger automatically regardless of the update parameter.
- Parameters:
notenum (int|:class:pico_synth_sandbox.keyboard.Note) – The value of the note that you would like to be removed. All notes in the buffer with this value will be removed. Can be defined by MIDI note value, a designated sample index, etc. Can also use a
pico_synth_sandbox.keyboard.Noteobject instead.update (bool) – Whether or not to update the keyboard logic and potentially trigger any associated callbacks.
remove_sustained (bool) – Whether or not you would like to override the current sustained state of the keyboard and release any notes that are being sustained.
- set_arpeggiator(arpeggiator)[source]¶
Assign an arpeggiator class to the keyboard. Must be of type
pico_synth_sandbox.arpeggiator.Arpeggiatoror a child of that class. When notes are appended to this object, the arpeggiator will automatically be updated. Callbacks from the arpeggiator will also be routed through the press and release callbacks of this object.- Parameters:
arpeggiator – The arpeggiator object to be assigned ot the keyboard. If this class is called multiple times, the callbacks of the previously allocated arpeggiator will be unassigned.
- set_key_press(callback)[source]¶
Set the callback method you would like to be called when a key is pressed.
- Parameters:
callback (function) – The callback method. Must have 3 parameters for keynum, note value, velocity (0.0-1.0), and keynum. Ie: def press(keynum, notenum, velocity):.
- set_key_release(callback)[source]¶
Set the callback method you would like to be called when a key is released.
- Parameters:
callback (function) – The callback method. Must have 2 parameters for keynum and note value. Velocity is always assumed to be 0.0. Ie: def release(keynum, notenum):.
- set_max_voices(value: int)[source]¶
Change the number of max voices used to allocate notes. Must be greater than 1. When this method is called, it will automatically release and delete any voices or add new voice objects depending on the previous number of voices. Any voice related callbacks may be triggered during this process.
- Parameters:
value (int) – The maximum number of voices to allocate notes
- set_mode(value: int)[source]¶
Set the note allocation mode of this object. Use one of the mode constants of this class such as pico_synth_sandbox.Keyboard.MODE_HIGH. Note allocation won’t be updated until the next update call.
- Parameters:
value (int) – The desired mode type.
- set_sustain(value: bool, update: bool = True)[source]¶
Set the sustain state of the keyboard. If sustain is set as True, it will prevent current and future notes from being released until sustain is set as False.
- Parameters:
value (bool) – The desired state of sustain. If sustain is set as False, any notes that are no longer being held will be released immediately.
update – Whether or not you would like to update the current list notes after changing the sustained state. This may trigger a new note press according to the note allocation rules immediately.
- set_voice_press(callback)[source]¶
Set the callback method you would like to be called when a voice is pressed.
- Parameters:
callback (function) – The callback method. Must have 4 parameters for voice index, note value, velocity (0.0-1.0), and keynum (if sourced from a
pico_synth_sandbox.keyboard.Keyclass). Ie: def press(voice, notenum, velocity, keynum=None):.
- set_voice_release(callback)[source]¶
Set the callback method you would like to be called when a voice is released.
- Parameters:
callback (function) – The callback method. Must have 3 parameters for voice index, note value, and keynum (if sourced from a
pico_synth_sandbox.keyboard.Keyclass). Velocity is always assumed to be 0.0. Ie: def release(voice, notenum, keynum=None):.
- async update()[source]¶
Update the keyboard logic and call any pre-defined callbacks if triggered. If any
pico_synth_sandbox.keyboard.Keyobjects (during initialization) or anpico_synth_sandbox.arpeggiator.Arpeggiatorobject (using the set_arpeggiator method) were associated with this object, it will also be updated in this process.
- class pico_synth_sandbox.keyboard.Note(notenum: int, velocity: float = 1.0, keynum: int = None)[source]¶
Bases:
objectObject which represents the parameters of a note. Contains note number, velocity, key number (if evoked by a
pico_synth_sandbox.keyboard.Keyobject), and timestamp of when the note was created.- Parameters:
notenum (int) – The MIDI note number representing the frequency of a note.
velocity (float) – The strength of which a note was pressed. Ranges from 0.0 to 1.0. Defaults to 1.0.
keynum – The index number of the
pico_synth_sandbox.keyboard.Keyobject which may have created thispico_synth_sandbox.keyboard.Noteobject. If not applicable, will be None. Defaults to None.
- class pico_synth_sandbox.keyboard.Voice(index: int)[source]¶
Bases:
objectObject which represents the parameters of a
pico_synth_sandbox.keyboard.Keyboardvoice. Used to allocatepico_synth_sandbox.keyboard.Noteobjects to a pre-defined number of available slots in a logical manner based on timing and keyboard mode.- Parameters:
index (int) – The position of the voice in the pre-defined set of keyboard voices. Used for external reference.
- clear()[source]¶
Remove any assigned
pico_synth_sandbox.keyboard.Noteobject from the voice. The voice will be made “inactive”.
- is_active() bool[source]¶
Determines whether or not a voice has a
pico_synth_sandbox.keyboard.Noteobject assigned to it. If it does, it will return True. Otherwise, False.- Returns:
the active state of the voice
- Return type:
bool
- set_note(note: Note)[source]¶
Assign a
pico_synth_sandbox.keyboard.Noteobject to a voice. When a note is assigned to a voice, the voice is “active” until the note is cleared.- Parameters:
note (
pico-synth_sandbox.keyboard.Note) – Thepico_synth_sandbox.keyboard.Noteobject
- pico_synth_sandbox.keyboard.get_keyboard_driver(board, max_voices: int = 1, root: int = None) Keyboard[source]¶
Automatically generate the proper
pico_synth_sandbox.keyboard.Keyboardobject based on the device’s settings.toml configuration.- Parameters:
board (
pico_synth_sandbox.board.Board) – The designated board configuration object. Can be obtained by calling pico_synth_sandbox.board.get_board().max_voices (int) – The maximum number of voices/notes to be played at once.
root (int) – Set the base note number of the physical key inputs. If left as None, the KEYBOARD_ROOT settings.toml value will be used instead.
- Returns:
a keyboard object for the designated board
- Return type:
Direct Capacitive Touch Keyboard¶
- class pico_synth_sandbox.keyboard.touch.TouchKeyboard(board, max_voices: int = 1, root: int = None)[source]¶
Bases:
KeyboardUse direct capactivie touch GPIO inputs as a
pico_synth_sandbox.keyboard.Keyboardobject. GPIO pins and order are defined by board.get_touch_keys().- Parameters:
board (
pico_synth_sandbox.board.Board) – The designated board configuration object. Can be obtained by calling pico_synth_sandbox.board.get_board().max_voices (int) – The maximum number of voices/notes to be played at once.
root (int) – Set the base note number of the physical key inputs. If left as None, the KEYBOARD_ROOT settings.toml value will be used instead.
- MODE_HIGH = 0¶
When the keyboard is set as this mode, it will prioritize the highest note value.
- Type:
int
- MODE_LAST = 2¶
When the keyboard is set as this mode, it will prioritize notes by the order in when they were played/appended.
- Type:
int
- MODE_LOW = 1¶
When the keyboard is set as this mode, it will prioritize the lowest note value.
- Type:
int
- NUM_MODES = 3¶
The number of available keyboard note allocation modes.
- Type:
int
- append(notenum: int | Note, velocity: float = 1.0, keynum: int = None, update: bool = True)¶
Add a note to the keyboard buffer. Useful when working with MIDI input or another note source. Any previous notes with the same notenum value will be removed automatically.
- Parameters:
notenum (int|:class:pico_synth_sandbox.keyboard.Note) – The number of the note. Can be defined by MIDI notes, a designated sample index, etc. When using MODE_HIGH or MODE_LOW, the value of this parameter will affect the order. A
pico_synth_sandbox.keyboard.Noteobject can be used instead of providing notenum, velocity, and keynum parameters directly.velocity (float) – The velocity of the note from 0.0 through 1.0.
keynum (int) – An additional index reference typically used to associate the note with a physical
pico_synth_sandbox.keyboard.Keyobject. Not required for use of the keyboard.update (bool) – Whether or not to update the keyboard logic and potentially trigger any associated callbacks.
- get(count: int = None) list[pico_synth_sandbox.keyboard.Note]¶
Retrieve a set of active notes according to the keyboard mode setting (MODE_HIGH, MODE_LOW, or MODE_LAST).
- Parameters:
count (int) – The number of notes to return. If left undefined, the max voices setting of the keyboard object will be used instead.
- Returns:
list of pico_synth_sandbox.keyboard.Note objects
- Return type:
- get_active_voices() list[pico_synth_sandbox.keyboard.Voice]¶
Get all keyboard voices that are “active”, have been assigned a note. The voices will automatically be sorted by the time they were last assigned a note from oldest to newest.
- Returns:
all active voices
- Return type:
- get_inactive_voices() list[pico_synth_sandbox.keyboard.Voice]¶
Get all keyboard voices that are “inactive”, do not currently have a note assigned. The voices will automatically be sorted by the time they were last assigned a note from oldest to newest.
- Returns:
all inactive voices
- Return type:
- get_max_voices() int¶
Return the maximum number of voices used by this keyboard to allocate notes.
- Returns:
max voices
- Return type:
int
- get_mode() int¶
Get the current note allocation mode of this object.
- Returns:
keyboard mode
- Return type:
int
- get_notes(include_sustained: bool = True) list[pico_synth_sandbox.keyboard.Note]¶
Get all active
pico_synth_sandbox.keyboard.Noteobjects within the keyboard object.- Parameters:
include_sustained (bool) – If set as True, any sustained notes will be included in the returned value.
- Returns:
list of note objects
- Return type:
- get_sustain() bool¶
Get the current sustain state of the keyboard.
- Returns:
sustain
- Return type:
bool
- get_voices() list[pico_synth_sandbox.keyboard.Voice]¶
Get all
pico_synth_sandbox.keyboard.Voiceobjects used by thepico_synth_sandbox.keyboard.Keyboardobject.- Returns:
list of voice objects
- Return type:
- has_active_voice() bool¶
Checks to see if any voice is currently “active”, has been assigned a note.
- Returns:
whether or not at least one voice is active
- Return type:
bool
- has_inactive_voices() bool¶
Checks to see if any voice is currently “inactive”, has not been assigned a note.
- Returns:
whether or not at least one voice is inactive
- Return type:
bool
- has_note(notenum: int | Note, include_sustained: bool = True) bool¶
Check whether the keyboard has an active note.
- Parameters:
notenum (int|:class:pico_synth_sandbox.keyboard.Note) – The MIDI note value or
pico_synth_sandbox.keyboard.Noteto check for.include_sustained (bool) – If set as True, any sustained notes (if sustain is active) will be included in the check.
- Returns:
has note
- Return type:
bool
- has_notes(include_sustained: bool = True) bool¶
Check whether the keyboard has any active notes.
- Parameters:
include_sustained (bool) – If set as True, any sustained notes (if sustain is active) will be included in the check.
- Returns:
has notes
- Return type:
bool
- remove(notenum: int | Note, update: bool = True, remove_sustained: bool = False)¶
Remove a note from the keyboard buffer. Useful when working with MIDI input or another note source. If the note is found (and the keyboard isn’t being sustained or remove_sustained is set as True), the release callback will trigger automatically regardless of the update parameter.
- Parameters:
notenum (int|:class:pico_synth_sandbox.keyboard.Note) – The value of the note that you would like to be removed. All notes in the buffer with this value will be removed. Can be defined by MIDI note value, a designated sample index, etc. Can also use a
pico_synth_sandbox.keyboard.Noteobject instead.update (bool) – Whether or not to update the keyboard logic and potentially trigger any associated callbacks.
remove_sustained (bool) – Whether or not you would like to override the current sustained state of the keyboard and release any notes that are being sustained.
- set_arpeggiator(arpeggiator)¶
Assign an arpeggiator class to the keyboard. Must be of type
pico_synth_sandbox.arpeggiator.Arpeggiatoror a child of that class. When notes are appended to this object, the arpeggiator will automatically be updated. Callbacks from the arpeggiator will also be routed through the press and release callbacks of this object.- Parameters:
arpeggiator – The arpeggiator object to be assigned ot the keyboard. If this class is called multiple times, the callbacks of the previously allocated arpeggiator will be unassigned.
- set_key_press(callback)¶
Set the callback method you would like to be called when a key is pressed.
- Parameters:
callback (function) – The callback method. Must have 3 parameters for keynum, note value, velocity (0.0-1.0), and keynum. Ie: def press(keynum, notenum, velocity):.
- set_key_release(callback)¶
Set the callback method you would like to be called when a key is released.
- Parameters:
callback (function) – The callback method. Must have 2 parameters for keynum and note value. Velocity is always assumed to be 0.0. Ie: def release(keynum, notenum):.
- set_max_voices(value: int)¶
Change the number of max voices used to allocate notes. Must be greater than 1. When this method is called, it will automatically release and delete any voices or add new voice objects depending on the previous number of voices. Any voice related callbacks may be triggered during this process.
- Parameters:
value (int) – The maximum number of voices to allocate notes
- set_mode(value: int)¶
Set the note allocation mode of this object. Use one of the mode constants of this class such as pico_synth_sandbox.Keyboard.MODE_HIGH. Note allocation won’t be updated until the next update call.
- Parameters:
value (int) – The desired mode type.
- set_sustain(value: bool, update: bool = True)¶
Set the sustain state of the keyboard. If sustain is set as True, it will prevent current and future notes from being released until sustain is set as False.
- Parameters:
value (bool) – The desired state of sustain. If sustain is set as False, any notes that are no longer being held will be released immediately.
update – Whether or not you would like to update the current list notes after changing the sustained state. This may trigger a new note press according to the note allocation rules immediately.
- set_voice_press(callback)¶
Set the callback method you would like to be called when a voice is pressed.
- Parameters:
callback (function) – The callback method. Must have 4 parameters for voice index, note value, velocity (0.0-1.0), and keynum (if sourced from a
pico_synth_sandbox.keyboard.Keyclass). Ie: def press(voice, notenum, velocity, keynum=None):.
- set_voice_release(callback)¶
Set the callback method you would like to be called when a voice is released.
- Parameters:
callback (function) – The callback method. Must have 3 parameters for voice index, note value, and keynum (if sourced from a
pico_synth_sandbox.keyboard.Keyclass). Velocity is always assumed to be 0.0. Ie: def release(voice, notenum, keynum=None):.
- async update()¶
Update the keyboard logic and call any pre-defined callbacks if triggered. If any
pico_synth_sandbox.keyboard.Keyobjects (during initialization) or anpico_synth_sandbox.arpeggiator.Arpeggiatorobject (using the set_arpeggiator method) were associated with this object, it will also be updated in this process.
- class pico_synth_sandbox.keyboard.touch.TouchPad(pin)[source]¶
Bases:
DebouncerKeyThis class is used by the
pico_synth_sandbox.keyboard.touch.TouchKeyboardclass to handle logic related to the capacitive touch inputs of the hardware platform.- Parameters:
pin (
microcontroller.Pin) – The GPIO pin of the capacitive touch input. Must use a pull-down resistor of around 1M ohms.
- NONE: int = 0¶
Indicates that the key hasn’t been activated in any way
- Type:
int
- PRESS: int = 1¶
Indicates that the key has been pressed
- Type:
int
- RELEASE: int = 2¶
Indicates that the key has been released
- Type:
int
- check() int¶
Updates the input pin or arbitraary predicate with basic debouncing and returns the current key state.
- Returns:
Key state constant
- Return type:
int
- get_velocity() float¶
Get the current velocity (0.0-1.0). Typically hard-coded at 1.0.
- Returns:
Key velocity
- Return type:
float
TTP229 Capacitive Touch Keyboard¶
- class pico_synth_sandbox.keyboard.ton_touch.TonTouchKeyboard(board, max_voices=1, root=None, input_mode=1, invert_clk=True)[source]¶
Bases:
Keyboard- MODE_HIGH = 0¶
When the keyboard is set as this mode, it will prioritize the highest note value.
- Type:
int
- MODE_LAST = 2¶
When the keyboard is set as this mode, it will prioritize notes by the order in when they were played/appended.
- Type:
int
- MODE_LOW = 1¶
When the keyboard is set as this mode, it will prioritize the lowest note value.
- Type:
int
- NUM_MODES = 3¶
The number of available keyboard note allocation modes.
- Type:
int
- append(notenum: int | Note, velocity: float = 1.0, keynum: int = None, update: bool = True)¶
Add a note to the keyboard buffer. Useful when working with MIDI input or another note source. Any previous notes with the same notenum value will be removed automatically.
- Parameters:
notenum (int|:class:pico_synth_sandbox.keyboard.Note) – The number of the note. Can be defined by MIDI notes, a designated sample index, etc. When using MODE_HIGH or MODE_LOW, the value of this parameter will affect the order. A
pico_synth_sandbox.keyboard.Noteobject can be used instead of providing notenum, velocity, and keynum parameters directly.velocity (float) – The velocity of the note from 0.0 through 1.0.
keynum (int) – An additional index reference typically used to associate the note with a physical
pico_synth_sandbox.keyboard.Keyobject. Not required for use of the keyboard.update (bool) – Whether or not to update the keyboard logic and potentially trigger any associated callbacks.
- get(count: int = None) list[pico_synth_sandbox.keyboard.Note]¶
Retrieve a set of active notes according to the keyboard mode setting (MODE_HIGH, MODE_LOW, or MODE_LAST).
- Parameters:
count (int) – The number of notes to return. If left undefined, the max voices setting of the keyboard object will be used instead.
- Returns:
list of pico_synth_sandbox.keyboard.Note objects
- Return type:
- get_active_voices() list[pico_synth_sandbox.keyboard.Voice]¶
Get all keyboard voices that are “active”, have been assigned a note. The voices will automatically be sorted by the time they were last assigned a note from oldest to newest.
- Returns:
all active voices
- Return type:
- get_inactive_voices() list[pico_synth_sandbox.keyboard.Voice]¶
Get all keyboard voices that are “inactive”, do not currently have a note assigned. The voices will automatically be sorted by the time they were last assigned a note from oldest to newest.
- Returns:
all inactive voices
- Return type:
- get_max_voices() int¶
Return the maximum number of voices used by this keyboard to allocate notes.
- Returns:
max voices
- Return type:
int
- get_mode() int¶
Get the current note allocation mode of this object.
- Returns:
keyboard mode
- Return type:
int
- get_notes(include_sustained: bool = True) list[pico_synth_sandbox.keyboard.Note]¶
Get all active
pico_synth_sandbox.keyboard.Noteobjects within the keyboard object.- Parameters:
include_sustained (bool) – If set as True, any sustained notes will be included in the returned value.
- Returns:
list of note objects
- Return type:
- get_sustain() bool¶
Get the current sustain state of the keyboard.
- Returns:
sustain
- Return type:
bool
- get_voices() list[pico_synth_sandbox.keyboard.Voice]¶
Get all
pico_synth_sandbox.keyboard.Voiceobjects used by thepico_synth_sandbox.keyboard.Keyboardobject.- Returns:
list of voice objects
- Return type:
- has_active_voice() bool¶
Checks to see if any voice is currently “active”, has been assigned a note.
- Returns:
whether or not at least one voice is active
- Return type:
bool
- has_inactive_voices() bool¶
Checks to see if any voice is currently “inactive”, has not been assigned a note.
- Returns:
whether or not at least one voice is inactive
- Return type:
bool
- has_note(notenum: int | Note, include_sustained: bool = True) bool¶
Check whether the keyboard has an active note.
- Parameters:
notenum (int|:class:pico_synth_sandbox.keyboard.Note) – The MIDI note value or
pico_synth_sandbox.keyboard.Noteto check for.include_sustained (bool) – If set as True, any sustained notes (if sustain is active) will be included in the check.
- Returns:
has note
- Return type:
bool
- has_notes(include_sustained: bool = True) bool¶
Check whether the keyboard has any active notes.
- Parameters:
include_sustained (bool) – If set as True, any sustained notes (if sustain is active) will be included in the check.
- Returns:
has notes
- Return type:
bool
- remove(notenum: int | Note, update: bool = True, remove_sustained: bool = False)¶
Remove a note from the keyboard buffer. Useful when working with MIDI input or another note source. If the note is found (and the keyboard isn’t being sustained or remove_sustained is set as True), the release callback will trigger automatically regardless of the update parameter.
- Parameters:
notenum (int|:class:pico_synth_sandbox.keyboard.Note) – The value of the note that you would like to be removed. All notes in the buffer with this value will be removed. Can be defined by MIDI note value, a designated sample index, etc. Can also use a
pico_synth_sandbox.keyboard.Noteobject instead.update (bool) – Whether or not to update the keyboard logic and potentially trigger any associated callbacks.
remove_sustained (bool) – Whether or not you would like to override the current sustained state of the keyboard and release any notes that are being sustained.
- set_arpeggiator(arpeggiator)¶
Assign an arpeggiator class to the keyboard. Must be of type
pico_synth_sandbox.arpeggiator.Arpeggiatoror a child of that class. When notes are appended to this object, the arpeggiator will automatically be updated. Callbacks from the arpeggiator will also be routed through the press and release callbacks of this object.- Parameters:
arpeggiator – The arpeggiator object to be assigned ot the keyboard. If this class is called multiple times, the callbacks of the previously allocated arpeggiator will be unassigned.
- set_key_press(callback)¶
Set the callback method you would like to be called when a key is pressed.
- Parameters:
callback (function) – The callback method. Must have 3 parameters for keynum, note value, velocity (0.0-1.0), and keynum. Ie: def press(keynum, notenum, velocity):.
- set_key_release(callback)¶
Set the callback method you would like to be called when a key is released.
- Parameters:
callback (function) – The callback method. Must have 2 parameters for keynum and note value. Velocity is always assumed to be 0.0. Ie: def release(keynum, notenum):.
- set_max_voices(value: int)¶
Change the number of max voices used to allocate notes. Must be greater than 1. When this method is called, it will automatically release and delete any voices or add new voice objects depending on the previous number of voices. Any voice related callbacks may be triggered during this process.
- Parameters:
value (int) – The maximum number of voices to allocate notes
- set_mode(value: int)¶
Set the note allocation mode of this object. Use one of the mode constants of this class such as pico_synth_sandbox.Keyboard.MODE_HIGH. Note allocation won’t be updated until the next update call.
- Parameters:
value (int) – The desired mode type.
- set_sustain(value: bool, update: bool = True)¶
Set the sustain state of the keyboard. If sustain is set as True, it will prevent current and future notes from being released until sustain is set as False.
- Parameters:
value (bool) – The desired state of sustain. If sustain is set as False, any notes that are no longer being held will be released immediately.
update – Whether or not you would like to update the current list notes after changing the sustained state. This may trigger a new note press according to the note allocation rules immediately.
- set_voice_press(callback)¶
Set the callback method you would like to be called when a voice is pressed.
- Parameters:
callback (function) – The callback method. Must have 4 parameters for voice index, note value, velocity (0.0-1.0), and keynum (if sourced from a
pico_synth_sandbox.keyboard.Keyclass). Ie: def press(voice, notenum, velocity, keynum=None):.
- set_voice_release(callback)¶
Set the callback method you would like to be called when a voice is released.
- Parameters:
callback (function) – The callback method. Must have 3 parameters for voice index, note value, and keynum (if sourced from a
pico_synth_sandbox.keyboard.Keyclass). Velocity is always assumed to be 0.0. Ie: def release(voice, notenum, keynum=None):.
- async update()[source]¶
Update the keyboard logic and call any pre-defined callbacks if triggered. If any
pico_synth_sandbox.keyboard.Keyobjects (during initialization) or anpico_synth_sandbox.arpeggiator.Arpeggiatorobject (using the set_arpeggiator method) were associated with this object, it will also be updated in this process.
- class pico_synth_sandbox.keyboard.ton_touch.TonTouchPad(index)[source]¶
Bases:
DebouncerKey- NONE: int = 0¶
Indicates that the key hasn’t been activated in any way
- Type:
int
- PRESS: int = 1¶
Indicates that the key has been pressed
- Type:
int
- RELEASE: int = 2¶
Indicates that the key has been released
- Type:
int
- check() int¶
Updates the input pin or arbitraary predicate with basic debouncing and returns the current key state.
- Returns:
Key state constant
- Return type:
int
- get_velocity() float¶
Get the current velocity (0.0-1.0). Typically hard-coded at 1.0.
- Returns:
Key velocity
- Return type:
float