Previous topic

music21.duration

Next topic

music21.editorial

Table Of Contents

Table Of Contents

This Page

music21.dynamics

Classes and functions for creating and manipulating dynamic symbols. Rather than subclasses, the Dynamic object is often specialized by parameters.

Functions

music21.dynamics.dynamicStrFromDecimal(n)

Given a decimal from 0 to 1, return a string representing a dynamic with 0 being the softest (0.01 = ‘ppp’) and 1 being the loudest (0.9+ = ‘fff’) 0 returns “n” (niente), while ppp and fff are the loudest dynamics used.

>>> dynamics.dynamicStrFromDecimal(0.25)
'pp'
>>> dynamics.dynamicStrFromDecimal(1)
'fff'

Dynamic

class music21.dynamics.Dynamic(value=None)

Object representation of Dynamics.

>>> pp1 = dynamics.Dynamic('pp')
>>> pp1.value
'pp'
>>> pp1.longName
'pianissimo'
>>> pp1.englishName
'very soft'

Dynamics can also be specified on a 0 to 1 scale with 1 being the loudest (see dynamicStrFromDecimal() above)

>>> pp2 = dynamics.Dynamic(0.15) # on 0 to 1 scale
>>> pp2.value
'ppp'
>>> print '%.2f' % pp2.volumeScalar
0.15

Dynamics can be placed anywhere in a stream.

>>> s = stream.Stream()
>>> s.insert(0, note.HalfNote('E-4'))
>>> s.insert(2, note.HalfNote('F#5'))
>>> s.insert(0, dynamics.Dynamic('pp'))
>>> s.insert(1, dynamics.Dynamic('mf'))
>>> s.insert(3, dynamics.Dynamic('fff'))
>>> s.show()
../_images/dynamics_simple.png

Dynamic bases

Dynamic read-only properties

Read-only properties inherited from Music21Object:

Dynamic read/write properties

Dynamic.positionVertical

Get or set the the vertical position, where 0 is the top line of the staff and units are in 10ths of a staff space.

>>> te = expressions.TextExpression()
>>> te.positionVertical = 10
>>> te.positionVertical
10.0
Dynamic.value

Get or set the value of this dynamic, which sets the long and english names of this Dynamic. The value is a string specification.

Dynamic.volumeScalar

Get or set the volume scalar for this dynamic. If not explicitly set, a default volume scalar will be provided. Any number between 0 and 1 can be used to set the volume scalar, overriding the expected behavior.

As mezzo is at .5, the unit interval range is doubled for generating final output. The default output is .5.

>>> d = dynamics.Dynamic('mf')
>>> d.volumeScalar
0.55...

int(volumeScalar * 127) gives the MusicXML <sound dynamics=”x”/> tag

>>> print musicxml.m21ToString.fromMusic21Object(d)
<?xml...
<direction>
    <direction-type>
      <dynamics default-x="-36" default-y="-80">
        <mf/>
      </dynamics>
    </direction-type>
    <offset>0</offset>
    <sound dynamics="69"/>
</direction>...

Read/write properties inherited from Music21Object:

Dynamic methods

Methods inherited from Music21Object:

Dynamic instance variables

Dynamic.englishName

the name of this dynamic in English.

>>> d = dynamics.Dynamic('pp')
>>> d.englishName
'very soft'
Dynamic.longName

the name of this dynamic in Italian.

>>> d = dynamic.Dynamic('pp')
>>> d.longName
'pianissimo'

Instance variables inherited from Music21Object:

Crescendo

class music21.dynamics.Crescendo(*arguments, **keywords)

A spanner crescendo wedge.

>>> from music21 import dynamics
>>> d = dynamics.Crescendo()
>>> d.getStartParameters()
{'spread': 0, 'type': 'crescendo'}
>>> d.getEndParameters()
{'spread': 15, 'type': 'stop'}

Crescendo bases

Crescendo read-only properties

Read-only properties inherited from Music21Object:

Crescendo read/write properties

Read/write properties inherited from Music21Object:

Crescendo methods

Crescendo.getEndParameters()

Return the parameters for the start of this spanner

Crescendo.getStartParameters()

Return the parameters for the start of this spanner

Methods inherited from Spanner:

Methods inherited from Music21Object:

Crescendo instance variables

Crescendo.classSortOrder

Property which returns an number (int or otherwise) depending on the class of the Music21Object that represents a priority for an object based on its class alone – used as a tie for stream sorting in case two objects have the same offset and priority. Lower numbers are sorted to the left of higher numbers. For instance, Clef, KeySignature, TimeSignature all come (in that order) before Note.

All undefined classes have classSortOrder of 20 – same as note.Note

>>> m21o = base.Music21Object()
>>> m21o.classSortOrder
20
>>> tc = clef.TrebleClef()
>>> tc.classSortOrder
0
>>> ks = key.KeySignature(3)
>>> ks.classSortOrder
1

New classes can define their own default classSortOrder

>>> class ExampleClass(base.Music21Object):
...     classSortOrderDefault = 5
...
>>> ec1 = ExampleClass()
>>> ec1.classSortOrder
5
Crescendo.groups

An instance of a Group object which describes arbitrary Groups that this object belongs to.

Crescendo.hideObjectOnPrint

if set to True will not print upon output (only used in MusicXML output at this point and Lilypond for notes, chords, and rests).

Crescendo.id

A unique identification string (not to be confused with the default .id() method.

Crescendo.isSpanner

Boolean value for quickly identifying Spanner objects (False by default).

Crescendo.isStream

Boolean value for quickly identifying Stream objects (False by default).

Crescendo.isVariant

Boolean value for quickly identifying Variant objects (False by default).

Crescendo.xPosition

if set, defines the display x-position from the start of the container (in musicxml “tenths” by default)

Instance variables inherited from DynamicWedge:

Instance variables inherited from Spanner:

Instance variables inherited from Music21Object:

Diminuendo

class music21.dynamics.Diminuendo(*arguments, **keywords)

A spanner diminuendo wedge.

>>> from music21 import dynamics
>>> d = dynamics.Diminuendo()
>>> d.getStartParameters()
{'spread': 15, 'type': 'diminuendo'}
>>> d.getEndParameters()
{'spread': 0, 'type': 'stop'}

Diminuendo bases

Diminuendo read-only properties

Read-only properties inherited from Music21Object:

Diminuendo read/write properties

Read/write properties inherited from Music21Object:

Diminuendo methods

Diminuendo.getEndParameters()

Return the parameters for the start of this spanner

Diminuendo.getStartParameters()

Return the parameters for the start of this spanner

Methods inherited from Spanner:

Methods inherited from Music21Object:

Diminuendo instance variables

Diminuendo.classSortOrder

Property which returns an number (int or otherwise) depending on the class of the Music21Object that represents a priority for an object based on its class alone – used as a tie for stream sorting in case two objects have the same offset and priority. Lower numbers are sorted to the left of higher numbers. For instance, Clef, KeySignature, TimeSignature all come (in that order) before Note.

All undefined classes have classSortOrder of 20 – same as note.Note

>>> m21o = base.Music21Object()
>>> m21o.classSortOrder
20
>>> tc = clef.TrebleClef()
>>> tc.classSortOrder
0
>>> ks = key.KeySignature(3)
>>> ks.classSortOrder
1

New classes can define their own default classSortOrder

>>> class ExampleClass(base.Music21Object):
...     classSortOrderDefault = 5
...
>>> ec1 = ExampleClass()
>>> ec1.classSortOrder
5
Diminuendo.groups

An instance of a Group object which describes arbitrary Groups that this object belongs to.

Diminuendo.hideObjectOnPrint

if set to True will not print upon output (only used in MusicXML output at this point and Lilypond for notes, chords, and rests).

Diminuendo.id

A unique identification string (not to be confused with the default .id() method.

Diminuendo.isSpanner

Boolean value for quickly identifying Spanner objects (False by default).

Diminuendo.isStream

Boolean value for quickly identifying Stream objects (False by default).

Diminuendo.isVariant

Boolean value for quickly identifying Variant objects (False by default).

Diminuendo.xPosition

if set, defines the display x-position from the start of the container (in musicxml “tenths” by default)

Instance variables inherited from DynamicWedge:

Instance variables inherited from Spanner:

Instance variables inherited from Music21Object:

DynamicWedge

class music21.dynamics.DynamicWedge(*arguments, **keywords)

Common base-class for Crescendo and Diminuendo.

DynamicWedge bases

DynamicWedge read-only properties

Read-only properties inherited from Music21Object:

DynamicWedge read/write properties

Read/write properties inherited from Music21Object:

DynamicWedge methods

Methods inherited from Spanner:

Methods inherited from Music21Object:

DynamicWedge instance variables

DynamicWedge.classSortOrder

Property which returns an number (int or otherwise) depending on the class of the Music21Object that represents a priority for an object based on its class alone – used as a tie for stream sorting in case two objects have the same offset and priority. Lower numbers are sorted to the left of higher numbers. For instance, Clef, KeySignature, TimeSignature all come (in that order) before Note.

All undefined classes have classSortOrder of 20 – same as note.Note

>>> m21o = base.Music21Object()
>>> m21o.classSortOrder
20
>>> tc = clef.TrebleClef()
>>> tc.classSortOrder
0
>>> ks = key.KeySignature(3)
>>> ks.classSortOrder
1

New classes can define their own default classSortOrder

>>> class ExampleClass(base.Music21Object):
...     classSortOrderDefault = 5
...
>>> ec1 = ExampleClass()
>>> ec1.classSortOrder
5
DynamicWedge.groups

An instance of a Group object which describes arbitrary Groups that this object belongs to.

DynamicWedge.hideObjectOnPrint

if set to True will not print upon output (only used in MusicXML output at this point and Lilypond for notes, chords, and rests).

DynamicWedge.id

A unique identification string (not to be confused with the default .id() method.

DynamicWedge.isSpanner

Boolean value for quickly identifying Spanner objects (False by default).

DynamicWedge.isStream

Boolean value for quickly identifying Stream objects (False by default).

DynamicWedge.isVariant

Boolean value for quickly identifying Variant objects (False by default).

DynamicWedge.xPosition

if set, defines the display x-position from the start of the container (in musicxml “tenths” by default)

Instance variables inherited from Spanner:

Instance variables inherited from Music21Object: