mutwo.music_events§
Object |
Documentation |
---|---|
NoteLike represents traditional discreet musical objects. |
- class NoteLike(pitch_list='c', duration=1, volume='mf', grace_note_sequential_event=None, after_grace_note_sequential_event=None, playing_indicator_collection=None, notation_indicator_collection=None, lyric=<mutwo.music_parameters.lyrics.DirectLyric object>)[source]§
NoteLike represents traditional discreet musical objects.
- Parameters:
pitch_list (Optional[Union[Pitch, Sequence, float, Fraction, int]]) – The pitch or pitches of the event. This can be a pitch object (any class that inherits from
mutwo.music_parameters.abc.Pitch
) or a list of pitch objects. Furthermore mutwo supports syntactic sugar to convert other objects on the fly to pitch objects: Atring can be read as pitch class names to buildmutwo.music_parameters.WesternPitch
objects or as ratios to buildmutwo.music_parameters.JustIntonationPitch
objects. Fraction will also buildmutwo.music_parameters.JustIntonationPitch
objects. Other numbers (integer and float) will be read as pitch class numbers to makemutwo.music_parameters.WesternPitch
objects.duration (Union[float, Fraction, int]) – The duration of
NoteLike
. This can be any number. The unit of the duration is up to the interpretation of the user and the respective converter routine that will be used.volume (Union[Volume, float, Fraction, int, str]) – The volume of the event. Can either be a object of
mutwo.music_parameters.abc.Volume
, a number or a string. If the number ranges from 0 to 1, mutwo automatically generates amutwo.music_parameters.DirectVolume
object (and the number will be interpreted as the amplitude). If the number is smaller than 0, automatically generates amutwo.music_parameters.volumes.DecibelVolume
object (and the number will be interpreted as decibel). If the argument is a string, mutwo will try to initialise amutwo.music_parameters.volumes.WesternVolume
object.grace_note_sequential_event (core_events.SequentialEvent[NoteLike]) –
after_grace_note_sequential_event (core_events.SequentialEvent[NoteLike]) –
playing_indicator_collection (music_parameters.playing_indicator_collection.PlayingIndicatorCollection) – A
PlayingIndicatorCollection
. Playing indicators alter the sound ofNoteLike
(e.g. tremolo, fermata, pizzicato).notation_indicator_collection (music_parameters.notation_indicator_collection.NotationIndicatorCollection) – A
NotationIndicatorCollection
. Notation indicators alter the visual representation ofNoteLike
(e.g. ottava, clefs) without affecting the resulting sound.lyric (core_parameters.abc.Lyric) –
By default mutwo doesn’t differentiate between Tones, Chords and Rests, but rather simply implements one general class which can represent any of the mentioned definitions (e.g. a NoteLike object with several pitches may be called a ‘Chord’ and a NoteLike object with only one pitch may be called a ‘Tone’).
Example:
>>> from mutwo import music_parameters >>> from mutwo import music_events >>> tone = music_events.NoteLike(music_parameters.WesternPitch('a'), 1, 1) >>> other_tone = music_events.NoteLike('3/2', 1, 0.5) >>> chord = music_events.NoteLike( [music_parameters.WesternPitch('a'), music_parameters.JustIntonationPitch('3/2')], 1, 1 ) >>> other_chord = music_events.NoteLike('c4 dqs3 10/7', 1, 3)
Public Data Attributes:
The pitch or pitches of the event.
The volume of the event.
core_events.SequentialEvent
beforeNoteLike
core_events.SequentialEvent
afterNoteLike
Inherited from
SimpleEvent
The duration of an event.
Inherited from
Event
The duration of an event.
The dynamic tempo of an event; specified as an envelope.
Public Methods:
__init__
([pitch_list, duration, volume, ...])Inherited from
SimpleEvent
__init__
([pitch_list, duration, volume, ...])__eq__
(other)Test for checking if two objects are equal.
__repr__
()Return repr(self).
Adapted deep copy method that returns a new object for every leaf.
get_parameter
(parameter_name[, flat, ...])Return event attribute with the entered name.
set_parameter
(parameter_name, object_or_function)Sets event parameter to new value.
mutate_parameter
(parameter_name, function)Mutate parameter with a function.
metrize
([mutate])Apply tempo envelope of event on itself
cut_out
(start, end)Time-based slicing of the respective event.
cut_off
(start, end)Time-based deletion / shortening of the respective event.
Inherited from
Event
__init__
([pitch_list, duration, volume, ...])copy
()Return a deep copy of the given Event.
Adapted deep copy method that returns a new object for every leaf.
set
(attribute_name, value)Set an attribute of the object to a specific value
get_parameter
(parameter_name[, flat, ...])Return event attribute with the entered name.
set_parameter
(parameter_name, object_or_function)Sets event parameter to new value.
mutate_parameter
(parameter_name, function)Mutate parameter with a function.
Set events tempo envelope so that one beat equals one second (tempo 60).
metrize
([mutate])Apply tempo envelope of event on itself
cut_out
(start, end)Time-based slicing of the respective event.
cut_off
(start, end)Time-based deletion / shortening of the respective event.
split_at
(absolute_time)Split event in two events at
absolute_time
.Private Data Attributes:
_parameter_to_print_tuple
Return tuple of attribute names which shall be printed for repr.
_abc_impl
Inherited from
SimpleEvent
_parameter_to_print_tuple
Return tuple of attribute names which shall be printed for repr.
_parameter_to_compare_tuple
Return tuple of attribute names which values define the
SimpleEvent
._abc_impl
Inherited from
Event
_abc_impl
Inherited from
ABC
_abc_impl
- cut_off(start, end)§
Time-based deletion / shortening of the respective event.
- Parameters:
- Return type:
Example:
>>> from mutwo import core_events >>> sequential_event = core_events.SequentialEvent( >>> [core_events.SimpleEvent(3), core_events.SimpleEvent(2)] >>> ) >>> sequential_event.cut_off(1, 3) >>> print(sequential_event) SequentialEvent([SimpleEvent(duration = 1), SimpleEvent(duration = 1)])
- cut_out(start, end)§
Time-based slicing of the respective event.
- Parameters:
- Return type:
Example:
>>> from mutwo import core_events >>> sequential_event = core_events.SequentialEvent( >>> [core_events.SimpleEvent(3), core_events.SimpleEvent(2)] >>> ) >>> sequential_event.cut_out(1, 4) >>> print(sequential_event) SequentialEvent([SimpleEvent(duration = 2), SimpleEvent(duration = 1)])
- destructive_copy()§
Adapted deep copy method that returns a new object for every leaf.
It’s called ‘destructive’, because it forgets potential repetitions of the same object in compound objects. Instead of reproducing the original structure of the compound object that shall be copied, every repetition of the same reference will return a new unique independent object.
The following example shall illustrate the difference between copy.deepcopy and destructive_copy:
>>> import copy >>> from mutwo import core_events >>> my_simple_event_0 = core_events.SimpleEvent(2) >>> my_simple_event_1 = core_events.SimpleEvent(3) >>> my_sequential_event = core_events.SequentialEvent( >>> [my_simple_event_0, my_simple_event_1, my_simple_event_0] >>> ) >>> deepcopied_event = copy.deepcopy(my_sequential_event) >>> destructivecopied_event = my_sequential_event.destructive_copy() >>> deepcopied_event[0].duration = 10 # setting the duration of the first event >>> destructivecopied_event[0].duration = 10 >>> # return True because the first and the third objects share the same >>> # reference (both are the same copy of 'my_simple_event_0') >>> deepcopied_event[0].duration == deepcopied_event[2].duration True >>> # return False because destructive_copy forgets the shared reference >>> destructivecopied_event[0].duration == destructivecopied_event[2].duration False
- Return type:
- get_parameter(parameter_name, flat=False, filter_undefined=False)§
Return event attribute with the entered name.
- Parameters:
parameter_name (str) – The name of the attribute that shall be returned.
flat (filter_undefined) –
True
for flat sequence of parameter values,False
if the resultingtuple
shall repeat the nested structure of the event.filter_undefined (bool) – If set to
True
allNone
values will be filtered from the returned tuple. Default toFalse
. This flag has no effect onget_parameter()
ofmutwo.core_events.SimpleEvent
.
- Returns:
Return tuple containing the assigned values for each contained event. If an event doesn’t posses the asked parameter, mutwo will simply add None to the tuple for the respective event.
- Return type:
Any
Example:
>>> from mutwo import core_events >>> sequential_event = core_events.SequentialEvent( >>> [core_events.SimpleEvent(2), core_events.SimpleEvent(3)] >>> ) >>> sequential_event.get_parameter('duration') (2, 3) >>> simple_event = core_events.SimpleEvent(10) >>> simple_event.get_parameter('duration') DirectDuration(10) >>> simple_event.get_parameter('undefined_parameter') None
- metrize(mutate=True)§
Apply tempo envelope of event on itself
Metrize is only syntactic sugar for a call of
EventToMetrizedEvent
:>>> from mutwo import core_converters >>> core_converters.EventToMetrizedEvent().convert( >>> my_event >>> ) == my_event.metrize() True
- Parameters:
mutate (bool) –
- Return type:
- mutate_parameter(parameter_name, function)§
Mutate parameter with a function.
- Parameters:
parameter_name (str) – The name of the parameter which shall be mutated.
function (Union[Callable[[Any], None], Any]) – The function which mutates the parameter. The function gets as an input the assigned value for the passed parameter_name of the respective object. The function shouldn’t return anything, but simply calls a method of the parameter value.
mutate – If
False
the function will return a copy of the given object. If set toTrue
the object itself will be changed and the function will return the changed object. Default toTrue
.
- Return type:
This method is useful when a particular parameter has been assigned to objects that know methods which mutate themselves. Then ‘mutate_parameter’ is a convenient wrapper to call the methods of those parameters for all children events.
Example:
>>> from mutwo import core_events >>> from mutwo import music_events >>> from mutwo import music_parameters >>> sequential_event = core_events.SequentialEvent( >>> [ >>> music_events.NoteLike( >>> [ >>> music_parameters.WesternPitch('c', 4), >>> music_parameters.WesternPitch('e', 4)], >>> ], >>> 2, 1, >>> ) >>> ] >>> ) >>> sequential_event.mutate_parameter( >>> 'pitch_list', lambda pitch_list: [pitch.add(12) for pitch in pitch_list] >>> ) >>> # now all pitches should be one octave higher (from 4 to 5) >>> sequential_event.get_parameter('pitch_list') ([WesternPitch(c5), WesternPitch(e5)],)
- reset_tempo_envelope()§
Set events tempo envelope so that one beat equals one second (tempo 60).
- Parameters:
mutate – If
False
the function will return a copy of the given object. If set toTrue
the object itself will be changed and the function will return the changed object. Default toTrue
.- Return type:
Example:
>>> from mutwo import core_events >>> simple_event = core_events.SimpleEvent(duration = 1) >>> simple_event.tempo_envelope[0].value = 100 >>> print(simple_event.tempo_envelope) TempoEnvelope([SimpleEvent(curve_shape = 0, duration = DirectDuration(duration = 1), value = 100), SimpleEvent(curve_shape = 0, duration = DirectDuration(duration = 0), value = 60)]) >>> simple_event.reset_tempo_envelope() >>> print(simple_event.tempo_envelope) TempoEnvelope([SimpleEvent(curve_shape = 0, duration = DirectDuration(duration = 1), value = 60), SimpleEvent(curve_shape = 0, duration = DirectDuration(duration = 0), value = 60)])
- set(attribute_name, value)§
Set an attribute of the object to a specific value
- Parameters:
attribute_name (str) – The name of the attribute which value shall be set.
value (Any) – The value which shall be assigned to the given
attribute_name
mutate – If
False
the function will return a copy of the given object. If set toTrue
the object itself will be changed and the function will return the changed object. Default toTrue
.
- Returns:
The event.
- Return type:
This function is merely a convenience wrapper for…
>>> event.attribute_name = value
Because the function return the event itself it can be used in function composition.
Example:
>>> from mutwo import core_events >>> sequential_event = core_events.SequentialEvent([core_events.SimpleEvent(2)]) >>> sequential_event.set('duration', 10).set('my_new_attribute', 'hello-world!')
- set_parameter(parameter_name, object_or_function, set_unassigned_parameter=True)§
Sets event parameter to new value.
- Parameters:
parameter_name (str) – The name of the parameter which values shall be changed.
object_or_function (Union[Callable[[Any], Any], Any]) – For setting the parameter either a new value can be passed directly or a function can be passed. The function gets as an argument the previous value that has had been assigned to the respective object and has to return a new value that will be assigned to the object.
set_unassigned_parameter (bool) – If set to
False
a new parameter will only be assigned to an Event if the Event already has a attribute with the respective parameter_name. If the Event doesn’t know the attribute yet and set_unassigned_parameter is False, the method call will simply be ignored.mutate – If
False
the function will return a copy of the given object. If set toTrue
the object itself will be changed and the function will return the changed object. Default toTrue
.
- Return type:
Example:
>>> from mutwo import core_events >>> simple_event = core_events.SimpleEvent(2) >>> simple_event.set_parameter( >>> 'duration', lambda old_duration: old_duration * 2 >>> ) >>> simple_event.duration 4 >>> simple_event.set_parameter('duration', 3) >>> simple_event.duration 3 >>> simple_event.set_parameter( >>> 'unknown_parameter', 10, set_unassigned_parameter=False >>> ) # this will be ignored >>> simple_event.unknown_parameter AttributeError: 'SimpleEvent' object has no attribute 'unknown_parameter' >>> simple_event.set_parameter( >>> 'unknown_parameter', 10, set_unassigned_parameter=True >>> ) # this will be written >>> simple_event.unknown_parameter 10
- split_at(absolute_time)§
Split event in two events at
absolute_time
.- Parameters:
absolute_time (Duration) – where event shall be split
- Returns:
Two events that result from splitting the present event.
- Return type:
tuple[mutwo.core_events.abc.Event, mutwo.core_events.abc.Event]
Example:
>>> from mutwo import core_events >>> sequential_event = core_events.SequentialEvent([core_events.SimpleEvent(3)]) >>> sequential_event.split_at(1) (SequentialEvent([SimpleEvent(duration = 1)]), SequentialEvent([SimpleEvent(duration = 2)])) >>> sequential_event[0].split_at(1) (SimpleEvent(duration = 1), SimpleEvent(duration = 2))
- property after_grace_note_sequential_event: SequentialEvent[SimpleEvent]§
core_events.SequentialEvent
afterNoteLike
- property duration: Duration§
The duration of an event.
This has to be an instance of
mutwo.core_parameters.abc.Duration
.
- property grace_note_sequential_event: SequentialEvent[SimpleEvent]§
core_events.SequentialEvent
beforeNoteLike
- parameter_to_exclude_from_representation_tuple = ('tempo_envelope',)§
- property pitch_list: Any§
The pitch or pitches of the event.
- property tempo_envelope: TempoEnvelope§
The dynamic tempo of an event; specified as an envelope.
Tempo envelopes are represented as
core_events.TempoEnvelope
objects. Tempo envelopes are valid for its respective event and all its children events.
- property volume: Any§
The volume of the event.
mutwo.music_events.configurations§
Set default values for mutwo.music_events.NoteLike
.