o
    ©›f¸Œ  ã                   @   sZ  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZ	dZ
dZdZdZdZdZdZd	Zd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'd Z(d!Z)d"Z*d#Z+eeeeiZ,eee*e)ee+e$fZ-eeeeeeee!e$ee)e*eegZ.ee'd$iee d%ed&ed'e%d(e&d)ed*ieed+ie#e(d,iiZ/d-d.„ Z0d/Z1d0Z2d1Z3d2d3„ Z4e 5d4ej6¡Z7e 5d5ej6¡Z8e 5d6¡Z9e 5d7¡Z:d8d9„ Z;G d:d;„ d;e<ƒZ=G d<d=„ d=ƒZ>G d>d?„ d?e>ƒZ?G d@dA„ dAe>ƒZ@G dBdC„ dCe@ƒZAG dDdE„ dEe@ƒZBe 5dFej6¡ZCe 5dGej6¡ZDG dHdI„ dIeBƒZEG dJdK„ dKeEƒZFG dLdM„ dMe@ƒZGeEeBeBeAeGeFdNœZHdS )Oé    NZafterZaltZbeforeZdoctitleZexampleindentÚfilenameÚfilterZfragmentZlayoutú
line-widthZ
nofragmentZ	nogettextZnoindentÚindentZinlineznoragged-rightÚbodyZnotimeÚoutputZoutputimageZpaperzpaper-heightZ	papersizezpaper-widthZparaZpreambleZprintfilenameZquotezragged-rightÚrelativeÚ	staffsizeZtexidocZverbatimÚlilypondversionz\relative c%(relative_quotes)sz#(set-paper-size %(papersize)s)zindent = %(indent)szÎline-width = %(line-width)s
  %% offset the left padding, also add 1mm as lilypond creates cropped
  %% images with a little space on the right
  line-width = #(- line-width (* mm  %(padding_mm)f) (* mm 1))zèline-width = %(line-width)s - 2.0 * %(exampleindent)s
  %% offset the left padding, also add 1mm as lilypond creates cropped
  %% images with a little space on the right
  line-width = #(- line-width (* mm  %(padding_mm)f) (* mm 1))zragged-right = ##tzragged-right = ##fze
 \context {
   \Score
   timing = ##f
 }
 \context {
   \Staff
   \remove Time_signature_engraver
 }z&#(set-global-staff-size %(staffsize)s)c                 C   s¬   | dkrt |fS | dkr|d u rtd fS t d| ¡}|r#d| d¡fS t d| ¡}|r2d| d¡fS | dks:| d	krTt d
|¡}|rTt| d¡ƒ}| d|| d¡f fS dS )NZ	lilyquoteZ
singlelinezrelative\s*([-0-9])r   é   z
([0-9]+)ptr	   r   r   z%([-.0-9]+)(cm|in|mm|pt|bp|staffspace)z%f\%sé   )NN)ÚQUOTEÚRAGGED_RIGHTÚreÚsearchÚgroupÚmatchÚfloat)ÚkeyÚvalueÚmÚf© r   úb/home/lily/lilypond-2.24.4/release/binaries/mingw/lilypond/lilypond-2.24.4/python/book_snippets.pyÚ#classic_lilypond_book_compatibility¡   s    r   a~  %%%% Generated by lilypond-book
%%%% Options: [%(option_string)s]
\include "lilypond-book-preamble.ly"


%% ****************************************************************
%% Start cut-&-pastable-section
%% ****************************************************************

%(padding_mm_string)s

%(preamble_string)s

\paper {
  %(paper_string)s
}

\layout {
  %(layout_string)s
}

a?  


%% ****************************************************************
%% ly snippet:
%% ****************************************************************
%(code)s


