ModalContextEvent

ModalContextEvent(
    duration: Duration | None = None,
    modal_context: ModalContext | None = None,
)

Sets the modal context (in WSMN, the key or key signature) for the material that follows.

None means undefined or undecided. For WSMN, “no key” is symbols.NoKey and a bare key signature is Key.from_signature(...); the printed signature is reached through the Key (event.modal_context.signature), never through the event.

Attributes

Name Description
__slots__
meta
id
duration
modal_context

Methods

Name Description
__setattr__
alter_duration
transform_tones Replaces the modal context, in place, with modal_context.transform(operation, ...).

__setattr__

__setattr__(name: str, value: Any)

alter_duration

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

transform_tones

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

Replaces the modal context, in place, with modal_context.transform(operation, ...).

An event with no modal context is left as it is, with an OmkWarning that callers can catch or filter.

Examples

>>> from openmusickit.systems.wsmn.tonal.key import Key, KeySignature
>>> from openmusickit.systems.wsmn.tonal.symbols import C, M2, m3, P5, Major
>>> from openmusickit.systems.wsmn.tonal.tonal_vector import TonalVector, TonalDirection

A Key moves to a new tonic, keeping its mode:

>>> event = ModalContextEvent(modal_context=Key.of(C, Major))
>>> event.transform_tones(TonalVector.transpose, M2)
>>> event.modal_context.name, event.modal_context.signature
('D Major', KeySignature(c=1, f=1))
>>> event.transform_tones(TonalVector.transpose, P5, TonalDirection.DOWN)
>>> event.modal_context.name
'G Major'

A bare key signature is transformed letter by letter:

>>> event = ModalContextEvent(modal_context=Key.from_signature(KeySignature()))
>>> event.transform_tones(TonalVector.transpose, m3)
>>> event.modal_context.signature, event.modal_context.tonic
(KeySignature(e=-1, a=-1, b=-1), None)

An empty event warns and is unchanged:

>>> import warnings
>>> event = ModalContextEvent()
>>> with warnings.catch_warnings(record=True) as caught:
...     warnings.simplefilter("always")
...     event.transform_tones(TonalVector.transpose, M2)
>>> event.modal_context is None, str(caught[0].message)
(True, 'You are attempting to transform an event with no modal context. Nothing will happen.')