Tone

Tone()

A Tone is a defined pitch or sound type within a TonalSystem.

Subclasses of Tone define a type of musical sound, noise, or silence with its own logical system of relationships, which are defined within the Tone subclass in concert with a subclass of Interval.

For example, see the following subclasses:

  • TonalVector encapsulates the 12-note diatonic/chromatic logic of Western music, and represents either a pitch or an interval. (TonalVector also subclasses Interval.)

  • SilentTone represents any rest or silence.

  • UnpitchedTone is the base for sounds with no pitch (a drum stroke, a clap); WSMN’s PercussionTone implements it.

>>> from openmusickit.systems.wsmn.tonal.tonal_vector import TonalVector
>>> from openmusickit.values.tone.silent_tone import SilentTone
>>> isinstance(TonalVector((0, 0)), Tone)
True
>>> isinstance(SilentTone(), Tone)
True
>>> TonalVector((0, 0)).tonal_system.name
'Western Standard Music Notation'

Tone and Interval should be subclassed to represent the members and relationships of any other pitch or sonic system.

Subclasses of Tone should be immutable and hashable, comparing by value, as they represent abstract values (‘C# above middle C’), rather than concrete instances of a note in a score.

Attributes

Name Description
__slots__
tonal_system The TonalSystem this tone belongs to (for introspection and compatibility checks).
pitch The PitchRepresentation of this Tone, defined within a specific

Methods

Name Description
from_string Parses a string and returns a Tone.
__format__ Display form of the Tone, used by str.format and f-strings.

from_string

from_string(s: str)

Parses a string and returns a Tone.

An optional hook: systems with a string form override it; the base raises.

>>> from openmusickit.systems.wsmn.tonal.tonal_vector import TonalVector
>>> TonalVector.from_string("G#")
TonalVector((4, 8))
>>> Tone.from_string("G#")
Traceback (most recent call last):
...
NotImplementedError

__format__

__format__(spec: str)

Display form of the Tone, used by str.format and f-strings.

For pitched tones, the format spec names an attribute of the Tone’s PitchRepresentation, defaulting to unicode; unpitched tones fall back to str(). str() and repr() are unaffected, so they remain available as debug forms (use {tone!r} or {tone!s} in a template to get them).

>>> from openmusickit.systems.wsmn.tonal.tonal_vector import TonalVector
>>> from openmusickit.values.tone.silent_tone import SilentTone
>>> Eb = TonalVector((2, 3))
>>> f"{Eb} major"
'E♭ major'
>>> f"{Eb:ascii} major"
'Eb major'
>>> f"{Eb!r}"
'TonalVector((2, 3))'
>>> f"{SilentTone()}"
'SilentTone()'

The spec must name a string attribute of the PitchRepresentation:

>>> f"{Eb:nonsense}"
Traceback (most recent call last):
...
ValueError: ...