Object models of bars and repeats.
Standardizes bar style names.
converts all names to lower case, None to ‘regular’, and ‘light-light’ to ‘double’ and ‘light-heavy’ to ‘final’, raises an error for unknown styles.
Convert a music21 barline name into the musicxml name – essentially just changes the names of ‘double’ and ‘final’ to ‘light-light’ and ‘light-heavy’
Does not do error checking to make sure it’s a valid name, since setting the style on a Barline object already does that.
>>> styleToMusicXMLBarStyle('final')
'light-heavy'
>>> styleToMusicXMLBarStyle('regular')
'regular'
Inherits from: Music21Object, JSONSerializer
A representation of a barline. Barlines are conventionally assigned to Measure objects using the leftBarline and rightBarline attributes.
>>> from music21 import *
>>> bl = bar.Barline('double')
>>> bl
<music21.bar.Barline style=double>
The style can also just be set via a keyword of “style”. Or if no style is specified, a regular barline is returned. Location can also be explicitly stored, but it’s not needed except for musicxml translation:
>>> bl2 = bar.Barline(style='dashed')
>>> bl2
<music21.bar.Barline style=dashed>
>>> bl3 = bar.Barline()
>>> bl3
<music21.bar.Barline style=regular>
>>> bl4 = bar.Barline(style='final', location='right')
>>> bl4
<music21.bar.Barline style=final>
Barline 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: validStyles, location
Attributes inherited from Music21Object: isSpanner, isStream, isVariant, hideObjectOnPrint, groups, id
Barline properties
- musicXMLBarStyle¶
No documentation.
- mx¶
>>> b = Barline('final') >>> mxBarline = b.mx >>> mxBarline.get('barStyle') 'light-heavy'
- style¶
Get and set the Barline style property.
>>> b = Barline()Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, isGrace, measureNumber, offset, priority, seconds
Properties inherited from JSONSerializer: json
Barline 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: RepeatMark, Barline, Music21Object, JSONSerializer
A Repeat barline.
The direction parameter can be one of ‘start’ or ‘end.’
>>> from music21 import *
>>> rep = bar.Repeat(direction='end', times=3)
>>> rep
<music21.bar.Repeat direction=end times=3>
To apply a repeat barline assign it to either the .leftBarline or .rightBarline attribute of a measure.
>>> m = stream.Measure()
>>> m.leftBarline = bar.Repeat(direction='start')
>>> m.rightBarline = bar.Repeat(direction='end')
>>> m.insert(0.0, meter.TimeSignature('4/4'))
>>> m.repeatAppend(note.Note('D--5'), 4)
>>> p = stream.Part()
>>> p.insert(0.0, m)
>>> p.show('text')
{0.0} <music21.stream.Measure 0 offset=0.0>
{0.0} <music21.bar.Repeat direction=start>
{0.0} <music21.meter.TimeSignature 4/4>
{0.0} <music21.note.Note D-->
{1.0} <music21.note.Note D-->
{2.0} <music21.note.Note D-->
{3.0} <music21.note.Note D-->
{4.0} <music21.bar.Repeat direction=end>
The method expandRepeats() on a Part object expands the repeats, but does not update measure numbers
>>> q = p.expandRepeats()
>>> q.show('text')
{0.0} <music21.stream.Measure 0 offset=0.0>
{0.0} <music21.bar.Barline style=double>
{0.0} <music21.meter.TimeSignature 4/4>
{0.0} <music21.note.Note D-->
{1.0} <music21.note.Note D-->
{2.0} <music21.note.Note D-->
{3.0} <music21.note.Note D-->
{4.0} <music21.bar.Barline style=double>
{4.0} <music21.stream.Measure 0 offset=4.0>
{0.0} <music21.bar.Barline style=double>
{0.0} <music21.meter.TimeSignature 4/4>
{0.0} <music21.note.Note D-->
{1.0} <music21.note.Note D-->
{2.0} <music21.note.Note D-->
{3.0} <music21.note.Note D-->
{4.0} <music21.bar.Barline style=double>
Repeat attributes
Attributes inherited from Barline: classSortOrder, validStyles, location
Attributes inherited from Music21Object: isSpanner, isStream, isVariant, hideObjectOnPrint, groups, id
Repeat properties
- direction¶
Get or set the direction of this Repeat barline. Can be start or end.
TODO: show how changing direction changes style.
- mx¶
No documentation.
- times¶
Get or set the times property of this barline. This defines how many times the repeat happens. A standard repeat repeats 2 times; values equal to or greater than 0 are permitted. A repeat of 0 skips the repeated passage.
>>> from music21 import bar >>> lb = bar.Repeat(direction='start') >>> rb = bar.Repeat(direction='end') >>> lb.times = 3 Traceback (most recent call last): BarException: cannot set repeat times on a start Repeat >>> rb.times = 3 >>> rb.times = -3 Traceback (most recent call last): BarException: cannot set repeat times to a value less than zero: -3Properties inherited from Barline: musicXMLBarStyle, style
Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, derivationHierarchy, duration, isGrace, measureNumber, offset, priority, seconds
Properties inherited from JSONSerializer: json
Repeat methods
- getTextExpression(prefix='', postfix='x')¶
Return a configured TextExpressions object describing the repeat times. Append this to the stream for annotation of repeat times.
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()