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)
>>> ppp = dynamics.Dynamic(0.15) # on 0 to 1 scale >>> ppp.value 'ppp' >>> print('%.2f' % ppp.volumeScalar) 0.15
Note that we got lucky last time because the dynamic 0.15 exactly corresponds to what we’ve considered the default for ‘ppp’. Here we assign 0.98 which is close to the 0.9 that is the default for ‘fff’ – but the 0.98 will be retained in the .volumeScalar
>>> loud = dynamics.Dynamic(0.98) # on 0 to 1 scale >>> loud.value 'fff' >>> print('%.2f' % loud.volumeScalar) 0.98
Transferring the .value (‘fff’) to a new Dynamic object will set the volumeScalar back to 0.9
>>> loud2 = dynamics.Dynamic(loud.value) >>> loud2.value 'fff' >>> print('%.2f' % loud2.volumeScalar) 0.90
Custom dynamics are possible:
>>> myDyn = dynamics.Dynamic('rfzsfmp') >>> myDyn.value 'rfzsfmp' >>> print(myDyn.volumeScalar) None >>> myDyn.volumeScalar = 0.87 >>> myDyn.volumeScalar 0.87
Dynamics can be placed anywhere in a stream.
>>> s = stream.Stream() >>> s.insert(0, note.Note('E-4', type='half')) >>> s.insert(2, note.Note('F#5', type='half')) >>> s.insert(0, dynamics.Dynamic('pp')) >>> s.insert(1, dynamics.Dynamic('mf')) >>> s.insert(3, dynamics.Dynamic('fff')) >>> s.show()
Dynamic
bases
Dynamic
read-only properties
Read-only properties inherited from Music21Object
:
Dynamic
read/write properties
-
Dynamic.
positionVertical
¶ Get or set 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...
>>> d.volumeScalar = 0.1 >>> d.volumeScalar 0.1 >>> d.value 'mf'
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="12"/> </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 = dynamics.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 >>> d.getStartParameters()['type'] 'crescendo'
>>> d.getEndParameters()['spread'] 15 >>> d.getEndParameters()['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
Instance variables inherited from Music21Object
:
Diminuendo¶
-
class
music21.dynamics.
Diminuendo
(*arguments, **keywords)¶ A spanner diminuendo wedge.
>>> from music21 import dynamics >>> d = dynamics.Diminuendo() >>> startP = d.getStartParameters() >>> startP['spread'] 15 >>> startP['type'] 'diminuendo'
>>> endP = d.getEndParameters() >>> endP['spread'] 0 >>> endP['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
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
Instance variables inherited from Music21Object
: