NoteEvent

NoteEvent(duration: Duration | None = None, tones: set[Tone])

A NoteEvent is a SequentialEvent that contains zero or more Tones played simultaneously within a single voice, line, or part.

A NoteEvent with zero tones is not considered a rest, but rather a duration with unspecified tonal content — either because the tonal content doesn’t need to be specified (for example, a comping chart), or because it has not yet been specified (for example, in a sketch or draft).

A Rest is represented as a NoteEvent with a SilentTone. An unpitched percussion note is a NoteEvent holding an UnpitchedTone (in WSMN, a PercussionTone); which instrument it is on is the Part’s business.

Attributes

Name Description
__slots__
meta
id
duration
tones
is_rest True if this NoteEvent contains a SilentTone.

Methods

Name Description
__setattr__
alter_duration
add_tone Adds a tone. Adding a pitched tone to a rest un-rests it;
remove_tone
clear_tones
make_rest
swap_tone
transform_tones Replaces every tone of this NoteEvent with the result of
__repr__ >>> from openmusickit.systems.wsmn.tonal.symbols import C

__setattr__

__setattr__(name: str, value: Any)

alter_duration

alter_duration(operation: Callable[[Duration, Any], Duration], operand: Any)

add_tone

add_tone(tone: Tone)

Adds a tone. Adding a pitched tone to a rest un-rests it; adding a SilentTone to a pitched NoteEvent is a no-op.

>>> from openmusickit.systems.wsmn.tonal.symbols import C
>>> rest = Rest(None)
>>> rest.add_tone(C)
>>> rest.tones == {C}
True
>>> rest.add_tone(SilentTone())
>>> rest.tones == {C}
True

remove_tone

remove_tone(tone: Tone)

clear_tones

clear_tones()

make_rest

make_rest()

swap_tone

swap_tone(old_tone: Tone, new_tone: Tone)

transform_tones

transform_tones(operation: Callable[..., Tone], *args, **kwargs)

Replaces every tone of this NoteEvent with the result of operation(tone, *args, **kwargs). Tones of a universal tonal system (a SilentTone) belong to no system, so no system’s operation applies to them: they are left as they are.

operation is typically a method of the relevant Tone subclass (such as TonalVector.transpose), but any callable that accepts a Tone as its first argument and returns a Tone will do. The result need not be of the same type (an operation may translate tones from one tonal system to another), but if it is not a Tone at all, a TypeError is raised and the NoteEvent is unchanged.

Examples

>>> from openmusickit.systems.wsmn.tonal.symbols import C, E, G, Gx, B, M3
>>> from openmusickit.systems.wsmn.tonal.tonal_vector import TonalVector, TonalDirection

Transposition, with the interval passed as the operand:

>>> note = NoteEvent(tones={C, E, G})
>>> note.transform_tones(TonalVector.transpose, M3)
>>> note.tones == {E, Gx, B}
True
>>> note.transform_tones(TonalVector.transpose, M3, TonalDirection.DOWN)
>>> note.tones == {C, E, G}
True

A user-defined operation that needs no operand:

>>> def sharpen(tv):
...     return tv + TonalVector((0, 1))
>>> note.transform_tones(sharpen)
>>> note.tones == {TonalVector((0, 1)), TonalVector((2, 5)), TonalVector((4, 8))}
True

An operation that does not produce a Tone is rejected:

>>> note.transform_tones(str)
Traceback (most recent call last):
...
TypeError: ...

A rest stays a rest:

>>> rest = Rest(None)
>>> rest.transform_tones(TonalVector.transpose, M3)
>>> rest
Rest(duration=None)

__repr__

__repr__()
>>> from openmusickit.systems.wsmn.tonal.symbols import C
>>> NoteEvent(tones={C}, duration=None)
NoteEvent(tones=[TonalVector((0, 0))], duration=None)
>>> Rest(None)
Rest(duration=None)