Previous topic

music21.pitch

Next topic

music21.roman

Table Of Contents

Table Of Contents

music21.repeat

This module provides the base class for all RepeatMark objects: entities that denote repeats.

Some RepeatMark objects are Expression objects; others are Bar objects. See for instance, Repeat which represents a normal barline repeat.

music21.repeat.deleteMeasures(s, toDelete, inPlace=False)

Given a stream s and a list of numbers, toDelete, removes each measure with a number corresponding to a number in toDelete and then renumbers the remaining measures in the stream.

>>> from music21 import *
>>> from copy import deepcopy
>>> chorale1 = corpus.parse('bwv10.7.mxl')
>>> s = deepcopy(chorale1)
>>> repeat.deleteMeasures(s,[6, 3, 4], inPlace=True)
>>> m2 = search.translateStreamToString( chorale1.parts[1].measure(2).notesAndRests)
>>> resm2 = search.translateStreamToString( s.parts[1].measure(2).notesAndRests)
>>> m2 == resm2
True
>>> m5 = search.translateStreamToString( chorale1.parts[1].measure(5).notesAndRests)
>>> resm3 = search.translateStreamToString( s.parts[1].measure(3).notesAndRests)
>>> m5 == resm3
True
>>> m7 = search.translateStreamToString( chorale1.parts[1].measure(7).notesAndRests)
>>> resm4 = search.translateStreamToString( s.parts[1].measure(4).notesAndRests)
>>> m7 == resm4
True
>>> lenS = len(s.parts[0].getElementsByClass(stream.Measure))
>>> lenChorale1 = len(chorale1.parts[0].getElementsByClass(stream.Measure))
>>> lenS + 3 == lenChorale1
True
music21.repeat.insertRepeat(s, start, end, inPlace=False)

Given a stream s, inserts a start-repeat at the beginning of the bar specified by start and inserts an end-repeat at the bar specified by barEnd. Only alters the stream s if inPlace=True.

>>> from music21 import *
>>> from copy import deepcopy
>>> chorale1 = corpus.parse('bwv10.7.mxl')
>>> s = repeat.insertRepeat(chorale1, 3, 6, inPlace=False)
>>> m4 = search.translateStreamToString( chorale1.parts[1].measure(4).notesAndRests)
>>> resm4 = search.translateStreamToString( s.parts[1].measure(4).notesAndRests)
>>> m6 = search.translateStreamToString( chorale1.parts[1].measure(4).notesAndRests)
>>> resm6 = search.translateStreamToString( s.parts[1].measure(4).notesAndRests)
>>> m7 = search.translateStreamToString( chorale1.parts[1].measure(4).notesAndRests)
>>> resm7 = search.translateStreamToString( s.parts[1].measure(4).notesAndRests)
>>> m4 == resm4
True
>>> m6 == resm6
True
>>> m7 == resm7
True

We should have 2 repeats in each part (a start and end) for a total of 8 repeats

>>> len(s.parts[0].flat.getElementsByClass(bar.Repeat))
2
>>> len(s.flat.getElementsByClass(bar.Repeat))
8
>>> s.parts[0].measure(3).leftBarline.direction
'start'
>>> s.parts[0].measure(6).rightBarline.direction
'end'
music21.repeat.insertRepeatEnding(s, start, end, endingNumber=1, inPlace=False)

Designates a range of measures as being repeated endings (i.e. first and second endings) within a stream s, where s either contains measures, or contains parts which contain measures. Start and end are integers corresponding to the first and last measure number of the “repeatNum” ending. e.g. if start=6, end=7, and repeatNum=2, the method adds a second ending from measures 6 to 7.

Does not (yet) add a RepeatMark to the end of the first ending.

Example: create first and second endings over measures 4-6 and measures 11-13 of a chorale, respectively.

