Timespan Demos

Work in progress...

from music21 import *
luca = corpus.parse('luca/gloria').measures(1,8)
tsCol = luca.asTimespans()
tsCol
 <TimespanTree {189} (0.0 to 24.0) <music21.stream.Score 0x10bf37358>>
for v in tsCol.iterateVerticalities():
    print(v)
 <Verticality 0.0 {F3 F4 C5}>
 <Verticality 3.0 {F3 F4 D5}>
 <Verticality 3.5 {F3 C4 C5}>
 <Verticality 4.5 {F3 C4 A4}>
 <Verticality 5.0 {F3 C4 F4}>
 <Verticality 5.5 {F3 A3 F4}>
 <Verticality 6.0 {F3 F4}>
 <Verticality 6.5 {F3 F4 A4}>
 <Verticality 7.5 {F3 F4 C5}>
 <Verticality 8.5 {F3 F4 C5}>
 <Verticality 9.0 {C4 E4 G4}>
 <Verticality 10.5 {D4 F4 A4}>
 <Verticality 12.0 {C4 E4 G4}>
 <Verticality 15.0 {G3 G4 D5}>
 <Verticality 16.5 {A3 E4 C5}>
 <Verticality 17.5 {A3 E4 B4}>
 <Verticality 18.0 {D4 F4 A4}>
 <Verticality 18.5 {D4 F4 G4}>
 <Verticality 19.0 {D4 F4}>
 <Verticality 19.5 {C4 E4 G4}>
 <Verticality 20.0 {C4 F4 G4}>
 <Verticality 20.5 {C4 D4 G4}>
 <Verticality 21.0 {C4 E4}>
 <Verticality 21.5 {A3 E4}>
 <Verticality 22.0 {A3 C4 F4}>
 <Verticality 22.5 {B-3 D4 F4}>
 <Verticality 23.0 {G3 B-3 D4}>
 <Verticality 23.5 {B-3 D4 F4}>
v4 = list(tsCol.iterateVerticalities())[4]
v4
 <Verticality 5.0 {F3 C4 F4}>
v4.pitchSet
 {<music21.pitch.Pitch F3>, <music21.pitch.Pitch C4>, <music21.pitch.Pitch F4>}
f = sorted(v4.pitchSet)[0]
f
 <music21.pitch.Pitch F3>
v4.startTimespans
 (<PitchedTimespan (5.0 to 6.0) <music21.note.Note F>>,)
v4.stopTimespans
 (<PitchedTimespan (4.5 to 5.0) <music21.note.Note A>>,)
v4.overlapTimespans
 (<PitchedTimespan (3.0 to 6.0) <music21.note.Note F>>,
  <PitchedTimespan (4.5 to 5.5) <music21.note.Note C>>)
v35 = tsCol.getVerticalityAt(3.5)
v35
 <Verticality 3.5 {F3 C4 C5}>
v35.startTimespans
 (<PitchedTimespan (3.5 to 4.5) <music21.note.Note C>>,
  <PitchedTimespan (3.5 to 4.5) <music21.note.Note C>>)
v35.stopTimespans
 (<PitchedTimespan (3.0 to 3.5) <music21.note.Note D>>,
  <PitchedTimespan (3.0 to 3.5) <music21.note.Note F>>)
v35.overlapTimespans
 (<PitchedTimespan (3.0 to 6.0) <music21.note.Note F>>,)
elTsC = v35.startTimespans[0]
elTsC, elTsC.element
 (<PitchedTimespan (3.5 to 4.5) <music21.note.Note C>>, <music21.note.Note C>)

Test previousVerticality with Rest

v22 = tsCol.getVerticalityAt(22.0)
v22
 <Verticality 22.0 {A3 C4 F4}>
v22.startTimespans
 (<PitchedTimespan (22.0 to 22.5) <music21.note.Note C>>,
  <PitchedTimespan (22.0 to 23.0) <music21.note.Note F>>)
elTSfollowingRest = v22.startTimespans[1]
elTSfollowingRest
 <PitchedTimespan (22.0 to 23.0) <music21.note.Note F>>
v22.stopTimespans
 (<PitchedTimespan (21.0 to 22.0) <music21.note.Note E>>,
  <PitchedTimespan (21.5 to 22.0) <music21.note.Rest rest>>)
elTSfollowingRest.part
 <music21.stream.Part Cantus>
