Object models of barlines, including repeat barlines.
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.
>>> bar.styleToMusicXMLBarStyle('final')
'light-heavy'
>>> bar.styleToMusicXMLBarStyle('regular')
'regular'
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 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>
Note that the barline style ‘ticked’ only is displayed correctly in Finale and Finale Notepad.
Barline bases
Barline read-only properties
Read-only properties inherited from Music21Object:
Barline read/write properties
Get and set the Barline style property.
>>> b = bar.Barline()
>>> b.style = 'tick'
>>> b.style
'tick'
Synonyms are given for some styles:
>>> b.style = 'light-light'
>>> b.style
'double'
Read/write properties inherited from Music21Object:
Barline methods
Methods inherited from Music21Object:
Barline instance variables
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
>>> m21o = base.Music21Object()
>>> m21o.classSortOrder
20
>>> tc = clef.TrebleClef()
>>> tc.classSortOrder
0
>>> ks = key.KeySignature(3)
>>> ks.classSortOrder
1
New classes can define their own default classSortOrder
>>> class ExampleClass(base.Music21Object):
... classSortOrderDefault = 5
...
>>> ec1 = ExampleClass()
>>> ec1.classSortOrder
5
An instance of a Group object which describes arbitrary Groups that this object belongs to.
if set to True will not print upon output (only used in MusicXML output at this point and Lilypond for notes, chords, and rests).
A unique identification string (not to be confused with the default .id() method.
if set, defines the display x-position from the start of the container (in musicxml “tenths” by default)
Instance variables inherited from Music21Object:
A Repeat barline.
The direction parameter can be one of start or end. A 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 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 bases
Repeat read-only properties
Read-only properties inherited from Barline:
Read-only properties inherited from Music21Object:
Repeat read/write properties
Get or set the direction of this Repeat barline. Can be start or end.
TODO: show how changing direction changes style.
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: -3
Read/write properties inherited from Barline:
Read/write properties inherited from Music21Object:
Repeat methods
Return a configured TextExpressions object describing the repeat times. Append this to the stream for annotation of repeat times.
Methods inherited from Music21Object:
Repeat instance variables
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
>>> m21o = base.Music21Object()
>>> m21o.classSortOrder
20
>>> tc = clef.TrebleClef()
>>> tc.classSortOrder
0
>>> ks = key.KeySignature(3)
>>> ks.classSortOrder
1
New classes can define their own default classSortOrder
>>> class ExampleClass(base.Music21Object):
... classSortOrderDefault = 5
...
>>> ec1 = ExampleClass()
>>> ec1.classSortOrder
5
An instance of a Group object which describes arbitrary Groups that this object belongs to.
if set to True will not print upon output (only used in MusicXML output at this point and Lilypond for notes, chords, and rests).
A unique identification string (not to be confused with the default .id() method.
if set, defines the display x-position from the start of the container (in musicxml “tenths” by default)
Instance variables inherited from Barline:
Instance variables inherited from Music21Object: