This module provides object representations of expressions, that is notational symbols such as Fermatas, Mordents, Trills, Turns, etc. which are stored under a Music21Object’s .expressions attribute
given a Music21Object with Ornament expressions, convert them into a list of objects that represents the performed version of the object:
>>> from music21 import *
>>> n1 = note.Note("D5")
>>> n1.quarterLength = 1
>>> n1.expressions.append(expressions.WholeStepMordent())
>>> expList = expressions.realizeOrnaments(n1)
>>> st1 = stream.Stream()
>>> st1.append(expList)
>>> st1.show()
Inherits from: GeneralAppoggiatura, Ornament, Expression, Music21Object, JSONSerializer
Inherits from: Music21Object, JSONSerializer
Inherits from: Expression, Music21Object, JSONSerializer
Fermatas by default get appended to the last note if a note is split because of measures. To override this (for Fermatas or for any expression) set .tieAttach to ‘all’ or ‘first’ instead of ‘last’.
>>> from music21 import *
>>> p1 = stream.Part()
>>> p1.append(meter.TimeSignature('6/8'))
>>> n1 = note.Note("D-2")
>>> n1.quarterLength = 6
>>> n1.expressions.append(expressions.Fermata())
>>> p1.append(n1)
>>> p1.show()
Fermata attributes
Attributes without Documentation: lily, shape, tieAttach, type
Attributes inherited from Music21Object: classSortOrder, hideObjectOnPrint, id, isSpanner, isStream, isWrapper, groups
Fermata properties
- mx¶
Advanced feature: As a getter gives the music21.musicxml object for the Fermata or as a setter changes the current fermata to have the characteristics of the musicxml object to fit this type:
>>> from music21 import * >>> a = Fermata() >>> mxFermata = a.mx >>> mxFermata.get('type') 'upright'>>> mxFermata2 = musicxml.Fermata() >>> mxFermata2.set('type', 'upright-inverted') >>> a.mx = mxFermata2 >>> a.type 'upright-inverted'Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, measureNumber, offset, priority
Properties inherited from JSONSerializer: json
Fermata methods
Methods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSpannerSite(), isClassOrSubclass(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), removeNonContainedLocations(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: Ornament, Expression, Music21Object, JSONSerializer
GeneralAppoggiatura attributes
Attributes without Documentation: direction, size
Attributes inherited from Ornament: connectedToPrevious, tieAttach
Attributes inherited from Music21Object: classSortOrder, hideObjectOnPrint, id, isSpanner, isStream, isWrapper, groups
GeneralAppoggiatura properties
Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, measureNumber, offset, priority
Properties inherited from JSONSerializer: json
GeneralAppoggiatura methods
- realize(srcObject)¶
realize an appoggiatura returns a three-element tuple. The first is the notes that the grace note was converted to. The second is the rest of the note The third is an empty list (since there are no notes at the end of an appoggiatura)
>>> from music21 import * >>> n1 = note.Note("C4") >>> n1.quarterLength = 0.5 >>> a1 = expressions.Appoggiatura() >>> a1.realize(n1) (<music21.note.Note D>, <music21.note.Note C>, []) >>> from music21 import * >>> n2 = note.Note("C4") >>> n2.quarterLength = 1 >>> a2 = expressions.HalfStepInvertedAppoggiatura() >>> a2.realize(n2) (<music21.note.Note B>, <music21.note.Note C>, [])Methods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSpannerSite(), isClassOrSubclass(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), removeNonContainedLocations(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: Ornament, Expression, Music21Object, JSONSerializer
GeneralMordent attributes
Attributes without Documentation: direction, quarterLength, size
Attributes inherited from Ornament: connectedToPrevious, tieAttach
Attributes inherited from Music21Object: classSortOrder, hideObjectOnPrint, id, isSpanner, isStream, isWrapper, groups
GeneralMordent properties
Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, measureNumber, offset, priority
Properties inherited from JSONSerializer: json
GeneralMordent methods
- realize(srcObject)¶
realize a mordent. returns a three-element tuple. The first is a list of the two notes that the beginning of the note were converted to. The second is the rest of the note The third is an empty list (since there are no notes at the end of a mordent)
>>> from music21 import * >>> n1 = note.Note("C4") >>> n1.quarterLength = 0.5 >>> m1 = expressions.Mordent() >>> m1.realize(n1) ([<music21.note.Note C>, <music21.note.Note B>], <music21.note.Note C>, []) >>> from music21 import * >>> n2 = note.Note("C4") >>> n2.quarterLength = 0.125 >>> m2 = expressions.GeneralMordent() >>> m2.realize(n2) ... ExpressionException: Cannot realize a mordent if I do not know its directionMethods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSpannerSite(), isClassOrSubclass(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), removeNonContainedLocations(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: Appoggiatura, GeneralAppoggiatura, Ornament, Expression, Music21Object, JSONSerializer
Inherits from: InvertedAppoggiatura, GeneralAppoggiatura, Ornament, Expression, Music21Object, JSONSerializer
Inherits from: InvertedMordent, GeneralMordent, Ornament, Expression, Music21Object, JSONSerializer
Inherits from: Mordent, GeneralMordent, Ornament, Expression, Music21Object, JSONSerializer
Inherits from: Trill, Ornament, Expression, Music21Object, JSONSerializer
Inherits from: GeneralAppoggiatura, Ornament, Expression, Music21Object, JSONSerializer
Inherits from: GeneralMordent, Ornament, Expression, Music21Object, JSONSerializer
Inherits from: Turn, Ornament, Expression, Music21Object, JSONSerializer
Inherits from: GeneralMordent, Ornament, Expression, Music21Object, JSONSerializer
Inherits from: Expression, Music21Object, JSONSerializer
Ornament attributes
Attributes without Documentation: connectedToPrevious, tieAttach
Attributes inherited from Music21Object: classSortOrder, hideObjectOnPrint, id, isSpanner, isStream, isWrapper, groups
Ornament properties
Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, measureNumber, offset, priority
Properties inherited from JSONSerializer: json
Ornament methods
- realize(sourceObject)¶
- subclassible method call that takes a sourceObject and returns a three-element tuple of a list of notes before the “main note”, the “main note” itself, and a list of notes after the “main note”.
Methods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSpannerSite(), isClassOrSubclass(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), removeNonContainedLocations(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: Expression, Music21Object, JSONSerializer, TextFormat
A TextExpression is a word, phrase, or similar bit of text that is positioned in a Stream or Measure. Conventional expressive indications are text like “agitato” or “con fuoco.”
>>> from music21 import *
>>> te = expressions.TextExpression('testing')
>>> te.size = 24
>>> te.size
24.0
>>> te.style = 'bolditalic'
>>> te.letterSpacing = 0.5
TextExpression 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 inherited from Music21Object: hideObjectOnPrint, id, isSpanner, isStream, isWrapper, groups
TextExpression properties
- content¶
Get or set the the content.
>>> from music21 import * >>> te = expressions.TextExpression('testing') >>> te.content 'testing'
- enclosure¶
Get or set the the enclosure.
>>> from music21 import * >>> te = expressions.TextExpression() >>> te.justify = 'center' >>> te.enclosure = None >>> te.enclosure = 'rectangle'
- 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.0Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, measureNumber, offset, priority
Properties inherited from JSONSerializer: json
Properties inherited from TextFormat: justify, letterSpacing, size, style
TextExpression methods
- getRepeatExpression()¶
- If this TextExpression can be a RepeatExpression, return a new RepeatExpression. object, otherwise, return None.
- getTempoText()¶
- No documentation.
Methods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSpannerSite(), isClassOrSubclass(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), removeNonContainedLocations(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: Ornament, Expression, Music21Object, JSONSerializer
Trill attributes
- size¶
An Interval class that encapsulates both Chromatic and Diatonic intervals all in one model. The interval is specified either as named arguments, a DiatonicInterval and a ChromaticInterval, or two Note objects, from which both a ChromaticInterval and DiatonicInterval are derived.
>>> from music21 import * >>> n1 = note.Note('c3') >>> n2 = note.Note('c5') >>> aInterval = interval.Interval(noteStart=n1, noteEnd=n2) >>> aInterval <music21.interval.Interval P15>Two Intervals are the same if their Chromatic and Diatonic intervals are the same. N.B. that interval.Interval(‘a4’) != ‘a4’ – maybe it should...
Attributes without Documentation: nachschlag, placement, quarterLength, tieAttach
Attributes inherited from Ornament: connectedToPrevious
Attributes inherited from Music21Object: classSortOrder, hideObjectOnPrint, id, isSpanner, isStream, isWrapper, groups
Trill properties
- mx¶
Returns a musicxml.TrillMark object
>>> a = Trill() >>> a.placement = 'above' >>> mxTrillMark = a.mx >>> mxTrillMark.get('placement') 'above'Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, measureNumber, offset, priority
Properties inherited from JSONSerializer: json
Trill methods
- realize(srcObject)¶
realize a trill. returns a three-element tuple. The first is a list of the notes that the note was converted to. The second is None because the trill “eats up” the whole note. The third is a list of the notes at the end if nachschlag is True, and empty list if False.
>>> from music21 import * >>> n1 = note.Note("C4") >>> n1.quarterLength = 0.5 >>> t1 = expressions.Trill() >>> t1.realize(n1) ([<music21.note.Note C>, <music21.note.Note D>, <music21.note.Note C>, <music21.note.Note D>], None, []) >>> from music21 import * >>> n2 = note.Note("D4") >>> n2.quarterLength = 0.125 >>> t2 = expressions.Trill() >>> t2.realize(n2) ... ExpressionException: The note is not long enough to realize a trillMethods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSpannerSite(), isClassOrSubclass(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), removeNonContainedLocations(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: Ornament, Expression, Music21Object, JSONSerializer
Turn attributes
- size¶
An Interval class that encapsulates both Chromatic and Diatonic intervals all in one model. The interval is specified either as named arguments, a DiatonicInterval and a ChromaticInterval, or two Note objects, from which both a ChromaticInterval and DiatonicInterval are derived.
>>> from music21 import * >>> n1 = note.Note('c3') >>> n2 = note.Note('c5') >>> aInterval = interval.Interval(noteStart=n1, noteEnd=n2) >>> aInterval <music21.interval.Interval P15>Two Intervals are the same if their Chromatic and Diatonic intervals are the same. N.B. that interval.Interval(‘a4’) != ‘a4’ – maybe it should...
Attributes without Documentation: nachschlag, placement, quarterLength, tieAttach
Attributes inherited from Ornament: connectedToPrevious
Attributes inherited from Music21Object: classSortOrder, hideObjectOnPrint, id, isSpanner, isStream, isWrapper, groups
Turn properties
Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, measureNumber, offset, priority
Properties inherited from JSONSerializer: json
Turn methods
- realize(srcObject)¶
realize a turn. returns a three-element tuple. The first is a list of the four notes that the beginning of the note was converted to. The second is a note of duration 0 because the turn “eats up” the whole note. The third is a list of the notes at the end if nachschlag is True, and empty list if False.
>>> from music21 import * >>> m1 = stream.Measure() >>> m1.append(key.Key('F', 'major')) >>> n1 = note.Note("C5") >>> m1.append(n1) >>> t1 = expressions.Turn() >>> t1.realize(n1) ([], <music21.note.Note C>, [<music21.note.Note D>, <music21.note.Note C>, <music21.note.Note B->, <music21.note.Note C>]) >>> from music21 import * >>> m2 = stream.Measure() >>> m2.append(key.KeySignature(5)) >>> n2 = note.Note("B4") >>> m2.append(n2) >>> t2 = expressions.InvertedTurn() >>> t2.realize(n2) ([], <music21.note.Note B>, [<music21.note.Note A#>, <music21.note.Note B>, <music21.note.Note C#>, <music21.note.Note B>])>>> from music21 import * >>> n2 = note.Note("C4") >>> n2.quarterLength = 0.125 >>> t2 = expressions.Turn() >>> t2.realize(n2) ... ExpressionException: The note is not long enough to realize a turnMethods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getCommonSiteIds(), getCommonSites(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSpannerSite(), isClassOrSubclass(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), removeNonContainedLocations(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: Appoggiatura, GeneralAppoggiatura, Ornament, Expression, Music21Object, JSONSerializer
Inherits from: InvertedAppoggiatura, GeneralAppoggiatura, Ornament, Expression, Music21Object, JSONSerializer
Inherits from: InvertedMordent, GeneralMordent, Ornament, Expression, Music21Object, JSONSerializer
Inherits from: Mordent, GeneralMordent, Ornament, Expression, Music21Object, JSONSerializer
Inherits from: Trill, Ornament, Expression, Music21Object, JSONSerializer