.. _usersGuide_97_timespans:

.. WARNING: DO NOT EDIT THIS FILE:
   AUTOMATICALLY GENERATED.
   PLEASE EDIT THE .py FILE DIRECTLY.


Timespan Demos
==============

Work in progress...


.. code:: python

    from music21 import *

.. code:: python

    luca = corpus.parse('luca/gloria').measures(1,8)

.. code:: python

    tsCol = luca.asTimespans()

.. code:: python

    tsCol




.. parsed-literal::
   :class: ipython-result

    <TimespanTree {189} (0.0 to 24.0) <music21.stream.Score 0x10bf37358>>



.. code:: python

    for v in tsCol.iterateVerticalities():
        print(v)


.. parsed-literal::
   :class: ipython-result

    <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}>


.. code:: python

    v4 = list(tsCol.iterateVerticalities())[4]

.. code:: python

    v4




.. parsed-literal::
   :class: ipython-result

    <Verticality 5.0 {F3 C4 F4}>



.. code:: python

    v4.pitchSet




.. parsed-literal::
   :class: ipython-result

    {<music21.pitch.Pitch F3>, <music21.pitch.Pitch C4>, <music21.pitch.Pitch F4>}



.. code:: python

    f = sorted(v4.pitchSet)[0]

.. code:: python

    f




.. parsed-literal::
   :class: ipython-result

    <music21.pitch.Pitch F3>



.. code:: python

    v4.startTimespans




.. parsed-literal::
   :class: ipython-result

    (<PitchedTimespan (5.0 to 6.0) <music21.note.Note F>>,)



.. code:: python

    v4.stopTimespans




.. parsed-literal::
   :class: ipython-result

    (<PitchedTimespan (4.5 to 5.0) <music21.note.Note A>>,)



.. code:: python

    v4.overlapTimespans




.. parsed-literal::
   :class: ipython-result

    (<PitchedTimespan (3.0 to 6.0) <music21.note.Note F>>,
     <PitchedTimespan (4.5 to 5.5) <music21.note.Note C>>)



.. code:: python

    v35 = tsCol.getVerticalityAt(3.5)

.. code:: python

    v35




.. parsed-literal::
   :class: ipython-result

    <Verticality 3.5 {F3 C4 C5}>



.. code:: python

    v35.startTimespans




.. parsed-literal::
   :class: ipython-result

    (<PitchedTimespan (3.5 to 4.5) <music21.note.Note C>>,
     <PitchedTimespan (3.5 to 4.5) <music21.note.Note C>>)



.. code:: python

    v35.stopTimespans




.. parsed-literal::
   :class: ipython-result

    (<PitchedTimespan (3.0 to 3.5) <music21.note.Note D>>,
     <PitchedTimespan (3.0 to 3.5) <music21.note.Note F>>)



.. code:: python

    v35.overlapTimespans




.. parsed-literal::
   :class: ipython-result

    (<PitchedTimespan (3.0 to 6.0) <music21.note.Note F>>,)



.. code:: python

    elTsC = v35.startTimespans[0]

.. code:: python

    elTsC, elTsC.element




.. parsed-literal::
   :class: ipython-result

    (<PitchedTimespan (3.5 to 4.5) <music21.note.Note C>>, <music21.note.Note C>)



Test previousVerticality with Rest

.. code:: python

    v22 = tsCol.getVerticalityAt(22.0)

.. code:: python

    v22




.. parsed-literal::
   :class: ipython-result

    <Verticality 22.0 {A3 C4 F4}>



.. code:: python

    v22.startTimespans




.. parsed-literal::
   :class: ipython-result

    (<PitchedTimespan (22.0 to 22.5) <music21.note.Note C>>,
     <PitchedTimespan (22.0 to 23.0) <music21.note.Note F>>)



.. code:: python

    elTSfollowingRest = v22.startTimespans[1]
    elTSfollowingRest




.. parsed-literal::
   :class: ipython-result

    <PitchedTimespan (22.0 to 23.0) <music21.note.Note F>>



.. code:: python

    v22.stopTimespans




.. parsed-literal::
   :class: ipython-result

    (<PitchedTimespan (21.0 to 22.0) <music21.note.Note E>>,
     <PitchedTimespan (21.5 to 22.0) <music21.note.Rest rest>>)



.. code:: python

    elTSfollowingRest.part




.. parsed-literal::
   :class: ipython-result

    <music21.stream.Part Cantus>



.. code:: python

    score = tree.makeExampleScore()
    score.show()




.. image:: usersGuide_97_timespans_29_0.png



.. code:: python

    tsColSmall = score.asTimespans()

.. code:: python

    for v in tsColSmall.iterateVerticalities():
        if v != []:
            print(v)
            print(v.getAllVoiceLeadingQuartets())
        


.. parsed-literal::
   :class: ipython-result

    <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'


.. code:: python

    lucaAll = corpus.parse('luca/gloria')
    tsCol = lucaAll.asTimespans()

.. code:: python

    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'


.. code:: python

    bach = corpus.parse('bwv66.6')

.. code:: python

    import time
    t = time.time()
    dummy = alpha.theoryAnalysis.theoryAnalyzer.getVLQs(bach, 0, 1) # two parts only of bach
    print(time.time() - t)


.. parsed-literal::
   :class: ipython-result

    0.13318204879760742


.. code:: python

    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'


.. code:: python

    meterCol = lucaAll.parts[0].asTimespans(classList=(meter.TimeSignature,))

.. code:: python

    meterCol




.. parsed-literal::
   :class: ipython-result

    <TimespanTree {4} (0.0 to 275.0) <music21.stream.Part Cantus>>



.. code:: python

    print(meterCol)


.. parsed-literal::
   :class: ipython-result

    <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>>

