
    rh                    0   S SK Jr  S SKrS SKrS SKrS SKJr  S SKJr  S SKJr  S SKJ	r	  S SKJ
r
   " S S	5      r " S
 S5      r " S S\5      r " S S\R                  5      r " S S\R                  5      r\S:X  a  S SKr\R&                  " \5        gg)    )annotationsN)chord)key)interval)note)streamc                      \ rS rSrSrS rS rSS jrSS jrSS jr	SS	 jr
SS
 jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrS rS rS rS rS rS rS rSS jrSrg)Hasher   aJ  
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                   [         R                  [         R                  [        R                  /U l        SU l        SU l        SU l        SU l	        SU l
        SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        SU l        / U l        SU l        0 U l        0 U l        g)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    W/home/james-whalen/.local/lib/python3.13/site-packages/music21/alpha/analysis/hasher.py__init__Hasher.__init__F   s      99dii= !& "' &*#(-% %
 "&"'%*"#(    "    c                    U R                   (       a  SU R                  S'   U R                  (       a9  U R                  R	                  [
        R                  5        SU R                  S'   gg)a  
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(   setupValidTypesAndStateVars"Hasher.setupValidTypesAndStateVarst   sP    ( ((59DNN12  OO""3#3#34-1DNN>* !r+   Nc                h    U(       a  UR                   R                  $ UR                   R                  $ )aJ  
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(   _hashDurationHasher._hashDuration   s)     %%333zz'''r+   c                   U(       a.  U R                  [        UR                  R                  5      5      $ U R                  [        UR                  R                  5      5      UR                  l        UR                  R                  $ )z 
TODO: Check if this is working
)_getApproxDurOrOffsetfloatr3   r4   r5   s      r(   _hashRoundedDurationHasher._hashRoundedDuration   s_     --eI4F4F4T4T.UVV#'#=#=eAJJD\D\>]#^

 zz'''r+   c                    U(       a  U R                   (       a  g[        U[        R                  5      (       a  gUR                  R
                  $ )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midir5   s      r(   _hashMIDIPitchNameHasher._hashMIDIPitchName   s4    ( 00499%%ww||r+   c                    U(       a  U R                   (       a  g[        U[        R                  5      (       a  g[	        UR
                  5      $ )a  
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   rA   r   r   strrB   r5   s      r(   _hashPitchNameHasher._hashPitchName   s4    & 00499%%177|r+   c                    U(       a  U R                   (       a  g[        U[        R                  5      (       a  g[	        UR
                  5      SS $ )a  
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'
rG   rH   NrI   r5   s      r(   _hashPitchNameNoOctaveHasher._hashPitchNameNoOctave   s;    & 00499%%177|CR  r+   c                    [        U[        R                  5      (       a  U R                  (       a  g[        U[        R
                  5      (       a  gUR                  $ )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
rN   )rA   r   r   r   r   r   octaver5   s      r(   _hashOctaveHasher._hashOctave   s=    $ a%%$*A*A499%%xxr+   c                    g N r5   s      r(   _hashIsAccidentalHasher._hashIsAccidental  s    r+   c                    U(       a  U R                  UR                  5      $ U R                  UR                  5      Ul        UR                  $ )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
)r;   offsetr5   s      r(   _hashRoundedOffsetHasher._hashRoundedOffset  s=     --i.>.>??--ahh7xxr+   c                @    U(       a  UR                   $ UR                   $ )zG
returns an unrounded floating point representation of a note's offset
)r[   r5   s      r(   _hashOffsetHasher._hashOffset  s     ###xxr+   c                Z    [        U[        R                  5      (       a{  UR                  S5      bh  UR                  S5      nUc  g[        R
                  " UUS9R                  n[        R                  " [        R
                  " U5      R                  5      $ gg! [         a     gf = f)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)	rA   r   r   previousr   IntervalintervalClassconvertGeneric	TypeError)r'   r6   r7   previousNoteintFromLastNotes        r(   _hashIntervalFromLastNote Hasher._hashIntervalFromLastNote'  s    
	1dii((

6*6 zz&1'"*"3"3l<=#??L}  ..x/@/@/Q/_/_`` 7 )  		s   AB AB 
B*)B*c                *    U(       a  UR                   $ g)zO
returns prime form of a chord as a string e.g. '<037>'
returns '<>' otherwise
<>)primeFormStringr5   s      r(   _hashPrimeFormStringHasher._hashPrimeFormString9  s    
 ,,,r+   c                H    U(       a  UR                  UR                  5      $ g)zQ
returns normal order of a chord as a string e.g. '<047>'
returns '<>' otherwise
rn   )formatVectorStringnormalOrderr5   s      r(   _hashChordNormalOrderString"Hasher._hashChordNormalOrderStringB  s!    
 //	0E0EFFr+   c                    / nU R                   (       a  UR                  S5        U R                  (       a  U R                  U R                  S'   OwU R                  (       d+  U R
                  (       d  U R                  U R                  S'   O;U R                  (       d*  U R
                  (       a  U R                  U R                  S'   U R                  (       a*  UR                  S5        U R                  U R                  S'   U R                  (       a*  UR                  S5        U R                  U R                  S'   U R                  (       a  OU R                  (       av  U R                  (       a*  UR                  S5        U R                  U R                  S'   U R                   (       a*  UR                  S5        U R"                  U R                  S'   U R$                  (       aU  UR                  S5        U R&                  (       a  U R(                  U R                  S'   OU R*                  U R                  S'   U R,                  (       aU  UR                  S5        U R&                  (       a  U R.                  U R                  S'   OU R0                  U R                  S'   U R2                  (       a*  UR                  S5        U R4                  U R                  S'   Xl        [8        R:                  " S	U5      U l        g
)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   rD   r%   r   rK   rO   r   rX   r   rS   r   r   r    ru   r!   rp   r   r   r=   r8   r   r\   r_   r   rk   r"   collections
namedtupler#   )r'   r"   s     r(   setupTupleListHasher.setupTupleListM  s.    	>>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                    g)zG
lightweight hasher. only hashes number of notes, first and last pitch
NrW   )r'   ss     r(   hashMeasuresHasher.hashMeasures  s    r+   c           
        / nU R                  5         UR                  5       n[        U R                  5      nU Vs/ s H  n[	        XT5      (       d  M  UPM     nnU R                  5         U GHV  nU R                  (       a/  [	        U[        R                  5      (       a  XPR                  S'   MD  [	        U[        R                  5      (       a  U R                  (       aJ  U HB  nU R                   Vs/ s H  nU R                  U   " XuS9PM     n	nU R                  XU5        MD     M  U R                   (       aC  U R                   Vs/ s H  nU R                  U   " SUS9PM     n	nU R                  XU5        GM  GM  U R                   Vs/ s H  nU R                  U   " U5      PM     n	nU R                  XU5        GMY     U$ s  snf s  snf s  snf s  snf )ah  
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)r7   N)r0   recursetupler   rA   r   r   r   r.   r$   r   r   r   r"   r%   addHashToFinalHashr   )
r'   r   	finalHashsstupValidTypeseltfinalEltsToBeHashednhashPropertysingleNoteHashs
             r(   
hashStreamHasher.hashStream  s    	((*YY[doo..0SbsJs4RsbS 'C$$C9I9I)J)J/2|,C--)) @D*P@N +/*?*?*Ma*_@N ' *P //1M	 !
 ,,<@NN&L<JL '+&;&;L&I$Z]&^<J # &L++NsK - 9="H8F #'"7"7"Ec"J8F  "H''3G% '( 1 T*P
&L"Hs   GG5GGGc                    U R                   R                  U5      nU R                  (       a  U R                  X$U5        g U R	                  X$5        g rV   )r#   _maker   #addNoteHashWithReferenceToFinalHashaddNoteHashToFinalHash)r'   r   r   	reference	tupleHashs        r(   r   Hasher.addHashToFinalHash  s=    __**>:	  44Y9U''	=r+   c                H    [        U5      nX4l        UR                  U5        g)a8  
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   *Hasher.addNoteHashWithReferenceToFinalHash  s!    & %Y/"r+   c                <    [        U5      nUR                  U5        g)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)r   r/   )r'   r   r   nhs       r(   r   Hasher.addNoteHashToFinalHash  s      i r+   c                J    [        XR                  -  5      U R                  -  $ rV   )roundr   )r'   durOrOffsets     r(   r;   Hasher._getApproxDurOrOffset  s!    [#3#334t7G7GGGr+   c                ^    X:H  =(       d#    [        USU-  -  5      [        USU-  -  5      :H  $ 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(   _approximatelyEqualHasher._approximatelyEqual  2    
 vIQw./3q2=7H3IIIr+   )r   r   r   r   r   r   r   r   r    r   r   r   r   r!   r%   r   r   r$   r#   r"   r   rV   )   )__name__
__module____qualname____firstlineno____doc__r)   r0   r8   r=   rD   rK   rO   rS   rX   r\   r_   rk   rp   ru   r   r   r   r   r   r   r;   r   __static_attributes__rW   r+   r(   r
   r
      s}    +Z,#\28(&(42!20	$9Hv
$L>.HHJr+   r
   c                  *    \ rS rSrSrS rS rS rSrg)r   i  a   
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                    S U l         UR                  5       nU H  n[        XX#   5        M     [        UR	                  5       5      U l        g rV   )r   _asdictsetattrr   keyshashItemsKeys)r'   hashItemsNThashItemsDictxs       r(   r)   NoteHashWithReference.__init__   sD    #++-AD]-. "=#5#5#78r+   c              #  L   #    U R                    H  n[        X5      v   M     g 7frV   )r   getattr)r'   keyNames     r(   __iter__NoteHashWithReference.__iter__'  s      ))G$(( *s   "$c                    Sn/ nU R                    H2  nUnUS-  nU[        [        X5      5      -  nUR                  U5        M4     USR	                  U5      -  nUS-  nU$ )NzNoteHashWithReference(=z, ))r   rJ   r   r/   join)r'   nhStrAllvalsr   nhStrs        r(   __repr__NoteHashWithReference.__repr__+  sl    +##AESLES)**EKK	 $
 	DIIdO#Cr+   )r   r   N)	r   r   r   r   r   r)   r   r   r   rW   r+   r(   r   r     s    89)r+   r   c                  ,   ^  \ rS rSrSrU 4S jrSrU =r$ )r   i9  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                >   > [         [        U ]  U [        U5      5      $ rV   )superr   __new__r   )clstupEls	__class__s     r(   r   NoteHash.__new__G  s    Xs+Cv??r+   rW   )r   r   r   r   r   r   r   __classcell__)r   s   @r(   r   r   9  s    @ @r+   r   c                  N    \ rS rSrS rSS jrS rS rS rS r	S r
S	 rS
 rSrg)TestiK  c                2    SSK Jn  U" U [        5       5        g )Nr   )testCopyAll)music21.test.commonTestr   globals)r'   r   s     r(   testCopyAndDeepcopyTest.testCopyAndDeepcopyL  s    7D')$r+   c                ^    X:H  =(       d#    [        USU-  -  5      [        USU-  -  5      :H  $ r   r   r   s       r(   r   Test._approximatelyEqualP  r   r+   c                   [         R                  " 5       n[        R                  " S5      nSUR                  l        [        R                  " S5      n[        R                  " S5      n[        R                  " / SQ5      nSUR                  l        [        R                  " SS9nUR                  U5        UR                  U5        UR                  U5        UR                  U5        UR                  U5        [        5       n/ SQn[        R                  " S	/ S
Q5      n	U V
VVs/ s H  u  pnU	" XUS
9PM     nnn
nU R                  UR                  U5      U5        gs  snnn
f )zb
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      ?)r4   ))<          @        )B         ?r   ).   r   g      @)r   r         @)C   r   r   )K   r   r   )r   r   g      @r   rx   r}   r~   N)r   Streamr   r   r3   typer   r   r   r/   r
   r   r   assertEqualr   )r'   s1note1note2note3cMinorrH   hhashes_plain_numbers	CNoteHashr   yrG   hashes_in_formats                 r(   testBasicHashTest.testBasicHashW  s   
 ]]_		$$		% 		% 01%IIC(
		%
		%
		%
		&
		!H O**:7VW	-AC-A	q &A!D-A 	 C 	b)+;<Cs   (E"c                   [         R                  " 5       n[        R                  " S5      nSUR                  l        [        R                  " / SQ5      nSUR                  l        [        R                  " / SQ5      nSUR                  l        UR                  U5        UR                  U5        UR                  U5        [        5       nSUl
        SUl        SUl        [        R                  " S/ S	Q5      n/ S
QnU VV	V
Vs/ s H  u  ppU" XXS	9PM     nn
n	nnU R                  UR!                  U5      U5        gs  snn
n	nf )zI
test to make sure that hashing works when trying to hash chord as chord
r   r   r   )r   r   E4wholeTFr   )rx   r|   r}   r~   )r   rn   r   r   r@   <037>r   r   )r@   r  r   r   N)r   r   r   r   r3   r   r   r   r/   r
   r   r   r!   r   r   r   r   )r'   r   r   r   cMajorr   r  r   r   r  rG   r   r  s                r(   %testHashChordsAsChordsPrimeFormString*Test.testHashChordsAsChordsPrimeFormStringt  s    ]]_		$$01%/0&
		%
		&
		&H## $**: 8N O	 8 1EF0Dq &A1W0D 	 F 	b)+;<Fs   E 
c                   [         R                  " 5       n[        R                  " S5      nSUR                  l        [        R                  " / SQ5      nSUR                  l        [        R                  " / SQ5      nSUR                  l        UR                  U5        UR                  U5        UR                  U5        [        5       nSUl
        SUl        SUl        SUl        [        R                  " S/ S	Q5      n/ S
QnU VV	V
Vs/ s H  u  ppU" XXS	9PM     nn
n	nnU R!                  UR#                  U5      U5        g s  snn
n	nf )Nr   r   r   )r   r   E3r  TFr   )rx   r{   r}   r~   )r	  r
  )r@   z<047>r   r   )r   r   r   r   r3   r   r   r   r/   r
   r   r   r!   r    r   r   r   r   )r'   s2r   r   r  r   r  r   r   r  rG   r   r  s                r(   !testHashChordsAsChordsNormalOrder&Test.testHashChordsAsChordsNormalOrder  s   ]]_		$$01%/0&
		%
		&
		&H## %"&**: 8N O	 8 1EF0Dq &AQY0D 	 Fb)+;<Fs   E
c                  ^  [         R                  " 5       n[        R                  " S5      n[        R                  " S5      n[        R
                  " SS/5      nSUR                  l        SUR                  l        SUR                  l        UR                  U5        UR                  U5        UR                  U5        [        5       nSUl        [        R                  " S/ SQ5      n/ S	QnU VV	V
s/ s H  u  pn
U" XU
S9PM     nn	nn
UR                  U5      nUS
   S   US   S   US   S   US   S   /nUS
   S   US   S   US   S   US   S   /n[        U 4S j[!        X5       5       5      (       d   eg s  sn
n	nf )Nr   r   I+?UUUUUU?r   Fr   r   ))r   r  r   )r   r  r  )r   r   2z[@)r   r   r  r      r@      c              3  B   >#    U  H  nTR                   " U6 v   M     g 7frV   )r   ).0valuesr'   s     r(   	<genexpr>1Test.testHashUnroundedDuration.<locals>.<genexpr>  s$      A!?v ++V4!?s   )r   r   r   r   r   r   r3   r4   r   r/   r
   r   r   r   r   allzip)r'   s3r   r   r   r   r  r   r   rG   r   r  h3	h3_floatsanswers_floatss   `              r(   testHashUnroundedDurationTest.testHashUnroundedDuration  s   ]]_		$		$dD\*',$',$%
		%
		%
		&H#( **:7VW	 : .BC-A	q &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 ACs   5F c                   [         R                  " 5       n[        R                  " S5      n[        R                  " S5      n[        R
                  " SS/5      nSUR                  l        SUR                  l        SUR                  l        UR                  U5        UR                  U5        UR                  U5        [        5       nSUl        [        R                  " S/ SQ5      n/ S	QnU VV	V
s/ s H  u  pn
U" XU
S9PM     nn	nn
UR                  U5      nU R                  X5        S
Ul        / SQnUR                  U5      nU R                  X5        g s  sn
n	nf )Nr   r   r  r  r   Tr   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   r3   r4   r   r/   r
   r   r   r   r   r   r   )r'   r!  r   r   r   r   r  r   r   rG   r   r  r"  new_hashes_in_formath4s                  r(   testHashRoundedDurationTest.testHashRoundedDuration  s*   ]]_		$		$dD\*',$',$%
		%
		%
		&H#' **:7VW	 3 .BC-A	q &A!D-A 	 C\\". 0 \\"2Cs   4Ec                   [         R                  " 5       n[        R                  " S5      n[        R                  " S5      nUR	                  X#/5        [        5       nSUl        UR                  U5      nUS   R                  nUS   R                  nU R                  UR                  UR                  5        U R                  UR                  UR                  5        g )Nr   r   Tr   r@   )r   r   r   r   r/   r
   r   r   r   r   id)r'   r   r   r   r   hashesnote1refnote2refs           r(   testReferencesTest.testReferences  s    MMO		$		$	% H!a!9&&!9&&8;;/8;;/r+   c                F   [         R                  " 5       n[        R                  " S5      n[        R                  " S5      n[        R                  " S5      nUR	                  X#U/5        [        5       nSUl        SUl        SUl        SUl	        UR                  U5      ng )NE5D5A5TF)r   r   r   r   r/   r
   r   r   r   r   r   )r'   r   r   r   r   r   unused_hashess          r(   testIntervalsTest.testIntervals  sv    MMO		$		$		$	%&'H%)"Qr+   rW   N)r  )r   r   r   r   r   r   r  r  r  r%  r/  r6  r=  r   rW   r+   r(   r   r   K  s1    %J=:=6=0A63:0 (r+   r   c                  $    \ rS rSrSrS rS rSrg)TestExternali  Tc                   SSK Jn  [        5       nSUl        SUl        UR                  SS5      R                  R                  5       nUR                  SS5      R                  R                  5       nUR                  S5      R                  R                  5       nUR                  U5      nUR                  U5      nUR                  U5      nU R                  (       a  [        [        R                  " XgS9R                  5       5        [        [        R                  " XhS9R                  5       5        [        [        R                  " XxS9R                  5       5        UR                  5         SUl        S	Ul        S	Ul        UR                  U5      nUR                  U5      nUR                  U5      nU R                  (       a  [        [        R                  " XgS9R                  5       5        [        [        R                  " XhS9R                  5       5        [        [        R                  " XxS9R                  5       5        g g )
Nr   corpusF
schoenberg   r  bwv66.6r   r   T)music21rC  r
   r   r   parsepartsfirstr   showprintdifflibSequenceMatcherratior   )	r'   rC  r   r   r  r!  hashes1hashes2hashes3s	            r(   	testBvSvSTestExternal.testBvSvS@  s   "H\\,*00668\\,*00668\\)$**002,,r",,r",,r"99'))G?EEGH'))G?EEGH'))G?EEGHGGI,,r",,r",,r"99'))G?EEGH'))G?EEGH'))G?EEGH r+   c                |   SSK Jn  [        5       nUR                  S5      R                  R                  5       nUR                  S5      R                  R                  5       R                  S5      nUR                  U5      nUR                  U5      nU R                  (       a+  [        [        R                  " XVS9R                  5       5        SUl        SUl        UR                  U5      nUR                  U5      nU R                  (       a,  [        [        R                  " XVS9R                  5       5        g g )Nr   rB  rF  M2rG  TF)rH  rC  r
   rI  rJ  rK  	transposer   rL  rM  rN  rO  rP  r   r   )r'   rC  r   r!  s4rS  hashes4s          r(   testIntervalTestExternal.testInterval_  s    "H\\)$**002\\)$**002<<TB,,r",,r"99'))G?EEGH%)",,r",,r"99'))G?EEGH r+   rW   N)r   r   r   r   rL  rT  r[  r   rW   r+   r(   r@  r@    s    DDI>Ir+   r@  __main__)
__future__r   r   rN  unittestrH  r   r   r   r   r   r
   r   r   r   TestCaser   r@  r   mainTestrW   r+   r(   <module>rb     s    #        eJ eJT4 4n@u @$o(8 o(duI8$$ uIp zT r+   