Timing

class pico_synth_sandbox.timer.Timer(bpm=120, steps=2.0, gate=0.5)[source]

Bases: Task

An abstract class to help handle timing functionality of the pico_synth_sandbox.arpeggiator.Arpeggiator and pico_synth_sandbox.sequencer.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).

Parameters:
  • bpm (int) – The beats per minute of timer.

  • steps (float) – The number of steps to divide a single beat. The minimum value allowed is 0.25, or a whole note.

  • gate (float) – The duration of each pressed note per step to play before releasing. This value is a ratio from 0.0 to 1.0.

STEP_DOTTED_QUARTER = 1.5

Dotted quarter note beat division

STEP_EIGHTH = 2.0

Eighth note beat division

STEP_HALF = 0.5

Half note beat division

STEP_QUARTER = 1.0

Quarter note beat division

STEP_SIXTEENTH = 4.0

Sixteenth note beat division

STEP_THIRTYSECOND = 8.0

Thirtysecond note beat division

STEP_TRIPLET = 3.0

Triplet note beat division

STEP_WHOLE = 0.25

Whole note beat division

disable()[source]

Disable the timer object and immediately release any pressed notes.

enable()[source]

Enable the timer object to start timing beat steps and triggering note press and release callbacks. The first step will immediately trigger.

get_bpm()[source]

Get the beats per minute.

Returns:

Beats per minute

Return type:

int

get_gate()[source]

Get the note gate within a step of a beat. This value is a ratio from 0.0 to 1.0.

Returns:

gate

Return type:

float

get_steps()[source]

Get the number of steps per beat (or the beat division).

Returns:

Steps per beat

Return type:

float

is_enabled()[source]

Whether or not the timer object is enabled (running).

Returns:

enabled state

Return type:

bool

set_bpm(value)[source]

Set the beats per minute.

Parameters:

value (int) – The desired beats per minute.

set_enabled(value: bool)[source]

Directly set whether or not the timer object is enabled (running).

Parameters:

value (bool) – The state of the timer.

set_gate(value)[source]

Set the note gate within a step of a beat.

Parameters:

value (float) – The duration of each pressed note per step to play before releasing. This value is a ratio from 0.0 to 1.0.

set_press(callback)[source]

Set the callback method you would like to be called when a timed step note is pressed.

Parameters:

callback (function) – The callback method. Must have 2 parameters for note value and velocity (0.0-1.0). Ie: def press(notenum, velocity):.

set_release(callback)[source]

Set the callback method you would like to be called when a timed step note is released.

Parameters:

callback (function) – The callback method. Must have 1 parameter for note value. Velocity is always assumed to be 0.0. Ie: def release(notenum):.

set_step(callback)[source]

Set the callback method you would like to be 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.

Parameters:

callback (function) – The callback method without any parameters. Ie: def step():.

set_steps(value)[source]

Set number of steps per beat (or the beat division). The pre-defined pico_synth_sandbox.Timer.STEP_… constants can be used here.

Parameters:

value (float) – The number of steps to divide a single beat. The minimum value allowed is 0.25, or a whole note.

toggle()[source]

Toggle between the enabled and disabled timer states. Any relevant actions may occur during this process (note press and release callbacks).

async update()[source]

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 pico_synth_sandbox.timer.Timer parent class.

Monophonic Arpeggiator

class pico_synth_sandbox.arpeggiator.Arpeggiator(bpm=120, steps=2.0, mode=0, octaves=0, probability=1.0)[source]

Bases: Timer

STEP_DOTTED_QUARTER = 1.5

Dotted quarter note beat division

STEP_EIGHTH = 2.0

Eighth note beat division

STEP_HALF = 0.5

Half note beat division

STEP_QUARTER = 1.0

Quarter note beat division

STEP_SIXTEENTH = 4.0

Sixteenth note beat division

STEP_THIRTYSECOND = 8.0

Thirtysecond note beat division

STEP_TRIPLET = 3.0

Triplet note beat division

STEP_WHOLE = 0.25

Whole note beat division

disable()

Disable the timer object and immediately release any pressed notes.

enable()

Enable the timer object to start timing beat steps and triggering note press and release callbacks. The first step will immediately trigger.

get_bpm()

Get the beats per minute.

Returns:

Beats per minute

Return type:

int

get_gate()

Get the note gate within a step of a beat. This value is a ratio from 0.0 to 1.0.

Returns:

gate

Return type:

float

get_steps()

Get the number of steps per beat (or the beat division).

Returns:

Steps per beat

Return type:

float

is_enabled()

Whether or not the timer object is enabled (running).

Returns:

enabled state

Return type:

bool

set_bpm(value)

Set the beats per minute.

Parameters:

value (int) – The desired beats per minute.

set_enabled(value: bool)

Directly set whether or not the timer object is enabled (running).

Parameters:

value (bool) – The state of the timer.

set_gate(value)

Set the note gate within a step of a beat.

Parameters:

value (float) – The duration of each pressed note per step to play before releasing. This value is a ratio from 0.0 to 1.0.

set_press(callback)

Set the callback method you would like to be called when a timed step note is pressed.

Parameters:

callback (function) – The callback method. Must have 2 parameters for note value and velocity (0.0-1.0). Ie: def press(notenum, velocity):.

set_release(callback)

Set the callback method you would like to be called when a timed step note is released.

Parameters:

callback (function) – The callback method. Must have 1 parameter for note value. Velocity is always assumed to be 0.0. Ie: def release(notenum):.

set_step(callback)

Set the callback method you would like to be 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.

Parameters:

callback (function) – The callback method without any parameters. Ie: def step():.

set_steps(value)

Set number of steps per beat (or the beat division). The pre-defined pico_synth_sandbox.Timer.STEP_… constants can be used here.

Parameters:

value (float) – The number of steps to divide a single beat. The minimum value allowed is 0.25, or a whole note.

toggle()

Toggle between the enabled and disabled timer states. Any relevant actions may occur during this process (note press and release callbacks).

async update()

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 pico_synth_sandbox.timer.Timer parent class.

Multi-Track Sequencer

class pico_synth_sandbox.sequencer.Sequencer(length=16, tracks=1, bpm=120)[source]

Bases: Timer

Sequence notes using the pico_synth_sandbox.timer.Timer class to create a multi-track sixteenth 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.

Parameters:
  • length (int) – The number of sixteenth note steps of each track. The minimum value allowed is 1.

  • tracks (int) – The number of tracks to create and sequence. The minimum value allowed is 1.

  • bpm (int) – The beats per minute of timer.

STEP_DOTTED_QUARTER = 1.5

Dotted quarter note beat division

STEP_EIGHTH = 2.0

Eighth note beat division

STEP_HALF = 0.5

Half note beat division

STEP_QUARTER = 1.0

Quarter note beat division

STEP_SIXTEENTH = 4.0

Sixteenth note beat division

STEP_THIRTYSECOND = 8.0

Thirtysecond note beat division

STEP_TRIPLET = 3.0

Triplet note beat division

STEP_WHOLE = 0.25

Whole note beat division

disable()

Disable the timer object and immediately release any pressed notes.

enable()

Enable the timer object to start timing beat steps and triggering note press and release callbacks. The first step will immediately trigger.

get_bpm()

Get the beats per minute.

Returns:

Beats per minute

Return type:

int

get_gate()

Get the note gate within a step of a beat. This value is a ratio from 0.0 to 1.0.

Returns:

gate

Return type:

float

get_length()[source]

Get the number of sixteenth notes for each track.

Returns:

track length

Return type:

int

get_note(position, track=0)[source]

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.

Parameters:
  • position (int) – Index of the step (0-based). Will be limited to the track length.

  • track (int) – Index of the track (0-based). Will be limited to the track count.

Returns:

note data (notenum, velocity)

Return type:

tuple

get_position()[source]

Get the current position of the sequencer within the track length (0-based).

Returns:

sequencer position

Return type:

int

get_steps()

Get the number of steps per beat (or the beat division).

Returns:

Steps per beat

Return type:

float

get_track(track=0)[source]

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.

Returns:

track data list of note tuples as (notenum, velocity)

Return type:

list

get_tracks()[source]

Get the number tracks being sequenced.

Returns:

track count

Return type:

int

has_note(position, track=0)[source]

Check whether or note a specific step within a track has been set with note data.

Parameters:
  • position (int) – Index of the step (0-based). Will be limited to the track length.

  • track (int) – Index of the track (0-based). Will be limited to the track count.

Returns:

if the track step has a note

Return type:

bool

is_enabled()

Whether or not the timer object is enabled (running).

Returns:

enabled state

Return type:

bool

remove_note(position, track=0)[source]

Remove the note data as a specific step within a track.

Parameters:
  • position (int) – Index of the step (0-based). Will be limited to the track length.

  • track (int) – Index of the track (0-based). Will be limited to the track count.

set_bpm(value)

Set the beats per minute.

Parameters:

value (int) – The desired beats per minute.

set_enabled(value: bool)

Directly set whether or not the timer object is enabled (running).

Parameters:

value (bool) – The state of the timer.

set_gate(value)

Set the note gate within a step of a beat.

Parameters:

value (float) – The duration of each pressed note per step to play before releasing. This value is a ratio from 0.0 to 1.0.

set_length(value)[source]

Set the number of sixteenth notes 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.

Parameters:

value (int) – The number of sixteenth note steps of each track. The minimum value allowed is 1.

set_note(position, notenum, velocity=1.0, track=0)[source]

Set the note value and velocity of a track at a specific step index.

Parameters:
  • position (int) – Index of the step (0-based). Will be limited to the track length.

  • notenum (int) – Value of the note.

  • velocity (float) – Velocity of the note (0.0-1.0).

  • track (int) – Index of the track (0-based). Will be limited to the track count.

set_press(callback)

Set the callback method you would like to be called when a timed step note is pressed.

Parameters:

callback (function) – The callback method. Must have 2 parameters for note value and velocity (0.0-1.0). Ie: def press(notenum, velocity):.

set_release(callback)

Set the callback method you would like to be called when a timed step note is released.

Parameters:

callback (function) – The callback method. Must have 1 parameter for note value. Velocity is always assumed to be 0.0. Ie: def release(notenum):.

set_step(callback)

Set the callback method you would like to be 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.

Parameters:

callback (function) – The callback method without any parameters. Ie: def step():.

set_steps(value)

Set number of steps per beat (or the beat division). The pre-defined pico_synth_sandbox.Timer.STEP_… constants can be used here.

Parameters:

value (float) – The number of steps to divide a single beat. The minimum value allowed is 0.25, or a whole note.

set_tracks(value)[source]

Set 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.

Parameters:

value (int) – The number of tracks to sequence. The minimum value allowed is 1.

toggle()

Toggle between the enabled and disabled timer states. Any relevant actions may occur during this process (note press and release callbacks).

async update()

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 pico_synth_sandbox.timer.Timer parent class.