
    3j                    .   d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dlm
Z
  G d d	      Z G d
 d      Z G d de      Z G d dej                        Z G d dej                        Zedk(  rd dlZ ej&                  e       yy)    )annotationsN)chord)key)interval)note)streamc                      e Zd ZdZd Zd ZddZddZddZddZ	dd	Z
dd
ZddZddZddZddZddZddZd Zd Zd Zd Zd Zd Zd ZddZy)Hashera  
    This is a modular hashing object that can hash notes, chords, and rests, and some of their
    properties. Steps to using and calling the hasher:

    1) Initialize a hasher object

    2) Set the properties that you want to hash. There are 4 main groups of properties/settings::

        a) self.validTypes should be some combination of notes, chords, rests

        b) general hashing settings include self.includeReference. if
           self.includeReference is True, a reference to the original note/rest/chord is created
           and kept track of during the hashing process.

        c) note properties are things like pitch, duration, offset, and some slightly fancier
           properties

        d) self.stateVars is a dictionary of things you might want to hash that require some memory
           e.g. current key signature, interval from the last note

    3) call the hashStream() function on the stream you want to hash.

    This is what the Hasher object does the in background once hashStream() is called:

    1) It runs self.setupValidTypesAndStateVars() and sets up properties from (a) and (d) from
    above based on your settings

    2) It runs self.preprocessStream() and based on settings from (d)

    3) It determines which objects in the passed-in stream should be hashed

    4) It runs self.setupTupleList() and sets up self.tupleList, self.hashingFunctions
    and self.tupleClass, all related to each other. self.tupleList is a list of all the
    properties that are hashed. self.hashingFunctions is a dictionary of which hashing function
    should be used for each property (there are multiple ways of hashing a note's pitch, for
    example, by MIDI number, or by a string representation). self.tupleClass is a NamedTuple
    that is constructed ad hoc based on which properties are to be hashed.

    5) For all the elements from the stream that are to be hashed, the hasher hashes every one of
    its properties that are to be hashed using the hashing function listed in
    self.hashingFunctions. It creates a single NamedTuple called a NoteHash for each element
    from the stream. However, if self.includeReference is set to True, a NoteHashWithReference
    tuple is created instead.
    c                   t         j                  t         j                  t        j                  g| _        d| _        d| _        d| _        d| _	        d| _
        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        d| _        g | _        d| _        i | _        i | _        y)z
        The Hasher object is initialized with defaults of what objects should be hashed, and
        what properties of those objects should be hashed.
        FT    N)r   NoteRestr   Chord