>>> from music21 import *
>>> c1 = corpus.parse('bwv10.7.mxl')
>>> repeat.insertRepeatEnding(c1,  4,  6, 1, inPlace=True)
>>> repeat.insertRepeatEnding(c1, 11, 13, 2, inPlace=True)

We now have 8 repeatBrackets since each part gets its own first and second ending.

>>> repeatBrackets = c1.flat.getElementsByClass(spanner.RepeatBracket)
>>> len(repeatBrackets)
8
>>> len(c1.parts[0].getElementsByClass(spanner.RepeatBracket))
2

RepeatExpression

Inherits from: RepeatMark, Expression, Music21Object

class music21.repeat.RepeatExpression

This class models any mark added to a Score to mark repeat start and end points that are designated by text expressions or symbols, such as D.S. Al Coda, etc.

N.B. Repeat(Barline) objects are not RepeatExpression objects, but both are RepeatMark subclasses.

This class stores internally a TextExpression. This object is used for rendering text output in translation. A properly configured TextExpression object can also be used to create an instance of a RepeatExpressions.

RepeatExpression attributes

Attributes without Documentation: useSymbol

Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, xPosition, id, sites, groups, hideObjectOnPrint

RepeatExpression properties

RepeatExpression methods

applyTextFormatting(te=None)

Apply the default text formatting to the text expression version of of this repeat

getText()

Get the text used for this expression.

getTextExpression()

Return a copy of the TextExpression stored in this object.

isValidText(value)

Return True or False if the supplied text could be used for this RepeatExpression.

setText(value)

Set the text of this repeat expression. This is also the primary way that the stored TextExpression object is created.

setTextExpression(value)

Directly set a TextExpression object.

