Table Of Contents

Previous topic

music21.stream

Next topic

music21.tinyNotation

music21.tempo

This module defines objects for describing tempo and changes in tempo.

music21.tempo.interpolateElements(element1, element2, sourceStream, destinationStream, autoAdd=True)

Assume that element1 and element2 are two elements in sourceStream and destinationStream with other elements (say eA, eB, eC) between them. For instance, element1 could be the downbeat at offset 10 in sourceStream (a Stream representing a score) and offset 20.5 in destinationStream (which might be a Stream representing the timing of notes in particular recording at approximately but not exactly qtr = 30). Element2 could be the following downbeat in 4/4, at offset 14 in source but offset 25.0 in the recording:

>>> from music21 import *
>>> sourceStream = stream.Stream()
>>> destinationStream = stream.Stream()
>>> element1 = note.QuarterNote("C4")
>>> element2 = note.QuarterNote("G4")
>>> sourceStream.insert(10, element1)
>>> destinationStream.insert(20.5, element1)
>>> sourceStream.insert(14, element2)
>>> destinationStream.insert(25.0, element2)

Suppose eA, eB, and eC are three quarter notes that lie between element1 and element2 in sourceStream and destinationStream, as in:

>>> eA = note.QuarterNote("D4")
>>> eB = note.QuarterNote("E4")
>>> eC = note.QuarterNote("F4")
>>> sourceStream.insert(11, eA)
>>> sourceStream.insert(12, eB)
>>> sourceStream.insert(13, eC)
>>> destinationStream.append([eA, eB, eC])  # not needed if autoAdd were true

then running this function will cause eA, eB, and eC to have offsets 21.625, 22.75, and 23.875 respectively in destinationStream:

>>> tempo.interpolateElements(element1, element2, sourceStream, destinationStream, autoAdd = False)
>>> for el in [eA, eB, eC]:
...    print el.getOffsetBySite(destinationStream)
21.625
22.75
23.875

if the elements between element1 and element2 do not yet appear in destinationStream, they are automatically added unless autoAdd is False.

(with the default autoAdd, elements are automatically added to new streams):

>>> destStream2 = stream.Stream()
>>> destStream2.insert(10.1, element1)
>>> destStream2.insert(50.5, element2)
>>> tempo.interpolateElements(element1, element2, sourceStream, destStream2)
>>> for el in [eA, eB, eC]:
...    print el.getOffsetBySite(destStream2)
20.2
30.3
40.4

(unless autoAdd is set to false, in which case a Tempo Exception arises...)

>>> destStream3 = stream.Stream()
>>> destStream3.insert(100, element1)
>>> destStream3.insert(500, element2)
>>> tempo.interpolateElements(element1, element2, sourceStream, destStream3, autoAdd = False)
...
TempoException: Could not find element <music21.note.Note D> with id ...

TempoMark

Inherits from: Music21Object, JSONSerializer

class music21.tempo.TempoMark(value=None)
>>> import music21
>>> tm = music21.tempo.TempoMark("adagio")
>>> tm.value
'adagio'

Common marks such as “adagio,” “moderato,” “molto allegro,” etc. get sensible default values. If not found, uses a default of 90:

>>> tm.number
52
>>> tm2 = music21.tempo.TempoMark(u"très vite")
>>> tm2.value.endswith('vite')
True
>>> tm2.value == u'très vite'   # TODO: Make sure is working again....
True
>>> tm3 = music21.tempo.TempoMark("extremely, wicked fast!")
>>> tm3.number
90

TempoMark attributes

classSortOrder

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

>>> from music21 import *
>>> 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

Attributes without Documentation: number, value

Attributes inherited from Music21Object: id, groups

TempoMark properties

Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, duration, measureNumberLocal, offset, priority

Properties inherited from JSONSerializer: json

TempoMark methods

Methods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()

MetronomeMark

Inherits from: TempoMark, Music21Object, JSONSerializer

class music21.tempo.MetronomeMark(number=60, referent=None, value=None)

A way of specifying only a particular tempo and referent and (optionally) a text description

>>> from music21 import *
>>> a = tempo.MetronomeMark(40, note.HalfNote(), "slow")
>>> a.number
40
>>> a.referent
<music21.duration.Duration 2.0>
>>> a.referent.type
'half'
>>> a.value
'slow'

MetronomeMark attributes

Attributes without Documentation: referent

Attributes inherited from TempoMark: classSortOrder, number, value

Attributes inherited from Music21Object: id, groups

MetronomeMark properties

Properties inherited from Music21Object: activeSite, beat, beatDuration, beatStr, beatStrength, classes, duration, measureNumberLocal, offset, priority

Properties inherited from JSONSerializer: json

MetronomeMark methods

Methods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndActiveSite(), freezeIds(), getAllContextsByClass(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), getSpannerSites(), hasContext(), mergeAttributes(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()

Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()