%% ****************************************************************
%% end ly snippet
%% ****************************************************************
ae  
%(notes_string)s
{


%% ****************************************************************
%% ly snippet contents follows:
%% ****************************************************************
%(code)s


%% ****************************************************************
%% end ly snippet
%% ****************************************************************
}
c                 C   s2   t | dƒ d¡}t d|¡}|rt| d¡ƒS dS )NÚrbi   s   
%%Pages: ([0-9]+)r   r   )ÚopenÚreadr   r   Úintr   )Zps_nameÚheaderr   r   r   r   Úps_page_countô   s
   r    z^([a-zA-Z]+)[\t ]*=z(%+[\t ]*)(.*)$zy\\(?:new|context)\s+(?:[a-zA-Z]*?(?:Staff(?:Group)?|Voice|FiguredBass|FretBoards|Names|Devnull))\s+=\s+"?([a-zA-Z]+)"?\s+z1^([0-9]+\.?[0-9]*|\.[0-9]+)\s*\\(cm|mm|in|pt|bp)$c                 C   s   |  d¡| |  d¡ƒ S )Nr   r   )r   )Útr   r   r   r   Úly_comment_gettext  s   r"   c                   @   s   e Zd ZdS )ÚCompileErrorN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r#     s    r#   c                   @   sH   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	efd
d„Zdefdd„Z	dS )ÚChunkc                 C   ó   dS ©NÚ r   ©Úselfr   r   r   Úreplacement_text  ó   zChunk.replacement_textc                 C   s   |   ¡ S ©N)r-   r+   r   r   r   Úfilter_text  s   zChunk.filter_textc                 C   r(   )NFr   r+   r   r   r   Úis_plain  r.   zChunk.is_plainc                 C   s
   d| _ d S r)   ©Z_output_fullpathr+   r   r   r   Ú__init__  ó   
zChunk.__init__Úout_fpc                 C   s
   || _ d S r/   r2   )r,   r5   r   r   r   Úset_output_fullpath  r4   zChunk.set_output_fullpathÚreturnc                 C   ó   | j S )z0The output file path that this chunk belongs to.r2   r+   r   r   r   Úoutput_fullpath   s   zChunk.output_fullpathN)
r$   r%   r&   r-   r0   r1   r3   Ústrr6   r9   r   r   r   r   r'     s    r'   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú	Substringú,A string that does not require extra memory.c                 C   s"   || _ || _|| _|| _d | _d S r/   )ÚsourceÚstartÚendÚline_numberÚoverride_text)r,   r=   r>   r?   r@   r   r   r   r3   (  s
   
zSubstring.__init__c                 C   r(   )NTr   r+   r   r   r   r1   /  r.   zSubstring.is_plainc                 C   s   | j r| j S | j| j| j… S r/   )rA   r=   r>   r?   r+   r   r   r   r-   2  s   zSubstring.replacement_textN)r$   r%   r&   Ú__doc__r3   r1   r-   r   r   r   r   r;   %  s
    r;   c                   @   ó4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚSnippetc                 C   sB   || _ || _d| _i | _|| _|| _|| _|jd tj	dœ| _
d S )Nr   Úprogram_version)rE   Úprogram_name)Útyper   ÚchecksumÚoption_dictÚ	formatterr@   Úglobal_optionsÚinformationÚlyrF   Úreplacements©r,   rG   r   rJ   r@   rK   r   r   r   r3   :  s   ÿzSnippet.__init__c                 C   s   t   | j¡S r/   )ÚcopyrN   r+   r   r   r   Úget_replacementsG  ó   zSnippet.get_replacementsc                 C   s   | j  d¡S )Nr   ©r   r   r+   r   r   r   r-   J  rR   zSnippet.replacement_textc                 C   ó   | j  |¡S r/   rS   ©r,   Úsr   r   r   Ú	substringM  rR   zSnippet.substringc                 C   s   t | jƒd | j S )Nz type = )ÚreprÚ	__class__rG   r+   r   r   r   Ú__repr__P  s   zSnippet.__repr__N)r$   r%   r&   r3   rQ   r-   rW   rZ   r   r   r   r   rD   9  s    rD   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚIncludeSnippetc                 C   s"   |   d¡}tj |¡d | jj S )Nr   r   )rW   ÚosÚpathÚsplitextrJ   Zdefault_extension)r,   r   r   r   r   Úprocessed_filenameU  s   
z!IncludeSnippet.processed_filenamec                 C   s(   | j  d¡}|  d¡}t ||  ¡ |¡S )Nr   r   )r   r   rW   r   Úsubr_   )r,   rV   r   r   r   r   r-   Y  s   
zIncludeSnippet.replacement_textN)r$   r%   r&   r_   r-   r   r   r   r   r[   T  s    r[   c                   @   sä   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZeZdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'ed(ed)efd*d+„Zd)efd,d-„Zd.d/„ Zd0d1„ Zd2d3„ Zd4S )5ÚLilypondSnippetc                 C   s<   t  | |||||¡ d| _d| _| d¡}|  || j¡ d S )Nr*   ú.lyÚoptions)rD   r3   r   Úextr   Úparse_snippet_optionsrG   )r,   rG   r   rJ   r@   rK   r\   r   r   r   r3   `  s   ÿ
zLilypondSnippet.__init__c                 C   ó   g S r/   r   r+   r   r   r   Úsnippet_optionsh  r.   zLilypondSnippet.snippet_optionsc                    s®   | j j}|s|S ztj| ‰ W n   | Y S t ‡ fdd„|¡}tj| jrUt 	|¡D ]}t
 d| dˆ |ƒ d |¡}q,t 	|¡D ]}t
 d| dˆ |ƒ d |¡}qC|S )Nc                    s
   t ˆ | ƒS r/   )r"   )r   ©r!   r   r   Ú<lambda>z  s   
 z1LilypondSnippet.verb_ly_gettext.<locals>.<lambda>z'(?m)(?<!\\clef)(^|[' \\#])%s([^a-zA-Z])z\1z\2z(\s+|")%s(\s+|"))rJ   Údocument_languageZlangdefsZtranslationÚly_comment_rer`   ZLANGDICTZenable_ly_identifier_l10nÚly_var_def_reÚfindallr   Úly_context_id_re)r,   rV   ZlangÚvÚidr   rh   r   Úverb_ly_gettextk  s(   
þ
þzLilypondSnippet.verb_ly_gettextc                 C   s4   |   d¡}t| jvr|  |¡}| d¡s|d7 }|S )NÚcodeÚ
)rW   Ú	NOGETTEXTrI   rq   Úendswith)r,   Z	verb_textr   r   r   Úverb_ly‡  s   



zLilypondSnippet.verb_lyc                 C   s   |   d¡}d| jd |f S )Nrr   z\sourcefileline %d
%sr   )rW   r@   )r,   Úcontentsr   r   r   rM     s   
ÿzLilypondSnippet.lyc                 C   s   |   ¡ }|r|  |¡S dS r)   )rM   Ú
compose_lyrU   r   r   r   Úfull_ly”  s   
zLilypondSnippet.full_lyc                 C   rT   r/   )rJ   Zsplit_snippet_options)r,   Úoption_stringr   r   r   Úsplit_optionsš  rR   zLilypondSnippet.split_optionsc                 C   s¶  i | _ |  |¡}|D ]g}|d }}d|v rt d|¡\}}n|tv r1t| | jv r1| j t| = d }t||ƒ\}}|rj|rSt t	dƒ||f ¡ t t	dƒ||f ¡ nt t	dƒ| ¡ t t	dƒ| ¡ ||}}|rq|| j |< q
t
| j v rƒd| j t
  d | j t