Methods inherited from Music21Object: findAttributeInHierarchy(), getContextAttr(), setContextAttr(), addContext(), addLocation(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), hasSite(), hasSpannerSite(), hasVariantSite(), isClassOrSubclass(), mergeAttributes(), next(), previous(), purgeLocations(), purgeOrphans(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unwrapWeakref(), wrapWeakref(), write()

RepeatExpressionMarker

Inherits from: RepeatExpression, RepeatMark, Expression, Music21Object

class music21.repeat.RepeatExpressionMarker

Some repeat expressions are markers of positions in the score to jump to; these classes model those makers, such as Coda, Segno, and Fine, which are subclassed below.

Coda

Inherits from: RepeatExpressionMarker, RepeatExpression, RepeatMark, Expression, Music21Object

class music21.repeat.Coda(text=None)

The coda symbol, or the word coda, as placed in a score.

>>> from music21 import *
>>> rm = repeat.Coda()

Segno

Inherits from: RepeatExpressionMarker, RepeatExpression, RepeatMark, Expression, Music21Object

class music21.repeat.Segno

The segno sign as placed in a score.

>>> from music21 import *
>>> rm = repeat.Segno()
>>> rm.useSymbol
True

Fine

Inherits from: RepeatExpressionMarker, RepeatExpression, RepeatMark, Expression, Music21Object

class music21.repeat.Fine

The fine word as placed in a score.

>>> from music21 import *
>>> rm = repeat.Fine()

RepeatExpressionCommand

Inherits from: RepeatExpression, RepeatMark, Expression, Music21Object

class music21.repeat.RepeatExpressionCommand

Some repeat expressions are commands, instructing the reader to go somewhere else. DaCapo and related are examples.

RepeatExpressionCommand attributes

Attributes without Documentation: repeatAfterJump

Attributes inherited from RepeatExpression: useSymbol

Attributes inherited from Music21Object: classSortOrder, isSpanner, isStream, isVariant, xPosition, id, sites, groups, hideObjectOnPrint

RepeatExpressionCommand properties

RepeatExpressionCommand methods

DaCapo

Inherits from: RepeatExpressionCommand, RepeatExpression, RepeatMark, Expression, Music21Object

class music21.repeat.DaCapo(text=None)

The Da Capo command, indicating a return to the beginning and a continuation to the end. By default, repeatAfterJump is False, indicating that any repeats encountered on the Da Capo repeat not be repeated.

DaCapoAlFine

Inherits from: RepeatExpressionCommand, RepeatExpression, RepeatMark, Expression, Music21Object

class music21.repeat.DaCapoAlFine(text=None)

The Da Capo al Fine command, indicating a return to the beginning and a continuation to the Fine object. By default, repeatAfterJump is False, indicating that any repeats encountered on the Da Capo repeat not be repeated.

>>> from music21 import *
>>> rm = repeat.DaCapoAlFine()

DaCapoAlCoda

Inherits from: RepeatExpressionCommand, RepeatExpression, RepeatMark, Expression, Music21Object

class music21.repeat.DaCapoAlCoda(text=None)

The Da Capo al Coda command, indicating a return to the beginning and a continuation to the Coda object. The music resumes at a second Coda object. By default, repeatAfterJump is False, indicating that any repeats encountered on the Da Capo repeat not be repeated.

>>> from music21 import *
>>> rm = repeat.DaCapoAlCoda()

AlSegno

Inherits from: RepeatExpressionCommand, RepeatExpression, RepeatMark, Expression, Music21Object

class music21.repeat.AlSegno(text=None)

Jump to the sign. Presumably a forward jump, not a repeat.

>>> from music21 import *
>>> rm = repeat.AlSegno()

DalSegno

Inherits from: RepeatExpressionCommand, RepeatExpression, RepeatMark, Expression, Music21Object

class music21.repeat.DalSegno(text=None)

The Dal Segno command, indicating a return to the segno and a continuation to the end. By default, repeatAfterJump is False, indicating that any repeats encountered on the Da Capo repeat not be repeated.

>>> from music21 import *
>>> rm = repeat.DaCapoAlFine()

DalSegnoAlFine

Inherits from: RepeatExpressionCommand, RepeatExpression, RepeatMark, Expression, Music21Object

class music21.repeat.DalSegnoAlFine(text=None)

The Dal Segno al Fine command, indicating a return to the segno and a continuation to the Fine object. By default, repeatAfterJump is False, indicating that any repeats encountered on the Dal Segno repeat not be repeated.

>>> from music21 import *
>>> rm = repeat.DaCapoAlFine()

DalSegnoAlCoda

Inherits from: RepeatExpressionCommand, RepeatExpression, RepeatMark, Expression, Music21Object

class music21.repeat.DalSegnoAlCoda(text=None)

The Dal Segno al Coda command, indicating a return to the beginning and a continuation to the Coda object. The music resumes at a second Coda object. By default, repeatAfterJump is False, indicating that any repeats encountered on the Da Segno repeat not be repeated.

>>> from music21 import *
>>> rm = repeat.DaCapoAlCoda()

RepeatFinder

class music21.repeat.RepeatFinder(inpStream=None, defaultMeasureHashFunction=None)

An object for finding and simplifying repeated sections of music. Must be passed a stream which contains either measures or parts containing measures.

To collapse a repeated section, call RepeatFinder.simplify() and to see which sections of a piece are repeated, call either RepeatFinder.getMeasureSimilarityList() or RepeatFinder.getSimilarMeasureGroups (see below for full documentation).

If the internal stream passed to RepeatFinder is altered in any way (e.g. if you call simplify() with inplace=True) then to ensure proper functionality, you should use a new RepeatFinder object.

Below is an example of calling simplify on a Bach chorale.

>>> from music21 import *
>>> chorale = corpus.parse('bwv117.4.mxl')
>>> chorale.show()

Only the first 8 bars are displayed

_images/repeat-SimplifyExample_Chorale.PNG
>>> repeat.RepeatFinder(chorale).simplify().show()

The same chorale as before, but simplified

_images/repeat-SimplifyExample_ChoraleSimplified.PNG

RepeatFinder attributes

defaultHash

A function that takes a stream of notes and rests and returns a string or an integer such that two measures are equal if their hashes are equal under the ‘==’ operator

s

The internal stream which is being analyzed for repeated sections

RepeatFinder methods

simplify(repeatThreshold=4, repeatEndingThreshold=3, inPlace=False)

Takes the piece stored in the RepeatFinder object and collapses repeated sections by replacing them with repeat signs. Includes first and second endings where appropriate.

Only detects repeated sections which are repeatThreshold bars long and only detecs repeat endings where the repeated sections is more than repeatEndingThreshold bars long. If inPlace is True, does not return a new music21 object, but instead alters the stream passed to the RepeatFinder object.

In the below example, we have an 8-measure stream where the last four measures are identical to the first four.

>>> from music21 import *
>>> s = stream.Stream()
>>> notes = [note.Note('D'), note.Note('E-'), note.Note('C'), note.Note('B3'),
...           note.Note('D'), note.Note('E-'), note.Note('C'), note.Note('B3')]
>>> for i in range(8):
...    m = stream.Measure()
...    m.number = i+1
...    myNote = notes[i]
...    myNote.duration.quarterLength = 4.0
...    m.append(myNote)
...    s.append(m)
>>> s.show()
_images/repeat-RepeatFinderDSCH.PNG
>>> s2 = RepeatFinder(s).simplify()
>>> s2.show()
_images/repeat-RepeatFinderDSCHsimplified.PNG
getMeasureSimilarityList()

Returns a list mList = [ [2, 3], [3], ... ] such that measures i and j are the same (with i < j) if and only if mList[i] contains j. NOTE: this function refers to the very first measure as measure 0 regardless of whether s starts with measure 0 or 1 (i.e. treats a pickup bar as an entire measure).

For instance, if getMeasureSimilarityList returned [[4], [5], [6], [7,8], [], [], [], [8], []], we would know that the first four measures repeat and the 4th, 8th, and 9th measures are the same.

Measures are considered the same if the defaultHash maps them to two values which are equal under the ‘==’ operator.

>>> from music21 import *
>>> chorales = corpus.getBachChorales()
>>> chorale = corpus.parse('bwv154.3.mxl')
>>> repeat.RepeatFinder(chorale).getMeasureSimilarityList()
[[4], [5], [6], [7, 15], [], [], [], [15], [], [], [], [], [], [], [], []]
>>> repeat.RepeatFinder(chorale.parts[0]).getMeasureSimilarityList()
[[4, 12], [5], [6], [7, 15], [12], [], [], [15], [], [], [], [], [], [], [], []]
>>> chorale2 = corpus.parse('bwv153.5.mxl')
>>> repeat.RepeatFinder(chorale2).getMeasureSimilarityList()    #bwv153.5 has a pickup
[[], [5], [6], [7], [], [], [], [], [], [], [], [], [], [], [], [], []]
>>> hashFunction = lambda m : str(len(m))
>>> repeat.RepeatFinder(chorale.parts[0].measures(1, 8), defaultMeasureHashFunction=hashFunction).getMeasureSimilarityList()
[[1, 2, 4, 5, 6], [2, 4, 5, 6], [4, 5, 6], [7], [5, 6], [6], [], []]
getSimilarMeasureGroups(threshold=1)

Returns a list of tuples containing information on repeated groups of measures.

Specifically, returns a list of tuples of the form (l1, l2) where l1 and l2 are lists of measure numbers such that measure l1[i] is the same as measure l2[i].

>>> from music21 import *
>>> chorale = corpus.parse('bwv117.4.mxl')
>>> chorale.show()

Measures 1-3 are the same as measures 4-6.

_images/repeat-SimplifyExample_Chorale.PNG
>>> repeat.RepeatFinder(chorale).getSimilarMeasureGroups()
[([1, 2, 3], [5, 6, 7])]

Notice that although measures 2-3 are the same as measures 6-7, we don’t have ([2, 3], [6, 7]) in our result, since ([1, 2, 3], [5, 6, 7]) already contains that information

getQuarterLengthOfPickupMeasure()

Looks at RepeatFinder’s internal stream and returns the duration of the pickup bar in quarterlengths. If there is no pickup, returns 0.0.

Raises an exception if RepeatFinder’s internal stream is too short (i.e. fewer than 3 measures long)

>>> from music21 import *
>>> noPickup = corpus.parse('bwv10.7.mxl')
>>> repeat.RepeatFinder(noPickup).getQuarterLengthOfPickupMeasure()
0.0
>>> noPickup.parts[0].measures(0,5).show()
_images/repeat-rf_noPickup.PNG
>>> hasPickup = corpus.parse('bwv101.7.mxl')
>>> repeat.RepeatFinder(hasPickup).getQuarterLengthOfPickupMeasure()
1.0
>>> hasPickup.parts[0].measures(0,2).show()
_images/repeat-rf_hasPickup.PNG
>>> tooShort = noPickup.parts[0].measures(1, 2)
>>> repeat.RepeatFinder(tooShort).getQuarterLengthOfPickupMeasure()
Traceback (most recent call last):
InsufficientLengthException: Cannot determine length of pickup given fewer than 3 measures
hasPickup()

Returns True when the RepeatFinder’s internal stream has a pickup bar.

Raises an exception if the internal stream is too short (i.e. fewer than 3 bars long).

>>> from music21 import *
>>> noPickup = corpus.parse('bwv10.7.mxl')
>>> repeat.RepeatFinder(noPickup).hasPickup()
False
>>> noPickup.parts[0].measures(0,5).show()
_images/repeat-rf_noPickup.PNG
>>> hasPickup = corpus.parse('bwv101.7.mxl')
>>> repeat.RepeatFinder(hasPickup).hasPickup()
True
>>> hasPickup.parts[0].measures(0,2).show()
_images/repeat-rf_hasPickup.PNG

Expander

class music21.repeat.Expander(streamObj=None)

The Expander object can expand a single Part or Part-like Stream with repeats. Nested repeats given with Repeat objects, or repeats and sections designated with RepeatExpression objects, are all expanded.

This class is a utility processor. Direct usage is more commonly from the expandRepeats() method.

To use this object directly, call process() on the score

>>> from music21 import *
>>> s = converter.parse('tinynotation: 3/4 A2. C4 D E F2.')
>>> s.makeMeasures(inPlace = True)
>>> s.measure(2).leftBarline = bar.Repeat(direction='start')
>>> s.measure(2).rightBarline = bar.Repeat(direction='end', times=3)
>>> s.show('text')
{0.0} <music21.stream.Measure 1 offset=0.0>
    {0.0} <music21.clef.BassClef>
    {0.0} <music21.meter.TimeSignature 3/4>
    {0.0} <music21.note.Note A>
{3.0} <music21.stream.Measure 2 offset=3.0>
    {0.0} <music21.bar.Repeat direction=start>
    {0.0} <music21.note.Note C>
    {1.0} <music21.note.Note D>
    {2.0} <music21.note.Note E>
    {3.0} <music21.bar.Repeat direction=end times=3>
{6.0} <music21.stream.Measure 3 offset=6.0>
    {0.0} <music21.note.Note F>
    {3.0} <music21.bar.Barline style=final>

>>> e = repeat.Expander(s)
>>> e.repeatBarsAreCoherent()
True
>>> s2 = e.process()
>>> s2.show('text')
{0.0} <music21.stream.Measure 1 offset=0.0>
    {0.0} <music21.clef.BassClef>
    {0.0} <music21.meter.TimeSignature 3/4>
    {0.0} <music21.note.Note A>
{3.0} <music21.stream.Measure 2 offset=3.0>
    {0.0} <music21.bar.Barline style=double>
    {0.0} <music21.note.Note C>
    {1.0} <music21.note.Note D>
    {2.0} <music21.note.Note E>
    {3.0} <music21.bar.Barline style=double>
{6.0} <music21.stream.Measure 2 offset=6.0>
    {0.0} <music21.bar.Barline style=double>
    {0.0} <music21.note.Note C>
    {1.0} <music21.note.Note D>
    {2.0} <music21.note.Note E>
    {3.0} <music21.bar.Barline style=double>
{9.0} <music21.stream.Measure 2 offset=9.0>
    {0.0} <music21.bar.Barline style=double>
    {0.0} <music21.note.Note C>
    {1.0} <music21.note.Note D>
    {2.0} <music21.note.Note E>
    {3.0} <music21.bar.Barline style=double>
{12.0} <music21.stream.Measure 3 offset=12.0>
    {0.0} <music21.note.Note F>
    {3.0} <music21.bar.Barline style=final>

Expander methods

process(deepcopy=True)

This is the main call for Expander

Processes all repeats. Note that this processing only happens for Measures contained in the given Stream. Other objects in that Stream are neither processed nor copied.

if deepcopy is False then it will leave the stream in a unusual state, but acceptable if the source stream has already been deepcopied and will be discarded later

measureMap(returnType='index')

returns a list where for each measure in the expanded stream, the index of the measure in the original stream is given. if returnType = ‘measureNumber’ then the str(measureNumber) of the original instead of the index of the original is used – suffixes are important here for endings etc..

Inefficient, because the entire stream is expanded before making this call, rather than just seeing what needs to be expanded and returning that.

>>> from music21 import *
>>> s = converter.parse('tinynotation: 3/4 A2.  C4 D E   F2.    G4 a b   c2.')
>>> s.makeMeasures(inPlace = True)
>>> s.measure(2).leftBarline = bar.Repeat(direction='start')
>>> s.measure(2).rightBarline = bar.Repeat(direction='end', times=3)
>>> s.measure(4).leftBarline = bar.Repeat(direction='start')
>>> s.measure(4).rightBarline = bar.Repeat(direction='end', times=2)
>>> e = repeat.Expander(s)
>>> e.measureMap()
[0, 1, 1, 1, 2, 3, 3, 4]
>>> e.measureMap(returnType='measureNumber')
['1', '2', '2', '2', '3', '4', '4', '5']
getRepeatExpressionIndex(streamObj, target)

Return a list of index positions of a Measure given a stream of measures. This requires the provided stream to only have measures.

>>> from music21 import *
>>> s = converter.parse('tinynotation: 3/4 A2. C4 D E F2.')
>>> s.makeMeasures(inPlace = True)
>>> s.measure(3).append(repeat.Segno())
>>> e = repeat.Expander()

getRepeatExpressionIndex returns the measureIndex not measure number

>>> e.getRepeatExpressionIndex(s.getElementsByClass('Measure'), 'Segno')
[2]
isExpandable()

Return True or False if this Stream is expandable, that is, if it has balanced repeats or sensible da copo or dal segno indications.

processInnermostRepeatBars(streamObj, repeatIndices=None, repeatTimes=None, returnExpansionOnly=False)

Process and return a new Stream of Measures, likely a Part.

If repeatIndices are given, only these indices will be copied. All inclusive indices must be listed, not just the start and end.

If returnExpansionOnly is True, only the expanded portion is returned, the rest of the Stream is not retained.

>>> from music21 import *
>>> s = converter.parse('tinynotation: 3/4 A2.  C4 D E   F2.    G4 a b   c2.')
>>> s.makeMeasures(inPlace = True)
>>> s.measure(2).leftBarline = bar.Repeat(direction='start')
>>> s.measure(2).rightBarline = bar.Repeat(direction='end', times=3)
>>> s.measure(4).leftBarline = bar.Repeat(direction='start')
>>> s.measure(4).rightBarline = bar.Repeat(direction='end', times=2)

processInnermostRepeatBars only will expand the first time.

>>> e = repeat.Expander(s)
>>> s2 = e.processInnermostRepeatBars(s)
>>> s2.show('text')
{0.0} <music21.stream.Measure 1 offset=0.0>
    {0.0} <music21.clef.BassClef>
    {0.0} <music21.meter.TimeSignature 3/4>
    {0.0} <music21.note.Note A>
{3.0} <music21.stream.Measure 2 offset=3.0>
    {0.0} <music21.bar.Barline style=double>
    {0.0} <music21.note.Note C>
    {1.0} <music21.note.Note D>
    {2.0} <music21.note.Note E>
    {3.0} <music21.bar.Barline style=double>
{6.0} <music21.stream.Measure 2 offset=6.0>
    {0.0} <music21.bar.Barline style=double>
    {0.0} <music21.note.Note C>
    {1.0} <music21.note.Note D>
    {2.0} <music21.note.Note E>
    {3.0} <music21.bar.Barline style=double>
{9.0} <music21.stream.Measure 2 offset=9.0>
    {0.0} <music21.bar.Barline style=double>
    {0.0} <music21.note.Note C>
    {1.0} <music21.note.Note D>
    {2.0} <music21.note.Note E>
    {3.0} <music21.bar.Barline style=double>
{12.0} <music21.stream.Measure 3 offset=12.0>
    {0.0} <music21.note.Note F>
{15.0} <music21.stream.Measure 4 offset=15.0>
    {0.0} <music21.bar.Repeat direction=start>
    {0.0} <music21.note.Note G>
    {1.0} <music21.note.Note A>
    {2.0} <music21.note.Note B>
    {3.0} <music21.bar.Repeat direction=end times=2>
{18.0} <music21.stream.Measure 5 offset=18.0>
    {0.0} <music21.note.Note C>
    {3.0} <music21.bar.Barline style=final>

Calling it again does the trick..., as _processRecursiveRepeatBars does

>>> s3 = e.processInnermostRepeatBars(s2)
>>> s3.show('text')
{0.0} <music21.stream.Measure 1 offset=0.0>
...
{3.0} <music21.stream.Measure 2 offset=3.0>
...
{6.0} <music21.stream.Measure 2 offset=6.0>
...
{9.0} <music21.stream.Measure 2 offset=9.0>
...
{12.0} <music21.stream.Measure 3 offset=12.0>
...
{15.0} <music21.stream.Measure 4 offset=15.0>
    {0.0} <music21.bar.Barline style=double>
    {0.0} <music21.note.Note G>
    {1.0} <music21.note.Note A>
    {2.0} <music21.note.Note B>
    {3.0} <music21.bar.Barline style=double>
{18.0} <music21.stream.Measure 4 offset=18.0>
    {0.0} <music21.bar.Barline style=double>
    {0.0} <music21.note.Note G>
    {1.0} <music21.note.Note A>
    {2.0} <music21.note.Note B>
    {3.0} <music21.bar.Barline style=double>
{21.0} <music21.stream.Measure 5 offset=21.0>
...
repeatBarsAreCoherent()

Check that all repeat bars are paired properly. Returns True or False

RepeatMark

class music21.repeat.RepeatMark

Base class of all repeat objects, including RepeatExpression objects and Repeat (Barline) objects.

This object is used to for multiple-inheritance of such objects and to filter by class in order to get all things that mark repeats.

The RepeatMark is not itself a Music21Object so you should use multiple inheritance to put these things in Streams.

The following demonstration shows how a user might see if a Stream has any repeats in it.

>>> from music21 import *
>>> class PartialRepeat(repeat.RepeatMark, base.Music21Object):
...    def __init__(self):
...        base.Music21Object.__init__(self)

>>> s = stream.Stream()
>>> s.append(note.Note())
>>> s.append(PartialRepeat())
>>> repeats = s.getElementsByClass(repeat.RepeatMark)
>>> if len(repeats) > 0:
...    print "Stream has %d repeat(s) in it" % (len(repeats))
Stream has 1 repeat(s) in it