music21.bar¶
Object models of barlines, including repeat barlines.
Barline¶
- class music21.bar.Barline(type=None, location=None)¶
- A representation of a barline. Barlines are conventionally assigned to Measure objects using the leftBarline and rightBarline attributes. - >>> bl = bar.Barline('double') >>> bl <music21.bar.Barline type=double> - The type can also just be set via a keyword of “type”. Or if no type 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(type='dashed') >>> bl2 <music21.bar.Barline type=dashed> >>> bl3 = bar.Barline() >>> bl3 <music21.bar.Barline type=regular> >>> bl4 = bar.Barline(type='final', location='right') >>> bl4 <music21.bar.Barline type=final> >>> bl4.type 'final' - Note that the barline type ‘ticked’ only is displayed correctly in Finale and Finale Notepad. - N.B. for backwards compatibility reasons, currently Bar objects do not use the style.Style class since the phrase “style” was already used. 
Barline bases
Barline read-only properties
Read-only properties inherited from Music21Object:
Read-only properties inherited from ProtoM21Object:
Barline read/write properties
- Barline.type¶
- Get and set the Barline type property. - >>> b = bar.Barline() >>> b.type = 'tick' >>> b.type 'tick' - Synonyms are given for some types, based on musicxml styles: - >>> b.type = 'light-light' >>> b.type 'double' 
Read/write properties inherited from Music21Object:
Barline methods
- Barline.musicXMLBarStyle()¶
- returns the musicxml style for the bar. most are the same as .type but “double” and “final” are different. - >>> b = bar.Barline('tick') >>> b.musicXMLBarStyle() 'tick' - >>> b.type = 'double' >>> b.musicXMLBarStyle() 'light-light' - >>> b.type = 'final' >>> b.musicXMLBarStyle() 'light-heavy' - Changed in v.5.7 – was a property before. 
Methods inherited from Music21Object:
Methods inherited from ProtoM21Object:
Barline instance variables
Instance variables inherited from Music21Object:
Repeat¶
- class music21.bar.Repeat(direction='start', times=None)¶
- A Repeat barline. - The direction parameter can be one of start or end. An end followed by a start should be encoded as two bar.Repeat signs. - >>> 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- Partobject 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 type=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 type=double> {4.0} <music21.stream.Measure 0a offset=4.0> {0.0} <music21.bar.Barline type=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 type=double> 
Repeat bases
Repeat read-only properties
Read-only properties inherited from Music21Object:
Read-only properties inherited from ProtoM21Object:
Repeat read/write properties
- Repeat.direction¶
- Get or set the direction of this Repeat barline. Can be start or end. - TODO: show how changing direction changes type. 
- Repeat.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. - >>> lb = bar.Repeat(direction='start') >>> rb = bar.Repeat(direction='end') - Only end expressions can have times: - >>> lb.times = 3 Traceback (most recent call last): music21.bar.BarException: cannot set repeat times on a start Repeat - >>> rb.times = 3 >>> rb.times = -3 Traceback (most recent call last): music21.bar.BarException: cannot set repeat times to a value less than zero: -3 
Read/write properties inherited from Barline:
Read/write properties inherited from Music21Object:
Repeat methods
- Repeat.getTextExpression(prefix='', postfix='x')¶
- Return a configured - TextExpressionsobject describing the repeat times. Append this to the stream for annotation of repeat times.- >>> rb = bar.Repeat(direction='end') >>> rb.times = 3 >>> rb.getTextExpression() <music21.expressions.TextExpression '3x'> - >>> rb.getTextExpression(prefix='repeat ', postfix=' times') <music21.expressions.TextExpression 'repeat 3 t...'> 
Methods inherited from Barline:
Methods inherited from Music21Object:
Methods inherited from ProtoM21Object:
Repeat instance variables
Instance variables inherited from Music21Object:
Functions¶
- music21.bar.standardizeBarType(value)¶
- Standardizes bar type 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. 
- music21.bar.typeToMusicXMLBarStyle(value)¶
- 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. - >>> bar.typeToMusicXMLBarStyle('final') 'light-heavy' >>> bar.typeToMusicXMLBarStyle('regular') 'regular'