Cookbook

This is a collection of small How-Tos in the mutwo framework.

Define your events by name

from mutwo import core_events

e = core_events.Concurrence(
    [core_events.Consecution([], tag="a", core_events.Concurrence([], tag="b"]
)

# We can access events by tags
e['a'] == e[0]

Set concert pitch

You can set the concert pitch locally:

from mutwo import music_parameters

music_parameters.WesternPitch('c', 4, concert_pitch=443)

But you can also set it globally:

from mutwo import music_parameters

music_parameters.configurations.DEFAULT_CONCERT_PITCH = 443

Make a glissando

All pitches have a pitch envelope. This pitch envelope defines a glissando: you can specify how much the pitch should derive in cents from the original frequency.

from mutwo import music_parameters

pitch_with_gliss = music_parameters.DirectPitch(300, envelope=[[0, 0], [1, -100], [2, 100], [3, 0]])

Set and apply tempo of your event

All events have a tempo attribute, which can be set in order to change the tempo of your event:

from mutwo import core_events

e = core_events.Chronon(duration=1, tempo=[[0, 60], [1, 30]])

# Apply tempo envelope on event:
e.metrize()

Write polytempic music

Because each Event has its own TempoEnvelope, it’s very easy to describe polytempic music:

from mutwo import core_events

e = core_events.Concurrence(
    [
        core_events.Consecution([], tempo=[[0, 60], [1, 30]]),
        core_events.Consecution([], tempo=[[0, 40], [1, 90]]),
    ]
)

Change all pitches / volumes / … of a Consecution or Concurrence

You can use set_parameter() or mutate_parameter() to change a parameter of an event and its children:

from mutwo import core_events
from mutwo import music_events
from mutwo import music_parameters

e = core_events.Concurrence(
    [
        core_events.Consecution([music_events.NoteLike('c', 2)]),
        music_events.NoteLike('d', 2),
    ]
)

# Set the volume of all 'NoteLike' to 'fff':
e.set_parameter('volume', music_parameters.WesternVolume('fff'))

# 'set_parameter' also allows to parse a function
# which gets the previous value of the parameter.
#
# Let's rise all pitches by an octave:
e.set_parameter(
    'pitch_list',
    lambda pitch_list: pitch_list[0].add(music_parameters.DirectPitchInterval(1200))
)