< t| j v }	t| j v }
|	s‘|
rô|
s˜d| j t< |	sŸd	| j t< | j t }t t|¡}|rµ| d
d¡\}}nt t	dƒt|f ¡ d\}}| j t }t t|¡}|rÚ| d
d¡\}}nt t	dƒt|f ¡ d\}}d||||f | j t
< t| j v }|r| j t d u r| j t= t| j v rd | j t< tdi| _| j | jj¡ | j | j ¡ dd„ t| j ¡ ƒD ƒ}g }|D ]\}}|d u rG| |¡ q7| |d | ¡ q7| ¡  || _d S )Nú=z\s*=\s*z deprecated ly-option used: %s=%sz%compatibility mode translation: %s=%szdeprecated ly-option used: %sz"compatibility mode translation: %sú"z297\mmz210\mmr   r   zignoring invalid option %s=%s)Z210Úmm)Z297r~   z'(cons (* %s %s) (* %s %s))z0\mmc                 S   s   g | ]
}|d  t vr|‘qS )r   )ÚPROCESSING_INDEPENDENT_OPTIONS)Ú.0Zx_yr   r   r   Ú
<listcomp>ø  s    ÿz9LilypondSnippet.parse_snippet_options.<locals>.<listcomp>)Zsnippet_option_dictr{   r   ÚsplitÚ
no_optionsrI   r   rM   ÚwarningÚ_Ú	PAPERSIZEÚPAPER_WIDTHÚPAPER_HEIGHTr   Úly_dimen_rer   Ú
LINE_WIDTHÚRELATIVEÚFRAGMENTÚINDENTÚupdaterJ   Údefault_snippet_optionsÚiterÚitemsÚappendÚsortÚoutputrelevant_option_list)r,   rz   rG   rc   Úoptionr   r   Zc_keyZc_valueZhas_paper_widthZhas_paper_heightZwdr   ÚwZw_unitZhtÚhZh_unitZhas_line_widthZlstZoption_listr   r   r   re     s’   

ÿÿ
ÿ
ÿ

€
ÿ





ÿ

ÿÿ




z%LilypondSnippet.parse_snippet_optionsc                 C   r8   r/   )r”   r+   r   r   r   Ú!get_outputrelevant_option_strings  s   z1LilypondSnippet.get_outputrelevant_option_stringsc                 C   sN  d}i }d|t < d|t< | | jj¡ | jj|d< d |  ¡ ¡}i }t	t
ttg}|D ]}g ||< q*t| j ¡ ƒ}|D ]G}	| j|	 }
|
rH|
||	< n|	|vrPd ||	< d}|D ]}|	t| v rk||  t| |	 ¡ d} nqT|s|	tvr|	|  ¡ vrt tdƒ|	 ¡ q:t|v r|t rt|t ƒ}d}|dk rž|d|  7 }n
|dkr¨|d	| 7 }t|v r°d
|d< t|t ƒD ]\}}| d¡rÎ|t  d|t  |¡¡  nq¶d |t ¡| }d |t ¡| }d |t	 ¡tƒ  }d |t
 ¡| }|d }|dkrd| }nd}tƒ  ¡ }| t ƒ ¡ | | jj!¡ t"| jv rt#}nt$}t%| | S )Nr   z0.4\inz5\inÚ
padding_mmú,r   zignoring unknown ly option: %sr*   ú'g-Cëâ6?z#(set-paper-sizez
  z$#(ly:set-option 'eps-box-padding %f))&ÚEXAMPLEINDENTrŠ   rŽ   rJ   r   rK   r™   Újoinr˜   ÚNOTESÚPREAMBLEÚLAYOUTÚPAPERÚsortedrI   Úkeysrg   r’   Úsimple_optionsrM   r„   r…   r‹   r   ÚINLINEÚ	enumerateÚ
startswithÚinsertÚpopÚvarsÚglobalsrP   ÚlocalsrL   rŒ   ÚFRAGMENT_LYÚFULL_LYÚPREAMBLE_LY)r,   rr   r   Úoverriderz   Zcompose_dictZcompose_typesÚaZoption_namesr   r   ÚfoundÚtypZrelative_quotesÚiÚelemZpaper_stringZlayout_stringZnotes_stringZpreamble_stringr™   Zpadding_mm_stringÚdr   r   r   r   rx     st   


ý€
þ
ÿ
zLilypondSnippet.compose_lyc                 C   sV   | j s(t |  |  ¡ ¡ d¡¡}|  ¡ D ]
}| | d¡¡ q| ¡ d d… | _ | j S )Núutf-8é
   )	rH   ÚhashlibZmd5Úrelevant_contentsrM   Úencoder˜   rŽ   Z	hexdigest)r,   Úhashr•   r   r   r   Úget_checksum…  s   ÿÿzLilypondSnippet.get_checksumc                 C   s.   |   ¡ }tj |d d… d|dd …  ¡}|S )Nr   zlily-%s)r½   r\   r]   r   )r,   ZcsÚnamer   r   r   Úbasename”  s   "zLilypondSnippet.basenamec           	      C   sÜ   |   ¡ }tj | jj|¡}tj |¡d }tj|dd |d }tj |¡r^t	|ddd 
¡ }|  |¡|  |  ¡ ¡kr\t d| ¡ |  ¡  d¡}d	| }tj |  ||¡ d¡¡ d S d S t	|d
dd}| |  ¡ ¡ d S )Nr   T©Úexist_okrb   Úrr·   ©Úencodingúd%s: duplicate filename but different contents of original file,
printing diff against existing file.údiff -u %s -r–   )r¿   r\   r]   r   rK   Úlily_output_dirr‚   ÚmakedirsÚexistsr   r   rº   ry   rM   r„   r»   ÚsysÚstderrÚwriteÚfilter_pipeÚdecode)	r,   Úbaser]   Ú	directoryr   ÚexistingÚencodedÚcmdÚoutr   r   r   Úwrite_ly›  s*   ÿ
ÿÿûzLilypondSnippet.write_lyc                 C   s   t  dd|¡S )Nz1\\(version|sourcefileline|sourcefilename)[^\n]*\nr*   )r   r`   )r,   rM   r   r   r   rº   ¯  ó   z!LilypondSnippet.relevant_contentsc              
   C   sÈ  |   |¡\}}|rt tdƒd |¡ ¡ t|  ¡ ƒ‚|D ]Ä}| jjrMt	| t
ƒrMtj |¡\}}| d¡}t|ƒdkrBd|d  }	nd}	|  ¡ |	 | }
n|}
zt tj ||
¡¡ W n	 tyd   Y nw tj ||¡}tj ||
¡}tj |¡d }tj|dd	 zG| jjr°t	| t
ƒr°t|d
ƒ ¡ }|  ¡  d¡}|  ¡  d¡}| ||¡}t|dƒ |¡ nzt ||¡ W n tyÇ   t ||¡ Y nw W q ttfyá   t tdƒ| ¡ t|  ¡ ƒ‚w d S )NzMissing files: %sz, ú-r   éÿÿÿÿr*   r   TrÀ   r   r·   ÚwbzCould not overwrite file %s)Úall_output_filesrM   Úerrorr…   r   r#   r¿   rK   Úuse_source_file_namesÚ
isinstanceÚLilypondFileSnippetr\   r]   r^   r‚   ÚlenÚfinal_basenameÚunlinkÚOSErrorrÈ   r   r   r»   ÚreplacerÌ   ÚlinkÚAttributeErrorÚshutilZcopyfileÚIOError)r,   Ú
output_dirZdestinationrÑ   Úmissingr¾   rÏ   rd   Z
componentsZbase_suffixZ
final_nameÚsrcZdstZdst_pathZcontentr¿   rà   r   r   r   Úlink_all_output_files²  sX   ÿ
ÿÿÿ€þÝz%LilypondSnippet.link_all_output_filesc                 C   rf   r/   r   )r,   rÏ   Úfullr   r   r   Úadditional_files_to_considerÞ  r.   z,LilypondSnippet.additional_files_to_considerc                 C   s"   g }| j dkr| || j  ¡ |S )Nrb   )rd   r’   )r,   rÏ   rì   Úresultr   r   r   Úadditional_files_requiredá  s   
z)LilypondSnippet.additional_files_requiredc              	      s¼  t ƒ ‰t ƒ ‰ |  ¡ }tj ˆ|¡}‡‡fdd„}‡ ‡‡fdd„}| jj}||d ƒ |s2||d ƒ d| jjv r>||d ƒ |d	 |d
 |d |d |d |d |d |d fD ]}||ƒ qX| jj	rz|d | jj	 |d | jj	 fD ]}||ƒ qs| j 
| ||ˆ¡}|D ]}||ƒ q…d}	|sžˆ sžtt|d dd ¡ ƒ}	td|	d ƒD ]}
d||
f }||d
 ƒ ||d ƒ ||d ƒ q¥|  ||¡D ]}||ƒ qÆ|  ||¡D ]}||ƒ qÓˆˆ fS )z†Return all files generated in lily_output_dir, a set.

        output_dir_files is the list of files in the output directory.
        c                    s(   t j t j ˆ | ¡¡rˆ | ¡ d S d S r/   ©r\   r]   Úisfiler   Úadd©r¾   )rè   rî   r   r   Úconsider_fileñ  s   ÿz7LilypondSnippet.all_output_files.<locals>.consider_filec                    s2   t j t j ˆ| ¡¡rˆ | ¡ d S ˆ  | ¡ d S r/   rð   ró   ©ré   rè   rî   r   r   Úrequire_fileõ  s   z6LilypondSnippet.all_output_files.<locals>.require_filerb   z-systems.countzdseparate-log-filez.logz.texz.epsz.pdfz.texidocz	.doctitlez-systems.texiz-systems.texz-systems.pdftexir   Úutf8rÃ   r   z%s-%dz.png)Úsetr¿   r\   r]   r   rK   Zskip_lilypond_runZprocess_cmdrJ   rj   Úrequired_filesr   r   r   Úrangerí   rï   )r,   rè   rÏ   rì   rô   rö   Z	skip_lilyr   rù   Zsystem_countZnumberZ
systemfiler   rõ   r   rÚ   ç  sZ   ù
ÿ
ÿ


z LilypondSnippet.all_output_filesc                 C   s   |   |¡\}}|S r/   )rÚ   )r,   rè   r²   ré   r   r   r   Úis_outdated*  s   zLilypondSnippet.is_outdatedÚinputrÓ   r7   c                 C   sú   t  tdƒ| d¡ d}tjdkrd}tj|dtjtjtj|d}|j|j	|j
}}}| |¡ | ¡ }|sAd}| ¡ }	| ¡ }| ¡  d¡}
|sLd}d|@ }|sV|	sv|
rv|d	? }t  td
ƒ||f ¡ t  tdƒ¡ tj
 |
¡ t|ƒ t  d¡ |	S )z°Pass input through cmd, and return the result.

        Args:
          input: the input
          cmd: a shell command

        Returns:
          the filtered result
        zRunning through filter `%s'TZmingw32F)ÚshellÚstdinÚstdoutrË   Z	close_fdsr   r·   é   é   z`%s' failed (%d)zThe ly.error log is as follows:rs   )rM   Zdebug_outputr…   rÊ   ÚplatformÚ
subprocessÚPopenÚPIPErþ   rÿ   rË   rÌ   Úcloser   rÎ   rÛ   Úexit)r,   rü   rÓ   ZclosefdsÚprþ   rÿ   rË   Zstatusr   ÚerrÚsignalZexit_statusr   r   r   rÍ   .  s4   


ÿ

zLilypondSnippet.filter_pipec                 C   s
   |   d¡S )Nrr   )rW   r+   r   r   r   Úget_snippet_codeZ  r4   z LilypondSnippet.get_snippet_codec                 C   sT   |   ¡  d¡}|  || jj¡}| j d¡}|du rd}| d¡|dœ}| j 	t
|¡S )z@Run snippet bodies through a command (say: convert-ly).
        r·   rc   Nr*   )rr   rc   )r  r»   rÍ   rK   Z
filter_cmdr   r   rÎ   rJ   Zoutput_simple_replacementsÚFILTER)r,   rr   r   rc   r¶   r   r   r   r0   ]  s   þzLilypondSnippet.filter_textc                 C   s   |   ¡ }| j || ¡S r/   )rà   rJ   Zsnippet_output©r,   rÏ   r   r   r   r-   k  s   z LilypondSnippet.replacement_textc                    s´   |   ¡ ‰ | jj}dˆ  }tj ||¡}tj |dˆ  ¡}|f}tj |¡rXtj |¡r;t |¡tj t |¡tj krXt	tj |dˆ  ¡ƒ}‡ fdd„t
d|d ƒD ƒ}t|ƒ}|S )Nz%s.pngz%s-page1.pngz%s.epsc                    s   g | ]}d ˆ |f ‘qS )z%s-page%d.pngr   )r€   Zpage©rÏ   r   r   r   |  s    ÿz.LilypondSnippet.get_images.<locals>.<listcomp>r   )rà   rK   rÇ   r\   r]   r   rÉ   ÚstatÚST_MTIMEr    rú   Útuple)r,   ÚoutdirZsingle_baseZsingleZmultipleZimagesÚcountr   r  r   Ú
get_imageso  s$   
ÿÿ
ÿzLilypondSnippet.get_imagesN)r$   r%   r&   r3   rg   rq   rv   rM   ry   r{   re   r˜   rx   r½   r¿   rà   rÕ   rº   rë   rí   rï   rÚ   rû   Úbytesr:   rÍ   r  r0   r-   r  r   r   r   r   ra   _  s4    tq,C,ra   z\s+%.*?begin verbatim.*\n*z\s+%.*?end verbatim.*$c                   @   sH   e Zd Zdd„ Zdefdd„Zdefdd„Zdd	„ Zd
d„ Z	dd„ Z
dS )rÞ   c                 C   s*   t  | |||||¡ |  d¡| _d | _d S )Nr   )ra   r3   rW   r   rw   rO   r   r   r   r3   ˆ  s
   ÿ
