music21.meter¶
This module defines the TimeSignature
object,
as well as component objects for defining nested metrical structures,
MeterTerminal
and MeterSequence
objects.
Functions¶
-
music21.meter.
bestTimeSignature
(meas)¶ Given a Measure with elements in it, get a TimeSignature that contains all elements.
Note: this does not yet accommodate triplets.
>>> s = converter.parse('tinynotation: C4 D4 E8 F8').flat.notes >>> m = stream.Measure() >>> for el in s: ... m.insert(el.offset, el) >>> ts = meter.bestTimeSignature(m) >>> ts <music21.meter.TimeSignature 3/4>
>>> s2 = converter.parse('tinynotation: C8. D16 E8 F8. G16 A8').flat.notes >>> m2 = stream.Measure() >>> for el in s2: ... m2.insert(el.offset, el) >>> ts2 = meter.bestTimeSignature(m2) >>> ts2 <music21.meter.TimeSignature 6/8>
>>> s3 = converter.parse('C2 D2 E2', format='tinyNotation').flat.notes >>> m3 = stream.Measure() >>> for el in s3: ... m3.insert(el.offset, el) >>> ts3 = meter.bestTimeSignature(m3) >>> ts3 <music21.meter.TimeSignature 3/2>
>>> s4 = converter.parse('C8. D16 E8 F8. G16 A8 C4. D4.', format='tinyNotation').flat.notes >>> m4 = stream.Measure() >>> for el in s4: ... m4.insert(el.offset, el) >>> ts4 = meter.bestTimeSignature(m4) >>> ts4 <music21.meter.TimeSignature 12/8>
>>> s5 = converter.parse('C4 D2 E4 F2', format='tinyNotation').flat.notes >>> m5 = stream.Measure() >>> for el in s5: ... m5.insert(el.offset, el) >>> ts5 = meter.bestTimeSignature(m5) >>> ts5 <music21.meter.TimeSignature 6/4>
>>> s6 = converter.parse('C4 D16.', format='tinyNotation').flat.notes >>> m6 = stream.Measure() >>> for el in s6: ... m6.insert(el.offset, el) >>> ts6 = meter.bestTimeSignature(m6) >>> ts6 <music21.meter.TimeSignature 11/32>
-
music21.meter.
fractionSum
(fList)¶ Given a list of fractions represented as a list, find the sum; does NOT reduce to lowest terms.
>>> meter.fractionSum([(3,8), (5,8), (1,8)]) (9, 8) >>> meter.fractionSum([(1,6), (2,3)]) (5, 6) >>> meter.fractionSum([(3,4), (1,2)]) (5, 4) >>> meter.fractionSum([(1,13), (2,17)]) (43, 221) >>> meter.fractionSum([]) (0, 1)
This method might seem like an easy place to optimize and simplify by just doing a fractions.Fraction() sum (I tried!), but not reducing to lowest terms is a feature of this method. 3/8 + 3/8 = 6/8, not 3/4:
>>> meter.fractionSum([(3,8), (3,8)]) (6, 8)
-
music21.meter.
fractionToSlashMixed
(fList)¶ Given a list of fraction values, compact numerators by sum if denominators are the same
>>> meter.fractionToSlashMixed([(3, 8), (2, 8), (5, 8), (3, 4), (2, 16), (1, 16), (4, 16)]) [('3+2+5', 8), ('3', 4), ('2+1+4', 16)]
-
music21.meter.
proportionToFraction
(value)¶ Given a floating point proportional value between 0 and 1, return the best-fit slash-base fraction
>>> meter.proportionToFraction(.5) (1, 2) >>> meter.proportionToFraction(.25) (1, 4) >>> meter.proportionToFraction(.75) (3, 4) >>> meter.proportionToFraction(.125) (1, 8) >>> meter.proportionToFraction(.375) (3, 8) >>> meter.proportionToFraction(.625) (5, 8) >>> meter.proportionToFraction(.333) (1, 3) >>> meter.proportionToFraction(0.83333) (5, 6)
-
music21.meter.
slashCompoundToFraction
(value)¶ >>> meter.slashCompoundToFraction('3/8+2/8') [(3, 8), (2, 8)] >>> meter.slashCompoundToFraction('5/8') [(5, 8)] >>> meter.slashCompoundToFraction('5/8+2/4+6/8') [(5, 8), (2, 4), (6, 8)]
-
music21.meter.
slashMixedToFraction
(valueSrc)¶ Given a mixture if possible meter fraction representations, return a list of pairs. If originally given as a summed numerator; break into separate fractions and return True as the second element of the tuple
>>> meter.slashMixedToFraction('3/8+2/8') ([(3, 8), (2, 8)], False)
>>> meter.slashMixedToFraction('3+2/8') ([(3, 8), (2, 8)], True)
>>> meter.slashMixedToFraction('3+2+5/8') ([(3, 8), (2, 8), (5, 8)], True)
>>> meter.slashMixedToFraction('3+2+5/8+3/4') ([(3, 8), (2, 8), (5, 8), (3, 4)], True)
>>> meter.slashMixedToFraction('3+2+5/8+3/4+2+1+4/16') ([(3, 8), (2, 8), (5, 8), (3, 4), (2, 16), (1, 16), (4, 16)], True)
>>> meter.slashMixedToFraction('3+2+5/8+3/4+2+1+4') Traceback (most recent call last): ... MeterException: cannot match denominator to numerator in: 3+2+5/8+3/4+2+1+4
-
music21.meter.
slashToTuple
(value)¶ Returns a three-element MeterTerminalTuple of numerator, denominator, and optional tempo indication.
>>> meter.slashToTuple('3/8') MeterTerminalTuple(numerator=3, denominator=8, tempoIndication=None) >>> meter.slashToTuple('7/32') MeterTerminalTuple(numerator=7, denominator=32, tempoIndication=None) >>> meter.slashToTuple('slow 6/8') MeterTerminalTuple(numerator=6, denominator=8, tempoIndication='slow')
TimeSignature¶
-
class
music21.meter.
TimeSignature
(value=None, partitionRequest=None)¶ The TimeSignature object representes time signatures in musical scores (4/4, 3/8, 2/4+5/16, Cut, etc.).
TimeSignatures should be present in the first Measure of each Part that they apply to. Alternatively you can put the time signature at the front of a Part or at the beginning of a Score and they will work within music21 but they won’t necessarily display properly in musicxml, lilypond, etc. So best is to create structures like this:
>>> s = stream.Score() >>> p = stream.Part() >>> m1 = stream.Measure() >>> ts = meter.TimeSignature('3/4') >>> m1.insert(0, ts) >>> m1.insert(0, note.Note('C#3', type='half')) >>> n = note.Note('D3', type='quarter') # we will need this later >>> m1.insert(1.0, n) >>> m1.number = 1 >>> p.insert(0, m1) >>> s.insert(0, p) >>> s.show('t') {0.0} <music21.stream.Part ...> {0.0} <music21.stream.Measure 1 offset=0.0> {0.0} <music21.meter.TimeSignature 3/4> {0.0} <music21.note.Note C#> {1.0} <music21.note.Note D>
Basic operations on a TimeSignature object are designed to be very simple.
>>> ts.ratioString '3/4'
>>> ts.numerator 3
>>> ts.beatCount 3
>>> ts.beatCountName 'Triple'
>>> ts.beatDuration.quarterLength 1.0
As an alternative to putting a TimeSignature in a Stream at a specific position (offset), it can be assigned to a special property in Measure that positions the TimeSignature at the start of a Measure. Notice that when we show() the Measure (or if we iterate through it), the TimeSignature appears as if it’s in the measure itself:
>>> m2 = stream.Measure() >>> m2.number = 2 >>> ts2 = meter.TimeSignature('2/4') >>> m2.timeSignature = ts2 >>> m2.append(note.Note('E3', type='half')) >>> p.append(m2) >>> s.show('text') {0.0} <music21.stream.Part ...> {0.0} <music21.stream.Measure 1 offset=0.0> {0.0} <music21.meter.TimeSignature 3/4> {0.0} <music21.note.Note C#> {1.0} <music21.note.Note D> {2.0} <music21.stream.Measure 2 offset=2.0> {0.0} <music21.meter.TimeSignature 2/4> {0.0} <music21.note.Note E>
Once a Note has a local TimeSignature, a Note can get its beat position and other meter-specific parameters. Remember n, our quarter note at offset 2.0 of m1, a 3/4 measure? Let’s get its beat:
>>> n.beat 2.0
This feature is more useful if there are more beats:
>>> m3 = stream.Measure() >>> m3.timeSignature = meter.TimeSignature('3/4') >>> eighth = note.Note(type='eighth') >>> m3.repeatAppend(eighth, 6) >>> [thisNote.beatStr for thisNote in m3.notes] ['1', '1 1/2', '2', '2 1/2', '3', '3 1/2']
Now lets change its measure’s TimeSignature and see what happens:
>>> sixEight = meter.TimeSignature('6/8') >>> m3.timeSignature = sixEight >>> [thisNote.beatStr for thisNote in m3.notes] ['1', '1 1/3', '1 2/3', '2', '2 1/3', '2 2/3']
TimeSignature(‘6/8’) defaults to fast 6/8:
>>> sixEight.beatCount 2
>>> sixEight.beatDuration.quarterLength 1.5
>>> sixEight.beatDivisionCountName 'Compound'
Let’s make it slow 6/8 instead:
>>> sixEight.beatCount = 6 >>> sixEight.beatDuration.quarterLength 0.5
>>> sixEight.beatDivisionCountName 'Simple'
Now let’s look at the beatStr for each of the notes in m3:
>>> [thisNote.beatStr for thisNote in m3.notes] ['1', '2', '3', '4', '5', '6']
TimeSignatures can also use symbols instead of numbers
>>> tsCommon = meter.TimeSignature('c') # or common >>> tsCommon.beatCount 4 >>> tsCommon.denominator 4
>>> tsCommon.symbol 'common'
>>> tsCut = meter.TimeSignature("cut") >>> tsCut.beatCount 2 >>> tsCut.denominator 2
>>> tsCut.symbol 'cut'
For complete details on using this object, see overviewMeters.
That’s it for the simple aspects of TimeSignature objects. You know enough to get started now!
Under the hood, they’re extremely powerful. For musicians, TimeSignatures do (at least) three different things:
- They define where the beats in the measure are and how many there are.
- They indicate how the notes should be beamed
- They give a sense of how much accent or weight each note gets, which also defines which are important notes and which might be ornaments.
These three aspects of TimeSignatures are controlled by the
beatSequence
,beamSequence
, andaccentSequence
properties of the TimeSignature. Each of them is an independentMeterSequence
element which might have nested properties (e.g., a 11/16 meter might be beamed as {1/4+1/4+{1/8+1/16}}), so if you want to change how beats are calculated or beams are generated you’ll want to learn more about meter.MeterSequence objects.There’s a fourth MeterSequence object inside a TimeSignature, and that is the
displaySequence
. That determines how the TimeSignature should actually look on paper. Normally this MeterSequence is pretty simple. In ‘4/4’ it’s usually just ‘4/4’. But if you have the ‘11/16’ time above, you may want to have it displayed as ‘2/4+3/16’ or ‘11/16 (2/4+3/16)’. Or you might want the written TimeSignature to contradict what the notes imply. All this can be done with .displaySequence.
TimeSignature
bases
TimeSignature
read-only properties
-
TimeSignature.
beatCountName
¶ Return the beat count name, or the name given for the number of beat units. For example, 2/4 is duple; 9/4 is triple.
>>> ts = meter.TimeSignature('3/4') >>> ts.beatCountName 'Triple'
>>> ts = meter.TimeSignature('6/8') >>> ts.beatCountName 'Duple'
-
TimeSignature.
beatDivisionCount
¶ Return the count of background beat units found within one beat, or the number of subdivisions in the beat unit in this TimeSignature.
>>> ts = meter.TimeSignature('3/4') >>> ts.beatDivisionCount 2
>>> ts = meter.TimeSignature('6/8') >>> ts.beatDivisionCount 3
>>> ts = meter.TimeSignature('15/8') >>> ts.beatDivisionCount 3
>>> ts = meter.TimeSignature('3/8') >>> ts.beatDivisionCount 2
>>> ts = meter.TimeSignature('13/8', 13) >>> ts.beatDivisionCount Traceback (most recent call last): TimeSignatureException: cannot determine beat backgrond when each beat is not partitioned
-
TimeSignature.
beatDivisionCountName
¶ Return the beat count name, or the name given for the number of beat units. For example, 2/4 is duple; 9/4 is triple.
>>> ts = meter.TimeSignature('3/4') >>> ts.beatDivisionCountName 'Simple'
>>> ts = meter.TimeSignature('6/8') >>> ts.beatDivisionCountName 'Compound'
-
TimeSignature.
beatDivisionDurations
¶ Return the beat division, or the durations that make up one beat, as a list of
Duration
objects, if and only if the TimeSignature has a uniform beat division for all beats.>>> ts = meter.TimeSignature('3/4') >>> ts.beatDivisionDurations [<music21.duration.Duration 0.5>, <music21.duration.Duration 0.5>]
>>> ts = meter.TimeSignature('6/8') >>> ts.beatDivisionDurations [<music21.duration.Duration 0.5>, <music21.duration.Duration 0.5>, <music21.duration.Duration 0.5>]
-
TimeSignature.
beatDuration
¶ Return a
Duration
object equal to the beat unit of this Time Signature, if and only if this TimeSignatyure has a uniform beat unit.>>> ts = meter.TimeSignature('3/4') >>> ts.beatDuration <music21.duration.Duration 1.0> >>> ts = meter.TimeSignature('6/8') >>> ts.beatDuration <music21.duration.Duration 1.5>
>>> ts = meter.TimeSignature('7/8') >>> ts.beatDuration <music21.duration.Duration 0.5>
-
TimeSignature.
beatLengthToQuarterLengthRatio
¶ >>> a = meter.TimeSignature('3/2') >>> a.beatLengthToQuarterLengthRatio 2.0
-
TimeSignature.
beatSubDivisionDurations
¶ Return a subdivision of the beat division, or a list of
Duration
objects representing each beat division divided by two.>>> ts = meter.TimeSignature('3/4') >>> ts.beatSubDivisionDurations [<music21.duration.Duration 0.25>, <music21.duration.Duration 0.25>, <music21.duration.Duration 0.25>, <music21.duration.Duration 0.25>]
>>> ts = meter.TimeSignature('6/8') >>> ts.beatSubDivisionDurations [<music21.duration.Duration 0.25>, <music21.duration.Duration 0.25>, <music21.duration.Duration 0.25>, <music21.duration.Duration 0.25>, <music21.duration.Duration 0.25>, <music21.duration.Duration 0.25>]
-
TimeSignature.
classification
¶ Return the classification of this TimeSignature, such as Simple Triple or Compound Quadruple.
>>> ts = meter.TimeSignature('3/4') >>> ts.classification 'Simple Triple' >>> ts = meter.TimeSignature('6/8') >>> ts.classification 'Compound Duple' >>> ts = meter.TimeSignature('4/32') >>> ts.classification 'Simple Quadruple'
-
TimeSignature.
quarterLengthToBeatLengthRatio
¶
-
TimeSignature.
totalLength
¶ Total length of the TimeSignature, in Quarter Lengths.
>>> ts = meter.TimeSignature('6/8') >>> ts.totalLength 3.0
Read-only properties inherited from Music21Object
:
TimeSignature
read/write properties
-
TimeSignature.
barDuration
¶ Return a
Duration
object equal to the total length of this TimeSignature.>>> ts = meter.TimeSignature('5/16') >>> ts.barDuration <music21.duration.Duration 1.25>
-
TimeSignature.
beatCount
¶ Return or set the count of beat units, or the number of beats in this TimeSignature.
When setting beat units, one level of sub-partitions is automatically defined. Users can provide beat count values as integers or as lists of durations. For more precise configuration of the beat MeterSequence, manipulate the .beatSequence attribute directly.
>>> ts = meter.TimeSignature('3/4') >>> ts.beatCount 3 >>> ts.beatDuration.quarterLength 1.0 >>> ts.beatCount = [1,1,1,1,1,1] >>> ts.beatCount 6 >>> ts.beatDuration.quarterLength 0.5
-
TimeSignature.
denominator
¶ Return the denominator of the TimeSignature as a number or set it.
(for complex TimeSignatures, note that this comes from the .beamSequence of the TimeSignature)
>>> ts = meter.TimeSignature('3/4') >>> ts.denominator 4 >>> ts.denominator = 8 >>> ts.ratioString '3/8'
In this folliwing case, the TimeSignature is silently being converted to 9/8 to get a single digit denominator:
>>> ts = meter.TimeSignature('2/4+5/8') >>> ts.denominator 8
-
TimeSignature.
numerator
¶ Return the numerator of the TimeSignature as a number.
Can set the numerator for a simple TimeSignature. To set the numerator of a complex TimeSignature, change beatCount.
(for complex TimeSignatures, note that this comes from the .beamSequence of the TimeSignature)
>>> ts = meter.TimeSignature('3/4') >>> ts.numerator 3 >>> ts.numerator = 5 >>> ts <music21.meter.TimeSignature 5/4>
In this case, the TimeSignature is silently being converted to 9/8 to get a single digit numerator:
>>> ts = meter.TimeSignature('2/4+5/8') >>> ts.numerator 9
-
TimeSignature.
ratioString
¶ returns a simple string representing the time signature ratio or sets a new one. Cannot be used for very complex time signatures:
>>> threeFour = meter.TimeSignature('3/4') >>> threeFour.ratioString '3/4'
>>> threeFour.ratioString = '5/8' >>> threeFour.numerator 5 >>> threeFour.denominator 8
Read/write properties inherited from Music21Object
:
TimeSignature
methods
-
TimeSignature.
averageBeatStrength
(streamIn, notesOnly=True)¶ returns a float of the average beat strength of all objects (or if notesOnly is True [default] only the notes) in the Stream specified as streamIn.
>>> s = converter.parse('C4 D4 E8 F8', format='tinyNotation').flat.notes >>> sixEight = meter.TimeSignature('6/8') >>> sixEight.averageBeatStrength(s) 0.4375 >>> threeFour = meter.TimeSignature('3/4') >>> threeFour.averageBeatStrength(s) 0.5625
If notesOnly is False then test objects will give added weight to the beginning of the measure:
>>> sixEight.averageBeatStrength(s, notesOnly=False) 0.4375 >>> s.insert(0.0, clef.TrebleClef()) >>> s.insert(0.0, clef.BassClef()) >>> sixEight.averageBeatStrength(s, notesOnly=False) 0.625
-
TimeSignature.
getAccent
(qLenPos)¶ Return True or False if the qLenPos is at the start of an accent division.
>>> a = meter.TimeSignature('3/4', 3) >>> a.accentSequence.partition([2,1]) >>> a.accentSequence <MeterSequence {2/4+1/4}> >>> a.getAccent(0) True >>> a.getAccent(1) False >>> a.getAccent(2) True
-
TimeSignature.
getAccentWeight
(qLenPos, level=0, forcePositionMatch=False, permitMeterModulus=False)¶ Given a qLenPos, return an accent level. In general, accents are assumed to define only a first-level weight.
If forcePositionMatch is True, an accent will only be returned if the provided qLenPos is a near exact match to the provided quarter length. Otherwise, half of the minimum quarter length will be provided.
If permitMeterModulus is True, quarter length positions greater than the duration of the Meter will be accepted as the modulus of the total meter duration.
>>> ts1 = meter.TimeSignature('3/4') >>> [ts1.getAccentWeight(x) for x in range(3)] [1.0, 0.5, 0.5]
Returns an error...
>>> [ts1.getAccentWeight(x) for x in range(6)] Traceback (most recent call last): MeterException: cannot access from qLenPos 3.0 where total duration is 3.0
...unless permitMeterModulus is employed
>>> [ts1.getAccentWeight(x, permitMeterModulus=True) for x in range(6)] [1.0, 0.5, 0.5, 1.0, 0.5, 0.5]
-
TimeSignature.
getBeams
(srcList, measureStartOffset=0.0)¶ Given a qLen position and a list of Duration objects, return a list of Beams object.
Can alternatively provide a flat stream, from which Durations are extracted.
Duration objects are assumed to be adjoining; offsets are not used.
This can be modified to take lists of rests and notes
Must process a list at time, because we cannot tell when a beam ends unless we see the context of adjoining durations.
>>> a = meter.TimeSignature('2/4', 2) >>> a.beamSequence[0] = a.beamSequence[0].subdivide(2) >>> a.beamSequence[1] = a.beamSequence[1].subdivide(2) >>> a.beamSequence <MeterSequence {{1/8+1/8}+{1/8+1/8}}> >>> b = [duration.Duration('16th')] * 8 >>> c = a.getBeams(b) >>> len(c) == len(b) True >>> print(c) [<music21.beam.Beams <music21.beam.Beam 1/start>/<music21.beam.Beam 2/start>>, <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/stop>>, <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/start>>, <music21.beam.Beams <music21.beam.Beam 1/stop>/<music21.beam.Beam 2/stop>>, <music21.beam.Beams <music21.beam.Beam 1/start>/<music21.beam.Beam 2/start>>, <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/stop>>, <music21.beam.Beams <music21.beam.Beam 1/continue>/<music21.beam.Beam 2/start>>, <music21.beam.Beams <music21.beam.Beam 1/stop>/<music21.beam.Beam 2/stop>>]
>>> a = meter.TimeSignature('6/8') >>> b = [duration.Duration('eighth')] * 6 >>> c = a.getBeams(b) >>> print(c) [<music21.beam.Beams <music21.beam.Beam 1/start>>, <music21.beam.Beams <music21.beam.Beam 1/continue>>, <music21.beam.Beams <music21.beam.Beam 1/stop>>, <music21.beam.Beams <music21.beam.Beam 1/start>>, <music21.beam.Beams <music21.beam.Beam 1/continue>>, <music21.beam.Beams <music21.beam.Beam 1/stop>>]
>>> fourFour = meter.TimeSignature('4/4') >>> d = duration.Duration >>> dList = [d('eighth'), d('quarter'), d('eighth'), d('eighth'), d('quarter'), d('eighth')] >>> beamList = fourFour.getBeams(dList) >>> print(beamList) [None, None, None, None, None, None]
Pickup measure support included by taking in an additional measureStartOffset argument.
>>> threeFour = meter.TimeSignature("3/4") >>> dList = [d('eighth'), d('eighth'), d('eighth')] >>> beamList = threeFour.getBeams(dList, measureStartOffset=1.5) >>> print(beamList) [<music21.beam.Beams <music21.beam.Beam 1/start>>, <music21.beam.Beams <music21.beam.Beam 1/continue>>, <music21.beam.Beams <music21.beam.Beam 1/stop>>]
-
TimeSignature.
getBeat
(offset)¶ Given an offset (quarterLength position), get the beat, where beats count from 1
If you want a fractional number for the beat, see getBeatProportion.
TODO: late: In v.1.4 – getBeat will probably do what getBeatProportion does now...
>>> a = meter.TimeSignature('3/4', 3) >>> a.getBeat(0) 1 >>> a.getBeat(2.5) 3 >>> a.beatSequence.partition(['3/8', '3/8']) >>> a.getBeat(2.5) 2
-
TimeSignature.
getBeatDepth
(qLenPos, align='quantize')¶ Return the number of levels of beat partitioning given a QL into the TimeSignature. Note that by default beat partitioning always has a single, top-level partition.
The align parameter is passed to the
offsetToDepth()
method, and can be used to find depths based on start position overlaps.>>> a = meter.TimeSignature('3/4', 3) >>> a.getBeatDepth(0) 1 >>> a.getBeatDepth(1) 1 >>> a.getBeatDepth(2) 1
>>> b = meter.TimeSignature('3/4', 1) >>> b.beatSequence[0] = b.beatSequence[0].subdivide(3) >>> b.beatSequence[0][0] = b.beatSequence[0][0].subdivide(2) >>> b.beatSequence[0][1] = b.beatSequence[0][1].subdivide(2) >>> b.beatSequence[0][2] = b.beatSequence[0][2].subdivide(2) >>> b.getBeatDepth(0) 3 >>> b.getBeatDepth(.5) 1 >>> b.getBeatDepth(1) 2
-
TimeSignature.
getBeatDuration
(qLenPos)¶ Returns a
Duration
object representing the length of the beat found at qLenPos. For most standard meters, you can give qLenPos = 0 and get the length of any beat in the TimeSignature; but the simplermusic21.meter.TimeSignature.beatDuration
parameter, will do that for you just as well.The advantage of this method is that it will work for asymmetrical meters, as the second example shows.
Ex. 1: beat duration for 3/4 is always 1.0 no matter where in the meter you query.
>>> ts1 = meter.TimeSignature('3/4') >>> ts1.getBeatDuration(.5) <music21.duration.Duration 1.0> >>> ts1.getBeatDuration(2.5) <music21.duration.Duration 1.0>
Ex. 2: same for 6/8:
>>> ts2 = meter.TimeSignature('6/8') >>> ts2.getBeatDuration(2.5) <music21.duration.Duration 1.5>
Ex. 3: but for a compound meter of 3/8 + 2/8, where you ask for the beat duration will determine the length of the beat:
>>> ts3 = meter.TimeSignature(['3/8','2/8']) # will partition as 2 beat >>> ts3.getBeatDuration(.5) <music21.duration.Duration 1.5> >>> ts3.getBeatDuration(1.5) <music21.duration.Duration 1.0>
-
TimeSignature.
getBeatOffsets
()¶ Return offset positions in a list for the start of each beat, assuming this object is found at offset zero.
>>> a = meter.TimeSignature('3/4') >>> a.getBeatOffsets() [0.0, 1.0, 2.0] >>> a = meter.TimeSignature('6/8') >>> a.getBeatOffsets() [0.0, 1.5]
-
TimeSignature.
getBeatProgress
(qLenPos)¶ Given a quarterLength position, get the beat, where beats count from 1, and return the the amount of qLen into this beat the supplied qLenPos is.
>>> a = meter.TimeSignature('3/4', 3) >>> a.getBeatProgress(0) (1, 0) >>> a.getBeatProgress(0.75) (1, 0.75) >>> a.getBeatProgress(1.0) (2, 0.0) >>> a.getBeatProgress(2.5) (3, 0.5)
Works for specifically partitioned meters too:
>>> a.beatSequence.partition(['3/8', '3/8']) >>> a.getBeatProgress(2.5) (2, 1.0)
-
TimeSignature.
getBeatProportion
(qLenPos)¶ Given a quarter length position into the meter, return a numerical progress through the beat (where beats count from one) with a floating-point or fractional value between 0 and 1 appended to this value that gives the proportional progress into the beat.
For faster, integer values, use simply .getBeat()
>>> ts1 = meter.TimeSignature('3/4') >>> ts1.getBeatProportion(0.0) 1.0 >>> ts1.getBeatProportion(0.5) 1.5 >>> ts1.getBeatProportion(1.0) 2.0
>>> ts3 = meter.TimeSignature(['3/8','2/8']) # will partition as 2 beat >>> ts3.getBeatProportion(.75) 1.5 >>> ts3.getBeatProportion(2.0) 2.5
-
TimeSignature.
getBeatProportionStr
(qLenPos)¶ Return a string presentation of the beat.
>>> ts1 = meter.TimeSignature('3/4') >>> ts1.getBeatProportionStr(0.0) '1' >>> ts1.getBeatProportionStr(0.5) '1 1/2' >>> ts1.getBeatProportionStr(1.0) '2' >>> ts3 = meter.TimeSignature(['3/8','2/8']) # will partition as 2 beat >>> ts3.getBeatProportionStr(.75) '1 1/2' >>> ts3.getBeatProportionStr(2) '2 1/2'
>>> ts4 = meter.TimeSignature(['6/8']) # will partition as 2 beat
-
TimeSignature.
getOffsetFromBeat
(beat)¶ Given a beat value, convert into an offset position.
>>> ts1 = meter.TimeSignature('3/4') >>> ts1.getOffsetFromBeat(1) 0.0 >>> ts1.getOffsetFromBeat(2) 1.0 >>> ts1.getOffsetFromBeat(3) 2.0 >>> ts1.getOffsetFromBeat(3.5) 2.5 >>> ts1.getOffsetFromBeat(3.25) 2.25
>>> from fractions import Fraction >>> ts1.getOffsetFromBeat(Fraction(8, 3)) # 2.66666 Fraction(5, 3)
>>> ts1 = meter.TimeSignature('6/8') >>> ts1.getOffsetFromBeat(1) 0.0 >>> ts1.getOffsetFromBeat(2) 1.5 >>> ts1.getOffsetFromBeat(2.33) 2.0 >>> ts1.getOffsetFromBeat(2.5) # will be + .5 * 1.5 2.25 >>> ts1.getOffsetFromBeat(2.66) 2.5
Works for asymmetrical meters as well:
>>> ts3 = meter.TimeSignature(['3/8','2/8']) # will partition as 2 beat >>> ts3.getOffsetFromBeat(1) 0.0 >>> ts3.getOffsetFromBeat(2) 1.5 >>> ts3.getOffsetFromBeat(1.66) 1.0 >>> ts3.getOffsetFromBeat(2.5) 2.0
Let’s try this on a real piece, a 4/4 chorale with a one beat pickup. Here we get the normal offset from the active TimeSignature but we subtract out the pickup length which is in a Measure‘s
paddingLeft
property.>>> c = corpus.parse('bwv1.6') >>> for m in c.parts[0].getElementsByClass('Measure'): ... print("%s %s" % (m.number, m.getContextByClass('TimeSignature').getOffsetFromBeat(4.5) - m.paddingLeft)) 0 0.5 1 3.5 2 3.5 ...
-
TimeSignature.
load
(value, partitionRequest=None)¶ Loading a meter destroys all internal representations
-
TimeSignature.
loadRatio
(numerator, denominator, partitionRequest=None)¶ Change the numerator and denominator for a given partition.
-
TimeSignature.
quarteroffsetToBeat
(currentQtrPosition=0)¶ For backward compatibility. Ultimately, remove.
-
TimeSignature.
ratioEqual
(other)¶ A basic form of comparison; does not determine if any internatl structures are equal; only outermost ratio.
-
TimeSignature.
resetValues
(value='4/4', partitionRequest=None)¶ reset all values according to a new value and partitionRequest
-
TimeSignature.
setAccentWeight
(weightList, level=0)¶ Set accent weight, or floating point scalars, for the accent MeterSequence. Provide a list of values; if this list is shorter than the length of the MeterSequence, it will be looped; if this list is longer, only the first relevant value will be used.
If the accent MeterSequence is subdivided, the level of depth to set is given by the optional level argument.
>>> a = meter.TimeSignature('4/4', 4) >>> len(a.accentSequence) 4 >>> a.setAccentWeight([.8, .2]) >>> a.getAccentWeight(0) 0.8... >>> a.getAccentWeight(.5) 0.8... >>> a.getAccentWeight(1) 0.2... >>> a.getAccentWeight(2.5) 0.8... >>> a.getAccentWeight(3.5) 0.2...
-
TimeSignature.
setDisplay
(value, partitionRequest=None)¶ Set an independent display value for a meter.
>>> a = meter.TimeSignature() >>> a.load('3/4') >>> a.setDisplay('2/8+2/8+2/8') >>> a.displaySequence <MeterSequence {2/8+2/8+2/8}> >>> a.beamSequence <MeterSequence {{1/8+1/8}+{1/8+1/8}+{1/8+1/8}}> >>> a.beatSequence # a single top-level partition is default for beat <MeterSequence {{1/8+1/8}+{1/8+1/8}+{1/8+1/8}}> >>> a.setDisplay('3/4') >>> a.displaySequence <MeterSequence {3/4}>
Methods inherited from Music21Object
:
TimeSignature
instance variables
-
TimeSignature.
accentSequence
¶ A
MeterSequence
governing accent partitioning.
-
TimeSignature.
beamSequence
¶ A
MeterSequence
governing automatic beaming.
-
TimeSignature.
beatSequence
¶ A
MeterSequence
governing beat partitioning.
-
TimeSignature.
displaySequence
¶ A
MeterSequence
governing the display of the TimeSignature.
-
TimeSignature.
symbol
¶ A string representation of how to display the TimeSignature. can be “common”, “cut”, “single-number” (i.e., no denominator), or “normal” or “”.
-
TimeSignature.
symbolizeDenominator
¶ If set to True (default is False) then the denominator will be displayed as a symbol rather than a number. Hindemith uses this in his scores. Finale and other MusicXML readers do not support this so don’t expect proper output yet.
Instance variables inherited from Music21Object
:
CompoundTimeSignature¶
-
class
music21.meter.
CompoundTimeSignature
(value=None, partitionRequest=None)¶
CompoundTimeSignature
bases
CompoundTimeSignature
read-only properties
Read-only properties inherited from TimeSignature
:
Read-only properties inherited from Music21Object
:
CompoundTimeSignature
read/write properties
Read/write properties inherited from TimeSignature
:
Read/write properties inherited from Music21Object
:
CompoundTimeSignature
methods
Methods inherited from TimeSignature
:
Methods inherited from Music21Object
:
CompoundTimeSignature
instance variables
Instance variables inherited from TimeSignature
:
Instance variables inherited from Music21Object
:
DurationDenominatorTimeSignature¶
-
class
music21.meter.
DurationDenominatorTimeSignature
(value=None, partitionRequest=None)¶ If you have played Hindemith you know these, 3/(dot-quarter) etc.
DurationDenominatorTimeSignature
bases
DurationDenominatorTimeSignature
read-only properties
Read-only properties inherited from TimeSignature
:
Read-only properties inherited from Music21Object
:
DurationDenominatorTimeSignature
read/write properties
Read/write properties inherited from TimeSignature
:
Read/write properties inherited from Music21Object
:
DurationDenominatorTimeSignature
methods
Methods inherited from TimeSignature
:
Methods inherited from Music21Object
:
DurationDenominatorTimeSignature
instance variables
Instance variables inherited from TimeSignature
:
Instance variables inherited from Music21Object
:
MeterSequence¶
-
class
music21.meter.
MeterSequence
(value=None, partitionRequest=None)¶ A meter sequence is a list of MeterTerminals, or other MeterSequences
MeterSequence
bases
MeterSequence
read-only properties
-
MeterSequence.
denominator
¶
-
MeterSequence.
depth
¶ Return how many unique levels deep this part is This should be optimized to store values unless the structure has changed.
-
MeterSequence.
flat
¶ Return a new MeterSequence composed of the flattend representation.
>>> a = meter.MeterSequence('3/4', 3) >>> b = a.flat >>> len(b) 3
>>> a[1] = a[1].subdivide(4) >>> b = a.flat >>> len(b) 6
>>> a[1][2] = a[1][2].subdivide(4) >>> a <MeterSequence {1/4+{1/16+1/16+{1/64+1/64+1/64+1/64}+1/16}+1/4}> >>> b = a.flat >>> len(b) 9
-
MeterSequence.
flatWeight
¶ Return a list of flat weight valuess
-
MeterSequence.
numerator
¶
-
MeterSequence.
partitionStr
¶ Return the number of top-level partitions in this MeterSequence as a string.
>>> ms = meter.MeterSequence('2/4+2/4') >>> ms <MeterSequence {2/4+2/4}> >>> ms.partitionStr 'Duple'
>>> ms = meter.MeterSequence('6/4', 6) >>> ms <MeterSequence {1/4+1/4+1/4+1/4+1/4+1/4}> >>> ms.partitionStr 'Sextuple'
>>> ms = meter.MeterSequence('6/4', 2) >>> ms.partitionStr 'Duple'
>>> ms = meter.MeterSequence('6/4', 3) >>> ms.partitionStr 'Triple'
MeterSequence
read/write properties
-
MeterSequence.
weight
¶ >>> a = meter.MeterSequence('3/4') >>> a.partition(3) >>> a.weight = 1 >>> a[0].weight 0.333... >>> b = meter.MeterTerminal('1/4', .25) >>> c = meter.MeterTerminal('1/4', .25) >>> d = meter.MeterSequence([b, c]) >>> d.weight 0.5
Read/write properties inherited from MeterTerminal
:
MeterSequence
methods
-
MeterSequence.
getLevel
(level=0, flat=True)¶ Return a complete MeterSequence with the same numerator/denominator reationship but that represents any partitions found at the rquested level. A sort of flatness with variable depth.
>>> b = meter.MeterSequence('4/4', 4) >>> b[1] = b[1].subdivide(2) >>> b[3] = b[3].subdivide(2) >>> b[3][0] = b[3][0].subdivide(2) >>> b <MeterSequence {1/4+{1/8+1/8}+1/4+{{1/16+1/16}+1/8}}> >>> b.getLevel(0) <MeterSequence {1/4+1/4+1/4+1/4}> >>> b.getLevel(1) <MeterSequence {1/4+1/8+1/8+1/4+1/8+1/8}> >>> b.getLevel(2) <MeterSequence {1/4+1/8+1/8+1/4+1/16+1/16+1/8}>
-
MeterSequence.
getLevelSpan
(level=0)¶ For a given level, return the time span of each terminal or sequnece
>>> b = meter.MeterSequence('4/4', 4) >>> b[1] = b[1].subdivide(2) >>> b[3] = b[3].subdivide(2) >>> b[3][0] = b[3][0].subdivide(2) >>> b <MeterSequence {1/4+{1/8+1/8}+1/4+{{1/16+1/16}+1/8}}> >>> b.getLevelSpan(0) [(0.0, 1.0), (1.0, 2.0), (2.0, 3.0), (3.0, 4.0)] >>> b.getLevelSpan(1) [(0.0, 1.0), (1.0, 1.5), (1.5, 2.0), (2.0, 3.0), (3.0, 3.5), (3.5, 4.0)] >>> b.getLevelSpan(2) [(0.0, 1.0), (1.0, 1.5), (1.5, 2.0), (2.0, 3.0), (3.0, 3.25), (3.25, 3.5), (3.5, 4.0)]
-
MeterSequence.
getLevelWeight
(level=0)¶ The weightList is an array of weights found in the components. The MeterSequence has a ._weight attribute, but it is not used here
>>> a = meter.MeterSequence('4/4', 4) >>> a.getLevelWeight() [0.25, 0.25, 0.25, 0.25]
>>> b = meter.MeterSequence('4/4', 4) >>> b.getLevelWeight(0) [0.25, 0.25, 0.25, 0.25]
>>> b[1] = b[1].subdivide(2) >>> b[3] = b[3].subdivide(2) >>> b.getLevelWeight(0) [0.25, 0.25, 0.25, 0.25]
>>> b[3][0] = b[3][0].subdivide(2) >>> b <MeterSequence {1/4+{1/8+1/8}+1/4+{{1/16+1/16}+1/8}}> >>> b.getLevelWeight(0) [0.25, 0.25, 0.25, 0.25] >>> b.getLevelWeight(1) [0.25, 0.125, 0.125, 0.25, 0.125, 0.125] >>> b.getLevelWeight(2) [0.25, 0.125, 0.125, 0.25, 0.0625, 0.0625, 0.125]
-
MeterSequence.
isUniformPartition
(depth=0)¶ Return True if the top-level partitions have equal durations
>>> ms = meter.MeterSequence('3/8+2/8+3/4') >>> ms.isUniformPartition() False >>> ms = meter.MeterSequence('4/4') >>> ms.isUniformPartition() True >>> ms = meter.MeterSequence('2/4+2/4') >>> ms.isUniformPartition() True
>>> ms = meter.MeterSequence('5/8', 5) >>> ms.isUniformPartition() True >>> ms.partition(2) >>> ms.isUniformPartition() False
-
MeterSequence.
load
(value, partitionRequest=None, autoWeight=False, targetWeight=None)¶ This method is called when a MeterSequence is created, or if a MeterSequence is re-set.
User can enter a list of values or an abbreviated slash notation.
autoWeight, if True, will attempt to set weights. tragetWeight, if given, will be used instead of self.weight
loading is a destructive operation.
>>> a = meter.MeterSequence() >>> a.load('4/4', 4) >>> str(a) '{1/4+1/4+1/4+1/4}'
>>> a.load('4/4', 2) # request 2 beats >>> str(a) '{1/2+1/2}'
>>> a.load('5/8', 2) # request 2 beats >>> str(a) '{2/8+3/8}'
>>> a.load('5/8+4/4') >>> str(a) '{5/8+4/4}'
-
MeterSequence.
offsetToAddress
(qLenPos, includeCoincidentBoundaries=False)¶ Give a list of values that show all indices necessary to access the exact terminal at a given qLenPos.
The len of the returned list also provides the depth at the specified qLen.
>>> a = meter.MeterSequence('3/4', 3) >>> a[1] = a[1].subdivide(4) >>> a <MeterSequence {1/4+{1/16+1/16+1/16+1/16}+1/4}> >>> len(a) 3 >>> a.offsetToAddress(.5) [0] >>> a[0] <MeterTerminal 1/4> >>> a.offsetToAddress(1.0) [1, 0] >>> a.offsetToAddress(1.5) [1, 2] >>> a[1][2] <MeterTerminal 1/16> >>> a.offsetToAddress(1.99) [1, 3] >>> a.offsetToAddress(2.5) [2]
-
MeterSequence.
offsetToDepth
(qLenPos, align='quantize')¶ Given a qLenPos, return the maximum available depth at this position
>>> b = meter.MeterSequence('4/4', 4) >>> b[1] = b[1].subdivide(2) >>> b[3] = b[3].subdivide(2) >>> b[3][0] = b[3][0].subdivide(2) >>> b <MeterSequence {1/4+{1/8+1/8}+1/4+{{1/16+1/16}+1/8}}> >>> b.offsetToDepth(0) 3 >>> b.offsetToDepth(0.25) # quantizing active by default 3 >>> b.offsetToDepth(1) 3 >>> b.offsetToDepth(1.5) 2
>>> b.offsetToDepth(-1) Traceback (most recent call last): MeterException: cannot access from qLenPos -1.0
-
MeterSequence.
offsetToIndex
(qLenPos, includeCoincidentBoundaries=False)¶ Given an offset in quarterLengths (0.0 through self.duration.quarterLength), return the index of the active MeterTerminal or MeterSequence
>>> a = meter.MeterSequence('4/4') >>> a.offsetToIndex(.5) 0 >>> a.offsetToIndex(3.5) 0 >>> a.partition(4) >>> a.offsetToIndex(0.5) 0 >>> a.offsetToIndex(3.5) 3
>>> a.partition([1,2,1]) >>> len(a) 3 >>> a.offsetToIndex(2.9) 1 >>> a[a.offsetToIndex(2.9)] <MeterTerminal 2/4>
>>> a = meter.MeterSequence('4/4') >>> a.offsetToIndex(5.0) Traceback (most recent call last): MeterException: cannot access from qLenPos 5.0 where total duration is 4.0
Negative numbers also raise an exception:
>>> a.offsetToIndex(-0.5) Traceback (most recent call last): MeterException: cannot access from qLenPos -0.5 where total duration is 4.0
-
MeterSequence.
offsetToSpan
(qLenPos, permitMeterModulus=False)¶ Given a qLenPos, return the span of the active region. Only applies to the top most level of partitions
If permitMeterModulus is True, quarter length positions greater than the duration of the Meter will be accepted as the modulus of the total meter duration.
>>> a = meter.MeterSequence('3/4', 3) >>> a.offsetToSpan(.5) (0, 1.0) >>> a.offsetToSpan(1.5) (1.0, 2.0)
This is the same as 1.5:
>>> a.offsetToSpan(4.5, permitMeterModulus=True) (1.0, 2.0)
Make sure it works for tuplets even with so-so rounding:
>>> a.offsetToSpan(4.33333336, permitMeterModulus=True) (1.0, 2.0)
-
MeterSequence.
offsetToWeight
(qLenPos)¶ Given a lenPos, return the weight of the active region. Only applies to the top-most level of partitions
>>> a = meter.MeterSequence('3/4', 3) >>> a.offsetToWeight(0.0) Fraction(1, 3) >>> a.offsetToWeight(1.5) Fraction(1, 3)
??? Not sure what this does...
-
MeterSequence.
partition
(value)¶ Partitioning creates and sets a number of MeterTerminals that make up this MeterSequence.
A simple way to partition based on argument time. Single integers are treated as beat counts; lists are treated as numerator lists; MeterSequence objects are partitioned by calling partitionByOtherMeterSequence().
>>> a = meter.MeterSequence('5/4+3/8') >>> len(a) 2 >>> str(a) '{5/4+3/8}'
>>> b = meter.MeterSequence('13/8') >>> len(b) 1 >>> str(b) '{13/8}' >>> b.partition(13) >>> len(b) 13 >>> str(b) '{1/8+1/8+1/8+...+1/8}'
>>> a.partition(b) >>> len(a) 13 >>> str(a) '{1/8+1/8+1/8+...+1/8}'
-
MeterSequence.
partitionByCount
(countRequest, loadDefault=True)¶ Divide the current MeterSequence into the requested number of parts.
If it is not possible to divide it into the requested number, and loadDefault is True, then give the default partition:
This will destroy any established structure in the stored partition.
>>> a = meter.MeterSequence('4/4') >>> a.partitionByCount(2) >>> str(a) '{1/2+1/2}' >>> a.partitionByCount(4) >>> str(a) '{1/4+1/4+1/4+1/4}'
The partitions are not guaranteed to be the same length if the meter is irregular:
>>> b = meter.MeterSequence('5/8') >>> b.partitionByCount(2) >>> str(b) '{2/8+3/8}'
This relies on a pre-defined exemption for partitioning 5 by 3:
>>> b.partitionByCount(3) >>> str(b) '{2/8+2/8+1/8}'
Here we use loadDefault = True to get the default:
>>> a = meter.MeterSequence('5/8') >>> a.partitionByCount(11) >>> str(a) '{2/8+3/8}'
If loadDefault is False then an error is raised:
>>> a.partitionByCount(11, loadDefault = False) Traceback (most recent call last): MeterException: Cannot set partition by 11 (5/8)
-
MeterSequence.
partitionByList
(numeratorList)¶ Given a numerator list, partition MeterSequence into a new list of MeterTerminals
>>> a = meter.MeterSequence('4/4') >>> a.partitionByList([1,1,1,1]) >>> str(a) '{1/4+1/4+1/4+1/4}'
This divides it into two equal parts:
>>> a.partitionByList([1,1]) >>> str(a) '{1/2+1/2}'
And now into one big part:
>>> a.partitionByList([1]) >>> str(a) '{1/1}'
Here we divide 4/4 very unconventionally:
>>> a.partitionByList(['3/4', '1/8', '1/8']) >>> a <MeterSequence {3/4+1/8+1/8}>
But the basics of the MeterSequence must be observed:
>>> a.partitionByList(['3/4', '1/8', '5/8']) Traceback (most recent call last): MeterException: Cannot set partition by ['3/4', '1/8', '5/8']
-
MeterSequence.
partitionByOtherMeterSequence
(other)¶ Set partition to that found in another MeterSequence
>>> a = meter.MeterSequence('4/4', 4) >>> str(a) '{1/4+1/4+1/4+1/4}'
>>> b = meter.MeterSequence('4/4', 2) >>> a.partitionByOtherMeterSequence(b) >>> len(a) 2 >>> str(a) '{1/2+1/2}'
-
MeterSequence.
setLevelWeight
(weightList, level=0)¶ The weightList is an array of weights to be applied to a single level of the MeterSequence.
>>> a = meter.MeterSequence('4/4', 4) >>> a.setLevelWeight([1, 2, 3, 4]) >>> a.getLevelWeight() [1, 2, 3, 4]
>>> b = meter.MeterSequence('4/4', 4) >>> b.setLevelWeight([2, 3]) >>> b.getLevelWeight(0) [2, 3, 2, 3]
>>> b[1] = b[1].subdivide(2) >>> b[3] = b[3].subdivide(2) >>> b.getLevelWeight(0) [2, 3.0, 2, 3.0]
>>> b[3][0] = b[3][0].subdivide(2) >>> b <MeterSequence {1/4+{1/8+1/8}+1/4+{{1/16+1/16}+1/8}}> >>> b.getLevelWeight(0) [2, 3.0, 2, 3.0] >>> b.getLevelWeight(1) [2, 1.5, 1.5, 2, 1.5, 1.5] >>> b.getLevelWeight(2) [2, 1.5, 1.5, 2, 0.75, 0.75, 1.5]
-
MeterSequence.
subdivideNestedHierarchy
(depth, firstPartitionForm=None, normalizeDenominators=True)¶ Create nested structure down to a specified depth; the first division is set to one; the second division may be by 2 or 3; remaining divisions are always by 2.
This a destructive procedure that will remove any existing partition structures.
normalizeDenominators, if True, will reduce all denominators to the same minimum level.
>>> ms = meter.MeterSequence('4/4') >>> ms.subdivideNestedHierarchy(1) >>> ms <MeterSequence {{1/2+1/2}}> >>> ms.subdivideNestedHierarchy(2) >>> ms <MeterSequence {{{1/4+1/4}+{1/4+1/4}}}> >>> ms.subdivideNestedHierarchy(3) >>> ms <MeterSequence {{{{1/8+1/8}+{1/8+1/8}}+{{1/8+1/8}+{1/8+1/8}}}}> >>> ms.subdivideNestedHierarchy(4) >>> ms <MeterSequence {{{{{1/16+1/16}+{1/16+1/16}}+{{1/16+1/16}+{1/16+1/16}}}+{{{1/16+1/16}+{1/16+1/16}}+{{1/16+1/16}+{1/16+1/16}}}}}> >>> ms.subdivideNestedHierarchy(5) >>> ms <MeterSequence {{{{{{1/32+1/32}+{1/32+1/32}}+{{1/32+1/32}+{1/32+1/32}}}+{{{1/32+1/32}+{1/32+1/32}}+{{1/32+1/32}+{1/32+1/32}}}}+{{{{1/32+1/32}+{1/32+1/32}}+{{1/32+1/32}+{1/32+1/32}}}+{{{1/32+1/32}+{1/32+1/32}}+{{1/32+1/32}+{1/32+1/32}}}}}}>
The effects above are not cumulative. Users can skip directly to whatever level of hierarchy they want.
>>> ms2 = meter.MeterSequence('4/4') >>> ms2.subdivideNestedHierarchy(3) >>> ms2 <MeterSequence {{{{1/8+1/8}+{1/8+1/8}}+{{1/8+1/8}+{1/8+1/8}}}}>
-
MeterSequence.
subdividePartitionsEqual
(divisions=None)¶ Subdivide all partitions by equally-spaced divisions, given a divisions value. Manipulates this MeterSequence in place.
Divisions value may optionally be a MeterSequence, from which a top-level partitioning structure is derived.
>>> ms = meter.MeterSequence('2/4') >>> ms.partition(2) >>> ms <MeterSequence {1/4+1/4}> >>> ms.subdividePartitionsEqual(2) >>> ms <MeterSequence {{1/8+1/8}+{1/8+1/8}}> >>> ms[0].subdividePartitionsEqual(2) >>> ms <MeterSequence {{{1/16+1/16}+{1/16+1/16}}+{1/8+1/8}}> >>> ms[1].subdividePartitionsEqual(2) >>> ms <MeterSequence {{{1/16+1/16}+{1/16+1/16}}+{{1/16+1/16}+{1/16+1/16}}}>
>>> ms = meter.MeterSequence('2/4+3/4') >>> ms.subdividePartitionsEqual(None)
Methods inherited from MeterTerminal
:
MeterTerminal¶
-
class
music21.meter.
MeterTerminal
(slashNotation=None, weight=1)¶ A MeterTerminal is a nestable primitive of rhythmic division.
>>> a = meter.MeterTerminal('2/4') >>> a.duration.quarterLength 2.0 >>> a = meter.MeterTerminal('3/8') >>> a.duration.quarterLength 1.5 >>> a = meter.MeterTerminal('5/2') >>> a.duration.quarterLength 10.0
MeterTerminal
bases
MeterTerminal
read-only properties
-
MeterTerminal.
depth
¶ Return how many levels deep this part is. Depth of a terminal is always 1
MeterTerminal
read/write properties
-
MeterTerminal.
denominator
¶
-
MeterTerminal.
duration
¶ duration gets or sets a duration value that is equal in length to the totalLength
>>> a = meter.MeterTerminal() >>> a.numerator = 3 >>> a.denominator = 8 >>> d = a.duration >>> d.type 'quarter' >>> d.dots 1 >>> d.quarterLength 1.5
-
MeterTerminal.
numerator
¶
-
MeterTerminal.
weight
¶
MeterTerminal
methods
-
MeterTerminal.
ratioEqual
(other)¶ Compare the numerator and denominator of another object. Note that these have to be exact matches; 3/4 is not the same as 6/8
>>> from music21 import meter >>> a = meter.MeterTerminal('3/4') >>> b = meter.MeterTerminal('6/4') >>> c = meter.MeterTerminal('2/4') >>> d = meter.MeterTerminal('3/4') >>> a.ratioEqual(b) False >>> a.ratioEqual(c) False >>> a.ratioEqual(d) True
-
MeterTerminal.
subdivide
(value)¶ Subdivision takes a MeterTerminal and, making it into a collection of MeterTerminals, Returns a MeterSequence.
This is different than a partitioning a MeterSequence in that this does not happen in place and instead returns a new object.
If an integer is provided, assume it is a partition count
-
MeterTerminal.
subdivideByCount
(countRequest=None)¶ returns a MeterSequence made up of taking this MeterTerminal and subdividing it into the given number of parts. Each of those parts is a MeterTerminal
>>> a = meter.MeterTerminal('3/4') >>> b = a.subdivideByCount(3) >>> isinstance(b, meter.MeterSequence) True >>> len(b) 3 >>> b[0] <MeterTerminal 1/4>
What happens if we do this?
>>> a = meter.MeterTerminal('5/8') >>> b = a.subdivideByCount(2) >>> isinstance(b, meter.MeterSequence) True >>> len(b) 2 >>> b[0] <MeterTerminal 2/8> >>> b[1] <MeterTerminal 3/8>
But what if you want to divide into 3/8+2/8 or something else? for that, see the
load()
method ofMeterSequence
.
-
MeterTerminal.
subdivideByList
(numeratorList)¶ Return a MeterSequence dividing this MeterTerminal according to the numeratorList
>>> a = meter.MeterTerminal('3/4') >>> b = a.subdivideByList([1,1,1]) >>> len(b) 3 >>> b[0] <MeterTerminal 1/4>
Unequal subdivisions work:
>>> c = a.subdivideByList([1,2]) >>> len(c) 2 >>> (c[0], c[1]) (<MeterTerminal 1/4>, <MeterTerminal 2/4>)
So does subdividing by strings
>>> c = a.subdivideByList(['2/4', '1/4']) >>> len(c) 2 >>> (c[0], c[1]) (<MeterTerminal 2/4>, <MeterTerminal 1/4>)
See
partitionByList()
method ofMeterSequence
for more details.
-
MeterTerminal.
subdivideByOther
(other)¶ Return a MeterSequence based on another MeterSequence
>>> a = meter.MeterSequence('1/4+1/4+1/4') >>> a <MeterSequence {1/4+1/4+1/4}> >>> b = meter.MeterSequence('3/8+3/8') >>> a.subdivideByOther(b) <MeterSequence {{3/8+3/8}}>
MeterTerminalTuple¶
-
class
music21.meter.
MeterTerminalTuple
(numerator, denominator, tempoIndication)¶
MeterTerminalTuple
read-only properties
-
MeterTerminalTuple.
denominator
¶ Alias for field number 1
-
MeterTerminalTuple.
numerator
¶ Alias for field number 0
-
MeterTerminalTuple.
tempoIndication
¶ Alias for field number 2
NonPowerOfTwoTimeSignature¶
-
class
music21.meter.
NonPowerOfTwoTimeSignature
(value=None, partitionRequest=None)¶
NonPowerOfTwoTimeSignature
bases
NonPowerOfTwoTimeSignature
read-only properties
Read-only properties inherited from TimeSignature
:
Read-only properties inherited from Music21Object
:
NonPowerOfTwoTimeSignature
read/write properties
Read/write properties inherited from TimeSignature
:
Read/write properties inherited from Music21Object
:
NonPowerOfTwoTimeSignature
methods
Methods inherited from TimeSignature
:
Methods inherited from Music21Object
:
NonPowerOfTwoTimeSignature
instance variables
Instance variables inherited from TimeSignature
:
Instance variables inherited from Music21Object
: