relic_keymanager
Tools to manage notes in musical applications. Includes note priority, arpeggiation, and sequencing.
Author(s): Cooper Dalrymple
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
Adafruit’s SimpleMath library: https://github.com/adafruit/Adafruit_CircuitPython_SimpleMath
Use this class to iterate over notes based on time parameters. Note press and release timing is managed by bpm (beats per minute), steps (divisions of a beat), and gate (note duration during step).
bpm – The beats per minute of timer.
steps – The number of steps to divide a single beat. The minimum value allowed is 0.25, or a whole note.
gate – The duration of each pressed note per step to play before releasing as a ratio from 0.0 to 1.0.
mode – The method of stepping through notes as specified by ArpeggiatorMode
constants.
The method of stepping through notes. See ArpeggiatorMode
for options.
The Note
objects which the arpeggiator is currently stepping through ordered as specified by mode
and affected by octaves
.
The number of octaves in which to extend the notes, either up or down.
The likeliness that a note will be played within a step, ranging from 0.0 (never) to 1.0 (always).
An enum-like class containing constaints for the possible modes of the Arpeggiator
class.
Play notes based on descending note value.
Play notes based on note value in descending order then ascending order. The topmost and bottommost notes will not be repeated.
Play notes based on the time at which they were played (ascending).
Play notes in a random order.
Play notes based on ascending note value.
Play notes based on note value in ascending order then descending order. The topmost and bottommost notes will not be repeated.
Manage notes, voice allocation, arpeggiator assignment, sustain, and relevant callbacks using this class.
keys – A list of Key
objects which will be used to update the keyboard state.
max_voices – The maximum number of voices/notes to be played at once.
root – Set the base note number of the physical key inputs.
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.
All active Note
objects.
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.
notenum – 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 Note
object can be used instead of providing notenum, velocity, and keynum parameters directly.
velocity – The velocity of the note from 0.0 through 1.0.
keynum – An additional index reference typically used to associate the note with a physical Key
object. Not required for use of the keyboard.
The Arpeggiator
object assigned to the keyboard.
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.
The keypad.Keys
object which will be used to update the keyboard state.
The maximum number of voices used by this keyboard to allocate notes. Must be greater than 1. When this property is set, 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.
The note allocation mode. Use one of the mode constants of KeyboardMode
. Note allocation won’t be updated until the next update call.
Active Notes
objects according to the current KeyboardMode
.
The callback method to be called when a Key
object is pressed. Must have 3 parameters for keynum, note value, velocity (0.0-1.0), and keynum. Ie: def press(keynum, notenum, velocity):
.
The callback method to be called when a Key
object is released. Must have 2 parameters for keynum and note value. Velocity is always assumed to be 0.0. Ie: def release(keynum, notenum):
.
The callback method to be called when a voice is pressed. Must have 1 parameter for the Voice
object. Ie: def press(voice):
.
The callback method to be called when a voice is released. Must have 1 parameter for the Voice
object. Velocity is always assumed to be 0.0. Ie: def release(voice):
.
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.
notenum – 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 Note
object instead.
remove_sustained – Whether or not you would like to override the current sustained state of the keyboard and release any notes that are being sustained.
Whether or not the notes pressed are sustained after being released until this property is set to False
.
Update keys
objects if they were provided during initialization.
delay – The amount of time to sleep between polling in seconds.
An enum-like class representing Keyboard note handling modes.
When the keyboard is set as this mode, it will prioritize the highest note value.
When the keyboard is set as this mode, it will prioritize notes by the order in when they were played/appended.
When the keyboard is set as this mode, it will prioritize the lowest note value.
Object which represents the parameters of a note. Contains note number, velocity, key number (if evoked by a Key
object), and timestamp of when the note was created.
notenum – The MIDI note number representing the frequency of a note.
velocity – The strength of which a note was pressed from 0.0 to 1.0.
keynum – The index number of the Key
object which created this Note
object.
(notenum:int, velocity:float, keynum:int). Keynum may be set as None
if not applicable.
Return all note data as tuple. The data is formatted as
The index number of the Key
object which created this Note
object.
The MIDI note number representing the frequency of a note.
The strength of which a note was pressed from 0.0 to 1.0.
Sequence notes using the Timer
class to create a multi-track note sequencer. By default, the Sequencer is set up for a single 4/4 measure of 16 notes with one track. Each note of each track can be assigned any note value and velocity. The length and number of tracks can be reassigned during runtime.
length – The number of steps of each track. The minimum value allowed is 1.
tracks – The number of tracks to create and sequence. The minimum value allowed is 1.
bpm – The beats per minute of the timer.
Get the note data for a specified track and step position. If a note isn’t defined at specific index, a value of None
will be returned.
position – Index of the step (0-based). Will be limited to the track length.
track – Index of the track (0-based). Will be limited to the track count.
note data (notenum, velocity)
Get list of note data for a specified track index (0-based). If the track isn’t available, a value of None
will be returned.
track data list of note tuples as (notenum, velocity)
Check whether or note a specific step within a track has been set with note data.
position – Index of the step (0-based). Will be limited to the track length.
track – Index of the track (0-based). Will be limited to the track count.
if the track step has a note
The number of steps for each track. If the length is shortened, all of the step data beyond the new length will be deleted, and if the sequencer is also currently running, it should loop back around automatically to the start of the track data. The minimum allowed is 1.
The callback method that is called when a step is triggered. This callback will fire whether or not the step has any notes. However, any pressed notes will occur before this callback is called. Must have 1 parameter for sequencer position index. Ie: def step(pos):
.
The current position of the sequencer within the track length (0-based).
Remove the note data as a specific step within a track.
position – Index of the step (0-based). Will be limited to the track length.
track – Index of the track (0-based). Will be limited to the track count.
Set the note value and velocity of a track at a specific step index.
position – Index of the step (0-based). Will be limited to the track length.
notenum – Value of the note.
velocity – Velocity of the note (0.0-1.0).
track – Index of the track (0-based). Will be limited to the track count.
The number of note tracks to sequence. If the number of tracks is shortened, the tracks at an index greater to or equal than the number will be deleted. If a larger number of tracks is provided, the newly created tracks will be empty. The minimum allowed is 1.
An abstract class to help handle timing functionality of the Arpeggiator
and Sequencer
classes. Note press and release timing is managed by bpm (beats per minute), steps (divisions of a beat), and gate (note duration during step).
bpm – The beats per minute of timer.
steps – The number of steps to divide a single beat. The minimum value allowed is 0.25, or a whole note.
gate – The duration of each pressed note per step to play before releasing as a ratio from 0.0 to 1.0.
Whether or not the timer object is enabled (running).
Beats per minute.
The duration each pressed note per step will play before releasing within a step of a beat as a ratio of that step from 0.0 to 1.0.
The callback method that is called when active
is changed. Must have 1 parameter for the current active state. Ie: def enabled(active):
The callback method that is called when a timed step note is pressed. Must have 2 parameters for note value and velocity (0.0-1.0). Ie: def press(notenum, velocity):
.
The callback method that is called when a timed step note is released. Must have 1 parameter for note value. Velocity is always assumed to be 0.0. Ie: def release(notenum):
.
The callback method that is called when a step is triggered. This callback will fire whether or not the step has pressed any notes. However, any pressed notes will occur before this callback is called.
The number of steps per beat (or the beat division). The minimum value allowed is 0.25, or a whole note. The pre-defined TimerStep
constants can be used here.
Update the timer object and call any relevant callbacks if a new beat step or the end of the gate of a step is reached. The actual functionality of this method will depend on the child class that utilizes the Timer
parent class.
An enum-like class representing common step divisions.
Dotted quarter note beat division
Eighth note beat division
Half note beat division
Quarter note beat division
Sixteenth note beat division
Thirtysecond note beat division
Triplet note beat division
Whole note beat division
Object which represents the parameters of a Keyboard
voice. Used to allocate Note
objects to a pre-defined number of available slots in a logical manner based on timing and keyboard mode.
index – The position of the voice in the pre-defined set of keyboard voices.
The active state of the voice. Will return True
if a note has been assigned to this voice.
The position of the voice in the pre-defined set of keyboard voices.
The Note
object assigned to this voice. When a note is assigned to a voice, the voice is “active” until the note is cleared by setting it to None
.
The last time in seconds at which a note was registered with this voice.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4