
    rh9                       S r SSKJ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  \	R                   " S5      r " S S\
R$                  5      r\R(                  " SS5      r " S S\R,                  5      r " S S\R0                  5      r " S S\R0                  5      r " S S\R0                  5      rS\\\/rS\R:                  \R<                  \/rSr Sr!Sr"Sr#\"\#-   r$\$RK                  5       r&\$\&-   r'SS .S! jr(SS".S# jr) " S$ S%\RT                  5      r+\,S&:X  a  SSKr\RZ                  " \+S'5        gg)(a'  
The Volpiano font is a specialized font for encoding Western Plainchant
easily with immediate visual feedback (see the CANTUS database).

This module parses chants encoded in Volpiano and can generate Volpiano
from any music21 Stream.

This module will move to a medren package hopefully by v7
    )annotationsN)bar)base)clef)environment)exceptions21)layout)note)pitch)spanner)streamzvolpiano.pyc                      \ rS rSrSrg)VolpianoException'    N)__name__
__module____qualname____firstlineno____static_attributes__r       J/home/james-whalen/.local/lib/python3.13/site-packages/music21/volpiano.pyr   r   '   s    r   r   
ErrorLevelzWARN LOGc                      \ rS rSrSrSrg)Neume0   zT
A spanner that represents a Neume.  No name of the neume, just that it is a Neume.
r   Nr   r   r   r   __doc__r   r   r   r   r   r   0   s    r   r   c                      \ rS rSrSrSrg)	LineBreak6   zT
Indicates that the line breaks at this point in the manuscript.

Denoted by one 7.
r   Nr   r   r   r   r    r    6       
 	r   r    c                      \ rS rSrSrSrg)	PageBreak?   zT
Indicates that the page breaks at this point in the manuscript

Denoted by two 7s.
r   Nr   r   r   r   r$   r$   ?   r"   r   r$   c                      \ rS rSrSrSrg)ColumnBreakH   zV
Indicates that the page breaks at this point in the manuscript

Denoted by three 7s.
r   Nr   r   r   r   r'   r'   H   r"   r   r'   9abcdefghjklmnopqrsz)ABCDEFGHJKLMNOPQRSwxiyzF)breaksToLayoutc                  [         R                  " 5       n[         R                  " 5       nUnSnSn[        R                  " 5       nSnSn	Sn
U  GHV  nUS:X  a  US-  nM  US:  aF  U(       d  [
        U   nU" 5       nO[        U   nUS:  a  U" SS9nOU" 5       nUR                  U5        SnUS	:X  a  SnU(       a  UR                  U5        SnM  US
;   a  SnSnUS;   aF  US:X  a  [        R                  " 5       nO[        R                  " 5       nUnUR                  U5        M  US;   aQ  [        R                  " 5       nUS:X  a  SUl        Xl        UR                  U5        [         R                  " 5       nGM0  U[        ;   d  U[        ;   GaZ  [        R                   " 5       nSUl        U[        ;   a*  [        R%                  U5      S-
  nSUR&                  l        O0[        R%                  U5      S-
  nSUl        SUR&                  l        UR,                  nUU-   nUUR.                  l        UR.                  R2                  S:X  a-  U	(       a&  [.        R4                  " S5      UR.                  l        OFUR.                  R2                  S:X  a,  U
(       a%  [.        R4                  " S5      UR.                  l        UR                  U5        Ub  [9        UU/5      nSnGM  UnGM  U[:        ;   d  GM  UR=                  5       [>        ;   a  U[@        ;   a  Sn
GM  UR=                  5       [B        ;   a  U[@        ;   a  Sn	GM  UR=                  5       [>        ;   a  U[D        ;   a  Sn
GM!  UR=                  5       [B        ;   a  U[D        ;   a  Sn	GMH  [G        SU-   S-   5      e   US:  a!  [
        U   nU" 5       nUR                  U5        U(       a  UR                  U5        U$ )aP  
Returns a music21 Part from volpiano text.

>>> veniSancti = volpiano.toPart('1---c--d---f--d---ed--c--d---f'
...                              + '---g--h--j---hgf--g--h---')
>>> veniSancti.show('text')
{0.0} <music21.stream.Measure 0 offset=0.0>
    {0.0} <music21.clef.TrebleClef>
    {0.0} <music21.note.Note C>
    {1.0} <music21.note.Note D>
    {2.0} <music21.note.Note F>
    {3.0} <music21.note.Note D>
    {4.0} <music21.note.Note E>
    {5.0} <music21.note.Note D>
    {6.0} <music21.volpiano.Neume <music21.note.Note E><music21.note.Note D>>
    {6.0} <music21.note.Note C>
    {7.0} <music21.note.Note D>
    {8.0} <music21.note.Note F>
    {9.0} <music21.note.Note G>
    {10.0} <music21.note.Note A>
    {11.0} <music21.note.Note B>
    {12.0} <music21.note.Note A>
    {13.0} <music21.note.Note G>
    {14.0} <music21.note.Note F>
    {15.0} <music21.volpiano.Neume <music21.note.Note A><music21.note.Note G>>
    {15.0} <music21.note.Note G>
    {16.0} <music21.note.Note A>

Clefs!

>>> clefTest = volpiano.toPart('1---c--2---c')
>>> clefTest.show('text')
{0.0} <music21.stream.Measure 0 offset=0.0>
    {0.0} <music21.clef.TrebleClef>
    {0.0} <music21.note.Note C>
    {1.0} <music21.clef.BassClef>
    {1.0} <music21.note.Note E>
>>> for n in clefTest.recurse().notes:
...     n.nameWithOctave
'C4'
'E2'

Flats and Naturals:

>>> accTest = volpiano.toPart('1---e--we--e--We--e')
>>> [n.name for n in accTest.recurse().notes]
['E', 'E-', 'E-', 'E', 'E']

Breaks and barlines

>>> breakTest = volpiano.toPart('1---e-7-e-77-e-777-e-3-e-4')
>>> breakTest.show('text')
{0.0} <music21.stream.Measure 0 offset=0.0>
    {0.0} <music21.clef.TrebleClef>
    {0.0} <music21.note.Note E>
    {1.0} <music21.volpiano.LineBreak object at 0x105250fd0>
    {1.0} <music21.note.Note E>
    {2.0} <music21.volpiano.PageBreak object at 0x105262128>
    {2.0} <music21.note.Note E>
    {3.0} <music21.volpiano.ColumnBreak object at 0x105262240>
    {3.0} <music21.note.Note E>
    {4.0} <music21.bar.Barline type=regular>
{4.0} <music21.stream.Measure 0 offset=4.0>
    {0.0} <music21.note.Note E>
    {1.0} <music21.bar.Barline type=double>


As layout objects using breaksToLayout=True

>>> breakTest = volpiano.toPart('1---e-7-e-77-e-777-e-3-e-4', breaksToLayout=True)
>>> breakTest.show('text')
{0.0} <music21.stream.Measure 0 offset=0.0>
    {0.0} <music21.clef.TrebleClef>
    {0.0} <music21.note.Note E>
    {1.0} <music21.layout.SystemLayout>
    {1.0} <music21.note.Note E>
    {2.0} <music21.layout.PageLayout>
    {2.0} <music21.note.Note E>
    {3.0} <music21.volpiano.ColumnBreak object at 0x105262240>
    {3.0} <music21.note.Note E>
    {4.0} <music21.bar.Barline type=regular>
{4.0} <music21.stream.Measure 0 offset=4.0>
    {0.0} <music21.note.Note E>
    {1.0} <music21.bar.Barline type=double>


Liquescence test:

>>> breakTest = volpiano.toPart('1---e-E-')
>>> breakTest.recurse().notes[0].editorial.liquescence
False
>>> breakTest.recurse().notes[0].notehead
'normal'
>>> breakTest.recurse().notes[1].editorial.liquescence
True
>>> breakTest.recurse().notes[1].notehead
'x'

* Changed in v5.7: corrected spelling of liquescence.
Nr   F7      T)isNew-1234121344doublenoStem   xBflatEzUnknown accidental: z: Should not happen)$r   PartMeasurer   
TrebleClefclassByNumBreakTokensclassByNumBreakTokensLayoutappendBassClefr   BarlinetyperightBarlinenormalPitchesliquescentPitchesr
   NotestemDirectionindex	editorialliquescencenotehead
lowestLiner   diatonicNoteNumstep
Accidental
accidentalr   accidentalTokenslowereflatTokensnaturalTokensbflatTokens
flatTokensr   )volpianoTextr,   pmcurrentMeasurecurrentNeumeSpannernoteThatWouldGoInSpannerlastClefcontinuousNumberOfBreakTokensbIsFlateIsFlattoken
breakClass
breakTokencblndistanceFromLowestLineclefLowestLinerR   s                       r   toPartrn   ^   sO   L 	AAN# H$%! GGC<)Q.)*Q.!23PQ
'\
89VW
014!+$!7J!+J!!*-()%C<'+$"%%&9:&*#F?'+$"&D=|OO%MMOHHHQKd]B|"NHHQK Am#u0A'A		A&AO%)6)<)<U)Ca)G&*/'):)@)@)G!)K& 
*.'%00N,/EEO&5AGG#ww||s"w%*%5%5f%="$%*%5%5f%="HHQK'3&+-Eq,I&J#+/(+,(&&{{}+0F+-%=2H+-%:2E+-%:2E'*U25JJL Lm t %q(*+HI
\
j)	Hr   )layoutToBreaksc                 ^^^^ / m[         R                  4S jmU4S jmU4S jnSSSSSS	.mS-UUU4S jjn[        R                  " 5       nS
nS
nU R	                  5        GH  nUR
                  nSU;   a;  UnSU;   a
  T" S5        M(  SU;   a
  T" S5        M8  T" U[         R                  5        MQ  SU;   a$  UR                  S;   a
  T" S5        Mq  T" S5        M{  SU;   Gac  Un	U	R                  n
U
R                  nXR                  -
  nUS-   nUS:  d  U[        [        5      :  a  T" U	[         R                  5        M  U	R                  S:X  d<  U	R                  (       a5  SU	R                  ;   a%  U	R                  R                   (       a
  ["        U   nO	[        U   nU
R$                  b  U
R$                  R&                  S:w  a  U
R(                  S;  a"  T" U[         R                  5        T" U5        GM  U
R$                  R&                  S:w  a"  T" U[         R                  5        T" U5        GM  U
R(                  S:X  a  U(       d  U" U5        SnOcU
R(                  S:X  a  U(       d
  U" U5        SnOAU
R*                  S:X  a  U(       a
  U" USS9  S
nO U
R*                  S:X  a  U(       a	  U" USS9  S
nT" U5        U	R-                  S5      nU(       a  XS   R/                  5       La  GM  U	R0                  (       d  T" S 5        GM  U	R2                  S   nUR4                  nUS!;   a  T" S"5        GM  T" S#5        GM  S$U;   a  U(       a  U" 5         T" S%5        GM  S&U;   a  U(       a  U" 5         T" S'5        GM#  S(U;   a  U" 5         T" S%5        GM;  S)U;   a  U" 5         T" S'5        GMS  S*U;   a  U" 5         T" S+5        GMk  T" U[         R                  5        GM     S,R7                  T5      $ ).a  
Convert a Stream to Volpiano.

These tests show how the same input converts back out:

>>> volpianoInput = '1--c--d---f--d---ed--c--d---f---g--h--j---hgf--g--h---'
>>> veniSancti = volpiano.toPart(volpianoInput)
>>> volpiano.fromStream(veniSancti)
'1---c-d-f-d-ed-c-d-f-g-h-j-hg-f-g-h-'

>>> breakTest = volpiano.toPart('1---e-E--')
>>> volpiano.fromStream(breakTest)
'1---e-E-'

>>> accTest = volpiano.toPart('1---e--we--e--We--e')
>>> volpiano.fromStream(accTest)
'1---e-we-e-We-e-'
c                    SU < S3nU[         R                  :X  a  [        R                  US-   5        g [        R	                  U5        g )NzCould not convert token z to Volpiano.z! this can lead to incorrect data.)r   WARNenvironLocalwarn
printDebug)innerEl
errorLevelmsgs      r   errorfromStream.<locals>.errorM  s>    (=A(c$GGH##C(r   c                :   > U  H  nTR                  U5        M     g N)rD   )tokenstvolpianoTokenss     r   apfromStream.<locals>.apT  s    A!!!$ r   c                 p   > T (       a.  T S   S:X  a$  T R                  5         T (       a  T S   S:X  a  M"  g g g g )Nr2   )pop)r   s   r   
popHyphensfromStream.<locals>.popHyphensX  s6    !3s!:  !3s!:n!:nr   ywir;   z)r            Fc                   > U T;  a  T" U  S3[         R                  5        g TU    nU(       a  UR                  5       nT" U5        g )Nz above lowest line)r   rr   upper)dist
setNaturalaccidentalTokenr   distToAccidentalry   s      r   setAccFromPitch#fromStream.<locals>.setAccFromPitche  sH    ''TF,-z?*40-335O
?r   ClefrA   z1---rE   z2---rF   )r8   finalz---4z---3rK   r:   r   rO   )r<   r>   r   r<   Tr>   )r   r   r2   )singleendz---z--SystemLayoutz7---
PageLayoutz77---r    r$   r'   z777--- )F)r   LOGr   rA   recurseclassesrr   rG   r   rR   rQ   lenrI   rP   hasEditorialInformationrN   rO   rJ   rU   alterrS   namegetSpannerSitesgetLastlyriclyricssyllabicjoin)sro   r   r   rb   rd   re   el	elClassesrk   r]   dnnrl   indexInPitchString	tokenNameneumeSpannerlyricObjectsylr   r   ry   r   s                     @@@@r   
fromStreamr   7  sC   ( N",.. )%!    HGGiikJJ	YHy(6
y(6
b*//*)#ww--6
6
y AA##C%(+>+>%>"!7!!;!A%);s=?Q)Qa)zzS Q%>%>*71;;*F*+++*A*A-.@A	)*<=	||'ALL,>,>!,C66+"joo.yM\\''2-"joo.yM66S=#$:;"GVVs]7#$:;"G37 64H37 64HyM,,W5La)@)@)B BWW3hhqk!**++uItHy(^LvJY&>LwKI%LvJI%LwKi'LxL"jnn%o r 77>""r   c                      \ rS rSr S rSrg)Testi  c                    g r|   r   )selfs    r   testNoteNamesTest.testNoteNames  s    r   r   N)r   r   r   r   r   r   r   r   r   r   r     s
    r   r   __main__importPlusRelative).r   
__future__r   enumunittestmusic21r   r   r   r   r   r	   r
   r   r   r   Environmentrs   Music21Exceptionr   Enumr   Spannerr   Music21Objectr    r$   r'   rB   r   r   rC   rI   rJ   rX   rZ   r[   r   rY   rV   rn   r   TestCaser   r   mainTestr   r   r   <module>r      s^   #             &&}5	55 	 YY|Z0
GOO 	"" 		"" 		$$$ 	 y)[A #V%8%8&:K:K[Y %) ;&
  "-  ,1 Ur %* U#r8  zT/0 r   