Previous topic

music21.audioSearch.transcriber

Next topic

music21.base

Table Of Contents

Table Of Contents

This Page

music21.bar

Object models of barlines, including repeat barlines.

Functions

music21.bar.standardizeBarStyle(value)

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.

music21.bar.styleToMusicXMLBarStyle(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.styleToMusicXMLBarStyle('final')
'light-heavy'
>>> bar.styleToMusicXMLBarStyle('regular')
'regular'

Barline

class music21.bar.Barline(style=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 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

Barline.musicXMLBarStyle

Read-only properties inherited from Music21Object:

Barline read/write properties

Barline.style

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

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. 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

Repeat.direction

Get or set the direction of this Repeat barline. Can be start or end.

TODO: show how changing direction changes style.

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.

>>> 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

Repeat.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:

Repeat instance variables

Instance variables inherited from Barline:

  • isStream
  • hideObjectOnPrint
  • classSortOrder
  • groups
  • isVariant
  • id
  • isSpanner
  • xPosition

Instance variables inherited from Music21Object: