This module defines objects for describing tempo and changes in tempo.
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)
If eA, eB, and eC are three quarter notes between element1 and element2 in sourceStream and destinationStream:
>>> 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 with autoAdd
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 ...
Inherits from: Music21Object, JSONSerializer
>>> tm = TempoMark("adagio")
>>> tm.value
'adagio'
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 5Attributes without Documentation: value
Attributes inherited from Music21Object: id, groups
TempoMark properties
Properties inherited from Music21Object: beat, beatDuration, beatStr, beatStrength, classes, duration, measureNumberLocal, offset, parent, priority
Properties inherited from JSONSerializer: json
TempoMark methods
Methods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndParent(), freezeIds(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), hasContext(), isClass(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()
Inherits from: TempoMark, Music21Object, JSONSerializer
>>> a = MetronomeMark(40)
>>> a.number
40
MetronomeMark attributes
Attributes without Documentation: number, referent
Attributes inherited from TempoMark: classSortOrder, value
Attributes inherited from Music21Object: id, groups
MetronomeMark properties
Properties inherited from Music21Object: beat, beatDuration, beatStr, beatStrength, classes, duration, measureNumberLocal, offset, parent, priority
Properties inherited from JSONSerializer: json
MetronomeMark methods
Methods inherited from Music21Object: searchParentByAttr(), getContextAttr(), setContextAttr(), addContext(), addLocation(), addLocationAndParent(), freezeIds(), getContextByClass(), getOffsetBySite(), getSiteIds(), getSites(), hasContext(), isClass(), purgeLocations(), removeLocationBySite(), removeLocationBySiteId(), setOffsetBySite(), show(), splitAtDurations(), splitAtQuarterLength(), splitByQuarterLengths(), unfreezeIds(), unwrapWeakref(), wrapWeakref(), write()
Methods inherited from JSONSerializer: jsonAttributes(), jsonComponentFactory(), jsonPrint(), jsonRead(), jsonWrite()