Classes and functions for creating and manipulating dynamic symbols. Rather than subclasses, the Dynamic object is often specialized by parameters.
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.
>>> from music21 import *
>>> dynamics.dynamicStrFromDecimal(0.25)
'pp'
>>> dynamics.dynamicStrFromDecimal(1)
'fff'
Inherits from: Music21Object, JSONSerializer
Object representation of Dynamics.
>>> from music21 import *
>>> 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'
>>> 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()
Dynamic attributes
- 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
>>> from music21 import * >>> tc = clef.TrebleClef() >>> tc.classSortOrder 0 >>> ks = key.KeySignature(3) >>> ks.classSortOrder 1New classes can define their own default classSortOrder
>>> class ExampleClass(base.Music21Object): ... classSortOrderDefault = 5 ... >>> ec1 = ExampleClass() >>> ec1.classSortOrder 5Attributes without Documentation: longName, englishName
Attributes inherited from Music21Object: isSpanner, isStream, isVariant, hideObjectOnPrint, groups, id
Dynamic properties
- musicxml¶
Provide a complete MusicXML representation.
- mx¶
No documentation.
- 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.
>>> from music21 import * >>> te = expressions.TextExpression() >>> te.positionVertical = 10 >>> te.positionVertical 10.0
- 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.
- 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.
>>> from music21 import * >>> d = dynamics.Dynamic('mf') >>> d.volumeScalar 0.55...int(volumeScalar * 127) gives the MusicXML <sound dynamics=”x”/> tag
>>> print d.musicxml <?xml... <direction> <direction-type> <dynamics default-x="-36" default-y="-80"> <mf/> </dynamics> </direction-type> <offset>0</offset> <sound dynamics="69"/> </direction>...Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, isGrace, measureNumber, offset, priority, seconds
Properties inherited from JSONSerializer: json
Dynamic methods
Methods inherited from Music21Object: searchActiveSiteByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), purgeUndeclaredIds(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: DynamicWedge, Spanner, Music21Object, JSONSerializer
A spanner crescendo wedge.
>>> from music21 import dynamics
>>> d = dynamics.Crescendo()
>>> d.getStartParameters()
{'spread': 0, 'type': 'crescendo'}
>>> d.getEndParameters()
{'spread': 15, 'type': 'stop'}
Crescendo attributes
Attributes inherited from DynamicWedge: spread, placement, type
Attributes inherited from Spanner: isSpanner, idLocal, completeStatus
Attributes inherited from Music21Object: classSortOrder, isStream, isVariant, hideObjectOnPrint, groups, id
Crescendo properties
Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, isGrace, measureNumber, offset, priority, seconds
Properties inherited from JSONSerializer: json
Crescendo methods
- getEndParameters()¶
Return the parameters for the start of this spanner
- getStartParameters()¶
Return the parameters for the start of this spanner
Methods inherited from Spanner: addComponents(), freezeIds(), getComponentIds(), getComponents(), getComponentsByClass(), getDurationBySite(), getDurationSpanBySite(), getFirst(), getLast(), getOffsetSpanBySite(), getOffsetsBySite(), getSpannerStorageId(), hasComponent(), isFirst(), isLast(), purgeLocations(), purgeOrphans(), replaceComponent(), unfreezeIds(), unwrapWeakref(), wrapWeakref()
Methods inherited from Music21Object: searchActiveSiteByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeUndeclaredIds(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: DynamicWedge, Spanner, Music21Object, JSONSerializer
A spanner diminuendo wedge.
>>> from music21 import dynamics
>>> d = dynamics.Diminuendo()
>>> d.getStartParameters()
{'spread': 15, 'type': 'diminuendo'}
>>> d.getEndParameters()
{'spread': 0, 'type': 'stop'}
Diminuendo attributes
Attributes inherited from DynamicWedge: spread, placement, type
Attributes inherited from Spanner: isSpanner, idLocal, completeStatus
Attributes inherited from Music21Object: classSortOrder, isStream, isVariant, hideObjectOnPrint, groups, id
Diminuendo properties
Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, isGrace, measureNumber, offset, priority, seconds
Properties inherited from JSONSerializer: json
Diminuendo methods
- getEndParameters()¶
Return the parameters for the start of this spanner
- getStartParameters()¶
Return the parameters for the start of this spanner
Methods inherited from Spanner: addComponents(), freezeIds(), getComponentIds(), getComponents(), getComponentsByClass(), getDurationBySite(), getDurationSpanBySite(), getFirst(), getLast(), getOffsetSpanBySite(), getOffsetsBySite(), getSpannerStorageId(), hasComponent(), isFirst(), isLast(), purgeLocations(), purgeOrphans(), replaceComponent(), unfreezeIds(), unwrapWeakref(), wrapWeakref()
Methods inherited from Music21Object: searchActiveSiteByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeUndeclaredIds(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: Spanner, Music21Object, JSONSerializer
Common base-class for Crescendo and Diminuendo.
DynamicWedge attributes
Attributes without Documentation: spread, placement, type
Attributes inherited from Spanner: isSpanner, idLocal, completeStatus
Attributes inherited from Music21Object: classSortOrder, isStream, isVariant, hideObjectOnPrint, groups, id
DynamicWedge properties
Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, isGrace, measureNumber, offset, priority, seconds
Properties inherited from JSONSerializer: json
DynamicWedge methods
Methods inherited from Spanner: addComponents(), freezeIds(), getComponentIds(), getComponents(), getComponentsByClass(), getDurationBySite(), getDurationSpanBySite(), getFirst(), getLast(), getOffsetSpanBySite(), getOffsetsBySite(), getSpannerStorageId(), hasComponent(), isFirst(), isLast(), purgeLocations(), purgeOrphans(), replaceComponent(), unfreezeIds(), unwrapWeakref(), wrapWeakref()
Methods inherited from Music21Object: searchActiveSiteByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeUndeclaredIds(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()