o c‚æc¸Œã@sZddlZddlZddlZddlZddlZddlZddlZddlZddlZ dZ dZ dZ dZ dZdZdZd Zd Zd Zd Zd ZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'd Z(d!Z)d"Z*d#Z+eeeeiZ,e ee*e)e e+e$fZ-eeeeeeee!e$e e)e*ee gZ.ee'd$iee d%ed&ed'e%d(e&d)ed*ieed+ie#e(d,iiZ/d-d.„Z0d/Z1d0Z2d1Z3d2d3„Z4e 5d4ej6¡Z7e 5d5ej6¡Z8e 5d6¡Z9e 5d7¡Z:d8d9„Z;Gd:d;„d;e<ƒZ=GdGd>d?„d?e>ƒZ?Gd@dA„dAe>ƒZ@GdBdC„dCe@ƒZAGdDdE„dEe@ƒZBe 5dFej6¡ZCe 5dGej6¡ZDGdHdI„dIeBƒZEGdJdK„dKeEƒZFGdLdM„dMe@ƒZGeEeBeBeAeGeFdNœZHdS)OéNZafterZaltZbeforeZdoctitleZ exampleindentÚfilenameÚfilterZfragmentZlayoutú line-widthZ nofragmentZ nogettextZnoindentÚindentZinlineznoragged-rightÚbodyZnotimeÚoutputZ outputimageZpaperz paper-heightZ papersizez paper-widthZparaZpreambleZ printfilenameZquotez ragged-rightÚrelativeÚ staffsizeZtexidocZverbatimÚlilypondversionz\relative c%(relative_quotes)sz#(set-paper-size %(papersize)s)zindent = %(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))zragged-right = ##tzragged-right = ##fze \context { \Score timing = ##f } \context { \Staff \remove Time_signature_engraver }z&#(set-global-staff-size %(staffsize)s)cCs¬|dkrt|fS|dkr|durtdfSt d|¡}|r#d| d¡fSt d|¡}|r2d| d¡fS|dks:|d krTt d |¡}|rTt| d¡ƒ}|d || d ¡ffSd S)NZ lilyquoteZ singlelinezrelative\s*([-0-9])réz ([0-9]+)ptr rrz%([-.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ú\/home/lily/lilypond-2.24.1/release/binaries/lilypond/lilypond-2.24.1/python/book_snippets.pyÚ#classic_lilypond_book_compatibility¡s    ra~%%%% 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 %% **************************************************************** } cCs2t|dƒ d¡}t d|¡}|rt| d¡ƒSdS)NÚrbis %%Pages: ([0-9]+)r r)ÚopenÚreadrrÚintr)Zps_nameÚheaderrrrrÚ 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)$cCs| d¡|| d¡ƒS)Nr r )r)ÚtrrrrÚly_comment_gettextsr"c@s eZdZdS)Ú CompileErrorN)Ú__name__Ú __module__Ú __qualname__rrrrr#sr#c@sHeZdZdd„Zdd„Zdd„Zdd„Zd efd d „Zd efd d„Z dS)ÚChunkcCódS©NÚr©ÚselfrrrÚreplacement_textózChunk.replacement_textcCs| ¡S©N)r-r+rrrÚ filter_textszChunk.filter_textcCr()NFrr+rrrÚis_plainr.zChunk.is_plaincCs d|_dSr)©Z_output_fullpathr+rrrÚ__init__ó zChunk.__init__Úout_fpcCs ||_dSr/r2)r,r5rrrÚset_output_fullpathr4zChunk.set_output_fullpathÚreturncCó|jS)z0The output file path that this chunk belongs to.r2r+rrrÚoutput_fullpath szChunk.output_fullpathN) r$r%r&r-r0r1r3Ústrr6r9rrrrr'sr'c@s(eZdZdZdd„Zdd„Zdd„ZdS) Ú Substringú,A string that does not require extra memory.cCs"||_||_||_||_d|_dSr/)ÚsourceÚstartÚendÚ line_numberÚ override_text)r,r=r>r?r@rrrr3(s  zSubstring.__init__cCr()NTrr+rrrr1/r.zSubstring.is_plaincCs|jr|jS|j|j|j…Sr/)rAr=r>r?r+rrrr-2szSubstring.replacement_textN)r$r%r&Ú__doc__r3r1r-rrrrr;%s  r;c@ó4eZdZdd„Zdd„Zdd„Zdd„Zd d „Zd S) ÚSnippetcCsB||_||_d|_i|_||_||_||_|jdtj dœ|_ dS)NrÚprogram_version)rEÚ program_name) ÚtyperÚchecksumÚ option_dictÚ formatterr@Úglobal_optionsÚ informationÚlyrFÚ replacements©r,rGrrJr@rKrrrr3:s ÿzSnippet.__init__cCs t |j¡Sr/)ÚcopyrNr+rrrÚget_replacementsGó zSnippet.get_replacementscCs |j d¡S)Nr©rrr+rrrr-JrRzSnippet.replacement_textcCó |j |¡Sr/rS©r,ÚsrrrÚ substringMrRzSnippet.substringcCst|jƒd|jS)Nz type = )ÚreprÚ __class__rGr+rrrÚ__repr__PszSnippet.__repr__N)r$r%r&r3rQr-rWrZrrrrrD9s   rDc@seZdZdd„Zdd„ZdS)ÚIncludeSnippetcCs"| d¡}tj |¡d|jjS)Nrr)rWÚosÚpathÚsplitextrJZdefault_extension)r,rrrrÚprocessed_filenameUs z!IncludeSnippet.processed_filenamecCs(|j d¡}| d¡}t || ¡|¡S)Nrr)rrrWrÚsubr_)r,rVrrrrr-Ys  zIncludeSnippet.replacement_textN)r$r%r&r_r-rrrrr[Ts r[c@säeZdZdd„Zdd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dd„Z dd„Z dd„Z dd„Z dd„ZeZdd„Zdd„Zdd„Zdd „Zd!d"„Zd#d$„Zd%d&„Zd'ed(ed)efd*d+„Zd)efd,d-„Zd.d/„Zd0d1„Zd2d3„Zd4S)5ÚLilypondSnippetcCs<t ||||||¡d|_d|_| d¡}| ||j¡dS)Nr*ú.lyÚoptions)rDr3rÚextrÚparse_snippet_optionsrG)r,rGrrJr@rKr\rrrr3`s ÿ zLilypondSnippet.__init__cCógSr/rr+rrrÚsnippet_optionshr.zLilypondSnippet.snippet_optionscs®|jj}|s|Sztj|‰Wn|YSt ‡fdd„|¡}tj|jrUt  |¡D]}t  d|dˆ|ƒd|¡}q,t   |¡D]}t  d|dˆ|ƒd|¡}qC|S)Ncs tˆ|ƒSr/)r")r©r!rrÚzs z1LilypondSnippet.verb_ly_gettext..z'(?m)(?øs ÿz9LilypondSnippet.parse_snippet_options..)Zsnippet_option_dictr{rÚsplitÚ no_optionsrIrrMÚ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,rzrGrcÚoptionrrZc_keyZc_valueZhas_paper_widthZhas_paper_heightZwdrÚwZw_unitZhtÚhZh_unitZhas_line_widthZlstZ option_listrrrres’   ÿÿ ÿ ÿ  € ÿ       ÿ   ÿÿ       z%LilypondSnippet.parse_snippet_optionscCr8r/)r”r+rrrÚ!get_outputrelevant_option_stringssz1LilypondSnippet.get_outputrelevant_option_stringscCsNd}i}d|t<d|t<| |jj¡|jj|d<d | ¡¡}i}t t t t g}|D]}g||<q*t |j ¡ƒ}|D]G} |j| } | rH| || <n| |vrPd|| <d} |D]} | t| vrk||  t| | ¡d} nqT| s| tvr| | ¡vrt tdƒ| ¡q:t|vr|trt|tƒ}d} |dkrž| d| 7} n |dkr¨| d |7} t|vr°d |d<t|t ƒD]\}}| d ¡rÎ|t  d|t  |¡¡nq¶d  |t ¡|}d  |t ¡|}d  |t ¡tƒ}d  |t ¡|}|d}|dkrd |}nd}tƒ ¡}| t ƒ¡| |jj!¡t"|jvrt#}nt$}t%||S)Nr z0.4\inz5\inÚ padding_mmú,rzignoring unknown ly option: %sr*ú'g-Cëâ6?z#(set-paper-sizez z$#(ly:set-option 'eps-box-padding %f))&Ú EXAMPLEINDENTrŠrŽrJrrKr™Újoinr˜ÚNOTESÚPREAMBLEÚLAYOUTÚPAPERÚsortedrIÚkeysrgr’Úsimple_optionsrMr„r…r‹rÚINLINEÚ enumerateÚ startswithÚinsertÚpopÚvarsÚglobalsrPÚlocalsrLrŒÚ FRAGMENT_LYÚFULL_LYÚ PREAMBLE_LY)r,rrrÚoverriderzZ compose_dictZ compose_typesÚaZ option_namesrrÚfoundÚtypZrelative_quotesÚiÚelemZ paper_stringZ layout_stringZ notes_stringZpreamble_stringr™Zpadding_mm_stringÚdrrrrrxst      ý€   þ ÿ    zLilypondSnippet.compose_lycCsV|js(t | | ¡¡ d¡¡}| ¡D] }| | d¡¡q| ¡dd…|_|jS)Núutf-8é ) rHÚhashlibZmd5Úrelevant_contentsrMÚencoder˜rŽZ hexdigest)r,Úhashr•rrrÚ get_checksum…sÿÿ zLilypondSnippet.get_checksumcCs.| ¡}tj |dd…d|dd…¡}|S)Nr zlily-%s)r½r\r]r)r,ZcsÚnamerrrÚbasename”s"zLilypondSnippet.basenamec CsÜ| ¡}tj |jj|¡}tj |¡d}tj|dd|d}tj |¡r^t |ddd  ¡}|  |¡|  |  ¡¡kr\t  d|¡|  ¡ d¡}d |}tj | ||¡ d¡¡dSdSt |d dd}| |  ¡¡dS) NrT©Ú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]rrKÚlily_output_dirr‚ÚmakedirsÚexistsrrrºryrMr„r»ÚsysÚstderrÚwriteÚ filter_pipeÚdecode) r,Úbaser]Ú directoryrÚexistingÚencodedÚcmdÚoutrrrÚwrite_ly›s* ÿ ÿÿûzLilypondSnippet.write_lycCst dd|¡S)Nz1\\(version|sourcefileline|sourcefilename)[^\n]*\nr*)rr`)r,rMrrrrº¯óz!LilypondSnippet.relevant_contentsc CsÈ| |¡\}}|rt tdƒd |¡¡t| ¡ƒ‚|D]Ä}|jjrMt |t ƒrMt j   |¡\}}| d¡}t|ƒdkrBd|d} nd} | ¡| |} n|} z t  t j  || ¡¡Wn tydYnwt j  ||¡} t j  || ¡} t j  | ¡d} t j| dd zG|jjr°t |t ƒr°t| d ƒ ¡}| ¡ d ¡}| ¡ d ¡}| ||¡}t| d ƒ |¡nzt  | | ¡WntyÇt | | ¡YnwWqttfyát td ƒ| ¡t| ¡ƒ‚wdS)NzMissing files: %sz, ú-r éÿÿÿÿr*rTrÀrr·ÚwbzCould not overwrite file %s)Úall_output_filesrMÚerrorr…rr#r¿rKÚuse_source_file_namesÚ isinstanceÚLilypondFileSnippetr\r]r^r‚ÚlenÚfinal_basenameÚunlinkÚOSErrorrÈrrr»ÚreplacerÌÚlinkÚAttributeErrorÚshutilZcopyfileÚIOError)r,Ú output_dirZ destinationrÑÚmissingr¾rÏrdZ componentsZ base_suffixZ final_nameÚsrcZdstZdst_pathZcontentr¿ràrrrÚlink_all_output_files²sX ÿ   ÿÿ  ÿ€ þÝz%LilypondSnippet.link_all_output_filescCrfr/r)r,rÏÚfullrrrÚadditional_files_to_considerÞr.z,LilypondSnippet.additional_files_to_considercCs"g}|jdkr| ||j¡|S)Nrb)rdr’)r,rÏrìÚresultrrrÚadditional_files_requiredás z)LilypondSnippet.additional_files_requiredc s¼tƒ‰tƒ‰| ¡}tj ˆ|¡}‡‡fdd„}‡‡‡fdd„}|jj}||dƒ|s2||dƒd|jjvr>||dƒ|d |d |d |d |d |d|d|dfD]}||ƒqX|jj rz|d |jj |d |jj fD]}||ƒqs|j  |||ˆ¡}|D]}||ƒq…d} |sžˆsžt t |ddd  ¡ƒ} td| dƒD]} d|| f} || d ƒ|| d ƒ|| dƒq¥| ||¡D]}||ƒqÆ| ||¡D]}||ƒqÓˆˆfS)z†Return all files generated in lily_output_dir, a set. output_dir_files is the list of files in the output directory. cs(tj tj ˆ|¡¡rˆ |¡dSdSr/©r\r]ÚisfilerÚadd©r¾)rèrîrrÚ consider_fileñsÿz7LilypondSnippet.all_output_files..consider_filecs2tj tj ˆ|¡¡rˆ |¡dSˆ |¡dSr/rðró©rérèrîrrÚ require_fileõsz6LilypondSnippet.all_output_files..require_filerbz-systems.countzdseparate-log-filez.logz.texz.epsz.pdfz.texidocz .doctitlez -systems.texiz -systems.texz-systems.pdftexirÚutf8rÃr z%s-%dz.png)Úsetr¿r\r]rrKZskip_lilypond_runZ process_cmdrJrjÚrequired_filesrrrÚrangerírï) r,rèrÏrìrôröZ skip_lilyrrùZ system_countZnumberZ systemfilerrõrrÚçsZ    ù ÿ ÿ      z LilypondSnippet.all_output_filescCs| |¡\}}|Sr/)rÚ)r,rèr²rérrrÚ is_outdated*szLilypondSnippet.is_outdatedÚinputrÓr7c Csút tdƒ|d¡d}tjdkrd}tj|dtjtjtj|d}|j|j |j }}}|  |¡|  ¡}|sAd}|  ¡} |  ¡}|  ¡ d¡} |sLd}d|@} |sV| sv| rv|d ?} t td ƒ|| f¡t td ƒ¡tj   | ¡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 zRunning through filter `%s'TZmingw32F)ÚshellÚstdinÚstdoutrËZ close_fdsrr·ééz`%s' failed (%d)zThe ly.error log is as follows:rs)rMZ debug_outputr…rÊÚplatformÚ subprocessÚPopenÚPIPErþrÿrËrÌÚcloserrÎrÛÚexit) r,rürÓZclosefdsÚprþrÿrËZstatusrÚerrÚsignalZ exit_statusrrrrÍ.s4    ÿ    zLilypondSnippet.filter_pipecCs | d¡S)Nrr)rWr+rrrÚget_snippet_codeZr4z LilypondSnippet.get_snippet_codecCsT| ¡ d¡}| ||jj¡}|j d¡}|durd}| d¡|dœ}|j  t |¡S)z@Run snippet bodies through a command (say: convert-ly). r·rcNr*)rrrc) r r»rÍrKZ filter_cmdrrrÎrJZoutput_simple_replacementsÚFILTER)r,rrrrcr¶rrrr0]s þzLilypondSnippet.filter_textcCs| ¡}|j ||¡Sr/)ràrJZsnippet_output©r,rÏrrrr-ksz LilypondSnippet.replacement_textcs´| ¡‰|jj}dˆ}tj ||¡}tj |dˆ¡}|f}tj |¡rXtj |¡r;t |¡tjt |¡tjkrXt tj |dˆ¡ƒ}‡fdd„t d|dƒDƒ}t |ƒ}|S)Nz%s.pngz %s-page1.pngz%s.epscsg|]}dˆ|f‘qS)z %s-page%d.pngr)r€Zpage©rÏrrr|sÿz.LilypondSnippet.get_images..r ) ràrKrÇr\r]rrÉÚstatÚST_MTIMEr rúÚtuple)r,ÚoutdirZ single_baseZsingleZmultipleZimagesÚcountrrrÚ get_imagesos$  ÿÿ  ÿzLilypondSnippet.get_imagesN)r$r%r&r3rgrqrvrMryr{rer˜rxr½r¿ràrÕrºrërírïrÚrûÚbytesr:rÍr r0r-rrrrrra_s4tq,C, raz\s+%.*?begin verbatim.*\n*z\s+%.*?end verbatim.*$c@sHeZdZdd„Zdefdd„Zdefdd„Zdd „Zd d „Z d d „Z dS)rÞcCs*t ||||||¡| d¡|_d|_dS)Nr)rar3rWrrwrOrrrr3ˆs  ÿ  zLilypondFileSnippet.__init__r7cCs.|jst |j|jj¡}t|dƒ ¡|_|jS)Nr)rwÚ book_baseZ find_filerrKZ include_pathrr)r,r]rrrÚ get_contentsŽs ÿz LilypondFileSnippet.get_contentscCs| ¡ d¡S)Nr·)rrÎr+rrrr •rÖz$LilypondFileSnippet.get_snippet_codecCsN| ¡}t |¡d}t |¡d}t|jvr| |¡}| d¡s%|d7}|S)NrØrrs)r Úre_begin_verbatimr‚Úre_end_verbatimrtrIrqrurUrrrrv˜s   zLilypondFileSnippet.verb_lycCs|j}d|| ¡fS©Nz)\sourcefilename "%s" \sourcefileline 0 %s)rr ©r,r¾rrrrM¢s ÿzLilypondFileSnippet.lycCs.|jjrtj tj |j¡¡d}|S| ¡S)Nr)rKrÜr\r]r^r¿rr rrrrà§sz"LilypondFileSnippet.final_basenameN) r$r%r&r3rrr:r rvrMràrrrrrÞ‡s rÞc@rC) ÚMusicXMLFileSnippetc Cs\t ||||||¡d|_d|_tj tj |j¡¡d|_ ddddddd d d d d œ |_ dS)NFr z --verbosez--lxmlú --compressedz --relativez --absolutez--no-articulation-directionsz--no-rest-positionsz--no-page-layoutz --no-beamingz --language) ÚverboseZlxmlÚ compressedrZabsolutezno-articulation-directionszno-rest-positionszno-page-layoutz no-beamingZlanguage) rÞr3rÚ converted_lyr\r]r^r¿rrdÚmusicxml_options_dictrOrrrr3°s" ÿ özMusicXMLFileSnippet.__init__cCst|j ¡ƒSr/)Úlistr!r£r+rrrrgÃrÖz#MusicXMLFileSnippet.snippet_optionsc CsÀ|j}g}t|j ¡ƒD]#\}}|j |d¡}|durq |dur&| |¡q | |d|¡q d|vr@d|vr@| d¡d|_d |¡}t   t dƒ|j¡d|}|  |  ¡|¡ d¡}|S) Nr|ú.mxlrTú z Converting MusicXML file `%s'...zmusicxml2ly %s --out=- - r·)rr"rIr‘r!Úgetr’rrrMZprogressr…rÍrrÎ) r,r¾Zxml2ly_option_listrrZcmd_keyZoptsrÓZly_coderrrÚconvert_from_musicxmlÆs"   z)MusicXMLFileSnippet.convert_from_musicxmlcCs(|jdur | ¡|_|j}d||jfSr)r r&rrrrrrMÛs  ÿzMusicXMLFileSnippet.lyc CsN| ¡}tj |jj|¡}tj |¡d}tj|dd|jr$|d}n|d}tj  |¡rM|  |  ¡d|¡}|rLt   tdƒ|¡tj | d¡¡nt|d ƒ}| |  ¡¡| ¡|d }tj  |¡r“| ¡ d¡}d |} |  || ¡ d¡}|r‘t   td ƒ|¡tj | d¡¡dSdSt|d dd}| | ¡¡| ¡dS)NrTrÀr#z.xmlz diff -u %s - rÅr·rÙrbrÆzn%s: duplicate filename but different contents of converted lilypond file, printing diff against existing file.r–rÃ)r¿r\r]rrKrÇr‚rÈrrÉrÍrrMr„r…rÊrËrÌrÎrrryr») r,rÏr]rÐZ xmlfilenameZdiff_against_existingrÔrrÒrÓrrrrÕâsL   ÿ ÿ€  ÿÿ ÿý zMusicXMLFileSnippet.write_lyN)r$r%r&r3rgr&rMrÕrrrrr¯s  rc@s eZdZdZdd„Zdd„ZdS)ÚLilyPondVersionStringr<cCst ||||||¡dSr/)rDr3rOrrrr3 s ÿzLilyPondVersionString.__init__cCs|j |j|¡Sr/)rJZ output_simplerGr+rrrr-sz&LilyPondVersionString.replacement_textN)r$r%r&rBr3r-rrrrr' s r')Z lilypond_fileZlilypond_blockZlilypondZincluder Z musicxml_file)IrPr¹r\rrærrÊrZlilylibrMZAFTERZALTZBEFOREZDOCTITLErœZFILENAMEr rŒr rŠZ NOFRAGMENTrtZNOINDENTrr¥ZNORAGGED_RIGHTržZNOTIMEZOUTPUTZ OUTPUTIMAGEr¡rˆr†r‡ZPARArŸZ PRINTFILENAMEr rr‹Z STAFFSIZEZTEXIDOCZVERBATIMZVERSIONrƒrr¤rgrr¯r®r­r ÚcompileÚMrlrkrnr‰r"Ú Exceptionr#r'r;rDr[rarrrÞrr'Zsnippet_type_to_classrrrrÚsä þþòÿôÿ ÿÚ,    (([  ú