zLilypondFileSnippet.__init__r7   c                 C   s.   | j st | j| jj¡}t|dƒ ¡ | _ | j S )Nr   )rw   Ú	book_baseZ	find_filer   rK   Zinclude_pathr   r   )r,   r]   r   r   r   Úget_contentsŽ  s   ÿz LilypondFileSnippet.get_contentsc                 C   s   |   ¡  d¡S )Nr·   )r  rÎ   r+   r   r   r   r  •  rÖ   z$LilypondFileSnippet.get_snippet_codec                 C   sN   |   ¡ }t |¡d }t |¡d }t| jvr|  |¡}| d¡s%|d7 }|S )NrØ   r   rs   )r  Úre_begin_verbatimr‚   Úre_end_verbatimrt   rI   rq   ru   rU   r   r   r   rv   ˜  s   


zLilypondFileSnippet.verb_lyc                 C   s   | j }d||  ¡ f S ©Nz)\sourcefilename "%s"
\sourcefileline 0
%s)r   r  ©r,   r¾   r   r   r   rM   ¢  s   
ÿzLilypondFileSnippet.lyc                 C   s.   | j jrtj tj | j¡¡d }|S |  ¡ S )Nr   )rK   rÜ   r\   r]   r^   r¿   r   r  r   r   r   rà   §  s   z"LilypondFileSnippet.final_basenameN)r$   r%   r&   r3   r  r  r:   r  rv   rM   rà   r   r   r   r   rÞ   ‡  s    
rÞ   c                   @   rC   )ÚMusicXMLFileSnippetc                 C   s\   t  | |||||¡ d| _d | _tj tj | j¡¡d | _	ddddddd	d
dddœ
| _
d S )NFr   z	--verbosez--lxmlú--compressedz
--relativez
--absolutez--no-articulation-directionsz--no-rest-positionsz--no-page-layoutz--no-beamingz
--language)
ÚverboseZlxmlÚ
compressedr   Zabsolutezno-articulation-directionszno-rest-positionszno-page-layoutz
no-beamingZlanguage)rÞ   r3   r  Úconverted_lyr\   r]   r^   r¿   r   rd   Úmusicxml_options_dictrO   r   r   r   r3   °  s"   ÿözMusicXMLFileSnippet.__init__c                 C   s   t | j ¡ ƒS r/   )Úlistr!  r£   r+   r   r   r   rg   Ã  rÖ   z#MusicXMLFileSnippet.snippet_optionsc           	      C   sÀ   | j }g }t| j ¡ ƒD ]#\}}| j |d ¡}|d u rq|d u r&| |¡ q| |d | ¡ qd|v r@d|vr@| d¡ d| _d |¡}t	 
tdƒ| j  ¡ d| }|  |  ¡ |¡ d¡}|S )	Nr|   ú.mxlr  Tú z Converting MusicXML file `%s'...zmusicxml2ly %s --out=- - r·   )r   r"  rI   r‘   r!  Úgetr’   r  r   rM   Zprogressr…   rÍ   r  rÎ   )	r,   r¾   Zxml2ly_option_listr   r   Zcmd_keyZoptsrÓ   Zly_coder   r   r   Úconvert_from_musicxmlÆ  s"   

z)MusicXMLFileSnippet.convert_from_musicxmlc                 C   s(   | j d u r
|  ¡ | _ | j}d|| j f S r  )r   r&  r   r  r   r   r   rM   Û  s   

ÿzMusicXMLFileSnippet.lyc           
      C   sN  |   ¡ }tj | jj|¡}tj |¡d }tj|dd | jr$|d }n|d }tj 	|¡rM|  
|  ¡ d| ¡}|rLt tdƒ| ¡ tj | d¡¡ nt|d	ƒ}| |  ¡ ¡ | ¡  |d
 }tj 	|¡r“|  ¡  d¡}d| }	|  
||	¡ d¡}|r‘t tdƒ| ¡ tj | d¡¡ d S d S t|ddd}| |  ¡ ¡ | ¡  d S )Nr   TrÀ   r#  z.xmlzdiff -u %s - rÅ   r·   rÙ   rb   rÆ   zn%s: duplicate filename but different contents of converted lilypond file,
printing diff against existing file.r–   rÃ   )r¿   r\   r]   r   rK   rÇ   r‚   rÈ   r  rÉ   rÍ   r  rM   r„   r…   rÊ   rË   rÌ   rÎ   r   r  ry   r»   )
r,   rÏ   r]   rÐ   ZxmlfilenameZdiff_against_existingrÔ   r   rÒ   rÓ   r   r   r   rÕ   â  sL   
ÿ
ÿ€
ÿÿ
ÿýzMusicXMLFileSnippet.write_lyN)r$   r%   r&   r3   rg   r&  rM   rÕ   r   r   r   r   r  ¯  s    r  c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚLilyPondVersionStringr<   c                 C   s   t  | |||||¡ d S r/   )rD   r3   rO   r   r   r   r3     s   ÿzLilyPondVersionString.__init__c                 C   s   | j  | j| ¡S r/   )rJ   Zoutput_simplerG   r+   r   r   r   r-     s   z&LilyPondVersionString.replacement_textN)r$   r%   r&   rB   r3   r-   r   r   r   r   r'  
  s    r'  )Zlilypond_fileZlilypond_blockZlilypondZincluder
   Zmusicxml_file)IrP   r¹   r\   r   ræ   r  rÊ   r  ZlilylibrM   ZAFTERZALTZBEFOREZDOCTITLErœ   ZFILENAMEr  rŒ   r    rŠ   Z
NOFRAGMENTrt   ZNOINDENTr   r¥   ZNORAGGED_RIGHTrž   ZNOTIMEZOUTPUTZOUTPUTIMAGEr¡   rˆ   r†   r‡   ZPARArŸ   ZPRINTFILENAMEr   r   r‹   Z	STAFFSIZEZTEXIDOCZVERBATIMZVERSIONrƒ   r   r¤   rg   r   r¯   r®   r­   r    ÚcompileÚMrl   rk   rn   r‰   r"   Ú	Exceptionr#   r'   r;   rD   r[   ra   r  r  rÞ   r  r'  Zsnippet_type_to_classr   r   r   r   Ú<module>   sä   þþòÿôÿÿÚ,	

    (([
ú