ipytone.Part#

class ipytone.Part(**kwargs: Any)#

Bases: Event

A collection of events (notes) that can be handled as a single unit.

Currently doesn’t support access to the underlying Event instances from within Python.

__init__(callback=None, events=None, **kwargs)#
Parameters:
  • callback (callable, optional) – Scheduling callback, which must accept two arguments (time, value).

  • events (list, optional) – A list of note events, i.e., each item being a Note instance or a dictionnary with “time”, “note” (and optionally “velocity”) keys.

Methods

add(note)

Add an event (note) to the part.

at(time, note)

Add or set a note at a given time.

cancel([time])

Clear all scheduled events of this Event greater or equal to the given (transport) time.

clear()

Remove all note events from the part.

dispose()

Dispose and disconnect this node.

remove([time, note])

Remove one or more events (notes) from the part.

schedule_dlink(target[, update_interval, ...])

Link a source attribute of this ipytone widget with a target widget attribute.

schedule_jsdlink(target[, update_interval, ...])

Link a source attribute of this ipytone widget with a target widget attribute.

schedule_observe(handler[, update_interval, ...])

Setup a handler to be called at regular intervals with the updated time / value of this ipytone widget.

schedule_unobserve(handler)

Cancel the scheduled updates of the time / value trait associated with the given handler.

start([time])

Start the event at the given (transport) time.

stop([time])

Stop the event at the given (transport) time.

Attributes

callback

disposed

Returns True if the node was disposed (i.e., disconnected and web audio node freed for garbage collection).

humanize

if True, apply small or user-defined random variations to callback time

length

number of scheduled notes in the part

log

A trait whose value must be an instance of a specified class.

loop

Loop the event indefinitely (True) or a given number of times

loop_end

loop ending (transport) time

loop_start

loop starting (transport) time

mute

if True, the callback is deactivated

name

A trait for unicode strings.

playback_rate

Playback rate of the event (normal speed is 1)

probability

probability of the event being triggered

start_offset

start from scheduled start time (ticks)

value

A trait which allows any value.

add(note)#

Add an event (note) to the part.

Parameters:

note (dict-like or Note) – The note event to add. If a dictionary is passed, it must contain at least the “time” and “note” keys, and optionally a “velocity” key.

at(time, note)#

Add or set a note at a given time.

Unlike in Tone.js, it doesn’t return any Event.

cancel(time=None)#

Clear all scheduled events of this Event greater or equal to the given (transport) time.

clear()#

Remove all note events from the part.

dispose()#

Dispose and disconnect this node.

property disposed#

Returns True if the node was disposed (i.e., disconnected and web audio node freed for garbage collection).

humanize#

if True, apply small or user-defined random variations to callback time

length#

number of scheduled notes in the part

loop#

Loop the event indefinitely (True) or a given number of times

loop_end#

loop ending (transport) time

loop_start#

loop starting (transport) time

mute#

if True, the callback is deactivated

playback_rate#

Playback rate of the event (normal speed is 1)

probability#

probability of the event being triggered

remove(time=None, note=None)#

Remove one or more events (notes) from the part.

Parameters:
  • time (float or str, optional) – If provided, remove all events scheduled at that time.

  • note (dict-like or Note) – Remove a specific note event.

Link a source attribute of this ipytone widget with a target widget attribute.

As the source attribute may have a continuously updated value (e.g., the gain of an audio signal, the current value of a parameter, etc.), The target widget attribute is synchronized at a given, finite resolution.

Parameters:
  • target ((object, str) tuple) – The target widget attribute to link, given as a (widget, attr_name) tuple.

  • update_interval (float or string, optional) – The interval at which the target attribute is updated in the front-end, in seconds (default: 0.04). If transport=True, any interval accepted by schedule_repeat() is also valid here.

  • transport (bool, optional) – if True, the target attribute is synced along the ipytone.Transport timeline, i.e., no update happens until the transport starts and updates stop when the transport stops. If False (default), the target attribute update is done with respect to the active audio context.

  • name (str, optional) – The name of the (source) Tone.js attribute to link. See schedule_observe for more details and for a list of available names.

Returns:

link – A link object that can be used to unlink the widget attributes (using the .unlink() method).

Return type:

ToneDirectionalLink

Link a source attribute of this ipytone widget with a target widget attribute.

The link is created in the front-end and does not rely on a roundtrip to the backend.

As the source attribute may have a continuously updated value (e.g., the gain of an audio signal, the current value of a parameter, etc.), The target widget attribute is synchronized at a given, finite resolution.

Parameters:
  • target ((object, str) tuple) – The target widget attribute to link, given as a (widget, attr_name) tuple.

  • update_interval (float or string, optional) – The interval at which the target attribute is updated in the front-end, in seconds (default: 0.04). If transport=True, any interval accepted by schedule_repeat() is also valid here.

  • transport (bool, optional) – if True, the target attribute is synced along the ipytone.Transport timeline, i.e., no update happens until the transport starts and updates stop when the transport stops. If False (default), the target attribute update is done with respect to the active audio context.

  • name (str, optional) – The name of the (source) Tone.js attribute to link. See schedule_observe for more details and for a list of available names.

Returns:

link – A link object that can be used to unlink the widget attributes (using the .unlink() method).

Return type:

ToneDirectionalLink

schedule_observe(handler, update_interval=1, transport=False, name=None, observe_time=False)#

Setup a handler to be called at regular intervals with the updated time / value of this ipytone widget.

Parameters:
  • handler (callable) – A callable that is called when the trait value is updated at regular intervals. The signature of the callable is similar to the signature expected by ipywidgets.Widget.observe(). Note that the handler will only apply to the trait given by the name argument here.

  • update_interval (float or string, optional) – The interval at which the trait is updated in the front-end, in seconds (default: 1). If transport=True, any interval accepted by schedule_repeat() is also valid here.

  • transport (bool, optional) – if True, the trait update is scheduled along the ipytone.Transport timeline, i.e., the handler is not called until the transport starts and will stop being called when the transport stops. If False (default), the trait update is done with respect to the active audio context.

  • name (str, optional) –

    The name of the Tone.js attribute to observe. Note that it doesn’t necessarily correspond to a trait of this ipytone widget. Instead, it may accept one of the following names (depending the observed ipytone widget, only a few may be supported):

    • ”time”: the current time (either transport time or audio context time).

    • ”value”: the current value of the Tone.js corresponding instance.

    • ”state”: current playback state

    • ”progress”: current progress (of an event or transport loop)

    • ”position”: current transport position in Bars:Beats:Sixteenths

    • ”ticks”: current transport tick position

    • ”seconds”: current transport time in seconds

    The default name also depends on the observed ipytone widget.

  • observe_time (bool, optional) – If True, both the (current audio context or transport) time and trait value are passed to the handler as a (time, trait_value) tuple when the trait value is updated (default: False).

schedule_unobserve(handler)#

Cancel the scheduled updates of the time / value trait associated with the given handler.

start(time=None)#

Start the event at the given (transport) time.

start_offset#

start from scheduled start time (ticks)

stop(time=None)#

Stop the event at the given (transport) time.