
    rh                       S r SSKJr  SSK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	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KJr  SSKJr  SSKJr  SSKJr  \R,                  (       a  SSKJr  \R0                  " S5      r\R4                  \R6                  \R8                  \R:                  \R<                  \R>                  S.r   S#       S$S jjr!          S%S jr"      S&S jr#            S'S jr$S(S jr%S#S jr&SS.S jr' " S S\RP                  5      r) " S  S!\RT                  5      r+\,S":X  a  SSKr\RZ                  " \+5        gg))aD  
Functions for translating music21 objects and
:class:`~music21.abcFormat.ABCHandler` instances.
Mostly, these functions are for advanced, low level usage.
For basic importing of ABC files from a file or URL to a
:class:`~music21.stream.Stream`, use the music21 converter
module's :func:`~music21.converter.parse` function.
    )annotationsN)articulations)bar)clef)chord)common)environment)exceptions21)harmony)meter)note)spanner)stream)tempo)tie	abcFormatzabcFormat.translate)staccatoupbowdownbowaccentstrongaccenttenutoc                R   SSK Jn  Uc  [        R                  " 5       nOUnUc  [        R
                  " 5       nSnSn/ nU R                  5       (       aI  U R                  5       n[        R                  " [        UR                     UR                  " U5      5      nOU /n[        U5      S::  a  Sn	OSn	Sn
SnU GH  n[        R                  (       a  [        XR                   5      (       d   eU	(       Ga0  UR#                  5       (       Ga  [        R$                  " 5       nUR&                  Gb#  UR&                  R)                  5       nUb  Xl        UR&                  R-                  5       (       a  UR/                  [        R0                  5      R3                  S5      nU(       dG  [        R0                  " U5      nUR&                  R-                  5       Ul        UR7                  U5        O@[        R                  " [        R0                  US   5      nUR9                  U5        SUl        UR&                  R-                  5       S:X  a  SUl        UR<                  b  UR<                  R)                  5       nUb  UUl        UR<                  RA                  5       (       a~  UR/                  [        R0                  5      R3                  S5      n[C        U5      (       a@  [        R                  " [        R0                  US   5      nUR9                  U5        SUl        U
S-  n
OUn[E        XXI5      u  peU	(       d  GM  [        U[        R$                  5      (       d  GM  U
S:X  a9  URF                  b,  URI                  5       S:  a  URK                  5         SUl        OXl        US-  nURM                  U5        GM     URO                  5          [Q        USS	9  U(       d  U[Z        R\                     (       d  U	(       ab  UR_                  [        R$                  5      Ra                  5       n[        R                  (       a  Uc   e[Z        Rb                  " USS
9Ul-        O%URe                  S[Z        Rb                  " USS
95        US:w  a  URg                  USS	9  U	(       a(  U[T        Rh                     (       a   URk                  SS	9  / nUR3                  S5       H&  nURs                  SU5        UR7                  U5        M(     U H  nURu                  U5        M     URO                  5         U$ ! [R        [T        RV                  [X        4 a     GN}f = f! [T        RV                  [        Rl                  4 a"  n[n        Rq                  SU 35         SnANSnAff = f)z
Handler conversion of a single Part of a Score with multiple Parts.
Results are added into the provided inputM21 object
or a newly created Part object

The part object is then returned.
r   r   N   FT         ?inPlace)recursezError in beaming. Ignoring: );music21r   r   Partr   SpannerBundledefinesMeasuressplitByMeasuretypingcastlist
ABCHandlermergeLeadingMetaDatalenTYPE_CHECKING
isinstanceABCHandlerBarhasNotesMeasureleftBarTokengetBarObjectleftBarlineisRepeatBracket
getByClassRepeatBracketgetByCompleteStatusnumberappendaddSpannedElementscompleteStatusrightBarTokenrightBarlineisRepeatanyparseTokenstimeSignaturebarDurationProportionpadAsAnacrusis
coreAppendcoreElementsChangedreBarABCTranslateExceptionr   MeterExceptionZeroDivisionErrorr   ClefgetElementsByClassfirstbestClefinsert	transposeTimeSignature	makeBeamsStreamExceptionenvironLocalwarn
coreInsertremove)
abcHandlerinputM21spannerBundler   pclefSetpostTranspositionmergedHandlersbarHandlersuseMeasuresbarCountmeasureNumbermhdstbLeft
rbSpannersrbbRightmermsps                         U/home/james-whalen/.local/lib/python3.13/site-packages/music21/abcFormat/translate.pyabcToStreamPartrm   ;   s    "KKM--/G 24N !!## !//1  T)*>*>%?%.%C%CK%PR % >a
 HM b"9"9::::
 2;;== .."C
 *446$&+O??2244!.!9!9':O:O "<<O<OPU<V 
 &$2237$&OO$C$C$E	%,,R0#[[)>)>
1N--c2,0) 668A=,0)+))668%'-C$ ##,,..
 "/!9!9--"//B/B5/I :#[[)>)>
1N--c2,0) MHC
 &1!%I" ;:c6>>::
 1}!2!2!>,,.4&&(!"CJ
 +
"LLu x a
 1TYY<$$V^^4::<A##}$}]]1d3AFHHQa67A	%t4q,,-	BKKK%
 
B//5	Q
		" 6 R   HO "5#7#79JK * $$f&<&<= 	B <QC@AA	Bs*   
T: U  :UU $V&V!!V&c                0   SSK Jn  SnSnU R                   GHi  n[        XtR                  5      (       a  [        XqXVU5      u  pVM/  [        XtR                  5      (       a  [        Xq5        MV  [        XtR                  5      (       aA  [        R                  (       a  UR                  c   eUR                  UR                  5        M  [        XtR                  5      (       aB  [        R                  (       a  UR                  c   eUR                  UR                  5        GM  [        XtR                  5      (       d  GM*  [        R                  (       a  UR                   c   eUR                  UR                   5        GMl     UR#                  5         XV4$ )z-
parses all the tokens in a measure or part.
r   r   F)r!   r   tokensr-   ABCMetadatametadataToM21ObjectABCNoteparseABCNoteABCSlurStartr&   r,   slurObjrD   ABCCrescStartcrescObjABCDimStartdimObjrE   )rb   rc   rZ   r_   r   r\   r[   ts           rl   r@   r@      s)    "GYYa..//)<)K*&w ,,-- 1122##yy,,,LL#2233##zz---LL$0011##xx+++LL"% & %%    c                
   SSK Jn  U R                  (       a  U R                  S   n[        R                  " SSU5      R                  5       R                  5       n[        R                  " SSU5      n[        R                  " U5      n US;   a  [        R                  " U5      nO-UR                  S5      (       a  g[        R                  " U5      nUR                  US	S
9  UR                  5         [!        XR"                  5      (       Ga  U R$                  (       d  g/ n/ nU R$                   Hq  n[!        XrR&                  5      (       d  M  UR(                  n[*        R,                  (       a  Uc   eUR/                  U5        UR/                  UR0                  5        Ms     [2        R4                  " U5      n	U R6                  U	R8                  l        U R:                  (       a  [<        R>                  " U R:                  5      n
U
R@                  c:  U
RC                  U	R8                  RD                  U	R8                  RF                  5        U	R8                  RI                  U
5        [K        [M        U	RN                  5      5       H*  nU	RN                  U   RP                  nUc  M!  Xk   Ul)        M,     UR                  U	5        gU RT                  (       a  [V        RX                  " 5       nO\[V        RZ                  " U R(                  5      nUR\                  RP                  b%  U R0                  UR\                  RP                  l)        U R6                  UR8                  l        U R:                  (       a  [<        R>                  " U R:                  5      n
U
R@                  c:  U
RC                  UR8                  RD                  UR8                  RF                  5        UR8                  RI                  U
5        U R^                  b|  U R^                  S;   a7  [^        R`                  " U R^                  5      Ul/        SUR^                  l1        O5U R^                  S:X  a%  [^        R`                  " U R^                  5      Ul/        U Rd                   H  nURg                  U5        M     U Rh                  (       a  URk                  5       n/ Ul6        [o        U Rl                  5      (       am  U Rl                  Rq                  5       nU[r        ;  a  M@  [r        U   nU" 5       nURl                  R/                  U5        [o        U Rl                  5      (       a  Mm  UR                  US	S
9  g! [         a     GNf = f)z?
Parse an ABCNote object and add it to the destination stream.
r   r   " z[()])NCzN.C.zNo ChordNone>NFsetActiveSite)startcontinuenormalstop):r!   r   chordSymbolsresublstriprstripr   cleanedFlatNotationr   NoChord
startswithChordSymbolrD   rE   
ValueErrorr-   ABCChord	subTokensrr   	pitchNamer&   r,   r9   accidentalDisplayStatusr   ChordquarterLengthdurationactiveTupletcopydeepcopydurationNormalsetDurationTypetypedotsappendTupletranger+   pitches
accidentaldisplayStatusisRestr   RestNotepitchr   TiestyleapplicableSpannersr:   inGracegetGracer   r?   pop_abcArticulationsToM21)rz   rc   r   cs_namecspitchNameListaccStatusListtSubpnc
thisTupletpIndexaccnspantokenArticulationStrm21ArticulationClassm21ArticulationObjs                     rl   rs   rs   !  s    " 	~~..#&&b'*113::<&&W-,,W5
	<<__W-##C((((1NN2UN3##%
 !''(({{ $&KKD$ 1 122^^''>)>$$R($$T%A%AB   KK&#$??

 >>q~~6J((0**1::??AJJOOLJJ##J/C		N+F))F#..C$1$9! , 	q 88		A		!++&Aww!!-343L3L""0#$??

 >>q~~6J((0**1::??AJJOOLJJ##J/ 55uu--&& ((D##A& ) 99

A!//""#$??#6#6#8 #+AA#9:N#O !5!7OO""#56 !//"" 	q.W  		s   
3U& >6U& &
U43U4c                P   U R                  5       (       a7  U R                  5       nUb!  U(       a	  XQl        X#4$ UR                  U5        X#4$ U R	                  5       (       as  U R                  5       nUb  U(       a  Xal        OUb  UR                  U5        U R                  5       u  pxUb&  Ub#  SnU(       a  Xql        OUR                  U5        UnX#4$ U R                  5       (       a;  U R                  5       n	[        R                  (       a  U	c   eUR                  U	5        X#4$ )aq  
Parse a single ABCMetadata token, that does not represent what
music21 considers metadata, such as a time signature, key signature,
clef, or tempo, and put it in dst.

This function uses coreAppend operations, so if called separately,
dst.coreElementsChanged() should be called before accessing the stream.

Returns the changed transposition and whether clef was set.
F)isMetergetTimeSignatureObjectrA   rD   isKeygetKeySignatureObjectkeySignaturegetClefObjectr   isTempogetMetronomeMarkObjectr&   r,   )
rz   rc   r\   r[   r_   tsksclefObjtranspositionmmObjs
             rl   rq   rq     s   " 	yy{{%%'>$&!8 %%5 r"4 %%3 
$$&>k!^NN2!"!2=#<G "w' - %% 
((*$$$u%%r{   c                   SSK Jn  SSK Jn  Uc  [        R                  " 5       nOUnUR                  5       nUR                  SU5        SnU R                   GH  n[        XrR                  5      (       d  M   UR                  5       (       aX  UR                  R                  SS5      R                  5       n U R                  [        R                   " SU5      5      U l        M  UR'                  5       (       aL  US:X  a#  UR)                  SUR                  5        US-  nM  UR)                  S	UR                  5        US-  nM  UR+                  5       (       a  UR)                  S
UR                  5        GM"  UR-                  5       (       a  UR)                  SUR                  5        GMV  UR/                  5       (       d  GMn  UR)                  S[1        UR                  5      5        GM     / n	U R3                  5       n
[5        U
5      S:X  a  U	R7                  U
S   5        O7[9        S[5        U
5      5       H  nU
S   X   -   nU	R7                  U5        M      / nU	 H  n[;        U5      nUR7                  U5        M!     U H  nUR=                  SU5        M     UR?                  5         U$ ! [$         a     GMg  f = f)a  
Given an abcHandler object, build into a
multi-part :class:`~music21.stream.Score` with metadata.

This assumes that this ABCHandler defines a single work (with 1 or fewer reference numbers).

if the optional parameter inputM21 is given a music21 Stream subclass, it will use that object
as the outermost object.  However, inner parts will
always be made :class:`~music21.stream.Part` objects.
r   r   )metadatazabc-versionr~   z(\d+).(\d+).?(\d+)?titler   alternativeTitlecomposerlocaleOfCompositionr8   ) r!   r   r   r   ScoreMetadatarN   ro   r-   rp   	isVersiondatareplacestripreturnAbcVersionFromMatchr   match
abcVersionAttributeErrorisTitleadd
isComposerisOriginisReferenceNumberintsplitByVoicer+   r9   r   rm   rU   rE   )rW   rX   r   r   smd
titleCountrz   vpartHandlerstokenCollectionsinewABCHandlerpartListpartHandlerrZ   s                   rl   abcToStreamScorer     sA    " LLN 
			BHHQO Ja..//{{}}FFNN="5;;=,6,P,P!7;-J) ?FF7AFF+!OJ FF-qvv6!OJz166* ,aff5 $$&&xQVV-? D L!..0
!,Q/0 q#./0A,Q/2B2EEM . 1 H#K( $ 	Q Hi & s   8+J11
K ?K c                   Uc  [         R                  " 5       nOUnU R                  5       (       a  U R                  5       nUb  X$;   a  [	        XB   5      nU$ / n[        UR                  5       5       H"  u  pg [	        U5      nUR                  U5        M$     U H  n	UR                  U	SS9  M     UR                  5          U$ UR                  [	        U 5      5        U$ ! [         a    [        R                  SU 35         M  f = f)z
Convert a multi-work stream into one or more complete works packed into an Opus Stream.

If a `number` argument is given, and a work is defined by
that number, that work is returned.
zFailure for piece number Fr   )r   OpusdefinesReferenceNumberssplitByReferenceNumberr   sorteditemsr9   
IndexErrorrS   rT   rD   rE   )
rW   rX   r8   opusabcDict	scoreListkeyvaluescscoreDocuments
             rl   abcToStreamOpusr     s    {{}
 ))++335&"3#GO4D" K I$W]]_5
I)%0B$$R( 6 "+UC "+$$& K 	$Z01K " I %%(A#&GHIs   9C!!"DDFr   c          
        U(       d  [         R                  " U 5      n SnSnU R                  [        R                  5      n[        [        U5      5       GHi  nXE   nUR                  b  UR                  nUc  [        S5      eUR                  R                  n[        R                  " UR                  5      nU=R                  U-  sl        X:  d  M  UR                  U5      u  pSU
l        UR                  R                  U
R                  :w  aF   U
R!                  5       U
l        U[        U5      S-
  :w  a  XES-      R                  c  X$US-      l        SU
l        SU
l        U	R                  S-   U
l        US-  nU R+                  [        R                  " U	R,                  U	R                  -   5      U
5        GMl     U(       d  U $ g! ["        R$                   a$  n[        SUR                   SU< SU 35      eSnAff = f)a  
Re-bar overflow measures using the last known time signature.

>>> irl2 = corpus.parse('irl', number=2)
>>> irl2.metadata.title
'Aililiu na Gamhna, S.35'
>>> music21Part = irl2[1]

The whole part is in 2/4 time, but there are some measures expressed in 4/4 time
without an explicit time signature change, an error in abc parsing due to the
omission of barlines. The method will split those measures such that they conform
to the last time signature, in this case 2/4. The default is to reBar in place.
The measure numbers are updated accordingly.

(NOTE: reBar is called automatically in abcToStreamPart, hence not demonstrated below.)

The key signature and clef are assumed to be the same in the second measure after the
split, so both are omitted. If the time signature is not the same in the second measure,
the new time signature is indicated, and the measure following returns to the last time
signature, except in the case that a new time signature is indicated.

>>> music21Part.measure(15).show('text')
{0.0} <music21.note.Note A>
{1.0} <music21.note.Note A>

>>> music21Part.measure(16).show('text')
{0.0} <music21.note.Note A>
{0.5} <music21.note.Note B->
{1.0} <music21.note.Note A>
{1.5} <music21.note.Note G>

An example where the time signature wouldn't be the same. This score is
mistakenly marked as 4/4, but has some measures that are longer.

>>> irl15 = corpus.parse('irl', number=15)
>>> irl15.metadata.title
'Esternowe, S. 60'
>>> music21Part2 = irl15.parts.first()  # 4/4 time signature
>>> music21Part2.measure(1).show('text')
{0.0} <music21.note.Note C>
{1.0} <music21.note.Note A>
{1.5} <music21.note.Note G>
{2.0} <music21.note.Note E>
{2.5} <music21.note.Note G>
>>> music21Part2.measure(1)[-1].duration.quarterLength
1.5

>>> music21Part2.measure(2).show('text')
{0.0} <music21.meter.TimeSignature 1/8>
{0.0} <music21.note.Note E>

* Changed in v5: inPlace is False by default, and a keyword only argument.
Nr   z$No time signature found in this PartzProblem with measure z (z): r   )r   r   rK   r   r0   r   r+   rA   rG   barDurationr   r   opFrachighestTimer8   splitAtQuarterLengthbestTimeSignaturer
   rR   r   r   rN   offset)music21Partr   lastTimeSignaturemeasureNumberOffsetallMeasuresmeasureIndexmusic21MeasuretsEndmEndm1m2ri   s               rl   rF   rF   =  s   n mmK000@Kc+./$2''3 . < <$'(NOO!--;;}}^778!44<#88?FB#B ,,::bnnLc')';';'=B$  3{#3a#77"!#34BBJFWL1$45C"BOBG		ABI1$v}}RYY-GH"M7 0J  ) $33 c//0E0E/FbHZZ]^_]`ac ccs   GH!H  Hc                      \ rS rSrSrg)rG   i   N)__name__
__module____qualname____firstlineno____static_attributes__r  r{   rl   rG   rG     s    r{   rG   c                      \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rSrg)Testi  c                    SSK Jn  S H@  nUR                  " 5       nUR                  U5      n[	        U5      nUR                  5         MB     g )Nr   r   r  )r!   r   ABCFilereadstrr   show)selfr   tfafahr   s         rl   	testBasicTest.testBasic  sA    %
B& ""$BBB $AFFH-
r{   c                p   SSK Jn  SSKJn  UR                  SSS4UR
                  SSS	4UR                  S
SS4UR                  SSS4UR                  SSS	44 HY  u  p4pVUR                  " 5       nUR                  U5      n[        U5      n	U R                  U	R                  R                  U5        M[     g)z/
NB -- only title is checked. not meter or key
r   r   	testFilesFyrareprisarnz3/4FzMystery ReelzC|GzThe Ale is Dearz4/4DzKitchen GirlzWilliam and Nancyz6/8N)r!   r   music21.abcFormatr$  fyrareprisarnmysteryReel	aleIsDear	kitchGirlwilliamAndNancyr  r  r   assertEqualr   r   )
r  r   r$  r  titleEncodedunused_meterEncodedunused_keyEncodedr  r  r   s
             rl   testGetMetaDataTest.testGetMetaData  s    
 	&/ $$oucB""ND#>  "3UCB  .%=&&(;UCHK
FR2 ""$BBB $AQZZ--|<K
r{   c                *   SSK Jn  SSKJn  UR                  nUR
                  " 5       n[        UR                  U5      5      nU R                  [        UR                  5      S5        U R                  [        UR                  S   R                  5       R                  5      S5        U R                  [        UR                  S   R                  5       R                  5      S5        U R                  [        UR                  S   [        R                     5      S5        UR                  S   R                  5       R                  [        R                  5      S	   R                    Vs/ s H  ofR"                  PM     nnU R                  U/ S
Q5        UR                  S   R                  5       R                  [        R                  5      S   R                    Vs/ s H  ofR"                  PM     nnU R                  U/ SQ5        g s  snf s  snf )Nr   r   r#  r   o   r             )zF#4D4B3   )E4zC#4A3)r!   r   r)  r$  r,  r  r   r  r/  r+   partsflattennotesAndRestsr   r   rK   r   nameWithOctave)r  r   r$  r  r  r   rZ   r   s           rl   
testChordsTest.testChords  s   %/   RZZ^,QWWq)QWWQZ//1??@#FQWWQZ//1??@#F 	QWWQZ45r: ,-771:+=+=+?+R+RKK,,#G,$ % ,$a!! ,$ % 34+,771:+=+=+?+R+RKK,,#G,$ % ,$a!! ,$ % 34%%s   +HHc                T   SSK Jn  SSKJn  UR                  nUR
                  " 5       n[        UR                  U5      5      nU R                  [        UR                  5      S5        U R                  [        UR                  S   R                  5       R                  5      S5        U R                  [        UR                  S   R                  5       R                  5      S5        U R                  [        UR                  S   R                  5       R                  5      S5        g )	Nr   r   r#  r<     r      r   )r!   r   r)  r$  testPrimitivePolyphonicr  r   r  r/  r+   r?  r@  rA  r  r   r$  r  r  r   s         rl   testMultiVoiceTest.testMultiVoice  s    %/.. RZZ^,QWWq)QWWQZ//1??@!DQWWQZ//1??@"EQWWQZ//1??@!Dr{   c           	        SSK Jn  SSKJn  UR                  nUR
                  " 5       n[        UR                  U5      5      n/ nUR                  5       R                   H  nUR                  UR                  5        M      / SQnU R                  Xh V	s/ s H  n	[        R                  " U	5      PM     sn	5        g s  sn	f )Nr   r   r#  )(UUUUUU?rM  rM  皙?rN  rN  rN  rN  UUUUUU?rO  rO  rO  rO  rO  $I$I?rP  rP  rP  rP  rP  rP  UUUUUU?rQ  rQ  rQ  rQ  rQ  UUUUUU?rR  rR  rR  rR  rR  rR  rR  rR  rR  rR  rR  r   )r!   r   r)  r$  testPrimitiveTupletr  r   r  r@  rA  r9   r   r/  r   r   )
r  r   r$  r  r  r   r   r   
shouldFindxs
             rl   testTupletsTest.testTuplets  s    %/** RZZ^,**ALL) +	

 	: F:aq!1: FG Fs    B=
c                @   SSK Jn  SSKJn  UR                  " 5       nUR                  UR                  5        [        U5      nUR                  S   R                  [        R                  5      R                  5       nU R                  UR                  R                  S5        U R                  UR                   R                  S5        UR"                  S   nUR"                  S   nU R                  UR%                  U5      UR&                  -   S5        U R                  UR"                  S   R(                  S5        U R                  UR%                  U5      UR&                  -   S5        U R                  UR"                  S   R(                  S5        UR                  " 5       nUR                  UR*                  5        [        U5      nUR                  S   R                  [        R                  5      R                  5       nU R                  UR                  R                  S5        U R                  UR                   R                  S	5        UR"                  S   nUR"                  S   nU R                  UR%                  U5      UR&                  -   S
5        U R                  UR"                  S   R(                  S5        U R                  UR%                  U5      UR&                  -   S5        U R                  UR"                  S   R(                  S5        g )Nr   r   r#  g      @g       @r   r   g      @g      ?g      @g      @g      @g      @)r!   r   r)  r$  r)   processhectorTheHeror   r?  rK   r   r0   rL   r/  r   r   r   rA  getOffsetBySitepaddingLeftbeattheAleWifesDaughter)r  r   r$  r  r   r  n0n1s           rl   testAnacrusisPaddingTest.testAnacrusisPadding$  sl   %/ !!#


9**+R WWQZ**6>>:@@B 	55s;22C8 a a ++B/"..@#F))!,1137++B/"..@#F))!,1137 !!#


9001R WWQZ**6>>:@@B 	55s;22C8a a ++B/"..@#F))!,1137++B/"..@$G))!,1148r{   c                   SSK Jn  SSK Jn  UR                  S5      nU R	                  UR
                  S5        U R	                  UR                  R
                  S5        UR                  " 5       nUR                  U5        UR                  5       nUR                  5         [        U5      nU R	                  [        U5      S5        g )Nr   corpusr   essenFolksong/testez	teste.abcessenFolksong   )r!   re  r   getWorkr/  nameparentr  openreadcloser   r+   )r  re  r   fpr  r  ops          rl   testOpusImportTest.testOpusImportT  s    "% ^^12+.9 
WWY

R R!$r{   c                    SSK Jn  SSKJn  UR                  nUR
                  " 5       n[        UR                  U5      5      nUc   eg )Nr   r   r#  )r!   r   r)  r$  	sicutRosar  r   r  rI  s         rl   
testLyricsTest.testLyricsf  s?     	&/   RZZ^,}}r{   c                   SSK Jn  UR                  S5      nU R                  [	        UR
                  5      S5        UR                  S5      R                  S   nU R                  UR                  S5        U R                  [	        UR                  5       R                  5      S5        UR                  S5      R                  S   nU R                  UR                  S5        U R                  [	        UR                  5       R                  5      S	5        UR                  S
5      R                  S   nU R                  UR                  S5        U R                  [	        UR                  5       R                  5      S5        UR                  S5      R                  S   nU R                  UR                  S5        U R                  [	        UR                  5       R                  5      S5        UR                  5       nU R                  UR                  R                  S5        U R                  UR                  R                  S5        U R                  [	        UR                  5      S5        U R                  UR                  S   [        R                      R#                  5       R$                  S5        U R                  UR                  S   [        R                      R#                  5       R$                  S5        U R                  UR                  S   [        R                      R#                  5       R$                  S5        U R                  UR                  S   [        R                      R#                  5       R&                  S5        U R                  UR                  S
   [        R                      R#                  5       R$                  S5        g )Nr   rd  zjosquin/milleRegretsr9  r           Z   r   P   r<  V   N   zMille regretszJosquin des Prezr'  r&  )r!   re  parser/  r+   scoresgetScoreByNumberr?  r  r@  rA  mergeScoresr   r   r   r   rJ   rL   signoctaveChange)r  re  op1p2p3p4sMergeds           rl   testMultiWorkImportedTest.testMultiWorkImportedy  s   "LL/0QXX*"((+C(RZZ\778"="((+C(RZZ\778"="((+C(RZZ\778"="((+C(RZZ\778"=--/))//A))224FGW]]+Q/q)$))4::<AA3Gq)$))4::<AA3Gq)$))4::<AA3Gq)$))4::<II2Nq)$))4::<AA3Gr{   c           	     0   SSK Jn  SSK Jn  UR                  S5      nU R	                  [        UR                  5      S5        UR                  S5      R                  S   nU R	                  UR                  S5        U R	                  [        UR                  5       R                  5      S5        U R	                  [        [        UR                  5       R                  [        R                  5      5      5      S	5        U R	                  [        UR                  5       R                  [        R                  5      5      S
   R!                  5       UR#                  S5      5        U R	                  [        UR                  5       R                  [        R                  5      5      S
   R%                  5       UR#                  S5      5        U R	                  [        UR                  5       R                  [        R                  5      5      S   R!                  5       UR#                  S5      5        U R	                  [        UR                  5       R                  [        R                  5      5      S   R%                  5       UR#                  S5      5        g )Nr   rd  r   znottingham-dataset/reelsa-cr   Q   rx  M         r>  C3   G3B2)r!   re  r   r~  r/  r+   r  r  r?  r  r@  rA  r(   rK   r   r   rootPitchbass)r  re  r   r  r  s        rl   testChordSymbolsTest.testChordSymbols  s   "!LL67QXX* #))!,C(RZZ\778"=T"**,"A"A'BUBU"VWXZ\]bjjl==g>Q>QRSTUV[[]T*	,bjjl==g>Q>QRSTUV[[]T*	, 	bjjl==g>Q>QRSTVW\\^T*	,bjjl==g>Q>QRSTVW\\^T*	,r{   c                ,   SSK Jn  SnUR                  USS9nU R                  [	        U[
        R                     5      S5        U R                  [	        U[
        R                     5      S5        [
        R                  " U5      nU R                  SUR                  [
        R                  5      R                  5       R                  5        U R                  SUR                  [
        R                  5      R                  5       R                  5        g )	Nr   	converterz
            T: No Chords
            M: 4/4
            L: 1/1
            K: C
            [| "C" C | "NC" C | "C" C | "N.C." C | "C" C
            | "No Chord" C | "C" C | "None" C | "C" C | "Other"
            C |]
            abcformat	   r9  rh  )r!   r  r~  r/  r+   r   r   r   realizeChordSymbolDurationsrK   lastr   rL   )r  r  
target_strscores       rl   testNoChordTest.testNoChord  s    %
 
59U7#6#678!<U7??34a833E:E44W5H5HI!TVMM	3E44W5H5HI"UW]]	4r{   c                    SSK Jn  / SQn/ SQn[        [        X#5      5       H  u  nu  pVUR                  " SU-   5      nUR                  5         UR                  5       nUR                  " SU-   5      nUR                  5         UR                  5       n	U R                  XHR                  5        U R                  XIR                  5        U R                  SUR                  5        U R                  SU	R                  5        M     / SQn/ S	Qn[        [        X#5      5       H  u  nu  pVUR                  " SU-   5      nUR                  5         UR                  5       nUR                  " SU-   5      nUR                  5         UR                  5       n	U R                  S
U-  UR                  5        U R                  S
U-  U	R                  5        U R                  SUR                  5        U R                  SU	R                  5        M     g )Nr   r   )Cr'  r(  AEBzF#zC#)AmEmBmzF#mzC#mzG#mzD#mzA#mzK:majorminor)r  r&  BbEbAbDbGbCb)r  DmGmCmFmBbmEbmAbmr}  )
r!   r   	enumerateziprp   preParser   r/  sharpsmode)
r  r   r  r  r   majNameminNameamks_majorks_minors
             rl   testAbcKeyImportTest.testAbcKeyImport  s   % ;E%.s5/@%A!A!&&tg~6BKKM//1H&&tg~6BKKM//1HQ0Q0Whmm4Whmm4 &B ?C%.s5/@%A!A!&&tg~6BKKM//1H&&tg~6BKKM//1HR!VX__5R!VX__5Whmm4Whmm4 &Br{   c                X   SSK Jn  UR                  S5      nU R                  [	        UR
                  5      S5        UR                  S5      nU R                  UR                  R                  S5        UR                  S5      nU R                  UR                  R                  S5        g )	Nr   rd  rf  rh  r9  zAsien, Ostasien, China, Sichuanr  zAmerika, Mittelamerika, Mexiko)	r!   re  r~  r/  r+   r  r  r   r   )r  re  r  r   s       rl   testLocaleOfCompositionImport"Test.testLocaleOfCompositionImport  s    "LL./QXX*q!779Z[q!779YZr{   c                   SSK Jn  SSKJn  UR	                  UR
                  5      nU R                  [        U[        R                     5      S5        UR	                  UR                  5      nU R                  [        U[        R                     5      S5        U R                  U[        R                     R                  5       R                  R                  S5        UR	                  UR                   5      nU R                  [        UR"                  R                  5       R%                  [&        R(                  5      R                  5       R*                  5      S5        g )Nr   r#  r  r   r<  r:  )r)  r$  r!   r  r~  morrisonsJigr/  r+   r   RepeatdraughtOfAler   r   rL   r   rB  rZ  r?  rK   r   r0   notes)r  r$  r  r   s       rl   testRepeatBracketsATest.testRepeatBracketsA  s    /%OOI223 	Qszz]+Q/
 OOI223Qszz]+Q/499++-33BBDI OOI334QWW]]_??OUUW]]^`abr{   c                   SSK Jn  SSKJn  SSKJn  UR                  UR                  5      nU R                  [        U[        R                     5      S5        UR                  UR                  5      nU R                  [        U[        R                     5      S5        UR                  S5      nU R                  [        U[        R                     5      S5        g )Nr   r#  r  rd  r   r9  JollyTinkersReel)r)  r$  r!   r  re  r~  r  r/  r+   r   r6   rZ  )r  r$  r  re  r   s        rl   testRepeatBracketsBTest.testRepeatBracketsB  s    /%"OOI223Qw4456: OOI334Qw4456:LL+,Qw4456:r{   c                   SSK Jn  SSKJn  UR	                  UR
                  5      nUR                  5       R                  [        R                  5      nU R                  [        U5      S5        U R                  [        US   5      S5        UR	                  UR                  5      nUR                  5       R                  [        R                  5      nU R                  [        U5      S5        U R                  [        US   5      S5        UR	                  UR                  5      nU[        R                     nU R                  [        U5      S5        U R                  [        US   5      S5        g )	Nr   r#  r  r   z)<music21.tempo.MetronomeMark Quarter=100>r   z)<music21.tempo.MetronomeMark Quarter=211>z1<music21.tempo.MetronomeMark maestoso Quarter=90>)r)  r$  r!   r  r~  fullRiggedShipr@  rK   r   TempoIndicationr/  r+   strr,  theBeggerBoy)r  r$  r  r   mmStreams        rl   testMetronomeMarkATest.testMetronomeMarkA!  s   /%OOI44599;11%2G2GHX*Xa[)+VWOOI//099;11%2G2GH 	X*Xa[)+VWOOI223U**+ 	X*Xa[)+^_r{   c                N    SSK Jn  S H  nUR                  U5      nUb  M   e   g )Nr   rd  )zToCashellImGoingJig.abczSundayIsMyWeddingDayJig.abczSinkHimDoddieHighlandFling.abczRandyWifeOfGreenlawReel.abczPassionFlowerHornpipe.abczNightingaleClog.abczMountainRangerHornpipe.abczLadiesPandelettsReel.abczJauntingCarHornpipe.abczGoodMorrowToYourNightCapJig.abczChandlersHornpipe.abcz"AlistairMaclalastairStrathspey.abcr!   re  r~  r  re  fnr   s       rl   testTranslateATest.testTranslateA9  s-     	#
B R A= =
r{   c                   SSK Jn  [        R                  " SSSS9nU R	                  UR                  5       UR                  S5      5        U R                  UR                  S   UR                  5       5        [        R                  " S5      nU R	                  UR                  5       UR                  S	5      5        U R	                  UR                  5       UR                  S5      5        U R	                  UR                  S   UR                  S5      5        [        R                  " S
5      nU R	                  UR                  5       UR                  S
5      5        U R	                  UR                  S   UR                  S5      5        U R	                  UR                  S   UR                  S5      5        [        R                  " S5      nU R	                  UR                  5       UR                  S5      5        U R	                  UR                  S   UR                  S5      5        U R	                  UR                  S   UR                  S5      5        U R	                  UR                  S   UR                  S5      5        g )Nr   r  ebbbdominant)r  r  kindzB-2ze-7/b-zE-3zb-3zB-3r   r:  bb3b2r  D3r   zF#3)
r!   r   r   r   r/  r  r  assertIsr   r  )r  r   r   s      rl   testCleanFlatTest.testCleanFlatP  s   !  dJGEKK$67bjjmRWWY/  *EKK$67EKK$67AE(:;
   'EKK$67AE(:;AD(9:  'EKK$56AD(9:AD(9:AE(:;r{   c                N    SSK Jn  S H  nUR                  U5      nUb  M   e   g)zN
Dylan -- this could be too slow to make it a test!

Numbers 637 and 749 fail
r   rd  )zairdsAirs/book4.abcNr  r  s       rl   xtestTranslateBTest.xtestTranslateBl  s)     	#)BR A= = *r{   c                0    SSK Jn  UR                  SSS9ng )Nr   rd  zhan2.abci  )r8   r  r  re  unuseds      rl   testTranslateBrokenDuration Test.testTranslateBrokenDurationz  s    "j5r{   c                    SSK Jn  UR                  SSS9nUR                  5       R                   Vs/ s H  o3R
                  R                  PM     nnU R                  U/ SQ5        g s  snf )Nr   r  zL:1/8
a-a-ar  r  )r   r   r   )r!   r  r~  r@  rA  r   r   assertListEqual)r  r  r  r   tiess        rl   testTiesTranslateTest.testTiesTranslate~  sV    %u=$)MMO$A$AB$Aq

$ABT#@A Cs   A)c                2    SSK Jn  UR                  S5      ng )Nr   rd  z0josquin/laDeplorationDeLaMorteDeJohannesOckeghemr  r  s      rl   xtestMergeScoresTest.xtestMergeScores  s    "PQr{   r  N)r  r  r  r  r   r3  rC  rJ  rV  ra  rq  ru  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r{   rl   r  r    s{    <=,58E&H0.9`%$	& HH,.42!5H
[c*;`0!.<8
!6BRr{   r  __main__)NN)rW   abcFormat.ABCHandlerrX   zstream.Part | NonerY   zspanner.SpannerBundle | Nonereturnstream.Part)
rb   r  rc   stream.Measure | stream.PartrZ   r  r_   boolr  tuple[int, bool])rz   zabcFormat.ABCNoterc   r  r  r   )rz   zabcFormat.ABCMetadatarc   r  r\   r   r[   r  r_   r  r  r  )N).__doc__
__future__r   r   unittestr   r&   r!   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   r,   r   EnvironmentrS   StaccatoUpBowDownBowAccentStrongAccentTenutor   rm   r@   rs   rq   r   r   rF   Music21ExceptionrG   TestCaser  r  mainTestr  r{   rl   <module>r     s   #   	  !              	! &&'<= &&  $$""!..""  "&04$ . 	D"&"&	#"& "& 	"&
 "&Hf/f/	#f/ 
f/R2&2&	#2& 2& 	2&
 2& 2&jUn$N #( bJ	L99 	
_R8 _RF zT r{   