validTypesincludeReference	hashPitchhashMIDIhashNoteNameOctave
hashOctavehashDurationroundDurationAndOffset
hashOffsetgranularityhashIntervalFromLastNotehashIsAccidental
hashIsTiedhashChordsAsNoteshashChordsAsChordshashNormalOrderStringhashPrimeFormString	tupleList
tupleClass	stateVarshashingFunctionsselfs    J/DATA/.local/lib/python3.12/site-packages/music21/alpha/analysis/hasher.py__init__zHasher.__init__E   s      99dii= !& "' &*#(-% %
 "&"'%*"#(    "    c                    | j                   rd| j                  d<   | j                  r9| j                  j	                  t
        j                         d| j                  d<   yy)aa  
        Sets up the self.stateVars dictionary depending on how the flags for
        self.hashIntervalFromLastNote and self.hashIsAccidental are set.

        >>> h = alpha.analysis.hasher.Hasher()
        >>> h.hashIntervalFromLastNote = True
        >>> h.setupValidTypesAndStateVars()
        >>> h.stateVars
        {'IntervalFromLastNote': None}

        >>> h2 = alpha.analysis.hasher.Hasher()
        >>> h2.hashIsAccidental = True
        >>> h2.setupValidTypesAndStateVars()
        >>> h2.stateVars
        {'KeySignature': None}

        >>> key.KeySignature in h2.validTypes
        True
        NIntervalFromLastNoteKeySignature)r   r#   r   r   appendr   r,   r%   s    r'   setupValidTypesAndStateVarsz"Hasher.setupValidTypesAndStateVarss   sP    ( ((59DNN12  OO""3#3#34-1DNN>* !r)   Nc                ^    |r|j                   j                  S |j                   j                  S )a  
        returns the duration of a chord object passed in, otherwise the duration of a note
        object passed in.

        >>> h = alpha.analysis.hasher.Hasher()
        >>> n = note.Note('A-', quarterLength=2.5)
        >>> h._hashDuration(n)
        2.5

        >>> d = duration.Duration(2.0)
        >>> c = chord.Chord('A-4 C#5 E5', duration=d)
        >>> h._hashDuration(n, thisChord=c)
        2.0
        )durationquarterLengthr&   e	thisChords      r'   _hashDurationzHasher._hashDuration   s)     %%333zz'''r)   c                   |r.| j                  t        |j                  j                              S | j                  t        |j                  j                              |j                  _        |j                  j                  S )z0
        TODO: Check if this is working
        )_getApproxDurOrOffsetfloatr0   r1   r2   s      r'   _hashRoundedDurationzHasher._hashRoundedDuration   s_     --eI4F4F4T4T.UVV#'#=#=eAJJD\D\>]#^

 zz'''r)   c                    |r| j                   ryt        |t        j                        ry|j                  j
                  S )a,  
        returns midi pitch value (21-108) of a note
        returns 0 if rest
        returns 1 if not hashing individual notes of a chord

        >>> n = note.Note(72)
        >>> c = chord.Chord('A-4 C#5 E5')
        >>> h = alpha.analysis.hasher.Hasher()
        >>> h.hashChordsAsChords = True
        >>> h._hashMIDIPitchName(n, thisChord=c)
        1
        >>> h.hashChordsAsChords = False
        >>> h._hashMIDIPitchName(n, thisChord=c)
        72
        >>> r = note.Rest()
        >>> h._hashMIDIPitchName(r, thisChord=c)
        0

           r   )r   
isinstancer   r   pitchmidir2   s      r'   _hashMIDIPitchNamezHasher._hashMIDIPitchName   s1    ( 00499%ww||r)   c                    |r| j                   ryt        |t        j                        ryt	        |j
                        S )aQ  
        returns string representation of a note e.g. 'F##4'
        returns 'r' if rest
        returns 'z' if not hashing individual notes of a chord (i.e. hashing chords as chords)

        >>> n = note.Note(72)
        >>> c = chord.Chord('A-4 C#5 E5')
        >>> h = alpha.analysis.hasher.Hasher()
        >>> h.hashChordsAsChords = True
        >>> h._hashPitchName(n, thisChord=c)
        'z'
        >>> h.hashChordsAsChords = False
        >>> h._hashPitchName(n, thisChord=c)
        'C5'
        >>> r = note.Rest()
        >>> h._hashPitchName(r, thisChord=c)
        'r'
        zrr   r<   r   r   strr=   r2   s      r'   _hashPitchNamezHasher._hashPitchName   s1    & 00499%177|r)   c                    |r| j                   ryt        |t        j                        ryt	        |j
                        dd S )aZ  
        returns string representation of a note without the octave e.g. 'F##'
        returns 'r' if rest
        returns 'z' if not hashing individual notes of a chord

        >>> n = note.Note(72)
        >>> c = chord.Chord('A-4 C#5 E5')
        >>> h = alpha.analysis.hasher.Hasher()
        >>> h.hashChordsAsChords = True
        >>> h._hashPitchNameNoOctave(n, thisChord=c)
        'z'
        >>> h.hashChordsAsChords = False
        >>> h._hashPitchNameNoOctave(n, thisChord=c)
        'C'
        >>> r = note.Rest()
        >>> h._hashPitchNameNoOctave(r, thisChord=c)
        'r'
        rA   rB   NrC   r2   s      r'   _hashPitchNameNoOctavezHasher._hashPitchNameNoOctave   s8    & 00499%177|CR  r)   c                    t        |t        j                        r| j                  ryt        |t        j
                        ry|j                  S )a  
        returns octave number of a note
        returns -1 if rest or not hashing individual notes of a chord

        >>> n = note.Note(72)
        >>> c = chord.Chord('A-4 C#5 E5')
        >>> h = alpha.analysis.hasher.Hasher()
        >>> h.hashChordsAsChords = True
        >>> h._hashOctave(c, thisChord=c)
        -1
        >>> h.hashChordsAsChords = False
        >>> h._hashOctave(n, thisChord=c)
        5
        >>> r = note.Rest()
        >>> h._hashOctave(r, thisChord=c)
        -1
        rG   )r<   r   r   r   r   r   octaver2   s      r'   _hashOctavezHasher._hashOctave   s7    $ a%$*A*A499%xxr)   c                     y N r2   s      r'   _hashIsAccidentalzHasher._hashIsAccidental  s    r)   c                    |r| j                  |j                        S | j                  |j                        |_        |j                  S )z
        Returns offset rounded to the nearest subdivided beat.
        The subdivided beat is indicated with self.granularity.
        By default, the granularity is set to 32, or 32nd notes
        )r7   offsetr2   s      r'   _hashRoundedOffsetzHasher._hashRoundedOffset  s=     --i.>.>??--ahh7xxr)   c                6    |r|j                   S |j                   S )zW
        returns an unrounded floating point representation of a note's offset
        )rQ   r2   s      r'   _hashOffsetzHasher._hashOffset  s     ###xxr)   c                J   	 t        |t        j                        ry|j                  d      g|j                  d      }|yt	        j
                  ||      j                  }t	        j                  t	        j
                  |      j                        S yy# t        $ r Y yw xY w)z
        returns the interval between last note and current note, if extant
        known issues with first note of every measure in transposed pieces
        returns 0 if things don't work
        r   Nr   )	noteStartnoteEnd)	r<   r   r   previousr   IntervalintervalClassconvertGeneric	TypeError)r&   r3   r4   previousNoteintFromLastNotes        r'   _hashIntervalFromLastNotez Hasher._hashIntervalFromLastNote&  s    
	1dii(

6*6 zz&1'"*"3"3l<=#??L}  ..x/@/@/Q/_/_`` 7 )  		s   >B AB 	B"!B"c                     |r|j                   S y)zg
        returns prime form of a chord as a string e.g. '<037>'
        returns '<>' otherwise
        <>)primeFormStringr2   s      r'   _hashPrimeFormStringzHasher._hashPrimeFormString8  s    
 ,,,r)   c                >    |r|j                  |j                        S y)zi
        returns normal order of a chord as a string e.g. '<047>'
        returns '<>' otherwise
        ra   )formatVectorStringnormalOrderr2   s      r'   _hashChordNormalOrderStringz"Hasher._hashChordNormalOrderStringA  s!    
 //	0E0EFFr)   c                V   g }| j                   r|j                  d       | j                  r| j                  | j                  d<   nc| j                  s&| j
                  s| j                  | j                  d<   n1| j                  s%| j
                  r| j                  | j                  d<   | j                  r*|j                  d       | j                  | j                  d<   | j                  r*|j                  d       | j                  | j                  d<   | j                  rnx| j                  rl| j                  r*|j                  d       | j                  | j                  d<   | j                   r*|j                  d       | j"                  | j                  d<   | j$                  rP|j                  d       | j&                  r| j(                  | j                  d<   n| j*                  | j                  d<   | j,                  rP|j                  d       | j&                  r| j.                  | j                  d<   n| j0                  | j                  d<   | j2                  r*|j                  d       | j4                  | j                  d<   || _        t9        j:                  d	|      | _        y
)a  
        Sets up self.hashingFunctions, a dictionary of which properties of self.validTypes should
        be hashed and which hashing functions should be used for those properties. Creates a
        tupleList of all the properties that are hashed and uses that to create a named tuple
        NoteHash with those properties. This is how we can generate a malleable named tuple
        NoteHash that is different depending upon which properties a particular instance of
        Hasher object hashes.
        PitchIsAccidentalOctaveNormalOrderStringPrimeFormStringDurationOffsetr+   NoteHashN)r   r-   r   r?   r$   r   rE   rH   r   rO   r   rK   r   r   r   rg   r    rc   r   r   r9   r5   r   rR   rT   r   r_   r!   collections
namedtupler"   )r&   r!   s     r'   setupTupleListzHasher.setupTupleListL  s0    	>>W%}}151H1H%%g.]]4+B+B151D1D%%g.]]t'>'>151L1L%%g.$$  08<8N8N%%n5??X&.2.>.>D!!(+!!$$))  !45=A=]=]%%&9:''  !23;?;T;T%%&78Z(**484M4M%%j1484F4F%%j1??X&**262I2I%%h/262B2B%%h/((34<@<Z<ZD!!"89"%00YGr)   c                     y)zW
        lightweight hasher. only hashes number of notes, first and last pitch
        NrN   )r&   ss     r'   hashMeasureszHasher.hashMeasures  s    r)   c           	     l   g }| j                          |j                         }t        | j                        }|D cg c]  }t	        ||      s| }}| j                          |D ]6  }| j                  r*t	        |t        j                        r|| j                  d<   :t	        |t        j                        r| j                  rI|D ]C  }| j                  D cg c]  } | j                  |   ||       }	}| j                  |	||       E | j                   s| j                  D cg c]  } | j                  |   d|       }	}| j                  |	||       | j                  D cg c]  } | j                  |   |       }	}| j                  |	||       9 |S c c}w c c}w c c}w c c}w )a  
        This method is the meat of the program. It goes through all the elements that are left
        to be hashed and individually hashes them by looking up which hashing functions ought
        to be used on each element and passing off the element to the method
        self.addSingleNoteHashToFinalHash, which creates the appropriate hash for that element
        and adds it to self.finalHash
        
currKeySig)r4   N)r.   recursetupler   r<   rs   r   r   r,   r#   r   r   r   r!   r$   addHashToFinalHashr   )
r&   ru   	finalHashsstupValidTypeseltfinalEltsToBeHashednhashPropertysingleNoteHashs
             r'   
hashStreamzHasher.hashStream  s    	((*YY[doo..0SbsJsM4RsbS 'C$$C9I9I)J/2|,C-)) @D*P@N +N$*?*?*Ma[^*_@N ' *P //	1M	 !
 ,,<@NN&L<JL 'Jd&;&;L&I$Z]&^<J # &L++NIsK 9="H8F #F$"7"7"Ec"J8F  "H''	3G% '( 1 T*P
&L"Hs   F"F"F'*F,,F1c                    | j                   j                  |      }| j                  r| j                  |||       y | j	                  ||       y rM   )r"   _maker   #addNoteHashWithReferenceToFinalHashaddNoteHashToFinalHash)r&   r   r|   	reference	tupleHashs        r'   r{   zHasher.addHashToFinalHash  sA    __**>:	  44Y	9U''	9=r)   c                J    t        |      }||_        |j                  |       y)a  
        creates a NoteHashWithReference object from tupleHash and with the reference pass in
        and adds the NoteHashWithReference object to the end of finalHash

        >>> from collections import namedtuple
        >>> n = note.Note('C4')
        >>> NoteHash = namedtuple('NoteHash', ['Pitch', 'Duration'])
        >>> nh = NoteHash(n.pitch, n.duration)
        >>> finalHash = []
        >>> h = alpha.analysis.hasher.Hasher()
        >>> h.addNoteHashWithReferenceToFinalHash(finalHash, nh, n)
        >>> finalHash
        [NoteHashWithReference(Pitch=C4, Duration=<music21.duration.Duration 1.0>)]

        >>> finalHash[0].reference.id == n.id
        True
        N)NoteHashWithReferencer   r-   )r&   r|   r   r   nhwrs        r'   r   z*Hasher.addNoteHashWithReferenceToFinalHash  s#    & %Y/"r)   c                <    t        |      }|j                  |       y)a  
        creates a NoteHash object from tupleHash and adds the NoteHash
        object to the end of finalHash

        >>> from collections import namedtuple
        >>> n = note.Note('C4')
        >>> NoteHash = namedtuple('NoteHash', ['Pitch', 'Duration'])
        >>> nh = NoteHash(n.pitch, n.duration)
        >>> finalHash = []
        >>> h = alpha.analysis.hasher.Hasher()
        >>> h.addNoteHashToFinalHash(finalHash, nh)
        >>> finalHash
        [(<music21.pitch.Pitch C4>, <music21.duration.Duration 1.0>)]
        N)rp   r-   )r&   r|   r   nhs       r'   r   zHasher.addNoteHashToFinalHash  s      i r)   c                L    t        || j                  z        | j                  z  S rM   )roundr   )r&   durOrOffsets     r'   r7   zHasher._getApproxDurOrOffset  s#    [4#3#334t7G7GGGr)   c                V    ||k(  xs# t        |d|z  z        t        |d|z  z        k(  S z
        use to look at whether beat lengths are close, within a certain range
        probably can use for other things that are approx. equal
        
   intr&   absig_figs       r'   _approximatelyEqualzHasher._approximatelyEqual  4    
 AvIQw./3q2=7H3IIIr)   rM   )   )__name__
__module____qualname____doc__r(   r.   r5   r9   r?   rE   rH   rK   rO   rR   rT   r_   rc   rg   rs   rv   r   r{   r   r   r7   r   rN   r)   r'   r
   r
      s}    +Z,#\28(&(42!20	$9Hv
$L>.HHJr)   r
   c                  "    e Zd ZdZd Zd Zd Zy)r   aT  
    returns tuple with reference to original note or chord or rest

    >>> from collections import namedtuple
    >>> NoteHash = namedtuple('NoteHash', ['Pitch', 'Duration'])
    >>> nh = NoteHash(60, 4)
    >>> nhwr = alpha.analysis.hasher.NoteHashWithReference(nh)
    >>> nhwr.reference = note.Note('C4')
    >>> nhwr
    NoteHashWithReference(Pitch=60, Duration=4)

    >>> nhwr.Pitch
    60
    >>> nhwr.Duration
    4

    >>> nhwr.hashItemsKeys
    ('Pitch', 'Duration')

    >>> for val in nhwr:
    ...     print(val)
    60
    4

    >>> nhwr.reference
    <music21.note.Note C>
    c                    d | _         |j                         }|D ]  }t        | |||           t        |j	                               | _        y rM   )r   _asdictsetattrrz   keyshashItemsKeys)r&   hashItemsNThashItemsDictxs       r'   r(   zNoteHashWithReference.__init__  sH    #++-AD!]1-. "=#5#5#78r)   c              #  J   K   | j                   D ]  }t        | |        y wrM   )r   getattr)r&   keyNames     r'   __iter__zNoteHashWithReference.__iter__&  s#     ))G$(( *s   !#c                    d}g }| j                   D ]2  }|}|dz  }|t        t        | |            z  }|j                  |       4 |dj	                  |      z  }|dz  }|S )NzNoteHashWithReference(=z, ))r   rD   r   r-   join)r&   nhStrAllvalsr   nhStrs        r'   __repr__zNoteHashWithReference.__repr__*  sn    +##AESLESq)**EKK	 $
 	DIIdO#Cr)   N)r   r   r   r   r(   r   r   rN   r)   r'   r   r     s    89)r)   r   c                  "     e Zd ZdZ fdZ xZS )rp   z
    >>> note1 = note.Note('C4')
    >>> nh = alpha.analysis.hasher.NoteHash((1, 2))
    >>> nh
    (1, 2)
    >>> a, b = nh
    >>> a
    1
    >>> b
    2
    >>> nh.__class__
    <... 'music21.alpha.analysis.hasher.NoteHash'>
    c                >    t         t        |   | t        |            S rM   )superrp   __new__rz   )clstupEls	__class__s     r'   r   zNoteHash.__new__F  s    Xs+Cv??r)   )r   r   r   r   r   __classcell__)r   s   @r'   rp   rp   8  s    @ @r)   rp   c                  D    e Zd Zd ZddZd Zd Zd Zd Zd Z	d Z
d	 Zy
)Testc                2    ddl m}  || t                      y )Nr   )testCopyAll)music21.test.commonTestr   globals)r&   r   s     r'   testCopyAndDeepcopyzTest.testCopyAndDeepcopyK  s    7D')$r)   c                V    ||k(  xs# t        |d|z  z        t        |d|z  z        k(  S r   r   r   s       r'   r   zTest._approximatelyEqualO  r   r)   c           
        t        j                         }t        j                  d      }d|j                  _        t        j                  d      }t        j                  d      }t        j                  g d      }d|j                  _        t        j                  d      }|j                  |       |j                  |       |j                  |       |j                  |       |j                  |       t               }g d}t        j                  d	g d
      }	|D 
cg c]  \  }
}} |	|
||
       }}}
}| j                  |j                  |      |       yc c}}}
w )zz
        test for hasher with basic settings: pitch, rounded duration, offset
        with notes, chord, and rest
        C4halfzF#4zB-2r   G4zE-5      ?)r1   ))<          @        )B         ?r   ).   r   g      @)r   r         @)C   r   r   )K   r   r   )r   r   g      @rp   ri   rn   ro   N)r   Streamr   r   r0   typer   r   r   r-   r
   rq   rr   assertEqualr   )r&   s1note1note2note3cMinorrB   hhashes_plain_numbers	CNoteHashr   yrA   hashes_in_formats                 r'   testBasicHashzTest.testBasicHashV  s   
 ]]_		$$		% 		% 01%IIC(
		%
		%
		%
		&
		!H O**:7VW	-AC-A	Aq &A!D-A 	 C 	b)+;<Cs   $E c                   t        j                         }t        j                  d      }d|j                  _        t        j                  g d      }d|j                  _        t        j                  g d      }d|j                  _        |j                  |       |j                  |       |j                  |       t               }d|_
        d|_        d|_        t        j                  dg d	      }g d
}|D 	
cg c]  \  }}	}
} |||	|
|	       }}
}	}}| j                  |j!                  |      |       yc c}}
}	}w )zY
        test to make sure that hashing works when trying to hash chord as chord
        r   r   r   )r   r   E4wholeTFrp   )ri   rm   rn   ro   )r   ra   r   r   r;   <037>r   r   )r;   r   r   r   N)r   r   r   r   r0   r   r   r   r-   r
   r   r   r    rq   rr   r   r   )r&   r   r   r   cMajorr   r   r   r   r   rA   r   r   s                r'   %testHashChordsAsChordsPrimeFormStringz*Test.testHashChordsAsChordsPrimeFormStrings  s    ]]_		$$01%/0&
		%
		&
		&H## $**: 8N O	 8 1EF0DAq! &Aq1UVW0D 	 F 	b)+;<Fs    D?
c                   t        j                         }t        j                  d      }d|j                  _        t        j                  g d      }d|j                  _        t        j                  g d      }d|j                  _        |j                  |       |j                  |       |j                  |       t               }d|_
        d|_        d|_        d|_        t        j                  dg d	      }g d
}|D 	
cg c]  \  }}	}
} |||	|
|	       }}
}	}}| j!                  |j#                  |      |       y c c}}
}	}w )Nr   r   r   )r   r   E3r   TFrp   )ri   rl   rn   ro   )r   r   )r;   z<047>r   r   )r   r   r   r   r0   r   r   r   r-   r
   r   r   r    r   rq   rr   r   r   )r&   s2r   r   r   r   r   r   r   r   rA   r   r   s                r'   !testHashChordsAsChordsNormalOrderz&Test.testHashChordsAsChordsNormalOrder  s!   ]]_		$$01%/0&
		%
		&
		&H## %"&**: 8N O	 8 1EF0DAq! &AQWXY0D 	 Fb)+;<Fs   E
c           
         t        j                         }t        j                  d      }t        j                  d      }t	        j
                  ddg      }d|j                  _        d|j                  _        d|j                  _        |j                  |       |j                  |       |j                  |       t               }d|_        t        j                  dg d      }g d	}|D 	
cg c]  \  }}	}
 |||	|
       }}	}}
|j                  |      }|d
   d   |d   d   |d   d   |d   d   g}|d
   d   |d   d   |d   d   |d   d   g}t         fdt!        ||      D              sJ y c c}
}	}w )Nr   r   I+?UUUUUU?r   Frp   r   ))r   r   r   )r   r   r   )r   r   2z[@)r   r   r   r      r;      c              3  <   K   | ]  } j                   |   y wrM   )r   ).0valuesr&   s     r'   	<genexpr>z1Test.testHashUnroundedDuration.<locals>.<genexpr>  s'      A!?v ,4++V4!?s   )r   r   r   r   r   r   r0   r1   r   r-   r
   r   rq   rr   r   allzip)r&   s3r   r   r   r   r   r   r   rA   r   r   h3	h3_floatsanswers_floatss   `              r'   testHashUnroundedDurationzTest.testHashUnroundedDuration  s   ]]_		$		$dD\*',$',$%
		%
		%
		&H#( **:7VW	 : .BC-A	Aq &A!D-A 	 C\\"U1Xr!uQxAq2a58<	*1-a0*1-a0*1-a0*1-a02  A!$Y!?A A 	A ACs   0E8c           
        t        j                         }t        j                  d      }t        j                  d      }t	        j
                  ddg      }d|j                  _        d|j                  _        d|j                  _        |j                  |       |j                  |       |j                  |       t               }d|_        t        j                  dg d      }g d	}|D 	
cg c]  \  }}	}
 |||	|
       }}	}}
|j                  |      }| j                  ||       d
|_        g d}|j                  |      }| j                  ||       y c c}
}	}w )Nr   r   r   r   r   Trp   r   ))r        ?r   )r   g      ?r  )r   r        @)r   r   r     ))r         ?r   )r   g      ?r  )r   r         @)r   r   r  )r   r   r   r   r   r   r0   r1   r   r-   r
   r   rq   rr   r   r   r   )r&   r   r   r   r   r   r   r   r   rA   r   r   r   new_hashes_in_formath4s                  r'   testHashRoundedDurationzTest.testHashRoundedDuration  s4   ]]_		$		$dD\*',$',$%
		%
		%
		&H#' **:7VW	 3 .BC-A	Aq &A!D-A 	 C\\"-. 0 \\"12Cs   /Ec                   t        j                         }t        j                  d      }t        j                  d      }|j	                  ||g       t               }d|_        |j                  |      }|d   j                  }|d   j                  }| j                  |j                  |j                         | j                  |j                  |j                         y )Nr   r   Tr   r;   )r   r   r   r   r-   r
   r   r   r   r   id)r&   ru   r   r   r   hashesnote1refnote2refs           r'   testReferenceszTest.testReferences  s    MMO		$		$	% H!a!9&&!9&&8;;/8;;/r)   c                @   t        j                         }t        j                  d      }t        j                  d      }t        j                  d      }|j	                  |||g       t               }d|_        d|_        d|_        d|_	        |j                  |      }y )NE5D5A5TF)r   r   r   r   r-   r
   r   r   r   r   r   )r&   ru   r   r   r   r   unused_hashess          r'   testIntervalszTest.testIntervals  sx    MMO		$		$		$	%&'H%)"Qr)   N)r   )r   r   r   r   r   r   r   r   r  r  r  r  rN   r)   r'   r   r   J  s1    %J=:=6=0A63:0 (r)   r   c                      e Zd ZdZd Zd Zy)TestExternalTc                   ddl m} t               }d|_        d|_        |j                  dd      j                  j                         }|j                  dd      j                  j                         }|j                  d      j                  j                         }|j                  |      }|j                  |      }|j                  |      }| j                  rt        t        j                  ||      j                                t        t        j                  ||      j                                t        t        j                  ||      j                                |j                          d|_        d	|_        d	|_        |j                  |      }|j                  |      }|j                  |      }| j                  rt        t        j                  ||      j                                t        t        j                  ||      j                                t        t        j                  ||      j                                y y )
Nr   corpusF
schoenberg   r   bwv66.6r   r   T)music21r  r
   r   r   parsepartsfirstr   showprintdifflibSequenceMatcherratior   )	r&   r  r   r   r   r   hashes1hashes2hashes3s	            r'   	testBvSvSzTestExternal.testBvSvS?  s   "H\\,*00668\\,*00668\\)$**002,,r",,r",,r"99'))Gw?EEGH'))Gw?EEGH'))Gw?EEGHGGI,,r",,r",,r"99'))Gw?EEGH'))Gw?EEGH'))Gw?EEGH r)   c                t   ddl m} t               }|j                  d      j                  j                         }|j                  d      j                  j                         j                  d      }|j                  |      }|j                  |      }| j                  r.t        t        j                  ||      j                                d|_        d|_        |j                  |      }|j                  |      }| j                  r/t        t        j                  ||      j                                y y )Nr   r  r  M2r   TF)r!  r  r
   r"  r#  r$  	transposer   r%  r&  r'  r(  r)  r   r   )r&   r  r   r   s4r,  hashes4s          r'   testIntervalzTestExternal.testInterval^  s    "H\\)$**002\\)$**002<<TB,,r",,r"99'))Gw?EEGH%)",,r",,r"99'))Gw?EEGH r)   N)r   r   r   r%  r-  r3  rN   r)   r'   r  r    s    DDI>Ir)   r  __main__)
__future__r   rq   r'  unittestr!  r   r   r   r   r   r
   r   rz   rp   TestCaser   r  r   mainTestrN   r)   r'   <module>r9     s    #        eJ eJT4 4n@u @$o(8 o(duI8$$ uIp zGT r)   