score = tree.makeExampleScore()
score.show()
../_images/usersGuide_97_timespans_29_0.png
tsColSmall = score.asTimespans()
for v in tsColSmall.iterateVerticalities():
    if v != []:
        print(v)
        print(v.getAllVoiceLeadingQuartets())
 <Verticality 0.0 {C3 C#3}>
 []
 <Verticality 1.0 {C#3 D3}>
---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

<ipython-input-30-f77717ce7edf> in <module>()
      2     if v != []:
      3         print(v)
----> 4         print(v.getAllVoiceLeadingQuartets())
      5


/Users/cuthbert/git/music21base/music21/tree/verticality.py in getAllVoiceLeadingQuartets(self, includeRests, includeOblique, includeNoMotion, returnObjects, partPairNumbers)
    670                             and n21 is not None
    671                             and n22 is not None):
--> 672                         vlq = VoiceLeadingQuartet(n11, n12, n21, n22)
    673                         filteredList.append(vlq)
    674


/Users/cuthbert/git/music21base/music21/voiceLeading.py in __init__(self, v1n1, v1n2, v2n1, v2n2, analyticKey)
    115             self.key = analyticKey
    116         if v1n1 is not None and v1n2 is not None and v2n1 is not None and v2n2 is not None:
--> 117             self._findIntervals()
    118
    119     def __repr__(self):


/Users/cuthbert/git/music21base/music21/voiceLeading.py in _findIntervals(self)
    233
    234     def _findIntervals(self):
--> 235         self.vIntervals.append(interval.notesToInterval(self.v1n1, self.v2n1))
    236         self.vIntervals.append(interval.notesToInterval(self.v1n2, self.v2n2))
    237         self.hIntervals.append(interval.notesToInterval(self.v1n1, self.v1n2))


/Users/cuthbert/git/music21base/music21/interval.py in notesToInterval(n1, n2)
   2533             from music21 import pitch
   2534             n2 = pitch.Pitch()
-> 2535     gInt = notesToGeneric(n1, n2)
   2536     cInt = notesToChromatic(n1, n2)
   2537     intObj = intervalFromGenericAndChromatic(gInt, cInt)


/Users/cuthbert/git/music21base/music21/interval.py in notesToGeneric(n1, n2)
   1466
   1467     '''
-> 1468     staffDist = n2.diatonicNoteNum - n1.diatonicNoteNum
   1469     genDist = convertStaffDistanceToInterval(staffDist)
   1470     return GenericInterval(genDist)


AttributeError: 'NoneType' object has no attribute 'diatonicNoteNum'
lucaAll = corpus.parse('luca/gloria')
tsCol = lucaAll.asTimespans()
for v in tsCol.iterateVerticalities():
    vlqs = v.getAllVoiceLeadingQuartets()
---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

<ipython-input-32-76b643c51e81> in <module>()
      1 for v in tsCol.iterateVerticalities():
----> 2     vlqs = v.getAllVoiceLeadingQuartets()


/Users/cuthbert/git/music21base/music21/tree/verticality.py in getAllVoiceLeadingQuartets(self, includeRests, includeOblique, includeNoMotion, returnObjects, partPairNumbers)
    670                             and n21 is not None
    671                             and n22 is not None):
--> 672                         vlq = VoiceLeadingQuartet(n11, n12, n21, n22)
    673                         filteredList.append(vlq)
    674


/Users/cuthbert/git/music21base/music21/voiceLeading.py in __init__(self, v1n1, v1n2, v2n1, v2n2, analyticKey)
    115             self.key = analyticKey
    116         if v1n1 is not None and v1n2 is not None and v2n1 is not None and v2n2 is not None:
--> 117             self._findIntervals()
    118
    119     def __repr__(self):


/Users/cuthbert/git/music21base/music21/voiceLeading.py in _findIntervals(self)
    233
    234     def _findIntervals(self):
--> 235         self.vIntervals.append(interval.notesToInterval(self.v1n1, self.v2n1))
    236         self.vIntervals.append(interval.notesToInterval(self.v1n2, self.v2n2))
    237         self.hIntervals.append(interval.notesToInterval(self.v1n1, self.v1n2))


/Users/cuthbert/git/music21base/music21/interval.py in notesToInterval(n1, n2)
   2533             from music21 import pitch
   2534             n2 = pitch.Pitch()
-> 2535     gInt = notesToGeneric(n1, n2)
   2536     cInt = notesToChromatic(n1, n2)
   2537     intObj = intervalFromGenericAndChromatic(gInt, cInt)


/Users/cuthbert/git/music21base/music21/interval.py in notesToGeneric(n1, n2)
   1466
   1467     '''
-> 1468     staffDist = n2.diatonicNoteNum - n1.diatonicNoteNum
   1469     genDist = convertStaffDistanceToInterval(staffDist)
   1470     return GenericInterval(genDist)


AttributeError: 'NoneType' object has no attribute 'diatonicNoteNum'
bach = corpus.parse('bwv66.6')
import time
t = time.time()
dummy = alpha.theoryAnalysis.theoryAnalyzer.getVLQs(bach, 0, 1) # two parts only of bach
print(time.time() - t)
 0.13318204879760742
t = time.time()
tsCol = bach.asTimespans()
for v in tsCol.iterateVerticalities():
    vlqs = v.getAllVoiceLeadingQuartets()
print(time.time() - t)  # all parts == 6 pairs
---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

<ipython-input-35-c7589ac93393> in <module>()
      2 tsCol = bach.asTimespans()
      3 for v in tsCol.iterateVerticalities():
----> 4     vlqs = v.getAllVoiceLeadingQuartets()
      5 print(time.time() - t)  # all parts == 6 pairs


/Users/cuthbert/git/music21base/music21/tree/verticality.py in getAllVoiceLeadingQuartets(self, includeRests, includeOblique, includeNoMotion, returnObjects, partPairNumbers)
    670                             and n21 is not None
    671                             and n22 is not None):
--> 672                         vlq = VoiceLeadingQuartet(n11, n12, n21, n22)
    673                         filteredList.append(vlq)
    674


/Users/cuthbert/git/music21base/music21/voiceLeading.py in __init__(self, v1n1, v1n2, v2n1, v2n2, analyticKey)
    115             self.key = analyticKey
    116         if v1n1 is not None and v1n2 is not None and v2n1 is not None and v2n2 is not None:
--> 117             self._findIntervals()
    118
    119     def __repr__(self):


/Users/cuthbert/git/music21base/music21/voiceLeading.py in _findIntervals(self)
    233
    234     def _findIntervals(self):
--> 235         self.vIntervals.append(interval.notesToInterval(self.v1n1, self.v2n1))
    236         self.vIntervals.append(interval.notesToInterval(self.v1n2, self.v2n2))
    237         self.hIntervals.append(interval.notesToInterval(self.v1n1, self.v1n2))


/Users/cuthbert/git/music21base/music21/interval.py in notesToInterval(n1, n2)
   2533             from music21 import pitch
   2534             n2 = pitch.Pitch()
-> 2535     gInt = notesToGeneric(n1, n2)
   2536     cInt = notesToChromatic(n1, n2)
   2537     intObj = intervalFromGenericAndChromatic(gInt, cInt)


/Users/cuthbert/git/music21base/music21/interval.py in notesToGeneric(n1, n2)
   1466
   1467     '''
-> 1468     staffDist = n2.diatonicNoteNum - n1.diatonicNoteNum
   1469     genDist = convertStaffDistanceToInterval(staffDist)
   1470     return GenericInterval(genDist)


AttributeError: 'NoneType' object has no attribute 'diatonicNoteNum'
meterCol = lucaAll.parts[0].asTimespans(classList=(meter.TimeSignature,))
meterCol
 <TimespanTree {4} (0.0 to 275.0) <music21.stream.Part Cantus>>
print(meterCol)
 <TimespanTree {4} (0.0 to 275.0) <music21.stream.Part Cantus>>
     <PitchedTimespan (0.0 to 0.0) <music21.meter.TimeSignature 6/8>>
     <PitchedTimespan (81.0 to 81.0) <music21.meter.TimeSignature 2/4>>
     <PitchedTimespan (185.0 to 185.0) <music21.meter.TimeSignature 6/8>>
     <PitchedTimespan (275.0 to 275.0) <music21.meter.TimeSignature 3/4>>
c = corpus.parse('reel')
c.measures(0, 3).show()
../_images/usersGuide_97_timespans_40_0.png
c.measures(0, 6).show('braille')
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠩⠩⠩⠼⠃⠲⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠼⠚⠀⠐⠊⠮⠉⠽⠯⠐⠊⠙⠋⠀⠮⠨⠽⠯⠮⠙⠾⠉⠮⠀⠿⠊⠋⠊⠨⠽⠋⠊⠛
⠀⠀⠨⠯⠙⠚⠊⠿⠊⠋⠙⠀⠊⠐⠮⠉⠽⠯⠐⠊⠙⠋⠀⠮⠨⠽⠯⠮⠙⠾⠉⠮
⠀⠀⠨⠿⠊⠋⠊⠨⠽⠋⠛⠋