python_ly-0.9.9/.readthedocs.yaml0000644000000000000000000000043013615410400013722 0ustar00version: 2 build: os: "ubuntu-22.04" tools: python: "3.8" python: install: - requirements: doc/requirements.txt # Install our python package before building the docs - method: pip path: . sphinx: configuration: doc/conf.py fail_on_warning: true python_ly-0.9.9/CHANGELOG.md0000644000000000000000000001601113615410400012306 0ustar00 # ChangeLog All notable changes to the python-ly project are documented in this file. ## [0.9.9] - 2025-01-04 ### Changed - LilyPond syntax updates - Use hatchling as build backend (#165) ### Fixed - Never use MUP as format guess (#164). Fixes frescobaldi/frescobaldi#1635 - Fix tests (#170) ## [0.9.8] - 2023-06-15 ### Added - Add list of string tunings (#149) ### Changed - Add LilyPond 2.24 words (#151) - Require Python 3.8 (#156) - Move packaging metadata to `pyproject.toml` (#155) ### Fixed - Fix `\set` highlighted on its own in `\set-abcd` and similar cases (#150) ## [0.9.7] - 2020-12-25 ### Changed - Added LilyPond 2.20 words (#140) ### Fixed - Fixed error when making rhythm implicit per line (#144) ## [0.9.6] - 2020-01-22 ### Fixed - eps-file -> epsfile (#1213 on Frescobaldi repository) - MusicXML output: - Correctly export measures without the help of explicit barchecks (#32) - Export \mark (#102) - Fix scale_rest bug (#107) - Stem direction is now supported (#110) - Fix empty measures created with no attributes (#114) ### Changed - Various improvements to the experimental MusicXML output by Felippe Roza, Peter Bjuhr, Urs Liska, Endre Oma and others, thanks! - Improved indentation of Scheme code, thanks to Paul Morris (#132) ## [0.9.5] - 2017-02-17 ### Added - Basic support for tokenizing the MUP format ### Fixed - Fixed wrong duration handling with \partial when changing durations (#832 on Frescobaldi repository) - XML export tests now work correctly with Python 3 - Fix traversing events failing in empty \alternative (#74) ## [0.9.4] - 2016-04-20 ### Added - Add simplifier transposer and simplify-accidentals ly command (#40) - Recognize \bookOutputName A (without quotes, although not recommended) - Allow multi-digit fingering, e.g. c-34, LilyPond supports that since at least 2.16. - Add ly-server: an HTTP-server for manipulating LilyPond source, contributed by Urs Liska ### Changed - Support LilyPond 2.18+ behaviour on \relative without startpitch in the ly.pitch.transpose, ly.pitch.rel2abs and ly.pitch.abs2rel modules. - Support LilyPond 2.18+ behaviour on \relative without startpitch in the transpose, rel2abs, abs2rel and musicxml ly commands. Two new variables were added to influence the behaviour: rel-absolute and rel-startpitch. - Various updates and improvements in MusicXML export contributed by Peter Bjuhr ### Fixed - Make define-markup-command recognition working again - Do not add durations to bass notes in chordmode (#56) - Handle \include commands correctly when exporting to MusicXML (#59) ## [0.9.3] - 2015-12-24 ### Added - Added ly.rhythm.music_items() for a more robust way of iterating through chords and notes (awaiting fully fledged editing support through ly.music or ly.xml) ### Fixed - Do not insert duration after a tie (#35) ### Changed - More configurability in ly.colorize, thanks to Urs Liska - MusicXML export various improvements and bug fixes, contributed by Peter Bjuhr ## [0.9.2] - 2015-05-14 ### Added - Add the default-language variable to the ly command; this can be set to a language in case a LilyPond document uses a language different than "nederlands" but does not specify it (#20) - Add the `-l`, `--language` option as shorthand for setting the default language - properly support drum notes in ly.lex and ly.music ### Changed - Updated scheme variables in ly.data.scheme* functions for LilyPond 2.18 - MusicXML export improvements: - support for isolated durations (a single duration without explicit pitch) - support for implicit starting pitch in relative mode (issues #18 and frescobaldi/frescobaldi#648) ### Fixed - Fix TypeError: expected string or buffer in dom.ly when string was a dom.Reference (#667 on Frescobaldi repository) - Fix issue #16: Duration after `\skip` may not be removed ## [0.9.1] - 2015-03-08 ### Changed - Updated LilyPond data to 2.18 ## [0.9] - 2015-03-07 ### Added - Added ly.rests containing various rest manipulations - A script `xml-export.ily` has been included to dump the music structure inside LilyPond to an XML file. This is not used yet, but could be used in the future to use LilyPond to parse files and build music, and then export it to other formats. ### Changed - Robust Python 3 support, Python 3 is now recommended, although 2.7 will still be supported for the foreseeable future. - MusicXML export improvements ### Fixed - Don't yield the duration in a \tuplet command as a music token (issue frescobaldi/frescobaldi#631) ## [0.8] -- 2015-01-24 ### Added - Basic api documentation included ### Fixed - Fix (albeit experimental) musicxml export ## [0.7] - 2015-01-23 ### Changed - First release as an officially separate project from Frescobaldi - Add INSTALL.md to source distribution ## [0.6] - 2015-01-23 ### Changed - node and slexer are no longer toplevel modules; only the ly package ## [0.5] - 2015-01-21 ### Changed - Large MusicXML export improvements, contributed by Peter Bjuhr (MusicXML export is still experimental) ### Fixed - Handle german pitch names asas and heses correctly when writing those - Don't transpose chord argument of \stringTuning command - Python 3 robustness improvements ## [0.4] - 2014-03-05 ### Changed - Small MusicXML export improvements, contributed by Peter Bjuhr (MusicXML export is still very experimental) ### Fixed - Fix transposing when alterations would be more than a double sharp or double flat; handle it by moving the note, just like LilyPond does it - Python 3 installation fixes ## [0.3] - 2014-02-05 ### Added - New command 'highlight' ('hl') to create syntax-highlighted HTML files of LilyPond source files (or any file that is understood by ly.lex) - New, very experimental, command 'musicxml' to export music to MusicXML ## [0.2] - 2014-01-08 ### Added - New commands 'abs2rel' and 'rel2abs' that convert \relative music to absolute and vice versa - Support for Python 3. Not all of the ly python module has already been tested, but installing and running the various ly commands works well. ## [0.1] - 2014-01-07 Initial release. [0.8]: https://github.com/frescobaldi/frescobaldi/compare/v0.7..v0.8 [0.9]: https://github.com/frescobaldi/frescobaldi/compare/v0.8..v0.9 [0.9.1]: https://github.com/frescobaldi/frescobaldi/compare/v0.9..v0.9.1 [0.9.2]: https://github.com/frescobaldi/frescobaldi/compare/v0.9.1..v0.9.2 [0.9.3]: https://github.com/frescobaldi/frescobaldi/compare/v0.9.2..v0.9.3 [0.9.4]: https://github.com/frescobaldi/frescobaldi/compare/v0.9.3..v0.9.4 [0.9.5]: https://github.com/frescobaldi/frescobaldi/compare/v0.9.4..v0.9.5 [0.9.6]: https://github.com/frescobaldi/frescobaldi/compare/v0.9.5..v0.9.6 [0.9.7]: https://github.com/frescobaldi/frescobaldi/compare/v0.9.6..v0.9.7 [0.9.8]: https://github.com/frescobaldi/frescobaldi/compare/v0.9.7..v0.9.8 [0.9.9]: https://github.com/frescobaldi/frescobaldi/compare/v0.9.8..v0.9.9 python_ly-0.9.9/INSTALL.rst0000644000000000000000000000147713615410400012347 0ustar00========== Installing ========== See `Installing Packages `_ in the Python Packaging User Guide for help on installing Python packages such as python-ly. Building the documentation -------------------------- The documentation resides in the ``doc`` directory and can be built using the Sphinx toolchain (http://sphinx-doc.org/). Typing ``make html`` in the ``doc`` directory generates full HTML documentation in the ``doc/build/html`` directory. Typing ``make man`` in the ``doc`` directory generates a manpage for the ``ly`` command. This manpage is created in ``doc/build/man/ly.1`` and can be installed on UNIX systems in a location like ``/usr/share/man/man1/``. The documentation is not installed by default. .. _pug-installing: https://packaging.python.org/en/latest/tutorials/installing-packages/ python_ly-0.9.9/.github/workflows/ci.yml0000644000000000000000000000107713615410400015216 0ustar00name: CI on: [push, pull_request] jobs: specs: runs-on: ubuntu-latest strategy: matrix: python-version: - 3.8 # oldest officially supported by python-ly - 3.12 # latest steps: - name: Check out code uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: pip install pytest lxml - name: Run tests run: pytest tests/ python_ly-0.9.9/.github/workflows/release.yml0000644000000000000000000000506113615410400016240 0ustar00name: Publish Python 🐍 distribution πŸ“¦ to PyPI and TestPyPI on: push jobs: build: name: Build distribution πŸ“¦ runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: persist-credentials: false - name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.x" - name: Install pypa/build run: >- python3 -m pip install build --user - name: Build a binary wheel and a source tarball run: python3 -m build - name: Store the distribution packages uses: actions/upload-artifact@v4 with: name: python-package-distributions path: dist/ publish-to-pypi: name: >- Publish Python 🐍 distribution πŸ“¦ to PyPI if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes needs: - build runs-on: ubuntu-latest environment: name: pypi url: https://pypi.org/p/python-ly permissions: id-token: write # IMPORTANT: mandatory for trusted publishing steps: - name: Download all the dists uses: actions/download-artifact@v4 with: name: python-package-distributions path: dist/ - name: Publish distribution πŸ“¦ to PyPI uses: pypa/gh-action-pypi-publish@release/v1 github-release: name: >- Sign the Python 🐍 distribution πŸ“¦ with Sigstore and upload them to GitHub Release needs: - publish-to-pypi runs-on: ubuntu-latest permissions: contents: write # IMPORTANT: mandatory for making GitHub Releases id-token: write # IMPORTANT: mandatory for sigstore steps: - name: Download all the dists uses: actions/download-artifact@v4 with: name: python-package-distributions path: dist/ - name: Sign the dists with Sigstore uses: sigstore/gh-action-sigstore-python@v3.0.0 with: inputs: >- ./dist/*.tar.gz ./dist/*.whl - name: Create GitHub Release env: GITHUB_TOKEN: ${{ github.token }} run: >- gh release create "$GITHUB_REF_NAME" --repo "$GITHUB_REPOSITORY" --notes "" - name: Upload artifact signatures to GitHub Release env: GITHUB_TOKEN: ${{ github.token }} # Upload to GitHub Release using the `gh` CLI. # `dist/` contains the built packages, and the # sigstore-produced signatures and certificates. run: >- gh release upload "$GITHUB_REF_NAME" dist/** --repo "$GITHUB_REPOSITORY" python_ly-0.9.9/doc/Makefile0000644000000000000000000001513113615410400012704 0ustar00# Makefile for Sphinx documentation # # You can set these variables from the command line. SPHINXOPTS = SPHINXBUILD = sphinx-build PAPER = BUILDDIR = build # User-friendly check for sphinx-build ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1) $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/) endif # Internal variables. PAPEROPT_a4 = -D latex_paper_size=a4 PAPEROPT_letter = -D latex_paper_size=letter ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext help: @echo "Please use \`make ' where is one of" @echo " html to make standalone HTML files" @echo " dirhtml to make HTML files named index.html in directories" @echo " singlehtml to make a single large HTML file" @echo " pickle to make pickle files" @echo " json to make JSON files" @echo " htmlhelp to make HTML files and a HTML help project" @echo " qthelp to make HTML files and a qthelp project" @echo " devhelp to make HTML files and a Devhelp project" @echo " epub to make an epub" @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" @echo " latexpdf to make LaTeX files and run them through pdflatex" @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx" @echo " text to make text files" @echo " man to make manual pages" @echo " texinfo to make Texinfo files" @echo " info to make Texinfo files and run them through makeinfo" @echo " gettext to make PO message catalogs" @echo " changes to make an overview of all changed/added/deprecated items" @echo " xml to make Docutils-native XML files" @echo " pseudoxml to make pseudoxml-XML files for display purposes" @echo " linkcheck to check all external links for integrity" @echo " doctest to run all doctests embedded in the documentation (if enabled)" clean: rm -rf $(BUILDDIR)/* html: $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." dirhtml: $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml @echo @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." singlehtml: $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml @echo @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." pickle: $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle @echo @echo "Build finished; now you can process the pickle files." json: $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json @echo @echo "Build finished; now you can process the JSON files." htmlhelp: $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp @echo @echo "Build finished; now you can run HTML Help Workshop with the" \ ".hhp project file in $(BUILDDIR)/htmlhelp." qthelp: $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp @echo @echo "Build finished; now you can run "qcollectiongenerator" with the" \ ".qhcp project file in $(BUILDDIR)/qthelp, like this:" @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/ly.qhcp" @echo "To view the help file:" @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/ly.qhc" devhelp: $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp @echo @echo "Build finished." @echo "To view the help file:" @echo "# mkdir -p $$HOME/.local/share/devhelp/ly" @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/ly" @echo "# devhelp" epub: $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub @echo @echo "Build finished. The epub file is in $(BUILDDIR)/epub." latex: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." @echo "Run \`make' in that directory to run these through (pdf)latex" \ "(use \`make latexpdf' here to do that automatically)." latexpdf: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through pdflatex..." $(MAKE) -C $(BUILDDIR)/latex all-pdf @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." latexpdfja: $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex @echo "Running LaTeX files through platex and dvipdfmx..." $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." text: $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text @echo @echo "Build finished. The text files are in $(BUILDDIR)/text." man: $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man @echo @echo "Build finished. The manual pages are in $(BUILDDIR)/man." texinfo: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." @echo "Run \`make' in that directory to run these through makeinfo" \ "(use \`make info' here to do that automatically)." info: $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo @echo "Running Texinfo files through makeinfo..." make -C $(BUILDDIR)/texinfo info @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." gettext: $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale @echo @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." changes: $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes @echo @echo "The overview file is in $(BUILDDIR)/changes." linkcheck: $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck @echo @echo "Link check complete; look for any errors in the above output " \ "or in $(BUILDDIR)/linkcheck/output.txt." doctest: $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest @echo "Testing of doctests in the sources finished, look at the " \ "results in $(BUILDDIR)/doctest/output.txt." xml: $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml @echo @echo "Build finished. The XML files are in $(BUILDDIR)/xml." pseudoxml: $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml @echo @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml." python_ly-0.9.9/doc/command.rst0000644000000000000000000000017413615410400013415 0ustar00The ``ly`` command ================== .. automodule:: ly.cli.doc :members: :undoc-members: :show-inheritance: python_ly-0.9.9/doc/conf.py0000644000000000000000000002441413615410400012547 0ustar00# -*- coding: utf-8 -*- # # ly documentation build configuration file, created by # sphinx-quickstart on Sat Jan 24 11:57:29 2015. # # This file is execfile()d with the current directory set to its # containing dir. # # Note that not all possible configuration values are present in this # autogenerated file. # # All configuration values have a default; values that are commented out # serve to show the default. import sys import os # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. #sys.path.insert(0, os.path.abspath('.')) sys.path.insert(0, os.path.abspath('..')) import ly.pkginfo # -- General configuration ------------------------------------------------ # If your documentation needs a minimal Sphinx version, state it here. #needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.viewcode', ] # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] # The suffix of source filenames. source_suffix = {'.rst': 'restructuredtext'} # The encoding of source files. #source_encoding = 'utf-8-sig' # The master toctree document. master_doc = 'index' # General information about the project. project = 'python-ly' copyright = '2025, Wilbert Berendsen' # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. version = ly.pkginfo.version # The full version, including alpha/beta/rc tags. release = ly.pkginfo.version # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. #language = None # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: #today = '' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = ['build'] # The reST default role (used for this markup: `text`) to use for all # documents. #default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). #add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. #show_authors = False # The name of the Pygments (syntax highlighting) style to use. pygments_style = 'sphinx' # A list of ignored prefixes for module index sorting. #modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. #keep_warnings = False # -- Options for HTML output ---------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. html_theme = 'sphinx_rtd_theme' # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. #html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. #html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". #html_title = None # A shorter title for the navigation bar. Default is the same as html_title. #html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. #html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. #html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". #html_static_path = ['_static'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. #html_extra_path = [] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. #html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. #html_use_smartypants = True # Custom sidebar templates, maps document names to template names. #html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. #html_additional_pages = {} # If false, no module index is generated. #html_domain_indices = True # If false, no index is generated. #html_use_index = True # If true, the index is split into individual pages for each letter. #html_split_index = False # If true, links to the reST sources are added to the pages. #html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. #html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. #html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. #html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). #html_file_suffix = None # Output file base name for HTML help builder. htmlhelp_basename = 'lydoc' # -- Options for LaTeX output --------------------------------------------- latex_elements = { # The paper size ('letterpaper' or 'a4paper'). #'papersize': 'letterpaper', # The font size ('10pt', '11pt' or '12pt'). #'pointsize': '10pt', # Additional stuff for the LaTeX preamble. #'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ ('index', 'python-ly.tex', 'python-ly Documentation', 'Wilbert Berendsen', 'manual'), ] # The name of an image file (relative to this directory) to place at the top of # the title page. #latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. #latex_use_parts = False # If true, show page references after internal links. #latex_show_pagerefs = False # If true, show URL addresses after external links. #latex_show_urls = False # Documents to append as an appendix to all manuals. #latex_appendices = [] # If false, no module index is generated. #latex_domain_indices = True # -- Options for manual page output --------------------------------------- # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ ('command', 'ly', 'Manipulate LilyPond source files', ['Wilbert Berendsen'], 1), ('servercmd', 'ly-server', 'Manipulate LilyPond source files via HTTP', ['Wilbert Berendsen'], 1), ] # If true, show URL addresses after external links. #man_show_urls = False # -- Options for Texinfo output ------------------------------------------- # Grouping the document tree into Texinfo files. List of tuples # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ ('index', 'python-ly', 'python-ly Documentation', 'Author', 'python-ly', 'Tool and library for manipulating LilyPond files', 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. #texinfo_appendices = [] # If false, no module index is generated. #texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. #texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. #texinfo_no_detailmenu = False # -- Options for Epub output ---------------------------------------------- # Bibliographic Dublin Core info. epub_title = 'python-ly' epub_author = 'Wilbert Berendsen' epub_publisher = 'Wilbert Berendsen' epub_copyright = '2025, Wilbert Berendsen' # The basename for the epub file. It defaults to the project name. #epub_basename = 'ly' # The HTML theme for the epub output. Since the default themes are not optimized # for small screen space, using the same theme for HTML and epub output is # usually not wise. This defaults to 'epub', a theme designed to save visual # space. #epub_theme = 'epub' # The language of the text. It defaults to the language option # or en if the language is not set. #epub_language = '' # The scheme of the identifier. Typical schemes are ISBN or URL. #epub_scheme = '' # The unique identifier of the text. This can be a ISBN number # or the project homepage. #epub_identifier = '' # A unique identification for the text. #epub_uid = '' # A tuple containing the cover image and cover page html template filenames. #epub_cover = () # A sequence of (type, uri, title) tuples for the guide element of content.opf. #epub_guide = () # HTML files that should be inserted before the pages created by sphinx. # The format is a list of tuples containing the path and title. #epub_pre_files = [] # HTML files shat should be inserted after the pages created by sphinx. # The format is a list of tuples containing the path and title. #epub_post_files = [] # A list of files that should not be packed into the epub file. epub_exclude_files = ['search.html'] # The depth of the table of contents in toc.ncx. #epub_tocdepth = 3 # Allow duplicate toc entries. #epub_tocdup = True # Choose between 'default' and 'includehidden'. #epub_tocscope = 'default' # Fix unsupported image types using the PIL. #epub_fix_images = False # Scale large images. #epub_max_image_width = 0 # How to display URL addresses: 'footnote', 'no', or 'inline'. #epub_show_urls = 'inline' # If false, no index is generated. #epub_use_index = True python_ly-0.9.9/doc/index.rst0000644000000000000000000000230413615410400013103 0ustar00.. python-ly documentation master file, created by sphinx-quickstart on Sat Jan 24 11:57:29 2015. You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. Welcome to python-ly's documentation! ===================================== This package provides a Python library `ly` containing various Python modules to parse, manipulate or create documents in LilyPond format. A command line program `ly` is also provided that can be used to do various manipulations with LilyPond files. The LilyPond format is a plain text input format that is used by the GNU music typesetter LilyPond (www.lilypond.org). The python-ly package is Free Software, licensed under the GPL. This package is written by the Frescobaldi developers and is used extensively by the Frescobaldi project. The main author is Wilbert Berendsen. | Download from: https://pypi.python.org/project/python-ly | Development homepage: https://github.com/frescobaldi/python-ly This documentation describes python-ly |version|. Contents: .. toctree:: :maxdepth: 4 command servercmd ly Indices and tables ================== * :ref:`genindex` * :ref:`modindex` * :ref:`search` python_ly-0.9.9/doc/ly.cli.rst0000644000000000000000000000065513615410400013175 0ustar00ly.cli package ============== Module contents --------------- .. automodule:: ly.cli :members: :undoc-members: :show-inheritance: Submodules ---------- ly.cli.command module --------------------- .. automodule:: ly.cli.command :members: :undoc-members: :show-inheritance: ly.cli.main module ------------------ .. automodule:: ly.cli.main :members: :undoc-members: :show-inheritance: python_ly-0.9.9/doc/ly.data.rst0000644000000000000000000000051213615410400013327 0ustar00ly.data package =============== Module contents --------------- .. automodule:: ly.data :members: :undoc-members: :show-inheritance: Submodules ---------- ly.data.makeschemedata module ----------------------------- .. automodule:: ly.data.makeschemedata :members: :undoc-members: :show-inheritance: python_ly-0.9.9/doc/ly.lex.rst0000644000000000000000000000167613615410400013222 0ustar00ly.lex package ============== Module contents --------------- .. automodule:: ly.lex :members: :undoc-members: :show-inheritance: Submodules ---------- ly.lex.docbook module --------------------- .. automodule:: ly.lex.docbook :members: :undoc-members: :show-inheritance: ly.lex.html module ------------------ .. automodule:: ly.lex.html :members: :undoc-members: :show-inheritance: ly.lex.latex module ------------------- .. automodule:: ly.lex.latex :members: :undoc-members: :show-inheritance: ly.lex.lilypond module ---------------------- .. automodule:: ly.lex.lilypond :members: :undoc-members: :show-inheritance: ly.lex.scheme module -------------------- .. automodule:: ly.lex.scheme :members: :undoc-members: :show-inheritance: ly.lex.texinfo module --------------------- .. automodule:: ly.lex.texinfo :members: :undoc-members: :show-inheritance: python_ly-0.9.9/doc/ly.music.rst0000644000000000000000000000107613615410400013544 0ustar00ly.music package ================ Module contents --------------- .. automodule:: ly.music :members: :undoc-members: :show-inheritance: Submodules ---------- ly.music.event module --------------------- .. automodule:: ly.music.event :members: :undoc-members: :show-inheritance: ly.music.items module --------------------- .. automodule:: ly.music.items :members: :undoc-members: :show-inheritance: ly.music.read module -------------------- .. automodule:: ly.music.read :members: :undoc-members: :show-inheritance: python_ly-0.9.9/doc/ly.musicxml.rst0000644000000000000000000000151613615410400014264 0ustar00ly.musicxml package =================== Module contents --------------- .. automodule:: ly.musicxml :members: :undoc-members: :show-inheritance: Submodules ---------- ly.musicxml.create_musicxml module ---------------------------------- .. automodule:: ly.musicxml.create_musicxml :members: :undoc-members: :show-inheritance: ly.musicxml.ly2xml_mediator module ---------------------------------- .. automodule:: ly.musicxml.ly2xml_mediator :members: :undoc-members: :show-inheritance: ly.musicxml.lymus2musxml module ------------------------------- .. automodule:: ly.musicxml.lymus2musxml :members: :undoc-members: :show-inheritance: ly.musicxml.xml_objs module --------------------------- .. automodule:: ly.musicxml.xml_objs :members: :undoc-members: :show-inheritance: python_ly-0.9.9/doc/ly.pitch.rst0000644000000000000000000000135313615410400013531 0ustar00ly.pitch package ================ Module contents --------------- .. automodule:: ly.pitch :members: :undoc-members: :show-inheritance: Submodules ---------- ly.pitch.abs2rel module ----------------------- .. automodule:: ly.pitch.abs2rel :members: :undoc-members: :show-inheritance: ly.pitch.rel2abs module ----------------------- .. automodule:: ly.pitch.rel2abs :members: :undoc-members: :show-inheritance: ly.pitch.translate module ------------------------- .. automodule:: ly.pitch.translate :members: :undoc-members: :show-inheritance: ly.pitch.transpose module ------------------------- .. automodule:: ly.pitch.transpose :members: :undoc-members: :show-inheritance: python_ly-0.9.9/doc/ly.rst0000644000000000000000000000431313615410400012422 0ustar00The ``ly`` package ================== Module contents --------------- .. automodule:: ly :members: :undoc-members: :show-inheritance: Subpackages ----------- .. toctree:: ly.lex ly.music ly.musicxml ly.pitch ly.xml ly.data ly.cli ly.server Submodules ---------- ly.slexer module ---------------- .. automodule:: ly.slexer :members: :undoc-members: :show-inheritance: ly.document module ------------------ .. automodule:: ly.document :members: :undoc-members: :show-inheritance: ly.docinfo module ----------------- .. automodule:: ly.docinfo :members: :undoc-members: :show-inheritance: ly.barcheck module ------------------ .. automodule:: ly.barcheck :members: :undoc-members: :show-inheritance: ly.colorize module ------------------ .. automodule:: ly.colorize :members: :undoc-members: :show-inheritance: ly.cursortools module --------------------- .. automodule:: ly.cursortools :members: :undoc-members: :show-inheritance: ly.dom module ------------- This module is deprecated. When `ly.music` is able to generate LilyPond code from scratch, this module will be removed. .. automodule:: ly.dom :members: :undoc-members: :show-inheritance: ly.duration module ------------------ .. automodule:: ly.duration :members: :undoc-members: :show-inheritance: ly.etreeutil module ------------------- .. automodule:: ly.etreeutil :members: :undoc-members: :show-inheritance: ly.indent module ---------------- .. automodule:: ly.indent :members: :undoc-members: :show-inheritance: ly.node module -------------- .. automodule:: ly.node :members: :undoc-members: :show-inheritance: ly.reformat module ------------------ .. automodule:: ly.reformat :members: :undoc-members: :show-inheritance: ly.rhythm module ---------------- .. automodule:: ly.rhythm :members: :undoc-members: :show-inheritance: ly.util module -------------- .. automodule:: ly.util :members: :undoc-members: :show-inheritance: ly.words module --------------- .. automodule:: ly.words :members: :undoc-members: :show-inheritance: python_ly-0.9.9/doc/ly.server.rst0000644000000000000000000000134713615410400013733 0ustar00ly.server package ================= Module contents --------------- .. automodule:: ly.server :members: :undoc-members: :show-inheritance: Submodules ---------- ly.server.command module ------------------------ .. automodule:: ly.server.command :members: :undoc-members: :show-inheritance: ly.server.handler module ------------------------ .. automodule:: ly.server.handler :members: :undoc-members: :show-inheritance: ly.server.main module --------------------- .. automodule:: ly.server.main :members: :undoc-members: :show-inheritance: ly.server.options module ------------------------ .. automodule:: ly.server.options :members: :undoc-members: :show-inheritance: python_ly-0.9.9/doc/ly.xml.rst0000644000000000000000000001437613615410400013233 0ustar00ly.xml package =============== Introduction ------------ This package is concerned with representing a LilyPond structure (e.g. music) as an XML tree. The structure of the tree closely follows LilyPond's data structures. The tree can be parsed or analysed, and could be used to convert the music to other formats like Mei of MusicXML. This package tries to define the exact format (dtd or schema) of the tree. There will be three ways to build the tree: - by hand, by creating XML elements (maybe with use of some helper methods). - from a tokenized document - by LilyPond, using the ``xml-export.ily`` script that is included. The latter case is very interesting as all the music parsing and handling is already done by LilyPond. The exported XML nearly contains all information of a score or music object. Below, some more information about the XML. Note that this is all in heavy development. Module contents --------------- .. automodule:: ly.xml :members: :undoc-members: :show-inheritance: The ``xml-export.ily`` file --------------------------- Written by Wilbert Berendsen, jan-feb 2015 This LilyPond module defines a function (``xml-export``) that converts LilyPond datastructures to XML. For convenience, a ``\displayLilyXML`` music function is added that converts a music expression to XML. Usage e.g.:: \include "/path/to/xml-export.ily" \displayLilyXML { c d e f } The XML closely follows the LilyPond music structure. All ``(make-music 'MusicName ...)`` objects translate to a ```` tag. The music in the ``'element`` and ``'elements`` properties is put in the ```` and ```` tags. (LilyPond uses ``'element`` when there is a single music argument, and ``'elements`` for a list of music arguments, but for example ``\repeat`` uses both: ``'element`` for the repeated music and ``'elements`` for the ``\alternatives``.) Thus ````, if there, always has one ```` child. ````, if there, can have more than one ```` child. Besides ``'element`` and ``'elements``, the following properties of music objects are handled specially: - ``'origin`` => ```` element with ``filename``, ``line`` and ``char`` attributes - ``'pitch`` => ```` element with ``octave``, ``notename`` and ``alteration`` attributes - ``'duration`` => ```` element with ``log``, ``dots``, ``numer`` and ``denom`` attributes - ``'articulations`` => ```` element containing ```` elements - ``'tweaks`` => ```` element containing pairs ``(symbol . value)`` All other properties a music object may have, are translated to a ```` element with a ``name`` attribute. The value is the child element and can be any object (string, list, pair, symbol, number etc.). (Note that the LilyPond command ``\displayMusic`` does not display all properties.) Markup objects are also converted to XML, where a toplevel ```` element is used. The individual markup commands are converted to an ```` element, with the name in the ``name`` attribute (e.g. ````). Arguments to markup commands may be other commands, or other objects (markup ``\score`` even has a score argument, which is also supported). Example ------- This LilyPond music:: \relative { c d e } maps to Scheme (using ``\displayMusic``):: (make-music 'RelativeOctaveMusic 'element (make-music 'SequentialMusic 'elements (list (make-music 'NoteEvent 'pitch (ly:make-pitch -1 0 0) 'duration (ly:make-duration 2 0 1)) (make-music 'NoteEvent 'pitch (ly:make-pitch -1 1 0) 'duration (ly:make-duration 2 0 1)) (make-music 'NoteEvent 'pitch (ly:make-pitch -1 2 0) 'duration (ly:make-duration 2 0 1))))) and maps to XML (using ``\displayLilyXML``):: By default, the XML is written to standard output. To automatically export a full LilyPond document to an XML representation, use the ``xml-export-init.ly`` script with the ``--init`` LilyPond option. That script automatically sets up LilyPond to output one XML document with a ```` root element, containing a ```` element for every book in the LilyPond file. (LilyPond always creates at least one book, collecting all the music or markup at the toplevel.) The ``xml-export-init.ly`` script is intended to be used via the ``--init`` option. It automatically converts every ``\book`` in the score to an XML document. In this case the XML is also written to standard output by default, but you can specify another file with ``-dxml-export=``. So, to convert a LilyPond source file to an XML file containing the LilyPond music structure in XML format, use the following command:: lilypond --init /path/to/xml-export-init.ly -dxml-export=song.xml song.ly The XML document has a ```` root element, containing a ```` element for every book in the LilyPond file. python_ly-0.9.9/doc/requirements.txt0000644000000000000000000000004613615410400014527 0ustar00Sphinx==8.1.3 sphinx-rtd-theme==3.0.2 python_ly-0.9.9/doc/servercmd.rst0000644000000000000000000000021513615410400013765 0ustar00The ``ly-server`` command ========================= .. automodule:: ly.server.doc :members: :undoc-members: :show-inheritance: python_ly-0.9.9/ly/__init__.py0000644000000000000000000000466313615410400013244 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2008 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ A package of modules dealing with LilyPond and the LilyPond format. The ly module supports both Python2 and Python3. This is a short description of some modules: * ly.slexer: generic tools to build parsers using regular expressions * ly.node: a generic list-like node object to build tree structures with * ly.document: a tokenized text document (LilyPond file) * ly.docinfo: harvests and caches various information from a LilyPond document * ly.lex: a parser for LilyPond, Scheme, and other formats, using slexer * ly.music: a tree structure of the contents of a document * ly.pitch: functions for translating, transposing etc * ly.rhythm: functions dealing with rhythm * ly.indent: indent LilyPond text * ly.reformat: format LilyPond text * ly.dom: (deprecated) tree structure to build LilyPond text from * ly.words: words for highlighting and autocompletion * ly.data: layout objects, properties, interfaces, font glyphs etc extracted from LilyPond * ly.cli: the implementation of the command-line 'ly' script A LilyPond document (source file) is held by a ly.document.Document. The Document class automatically parses and tokenizes the text, also when its contents are changed. A music tree can be built from a document using the ly.music module. In the near future, music trees can be built from scratch and also generate LilyPond output from scratch. At that moment, ly.dom is deprecated. The functions in ly.pitch, such as transpose and translate currently access the tokens in the document, but in the future they will work on the music tree. """ python_ly-0.9.9/ly/__main__.py0000644000000000000000000000025713615410400013220 0ustar00# included for testing, use: # python -m ly to call the command line interface if __name__ == "__main__": import sys from ly.cli.main import main sys.exit(main()) python_ly-0.9.9/ly/barcheck.py0000644000000000000000000001262613615410400013245 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2008 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ Add, check or remove bar checks in selected music. """ from __future__ import unicode_literals from __future__ import print_function import collections import itertools import ly.document import ly.lex.lilypond def remove(cursor): """Remove bar checks from the selected music.""" s = ly.document.Source(cursor, tokens_with_position=True) prv, cur = None, None with cursor.document as d: for nxt in itertools.chain(s, (None,)): if isinstance(cur, ly.lex.lilypond.PipeSymbol): if isinstance(prv, ly.lex.Space): # pipesymbol and adjacent space may be deleted if nxt == '\n': del d[prv.pos:cur.end] elif isinstance(nxt, ly.lex.Space): del d[cur.pos:nxt.end] else: del d[cur.pos:cur.end] elif isinstance(nxt, ly.lex.Space): # delete if followed by a space del d[cur.pos:cur.end] else: # replace "|" with a space d[cur.pos:cur.end] = " " prv, cur = cur, nxt class event(object): """A limited event type at a certain time.""" def __init__(self): self._nodes = [] self.cadenza = None self.barcheck = False self.timesig = None self.partial = None def append(self, node): self._nodes.append(node) def __repr__(self): s = [] if self.cadenza is not None: s.append('cadenza' + ('On' if self.cadenza else 'Off')) if self.barcheck: s.append('bar') if self.timesig is not None: s.append('T{0}'.format(self.timesig)) if self.partial is not None: s.append('P{0}'.format(self.partial)) if self._nodes: s.append(repr(self._nodes)) return ''.format(' '.join(s)) def insert(cursor, music=None): """Insert bar checks within the selected range.""" if music is None: import ly.music music = ly.music.document(cursor.document) if len(music) == 0: return if cursor.start: n = music.node(cursor.start, 1) nodes = itertools.chain((n,), n.forward()) else: nodes = music if cursor.end is None: iter_nodes = iter else: predicate = lambda node: node.position < cursor.end def iter_nodes(it): return itertools.takewhile(predicate, it) # make time-based lists of events event_lists = [] def do_topnode(node): if not isinstance(node, ly.music.items.Music): for n in node: do_topnode(n) return def do_node(node, time, scaling): if isinstance(node, (ly.music.items.Durable, ly.music.items.UserCommand)): if node.position >= cursor.start: events[time].append(node) time += node.length() * scaling elif isinstance(node, ly.music.items.TimeSignature): events[time].timesig = node.measure_length() elif isinstance(node, ly.music.items.Partial): events[time].partial = node.length() elif isinstance(node, ly.music.items.PipeSymbol): events[time].barcheck = True elif isinstance(node, ly.music.items.Command) and node.token in ( 'cadenzaOn', 'cadenzaOff'): events[time].cadenza = node.token == 'cadenzaOn' elif isinstance(node, ly.music.items.Grace): pass elif isinstance(node, ly.music.items.LyricMode): pass elif isinstance(node, ly.music.items.MusicList) and node.simultaneous: time = max(do_node(n, time, scaling) for n in iter_nodes(node)) elif isinstance(node, ly.music.items.Music): if isinstance(node, ly.music.items.Scaler): scaling *= node.scaling for n in iter_nodes(node): time = do_node(n, time, scaling) else: do_topnode(node) return time events = collections.defaultdict(event) do_node(node, 0, 1) event_lists.append(sorted(events.items())) do_topnode(nodes) for event_list in event_lists: # default to 4/4 without pickup measure_length = 1 measure_pos = 0 for time, evt in event_list: print(time, evt) python_ly-0.9.9/ly/colorize.py0000644000000000000000000005201613615410400013326 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2013 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ Classes and functions to colorize (syntax-highlight) parsed source. Highlighting is based on CSS properties and their values, although the Mapping object can map a token's class to any object or value. The Mapping object normally maps a token's class basically to a CSS class and possibly a base CSS class. This way you can define base styles (e.g. string, comment, etc) and have specific classes (e.g. LilyPond string, Scheme comment) inherit from that base style. This CSS class is described by the css_class named tuple, with its three fields: mode, name, base. E.g. ('lilypond', 'articulation', 'keyword'). The base field may be None. The css classes are mapped to dictionaries of css properties, like {'font-weight': 'bold', 'color': '#4800ff'}, etc. A scheme (a collection of styles) is simply a dictionary mapping the mode to a dictionary of CSS dictionaries. The base styles are in the [None] item of the scheme dictionary. """ from __future__ import unicode_literals from __future__ import absolute_import from __future__ import print_function import collections import ly.lex # don't test all the Token base classes _token_mro_slice = slice(1, -len(ly.lex.Token.__mro__)) style = collections.namedtuple("style", "name base classes") css_class = collections.namedtuple("css_class", "mode name base") class Mapper(dict): """Maps token classes to arbitrary values, which can be highlighting styles. Mapper behaves like a dict, you set items with a token class as key to an arbitrary value. But getting items can be done using a token. The token class's method resolution order is walked up and the value for the first available class found in the keys is returned. The class is also cached to speed up requests for other tokens. """ def __getitem__(self, token): cls = type(token) try: return dict.__getitem__(self, cls) except KeyError: for c in cls.__mro__[_token_mro_slice]: try: value = dict.__getitem__(self, c) break except KeyError: pass else: value = None self[cls] = value return value def default_mapping(): """Return a good default mapping from token class(es) to style and default style, per group.""" from ly.lex import lilypond from ly.lex import scheme from ly.lex import html from ly.lex import texinfo #from ly.lex import latex #from ly.lex import docbook from ly.lex import mup return ( ('lilypond', ( style('keyword', 'keyword', (lilypond.Keyword,)), style('command', 'function', (lilypond.Command, lilypond.Skip)), style('pitch', None, (lilypond.MusicItem,)), style('octave', None, (lilypond.Octave,)), style('accidental', None, (lilypond.Accidental, lilypond.FigureAccidental)), style('duration', None, (lilypond.Duration,)), style('dynamic', None, (lilypond.Dynamic,)), style('check', None, (lilypond.OctaveCheck, lilypond.PipeSymbol)), style('articulation', None, (lilypond.Direction, lilypond.Articulation)), style('fingering', None, (lilypond.Fingering,)), style('stringnumber', None, (lilypond.StringNumber,)), style('slur', None, (lilypond.Slur,)), style('beam', None, (lilypond.Beam, lilypond.FigureBracket,)), style('chord', None, (lilypond.Chord, lilypond.ChordItem)), style('markup', 'function', (lilypond.Markup,)), style('lyricmode', 'function', (lilypond.LyricMode,)), style('lyrictext', None, (lilypond.Lyric,)), style('repeat', 'function', (lilypond.Repeat, lilypond.Tremolo,)), style('specifier', 'variable', (lilypond.Specifier,)), style('usercommand', 'variable', (lilypond.UserCommand,)), style('figbass', None, (lilypond.Figure,)), style('figbstep', None, (lilypond.FigureStep,)), style('figbmodif', None, (lilypond.FigureModifier,)), style('delimiter', 'keyword', (lilypond.Delimiter,)), style('context', None, (lilypond.ContextName,)), style('grob', None, (lilypond.GrobName,)), style('property', 'variable', (lilypond.ContextProperty,)), style('variable', 'variable', (lilypond.Variable,)), style('uservariable', None, (lilypond.UserVariable,)), style('value', 'value', (lilypond.Value,)), style('string', 'string', (lilypond.String,)), style('stringescape', 'escape', (lilypond.StringQuoteEscape,)), style('comment', 'comment', (lilypond.Comment,)), style('error', 'error', (lilypond.Error,)), )), ('scheme', ( style('scheme', None, (lilypond.SchemeStart, scheme.Scheme,)), style('string', 'string', (scheme.String,)), style('stringescape', 'escape', (scheme.StringQuoteEscape,)), style('comment', 'comment', (scheme.Comment,)), style('number', 'value', (scheme.Number,)), style('lilypond', None, (scheme.LilyPond,)), style('keyword', 'keyword', (scheme.Keyword,)), style('function', 'function', (scheme.Function,)), style('variable', 'variable', (scheme.Variable,)), style('constant', 'variable', (scheme.Constant,)), style('delimiter', None, (scheme.OpenParen, scheme.CloseParen,)), )), ('html', ( style('tag', 'keyword', (html.Tag,)), style('attribute', 'variable', (html.AttrName,)), style('value', 'value', (html.Value,)), style('string', 'string', (html.String,)), style('entityref', 'escape', (html.EntityRef,)), style('comment', 'comment', (html.Comment,)), style('lilypondtag', 'function', (html.LilyPondTag,)), )), ('texinfo', ( style('keyword', 'keyword', (texinfo.Keyword,)), style('block', 'function', (texinfo.Block,)), style('attribute', 'variable', (texinfo.Attribute,)), style('escapechar', 'escape', (texinfo.EscapeChar,)), style('verbatim', 'string', (texinfo.Verbatim,)), style('comment', 'comment', (texinfo.Comment,)), )), ('mup', ( style('string', 'string', (mup.String,)), style('stringescape', 'escape', (mup.StringQuoteEscape,)), style('comment', 'comment', (mup.Comment,)), style('macro', 'variable', (mup.Macro,)), style('preprocessor', 'keyword', (mup.Preprocessor,)), )), ) # end of mapping default_scheme = { # the base styles None: { 'keyword': { 'font-weight': 'bold', }, 'function': { 'font-weight': 'bold', 'color': '#0000c0', }, 'variable': { 'color': '#0000ff', }, 'value': { 'color': '#808000', }, 'string': { 'color': '#c00000', }, 'escape': { 'color': '#008080', }, 'comment': { 'color': '#808080', 'font-style': 'italic', }, 'error': { 'color': '#ff0000', 'text-decoration': 'underline', 'text-decoration-color': '#ff0000', }, }, 'lilypond': { 'duration': { 'color': '#008080', }, 'markup': { 'color': '#008000', 'font-weight': 'normal', }, 'lyricmode': { 'color': '#006000', }, 'lyrictext': { 'color': '#006000', }, 'grob': { 'color': '#c000c0', }, 'context': { 'font-weight': 'bold', }, 'slur': { 'font-weight': 'bold', }, 'articulation': { 'font-weight': 'bold', 'color': '#ff8000', }, 'dynamic': { 'font-weight': 'bold', 'color': '#ff8000', }, 'fingering': { 'color': '#ff8000', }, 'stringnumber': { 'color': '#ff8000', }, }, 'scheme': { }, 'html': { }, 'texinfo': { }, 'mup': { }, } # end of default_css_styles def get_tokens(cursor): """Return the list of tokens for the cursor. Tokens that are partially inside the cursor's selection are re-created so that they fall exactly within the selection. This can be used to convert a highlighted part of a document to e.g. HTML. """ tokens = list(ly.document.Source(cursor, None, ly.document.PARTIAL, True)) if tokens: if cursor.end is not None and tokens[-1].end > cursor.end: t = tokens[-1] tokens[-1] = type(t)(t[:cursor.end - t.end], t.pos) if cursor.start > tokens[0].pos: t = tokens[0] tokens[0] = type(t)(t[cursor.start - t.pos:], cursor.start) return tokens def map_tokens(cursor, mapper): """Yield a two-tuple(token, style) for every token. The style is what mapper[token] returns. Style may be None, which also happens with unparsed (not-tokenized) text. """ text = cursor.document.plaintext() start = cursor.start tokens = get_tokens(cursor) t = None for t in tokens: if t.pos > start: yield text[start:t.pos], None yield t, mapper[t] start = t.end if t and cursor.end is not None and cursor.end > t.end: yield text[t.end:cursor.end] def melt_mapped_tokens(mapped_tokens): """Melt adjacent tokens with the same mapping together.""" prev_tokens = [] prev_style = None for t, s in mapped_tokens: if s == prev_style or t.isspace(): prev_tokens.append(t) else: if prev_tokens: if prev_tokens[-1] == ' ': yield ''.join(prev_tokens[:-1]), prev_style yield ' ', None else: yield ''.join(prev_tokens), prev_style prev_tokens = [t] prev_style = s if prev_tokens: yield ''.join(prev_tokens), prev_style def css_mapper(mapping=None): """Return a Mapper dict, mapping token classes to two CSS classes. By default the mapping returned by default_mapping() is used. """ if mapping is None: mapping = default_mapping() return Mapper((cls, css_class(mode, style.name, style.base)) for mode, styles in mapping for style in styles for cls in style.classes) def css_dict(css_style, scheme=default_scheme): """Return the css properties dict for the style, taken from the scheme. This can be used for inline style attributes. """ d = {} try: d.update(scheme[None][css_style.base]) except KeyError: pass try: d.update(scheme[css_style.mode][css_style.name]) except KeyError: pass return d def css_item(i): """Return "name: value;" where i = (name, value).""" return '{0}: {1};'.format(*i) def css_attr(d): """Return a dictionary with a 'style' key. The value is the style items in d formatted with css_item() joined with spaces. If d is empty, an empty dictionary is returned. """ if d: return {'style': ' '.join(map(css_item, sorted(d.items())))} return {} def css_group(selector, d): """Return a "selector { items...}" part of a CSS stylesheet.""" return '{0} {{\n {1}\n}}\n'.format( selector, '\n '.join(map(css_item, sorted(d.items())))) def format_css_span_class(css_style): """Return a string like 'class="mode-style base"' for the specified style.""" c = css_style.mode + '-' + css_style.name if css_style.base: c += ' ' + css_style.base return 'class="{0}"'.format(c) class css_style_attribute_formatter(object): """Return the inline style attribute for a specified style.""" def __init__(self, scheme=default_scheme): self.scheme = scheme def __call__(self, css_style): d = css_dict(css_style, self.scheme) if d: return 'style="{0}"'.format(' '.join(map(css_item, sorted(d.items())))) def format_stylesheet(scheme=default_scheme): """Return a formatted stylesheet for the stylesheet scheme dictionary.""" sheet = [] key = lambda i: '' if i[0] is None else i[0] for mode, styles in sorted(scheme.items(), key=key): if styles: sheet.append('/* {0} */'.format( "mode: " + mode if mode else "base styles")) for css_class, d in sorted(styles.items()): if mode: selector = 'span.{0}-{1}'.format(mode, css_class) else: selector = '.' + css_class sheet.append(css_group(selector, d)) return '\n'.join(sheet) def html_escape(text): """Escape &, < and >.""" return text.replace('&', '&').replace('<', '<').replace('>', '>') def html_escape_attr(text): """Escape &, ", < and >.""" return html_escape(text).replace('"', '"') def html_format_attrs(d): """Format the attributes dict as a string. The attributes are escaped correctly. A space is prepended for every assignment. """ return ''.join(' {0}="{1}"'.format( k, html_escape_attr(format(v))) for k, v in d.items()) def html(cursor, mapper, span=format_css_span_class): """Return a HTML string with the tokens wrapped in elements. The span argument is a function returning an attribute for the tag for the specified style. By default the format_css_span_class() function is used, that returns a 'class="group style base"' string. You'll want to wrap the HTML inside
 tokens and add a CSS stylesheet.

    """
    result = []
    for t, style in melt_mapped_tokens(map_tokens(cursor, mapper)):
        arg = span(style) if style else None
        if arg:
            result.append(''.format(arg))
            result.append(html_escape(t))
            result.append('')
        else:
            result.append(html_escape(t))
    return ''.join(result)


def add_line_numbers(cursor, html, linenum_attrs=None, document_attrs=None):
    """Combines the html (returned by html()) with the line numbers in a HTML table.

    The linenum_attrs are put in the  tag for the line numbers. The
    default value is: {"style": "background: #eeeeee;"}. The document_attrs
    are put in the  tag for the document. The default is empty.

    By default, the id for the linenumbers  is set to "linenumbers",
    and the id for the document  is set to "document".

    """
    linenum_attrs = dict(linenum_attrs) if linenum_attrs else {"style": "background: #eeeeee;"}
    document_attrs = dict(document_attrs) if document_attrs else {}
    linenum_attrs.setdefault('id', 'linenumbers')
    document_attrs.setdefault('id', 'document')
    linenum_attrs['valign'] = 'top'
    linenum_attrs['align'] = 'right'
    linenum_attrs['style'] = linenum_attrs.get('style', '') + 'vertical-align: top; text-align: right;'
    document_attrs['valign'] = 'top'
    document_attrs['style'] = document_attrs.get('style', '') + 'vertical-align: top;'

    start_num = cursor.document.index(cursor.start_block()) + 1
    end_num = cursor.document.index(cursor.end_block()) + 1
    linenumbers = '
{0}
'.format('\n'.join(map(format, range(start_num, end_num)))) body = '
{0}
'.format(html) return ( '' '' '' '\n{1}\n' '' '' '\n{3}\n' '
\n').format( html_format_attrs(linenum_attrs), linenumbers, html_format_attrs(document_attrs), body) def format_html_document(body, title="", stylesheet=None, stylesheet_ref=None, encoding='UTF-8'): """Return a complete HTML document. The body is put inside body tags unchanged. The title is html-escaped. If stylesheet_ref is given, it is put as a reference in the HTML; if stylesheet is given, it is put verbatim in a \n'.format(stylesheet) return ( '\n' '\n' '{title}\n' '\n' '{css}' '\n' '\n{body}\n\n').format( title = html_escape(title), encoding = encoding, body = body, css = css, ) class HtmlWriter(object): """A do-it-all object to create syntax highlighted HTML. You can set the instance attributes to configure the behaviour in all details. Then call the html(cursor) method to get the HTML. """ fgcolor = None bgcolor = None linenumbers_fgcolor = None linenumbers_bgcolor = "#eeeeee" inline_style = False number_lines = False wrapper_tag = "pre" wrapper_attribute = "id" document_id = "document" linenumbers_id = "linenumbers" title = "" css_scheme = default_scheme css_mapper = None encoding = 'UTF-8' stylesheet_ref = None full_html = True def set_wrapper_attribute(self, attr): """Choose attribute name for wrapper tag""" valid_attrs = ["id", "class"] if attr in valid_attrs: self.wrapper_attribute = attr else: print("Invalid attribute, has to be one of {}".format(valid_attrs)) def set_wrapper_tag(self, tag): """Define the tag to be used for wrapping the content""" valid_tags = ['pre', 'code', 'div'] if tag in valid_tags: self.wrapper_tag = tag else: print("Invalid tag, has to be one of {}".format(valid_tags)) def html(self, cursor): """Return the output HTML.""" doc_style = {} if self.fgcolor: doc_style['color'] = self.fgcolor if self.bgcolor: doc_style['background'] = self.bgcolor num_style = {} if self.linenumbers_fgcolor: num_style['color'] = self.linenumbers_fgcolor if self.linenumbers_bgcolor: num_style['background'] = self.linenumbers_bgcolor num_attrs = {self.wrapper_attribute: self.linenumbers_id} doc_attrs = {self.wrapper_attribute: self.document_id} css = [] if self.inline_style: formatter = css_style_attribute_formatter(self.css_scheme) num_attrs.update(css_attr(num_style)) doc_attrs.update(css_attr(doc_style)) else: formatter = format_css_span_class wrap_type = '#' if self.wrapper_attribute == 'id' else '.' css.append(css_group(wrap_type + self.document_id, doc_style)) if self.number_lines: css.append(css_group(wrap_type + self.linenumbers_id, num_style)) css.append(format_stylesheet(self.css_scheme)) body = html(cursor, self.css_mapper or css_mapper(), formatter) if self.number_lines: body = add_line_numbers(cursor, body, num_attrs, doc_attrs) else: body = '<{0}{1}>{2}'.format(self.wrapper_tag, html_format_attrs(doc_attrs), body) if not self.full_html: return body if self.stylesheet_ref: css = None else: css = '\n'.join(css) return format_html_document(body, self.title, css, self.stylesheet_ref, self.encoding) python_ly-0.9.9/ly/cursortools.py0000644000000000000000000000547713615410400014107 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2013 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ Routines manipulating ly.document.Cursor instances. """ from __future__ import unicode_literals import ly.lex import ly.document def find_indent(iterable): """Yield (token, is_indent, nest) for every occurring indent/dedent token. The tokens are yielded from the specified iterable. """ nest = 0 for token in iterable: if isinstance(token, ly.lex.Indent): nest += 1 yield token, True, nest elif isinstance(token, ly.lex.Dedent): nest -= 1 yield token, False, nest def select_block(cursor): """Try to select a meaningful block. Searches backwards for an indenting token, then selects up to the corresponding dedenting token. If needed searches an extra level back to always extend the selection. Returns True if the cursor's selection has changed. """ end = cursor.end if cursor.end is not None else cursor.document.size() tokens = ly.document.Runner.at(cursor, after_token=True) # search backwards to the first indenting token for token, isindent, nest in find_indent(tokens.backward()): if isindent and nest == 1: pos1 = tokens.position() startpoint = tokens.copy() # found, now look forward for token, isindent, nest in find_indent(tokens.forward()): if not isindent and nest < 0 and tokens.position() + len(token) >= end: # we found the endpoint pos2 = tokens.position() + len(token) if nest < -1: threshold = 1 - nest for token, isindent, nest in find_indent(startpoint.backward()): if isindent and nest == threshold: pos1 = tokens.position() break cursor.start, cursor.end = pos1, pos2 return True return python_ly-0.9.9/ly/docinfo.py0000644000000000000000000003120613615410400013117 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2013 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ Harvest information from a ly.document.DocumentBase instance. """ from __future__ import unicode_literals from __future__ import absolute_import import re import collections import functools import itertools import ly.lex.lilypond import ly.pitch def _cache(func): """Simple decorator caching the return value of a function.""" @functools.wraps(func) def wrapper(self): try: return self._cache_[func] except AttributeError: self._cache_ = {} except KeyError: pass result = self._cache_[func] = func(self) return result return wrapper class DocInfo(object): """Harvest information from a ly.document.DocumentBase instance. All tokens are saved in the tokens attribute as a tuple. Newline tokens are added between all lines. All corresponding classes are in the classes attribute as a tuple. This makes quick search and access possible. The tokens are requested from the document using the tokens_with_position() method, so you can always locate them back in the original document using their pos attribute. DocInfo does not update when the document changes, you should just instantiate a new one. """ def __init__(self, doc): """Initialize with ly.document.DocumentBase instance.""" self._d = doc blocks = iter(doc) for b in blocks: tokens = doc.tokens_with_position(b) self.tokens = sum(map( lambda b: ((ly.lex.Newline('\n', doc.position(b) - 1),) + doc.tokens_with_position(b)), blocks), tokens) self.classes = tuple(map(type, self.tokens)) @property def document(self): return self._d def range(self, start=0, end=None): """Return a new instance of the DocInfo class for the selected range. Only the tokens completely contained within the range start..end are added to the new instance. This can be used to perform fast searches on a subset of a document. """ if start == 0 and end is None: return self lo = 0 hi = len(self.tokens) while lo < hi: mid = (lo + hi) // 2 if start > self.tokens[mid].pos: lo = mid + 1 else: hi = mid start = lo if end is not None: lo = 0 hi = len(self.tokens) while lo < hi: mid = (lo + hi) // 2 if end < self.tokens[mid].pos: hi = mid else: lo = mid + 1 end = lo - 1 s = slice(start, end) n = type(self).__new__(type(self)) n._d = self._d n.tokens = self.tokens[s] n.classes = self.classes[s] return n @_cache def mode(self): """Return the mode, e.g. "lilypond".""" return self._d.initial_state().mode() def find(self, token=None, cls=None, pos=0, endpos=-1): """Return the index of the first specified token and/or class after pos. If token is None, the cls should be specified. If cls is given, the token should be an instance of the specified class. If endpos is given, never searches beyond endpos. Returns -1 if the token is not found. """ if token is None: try: return self.classes.index(cls, pos, endpos) except ValueError: return -1 elif cls is None: try: return self.tokens.index(token, pos, endpos) except ValueError: return -1 else: while True: try: i = self.tokens.index(token, pos, endpos) except ValueError: return -1 if cls == self.classes[i]: return i pos = i + 1 def find_all(self, token=None, cls=None, pos=0, endpos=-1): """Yield all indices of the first specified token and/or class after pos. If token is None, the cls should be specified. If cls is given, the token should be an instance of the specified class. If endpos is given, never searches beyond endpos. Returns -1 if the token is not found. """ while True: i = self.find(token, cls, pos, endpos) if i == -1: break yield i pos = i + 1 @_cache def version_string(self): r"""Return the version as a string, e.g. "2.19.8". Looks for the \version LilyPond command. The string is returned without quotes. Returns None if there was no \version command found. """ i = self.find("\\version", ly.lex.lilypond.Keyword) if i != -1: tokens = iter(self.tokens[i+1:i+10]) for t in tokens: if not isinstance(t, (ly.lex.Space, ly.lex.Comment)): if t == '"': pred = lambda t: t != '"' else: pred = lambda t: not isinstance(t, (ly.lex.Space, ly.lex.Comment)) return ''.join(itertools.takewhile(pred, tokens)) @_cache def version(self): """Return the version_string() as a tuple of ints, e.g. (2, 16, 2).""" version = self.version_string() if version: return tuple(map(int, re.findall(r"\d+", version))) return () @_cache def include_args(self): r"""The list of \include command arguments.""" result = [] for i in self.find_all("\\include", ly.lex.lilypond.Keyword): tokens = iter(self.tokens[i+1:i+10]) for token in tokens: if not isinstance(token, (ly.lex.Space, ly.lex.Comment)): if token == '"': result.append(''.join(itertools.takewhile(lambda t: t != '"', tokens))) break return result @_cache def scheme_load_args(self): """The list of scheme (load) command arguments.""" result = [] for i in self.find_all("load", ly.lex.scheme.Keyword): tokens = iter(self.tokens[i+1:i+10]) for token in tokens: if not isinstance(token, (ly.lex.Space, ly.lex.Comment)): if token == '"': result.append(''.join(itertools.takewhile(lambda t: t != '"', tokens))) break return result @_cache def output_args(self): r"""The list of arguments of constructs defining the name of output documents. This looks at the \bookOutputName, \bookOutputSuffix and define output-suffix commands. Every argument is a two tuple(type, argument) where type is either "suffix" or "name". """ result = [] for arg_type, cmd, cls in ( ("suffix", "output-suffix", ly.lex.scheme.Word), ("suffix", "\\bookOutputSuffix", ly.lex.lilypond.Command), ("name", "\\bookOutputName", ly.lex.lilypond.Command), ): for i in self.find_all(cmd, cls): tokens = iter(self.tokens[i+1:i+6]) for t in tokens: if t == '"': arg = ''.join(itertools.takewhile(lambda t: t != '"', tokens)) result.append((arg_type, arg)) break elif isinstance(t, ly.lex.lilypond.Name): result.append((arg_type, format(t))) elif isinstance(t, (ly.lex.lilypond.SchemeStart, ly.lex.Space, ly.lex.Comment)): continue break return result @_cache def definitions(self): """The list of LilyPond identifiers the document defines.""" result = [] for i in self.find_all(None, ly.lex.lilypond.Name): if i == 0 or self.tokens[i-1] == '\n': result.append(self.tokens[i]) return result @_cache def markup_definitions(self): """The list of markup command definitions in the document.""" result = [] # find bla = \markup { .. } for i in self.find_all(None, ly.lex.lilypond.Name): if i == 0 or self.tokens[i-1] == '\n': for t in self.tokens[i+1:i+6]: if t == "\\markup": result.append(self.tokens[i]) elif t == "=" or t.isspace(): continue break # find #(define-markup-command construction for i in self.find_all('define-markup-command', ly.lex.scheme.Function): for t in self.tokens[i+1:i+6]: if isinstance(t, ly.lex.scheme.Word): result.append(t) break result.sort(key=lambda t: t.pos) return result @_cache def language(self): """The pitch language, None if not set in the document.""" languages = ly.pitch.pitchInfo.keys() for i in self.find_all("\\language", ly.lex.lilypond.Keyword): for t in self.tokens[i+1:i+10]: if isinstance(t, ly.lex.Space): continue elif t == '"': continue if t in languages: return t for n in self.include_args(): lang = n.rsplit('.', 1)[0] if lang in languages: return lang @_cache def global_staff_size(self): """The global-staff-size, if set, else None.""" i = self.find('set-global-staff-size', ly.lex.scheme.Function) if i != -1: try: return int(self.tokens[i+2]) except (IndexError, ValueError): pass @_cache def token_hash(self): """Return an integer hash for all non-whitespace and non-comment tokens. This hash does not change when only comments or whitespace are changed. """ return hash(tuple(t for t in self.tokens if not isinstance(t, (ly.lex.Space, ly.lex.Comment)))) @_cache def complete(self): """Return whether the document is probably complete and could be compilable.""" return self._d.state_end(self._d[len(self._d)-1]).depth() == 1 @_cache def has_output(self): """Return True when the document probably generates output. I.e. has notes, rests, markup or other output-generating commands. """ for t, c in ( (None, ly.lex.lilypond.MarkupStart), (None, ly.lex.lilypond.Note), (None, ly.lex.lilypond.Rest), ('\\include', ly.lex.lilypond.Keyword), (None, ly.lex.lilypond.LyricMode), ): for i in self.find_all(t, c): return True return False def count_tokens(self, cls): """Return the number of tokens that are (a subclass) of the specified class. If you only want the number of instances of the exact class (not a subclass of) you can use info.classes.count(cls), where info is a DocInfo instance. """ return sum([issubclass(c, cls) for c in self.classes], False) def counted_tokens(self): """Return a dictionary mapping classes to the number of instances of that class.""" return collections.Counter(self.classes) python_ly-0.9.9/ly/document.py0000644000000000000000000010410613615410400013314 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2013 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ DocumentBase and Document ========================= Represents a LilyPond source document (the text contents). The Document implementation keeps the document in a (unicode) text string, but you can inherit from the DocumentBase class to support other representations of the text content. Modifying is preferably done inside a context (the with statement), e.g.: .. code-block:: python d = Document('some string') with d: d[5:5] = 'different ' d.plaintext() --> 'some different string' Changes are applied when the context is exited, also the modified part of the document is re-tokenized. Changes may not overlap. You may modify the document outside a context, in which case the document is re-tokenized immediately. This is much slower however when performing multiple changes after each other. The tokens(block) method returns a tuple of tokens for the specified block. Depending on the implementation, a block describes a line in the LilyPond source document. It is not expected to have any methods, except that the '==' operator is supported between two blocks, and returns True if both refer to the same line of text in the source document. Cursor ====== Defines a range or position in a Document. Runner ====== A Runner allows iterating back and forth over the tokens of a document. Source ====== Iterate over tokens in a (part of a) Document, with or without state. """ from __future__ import unicode_literals from __future__ import absolute_import import io import sys import operator import collections import weakref import ly.lex class DocumentBase(object): """Abstract base class for Document instances. You should inherit the following methods: setplaintext __len__ __getitem__ block index position text tokens isvalid initial_state state_end apply_changes You may inherit (e.g. to get speed improvements): plaintext next_block previous_block blocks_forward blocks_backward state You may use the following attributes: filename (None) # can represent the filename of the document on disk encoding (None) # can represent the encoding of the document when reading/writing to disk """ filename = None encoding = None def __init__(self): """Constructor""" self._writing = 0 self._changes = collections.defaultdict(list) self._cursors = weakref.WeakSet() def __bool__(self): return True __nonzero__ = __bool__ # py2 compat def __iter__(self): """Iter over all blocks.""" return self.blocks_forward(self[0]) def __len__(self): """Return the number of blocks""" raise NotImplementedError() def __getitem__(self, index): """Return the block at the specified index.""" raise NotImplementedError() def plaintext(self): """The document contents as a plain text string.""" return '\n'.join(map(self.text, self)) def setplaintext(self, text): """Sets the document contents to the text string.""" raise NotImplementedError() def size(self): """Return the number of characters in the document.""" last_block = self[len(self) - 1] return self.position(last_block) + len(self.text(last_block)) def block(self, position): """Return the text block at the specified character position. The text block itself has no methods, but it can be used as an argument to other methods of this class. (Blocks do have to support the '==' operator.) """ raise NotImplementedError() def index(self, block): """Return the linenumber of the block (starting with 0).""" raise NotImplementedError() def blocks_forward(self, block): """Iter forward starting with the specified block.""" while self.isvalid(block): yield block block = self.next_block(block) def blocks_backward(self, block): """Iter backwards starting with the specified block.""" while self.isvalid(block): yield block block = self.previous_block(block) def position(self, block): """Return the position of the specified block.""" raise NotImplementedError() def text(self, block): """Return the text of the specified block.""" raise NotImplementedError() def next_block(self, block): """Return the next block, which may be invalid.""" index = self.index(block) if index < len(self) - 1: return self[index + 1] def previous_block(self, block): """Return the previous block, which may be invalid.""" index = self.index(block) if index > 0: return self[index - 1] def isvalid(self, block): """Return True if the block is a valid block.""" raise NotImplementedError() def isblank(self, block): """Return True if the block is empty or blank.""" t = self.text(block) return not t or t.isspace() def __enter__(self): """Start the context for modifying the document.""" self._writing += 1 return self def __exit__(self, exc_type, exc_val, exc_tb): """Exit the context for modifying.""" if exc_type is not None: # cancel all edits when an exception occurred self._writing = 0 self._changes.clear() elif self._writing == 1: if self._changes: self._sort_changes() self.update_cursors() self.apply_changes() del self._changes_list self._writing = 0 elif self._writing > 1: self._writing -= 1 def _register_cursor(self, cursor): """Make a weak reference to the cursor. This is called by the constructor of the Cursor. The Cursor gets updated when the document is changed. """ self._cursors.add(cursor) def check_changes(self): """Debugging method that checks for overlapping edits.""" pos = self.size() for start, end, text in self._changes_list: if end > pos: if len(text) > 12: text = text[:10] + '...' raise ValueError("overlapping edit: {0}-{1}: {2}".format(start, end, text)) pos = start def _sort_changes(self): """Sort all the changes and put them in the _changes_list.""" self._changes_list = [(start, end, text) for start, items in sorted(self._changes.items(), reverse=True) for end, text in reversed(sorted(items, key=lambda i: (i[0] is None, i[0])))] self._changes.clear() def update_cursors(self): """Updates the position of the registered Cursor instances.""" for start, end, text in self._changes_list: for c in self._cursors: if c.start > start: if end is None or end >= c.start: c.start = start else: c.start += start + len(text) - end if c.end is not None and c.end >= start: if end is None or end >= c.end: c.end = start + len(text) else: c.end += start + len(text) - end def apply_changes(self): """Apply the changes and update the tokens.""" raise NotImplementedError() def tokens(self, block): """Return the tuple of tokens of the specified block. The pos and end attributes of every token point to the position of the token in the block. """ raise NotImplementedError() def tokens_with_position(self, block): """Return a tuple of tokens of the specified block. The pos and end attributes of every token point to the position in the Document, instead of to the position in the current block. This makes it easier to iterate over tokens and change the document. """ pos = self.position(block) return tuple(type(t)(t, pos + t.pos) for t in self.tokens(block)) def initial_state(self): """Return the state at the beginning of the document.""" raise NotImplementedError() def state(self, block): """Return the state at the start of the specified block.""" prev = self.previous_block(block) if self.isvalid(prev): return self.state_end(prev) return self.initial_state() def state_end(self, block): """Return the state at the end of the specified block.""" raise NotImplementedError() def __setitem__(self, key, text): """Change the text pointed to in key (integer or slice). If start > stop in the slice (and stop is not None), start and stop are swapped. (This is different than usual Python behaviour, where stop is set to start if it was lower.) """ if isinstance(key, slice): start = key.start or 0 end = key.stop if end is not None and start > end: start, end = end, start else: start = key end = start + 1 text = text.replace('\r', '') if text or start != end: self._changes[start].append((end, text)) # when a change is made outside context manager, apply immediately if self._writing == 0: self._sort_changes() self.update_cursors() self.apply_changes() del self._changes_list def __delitem__(self, key): """Remove the range of text.""" self[key] = "" class Document(DocumentBase): """A plain text LilyPond source document that auto-updates the tokens. The modified attribute is set to True as soon as the document is changed, but the setplaintext() method sets it to False. """ modified = False def __init__(self, text='', mode=None): super(Document, self).__init__() self._fridge = ly.lex.Fridge() self._mode = mode self._guessed_mode = None self.setplaintext(text) @classmethod def load(cls, filename, encoding='utf-8', mode=None): """Load the document from a file, using the specified encoding and mode.""" with io.open(filename, encoding=encoding) as f: doc = cls(f.read(), mode) doc.filename = filename return doc def copy(self): """Return a full copy of the document.""" doc = Document(self.plaintext(), self.mode()) doc.filename = self.filename doc.encoding = self.encoding doc.modified = self.modified return doc def __len__(self): """Return the number of blocks""" return len(self._blocks) def __getitem__(self, index): """Return the block at the specified index.""" return self._blocks[index] def setmode(self, mode): """Sets the mode to one of the ly.lex modes. Use None to auto-determine the mode. """ if mode not in ly.lex.modes: mode = None if mode == self._mode: return self._mode, old_mode = mode, self._mode if not mode: self._guessed_mode = ly.lex.guessMode(self.plaintext()) if self._guessed_mode == old_mode: return elif not old_mode: if mode == self._guessed_mode: return self._update_all_tokens() def mode(self): """Return the mode (lilypond, html, etc). None means automatic mode.""" return self._mode def setplaintext(self, text): """Set the text of the document, sets modified to False.""" text = text.replace('\r', '') lines = text.split('\n') self._blocks = [_Block(t, n) for n, t in enumerate(lines)] pos = 0 for b in self._blocks: b.position = pos pos += len(b.text) + 1 if not self._mode: self._guessed_mode = ly.lex.guessMode(text) self._update_all_tokens() self.modified = False def _update_all_tokens(self): state = self.initial_state() for b in self._blocks: b.tokens = tuple(state.tokens(b.text)) b.state = self._fridge.freeze(state) def initial_state(self): """Return the state at the beginning of the document.""" return ly.lex.state(self._mode or self._guessed_mode) def state_end(self, block): """Return the state at the end of the specified block.""" return self._fridge.thaw(block.state) def block(self, position): """Return the text block at the specified character position.""" if 0 <= position <= self._blocks[-1].position + len(self._blocks[-1].text): lo = 0 hi = len(self._blocks) while lo < hi: mid = (lo + hi) // 2 if position < self._blocks[mid].position: hi = mid else: lo = mid + 1 return self._blocks[lo-1] def index(self, block): """Return the linenumber of the block (starting with 0).""" return block.index def position(self, block): """Return the position of the specified block.""" return block.position def text(self, block): """Return the text of the specified block.""" return block.text def isvalid(self, block): """Return True if the block is a valid block.""" return bool(block) def tokens(self, block): """Return the tuple of tokens of the specified block.""" return block.tokens def apply_changes(self): for start, end, text in self._changes_list: s = self.block(start) # first remove the old contents if end is None: # all text to the end should be removed s.text = s.text[:start - s.position] del self._blocks[s.index+1:] else: # remove until the end position e = self.block(end) s.text = s.text[:start - s.position] + e.text[end - e.position:] del self._blocks[s.index+1:e.index+1] # now insert the new stuff if text: lines = text.split('\n') lines[-1] += s.text[start - s.position:] s.text = s.text[:start - s.position] + lines[0] self._blocks[s.index+1:s.index+1] = map(_Block, lines[1:]) # make sure this line gets reparsed s.tokens = None # update the position of all the new blocks pos = s.position for i, b in enumerate(self._blocks[s.index:], s.index): b.index = i b.position = pos pos += len(b.text) + 1 self.modified = True # if the initial state has changed, reparse everything if not self._mode: mode = ly.lex.guessMode(self.plaintext()) if mode != self._guessed_mode: self._guessed_mode = mode self._update_all_tokens() return # update the tokens starting at block s state = self.state(s) reparse = False for block in self._blocks[s.index:]: if reparse or block.tokens is None: block.tokens = tuple(state.tokens(block.text)) frozen = self._fridge.freeze(state) reparse = block.state != frozen block.state = frozen else: state = self._fridge.thaw(block.state) class _Block(object): """A line of text. This class is only used by the Document implementation. """ position = sys.maxsize # prevent picking those blocks before updating pos state = None tokens = None def __init__(self, text="", index=-1): self.text = text self.index = index class Cursor(object): """Defines a certain range (selection) in a Document. You may change the start and end attributes yourself. Both must be an integer, end may also be None, denoting the end of the document. As long as you keep a reference to the Cursor, its positions are updated when the document changes. When text is inserted at the start position, it remains the same. But when text is inserted at the end of a cursor, the end position moves along with the new text. E.g.: .. code-block:: python d = Document('hi there, folks!') c = Cursor(d, 8, 8) with d: d[8:8] = 'new text' c.start, c.end --> (8, 16) Many tools in the ly module use this object to describe (part of) a document. """ def __init__(self, doc, start=0, end=None): self._d = doc self.start = start self.end = end doc._register_cursor(self) @property def document(self): return self._d def start_block(self): """Return the block the start attribute points at.""" return self._d.block(self.start) def end_block(self): """Return the block the end attribute points at.""" if self.end is None: return self._d[len(self._d)-1] return self._d.block(self.end) def blocks(self): """Iterate over the selected blocks. If there are multiple blocks and the cursor ends on the first position of the last selected block, that block is not included. """ if self.end == self.start: yield self.start_block() else: for b in self._d.blocks_forward(self.start_block()): if self.end is not None and self._d.position(b) >= self.end: break yield b def text(self): """Convenience method to return the selected text.""" return self._d.plaintext()[self.start:self.end] def text_before(self): """Return text before the cursor in it's start block.""" b = self.start_block() pos = self.start - self._d.position(b) return self._d.text(b)[:pos] def text_after(self): """Return text after the cursor in it's end block.""" if self.end is None: return "" b = self.end_block() pos = self.end - self._d.position(b) return self._d.text(b)[pos:] def has_selection(self): """Return True when there is some text selected.""" end = self.end if end is None: end = self._d.size() return self.start != end def select_all(self): """Select all text.""" self.start, self.end = 0, None def select_end_of_block(self): """Move end to the end of the block.""" if self.end is not None: end = self.end_block() self.end = self._d.position(end) + len(self._d.text(end)) def select_start_of_block(self): """Move start to the start of the block.""" start = self.start_block() self.start = self._d.position(start) def lstrip(self, chars=None): """Move start to the right, like Python's lstrip() string method.""" if self.has_selection(): text = self.text() self.start += len(text) - len(text.lstrip(chars)) def rstrip(self, chars=None): """Move end to the left, like Python's lstrip() string method.""" if self.has_selection(): text = self.text() end = self._d.size() if self.end is None else self.end end -= len(text) - len(text.rstrip(chars)) if end < self._d.size(): self.end = end def strip(self, chars=None): """Strip chars from the selection, like Python's strip() method.""" self.rstrip(chars) self.lstrip(chars) class Runner(object): """Iterates back and forth over tokens. A Runner can stop anywhere and remembers its current token. """ def __init__(self, doc, tokens_with_position=False): """Create and init with Document. If tokens_with_position is True, uses the tokens_with_position() method to get the tokens, else (by default), the tokens() method is used. The Runner is initialized at position 0. Alternatively, you can use the 'at' classmethod to construct a Runner at a specific cursor position. """ self._doc = doc self._wp = tokens_with_position self.move_to_block(doc[0]) @classmethod def at(cls, cursor, after_token=False, tokens_with_position=False): """Create and init from a Cursor. The Runner is positioned so that yielding forward starts with the first complete token after the cursor's start position. Set after_token to True if you want to position the cursor after the token, so that it gets yielded when you go backward. If tokens_with_position is True, uses the tokens_with_position() method to get the tokens, else (by default), the tokens() method is used. """ runner = cls(cursor.document, tokens_with_position) runner.set_position(cursor.start, after_token) return runner @property def document(self): """Return our Document.""" return self._doc def set_position(self, position, after_token=False): """Positions the Runner at the specified position. Set after_token to True if you want to position the cursor after the token, so that it gets yielded when you go backward. """ block = self._doc.block(position) self.move_to_block(block) if after_token: for t in self.forward_line(): if self.position() + len(t) >= position: self._index += 1 break else: for t in self.forward_line(): if self.position() + len(t) > position: self._index -= 1 break def move_to_block(self, block, at_end=False): """Positions the Runner at the start of the given text block. If at_end == True, the iterator is positioned past the end of the block. """ if self._doc.isvalid(block): self.block = block method = self._doc.tokens_with_position if self._wp else self._doc.tokens self._tokens = method(block) self._index = len(self._tokens) if at_end else -1 return True def _newline(self): """(Internal) Create a Newline token at the end of the current block.""" pos = len(self._doc.text(self.block)) if self._wp: pos += self._doc.position(self.block) return ly.lex.Newline('\n', pos) def next(self, current_block=False): """Return the next token or False if there is no more token. If current_block=True stop at the end of the current block.""" if self._index < len(self._tokens) - 1: self._index += 1 return self._tokens[self._index] elif current_block or not self.next_block(): return False else: return self._newline() def previous(self, current_block=False): """Return the previous token or False if there is no more token. If current_block=True stop at the beginning of the current block.""" if self._index > 0: self._index -= 1 return self._tokens[self._index] elif current_block or not self.previous_block(): return False else: return self._newline() def _forward(self, current_block): """Internal method to yield tokens in forward direction. current_block determines whether this is globally or limited to the current block.""" while True: token = self.next(current_block) if not token: break yield token def forward_line(self): """Yields tokens in forward direction in the current block.""" for token in self._forward(current_block=True): yield token def forward(self): """Yields tokens in forward direction across blocks.""" for token in self._forward(current_block=False): yield token def _backward(self, current_block): """Internal method to yield tokens in backward direction. current_block determines whether this is globally or limited to the current block.""" while True: token = self.previous(current_block) if not token: break yield token def backward_line(self): """Yields tokens in backward direction in the current block.""" for token in self._backward(current_block=True): yield token def backward(self): """Yields tokens in backward direction across blocks.""" for token in self._backward(current_block=False): yield token def previous_block(self, at_end=True): """Go to the previous block, positioning the cursor at the end by default. Returns False if there was no previous block, else True. """ return self.move_to_block(self._doc.previous_block(self.block), at_end) def next_block(self, at_end=False): """Go to the next block, positioning the cursor at the start by default. Returns False if there was no next block, else True. """ return self.move_to_block(self._doc.next_block(self.block), at_end) def token(self): """Re-returns the last yielded token.""" if self._tokens: index = self._index if index < 0: index = 0 elif index >= len(self._tokens): index = len(self._tokens) - 1 return self._tokens[index] def position(self): """Returns the position of the current token.""" if self._tokens: pos = self.token().pos if not self._wp: pos += self._doc.position(self.block) return pos else: return self._d.position(self.block) def copy(self): """Return a new Runner at the current position.""" obj = type(self)(self._doc, self._wp) obj.block = self.block obj._tokens = self._tokens obj._index = self._index return obj OUTSIDE = -1 PARTIAL = 0 INSIDE = 1 class Source(object): """Helper iterator. Iterates over the (block, tokens) tuples from a Document (or a part thereof). Stores the current block in the block attribute and the tokens (which also is a generator) in the tokens attribute. Iterating over the source object itself just yields the tokens, while the block attribute contains the current block. You can also iterate over the tokens attribute, which will yield the remaining tokens of the current block and then stop. If you specify a state, the tokens will update the state. If you specify state = True, the state will be taken from the document. """ def __init__(self, cursor, state=None, partial=INSIDE, tokens_with_position=False): """Initialize the iterator. cursor is a Cursor instance, describing a Document and a selected range state is, if given, a ly.lex.State instance or True (in which case the state is taken from the document). The following keyword arguments can be used: partial is either OUTSIDE, PARTIAL, or INSIDE: OUTSIDE: tokens that touch the selected range are also yielded PARTIAL: tokens that overlap the start or end positions are yielded INSIDE: (default) yield only tokens fully contained in the range The partial argument only makes sense if start or end are specified. If tokens_with_position is True, uses the document.tokens_with_position() method to get the tokens from the cursor's document, else (by default), the document.tokens() method is used. """ self._pushback = False self._last = None self._doc = document = cursor.document start_block = document.block(cursor.start) self._wp = tokens_with_position tokens_method = document.tokens_with_position if tokens_with_position else document.tokens # start, end predicates start_pred, end_pred = { OUTSIDE: ( lambda t: t.end < start_pos, lambda t: t.pos > end_pos, ), PARTIAL: ( lambda t: t.end <= start_pos, lambda t: t.pos >= end_pos, ), INSIDE: ( lambda t: t.pos < start_pos, lambda t: t.end > end_pos, ), }[partial] # if a state is given, use it (True: pick state from doc) if state: if state is True: state = document.state(start_block) def token_source(block): for t in tokens_method(block): state.follow(t) yield t else: def token_source(block): return iter(tokens_method(block)) self.state = state # where to start if cursor.start: start_pos = cursor.start if not tokens_with_position: start_pos -= document.position(start_block) # token source for first block def source_start(block): source = token_source(block) for t in source: if not start_pred(t): yield t for t in source: yield t else: source_start = token_source # where to end if cursor.end is not None: end_block = cursor.end_block() end_pos = cursor.end if not tokens_with_position: end_pos -= document.position(end_block) def source_end(source): for t in source: if end_pred(t): break yield t # generate the tokens def generator(): source = source_start block = start_block if cursor.end is not None: while block != end_block: yield block, source(block) source = token_source block = document.next_block(block) yield block, source_end(source(block)) else: for block in document.blocks_forward(start_block): yield block, source(block) source = token_source gen = generator() if tokens_with_position: def newline(): pos = document.position(self.block) - 1 return ly.lex.Newline('\n', pos) else: def newline(): pos = len(document.text(document.previous_block(self.block))) return ly.lex.Newline('\n', pos) # initialize block and tokens for self.block, self.tokens in gen: break # keep them going after the first line def g(): for t in self.tokens: yield t for self.block, self.tokens in gen: yield newline() for t in self.tokens: yield t self._gen = g() def __iter__(self): return self def __next__(self): if self._pushback: self._pushback = False return self._last i = self._last = next(self._gen) return i next = __next__ def pushback(self, pushback=True): """Yields the last yielded token again on the next request. This can be called multiple times, but only the last token will be yielded again. You can also undo a call to pushback() using pushback(False). """ self._pushback = pushback def token(self): """Re-returns the last yielded token.""" return self._last @property def document(self): """Return our Document.""" return self._doc def position(self, token): """Returns the position of the token in the current block. If the iterator was instantiated with tokens_with_position == True, this position is the same as the token.pos attribute, and the current block does not matter. (In that case you'll probably not use this method.) """ pos = token.pos if not self._wp: pos += self._doc.position(self.block) return pos def until_parser_end(self): """Yield the tokens until the current parser is quit. You can only use this method if you have a State enabled. """ depth = self.state.depth() for t in self: yield t if self.state.depth() < depth and not self._pushback: break def consume(self, iterable, position): """Consumes iterable (supposed to be reading from us) until position. Returns the last token if that overlaps position. """ if self._doc.position(self.block) < position: for t in iterable: pos = self.position(t) end = pos + len(t) if end == position: return elif end > position: return t python_ly-0.9.9/ly/dom.py0000644000000000000000000006201013615410400012252 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2008 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ LilyPond DOM (c) 2008-2011 Wilbert Berendsen License: GPL. A simple Document Object Model for LilyPond documents. The purpose is to easily build a LilyPond document with good syntax, not to fully understand all features LilyPond supports. (This DOM does not enforce a legal LilyPond file.) All elements of a LilyPond document inherit Node. Note: elements keep a weak reference to their parent. """ from __future__ import unicode_literals from __future__ import absolute_import # prevent picking old stale node.py from package try: string_types = basestring except NameError: string_types = str import fractions import re import ly.pitch import ly.duration from ly.node import WeakNode class LyNode(WeakNode): """ Base class for LilyPond objects, based on Node, which takes care of the tree structure. """ ## # True if this element is single LilyPond atom, word, note, etc. # When it is the only element inside { }, the brackets can be removed. isAtom = False ## # The number of newlines this object wants before it. before = 0 ## # The number of newlines this object wants after it. after = 0 def ly(self, printer): """ Returns printable output for this object. Can ask printer for certain settings, e.g. pitch language etc. """ return '' def concat(self, other): """ Returns a string with newlines to concat this node to another one. If zero newlines are requested, an empty string is returned. """ return '\n' * max(self.after, other.before) ## # Leaf and Container are the two base classes the rest of the LilyPond # element classes is based on. # class Leaf(LyNode): """ A leaf node without children """ pass class Container(LyNode): """ A node that concatenates its children on output """ ## # default character to concatenate children with defaultSpace = " " @property def before(self): if len(self): return self[0].before else: return 0 @property def after(self): if len(self): return self[-1].after else: return 0 def ly(self, printer): if len(self) == 0: return '' else: n = self[0] res = [n.ly(printer)] for m in self[1:]: res.append(n.concat(m) or self.defaultSpace) res.append(m.ly(printer)) n = m return "".join(res) ## # Helper classes # class Printer(object): """ Performs certain operations on behalf of a LyNode tree, like quoting strings or translating pitch names, etc. """ # You may change these primary_quote_left = '\u2018' primary_quote_right = '\u2019' secondary_quote_left = '\u201C' secondary_quote_right = '\u201D' def __init__(self): self.typographicalQuotes = True self.language = "nederlands" self.indentString = ' ' def quoteString(self, text): if self.typographicalQuotes: text = re.sub(r'"(.*?)"', self.primary_quote_left + r'\1' + self.primary_quote_right, text) text = re.sub(r"'(.*?)'", self.secondary_quote_left + r'\1' + self.secondary_quote_right, text) text = text.replace("'", '\u2018') # escape regular double quotes text = text.replace('"', '\\"') # quote the string return '"{0}"'.format(text) def indentGen(self, node, startIndent = 0): """ A generator that walks on the output of the given node, and returns properly indented LilyPond code. """ d = startIndent for t in node.ly(self).splitlines() + [''] * node.after: if d and re.match(r'#?}|>|%}', t): d -= 1 yield self.indentString * d + t if re.search(r'(\{|<|%{)$', t): d += 1 def indent(self, node): """ Return a formatted printout of node (and its children) """ return '\n'.join(self.indentGen(node)) class Reference(object): """ A simple object that keeps a name, to use as a (context) identifier. Set the name attribute to the name you want to display, and on all places in the document the name will show up. """ def __init__(self, name=""): self.name = name def __format__(self, format_spec): return self.name class Named(object): r""" Mixin to print a \name before the contents of the container. format() is called on the self.name attribute, so it may also be a Reference. """ name = "" def ly(self, printer): return "\\{0} {1}".format(self.name, super(Named, self).ly(printer)) class HandleVars(object): """ A powerful mixin class to facilitate handling unique variable assignments inside a Container more. E.g.: >>> h = Header() >>> h['composer'] = "Johann Sebastian Bach" creates a subnode (by default Assignment) with the name 'composer', and that node again gets an autogenerated subnode of type QuotedString (if the argument wasn't already a Node). """ childClass = None # To be filled in later def ifbasestring(func): """ Ensure that the method is only called for basestring objects. Otherwise the same method from the super class is called. """ def newfunc(obj, name, *args): if isinstance(name, string_types): return func(obj, name, *args) else: f = getattr(super(HandleVars, obj), func.__name__) return f(name, *args) return newfunc @ifbasestring def __getitem__(self, name): for node in self.find_children(self.childClass, 1): if node.name == name: return node @ifbasestring def __setitem__(self, name, valueObj): if not isinstance(valueObj, LyNode): valueObj = self.importNode(valueObj) assignment = self[name] if assignment: assignment.setValue(valueObj) else: self.childClass(name, self, valueObj) @ifbasestring def __contains__(self, name): return bool(self[name]) @ifbasestring def __delitem__(self, name): h = self[name] if h: self.remove(h) def importNode(self, obj): """ Try to interpret the object and transform it into a Node object of the right species. """ return QuotedString(obj) class AddDuration(object): """ Mixin to add a duration (as child). """ def ly(self, printer): s = super(AddDuration, self).ly(printer) dur = self.find_child(Duration, 1) if dur: s += dur.ly(printer) return s class Block(Container): """ A vertical container type that puts everything on a new line. """ defaultSpace = "\n" before, after = 1, 1 class Document(Container): """ A container type that puts everything on a new line. To be used as a full LilyPond document. """ defaultSpace = "\n" after = 1 ## # These classes correspond to real LilyPond data. # class Text(Leaf): """ A leaf node with arbitrary text """ def __init__(self, text="", parent=None): super(Text, self).__init__(parent) self.text = text def ly(self, printer): return self.text class TextDur(AddDuration, Text): """ A text note with an optional duration as child. """ pass class Line(Text): """ A text node that claims its own line. """ before, after = 1, 1 class Comment(Text): """ A LilyPond comment at the end of a line """ after = 1 def ly(self, printer): return re.compile('^', re.M).sub('% ', self.text) class LineComment(Comment): """ A LilyPond comment that takes a full line """ before = 1 class BlockComment(Comment): """ A block comment between %{ and %} """ @property def before(self): return '\n' in self.text and 1 or 0 @property def after(self): return '\n' in self.text and 1 or 0 def ly(self, printer): text = self.text.replace('%}', '') f = "%{{\n{0}\n%}}" if '\n' in text else "%{{ {0} %}}" return f.format(text) class QuotedString(Text): """ A string that is output inside double quotes. """ isAtom = True def ly(self, printer): # we call format(), since self.text MIGHT be a Reference... return printer.quoteString(format(self.text)) class Newline(LyNode): """ A newline. """ after = 1 class BlankLine(Newline): """ A blank line. """ before = 1 class Scheme(Text): """ A Scheme expression, without the extra # prepended """ isAtom = True def ly(self, printer): return '#' + self.text class Version(Line): """ a LilyPond version instruction """ def ly(self, printer): return r'\version "{0}"'.format(self.text) class Include(Line): r""" a LilyPond \include statement """ def ly(self, printer): return r'\include "{0}"'.format(self.text) class Assignment(Container): """ A varname = value construct with it's value as its first child The name can be a string or a Reference object: so that everywhere where this varname is referenced, the name is the same. """ before, after = 1, 1 def __init__(self, name=None, parent=None, valueObj=None): super(Assignment, self).__init__(parent) self.name = name if valueObj: self.append(valueObj) # Convenience methods: def setValue(self, obj): if len(self): self[0] = obj else: self.append(obj) def value(self): if len(self): return self[0] def ly(self, printer): return "{0} = {1}".format(self.name, super(Assignment, self).ly(printer)) HandleVars.childClass = Assignment class Identifier(Leaf): """ An identifier, prints as \\name. Name may be a string or a Reference object. """ isAtom = True def __init__(self, name=None, parent=None): super(Identifier, self).__init__(parent) self.name = name def ly(self, printer): return "\\{0}".format(self.name) class Statement(Named, Container): """ Base class for statements with arguments. The statement is read in the name attribute, the arguments are the children. """ before = 0 # do not read property from container isAtom = True class Command(Statement): """ Use this to create a LilyPond command supplying the name (or a Reference) when instantiating. """ def __init__(self, name, parent=None): super(Command, self).__init__(parent) self.name = name class Enclosed(Container): """ Encloses all children between brackets: { ... } If may_remove_brackets is True in subclasses, the brackets are removed if there is only one child and that child is an atom (i.e. a single LilyPond expression. """ may_remove_brackets = False pre, post = "{", "}" before, after = 0, 0 isAtom = True def ly(self, printer): if len(self) == 0: return " ".join((self.pre, self.post)) sup = super(Enclosed, self) text = sup.ly(printer) if self.may_remove_brackets and len(self) == 1 and self[0].isAtom: return text elif sup.before or sup.after or '\n' in text: return "".join((self.pre, "\n" * max(sup.before, 1), text, "\n" * max(sup.after, 1), self.post)) else: return " ".join((self.pre, text, self.post)) class Seq(Enclosed): """ An SequentialMusic expression between { } """ pre, post = "{", "}" class Sim(Enclosed): """ An SimultaneousMusic expression between << >> """ pre, post = "<<", ">>" class Seqr(Seq): may_remove_brackets = True class Simr(Sim): may_remove_brackets = True class SchemeLily(Enclosed): """ A LilyPond expression between #{ #} (inside scheme) """ pre, post = "#{", "#}" class SchemeList(Enclosed): """ A list of items enclosed in parentheses """ pre, post = "(", ")" def ly(self, printer): return self.pre + Container.ly(self, printer) + self.post class StatementEnclosed(Named, Enclosed): """ Base class for LilyPond commands that have a single bracket-enclosed list of arguments. """ may_remove_brackets = True class CommandEnclosed(StatementEnclosed): """ Use this to print LilyPond commands that have a single bracket-enclosed list of arguments. The command name is supplied to the constructor. """ def __init__(self, name, parent=None): super(CommandEnclosed, self).__init__(parent) self.name = name class Section(StatementEnclosed): """ Very much like a Statement. Use as base class for \\book { }, \\score { } etc. By default never removes the brackets and always starts on a new line. """ may_remove_brackets = False before, after = 1, 1 class Book(Section): name = 'book' class BookPart(Section): name = 'bookpart' class Score(Section): name = 'score' class Paper(HandleVars, Section): name = 'paper' class Layout(HandleVars, Section): name = 'layout' class Midi(HandleVars, Section): name = 'midi' class Header(HandleVars, Section): name = 'header' class With(HandleVars, Section): """ If this item has no children, it prints nothing. """ name = 'with' before, after = 0, 0 def ly(self, printer): if len(self): return super(With, self).ly(printer) else: return '' class ContextName(Text): """ Used to print a context name, like \\Score. """ def ly(self, printer): return "\\" + self.text class Context(HandleVars, Section): r""" A \context section for use inside Layout or Midi sections. """ name = 'context' def __init__(self, contextName="", parent=None): super(Context, self).__init__(parent) if contextName: ContextName(contextName, self) class ContextType(Container): r""" \new or \context Staff = 'bla' \with { } << music >> A \with (With) element is added automatically as the first child as soon as you use our convenience methods that manipulate the variables in \with. If the \with element is empty, it does not print anything. You should add one other music object to this. """ before, after = 1, 1 isAtom = True ctype = None def __init__(self, cid=None, new=True, parent=None): super(ContextType, self).__init__(parent) self.new = new self.cid = cid def ly(self, printer): res = [] res.append(self.new and "\\new" or "\\context") res.append(self.ctype or self.__class__.__name__) if self.cid: res.append("=") res.append(printer.quoteString(format(self.cid))) res.append(super(ContextType, self).ly(printer)) return " ".join(res) def getWith(self): """ Gets the attached with clause. Creates it if not there. """ for node in self: if isinstance(node, With): return node self.insert(0, With()) return self[0] def addInstrumentNameEngraverIfNecessary(self): """ Adds the Instrument_name_engraver to the node if it would need it to print instrument names. """ if not isinstance(self, (Staff, RhythmicStaff, PianoStaff, Lyrics, FretBoards)): Line('\\consists "Instrument_name_engraver"', self.getWith()) class ChoirStaff(ContextType): pass class ChordNames(ContextType): pass class CueVoice(ContextType): pass class Devnull(ContextType): pass class DrumStaff(ContextType): pass class DrumVoice(ContextType): pass class Dynamics(ContextType): pass class FiguredBass(ContextType): pass class FretBoards(ContextType): pass class Global(ContextType): pass class GrandStaff(ContextType): pass class GregorianTranscriptionStaff(ContextType): pass class GregorianTranscriptionVoice(ContextType): pass class InnerChoirStaff(ContextType): pass class InnerStaffGroup(ContextType): pass class Lyrics(ContextType): pass class MensuralStaff(ContextType): pass class MensuralVoice(ContextType): pass class NoteNames(ContextType): pass class PianoStaff(ContextType): pass class RhythmicStaff(ContextType): pass class ScoreContext(ContextType): r""" Represents the Score context in LilyPond, but the name would collide with the Score class that represents \score { } constructs. Because the latter is used more often, use ScoreContext to get \new Score etc. """ ctype = 'Score' class Staff(ContextType): pass class StaffGroup(ContextType): pass class TabStaff(ContextType): pass class TabVoice(ContextType): pass class VaticanaStaff(ContextType): pass class VaticanaVoice(ContextType): pass class Voice(ContextType): pass class UserContext(ContextType): r""" Represents a context the user creates. e.g. \new MyStaff = cid << music >> """ def __init__(self, ctype, cid=None, new=True, parent=None): super(UserContext, self).__init__(cid, new, parent) self.ctype = ctype class ContextProperty(Leaf): """ A Context.property or Context.layoutObject construct. Call e.g. ContextProperty('aDueText', 'Staff') to get 'Staff.aDueText'. """ def __init__(self, prop, context=None, parent=None): self.prop = prop self.context = context def ly(self, printer): if self.context: # In \lyrics or \lyricmode: put spaces around dot. p = self.find_parent(InputMode) if p and isinstance(p, LyricMode): f = '{0} . {1}' else: f = '{0}.{1}' return f.format(self.context, self.prop) else: return self.prop class InputMode(StatementEnclosed): """ The abstract base class for input modes such as lyricmode/lyrics, chordmode/chords etc. """ pass class ChordMode(InputMode): name = 'chordmode' class InputChords(ChordMode): name = 'chords' class LyricMode(InputMode): name = 'lyricmode' class InputLyrics(LyricMode): name = 'lyrics' class NoteMode(InputMode): name = 'notemode' class InputNotes(NoteMode): name = 'notes' class FigureMode(InputMode): name = 'figuremode' class InputFigures(FigureMode): name = 'figures' class DrumMode(InputMode): name = 'drummode' class InputDrums(DrumMode): name = 'drums' class AddLyrics(InputLyrics): name = 'addlyrics' may_remove_brackets = False before, after = 1, 1 class LyricsTo(LyricMode): name = 'lyricsto' def __init__(self, cid, parent=None): super(LyricsTo, self).__init__(parent) self.cid = cid def ly(self, printer): res = ["\\" + self.name] res.append(printer.quoteString(format(self.cid))) res.append(Enclosed.ly(self, printer)) return " ".join(res) class Pitch(Leaf): """ A pitch with octave, note, alter. octave is specified by an integer, zero for the octave containing middle C. note is a number from 0 to 6, with 0 corresponding to pitch C and 6 corresponding to pitch B. alter is the number of whole tones for alteration (can be int or Fraction) """ def __init__(self, octave=0, note=0, alter=0, parent=None): super(Pitch, self).__init__(parent) self.octave = octave self.note = note self.alter = fractions.Fraction(alter) def ly(self, printer): """ Print the pitch in the preferred language. """ p = ly.pitch.pitchWriter(printer.language)(self.note, self.alter) if self.octave < -1: return p + ',' * (-self.octave - 1) elif self.octave > -1: return p + "'" * (self.octave + 1) return p class Duration(Leaf): r""" A duration with duration (in logarithmic form): (-2 ... 8), where -2 = \longa, -1 = \breve, 0 = 1, 1 = 2, 2 = 4, 3 = 8, 4 = 16, etc, dots (number of dots), factor (Fraction giving the scaling of the duration). """ def __init__(self, dur, dots=0, factor=1, parent=None): super(Duration, self).__init__(parent) self.dur = dur # log self.dots = dots self.factor = fractions.Fraction(factor) def ly(self, printer): return ly.duration.tostring(self.dur, self.dots, self.factor) class Chord(Container): """ A chord containing one of more Pitches and optionally one Duration. This is a bit of a hack, awaiting real music object support. """ def ly(self, printer): pitches = list(self.find_children(Pitch, 1)) if len(pitches) == 1: s = pitches[0].ly(printer) else: s = "<{0}>".format(' '.join(p.ly(printer) for p in pitches)) duration = self.find_child(Duration, 1) if duration: s += duration.ly(printer) return s class Relative(Statement): r""" \relative music You should add a Pitch (optionally) and another music object, e.g. Sim or Seq, etc. """ name = 'relative' class Transposition(Statement): r""" \transposition You should add a Pitch. """ name = 'transposition' class KeySignature(Leaf): r""" A key signature expression, like: \key c \major The pitch should be given in the arguments note and alter and is written out in the document's language. """ def __init__(self, note=0, alter=0, mode="major", parent=None): super(KeySignature, self).__init__(parent) self.note = note self.alter = fractions.Fraction(alter) self.mode = mode def ly(self, printer): pitch = ly.pitch.pitchWriter(printer.language)(self.note, self.alter) return "\\key {0} \\{1}".format(pitch, self.mode) class TimeSignature(Leaf): r""" A time signature, like: \time 4/4 """ def __init__(self, num, beat, parent=None): super(TimeSignature, self).__init__(parent) self.num = num self.beat = beat def ly(self, printer): return "\\time {0}/{1}".format(self.num, self.beat) class Partial(Named, Duration): r""" \partial You should add a Duration element """ name = "partial" before, after = 1, 1 class Tempo(Container): r""" A tempo setting, like: \tempo 4 = 100 May have a child markup or quoted string. """ before, after = 1, 1 def __init__(self, duration, value, parent=None): super(Tempo, self).__init__(parent) self.duration = duration self.value = value def ly(self, printer): result = ['\\tempo'] if len(self) > 0: result.append(super(Tempo, self).ly(printer)) if self.value: result.append("{0}={1}".format(self.duration, self.value)) return ' '.join(result) class Clef(Leaf): """ A clef. """ def __init__(self, clef, parent=None): super(Clef, self).__init__(parent) self.clef = clef def ly(self, printer): clef = self.clef if self.clef.isalpha() else '"{0}"'.format(self.clef) return "\\clef " + clef class VoiceSeparator(Leaf): r""" A Voice Separator: \\ """ def ly(self, printer): return r'\\' class Mark(Statement): r""" The \mark command. """ name = 'mark' class Markup(StatementEnclosed): r""" The \markup command. You can add many children, in that case Markup automatically prints { and } around them. """ name = 'markup' class MarkupEnclosed(CommandEnclosed): """ A markup that auto-encloses all its arguments, like 'italic', 'bold' etc. You must supply the name. """ pass class MarkupCommand(Command): """ A markup command with more or no arguments, that does not auto-enclose its arguments. Useful for commands like note-by-number or hspace. You must supply the name. Its arguments are its children. If one argument can be a markup list, use a Enclosed() construct for that. """ pass python_ly-0.9.9/ly/duration.py0000644000000000000000000000567613615410400013337 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2008 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ LilyPond information and logic concerning durations """ from __future__ import unicode_literals from fractions import Fraction durations = [ '\\maxima', '\\longa', '\\breve', '1', '2', '4', '8', '16', '32', '64', '128', '256', '512', '1024', '2048' ] def tostring(dur, dots=0, factor=1): r"""Returns the LilyPond string representation of a given logarithmic duration. Supports values from -3 up to and including 11. -2 = '\longa', 0 = '1' (whole note), etc. Adds the number of dots (defaults to 0) and the fraction factor if given. """ s = durations[dur + 3] + '.' * dots if factor != 1: s += '*{0}'.format(factor) return s def base_scaling(tokens): """Return (base, scaling) as two Fractions for the list of tokens.""" base = Fraction(8, 1 << durations.index(tokens[0])) scaling = Fraction(1) half = base for t in tokens[1:]: if t == '.': half /= 2 base += half elif t.startswith('*'): scaling *= Fraction(t[1:]) return base, scaling def base_scaling_string(duration): """Return (base, scaling) as two Fractions for the specified string.""" items = duration.split('*') dots = items[0].split('.') base = Fraction(8, 1 << durations.index(dots[0].strip())) scaling = Fraction(1) half = base for dot in dots[1:]: half /= 2 base += half for f in items[1:]: scaling *= Fraction(f.strip()) return base, scaling def fraction(tokens): """Return the duration of the Duration tokens as a Fraction.""" base, scaling = base_scaling(tokens) return base * scaling def fraction_string(duration): """Return the duration of the specified string as a Fraction.""" base, scaling = base_scaling_string(duration) return base * scaling def format_fraction(value): """Format the value as "5/1" etc.""" if value == 0: return "0" elif isinstance(value, Fraction): return "{0}/{1}".format(value.numerator, value.denominator) else: return "{0}/1".format(value) python_ly-0.9.9/ly/etreeutil.py0000644000000000000000000000327113615410400013501 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2013 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ Utility functions for use with xml.etree.ElementTree. """ from __future__ import unicode_literals def isblank(s): """Return True if s is empty or whitespace only.""" return not s or s.isspace() def indent(elem, indent_string=" ", level=0): """Indent the XML in element. Text content that is already non-whitespace is not changed. """ # based on http://effbot.org/zone/element-lib.htm#prettyprint i = "\n" + indent_string * level if len(elem): if isblank(elem.text): elem.text = i + indent_string if isblank(elem.tail): elem.tail = i for elem in elem: indent(elem, indent_string, level+1) if isblank(elem.tail): elem.tail = i else: if level and isblank(elem.tail): elem.tail = i python_ly-0.9.9/ly/indent.py0000644000000000000000000003242113615410400012757 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2008 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ Indent and auto-indent. """ from __future__ import unicode_literals import ly.lex.lilypond import ly.lex.scheme class Indenter(object): # variables indent_tabs = False # use tabs for indent indent_width = 2 # amount of spaces if indent_tabs == False def __init__(self): pass def indent(self, cursor, indent_blank_lines=False): """Indent all lines in the cursor's range. If indent_blank_lines is True, the indent of blank lines is made larger if necessary. If False (the default), the indent of blank lines if not changed if it is shorter than it should be. """ indents = [''] start_block, end_block = cursor.start_block(), cursor.end_block() in_range = False pline = None prev_indent = '' with cursor.document as d: for b in cursor.document: if b == start_block: in_range = True line = Line(d, b) # handle indents of prev line if pline: if pline.indent is not False: prev_indent = pline.indent if pline.indenters: current_indent = indents[-1] for align, indent in pline.indenters: new_indent = current_indent if align: new_indent += ' ' * (align - len(prev_indent)) if indent: new_indent += '\t' if self.indent_tabs else ' ' * self.indent_width indents.append(new_indent) del indents[max(1, len(indents) - line.dedenters_start):] # if we may not change the indent just remember the current if line.indent is not False: if not in_range: indents[-1] = line.indent elif not indent_blank_lines and line.isblank and indents[-1].startswith(line.indent): pass # don't make shorter indents longer on blank lines elif line.indent != indents[-1]: d[d.position(b):d.position(b)+len(line.indent)] = indents[-1] del indents[max(1, len(indents) - line.dedenters_end):] if b == end_block: break pline = line def increase_indent(self, cursor): """Manually add indent to all lines of cursor.""" indent = '\t' if self.indent_tabs else ' ' * self.indent_width with cursor.document as d: for block in cursor.blocks(): ins = d.position(block) tokens = d.tokens(block) if tokens and isinstance(tokens[0], ly.lex.Space): tab_pos = tokens[0].rfind('\t') if tab_pos != -1: ins += tokens[0].pos + tab_pos + 1 else: ins += tokens[0].end d[ins:ins] = indent def decrease_indent(self, cursor): """Manually remove one level of indent from all lines of cursor.""" with cursor.document as d: for block in cursor.blocks(): tokens = d.tokens(block) if tokens: token = tokens[0] if isinstance(token, ly.lex.Space): space = token else: space = token[0:-len(token.lstrip())] pos = d.position(block) end = pos + len(space) if '\t' in space and space.endswith(' '): # strip alignment del d[pos + space.rfind('\t') + 1 : end] elif space.endswith('\t'): # just strip one tab del d[end - 1] elif space.endswith(' ' * self.indent_width): del d[end - self.indent_width: end] else: del d[pos:end] def get_indent(self, document, block): """Return the indent the block currently has. Returns False if the block is not indentable, e.g. when it is part of a multiline string. """ return Line(document, block).indent def compute_indent(self, document, block): """Return the indent the specified block should have. Returns False if the block is not indentable, e.g. when it is part of a multiline string. This method is used to determine the indent of one line, and just looks to previous lines, copying the indent of the line where the current indent depth starts, and/or adding a level of indent or alignment space. Use this method only for one line or the first of a group you're indenting. """ line = Line(document, block) if line.indent is False: return False depth = line.dedenters_start blocks = document.blocks_backward(document.previous_block(block)) align, indent = None, False for b in blocks: line = Line(document, b) indents = len(line.indenters) if 0 <= depth < indents: # we found the indent token index = indents - depth - 1 align, indent = line.indenters[index] break depth -= indents depth += line.dedenters_end if depth == 0: # same indent as this line break depth += line.dedenters_start else: return "" # here we arrive after 'break' i = line.indent if i is False: for b in blocks: i = Line(document, b).indent if i is not False: break else: i = "" if align: i += ' ' * (align - len(i)) if indent: i += '\t' if self.indent_tabs else ' ' * self.indent_width return i class Line(object): """Brings together all relevant information about a line (block).""" def __init__(self, document, block): """Initialize with a block (line) of the document. After init, the following attributes are set: indent The indent the current line has. This is a string containing whitespace (i.e. spaces and/or tabs) which can be empty. A special case is False, which means the current line is not indentable, e.g. it is a multiline string and should never be automatically be re-indented. isblank True if the line is empty or white-space only. It is False when the indent attribute is also False (e.g. when the line is part of a multiline string). dedenters_start The number of dedent tokens that should cause the indenter to go a level up. dedenters_end The number of dedent tokens that should cause the next line to go a level up. indenters A list of tuples (align, indent). Each item corresponds with an indent that starts on the line. The align value (integer) determines the position the next line should be padded to with spaces, 0 or None means no alignment. The indent value (bool) specifies if there should a new indent level be added (a tab or some amount of spaces). """ state = document.state(block) tokens = document.tokens(block) # are we in a multi-line string? if isinstance(state.parser(), ( ly.lex.lilypond.ParseString, ly.lex.scheme.ParseString, )): self.indent = False self.isblank = False # or a multi-line comment? elif isinstance(state.parser(), ( ly.lex.lilypond.ParseBlockComment, ly.lex.scheme.ParseBlockComment, )): # do allow indent the last line of a block comment if it only # contains space if tokens and isinstance(tokens[0], ly.lex.BlockCommentEnd): self.indent = "" elif (len(tokens) > 1 and isinstance(tokens[0], ly.lex.BlockComment) and isinstance(tokens[1], ly.lex.BlockCommentEnd) and tokens[0].isspace()): self.indent = tokens[0] else: self.indent = False self.isblank = False elif tokens and isinstance(tokens[0], ly.lex.Space): self.indent = tokens[0] self.isblank = len(tokens) == 1 else: self.indent = "" self.isblank = not tokens find_dedenters = True self.dedenters_start = 0 self.dedenters_end = 0 # quickly iter over the tokens, collecting the indent tokens and # possible stuff to align to after the indent tokens indenters = [] for t in tokens: if isinstance(t, ly.lex.Indent): find_dedenters = False if indenters: indenters[-1].append(t) indenters.append([t]) elif isinstance(t, ly.lex.Dedent): if find_dedenters and not isinstance(t, ly.lex.scheme.CloseParen): self.dedenters_start += 1 else: find_dedenters = False if indenters: indenters.pop() else: self.dedenters_end += 1 elif not isinstance(t, ly.lex.Space): find_dedenters = False if indenters: indenters[-1].append(t) # now analyse the indent tokens that are not closed on the same line # and determine how the next line should be indented self.indenters = [] for indent in indenters: token, rest = indent[0], indent[1:] if isinstance(token, ly.lex.scheme.OpenParen): if len(rest) > 1 and not self.is_special_scheme_keyword(rest[0]): align, indent = rest[1].pos, False elif len(rest) == 1 and not isinstance(rest[0], ly.lex.Comment): align, indent = rest[0].pos, False else: align, indent = token.pos, True elif rest and not isinstance(rest[0], ly.lex.Comment): align, indent = rest[0].pos, False else: align, indent = None, True self.indenters.append((align, indent)) def is_special_scheme_keyword(self, token): """Return True if token is a special Scheme word like "define", etc. The tokens in the list below and those that start with "def", like "define", do not follow the standard Scheme indentation patterns. The list below and the "def" rule are from GNU Emacs source code, which sets the standard for GNU Guile Scheme indentation. See: emacs/lisp/progmodes/scheme.el See also: http://community.schemewiki.org/?scheme-style """ return (isinstance(token, ly.lex.scheme.Word) and (token[0:3] == "def" or token in ( 'begin', 'case', 'delay', 'do', 'lambda', 'let', 'let*', 'letrec', 'let-values', 'let*-values', 'sequence', 'let-syntax', 'letrec-syntax', 'syntax-rules', 'syntax-case', 'library', 'call-with-input-file', 'with-input-from-file', 'with-input-from-port', 'call-with-output-file', 'with-output-to-file', 'with-output-to-port', 'call-with-values', 'dynamic-wind', 'when', 'unless', 'letrec*', 'parameterize', 'define-values', 'define-record-type', 'define-library', 'receive', ))) python_ly-0.9.9/ly/node.py0000644000000000000000000002520413615410400012424 0ustar00# node.py -- Node is a list-like type to build tree structures with # # Copyright (c) 2008 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ The Node class. (c) 2008-2011 Wilbert Berendsen License: GPL. This module contains the Node class that can be used as a simple DOM (Document Object Model) for building a tree structure. A Node has children with list-like access methods and keeps also a reference to its parent. A Node can have one parent; appending a Node to another Node causes it to be removed from its parent node (if any). To iterate over the children of a Node:: for n in node: do_something(n) To get the list of children of a Node:: children = list(node) Of course you can get the children directly using:: child = node[3] You should inherit from Node to make meaningful tree node types, e.g. to add custom attributes or multiple sub-types. A WeakNode class is provided as well, which uses a weak reference to the parent, so that no cyclic references are created which might improve garbage collection. """ import weakref class Node(object): """A list-like class to build tree structures with.""" __slots__ = ('__weakref__', '_parent', '_children') def __init__(self, parent=None): self._parent = None self._children = [] if parent: parent.append(self) def _own(self, node): """(Internal) Remove node from its parent if any and make us parent.""" parent = node.parent() if parent: parent.remove(node) node._set_parent(self) def _set_parent(self, node): """(Internal) Set the Node (or None) as our parent.""" self._parent = node def parent(self): """The parent, or None if the node has no parent.""" return self._parent def index(self, node): """Return the index of the given child node.""" return self._children.index(node) def append(self, node): """Append a node to the current node. It will be reparented, that means it will be removed from it's former parent if it had one. """ self._own(node) self._children.append(node) def extend(self, iterable): """Append every Node from iterable.""" for node in iterable: self.append(node) def insert(self, index, node): """Insert a node at the specified index.""" self._own(node) self._children.insert(index, node) def insert_before(self, other, node): """Insert a node before the other node.""" i = self.index(other) self._own(node) self._children.insert(i, node) def remove(self, node): """Remove the given child node.""" self._children.remove(node) node._set_parent(None) def __bool__(self): """We are always true.""" return True __nonzero__ = __bool__ # py2 compat def __len__(self): """Return the number of children.""" return len(self._children) def __getitem__(self, k): """Return child at index or children at slice.""" return self._children[k] def __setitem__(self, k, obj): """Set child at index or children at slice.""" old = self._children[k] if isinstance(k, slice): if k.step: # extended slice, number of items must be same self._children[k] = obj # if this succeeded it's OK new = self._children[k] else: new = tuple(obj) self._children[k] = new for node in old: node._set_parent(None) for node in new: self._own(node) else: old._set_parent(None) self._children[k] = obj self._own(obj) def __delitem__(self, k): """Delete child at index or children at slice.""" if isinstance(k, slice): for node in self._children[k]: node._set_parent(None) else: self._children[k]._set_parent(None) del self._children[k] def __contains__(self, node): """Return True if the node is our child.""" return node in self._children def clear(self): """Remove all children.""" del self[:] def unlink(self): """Remove all children and unlink() them as well.""" for node in self: node.unlink() del self._children[:] def replace(self, old, new): """Replace a child node with another node.""" i = self.index(old) self[i] = new def sort(self, key=None, reverse=False): """Sorts the children, optionally using the key function. Using a key function is recommended, or you must add comparison methods to your Node subclass. """ self._children.sort(key, reverse=reverse) def copy(self): """Return a deep copy of the node and its children """ obj = self.__class__.__new__(self.__class__) obj._parent = None obj._children = [] self._copy_attrs(obj) for n in self: obj.append(n.copy()) return obj def _copy_attrs(self, node): """Called by copy(); copy attributes not starting with '_'.""" for name, value in vars(self).items(): name.startswith("_") or setattr(node, name, value) def ancestors(self): """Climb the tree up over the parents.""" node = self.parent() while node: yield node node = node.parent() def previous_sibling(self): """Return the sibling object just before us in our parents list. Returns None if this is the first child, or if we have no parent. """ for i in self.backward(): return i def next_sibling(self): """Return the sibling object just after us in our parents list. Returns None if this is the last child, or if we have no parent. """ for i in self.forward(): return i def backward(self): """Iterate (backwards) over the preceding siblings.""" parent = self.parent() if parent: i = parent.index(self) return iter(parent[i-1::-1]) def forward(self): """Iterate over the following siblings.""" parent = self.parent() if parent: i = parent.index(self) return iter(parent[i+1::]) def is_descendant_of(self, parent): """Return True if self is a descendant of parent, else False.""" for n in self.ancestors(): if n is parent: return True return False def toplevel(self): """Return the toplevel parent Node of this node.""" node = self parent = self.parent() while parent: node = parent parent = node.parent() return node def descendants(self, depth = -1): """Yield all the descendants, in tree order. Same as iter_depth().""" return self.iter_depth(depth) def iter_depth(self, depth = -1): """Iterate over all the children, and their children, etc. Set depth to restrict the search to a certain depth, -1 is unrestricted. """ if depth != 0: for i in self: yield i for j in i.iter_depth(depth - 1): yield j def iter_rings(self, depth = -1): """Iterate over the children in rings, depth last. This method returns the closest descendants first. Set depth to restrict the search to a certain depth, -1 is unrestricted. """ children = list(self) while children and depth: depth -= 1 newchildren = [] for i in children: yield i newchildren.extend(i) children = newchildren def find(self, cls, depth = -1): """Yield all descendants if they are an instance of cls. cls may also be a tuple of classes. This method uses iter_depth(). """ for node in self.iter_depth(depth): if isinstance(node, cls): yield node def find_children(self, cls, depth = -1): """Yield all descendants if they are an instance of cls. cls may also be a tuple of classes. This method uses iter_rings(). """ for node in self.iter_rings(depth): if isinstance(node, cls): yield node def find_child(self, cls, depth = -1): """Return the first descendant that's an instance of cls. cls may also be a tuple of classes. This method uses iter_rings(). """ for node in self.iter_rings(depth): if isinstance(node, cls): return node def find_parent(self, cls): """Find an ancestor that's an instance of the given class. cls may also be a tuple of classes. """ for node in self.ancestors(): if isinstance(node, cls): return node def dump(self): """Return a string representation of the tree.""" def line(obj, indent): yield indent * " " + repr(obj) for c in obj: for l in line(c, indent + 1): yield l return '\n'.join(line(self, 0)) class WeakNode(Node): """A Node type using a weak reference to the parent.""" __slots__ = () def _set_parent(self, node): self._parent = None if node is None else weakref.ref(node) def parent(self): """The parent, or None if the node has no parent.""" if self._parent is not None: return self._parent() python_ly-0.9.9/ly/pkginfo.py0000644000000000000000000000010013615410400013120 0ustar00"""Meta-information about the LY package.""" version = "0.9.9" python_ly-0.9.9/ly/reformat.py0000644000000000000000000000757213615410400013326 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2008 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ Formatting tools to improve the readability of a ly.document.Document without changing the semantic meaning of the LilyPond source. Basically the tools only change whitespace to make the source-code more readable. See also ly.indent. """ from __future__ import unicode_literals import ly.indent import ly.lex def break_indenters(cursor): """Add newlines around indent and dedent tokens where needed. If there is stuff after a { or << (that's not closed on the same line) it is put on a new line, and if there if stuff before a } or >>, the } or >> is put on a new line. It is necessary to run the indenter again over the same part of the document, as it will look garbled with the added newlines. """ with cursor.document as d: for b in cursor.blocks(): denters = [] tokens = d.tokens(b) nonspace_index = -1 for i, t in enumerate(tokens): if isinstance(t, ly.lex.Indent) and t in ('{', '<<'): denters.append(i) elif isinstance(t, ly.lex.Dedent) and t in ('}', '>>'): if denters: denters.pop() elif nonspace_index != -1: # add newline before t pos = d.position(b) + t.pos d[pos:pos] = '\n' if not isinstance(t, ly.lex.Space): nonspace_index = i for i in denters: if i < nonspace_index: # add newline after tokens[i] pos = d.position(b) + tokens[i].end d[pos:pos] = '\n' def move_long_comments(cursor): """Move line comments with more than 2 comment characters to column 0.""" with cursor.document as d: for b in cursor.blocks(): tokens = d.tokens(b) if (len(tokens) == 2 and isinstance(tokens[0], ly.lex.Space) and isinstance(tokens[1], ( ly.lex.lilypond.LineComment, ly.lex.scheme.LineComment)) and tokens[1][:3] in ('%%%', ';;;')): del d[d.position(b):d.position(b) + tokens[1].pos] def remove_trailing_whitespace(cursor): """Removes whitespace from all lines in the cursor's range.""" with cursor.document as d: for b in cursor.blocks(): tokens = d.tokens(b) if tokens: t = tokens[-1] end = d.position(b) + t.end if isinstance(t, ly.lex.Space): del d[end-len(t):end] elif not isinstance(t, ly.lex.String): offset = len(t) - len(t.rstrip()) if offset: del d[end-offset:end] def reformat(cursor, indenter): """A do-it-all function improving the LilyPond source formatting.""" break_indenters(cursor) indenter.indent(cursor) move_long_comments(cursor) remove_trailing_whitespace(cursor) python_ly-0.9.9/ly/rests.py0000644000000000000000000000642313615410400012641 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2011 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ Implementation of tools to edit rests of selected music. All functions except a ly.document.Cursor with the selected range. """ from __future__ import unicode_literals import ly.document import ly.lex.lilypond def replace_rest(cursor, replace_token): """Replace full rests (r) with optional token. """ source = ly.document.Source(cursor, True, tokens_with_position=True) with cursor.document as d: for token in source: if isinstance(token, ly.lex.lilypond.Rest): if token == 'r': d[token.pos:token.end] = replace_token def replace_fmrest(cursor, replace_token): """Replace full measure rests (R) with optional token. """ source = ly.document.Source(cursor, True, tokens_with_position=True) with cursor.document as d: for token in source: if isinstance(token, ly.lex.lilypond.Rest): if token == 'R': d[token.pos:token.end] = replace_token def replace_spacer(cursor, replace_token): """Replace spacer rests (s) with optional token. """ source = ly.document.Source(cursor, True, tokens_with_position=True) with cursor.document as d: for token in source: if isinstance(token, ly.lex.lilypond.Spacer): d[token.pos:token.end] = replace_token def replace_restcomm(cursor, replace_token): r"""Replace rests by rest command (\rest) with optional token. """ def get_comm_rests(source): r"""Catch all rests by rest command (\rest) from source.""" rest_tokens = None for token in source: if isinstance(token, ly.lex.lilypond.Note): rest_tokens = [token] continue if rest_tokens and isinstance(token, ly.lex.Space): rest_tokens.append(token) continue if rest_tokens and isinstance(token, ly.lex.lilypond.Command): if token == '\\rest': rest_tokens.append(token) yield rest_tokens rest_tokens = None source = ly.document.Source(cursor, True, tokens_with_position=True) with cursor.document as d: for rt in get_comm_rests(source): note = rt[0] space = rt[-2] comm = rt[-1] d[note.pos:note.end] = replace_token del d[space.pos:space.end] del d[comm.pos:comm.end] python_ly-0.9.9/ly/rhythm.py0000644000000000000000000003353213615410400013015 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2011 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ Implementation of the tools to edit durations of selected music. Durations are represented simply by lists of ly.lex.lilypond.Duration tokens. All functions expect a ly.document.Cursor with the selected range. """ from __future__ import unicode_literals import collections import itertools import ly.document import ly.lex.lilypond durations = ['\\maxima', '\\longa', '\\breve', '1', '2', '4', '8', '16', '32', '64', '128', '256', '512', '1024', '2048'] def remove_dups(iterable): """Change reoccurring strings to '' in iterable.""" old = None for i in iterable: yield '' if i == old else i old = i # describes a musical item that has a duration music_item = collections.namedtuple('music_item', ( 'tokens', # tokens of the item 'dur_tokens', # Duration tokens of the item 'may_remove', # whether the duration may be removed 'insert_pos', # where a Duration could be inserted 'pos', # position of the first token 'end', # end position of the last token )) _start = ( ly.lex.lilypond.Rest, ly.lex.lilypond.Skip, ly.lex.lilypond.Note, ly.lex.lilypond.ChordEnd, ly.lex.lilypond.Q, ly.lex.lilypond.Octave, ly.lex.lilypond.Accidental, ly.lex.lilypond.OctaveCheck, ly.lex.lilypond.Duration, ly.lex.lilypond.Tempo, ly.lex.lilypond.Partial ) _stay = ( ly.lex.lilypond.Octave, ly.lex.lilypond.Accidental, ly.lex.lilypond.OctaveCheck, ly.lex.lilypond.Duration, ly.lex.lilypond.Tie, ) def music_tokens(source, command=False, chord=False): r"""DEPRECATED. Yield lists of tokens describing rests, skips or pitches. source is a ly.document.Source instance following the state. The following keyword arguments can be used: - command: whether to allow pitches in \\relative, \\transpose, etc. - chord: whether to allow pitches inside chords. This function is deprecated and will be removed. You should use music_items() instead. """ skip_parsers = () if not command: skip_parsers += (ly.lex.lilypond.ParsePitchCommand,) if not chord: skip_parsers += (ly.lex.lilypond.ParseChord,) for token in source: if isinstance(source.state.parser(), skip_parsers): continue # make sure to skip the duration tokens in a \tuplet command if token == '\\tuplet': for token in source: if isinstance(token, ly.lex.lilypond.Duration): for token in source: if not isinstance(token, ly.lex.lilypond.Duration): break break elif not isinstance(token, (ly.lex.Space, ly.lex.Numeric)): break while isinstance(token, _start): l = [token] for token in source: if isinstance(token, ly.lex.Space): continue if not isinstance(token, _stay): yield l break l.append(token) else: yield l break def music_items(cursor, command=False, chord=False, partial=ly.document.INSIDE): r"""Yield music_item instances describing rests, skips or pitches. cursor is a ly.document.Cursor instance. The following keyword arguments can be used: - command: whether to allow pitches in \\relative, \\transpose, etc. - chord: whether to allow pitches inside chords. - partial: ly.document.INSIDE (default), PARTIAL or OUTSIDE. See the documentation of ly.document.Source.__init__(). """ skip_parsers = () if not command: skip_parsers += (ly.lex.lilypond.ParsePitchCommand,) if not chord: skip_parsers += (ly.lex.lilypond.ParseChord,) source = ly.document.Source(cursor, True, partial=partial, tokens_with_position=True) def mk_item(l): """Convert a list of tokens to a music_item instance.""" tokens = [] dur_tokens = [] pos = l[0].pos end = l[-1].end for t in l: if isinstance(t, ly.lex.lilypond.Duration): dur_tokens.append(t) else: tokens.append(t) may_remove = not any(map(('\\skip', '\\tempo', '\\tuplet', '\\partial').__contains__, tokens)) if dur_tokens: insert_pos = dur_tokens[0].pos else: for t in reversed(tokens): if not isinstance(t, ly.lex.lilypond.Tie): break insert_pos = t.end return music_item(tokens, dur_tokens, may_remove, insert_pos, pos, end) for token in source: if isinstance(source.state.parser(), skip_parsers): continue # make sure to skip the duration tokens in a \tuplet command if token == '\\tuplet': l = [token] for token in source: if isinstance(token, ly.lex.lilypond.Duration): l.append(token) for token in source: if not isinstance(token, ly.lex.lilypond.Duration): break l.append(token) break elif isinstance(token, ly.lex.Numeric): l.append(token) elif not isinstance(token, ly.lex.Space): break yield mk_item(l) length_seen = False while isinstance(token, _start): l = [token] if isinstance(token, ly.lex.lilypond.Length): length_seen = True for token in source: if isinstance(token, ly.lex.lilypond.Length): if length_seen is True: yield mk_item(l) length_seen = False break else: length_seen = True elif isinstance(token, ly.lex.Space): continue elif isinstance(token, ly.lex.lilypond.ChordSeparator): # prevent seeing the g in e.g. chordmode { c/g } for token in source: if not isinstance(token, (ly.lex.Space, ly.lex.lilypond.Note)): break continue elif not isinstance(token, _stay): yield mk_item(l) length_seen = False break l.append(token) else: yield mk_item(l) break def preceding_duration(cursor): """Return a preceding duration before the cursor, or an empty list.""" tokens = ly.document.Runner.at(cursor).backward() for t in tokens: if isinstance(t, ly.lex.lilypond.Duration): l = [t] for t in tokens: if isinstance(t, ly.lex.lilypond.Duration): l.append(t) elif not isinstance(t, ly.lex.Space): break l.reverse() return l return [] def rhythm_double(cursor): """Doubles all duration values.""" with cursor.document as d: for item in music_items(cursor): for token in item.dur_tokens: if isinstance(token, ly.lex.lilypond.Length): try: i = durations.index(token) except ValueError: pass else: if i > 0: d[token.pos:token.end] = durations[i - 1] break def rhythm_halve(cursor): """Halves all duration values.""" with cursor.document as d: for item in music_items(cursor): for token in item.dur_tokens: if isinstance(token, ly.lex.lilypond.Length): try: i = durations.index(token) except ValueError: pass else: if i < len(durations) - 1: d[token.pos:token.end] = durations[i + 1] break def rhythm_dot(cursor): """Add a dot to all durations.""" with cursor.document as d: for item in music_items(cursor): for token in item.dur_tokens: if isinstance(token, ly.lex.lilypond.Length): d[token.end:token.end] = "." break def rhythm_undot(cursor): """Remove one dot from all durations.""" with cursor.document as d: for item in music_items(cursor): for token in item.dur_tokens: if isinstance(token, ly.lex.lilypond.Dot): del d[token.pos:token.end] break def rhythm_remove_scaling(cursor): """Remove the scaling (like ``*3``, ``*1/3``) from all durations.""" with cursor.document as d: for item in music_items(cursor): for token in item.dur_tokens: if isinstance(token, ly.lex.lilypond.Scaling): del d[token.pos:token.end] def rhythm_remove_fraction_scaling(cursor): """Remove the scaling containing fractions (like ``*1/3``) from all durations.""" with cursor.document as d: for item in music_items(cursor): for token in item.dur_tokens: if isinstance(token, ly.lex.lilypond.Scaling) and '/' in token: del d[token.pos:token.end] def rhythm_remove(cursor): """Remove all durations.""" with cursor.document as d: for item in music_items(cursor): if item.dur_tokens and item.may_remove: del d[item.dur_tokens[0].pos:item.dur_tokens[-1].end] def rhythm_implicit(cursor): """Remove reoccurring durations.""" items = music_items(cursor) for item in items: break else: return if set(item.tokens) & set(('\\tempo', '\\tuplet', '\\partial')): prev = None else: prev = item.dur_tokens or preceding_duration(cursor) with cursor.document as d: for item in items: if not set(item.tokens) & set(('\\tempo', '\\tuplet', '\\partial')): if item.dur_tokens: if item.dur_tokens == prev and item.may_remove: del d[item.dur_tokens[0].pos:item.dur_tokens[-1].end] prev = item.dur_tokens def rhythm_implicit_per_line(cursor): """Remove reoccurring durations, but always write one on a new line.""" items = music_items(cursor) for item in items: break else: return if set(item.tokens) & set(('\\tempo', '\\tuplet', '\\partial')): prev = None else: prev = item.dur_tokens or preceding_duration(cursor) if prev: previous_block = cursor.document.block(prev[0].pos) else: previous_block = None with cursor.document as d: for item in items: if not set(item.tokens) & set(('\\tempo', '\\tuplet', '\\partial')): block = d.block( (item.dur_tokens or item.tokens) [0].pos) if block != previous_block: if not item.dur_tokens: d[item.insert_pos:item.insert_pos] = ''.join(prev) else: prev = item.dur_tokens previous_block = block elif item.dur_tokens: if item.dur_tokens == prev and item.may_remove: del d[item.dur_tokens[0].pos:item.dur_tokens[-1].end] prev = item.dur_tokens def rhythm_explicit(cursor): """Make all durations explicit.""" items = music_items(cursor) for item in items: break else: return prev = item.dur_tokens or preceding_duration(cursor) with cursor.document as d: for item in items: if not set(item.tokens) & set(('\\tempo', '\\tuplet', '\\partial')): if item.dur_tokens: prev = item.dur_tokens else: d[item.insert_pos:item.insert_pos] = ''.join(prev) def rhythm_overwrite(cursor, durations): """Apply a list of durations to the cursor's range. The durations list looks like ["4", "8", "", "16.",] etc. """ durations_source = remove_dups(itertools.cycle(durations)) with cursor.document as d: for item in music_items(cursor): pos = item.insert_pos end = item.dur_tokens[-1].end if item.dur_tokens else pos d[pos:end] = next(durations_source) def rhythm_extract(cursor): """Return a list of the durations from the cursor's range.""" source = ly.document.Source(cursor, True) durations = [] for item in music_items(cursor): tokens = item.dur_tokens + [t for t in item.tokens if isinstance(t, ly.lex.lilypond.Tie)] durations.append(tokens) # if the first duration was not given, find it if durations and not durations[0]: durations[0] = preceding_duration(cursor) or ['4'] return ["".join(tokens) for tokens in durations] python_ly-0.9.9/ly/slexer.py0000644000000000000000000004307613615410400013010 0ustar00# === Python slexer (Stateful Lexer) module === # # Copyright (c) 2008 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. r""" slexer -- Stateful Lexer ======================== parses text, searching for tokens represented by a regular expression. Only depends on the standard Python re module. You need to create at least one subclass of Parser, and a subclass of Token for every type of text to search for. Then you list the token class names in the 'items' tuple of the Parser subclass definition. Different contexts can be parsed by creating multiple Parser subclasses. A Parser searches for tokens using the list of Token classes. (Token is simply a subclass of str). Every Token subclass has the regular expression part to search for in its 'rx' class attribute. You start parsing text by instantiating a State (you don't need to subclass that) with the Parser subclass you want to parse the text with. Then you iterate over the generated tokens using the tokens(text) method of the State instance. You can use the tokens just as strings (e.g. if token == 'text'...) but you can also test for the type of the token (e.g. if isinstance(token, Number)...). The tokens also carry a 'pos' and an 'end' attribute, specifying their position in the parsed text string. A token may cause a different Parser to be entered, of the current Parser to be left, etc. This is done by implementing the update_state() method of the Token subclass. This method is called automatically when the Token is instantiated. The State maintains the parsing state (the list of active Parser instances). A State can be frozen to be thawed later to resume parsing text starting in a particular context. A Fridge can be used to store and recover a state under a simple integer number. How to use slexer:: from slexer import Token, Parser, State # create token classes: class Word(Token): rx = r'\w+' class Number(Token): rx = r'\d+' class String(Token): pass class StringStart(String): rx = '"' def update_state(self, state): state.enter(PString()) class StringEnd(String): rx = '"' def update_state(self, state): state.leave() # create parsers: class PTest(Parser): '''Looks for numbers, words and the double quote.''' items = ( Number, Word, StringStart, ) class PString(Parser): '''Returns String by default, quits at double quote.''' default = String items = ( StringEnd, ) s = State(PTest) for t in s.tokens( 'een tekst met 7 woorden, ' 'een "tekst met 2 aanhalingstekens" ' 'en 2 of 3 nummers'): print(t.__class__, t) Running the above code, the result is:: een tekst met 7 woorden een " tekst met 2 aanhalingstekens " en 2 of 3 nummers """ from __future__ import unicode_literals from __future__ import print_function try: str = unicode except NameError: pass import re __all__ = ['Token', 'Parser', 'FallthroughParser', 'State', 'Fridge'] class State(object): """Maintains state while parsing text. You instantiate a State object with an initial parser class. Then you use tokens(text) to start parsing for tokens. The state is basically a list of Parser instances; the last one is the active one. The enter() and leave() methods respectively enter a new parser or leave the current parser. You can't leave() the initial parser instance. """ def __init__(self, initialParserClass): """Construct the State with an initial Parser instance.""" self.state = [initialParserClass()] def parser(self): """Return the currently active Parser instance.""" return self.state[-1] def parsers(self): """Return all active parsers, the most current one first.""" return self.state[::-1] def tokens(self, text, pos=0): """Parse a text string using our state info. Yields Token instances. All tokens are a subclass of str and have a pos and an end attribute, describing their position in the original string. If the current parser defines a 'default' class attribute, it is the Token subclass to use for pieces of text that would otherwise be skipped. """ while True: parser = self.parser() m = parser.parse(text, pos) if m: if parser.default and pos < m.start(): token = parser.default(text[pos:m.start()], pos) token.update_state(self) yield token token = parser.token(m) token.update_state(self) yield token pos = m.end() elif pos == len(text) or parser.fallthrough(self): break if parser.default and pos < len(text): token = parser.default(text[pos:], pos) token.update_state(self) yield token def enter(self, parser): """Enter a new parser. Note: 'parser' is an instantiated Parser subclass. Most times this method will be called from with the update_state() method of a Token subclass (or from a Parser subclass, which is also possible: the default implementation of Token.update_state() calls Parser.update_state(), which does nothing by default). E.g. in the Token subclass:: def update_state(self, state): state.enter(SomeDifferentParser()) """ self.state.append(parser) def leave(self): """Leave the current parser and pop back to the previous. The first parser (specified on instantiation) will never be left. """ if len(self.state) > 1: self.state.pop() def replace(self, parser): """Replace the current parser with a new one. Somewhat equivalent to:: state.leave() state.enter(SomeDifferentParser) But using this method you can also replace the first parser. """ self.state[-1] = parser def depth(self): """Return the number of parsers currently active (1 or more). You can use this e.g. to keep parsing until some context ends:: tokens = state.tokens(text) # iterator depth = state.depth() for token in tokens: if state.depth() < depth: break # do something """ return len(self.state) def follow(self, token): """Act as if the token has been instantiated with the current state. You need this when you already have the parsed tokens, (e.g. cached or saved somehow) but want to know which parser created them. This method changes state according to the token. Basically it calls the update_state() method of the token instance, but it does some more work behind the scenes to ensure that the FallthroughParser type (see below) also is handled correctly. """ while self.parser()._follow(token, self): pass token.update_state(self) def freeze(self): """Return the current state as a tuple (hashable object).""" return tuple((p.__class__, p.freeze()) for p in self.state) @classmethod def thaw(cls, frozen): """Reproduce a State object from the frozen state argument.""" state = cls.__new__(cls) state.state = [cls.thaw(attrs) for cls, attrs in frozen] return state class Token(str): """Represents a parsed piece of text. The subclass determines the type. You should put the regular expression string in the rx class attribute. In the rx string, you may not use named groups starting with "g\\_". To add token types to a Parser class, list the token class in the items attribute of the Parser class. """ __slots__ = ['pos', 'end'] rx = None @classmethod def test_match(cls, match): """Should return True if the match should indeed instantiate this class. This class method is only called if multiple Token classes in the Parser's items list have the same rx attribute. This method is then called for every matching Token subclass until one returns True. That token is then instantiated. (The method is not called for the last class in the list that have the same rx attribute, and also not if there is only one class with that rx attribute.) The default implementation always returns True. """ return True def __new__(cls, string, pos): token = str.__new__(cls, string) token.pos = pos token.end = pos + len(token) return token def update_state(self, state): """Lets the token update the state, e.g. enter a different parser. This method is called by the State upon instantiation of the tokens. Don't use it later on to have a State follow already instantiated Tokens because the FallthroughParser type can also change the state without generating a Token. Use State.follow() to have a State follow instantiated Tokens. The default implementation lets the Parser decide on state change. """ state.parser().update_state(state, self) class PatternProperty(object): """A descriptor that lazily generates a regular expression. The expression is based on the list of Token subclasses in the items attribute of a Parser class. Also creates an index attribute for the parser class that maps the lastindex property of a match object to the token class. When the pattern is requested for the first time, it is created and also written in the class, overwriting this descriptor. """ def __get__(self, instance, owner): try: owner.pattern = self.pattern owner.index = self.index except AttributeError: # if Token classes have the same regexp string, group them patterns = [] counter = {} for cls in uniq(owner.items): rx = cls.rx try: counter[rx].append(cls) except KeyError: counter[rx] = [cls] patterns.append(rx) # make the pattern owner.pattern = self.pattern = pattern = re.compile("|".join( "(?P{1})".format(i, rx) for i, rx in enumerate(patterns)), owner.re_flags) # make a fast mapping list from matchObj.lastindex to the token class indices = sorted(v for k, v in pattern.groupindex.items() if k.startswith('g_')) owner.index = self.index = index = [None] * (indices[-1] + 1) for i, rx in zip(indices, patterns): index[i] = counter[rx] return owner.pattern class ParserMeta(type): """Metaclass for Parser subclasses. Adds a 'pattern' attribute with a PatternProperty() when the class also defines 'items'. """ def __new__(cls, name, bases, attrd): if attrd.get('items'): attrd['pattern'] = PatternProperty() return type.__new__(cls, name, bases, attrd) class Parser(object): """Abstract base class for Parsers. When creating Parser subclasses, you should set the 'items' attribute to a tuple of Token subclasses. On class construction, a large regular expression pattern is built by combining the expressions from the 'rx' attributes of the Token subclasses. Additionally, you may implement the update_state() method which is called by the default implementation of update_state() in Token. """ re_flags = 0 # the re.compile flags to use default = None # if not None, the default class for unparsed pieces of text # tuple of Token classes to look for in text items = () def parse(self, text, pos): """Parse text from position pos and returns a Match Object or None.""" return self.pattern.search(text, pos) def token(self, match): """Return a Token instance of the correct class. The match object is returned by the parse() method. """ clss = self.index[match.lastindex] for c in clss[:-1]: if c.test_match(match): return c(match.group(), match.start()) return clss[-1](match.group(), match.start()) def _follow(self, token, state): """(Internal) Called by State.follow(). Does nothing.""" pass def freeze(self): """Return our instance values as a hashable tuple.""" return () @classmethod def thaw(cls, attrs): return cls(*attrs) def fallthrough(self, state): """Called when no match is returned by parse(). If this function returns True, the tokenizer stops parsing, assuming all text has been consumed. If this function returns False or None, it should alter the state (switch parsers) and parsing continues using the new Parser. The default implementation simply returns True. """ return True def update_state(self, state, token): """Called by the default implementation of Token.update_state(). Does nothing by default. """ pass # This syntax to make Parser use the metaclass works in both Python2 and 3 Parser = ParserMeta(Parser.__name__, Parser.__bases__, dict(Parser.__dict__)) class FallthroughParser(Parser): """Base class for parsers that 'match' instead of 'search' for a pattern. You can also implement the fallthrough() method to do something with the state if there is no match. The default is to leave the current parser. See Parser(). """ def parse(self, text, pos): """Match text at position pos and returns a Match Object or None.""" return self.pattern.match(text, pos) def _follow(self, token, state): """(Internal) Called by State.follow(). Falls through if the token can't have been generated by this parser. """ if type(token) not in self.items: self.fallthrough(state) return True def fallthrough(self, state): """Called when no match is returned by parse(). This implementation leaves the current parser and returns None (causing the State to continue parsing). """ state.leave() class Fridge(object): """Stores frozen States under an integer number.""" def __init__(self, stateClass = State): self._stateClass = stateClass self._states = [] def freeze(self, state): """Stores a state and return an identifying integer.""" frozen = state.freeze() try: return self._states.index(frozen) except ValueError: i = len(self._states) self._states.append(frozen) return i def thaw(self, num): """Returns the state stored under the specified number.""" if 0 <= num < len(self._states): return self._stateClass.thaw(self._states[num]) def count(self): """Returns the number of stored frozen states.""" return len(self._states) def uniq(iterable): """Yields unique items from iterable.""" seen, l = set(), 0 for i in iterable: seen.add(i) if len(seen) > l: yield i l = len(seen) if __name__ == "__main__": # test class Word(Token): rx = r'\w+' class Number(Token): rx = r'\d+' class String(Token): pass class StringStart(String): rx = '"' def update_state(self, state): state.enter(PString()) class StringEnd(String): rx = '"' def update_state(self, state): state.leave() class PTest(Parser): items = ( Number, Word, StringStart, ) class PString(Parser): default = String items = ( StringEnd, ) s = State(PTest) print('test:') for t in s.tokens( 'een tekst met 7 woorden, ' 'een "tekst met 2 aanhalingstekens" ' 'en 2 of 3 nummers'): print(t.__class__, t) print('test the Fridge:') s = State(PTest) f = Fridge() for t in s.tokens('text with "part of a '): print(t.__class__, t) n = f.freeze(s) # recover print('freeze and recover:') s = f.thaw(n) for t in s.tokens('quoted string" in the middle'): print(t.__class__, t) python_ly-0.9.9/ly/util.py0000644000000000000000000000724313615410400012457 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2008 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ Utility functions. """ from __future__ import unicode_literals import string _nums = ( '', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen') _tens = ( 'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety') def int2text(number): """Converts an integer to the English language name of that integer. E.g. converts 1 to "One". Supports numbers 0 to 999999. This can be used in LilyPond identifiers (that do not support digits). """ result = [] if number >= 1000: hundreds, number = divmod(number, 1000) result.append(int2text(hundreds) + "Thousand") if number >= 100: tens, number = divmod(number, 100) result.append(_nums[tens] + "Hundred") if number < 20: result.append(_nums[number]) else: tens, number = divmod(number, 10) result.append(_tens[tens-2] + _nums[number]) text = "".join(result) return text or 'Zero' # Thanks: http://billmill.org/python_roman.html _roman_numerals = (("M", 1000), ("CM", 900), ("D", 500), ("CD", 400), ("C", 100), ("XC", 90), ("L", 50), ("XL", 40), ("X", 10), ("IX", 9), ("V", 5), ("IV", 4), ("I", 1)) def int2roman(n): """Convert an integer value to a roman number string. E.g. 1 -> "I", 12 -> "XII", 2015 -> "MMXV" n has to be > 1. """ if n < 1: raise ValueError('Roman numerals must be positive integers, got %s' % n) roman = [] for ltr, num in _roman_numerals: k, n = divmod(n, num) roman.append(ltr * k) return "".join(roman) def int2letter(number, chars=string.ascii_uppercase): """Converts an integer to one or more letters. E.g. 1 -> A, 2 -> B, ... 26 -> Z, 27 -> AA, etc. Zero returns the empty string. chars is the string to pick characters from, defaulting to string.ascii_uppercase. """ mod = len(chars) result = [] while number > 0: number, c = divmod(number - 1, mod) result.append(c) return "".join(chars[c] for c in reversed(result)) def mkid(*args): """Makes a lower-camel-case identifier of the strings in args. All strings are concatenated with the first character of every string uppercased, except for the first character, which is lowercased. Examples:: mkid("Violin") ==> "violin" mkid("soprano", "verse") ==> "sopranoVerse" mkid("scoreOne", "choirII") ==> "scoreOneChoirII" """ result = [] for a in args[:1]: result.append(a[:1].lower()) result.append(a[1:]) for a in args[1:]: result.append(a[:1].upper()) result.append(a[1:]) return "".join(result) python_ly-0.9.9/ly/words.py0000644000000000000000000007376513615410400012654 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2008 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ LilyPond reserved words for auto completion and highlighting. """ from __future__ import unicode_literals lilypond_keywords = ( 'accepts', 'alias', 'book', 'bookpart', 'consists', 'context', 'defaultchild', 'denies', 'description', 'etc', 'header', 'hide', # since 2.18 'include', 'inherit-acceptability', 'language', 'layout', 'midi', 'name', 'omit', # since 2.18 'once', 'override', 'paper', 'remove', 'revert', 'score', 'set', 'sourcefileline', # since 2.20 'sourcefilename', # since 2.20 'tagGroup', # since 2.20 'temporary', # since 2.18 'type', 'undo', # since 2.18 (not mentioned in the command index) 'unset', 'version', 'with', ) lilypond_music_commands = ( 'absolute', # since 2.18 'acciaccatura', 'accidentalStyle', # since 2.16 'addChordShape', # since 2.16 'addInstrumentDefinition', 'addlyrics', 'addQuote', 'after', 'afterGrace', #'afterGraceFraction', # this is a parser variable 'aikenHeads', 'aikenHeadsMinor', 'aikenThinHeads', 'aikenThinHeadsMinor', 'allowBreak', 'allowPageTurn', 'allowVoltaHook', 'alterBroken', # since 2.18 (?) 'alternative', 'ambitusAfter', #'AncientRemoveEmptyStaffContext', 'appendToTag', # since 2.16 'applyContext', 'applyMusic', 'applyOutput', 'appoggiatura', 'arabicStringNumbers', # since 2.20 'arpeggio', 'arpeggioArrowDown', 'arpeggioArrowUp', 'arpeggioBracket', 'arpeggioNormal', 'arpeggioParenthesis', 'arpeggioParenthesisDashed', 'ascendens', 'assertBeamQuant', 'assertBeamSlope', 'auctum', 'aug', 'augmentum', 'autoAccidentals', 'autoBeamOff', 'autoBeamOn', 'autoBreaksOff', 'autoBreaksOn', 'autoChange', 'autoLineBreaksOff', 'autoLineBreaksOn', 'autoPageBreaksOff', 'autoPageBreaksOn', 'balloonGrobText', 'balloonLengthOff', 'balloonLengthOn', 'balloonText', 'bar', 'barNumberCheck', 'bassFigureExtendersOff', 'bassFigureExtendersOn', 'bassFigureStaffAlignmentDown', 'bassFigureStaffAlignmentNeutral', 'bassFigureStaffAlignmentUp', 'beamExceptions', # since 2.20 'bendAfter', 'bendHold', # since 2.23 'bendStartLevel', 'blackTriangleMarkup', 'bookOutputName', 'bookOutputSuffix', 'bp', # since 2.24 'break', 'breathe', 'breve', 'cadenzaOff', 'cadenzaOn', 'caesura', 'cavum', 'change', 'chordmode', #'chordNameSeparator', #'chordPrefixSpacer', 'chordRepeats', # since 2.16 #'chordRootNamer', 'chords', 'clef', 'cm', 'codaMark', # since 2.24 'compoundMeter', # since 2.16 #'compressFullBarRests', renamed to compressEmptyMeasures 'compressEmptyMeasures', 'compressMMRests', # since 2.23 'context', 'cr', 'cresc', 'crescHairpin', 'crescTextCresc', 'crossStaff', # since 2.16 'cueClef', # since 2.16 'cueClefUnset', # since 2.16 'cueDuring', 'cueDuringWithClef', # since 2.16 'dashBang', # since 2.20 'dashBar', 'dashDash', 'dashDot', 'dashHat', 'dashLarger', 'dashPlus', 'dashUnderscore', 'deadNote', # since 2.16 'deadNotesOff', 'deadNotesOn', 'decr', 'decresc', # since 2.14 or earlier 'default', 'defaultNoteHeads', # since 2.16 'defaultTimeSignature', 'defineBarLine', # since 2.18 'deminutum', 'denies', 'deprecatedcresc', 'deprecateddim', 'deprecatedendcresc', 'deprecatedenddim', 'descendens', 'dim', 'dimHairpin', 'dimTextDecr', 'dimTextDecresc', 'dimTextDim', 'displayLilyMusic', 'displayMusic', 'displayScheme', # since 2.23 'divisioMaior', 'divisioMaxima', 'divisioMinima', 'dotsDown', 'dotsNeutral', 'dotsUp', 'dropNote', # since 2.23 'drummode', 'drumPitchTable', 'drums', 'dynamicDown', 'dynamicNeutral', 'dynamicUp', 'easyHeadsOff', 'easyHeadsOn', 'EnableGregorianDivisiones', # 2.24 'enablePolymeter', 'endcr', 'endcresc', 'enddecr', 'enddim', 'endincipit', 'endSkipNCs', 'endSpanners', 'episemFinis', 'episemInitium', 'eventChords', # since 2.23 'expandEmptyMeasures', 'expandFullBarRests', 'f', 'featherDurations', 'fermataMarkup', 'ff', 'fff', 'ffff', 'fffff', 'figuremode', 'figures', 'finalis', 'fine', 'finger', # since 2.23 'fingeringOrientations', 'fixed', # since 2.23 'flexa', 'footnote', # since 2.23 'fp', 'frenchChords', 'fullJazzExceptions', 'funkHeads', 'funkHeadsMinor', 'fz', 'germanChords', 'glide', # since 2.24 'glissando', 'grace', 'graceSettings', 'grobdescriptions', # since 2.23 'harmonic', 'harmonicByFret', # since 2.20 'harmonicByRatio', # since 2.20 'harmonicNote', 'harmonicsOff', 'harmonicsOn', 'hideNotes', 'hideSplitTiedTabNotes', 'hideStaffSwitch', 'huge', 'ignatzekExceptionMusic', 'ignatzekExceptions', 'iij', 'IIJ', 'ij', 'IJ', 'improvisationOff', 'improvisationOn', 'in', 'incipit', 'inclinatum', 'includePageLayoutFile', 'indent', 'inStaffSegno', # since 2.23 'instrumentSwitch', 'instrumentTransposition', 'interscoreline', 'inversion', # since 2.23 'invertChords', # since 2.23 'italianChords', 'jump', 'keepWithTag', 'key', 'kievanOff', 'kievanOn', 'killCues', 'label', 'laissezVibrer', 'languageRestore', # since 2.23 'languageSaveAndChange', # since 2.23 'large', 'ligature', 'linea', 'longa', 'lyricmode', 'lyrics', 'lyricsto', 'magnifyMusic', # since 2.20 'magnifyStaff', # since 2.23 'maininput', 'maj', 'majorSevenSymbol', 'makeClusters', 'makeDefaultStringTuning', 'mark', 'markLengthOff', # since 2.18 'markLengthOn', # since 2.18 'markup', 'markuplines', # deprecated, till 2.14 'markuplist', # from 2.16 'markupMap', #since 2.23 'maxima', 'medianChordGridStyle', 'melisma', 'melismaEnd', 'mergeDifferentlyDottedOff', 'mergeDifferentlyDottedOn', 'mergeDifferentlyHeadedOff', 'mergeDifferentlyHeadedOn', 'mf', 'mm', 'modalInversion', # since 2.23 'modalTranspose', # since 2.23 'mp', 'musicMap', 'n', # since 2.22 'neumeDemoLayout', 'new', 'newSpacingSection', 'noBeam', 'noBreak', 'noPageBreak', 'noPageTurn', 'normalsize', 'notemode', 'numericTimeSignature', 'octaveCheck', 'offset', # since 2.23 'oldaddlyrics', 'oneVoice', 'oriscus', 'ottava', 'override', 'overrideProperty', 'overrideTimeSignatureSettings', # since 2.16 'p', 'pageBreak', 'pageTurn', 'palmMute', # since 2.16 'palmMuteOff', 'palmMuteOn', # since 2.16 'parallelMusic', 'parenthesize', 'partCombine', 'partCombineApart', 'partCombineAutomatic', 'partCombineChords', 'partCombineDown', # since 2.23 'partCombineForce', 'partCombineListener', 'partCombineSoloI', 'partCombineSoloII', 'partCombineUnisono', 'partCombineUp', # since 2.23 'partial', 'partialJazzExceptions', 'partialJazzMusic', 'pes', 'phrasingSlurDashed', 'phrasingSlurDashPattern', 'phrasingSlurDotted', 'phrasingSlurDown', 'phrasingSlurHalfDashed', 'phrasingSlurHalfSolid', 'phrasingSlurNeutral', 'phrasingSlurSolid', 'phrasingSlurUp', 'pitchedTrill', 'pointAndClickOff', 'pointAndClickOn', 'pointAndClickTypes', 'pp', 'ppp', 'pppp', 'ppppp', 'preBend', # since 2.23 'preBendHold', # since 2.23 'predefinedFretboardsOff', 'predefinedFretboardsOn', 'propertyOverride', # since 2.23 'propertyRevert', # since 2.23 'propertySet', # since 2.23 'propertyTweak', # since 2.23 'propertyUnset', # since 2.23 'pt', 'pushToTag', # since 2.16 'quilisma', 'quoteDuring', 'raiseNote', # since 2.23 'reduceChords', # since 2.23 'relative', 'RemoveAllEmptyStaves', # since 2.20 'RemoveEmptyRhythmicStaffContext', 'RemoveEmptyStaffContext', 'RemoveEmptyStaves', # since 2.20 'removeWithTag', 'repeat', 'repeatTie', 'resetRelativeOctave', 'responsum', 'rest', 'retrograde', # since 2.23 'revert', 'revertTimeSignatureSettings', # since 2.23 'rfz', 'rightHandFinger', 'romanStringNumbers', # since 2.20 'sacredHarpHeads', 'sacredHarpHeadsMinor', 'scaleDurations', 'scoreTweak', 'section', 'sectionLabel', 'segnoMark', 'semiGermanChords', 'set', 'setDefaultDurationToQuarter', 'settingsFrom', # 2.23 'sf', 'sff', 'sfp', 'sfz', 'shape', # since 2.16 'shiftDurations', 'shiftOff', 'shiftOn', 'shiftOnn', 'shiftOnnn', 'showSplitTiedTabNotes', 'showStaffSwitch', 'single', # since 2.18 'skip', 'skipNC', 'skipNCs', 'skipTypesetting', 'slashedGrace', # since 2.20 'slurDashed', 'slurDashPattern', 'slurDotted', 'slurDown', 'slurHalfDashed', 'slurHalfSolid', 'slurNeutral', 'slurSolid', 'slurUp', 'small', 'sostenutoOff', 'sostenutoOn', 'southernHarmonyHeads', 'southernHarmonyHeadsMinor', 'sp', 'spacingTweaks', 'spp', 'staff-space', 'staffHighlight', 'startAcciaccaturaMusic', 'startAppoggiaturaMusic', 'startGraceMusic', 'startGroup', 'startMeasureCount', 'startMeasureSpanner', 'startSlashedGraceMusic', 'startStaff', 'startTextSpan', 'startTrillSpan', 'stemDown', 'stemNeutral', 'stemUp', 'stopAcciaccaturaMusic', 'stopAppoggiaturaMusic', 'stopGraceMusic', 'stopGroup', 'stopMeasureCount', 'stopMeasureSpanner', 'stopSlashedGraceMusic', 'stopStaff', 'stopStaffHighlight', 'stopTextSpan', 'stopTrillSpan', 'storePredefinedDiagram', 'stringTuning', # since 2.16 'strokeFingerOrientations', 'stropha', 'styledNoteHeads', # since 2.23 'sustainOff', 'sustainOn', 'tabChordRepeats', 'tabChordRepetition', 'tabFullNotation', 'tag', 'teeny', 'tempo', 'tempoWholesPerMinute', 'textEndMark', 'textLengthOff', 'textLengthOn', 'textMark', 'textSpannerDown', 'textSpannerNeutral', 'textSpannerUp', 'tieDashed', 'tieDashPattern', 'tieDotted', 'tieDown', 'tieHalfDashed', 'tieHalfSolid', 'tieNeutral', 'tieSolid', 'tieUp', 'time', 'times', 'timing', 'tiny', 'tocItem', # since ? 'transpose', 'transposedCueDuring', 'transposition', 'treCorde', 'tuplet', # since 2.18 'tupletDown', 'tupletNeutral', 'tupletSpan', #since 2.23 'tupletUp', 'tweak', 'unaCorda', 'unfolded', # since 2.23 'unfoldRepeats', 'unHideNotes', 'unit', 'unset', 'versus', 'virga', 'virgula', 'voiceFour', 'voiceFourStyle', 'voiceNeutralStyle', 'voiceOne', 'voiceOneStyle', 'voices', # since 2.23 'voiceThree', 'voiceThreeStyle', 'voiceTwo', 'voiceTwoStyle', 'void', # since 2.23 'volta', # since 2.24 'vshape', # since 2.23 'walkerHeads', 'walkerHeadsMinor', 'whiteTriangleMarkup', 'withMusicProperty', 'xNote', 'xNotesOff', 'xNotesOn', ) articulations = ( 'accent', 'espressivo', 'marcato', 'portato', 'staccatissimo', 'staccato', 'tenuto', ) ornaments = ( 'downmordent', 'downprall', 'haydnturn', # since 2.22 'lineprall', 'mordent', 'prall', 'pralldown', 'prallmordent', 'prallprall', 'prallup', 'reverseturn', 'slashturn', # since 2.22 'trill', 'turn', 'upmordent', 'upprall', ) fermatas = ( 'fermata', 'henzelongfermata', # since 2.22 'henzeshortfermata', # since 2.22 'longfermata', 'shortfermata', 'verylongfermata', 'veryshortfermata', # since 2.22 ) instrument_scripts = ( 'downbow', 'flageolet', 'halfopen', 'lheel', 'ltoe', 'open', 'rheel', 'rtoe', 'snappizzicato', 'stopped', 'thumb', 'upbow', ) repeat_scripts = ( 'coda', 'segno', 'varcoda', ) ancient_scripts = ( 'accentus', 'circulus', 'ictus', 'semicirculus', 'signumcongruentiae', ) modes = ( 'aeolian', 'dorian', 'ionian', 'locrian', 'lydian', 'major', 'minor', 'mixolydian', 'phrygian', ) markupcommands_nargs = ( # no arguments ( 'coda', 'doubleflat', 'doublesharp', 'eyeglasses', 'fermata', 'flat', 'natural', 'null', 'segno', 'semiflat', 'semisharp', 'sesquiflat', 'sesquisharp', 'sharp', 'strut', 'table-of-contents', 'varcoda', ), # one argument ( 'accidental', 'backslashed-digit', 'bold', 'box', 'bracket', 'caps', 'center-align', 'center-column', 'char', 'circle', 'column', 'compound-meter', 'concat', 'dir-column', 'discant', 'draw-dashed-line', # since 2.18 'draw-dotted-line', # since 2.18 'draw-hline', 'draw-line', 'dynamic', 'ellipse', 'fill-line', 'figured-bass', 'finger', 'first-visible', 'fontCaps', 'freeBass', 'fret-diagram', 'fret-diagram-terse', 'fret-diagram-verbose', 'fromproperty', 'harp-pedal', 'hbracket', 'hspace', 'huge', 'italic', 'justify', 'justify-field', 'justify-line', #since 2.20 'justify-string', 'large', 'larger', 'left-align', 'left-brace', 'left-column', 'line', 'lookup', 'markalphabet', 'markletter', 'medium', 'multi-measure-rest-by-number', 'musicglyph', 'normalsize', 'normal-size-sub', 'normal-size-super', 'normal-text', 'number', 'oval', # since 2.18 'overlay', # since 2.20 'overtie', # since 2.20 'polygon', 'postscript', 'property-recursive', 'rest', 'right-align', 'right-brace', 'right-column', 'roman', 'rounded-box', 'rhythm', 'sans', 'score', 'score-lines', 'simple', 'slashed-digit', 'small', 'smallCaps', 'smaller', 'stdBass', # since 2.18 'stdBassIV', # since 2.18 'stdBassV', # since 2.18 'stdBassVI', # since 2.18 'stencil', 'string-lines', 'sub', 'super', 'teeny', 'text', 'tie', # since 2.20 'tied-lyric', 'tiny', 'transparent', 'triangle', 'typewriter', 'underline', 'undertie', # since 2.20 'upright', 'vcenter', 'verbatim-file', 'vspace', 'whiteout', 'with-true-dimensions', 'wordwrap', 'wordwrap-field', 'wordwrap-string', ), # two arguments ( 'abs-fontsize', 'auto-footnote', # since 2.16 'combine', 'customTabClef', 'fontsize', 'footnote', 'fraction', 'halign', 'hcenter-in', 'if', 'lower', 'magnify', 'note', 'on-the-fly', 'override', 'pad-around', 'pad-markup', 'pad-x', 'page-link', 'path', # added in LP 2.13.31 'raise', 'replace', 'rest-by-number', 'rotate', 'scale', 'table', # since 2.20 'translate', 'translate-scaled', 'unless', 'with-color', 'with-dimensions-from', # since 2.20 'with-link', 'with-outline', 'with-string-transformer', 'with-true-dimension', 'with-url', 'woodwind-diagram', ), # three arguments ( 'arrow-head', 'beam', 'draw-circle', 'draw-squiggle-line', # since 2.20 'epsfile', 'filled-box', 'general-align', 'note-by-number', 'pad-to-box', 'page-ref', 'with-dimension', 'with-dimension-from', 'with-dimensions', ), # four arguments ( 'pattern', 'put-adjacent', ), # five arguments, ( 'align-on-other', 'fill-with-pattern', ), ) markupcommands = sum(markupcommands_nargs, ()) markuplistcommands = ( 'column-lines', 'justified-lines', 'map-commands', # since 2.24 'override-lines', 'wordwrap-internal', 'wordwrap-lines', 'wordwrap-string-internal', ) contexts = ( 'ChoirStaff', 'ChordGrid', 'ChordGridScore', 'ChordNames', 'CueVoice', 'Devnull', 'DrumStaff', 'DrumVoice', 'Dynamics', 'FiguredBass', 'FretBoards', 'Global', 'GrandStaff', 'GregorianTranscriptionLyrics', 'GregorianTranscriptionStaff', 'GregorianTranscriptionVoice', 'InternalGregorianStaff', 'KievanStaff', # since 2.16 'KievanVoice', # since 2.16 'Lyrics', 'MensuralStaff', 'MensuralVoice', 'NoteNames', 'NullVoice', # since 2.18 'OneStaff', 'PetrucciStaff', # since 2.16 'PetrucciVoice', # since 2.16 'PianoStaff', 'RhythmicStaff', 'Score', 'Staff', 'StaffGroup', 'StandaloneRhythmScore', 'StandaloneRhythmStaff', 'StandaloneRhythmVoice', 'TabStaff', 'TabVoice', 'Timing', 'VaticanaLyrics', 'VaticanaStaff', 'VaticanaVoice', 'Voice', ) midi_instruments = ( # (1-8 piano) 'acoustic grand', 'bright acoustic', 'electric grand', 'honky-tonk', 'electric piano 1', 'electric piano 2', 'harpsichord', 'clav', # (9-16 chrom percussion) 'celesta', 'glockenspiel', 'music box', 'vibraphone', 'marimba', 'xylophone', 'tubular bells', 'dulcimer', # (17-24 organ) 'drawbar organ', 'percussive organ', 'rock organ', 'church organ', 'reed organ', 'accordion', 'harmonica', 'concertina', # (25-32 guitar) 'acoustic guitar (nylon)', 'acoustic guitar (steel)', 'electric guitar (jazz)', 'electric guitar (clean)', 'electric guitar (muted)', 'overdriven guitar', 'distorted guitar', 'guitar harmonics', # (33-40 bass) 'acoustic bass', 'electric bass (finger)', 'electric bass (pick)', 'fretless bass', 'slap bass 1', 'slap bass 2', 'synth bass 1', 'synth bass 2', # (41-48 strings) 'violin', 'viola', 'cello', 'contrabass', 'tremolo strings', 'pizzicato strings', 'orchestral harp', # till LilyPond 2.12 was this erroneously called: 'orchestral strings' 'timpani', # (49-56 ensemble) 'string ensemble 1', 'string ensemble 2', 'synthstrings 1', 'synthstrings 2', 'choir aahs', 'voice oohs', 'synth voice', 'orchestra hit', # (57-64 brass) 'trumpet', 'trombone', 'tuba', 'muted trumpet', 'french horn', 'brass section', 'synthbrass 1', 'synthbrass 2', # (65-72 reed) 'soprano sax', 'alto sax', 'tenor sax', 'baritone sax', 'oboe', 'english horn', 'bassoon', 'clarinet', # (73-80 pipe) 'piccolo', 'flute', 'recorder', 'pan flute', 'blown bottle', 'shakuhachi', 'whistle', 'ocarina', # (81-88 synth lead) 'lead 1 (square)', 'lead 2 (sawtooth)', 'lead 3 (calliope)', 'lead 4 (chiff)', 'lead 5 (charang)', 'lead 6 (voice)', 'lead 7 (fifths)', 'lead 8 (bass+lead)', # (89-96 synth pad) 'pad 1 (new age)', 'pad 2 (warm)', 'pad 3 (polysynth)', 'pad 4 (choir)', 'pad 5 (bowed)', 'pad 6 (metallic)', 'pad 7 (halo)', 'pad 8 (sweep)', # (97-104 synth effects) 'fx 1 (rain)', 'fx 2 (soundtrack)', 'fx 3 (crystal)', 'fx 4 (atmosphere)', 'fx 5 (brightness)', 'fx 6 (goblins)', 'fx 7 (echoes)', 'fx 8 (sci-fi)', # (105-112 ethnic) 'sitar', 'banjo', 'shamisen', 'koto', 'kalimba', 'bagpipe', 'fiddle', 'shanai', # (113-120 percussive) 'tinkle bell', 'agogo', 'steel drums', 'woodblock', 'taiko drum', 'melodic tom', 'synth drum', 'reverse cymbal', # (121-128 sound effects) 'guitar fret noise', 'breath noise', 'seashore', 'bird tweet', 'telephone ring', 'helicopter', 'applause', 'gunshot', # (channel 10 drum-kits - subtract 32768 to get program no.) 'standard kit', 'standard drums', 'drums', 'room kit', 'room drums', 'power kit', 'power drums', 'rock drums', 'electronic kit', 'electronic drums', 'tr-808 kit', 'tr-808 drums', 'jazz kit', 'jazz drums', 'brush kit', 'brush drums', 'orchestra kit', 'orchestra drums', 'classical drums', 'sfx kit', 'sfx drums', 'mt-32 kit', 'mt-32 drums', 'cm-64 kit', 'cm-64 drums', ) # Follow the order of lilypond sources in ly/string-tunings-init.ly string_tunings = ( 'guitar-tuning', 'guitar-seven-string-tuning', 'guitar-drop-d-tuning', 'guitar-drop-c-tuning', 'guitar-open-g-tuning', 'guitar-open-d-tuning', 'guitar-dadgad-tuning', 'guitar-lute-tuning', 'guitar-asus4-tuning', 'bass-tuning', 'bass-four-string-tuning', 'bass-drop-d-tuning', 'bass-five-string-tuning', 'bass-six-string-tuning', 'mandolin-tuning', 'banjo-open-g-tuning', 'banjo-c-tuning', 'banjo-modal-tuning', 'banjo-open-d-tuning', 'banjo-open-dm-tuning', 'banjo-double-c-tuning', 'banjo-double-d-tuning', 'ukulele-tuning', 'ukulele-d-tuning', 'tenor-ukulele-tuning', 'baritone-ukulele-tuning', 'violin-tuning', 'viola-tuning', 'cello-tuning', 'double-bass-tuning', ) #scheme_functions = ( # 'set-accidental-style', # 'set-global-staff-size', # 'set-octavation', # 'set-paper-size', # 'define-public', # 'define-music-function', # 'define-markup-command', # 'empty-stencil', # 'markup', # 'number?', # 'string?', # 'pair?', # 'ly:duration?', # 'ly:grob?', # 'ly:make-moment', # 'ly:make-pitch', # 'ly:music?', # 'ly:moment?', # 'ly:format', # 'markup?', # 'interpret-markup', # 'make-line-markup', # 'make-center-markup', # 'make-column-markup', # 'make-musicglyph-markup', # 'color?', # 'rgb-color', # 'x11-color', #) scheme_values = ( 'UP', 'DOWN', 'LEFT', 'RIGHT', 'CENTER', 'minimum-distance', 'basic-distance', 'padding', 'stretchability', ) headervariables = ( 'arranger', 'breakbefore', 'composer', 'copyright', 'date', 'dedication', 'enteredby', 'footer', 'instrument', 'lastupdated', 'maintainer', 'maintainerEmail', 'maintainerWeb', 'meter', 'moreInfo', 'mutopiacomposer', 'mutopiainstrument', 'mutopiaopus', 'mutopiapoet', 'mutopiatitle', 'opus', 'piece', 'poet', 'source', 'style', 'subsubtitle', 'subtitle', 'tagline', 'texidoc', 'title', ) papervariables = ( # fixed vertical 'paper-height', 'top-margin', 'bottom-margin', 'ragged-bottom', 'ragged-last-bottom', # horizontal 'paper-width', 'line-width', 'left-margin', 'right-margin', 'check-consistency', 'ragged-right', 'ragged-last', 'two-sided', 'inner-margin', 'outer-margin', 'binding-offset', 'horizontal-shift', 'indent', 'short-indent', # flex vertical 'markup-system-spacing', # the distance between a (title or top-level) markup and the system that follows it. 'score-markup-spacing', # the distance between the last system of a score and the (title or top-level) markup that follows it. 'score-system-spacing', # the distance between the last system of a score and the first system of the score that follows it, when no (title or top-level) markup exists between them. 'system-system-spacing', # the distance between two systems in the same score. 'markup-markup-spacing', # the distance between two (title or top-level) markups. 'last-bottom-spacing', # the distance from the last system or top-level markup on a page to the bottom of the printable area (i.e. the top of the bottom margin). 'top-system-spacing', # the distance from the top of the printable area (i.e. the bottom of the top margin) to the first system on a page, when there is no (title or top-level) markup between the two. 'top-markup-spacing', # the distance from the top of the printable area (i.e. the bottom of the top margin) to the first (title or top-level) markup on a page, when there is no system between the two. # line breaking 'max-systems-per-page', 'min-systems-per-page', 'system-count', 'systems-per-page', # page breaking 'blank-after-score-page-force', # The penalty for having a blank page after the end of one score and before the next. By default, this is smaller than blank-page-force, so that we prefer blank pages after scores to blank pages within a score. 'blank-last-page-force', # The penalty for ending the score on an odd-numbered page. 'blank-page-force', # The penalty for having a blank page in the middle of a score. This is not used by ly:optimal-breaking since it will never consider blank pages in the middle of a score. 'page-breaking', # The page-breaking algorithm to use. Choices are ly:minimal-breaking, ly:page-turn-breaking, and ly:optimal-breaking. 'page-breaking-system-system-spacing', # Tricks the page breaker into thinking that system-system-spacing is set to something different than it really is. For example, if page-breaking-system-system-spacing #'padding is set to something substantially larger than system-system-spacing #'padding, then the page-breaker will put fewer systems on each page. Default: unset. 'page-count', # The number of pages to be used for a score, unset by default. # page numbering 'auto-first-page-number', 'first-page-number', 'print-first-page-number', 'print-page-number', # misc 'footnote-separator-markup', 'page-spacing-weight', 'print-all-headers', 'system-separator-markup', # debugging 'annotate-spacing', # different markups 'bookTitleMarkup', 'evenFooterMarkup', 'evenHeaderMarkup', 'oddFooterMarkup', 'oddHeaderMarkup', 'scoreTitleMarkup', 'tocItemMarkup', 'tocTitleMarkup', # fonts 'fonts', # undocumented? #'blank-after-score-page-force', #'force-assignment', #'input-encoding', #'output-scale', ) layoutvariables = ( 'indent', 'line-width', 'ragged-last', 'ragged-right', 'short-indent', 'system-count', ) midivariables = ( ) repeat_types = ( 'percent', 'segno', 'tremolo', 'unfold', 'volta', ) accidentalstyles = ( 'choral', # since 2.20 'choral-cautionary', # since 2.20 'default', 'dodecaphonic', 'dodecaphonic-no-repeat', # since 2.20 'dodecaphonic-first', # since 2.20 'forget', 'modern', 'modern-cautionary', 'modern-voice', 'modern-voice-cautionary', 'neo-modern', 'neo-modern-cautionary', 'neo-modern-voice', 'neo-modern-voice-cautionary', 'no-reset', 'piano', 'piano-cautionary', 'teaching', 'voice', ) clefs_plain = ( 'alto', 'altovarC', 'baritone', 'baritonevarC', 'baritonevarF', 'bass', 'blackmensural-c1', 'blackmensural-c2', 'blackmensural-c3', 'blackmensural-c4', 'blackmensural-c5', 'C', 'F', 'french', 'G', 'GG', # since 2.19 'G2', 'hufnagel-do-fa', 'hufnagel-do1', 'hufnagel-do2', 'hufnagel-do3', 'hufnagel-fa1', 'hufnagel-fa2', 'kievan-do', 'medicaea-do1', 'medicaea-do2', 'medicaea-do3', 'medicaea-fa1', 'medicaea-fa2', 'mensural-c1', 'mensural-c2', 'mensural-c3', 'mensural-c4', 'mensural-c5', 'mensural-f', 'mensural-g', 'mezzosoprano', 'moderntab', 'neomensural-c1', 'neomensural-c2', 'neomensural-c3', 'neomensural-c4', 'neomensural-c5', 'percussion', 'petrucci-c1', 'petrucci-c2', 'petrucci-c3', 'petrucci-c4', 'petrucci-c5', 'petrucci-f', 'petrucci-f2', 'petrucci-f3', 'petrucci-f4', 'petrucci-f5', 'petrucci-g', 'petrucci-g1', 'petrucci-g2', 'soprano', 'subbass', 'tab', 'tenor', 'tenorG', # since 2.19 'tenorvarC', 'treble', 'varbaritone', 'varC', # since 2.19 'varpercussion', # since 2.19 'vaticana-do1', 'vaticana-do2', 'vaticana-do3', 'vaticana-fa1', 'vaticana-fa2', 'violin', ) clefs = clefs_plain + ( 'bass_8', 'treble_8', ) break_visibility = ( 'all-invisible', 'all-visible', 'begin-of-line-invisible', 'begin-of-line-visible', 'center-invisible', 'end-of-line-invisible', 'end-of-line-visible', ) mark_formatters = ( 'format-mark-alphabet', 'format-mark-barnumbers', 'format-mark-box-alphabet', 'format-mark-box-barnumbers', 'format-mark-box-letters', 'format-mark-box-numbers', 'format-mark-circle-alphabet', 'format-mark-circle-barnumbers', 'format-mark-circle-letters', 'format-mark-circle-numbers', 'format-mark-letters', 'format-mark-numbers', ) python_ly-0.9.9/ly/cli/__init__.py0000644000000000000000000000165513615410400014011 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2014 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ The commandline interface of the 'ly' command. """ python_ly-0.9.9/ly/cli/command.py0000644000000000000000000002223113615410400013661 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2014 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. """ The commands that are available to the command line. """ from __future__ import unicode_literals import re import sys import ly.docinfo import ly.indent import ly.pitch import ly.reformat class _command(object): """Base class for commands. If the __init__() fails with TypeError or ValueError, the command is considered invalid and an error message will be written to the console in the parse_command() function in main.py. By default, __init__() expects no arguments. If your command does accept arguments, they are provided in a single argument that you should parse yourself. """ def __init__(self): pass def run(self, opts, cursor, output): pass @staticmethod def get_absolute(opts, cursor): """Utility function to determine whether the first pitch in a relative should be regarded as absolute (LilyPond 2.18+ behaviour). """ if opts.rel_absolute is None: return ly.docinfo.DocInfo(cursor.document).version() >= (2, 18) else: return opts.rel_absolute class set_variable(_command): """set a variable to a value""" def __init__(self, arg): self.name, self.value = arg.split('=', 1) def run(self, opts, cursor, output): opts.set_variable(self.name, self.value) class _info_command(_command): """base class for commands that print some output to stdout.""" def run(self, opts, cursor, output): info = ly.docinfo.DocInfo(cursor.document) text = self.get_info(info) if text: if opts.with_filename: text = cursor.document.filename + ":" + text sys.stdout.write(text + '\n') def get_info(self, info): """Should return the desired information from the docinfo object. If it returns None or an empty string, nothing is printed. """ raise NotImplementedError() class mode(_info_command): """print mode to stdout""" def get_info(self, info): return info.mode() class version(_info_command): """print version to stdout""" def get_info(self, info): return info.version_string() class language(_info_command): """print language to stdout""" def get_info(self, info): return info.language() class _edit_command(_command): """a command that edits the source file""" pass class indent(_edit_command): """run the indenter""" def indenter(self, opts): """Get a ly.indent.Indenter initialized with our options.""" i = ly.indent.Indenter() i.indent_tabs = opts.indent_tabs i.indent_width = opts.indent_width return i def run(self, opts, cursor, output): self.indenter(opts).indent(cursor) class reformat(indent): """reformat the document""" def run(self, opts, cursor, output): ly.reformat.reformat(cursor, self.indenter(opts)) class translate(_edit_command): """translate pitch names""" def __init__(self, language): if language not in ly.pitch.pitchInfo: raise ValueError() self.language = language def run(self, opts, cursor, output): import ly.pitch.translate try: changed = ly.pitch.translate.translate(cursor, self.language, opts.default_language) except ly.pitch.PitchNameNotAvailable: sys.stderr.write( "warning: transate: pitch names not available in \"{0}\"\n" " skipping file: {1}\n".format(self.language, cursor.document.filename)) return if not changed: version = ly.docinfo.DocInfo(cursor.document).version() ly.pitch.translate.insert_language(cursor.document, self.language, version) class transpose(_edit_command): """transpose music""" def __init__(self, arg): result = [] for pitch, octave in re.findall(r"([a-z]+)([,']*)", arg): r = ly.pitch.pitchReader("nederlands")(pitch) if r: result.append(ly.pitch.Pitch(*r, octave=ly.pitch.octaveToNum(octave))) self.from_pitch, self.to_pitch = result def run(self, opts, cursor, output): absolute = self.get_absolute(opts, cursor) import ly.pitch.transpose transposer = ly.pitch.transpose.Transposer(self.from_pitch, self.to_pitch) try: ly.pitch.transpose.transpose(cursor, transposer, opts.default_language, absolute) except ly.pitch.PitchNameNotAvailable: language = ly.docinfo.DocInfo(cursor.document).language() or opts.default_language sys.stderr.write( "warning: transpose: pitch names not available in \"{0}\"\n" " skipping file: {1}\n".format(language, cursor.document.filename)) class rel2abs(_edit_command): """convert relative music to absolute""" def run(self, opts, cursor, output): absolute = self.get_absolute(opts, cursor) import ly.pitch.rel2abs ly.pitch.rel2abs.rel2abs(cursor, opts.default_language, absolute) class abs2rel(_edit_command): """convert absolute music to relative""" def run(self, opts, cursor, output): absolute = self.get_absolute(opts, cursor) import ly.pitch.abs2rel ly.pitch.abs2rel.abs2rel(cursor, opts.default_language, opts.rel_startpitch, absolute) class simplify_accidentals(_edit_command): """replace notes with accidentals as much as possible with their natural neighbors""" def run(self, opts, cursor, output): absolute = self.get_absolute(opts, cursor) import ly.pitch.transpose transposer = ly.pitch.transpose.Simplifier() try: ly.pitch.transpose.transpose(cursor, transposer, opts.default_language, absolute) except ly.pitch.PitchNameNotAvailable: language = ly.docinfo.DocInfo(cursor.document).language() or opts.default_language sys.stderr.write( "warning: simplify_accidentals: pitch names not available in \"{0}\"\n" " skipping file: {1}\n".format(language, cursor.document.filename)) class _export_command(_command): """Command that exports to a file.""" def __init__(self, output=None): self.output = output class musicxml(_export_command): def run(self, opts, cursor, output): absolute = self.get_absolute(opts, cursor) import ly.musicxml writer = ly.musicxml.writer() writer.parse_document(cursor.document, absolute) xml = writer.musicxml() if self.output: filename = self.output else: filename = output.get_filename(opts, cursor.document.filename) encoding = opts.output_encoding or "utf-8" with output.file(opts, filename, "binary") as f: xml.write(f, encoding) class write(_command): """write the source file.""" def __init__(self, output=None): self.output = output def run(self, opts, cursor, output): # determine the real output filename to use encoding = opts.output_encoding or opts.encoding if self.output: filename = self.output elif opts.in_place: if not cursor.document.modified and encoding == opts.encoding: return filename = cursor.document.filename else: filename = output.get_filename(opts, cursor.document.filename) with output.file(opts, filename, encoding) as f: f.write(cursor.document.plaintext()) class highlight(_export_command): """write syntax colored HTML.""" def run(self, opts, cursor, output): import ly.colorize w = ly.colorize.HtmlWriter() w.full_html = opts.full_html w.inline_style = opts.inline_style w.stylesheet_ref = opts.stylesheet w.number_lines = opts.number_lines w.title = cursor.document.filename w.encoding = opts.output_encoding or "utf-8" w.wrapper_tag = opts.wrapper_tag w.wrapper_attribute = opts.wrapper_attribute w.document_id = opts.document_id w.linenumbers_id = opts.linenumbers_id doc = w.html(cursor) if self.output: filename = self.output else: filename = output.get_filename(opts, cursor.document.filename) with output.file(opts, filename, w.encoding) as f: f.write(doc) hl = highlight python_ly-0.9.9/ly/cli/doc.py0000644000000000000000000001672513615410400013023 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly # # Copyright (c) 2015 - 2015 by Wilbert Berendsen # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # See http://www.gnu.org/licenses/ for more information. # this module only contains a doc string, which is printed when using # ly -h . """ Usage:: ly [options] commands file, ... A tool for manipulating LilyPond source files Options ------- -v, --version show version number and exit -h, --help show this help text and exit -i, --in-place overwrite input files -o, --output NAME output file name -e, --encoding ENC (input) encoding (default UTF-8) --output-encoding ENC output encoding (default to input encoding) -l, --language NAME default pitch name language (default to "nederlands") -d set a variable The special option ``--`` considers the remaining arguments to be file names. Arguments --------- The command is one argument with semicolon-separated commands. In most cases you'll quote the command so that it is seen as one argument. You can specify more than one LilyPond file. If you want to process many files and write the results of the operations on each file to a separate output file, you can use two special characters in the output filename: a '*' will be replaced with the full path name of the current input file (without extension), and a '?' will be replaced with the input filename (without path and extension). If you don't want to have '*' or '?' replaced in the output filename, you can set ``-d replace-pattern=false``. If you don't specify input or output filenames, standard input is read and standard output is written to. Commands -------- Informative commands that write information to standard output and do not change the file: ``mode`` print the mode (guessing if not given) of the document ``version`` print the LilyPond version, if set in the document ``language`` print the pitch name language, if set in the document Commands that change the file: ``indent`` re-indent the file ``reformat`` reformat the file ``translate `` translate the pitch names to the language ``transpose `` transpose the file like LilyPond would do, pitches are given in the 'nederlands' language ``abs2rel`` convert absolute music to relative ``rel2abs`` convert relative music to absolute ``simplify-accidentals`` replace notes with accidentals as much as possible with their natural neighbors ``write [filename]`` write the file to the given filename or the output variable. If the last command was an editing command, write is automatically called. Commands that export the file to another format: ``musicxml [filename]`` export to MusicXML (in development, far from complete) ``highlight [filename]`` export the document as syntax colored HTML ``hl [filename]`` alias for highlight Between commands, you can set or unset a variable using: ``variable=value`` set a variable to value. Special values are true, false, which are interpreted as boolean values, or digits, which will be interpreted as integer values. ``variable=`` unset a variable Variables --------- The following variables can be set to influence the behaviour of commands. If there is a default value, it is written between brackets: ``mode`` mode of the file to read (default automatic) can be one of: lilypond, scheme, latex, html, docbook, texinfo. ``output`` [-] the output filename (also set by -o argument) ``encoding`` [UTF-8] encoding to read (also set by -e argument) ``default-language`` [nederlands] the pitch names language to use by default, when not specified otherwise in the document ``output-encoding`` encoding to write (defaults to ``encoding``, also set by the ``--output-encoding`` argument) ``in-place`` [``false``] whether to overwrite input files (same as ``-i``) ``backup-suffix`` [~] suffix to use when editing files in-place, if set, backs up the original file before overwriting it ``replace-pattern`` [``true``] whether to replace '*' and '?' in the output filename. ``rel-startpitch`` [``true``] whether to write relative music with a startpitch ``rel-absolute`` whether to assume that the first pitch in a relative expression without specified startpitch is absolute. If ``false``, it is assumed to be relative to ``c'``. If ``true``, it is assumed to be absolute (in fact relative to ``f``. If not set, this variable defaults to ``true`` only when the LilyPond version in the document >= 2.18. ``indent-tabs`` [``false``] whether to use tabs for indent ``indent-width`` [2] how many spaces for each indent level (if not using tabs) ``full-html`` [``True``] if set to True a full document with syntax-highlighted HTML will be exported, otherwise only the bare content wrapped in an element configured by the ``wrapper-`` variables. ``stylesheet`` filename to reference as an external stylesheet for syntax-highlighted HTML. This filename is literally used in the ```` tag. ``inline-style`` [``false``] whether to use inline style attributes for syntax-highlighted HTML. By default a css stylesheet is embedded. ``number-lines`` [``false``] whether to add line numbers when creating syntax-highlighted HTML. ``wrapper-tag`` [``pre``] which tag syntax highlighted HTML will be wrapped in. Possible values: ``div``, ``pre``, ``id`` and ``code`` ``wrapper-attribute`` [``class``] attribute used for the wrapper tag. Possible values: ``id`` and ``class``. ``document-id`` [``lilypond``] name applied to the wrapper-attribute. If the three last options use their default settings the highlighted HTML elements are wrapped in an element ``
``

  ``linenumbers-id`` [``linenumbers``]
        if linenumbers are exported this is the name used for the ```` elements

These variables influence the output of information commands:

  ``with-filename``
         prints the filename next to information like version,
         etc. This is ``true`` by default if there is more than one
         file specified.


Examples
--------

Here is an example to re-indent and transpose a LilyPond file::

  ly "indent; transpose c d" -o output.ly file.ly

Examples using the '*' in the output file name::

  ly "transpose c d" *.ly -o '*-transposed.ly'
  ly highlight *.ly -o 'html/?.html'


"""
python_ly-0.9.9/ly/cli/main.py0000644000000000000000000002125213615410400013171 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2014 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
The entry point for the 'ly' command.
"""

from __future__ import unicode_literals

import contextlib
import copy
import io
import os
import shutil
import sys

import ly.pkginfo
from . import setvar


def usage():
    """Print usage info."""
    from . import doc
    sys.stdout.write(doc.__doc__)

def usage_short():
    """Print short usage info."""
    sys.stdout.write("""\
Usage: ly [options] commands file, ...

A tool for manipulating LilyPond source files

See ly -h for a full list of commands and options.
""")

def version():
    """Print version info."""
    sys.stdout.write("ly {0}\n".format(ly.pkginfo.version))

def die(message):
    """Exit with message to STDERR."""
    sys.stderr.write("error: " + message + '\n')
    sys.stderr.write(
        "See ly -h for a full list of commands and options.\n")
    sys.exit(1)

class Options(object):
    """Store all the startup options and their defaults."""
    def __init__(self):
        self.mode = None
        self.in_place = False
        self.encoding = 'UTF-8'
        self.output_encoding = None
        self.output = None
        self.replace_pattern = True
        self.backup_suffix = '~'
        self.with_filename = None
        self.default_language = "nederlands"
        self.rel_startpitch = True
        self.rel_absolute = None

        self.indent_width = 2
        self.indent_tabs = False
        self.tab_width = 8

        self.full_html = True
        self.inline_style = False
        self.stylesheet = None
        self.number_lines = False
        self.wrapper_tag = 'pre'
        self.wrapper_attribute = 'class'
        self.document_id = 'lilypond'
        self.linenumbers_id = 'linenumbers'

    def set_variable(self, name, value):
        name = name.replace('-', '_')
        try:
            func = getattr(setvar, name)
        except AttributeError:
            die("unknown variable: {name}".format(name=name))
        try:
            value = func(value)
        except ValueError as e:
            die(format(e))
        setattr(self, name, value)

class Output(object):
    """Object living for a whole file/command operation, handling the output.

    When opening a file it has already opened earlier, the file is appended to
    (like awk).

    """
    def __init__(self):
        self._seen_filenames = set()

    def get_filename(self, opts, filename):
        """Queries the output attribute from the Options and returns it.

        If replace_pattern is True (by default) and the attribute contains a
        '*', it is replaced with the full path of the specified filename,
        but without extension. It the attribute contains a '?', it is
        replaced with the filename without path and extension.

        If '-' is returned, it denotes standard output.

        """
        if not opts.output:
            return '-'
        elif opts.replace_pattern:
            path, ext = os.path.splitext(filename)
            directory, name = os.path.split(path)
            return opts.output.replace('?', name).replace('*', path)
        else:
            return opts.output

    @contextlib.contextmanager
    def file(self, opts, filename, encoding):
        """Return a context manager for writing to.

        If you set encoding to "binary" or False, the file is opened in binary
        mode and you should encode the data you write yourself.

        """
        if not filename or filename == '-':
            filename, mode = sys.stdout.fileno(), 'w'
        else:
            if filename not in self._seen_filenames:
                self._seen_filenames.add(filename)
                if opts.backup_suffix and os.path.exists(filename):
                    shutil.copy(filename, filename + opts.backup_suffix)
                mode = 'w'
            else:
                mode = 'a'
        if encoding in (False, "binary"):
            f = io.open(filename, mode + 'b')
        else:
            f = io.open(filename, mode, encoding=encoding)
        try:
            yield f
        finally:
            f.close()

def parse_command_line():
    """Return a three-tuple(options, commands, files).

    options is an Options instance with all the command-line options
    commands is a list of command.command instances
    files is the list of filename arguments

    Also performs error handling and may exit on certain circumstances.

    """
    if len(sys.argv) < 2:
        usage_short()
        sys.exit(2)

    args = iter(sys.argv[1:])

    opts = Options()
    commands = []
    files = []

    def next_arg(message):
        """Get the next argument, if missing, die with message."""
        try:
            return next(args)
        except StopIteration:
            die(message)

    for arg in args:
        if arg in ('-h', '--help'):
            usage()
            sys.exit(0)
        elif arg in ('-v', '--version'):
            version()
            sys.exit(0)
        elif arg in ('-i', '--in-place'):
            opts.in_place = True
        elif arg in ('-o', '--output'):
            opts.output = next_arg("missing output filename")
        elif arg == '-d':
            s = next_arg("missing variable=value")
            try:
                name, value = s.split('=', 1)
            except ValueError:
                die("missing '=' in variable set")
            opts.set_variable(name, value)
        elif arg in ('-e', '--encoding'):
            opts.encoding = next_arg("missing encoding name")
        elif arg == '--output-encoding':
            opts.output_encoding = next_arg("missing output encoding name")
        elif arg in ('-l', '--language'):
            s = next_arg("missing language name")
            opts.set_variable("default-language", s)
        elif arg == '--':
            files.extend(args)
        elif arg.startswith('-'):
            die('unknown option: ' + arg)
        elif not commands:
            commands = parse_command(arg)
        else:
            files.append(arg)
    from . import command
    if not commands or isinstance(commands[-1], command._edit_command):
        commands.append(command.write())
    if not files:
        files.append('-')
    if opts.with_filename is None:
        opts.with_filename = len(files) > 1
    return opts, commands, files

def parse_command(arg):
    """Parse the command string, returning a list of command.command instances.

    Exits when a command is invalid.

    """
    from . import command

    result = []

    for c in arg.split(';'):
        args = c.split(None, 1)
        if args:
            if '=' in args[0]:
                args = ['set_variable', c.strip()]
            cmd = args.pop(0)
            if not cmd or not cmd[0].isalpha():
                die("unknown command: " + cmd)
            try:
                cmd_class = getattr(command, cmd.replace('-', '_'))
            except AttributeError:
                die("unknown command: " + cmd)
            try:
                result.append(cmd_class(*args))
            except (TypeError, ValueError):
                die("invalid arguments: " + c)
    return result

def load(filename, encoding, mode):
    """Load a file, returning a ly.document.Document"""
    import ly.document
    if filename == '-':
        doc = ly.document.Document.load(sys.stdin.fileno(), encoding, mode)
        doc.filename = '-'
    else:
        doc = ly.document.Document.load(filename, encoding, mode)
    return doc

def main():
    opts, commands, files = parse_command_line()
    import ly.document
    output = Output()
    exit_code = 0
    for filename in files:
        options = copy.deepcopy(opts)
        try:
            doc = load(filename, options.encoding, options.mode)
        except IOError as err:
            sys.stderr.write('warning: skipping file "{0}":\n  {1}\n'.format(filename, err))
            exit_code = 1
            continue
        cursor = ly.document.Cursor(doc)
        for c in commands:
            c.run(options, cursor, output)
    return exit_code
python_ly-0.9.9/ly/cli/setvar.py0000644000000000000000000000754213615410400013557 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2015 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Variables, checking and defaults.
"""

from __future__ import unicode_literals


def _check_bool(name, value):
    """Check for boolean value."""
    if value.lower() in ('yes', 'on', 'true'):
        return True
    elif value.lower() in ('no', 'off', 'false'):
        return False
    elif value.isdigit():
        return bool(int(value))
    raise ValueError(
        "{name}: ambiguous boolean value: {value}".format(
            name=name, value=value))


def _check_int(name, value):
    """Check for integer value."""
    if value.isdigit():
        return int(value)
    raise ValueError("{name}: not an integer value: {value}".format(
            name=name, value=value))


def mode(arg):
    import ly.lex
    if arg is not None and arg not in ly.lex.modes:
        raise ValueError("unknown mode: {mode}".format(mode=arg))
    return mode


def in_place(arg):
    return _check_bool("in-place", arg)


def encoding(arg):
    import codecs
    try:
        codecs.lookup(arg)
    except LookupError:
        raise ValueError("encoding: unknown encoding: {encoding}".format(
            encoding=encoding))
    return arg


def output_encoding(arg):
    if arg:
        import codecs
        try:
            codecs.lookup(arg)
        except LookupError:
            raise ValueError("output-encoding: unknown encoding: {encoding}".format(
                encoding=encoding))
        return arg
    return None


def output(arg):
    return arg or None


def replace_pattern(arg):
    return _check_bool("replace-pattern", arg)


def backup_suffix(arg):
    if "/" in arg:
        raise ValueError("/ not allowed in backup-suffix")


def with_filename(arg):
    if arg:
        return _check_bool("with-filename", arg)
    return None


def default_language(arg):
    import ly.pitch
    if arg:
        if arg not in ly.pitch.pitchInfo:
            raise ValueError("unknown pitch language: {language}".format(
                language=arg))
        return arg
    return "nederlands"


def rel_startpitch(arg):
    return _check_bool("rel-startpitch", arg)


def rel_absolute(arg):
    return _check_bool("rel-absolute", arg)


def indent_width(arg):
    return _check_int("indent-width", arg)


def indent_tabs(arg):
    return _check_bool("indent-tabs", arg)


def tab_width(arg):
    return _check_int("tab-width", arg)


def inline_style(arg):
    return _check_bool("inline-style", arg)


def full_html(arg):
    return _check_bool("full_html", arg)


def stylesheet(arg):
    return arg or None


def number_lines(arg):
    return _check_bool("number-lines", arg)


def wrapper_tag(arg):
    if not arg in ['div', 'pre', 'code', 'id']:
        raise ValueError("unknown wrapper tag: {tag}".format(
            tag=arg))
    return arg


def wrapper_attribute(arg):
    if not arg in ['id', 'class']:
        raise ValueError("wrapper attribute must be 'id' or 'class', found {attr}".format(
            attr=arg))
    return arg

    
def document_id(arg):
    return arg or None


def linenumbers_id(arg):
    return arg or None
python_ly-0.9.9/ly/data/Makefile0000644000000000000000000000043413615410400013474 0ustar00# MakeFile

all: _lilypond_data.py _scheme_data.py

# Set your LILYPOND environment variable before running make.
# export LILYPOND=/path/to/bin/lilypond
_lilypond_data.py: getdata.ly
	$(LILYPOND) -dno-print-pages $< > $@

_scheme_data.py: makeschemedata.py
	python makeschemedata.py
python_ly-0.9.9/ly/data/__init__.py0000644000000000000000000000725313615410400014153 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2011 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Query functions to get data from the LilyPond-generated _data.py module.
"""

def grob_properties(grob):
    """Returns the list of properties the named grob supports."""
    from . import _data
    return sorted(set(prop
        for iface in _data.grobs.get(grob, [])
        for prop in _data.interfaces[iface]))

def grob_properties_with_interface(grob):
    """Returns a list of two-tuples (property, interface)."""
    from . import _data
    return sorted(
        (prop, iface)
        for iface in _data.grobs.get(grob, [])
        for prop in _data.interfaces[iface])

def grob_interfaces(grob, prop=None):
    """Returns the list of interfaces a grob supports.
    
    If prop is given, only returns the interfaces that define prop.
    
    """
    from . import _data
    ifaces = _data.grobs.get(grob, [])
    if prop is None:
        return ifaces
    return [iface for iface in ifaces
            if prop in grob_interface_properties(iface)]

def grob_interface_properties(iface):
    """Returns the list of properties an interface supports."""
    from . import _data
    return _data.interfaces.get(iface, [])

def grob_interfaces_for_property(prop):
    """Returns the list of interfaces that define the property.
    
    Most times returns one, but several interface names may be returned.
    
    """
    from . import _data
    return [iface
        for iface, props in _data.interfaces.items()
        if prop in props]

def grobs():
    """Returns the sorted list of all grob names."""
    from . import _data
    return sorted(_data.grobs.keys())
    
def all_grob_properties():
    """Returns the list of all properties."""
    from . import _data
    return sorted(set(sum(_data.interfaces.values(), [])))

def context_properties():
    """Returns the list of context properties."""
    from . import _data
    return _data.contextproperties

def engravers():
    """Returns the list of engravers and performers."""
    from . import _data
    return _data.engravers

def music_glyphs():
    """Returns the list of glyphs in the emmentaler font."""
    from . import _data
    return _data.musicglyphs

def scheme_keywords():
    """Returns the list of guile keywords."""
    from . import _data
    return _data.scheme_keywords

def scheme_functions():
    """Returns the list of scheme functions."""
    from . import _data
    return _data.scheme_functions

def scheme_variables():
    """Returns the list of scheme variables."""
    from . import _data
    return _data.scheme_variables

def scheme_constants():
    """Returns the list of scheme constants."""
    from . import _data
    return _data.scheme_constants

def all_scheme_words():
    """Returns the list of all scheme words."""
    from . import _data
    return _data.scheme_keywords + _data.scheme_functions \
        + _data.scheme_variables + _data.scheme_constants
python_ly-0.9.9/ly/data/_data.py0000644000000000000000000000220713615410400013456 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2011 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Load the LilyPond-generated data, and add some missing things.
"""

from ._lilypond_data import *
from ._scheme_data import *

# BarLine #'bar-extent
if "bar-extent" not in interfaces["bar-line-interface"]:
    interfaces["bar-line-interface"].insert(1, "bar-extent")


python_ly-0.9.9/ly/data/_lilypond_data.py0000644000000000000000000024052613615410400015400 0ustar00# generated by LilyPond 2.24.0

version = "2.24.0"

interfaces = {
    "accidental-interface": [
        "alteration",
        "alteration-glyph-name-alist",
        "avoid-slur",
        "glyph-name",
        "hide-tied-accidental-after-break",
        "restore-first",
    ],
    "accidental-placement-interface": [
        "direction",
        "padding",
        "positioning-done",
        "right-padding",
        "script-priority",
    ],
    "accidental-suggestion-interface": [],
    "accidental-switch-interface": [
        "alteration-glyph-name-alist",
    ],
    "align-interface": [
        "align-dir",
        "axes",
        "padding",
        "positioning-done",
        "stacking-dir",
    ],
    "ambitus-interface": [
        "gap",
        "length-fraction",
        "maximum-gap",
        "thickness",
    ],
    "arpeggio-interface": [
        "arpeggio-direction",
        "dash-definition",
        "line-thickness",
        "positions",
        "protrusion",
        "script-priority",
        "thickness",
    ],
    "axis-group-interface": [
        "axes",
        "default-staff-staff-spacing",
        "nonstaff-nonstaff-spacing",
        "nonstaff-relatedstaff-spacing",
        "nonstaff-unrelatedstaff-spacing",
        "staff-affinity",
        "staff-staff-spacing",
    ],
    "balloon-interface": [
        "X-attachment",
        "Y-attachment",
        "annotation-balloon",
        "annotation-line",
        "padding",
        "text",
        "text-alignment-X",
        "text-alignment-Y",
        "thickness",
    ],
    "bar-line-interface": [
        "allow-span-bar",
        "bar-extent",
        "gap",
        "glyph",
        "glyph-left",
        "glyph-name",
        "glyph-right",
        "hair-thickness",
        "kern",
        "rounded",
        "segno-kern",
        "thick-thickness",
    ],
    "bar-number-interface": [],
    "bass-figure-alignment-interface": [],
    "bass-figure-interface": [
        "implicit",
    ],
    "beam-interface": [
        "X-positions",
        "auto-knee-gap",
        "beam-thickness",
        "beamed-stem-shorten",
        "beaming",
        "break-overshoot",
        "clip-edges",
        "collision-interfaces",
        "collision-voice-only",
        "concaveness",
        "damping",
        "details",
        "direction",
        "gap",
        "gap-count",
        "grow-direction",
        "inspect-quants",
        "knee",
        "length-fraction",
        "neutral-direction",
        "positions",
        "skip-quanting",
    ],
    "bend-after-interface": [
        "thickness",
    ],
    "bend-interface": [
        "bend-me",
        "details",
        "direction",
        "style",
    ],
    "bezier-curve-interface": [
        "show-control-points",
    ],
    "break-alignable-interface": [
        "break-align-symbols",
        "non-break-align-symbols",
    ],
    "break-aligned-interface": [
        "break-align-anchor",
        "break-align-anchor-alignment",
        "break-align-symbol",
        "space-alist",
    ],
    "break-alignment-interface": [
        "break-align-orders",
        "positioning-done",
    ],
    "breathing-sign-interface": [
        "direction",
        "thickness",
    ],
    "caesura-script-interface": [],
    "centered-bar-number-interface": [],
    "centered-bar-number-line-spanner-interface": [],
    "centered-spanner-interface": [
        "self-alignment-X",
        "spacing-pair",
    ],
    "chord-name-interface": [],
    "chord-square-interface": [
        "measure-division",
        "measure-division-chord-placement-alist",
        "measure-division-lines-alist",
    ],
    "clef-interface": [
        "full-size-change",
        "glyph",
        "glyph-name",
        "non-default",
    ],
    "clef-modifier-interface": [
        "clef-alignments",
    ],
    "cluster-beacon-interface": [
        "positions",
    ],
    "cluster-interface": [
        "padding",
        "style",
    ],
    "coda-mark-interface": [],
    "control-point-interface": [],
    "control-polygon-interface": [
        "extroversion",
        "filled",
    ],
    "custos-interface": [
        "neutral-direction",
        "neutral-position",
        "style",
    ],
    "dot-column-interface": [
        "chord-dots-limit",
        "direction",
        "padding",
        "positioning-done",
    ],
    "dots-interface": [
        "direction",
        "dot-count",
        "glyph-name",
        "style",
    ],
    "duration-line-interface": [
        "details",
    ],
    "dynamic-interface": [],
    "dynamic-line-spanner-interface": [
        "avoid-slur",
    ],
    "dynamic-text-interface": [
        "right-padding",
    ],
    "dynamic-text-spanner-interface": [
        "text",
    ],
    "enclosing-bracket-interface": [
        "bracket-flare",
        "dashed-edge",
        "edge-height",
        "padding",
        "shorten-pair",
        "thickness",
    ],
    "episema-interface": [],
    "figured-bass-continuation-interface": [
        "padding",
        "thickness",
    ],
    "finger-glide-interface": [
        "dash-fraction",
        "dash-period",
        "details",
        "style",
        "zigzag-length",
        "zigzag-width",
    ],
    "finger-interface": [],
    "fingering-column-interface": [
        "padding",
        "positioning-done",
        "snap-radius",
    ],
    "flag-interface": [
        "glyph-name",
        "stroke-style",
        "style",
    ],
    "font-interface": [
        "font-encoding",
        "font-family",
        "font-features",
        "font-name",
        "font-series",
        "font-shape",
        "font-size",
    ],
    "footnote-interface": [
        "automatically-numbered",
        "footnote",
        "footnote-text",
    ],
    "fret-diagram-interface": [
        "align-dir",
        "dot-placement-list",
        "fret-diagram-details",
        "size",
        "thickness",
    ],
    "glissando-interface": [],
    "grace-spacing-interface": [
        "common-shortest-duration",
    ],
    "gregorian-ligature-interface": [],
    "grid-chord-name-interface": [],
    "grid-line-interface": [
        "thickness",
    ],
    "grid-point-interface": [],
    "grob-interface": [
        "X-extent",
        "X-offset",
        "Y-extent",
        "Y-offset",
        "after-line-breaking",
        "avoid-slur",
        "before-line-breaking",
        "color",
        "cross-staff",
        "extra-offset",
        "footnote-music",
        "forced-spacing",
        "horizontal-skylines",
        "id",
        "layer",
        "minimum-X-extent",
        "minimum-Y-extent",
        "output-attributes",
        "parenthesis-friends",
        "parenthesis-id",
        "parenthesized",
        "rotation",
        "show-horizontal-skylines",
        "show-vertical-skylines",
        "skyline-horizontal-padding",
        "springs-and-rods",
        "stencil",
        "transparent",
        "vertical-skylines",
        "whiteout",
        "whiteout-style",
    ],
    "hairpin-interface": [
        "bound-padding",
        "broken-bound-padding",
        "circled-tip",
        "endpoint-alignments",
        "grow-direction",
        "height",
        "shorten-pair",
    ],
    "hara-kiri-group-spanner-interface": [
        "remove-empty",
        "remove-first",
        "remove-layer",
    ],
    "horizontal-bracket-interface": [
        "bracket-flare",
        "connect-to-neighbor",
        "dashed-edge",
        "edge-height",
        "shorten-pair",
    ],
    "horizontal-bracket-text-interface": [],
    "horizontal-line-spanner-interface": [],
    "inline-accidental-interface": [],
    "instrument-specific-markup-interface": [
        "fret-diagram-details",
        "graphical",
        "harp-pedal-details",
        "size",
        "thickness",
        "woodwind-diagram-details",
    ],
    "item-interface": [
        "break-visibility",
        "extra-spacing-height",
        "extra-spacing-width",
        "non-musical",
    ],
    "jump-script-interface": [],
    "key-cancellation-interface": [],
    "key-signature-interface": [
        "alteration-alist",
        "alteration-glyph-name-alist",
        "flat-positions",
        "non-default",
        "padding",
        "padding-pairs",
        "sharp-positions",
    ],
    "kievan-ligature-interface": [
        "padding",
    ],
    "ledger-line-spanner-interface": [
        "gap",
        "length-fraction",
        "minimum-length-fraction",
    ],
    "ledgered-interface": [
        "no-ledgers",
    ],
    "ligature-bracket-interface": [
        "height",
        "thickness",
        "width",
    ],
    "ligature-head-interface": [],
    "ligature-interface": [],
    "line-interface": [
        "arrow-length",
        "arrow-width",
        "dash-fraction",
        "dash-period",
        "style",
        "thickness",
        "zigzag-length",
        "zigzag-width",
    ],
    "line-spanner-interface": [
        "bound-details",
        "extra-dy",
        "gap",
        "left-bound-info",
        "right-bound-info",
        "thickness",
        "to-barline",
    ],
    "lyric-extender-interface": [
        "left-padding",
        "next",
        "right-padding",
        "thickness",
    ],
    "lyric-hyphen-interface": [
        "dash-period",
        "height",
        "length",
        "minimum-distance",
        "minimum-length",
        "padding",
        "thickness",
    ],
    "lyric-interface": [],
    "lyric-repeat-count-interface": [],
    "lyric-space-interface": [],
    "lyric-syllable-interface": [],
    "mark-interface": [],
    "measure-counter-interface": [
        "count-from",
        "left-number-text",
        "number-range-separator",
        "right-number-text",
    ],
    "measure-grouping-interface": [
        "height",
        "style",
        "thickness",
    ],
    "measure-spanner-interface": [
        "bracket-flare",
        "bracket-visibility",
        "connect-to-neighbor",
        "direction",
        "edge-height",
        "padding",
        "shorten-pair",
        "spacing-pair",
        "staff-padding",
        "thickness",
    ],
    "melody-spanner-interface": [
        "neutral-direction",
    ],
    "mensural-ligature-interface": [
        "thickness",
    ],
    "metronome-mark-interface": [],
    "multi-measure-interface": [
        "bound-padding",
    ],
    "multi-measure-rest-interface": [
        "bound-padding",
        "expand-limit",
        "hair-thickness",
        "max-symbol-separation",
        "measure-count",
        "minimum-length",
        "round-up-exceptions",
        "round-up-to-longer-rest",
        "spacing-pair",
        "thick-thickness",
        "usable-duration-logs",
    ],
    "multi-measure-rest-number-interface": [],
    "musical-paper-column-interface": [
        "shortest-playing-duration",
        "shortest-starter-duration",
    ],
    "non-musical-paper-column-interface": [
        "between-cols",
        "full-measure-extra-space",
        "line-break-penalty",
        "line-break-permission",
        "line-break-system-details",
        "page-break-penalty",
        "page-break-permission",
        "page-turn-penalty",
        "page-turn-permission",
    ],
    "note-collision-interface": [
        "fa-merge-direction",
        "merge-differently-dotted",
        "merge-differently-headed",
        "note-collision-threshold",
        "positioning-done",
        "prefer-dotted-right",
    ],
    "note-column-interface": [
        "force-hshift",
        "glissando-skip",
        "horizontal-shift",
        "ignore-collision",
        "main-extent",
    ],
    "note-head-interface": [
        "duration-log",
        "glyph-name",
        "ignore-ambitus",
        "ledger-positions",
        "note-names",
        "stem-attachment",
        "style",
    ],
    "note-name-interface": [],
    "note-spacing-interface": [
        "knee-spacing-correction",
        "same-direction-correction",
        "space-to-barline",
        "stem-spacing-correction",
    ],
    "number-interface": [
        "number-type",
    ],
    "ottava-bracket-interface": [
        "bracket-flare",
        "dashed-edge",
        "edge-height",
        "minimum-length",
        "shorten-pair",
    ],
    "outside-staff-axis-group-interface": [
        "outside-staff-placement-directive",
    ],
    "outside-staff-interface": [
        "outside-staff-horizontal-padding",
        "outside-staff-padding",
        "outside-staff-priority",
    ],
    "paper-column-interface": [
        "labels",
        "rhythmic-location",
        "used",
        "when",
    ],
    "parentheses-interface": [
        "padding",
        "stencils",
    ],
    "percent-repeat-interface": [
        "dot-negative-kern",
        "slash-negative-kern",
        "slope",
        "thickness",
    ],
    "piano-pedal-bracket-interface": [
        "bound-padding",
        "bracket-flare",
        "dashed-edge",
        "edge-height",
        "shorten-pair",
    ],
    "piano-pedal-interface": [],
    "piano-pedal-script-interface": [],
    "pitched-trill-interface": [],
    "pure-from-neighbor-interface": [],
    "rehearsal-mark-interface": [],
    "rest-collision-interface": [
        "minimum-distance",
        "positioning-done",
    ],
    "rest-interface": [
        "direction",
        "minimum-distance",
        "style",
        "voiced-position",
    ],
    "rhythmic-grob-interface": [],
    "rhythmic-head-interface": [
        "duration-log",
        "glissando-skip",
    ],
    "script-column-interface": [],
    "script-interface": [
        "avoid-slur",
        "positioning-done",
        "script-priority",
        "side-relative-direction",
        "slur-padding",
        "toward-stem-shift",
        "toward-stem-shift-in-column",
    ],
    "section-label-interface": [],
    "segno-mark-interface": [],
    "self-alignment-interface": [
        "X-align-on-main-noteheads",
        "parent-alignment-X",
        "parent-alignment-Y",
        "self-alignment-X",
        "self-alignment-Y",
    ],
    "semi-tie-column-interface": [
        "head-direction",
        "positioning-done",
        "tie-configuration",
    ],
    "semi-tie-interface": [
        "control-points",
        "details",
        "direction",
        "head-direction",
        "line-thickness",
        "thickness",
    ],
    "separation-item-interface": [
        "X-extent",
        "horizontal-skylines",
        "padding",
        "skyline-vertical-padding",
    ],
    "side-position-interface": [
        "add-stem-support",
        "direction",
        "horizon-padding",
        "minimum-space",
        "padding",
        "side-axis",
        "slur-padding",
        "staff-padding",
        "use-skylines",
    ],
    "signum-repetitionis-interface": [
        "allow-span-bar",
        "bar-extent",
        "gap",
        "glyph",
        "glyph-name",
        "hair-thickness",
        "kern",
        "rounded",
        "segno-kern",
        "thick-thickness",
    ],
    "slur-interface": [
        "avoid-slur",
        "control-points",
        "dash-definition",
        "details",
        "direction",
        "eccentricity",
        "height-limit",
        "inspect-quants",
        "line-thickness",
        "positions",
        "ratio",
        "thickness",
    ],
    "spaceable-grob-interface": [
        "allow-loose-spacing",
        "keep-inside-line",
        "measure-length",
    ],
    "spacing-interface": [],
    "spacing-options-interface": [
        "shortest-duration-space",
        "spacing-increment",
    ],
    "spacing-spanner-interface": [
        "average-spacing-wishes",
        "base-shortest-duration",
        "common-shortest-duration",
        "packed-spacing",
        "shortest-duration-space",
        "spacing-increment",
        "strict-grace-spacing",
        "strict-note-spacing",
        "uniform-stretching",
    ],
    "span-bar-interface": [
        "glyph-name",
    ],
    "spanner-interface": [
        "minimum-length",
        "minimum-length-after-break",
        "normalized-endpoints",
        "spanner-id",
        "to-barline",
    ],
    "staff-grouper-interface": [
        "staff-staff-spacing",
        "staffgroup-staff-spacing",
    ],
    "staff-highlight-interface": [
        "bound-prefatory-paddings",
        "shorten-pair",
    ],
    "staff-spacing-interface": [
        "stem-spacing-correction",
    ],
    "staff-symbol-interface": [
        "break-align-symbols",
        "ledger-extra",
        "ledger-line-thickness",
        "ledger-positions",
        "ledger-positions-function",
        "line-count",
        "line-positions",
        "staff-space",
        "thickness",
        "widened-extent",
        "width",
    ],
    "staff-symbol-referencer-interface": [
        "staff-position",
    ],
    "stanza-number-interface": [],
    "stem-interface": [
        "avoid-note-head",
        "beaming",
        "beamlet-default-length",
        "beamlet-max-length-proportion",
        "default-direction",
        "details",
        "direction",
        "double-stem-separation",
        "duration-log",
        "french-beaming",
        "length",
        "length-fraction",
        "max-beam-connect",
        "neutral-direction",
        "no-stem-extend",
        "note-collision-threshold",
        "positioning-done",
        "stem-begin-position",
        "stemlet-length",
        "thickness",
    ],
    "stem-tremolo-interface": [
        "beam-thickness",
        "beam-width",
        "direction",
        "flag-count",
        "length-fraction",
        "shape",
        "slope",
    ],
    "sticky-grob-interface": [],
    "string-number-interface": [],
    "stroke-finger-interface": [
        "digit-names",
    ],
    "system-interface": [
        "labels",
        "page-number",
        "rank-on-page",
    ],
    "system-start-delimiter-interface": [
        "collapse-height",
        "style",
        "thickness",
    ],
    "system-start-text-interface": [
        "long-text",
        "self-alignment-X",
        "self-alignment-Y",
        "text",
    ],
    "tab-note-head-interface": [
        "details",
    ],
    "text-interface": [
        "baseline-skip",
        "flag-style",
        "replacement-alist",
        "text",
        "text-direction",
        "word-space",
    ],
    "text-mark-interface": [],
    "text-script-interface": [
        "avoid-slur",
        "script-priority",
    ],
    "tie-column-interface": [
        "positioning-done",
        "tie-configuration",
    ],
    "tie-interface": [
        "avoid-slur",
        "control-points",
        "dash-definition",
        "details",
        "direction",
        "head-direction",
        "line-thickness",
        "neutral-direction",
        "staff-position",
        "thickness",
    ],
    "time-signature-interface": [
        "fraction",
        "style",
    ],
    "trill-pitch-accidental-interface": [],
    "trill-spanner-interface": [],
    "tuplet-bracket-interface": [
        "X-positions",
        "avoid-scripts",
        "bracket-flare",
        "bracket-visibility",
        "break-overshoot",
        "connect-to-neighbor",
        "dashed-edge",
        "direction",
        "edge-height",
        "edge-text",
        "full-length-padding",
        "full-length-to-extent",
        "gap",
        "padding",
        "positions",
        "shorten-pair",
        "staff-padding",
        "thickness",
        "tuplet-slur",
        "visible-over-note-heads",
    ],
    "tuplet-number-interface": [
        "avoid-slur",
        "direction",
        "knee-to-beam",
    ],
    "unbreakable-spanner-interface": [
        "breakable",
    ],
    "vaticana-ligature-interface": [
        "glyph-name",
        "thickness",
    ],
    "volta-bracket-interface": [
        "dashed-edge",
        "height",
        "shorten-pair",
        "thickness",
    ],
    "volta-interface": [],
}


grobs = {
    "Accidental": [
        "accidental-interface",
        "accidental-switch-interface",
        "font-interface",
        "grob-interface",
        "inline-accidental-interface",
        "item-interface",
    ],
    "AccidentalCautionary": [
        "accidental-interface",
        "accidental-switch-interface",
        "font-interface",
        "grob-interface",
        "inline-accidental-interface",
        "item-interface",
    ],
    "AccidentalPlacement": [
        "accidental-placement-interface",
        "grob-interface",
        "item-interface",
    ],
    "AccidentalSuggestion": [
        "accidental-interface",
        "accidental-suggestion-interface",
        "accidental-switch-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "script-interface",
        "self-alignment-interface",
        "side-position-interface",
    ],
    "Ambitus": [
        "ambitus-interface",
        "axis-group-interface",
        "break-aligned-interface",
        "grob-interface",
        "item-interface",
    ],
    "AmbitusAccidental": [
        "accidental-interface",
        "accidental-switch-interface",
        "break-aligned-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
    ],
    "AmbitusLine": [
        "ambitus-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
    ],
    "AmbitusNoteHead": [
        "ambitus-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "ledgered-interface",
        "note-head-interface",
        "rhythmic-head-interface",
        "staff-symbol-referencer-interface",
    ],
    "Arpeggio": [
        "arpeggio-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "side-position-interface",
        "staff-symbol-referencer-interface",
    ],
    "BalloonText": [
        "accidental-switch-interface",
        "balloon-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "spanner-interface",
        "sticky-grob-interface",
        "text-interface",
    ],
    "BarLine": [
        "bar-line-interface",
        "break-aligned-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "pure-from-neighbor-interface",
    ],
    "BarNumber": [
        "bar-number-interface",
        "break-alignable-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "text-interface",
    ],
    "BassFigure": [
        "accidental-switch-interface",
        "bass-figure-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "rhythmic-grob-interface",
        "text-interface",
    ],
    "BassFigureAlignment": [
        "align-interface",
        "axis-group-interface",
        "bass-figure-alignment-interface",
        "grob-interface",
        "spanner-interface",
    ],
    "BassFigureAlignmentPositioning": [
        "axis-group-interface",
        "grob-interface",
        "outside-staff-interface",
        "side-position-interface",
        "spanner-interface",
    ],
    "BassFigureBracket": [
        "enclosing-bracket-interface",
        "grob-interface",
        "item-interface",
    ],
    "BassFigureContinuation": [
        "figured-bass-continuation-interface",
        "grob-interface",
        "spanner-interface",
    ],
    "BassFigureLine": [
        "axis-group-interface",
        "grob-interface",
        "outside-staff-axis-group-interface",
        "spanner-interface",
    ],
    "Beam": [
        "beam-interface",
        "grob-interface",
        "spanner-interface",
        "staff-symbol-referencer-interface",
        "unbreakable-spanner-interface",
    ],
    "BendAfter": [
        "bend-after-interface",
        "grob-interface",
        "spanner-interface",
    ],
    "BendSpanner": [
        "bend-interface",
        "font-interface",
        "grob-interface",
        "line-spanner-interface",
        "outside-staff-interface",
        "spanner-interface",
        "text-interface",
        "text-script-interface",
    ],
    "BreakAlignGroup": [
        "axis-group-interface",
        "break-aligned-interface",
        "grob-interface",
        "item-interface",
    ],
    "BreakAlignment": [
        "axis-group-interface",
        "break-alignment-interface",
        "grob-interface",
        "item-interface",
    ],
    "BreathingSign": [
        "break-aligned-interface",
        "breathing-sign-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "text-interface",
    ],
    "CaesuraScript": [
        "caesura-script-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "script-interface",
        "self-alignment-interface",
        "side-position-interface",
    ],
    "CenteredBarNumber": [
        "bar-number-interface",
        "centered-bar-number-interface",
        "centered-spanner-interface",
        "font-interface",
        "grob-interface",
        "spanner-interface",
        "text-interface",
    ],
    "CenteredBarNumberLineSpanner": [
        "axis-group-interface",
        "bar-number-interface",
        "centered-bar-number-line-spanner-interface",
        "grob-interface",
        "outside-staff-interface",
        "side-position-interface",
        "spanner-interface",
    ],
    "ChordName": [
        "accidental-switch-interface",
        "chord-name-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "rhythmic-grob-interface",
        "text-interface",
    ],
    "ChordSquare": [
        "chord-square-interface",
        "grob-interface",
        "line-interface",
        "spanner-interface",
    ],
    "Clef": [
        "break-aligned-interface",
        "clef-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "pure-from-neighbor-interface",
        "staff-symbol-referencer-interface",
    ],
    "ClefModifier": [
        "clef-modifier-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "text-interface",
    ],
    "ClusterSpanner": [
        "cluster-interface",
        "grob-interface",
        "spanner-interface",
    ],
    "ClusterSpannerBeacon": [
        "cluster-beacon-interface",
        "grob-interface",
        "item-interface",
        "rhythmic-grob-interface",
    ],
    "CodaMark": [
        "break-alignable-interface",
        "coda-mark-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "mark-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "text-interface",
    ],
    "CombineTextScript": [
        "accidental-switch-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "text-interface",
        "text-script-interface",
    ],
    "ControlPoint": [
        "control-point-interface",
        "grob-interface",
        "item-interface",
        "spanner-interface",
        "sticky-grob-interface",
        "text-interface",
    ],
    "ControlPolygon": [
        "control-polygon-interface",
        "grob-interface",
        "item-interface",
        "spanner-interface",
        "sticky-grob-interface",
        "text-interface",
    ],
    "CueClef": [
        "break-aligned-interface",
        "clef-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "pure-from-neighbor-interface",
        "staff-symbol-referencer-interface",
    ],
    "CueEndClef": [
        "break-aligned-interface",
        "clef-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "pure-from-neighbor-interface",
        "staff-symbol-referencer-interface",
    ],
    "Custos": [
        "break-aligned-interface",
        "custos-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "staff-symbol-referencer-interface",
    ],
    "Divisio": [
        "break-aligned-interface",
        "breathing-sign-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "text-interface",
    ],
    "DotColumn": [
        "axis-group-interface",
        "dot-column-interface",
        "grob-interface",
        "item-interface",
    ],
    "Dots": [
        "dots-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "staff-symbol-referencer-interface",
    ],
    "DoublePercentRepeat": [
        "break-aligned-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "percent-repeat-interface",
    ],
    "DoublePercentRepeatCounter": [
        "font-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "text-interface",
    ],
    "DoubleRepeatSlash": [
        "font-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "percent-repeat-interface",
        "rhythmic-grob-interface",
    ],
    "DurationLine": [
        "duration-line-interface",
        "font-interface",
        "grob-interface",
        "horizontal-line-spanner-interface",
        "line-interface",
        "line-spanner-interface",
        "spanner-interface",
        "unbreakable-spanner-interface",
    ],
    "DynamicLineSpanner": [
        "axis-group-interface",
        "dynamic-interface",
        "dynamic-line-spanner-interface",
        "grob-interface",
        "outside-staff-interface",
        "side-position-interface",
        "spanner-interface",
    ],
    "DynamicText": [
        "dynamic-interface",
        "dynamic-text-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "script-interface",
        "self-alignment-interface",
        "text-interface",
    ],
    "DynamicTextSpanner": [
        "dynamic-interface",
        "dynamic-text-spanner-interface",
        "font-interface",
        "grob-interface",
        "horizontal-line-spanner-interface",
        "line-interface",
        "line-spanner-interface",
        "spanner-interface",
        "text-interface",
    ],
    "Episema": [
        "episema-interface",
        "font-interface",
        "grob-interface",
        "horizontal-line-spanner-interface",
        "line-interface",
        "line-spanner-interface",
        "side-position-interface",
        "spanner-interface",
    ],
    "FingerGlideSpanner": [
        "finger-glide-interface",
        "grob-interface",
        "line-spanner-interface",
        "spanner-interface",
    ],
    "Fingering": [
        "finger-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "text-interface",
        "text-script-interface",
    ],
    "FingeringColumn": [
        "fingering-column-interface",
        "grob-interface",
        "item-interface",
    ],
    "Flag": [
        "flag-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
    ],
    "Footnote": [
        "balloon-interface",
        "font-interface",
        "footnote-interface",
        "grob-interface",
        "item-interface",
        "spanner-interface",
        "sticky-grob-interface",
        "text-interface",
    ],
    "FretBoard": [
        "chord-name-interface",
        "font-interface",
        "fret-diagram-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "rhythmic-grob-interface",
    ],
    "Glissando": [
        "glissando-interface",
        "grob-interface",
        "line-interface",
        "line-spanner-interface",
        "spanner-interface",
        "unbreakable-spanner-interface",
    ],
    "GraceSpacing": [
        "grace-spacing-interface",
        "grob-interface",
        "spacing-options-interface",
        "spanner-interface",
    ],
    "GridChordName": [
        "accidental-switch-interface",
        "font-interface",
        "grid-chord-name-interface",
        "grob-interface",
        "spanner-interface",
        "text-interface",
    ],
    "GridLine": [
        "grid-line-interface",
        "grob-interface",
        "item-interface",
        "self-alignment-interface",
    ],
    "GridPoint": [
        "grid-point-interface",
        "grob-interface",
        "item-interface",
    ],
    "Hairpin": [
        "dynamic-interface",
        "grob-interface",
        "hairpin-interface",
        "line-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "spanner-interface",
    ],
    "HorizontalBracket": [
        "grob-interface",
        "horizontal-bracket-interface",
        "line-interface",
        "outside-staff-interface",
        "side-position-interface",
        "spanner-interface",
    ],
    "HorizontalBracketText": [
        "accidental-switch-interface",
        "font-interface",
        "grob-interface",
        "horizontal-bracket-text-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "spanner-interface",
        "text-interface",
    ],
    "InstrumentName": [
        "accidental-switch-interface",
        "font-interface",
        "grob-interface",
        "self-alignment-interface",
        "side-position-interface",
        "spanner-interface",
        "system-start-text-interface",
        "text-interface",
    ],
    "InstrumentSwitch": [
        "accidental-switch-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "text-interface",
    ],
    "JumpScript": [
        "break-alignable-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "jump-script-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "text-interface",
    ],
    "KeyCancellation": [
        "accidental-switch-interface",
        "break-aligned-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "key-cancellation-interface",
        "key-signature-interface",
        "pure-from-neighbor-interface",
        "staff-symbol-referencer-interface",
    ],
    "KeySignature": [
        "accidental-switch-interface",
        "break-aligned-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "key-signature-interface",
        "pure-from-neighbor-interface",
        "staff-symbol-referencer-interface",
    ],
    "KievanLigature": [
        "font-interface",
        "grob-interface",
        "kievan-ligature-interface",
        "spanner-interface",
    ],
    "LaissezVibrerTie": [
        "bezier-curve-interface",
        "grob-interface",
        "item-interface",
        "semi-tie-interface",
        "tie-interface",
    ],
    "LaissezVibrerTieColumn": [
        "grob-interface",
        "item-interface",
        "semi-tie-column-interface",
    ],
    "LedgerLineSpanner": [
        "grob-interface",
        "ledger-line-spanner-interface",
        "spanner-interface",
    ],
    "LeftEdge": [
        "break-aligned-interface",
        "grob-interface",
        "item-interface",
    ],
    "LigatureBracket": [
        "grob-interface",
        "line-interface",
        "spanner-interface",
        "tuplet-bracket-interface",
    ],
    "LyricExtender": [
        "grob-interface",
        "lyric-extender-interface",
        "lyric-interface",
        "spanner-interface",
    ],
    "LyricHyphen": [
        "font-interface",
        "grob-interface",
        "lyric-hyphen-interface",
        "lyric-interface",
        "spanner-interface",
    ],
    "LyricRepeatCount": [
        "break-alignable-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "lyric-interface",
        "lyric-repeat-count-interface",
        "self-alignment-interface",
        "text-interface",
    ],
    "LyricSpace": [
        "grob-interface",
        "lyric-hyphen-interface",
        "lyric-space-interface",
        "spanner-interface",
    ],
    "LyricText": [
        "font-interface",
        "grob-interface",
        "item-interface",
        "lyric-syllable-interface",
        "rhythmic-grob-interface",
        "self-alignment-interface",
        "text-interface",
    ],
    "MeasureCounter": [
        "centered-spanner-interface",
        "font-interface",
        "grob-interface",
        "measure-counter-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "spanner-interface",
        "text-interface",
    ],
    "MeasureGrouping": [
        "grob-interface",
        "measure-grouping-interface",
        "outside-staff-interface",
        "side-position-interface",
        "spanner-interface",
    ],
    "MeasureSpanner": [
        "accidental-switch-interface",
        "font-interface",
        "grob-interface",
        "line-interface",
        "measure-spanner-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "spanner-interface",
        "text-interface",
    ],
    "MelodyItem": [
        "grob-interface",
        "item-interface",
        "melody-spanner-interface",
    ],
    "MensuralLigature": [
        "font-interface",
        "grob-interface",
        "mensural-ligature-interface",
        "spanner-interface",
    ],
    "MetronomeMark": [
        "break-alignable-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "metronome-mark-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "text-interface",
    ],
    "MultiMeasureRest": [
        "font-interface",
        "grob-interface",
        "multi-measure-interface",
        "multi-measure-rest-interface",
        "outside-staff-interface",
        "rest-interface",
        "spanner-interface",
        "staff-symbol-referencer-interface",
    ],
    "MultiMeasureRestNumber": [
        "font-interface",
        "grob-interface",
        "multi-measure-interface",
        "multi-measure-rest-number-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "spanner-interface",
        "text-interface",
    ],
    "MultiMeasureRestScript": [
        "font-interface",
        "grob-interface",
        "multi-measure-interface",
        "outside-staff-interface",
        "script-interface",
        "self-alignment-interface",
        "side-position-interface",
        "spanner-interface",
    ],
    "MultiMeasureRestText": [
        "font-interface",
        "grob-interface",
        "multi-measure-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "spanner-interface",
        "text-interface",
    ],
    "NonMusicalPaperColumn": [
        "axis-group-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "non-musical-paper-column-interface",
        "paper-column-interface",
        "separation-item-interface",
        "spaceable-grob-interface",
    ],
    "NoteCollision": [
        "axis-group-interface",
        "grob-interface",
        "item-interface",
        "note-collision-interface",
    ],
    "NoteColumn": [
        "axis-group-interface",
        "bend-interface",
        "grob-interface",
        "item-interface",
        "note-column-interface",
        "separation-item-interface",
    ],
    "NoteHead": [
        "bend-interface",
        "font-interface",
        "gregorian-ligature-interface",
        "grob-interface",
        "item-interface",
        "ledgered-interface",
        "ligature-head-interface",
        "mensural-ligature-interface",
        "note-head-interface",
        "rhythmic-grob-interface",
        "rhythmic-head-interface",
        "staff-symbol-referencer-interface",
        "vaticana-ligature-interface",
    ],
    "NoteName": [
        "accidental-switch-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "note-name-interface",
        "text-interface",
    ],
    "NoteSpacing": [
        "grob-interface",
        "item-interface",
        "note-spacing-interface",
        "spacing-interface",
    ],
    "OttavaBracket": [
        "font-interface",
        "grob-interface",
        "horizontal-bracket-interface",
        "line-interface",
        "ottava-bracket-interface",
        "outside-staff-interface",
        "side-position-interface",
        "spanner-interface",
        "text-interface",
    ],
    "PaperColumn": [
        "axis-group-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "musical-paper-column-interface",
        "paper-column-interface",
        "separation-item-interface",
        "spaceable-grob-interface",
    ],
    "Parentheses": [
        "font-interface",
        "grob-interface",
        "item-interface",
        "parentheses-interface",
        "spanner-interface",
        "sticky-grob-interface",
    ],
    "PercentRepeat": [
        "centered-spanner-interface",
        "font-interface",
        "grob-interface",
        "multi-measure-rest-interface",
        "percent-repeat-interface",
        "spanner-interface",
    ],
    "PercentRepeatCounter": [
        "font-interface",
        "grob-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "spanner-interface",
        "text-interface",
    ],
    "PhrasingSlur": [
        "bezier-curve-interface",
        "grob-interface",
        "outside-staff-interface",
        "slur-interface",
        "spanner-interface",
    ],
    "PianoPedalBracket": [
        "grob-interface",
        "line-interface",
        "piano-pedal-bracket-interface",
        "piano-pedal-interface",
        "spanner-interface",
    ],
    "RehearsalMark": [
        "accidental-switch-interface",
        "break-alignable-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "mark-interface",
        "outside-staff-interface",
        "rehearsal-mark-interface",
        "self-alignment-interface",
        "side-position-interface",
        "text-interface",
    ],
    "RepeatSlash": [
        "grob-interface",
        "item-interface",
        "percent-repeat-interface",
        "rhythmic-grob-interface",
    ],
    "RepeatTie": [
        "bezier-curve-interface",
        "grob-interface",
        "item-interface",
        "semi-tie-interface",
        "tie-interface",
    ],
    "RepeatTieColumn": [
        "grob-interface",
        "item-interface",
        "semi-tie-column-interface",
    ],
    "Rest": [
        "font-interface",
        "grob-interface",
        "item-interface",
        "rest-interface",
        "rhythmic-grob-interface",
        "rhythmic-head-interface",
        "staff-symbol-referencer-interface",
    ],
    "RestCollision": [
        "grob-interface",
        "item-interface",
        "rest-collision-interface",
    ],
    "Script": [
        "font-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "script-interface",
        "self-alignment-interface",
        "side-position-interface",
    ],
    "ScriptColumn": [
        "grob-interface",
        "item-interface",
        "script-column-interface",
    ],
    "ScriptRow": [
        "grob-interface",
        "item-interface",
        "script-column-interface",
    ],
    "SectionLabel": [
        "break-alignable-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "section-label-interface",
        "self-alignment-interface",
        "side-position-interface",
        "text-interface",
    ],
    "SegnoMark": [
        "break-alignable-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "mark-interface",
        "outside-staff-interface",
        "segno-mark-interface",
        "self-alignment-interface",
        "side-position-interface",
        "text-interface",
    ],
    "SignumRepetitionis": [
        "break-aligned-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "pure-from-neighbor-interface",
        "signum-repetitionis-interface",
    ],
    "Slur": [
        "bezier-curve-interface",
        "grob-interface",
        "outside-staff-interface",
        "slur-interface",
        "spanner-interface",
    ],
    "SostenutoPedal": [
        "font-interface",
        "grob-interface",
        "item-interface",
        "piano-pedal-script-interface",
        "self-alignment-interface",
        "text-interface",
    ],
    "SostenutoPedalLineSpanner": [
        "axis-group-interface",
        "grob-interface",
        "outside-staff-interface",
        "piano-pedal-interface",
        "side-position-interface",
        "spanner-interface",
    ],
    "SpacingSpanner": [
        "grob-interface",
        "spacing-options-interface",
        "spacing-spanner-interface",
        "spanner-interface",
    ],
    "SpanBar": [
        "bar-line-interface",
        "break-aligned-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "span-bar-interface",
    ],
    "SpanBarStub": [
        "grob-interface",
        "item-interface",
        "pure-from-neighbor-interface",
    ],
    "StaffEllipsis": [
        "break-aligned-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "text-interface",
    ],
    "StaffGrouper": [
        "grob-interface",
        "spanner-interface",
        "staff-grouper-interface",
    ],
    "StaffHighlight": [
        "grob-interface",
        "spanner-interface",
        "staff-highlight-interface",
    ],
    "StaffSpacing": [
        "grob-interface",
        "item-interface",
        "spacing-interface",
        "staff-spacing-interface",
    ],
    "StaffSymbol": [
        "grob-interface",
        "spanner-interface",
        "staff-symbol-interface",
    ],
    "StanzaNumber": [
        "font-interface",
        "grob-interface",
        "item-interface",
        "side-position-interface",
        "stanza-number-interface",
        "text-interface",
    ],
    "Stem": [
        "grob-interface",
        "item-interface",
        "stem-interface",
    ],
    "StemStub": [
        "grob-interface",
        "item-interface",
    ],
    "StemTremolo": [
        "grob-interface",
        "item-interface",
        "self-alignment-interface",
        "stem-tremolo-interface",
    ],
    "StringNumber": [
        "font-interface",
        "grob-interface",
        "item-interface",
        "number-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "string-number-interface",
        "text-interface",
        "text-script-interface",
    ],
    "StrokeFinger": [
        "font-interface",
        "grob-interface",
        "item-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "stroke-finger-interface",
        "text-interface",
        "text-script-interface",
    ],
    "SustainPedal": [
        "font-interface",
        "grob-interface",
        "item-interface",
        "piano-pedal-interface",
        "piano-pedal-script-interface",
        "self-alignment-interface",
        "text-interface",
    ],
    "SustainPedalLineSpanner": [
        "axis-group-interface",
        "grob-interface",
        "outside-staff-interface",
        "piano-pedal-interface",
        "side-position-interface",
        "spanner-interface",
    ],
    "System": [
        "axis-group-interface",
        "grob-interface",
        "outside-staff-axis-group-interface",
        "spanner-interface",
        "system-interface",
    ],
    "SystemStartBar": [
        "grob-interface",
        "side-position-interface",
        "spanner-interface",
        "system-start-delimiter-interface",
    ],
    "SystemStartBrace": [
        "font-interface",
        "grob-interface",
        "side-position-interface",
        "spanner-interface",
        "system-start-delimiter-interface",
    ],
    "SystemStartBracket": [
        "font-interface",
        "grob-interface",
        "side-position-interface",
        "spanner-interface",
        "system-start-delimiter-interface",
    ],
    "SystemStartSquare": [
        "font-interface",
        "grob-interface",
        "side-position-interface",
        "spanner-interface",
        "system-start-delimiter-interface",
    ],
    "TabNoteHead": [
        "bend-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "note-head-interface",
        "rhythmic-grob-interface",
        "rhythmic-head-interface",
        "staff-symbol-referencer-interface",
        "tab-note-head-interface",
        "text-interface",
    ],
    "TextMark": [
        "accidental-switch-interface",
        "break-alignable-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "mark-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "text-interface",
        "text-mark-interface",
    ],
    "TextScript": [
        "accidental-switch-interface",
        "font-interface",
        "grob-interface",
        "instrument-specific-markup-interface",
        "item-interface",
        "outside-staff-interface",
        "self-alignment-interface",
        "side-position-interface",
        "text-interface",
        "text-script-interface",
    ],
    "TextSpanner": [
        "font-interface",
        "grob-interface",
        "horizontal-line-spanner-interface",
        "line-interface",
        "line-spanner-interface",
        "outside-staff-interface",
        "side-position-interface",
        "spanner-interface",
    ],
    "Tie": [
        "bezier-curve-interface",
        "grob-interface",
        "spanner-interface",
        "tie-interface",
    ],
    "TieColumn": [
        "grob-interface",
        "spanner-interface",
        "tie-column-interface",
    ],
    "TimeSignature": [
        "break-aligned-interface",
        "font-interface",
        "grob-interface",
        "item-interface",
        "pure-from-neighbor-interface",
        "time-signature-interface",
    ],
    "TrillPitchAccidental": [
        "accidental-interface",
        "accidental-switch-interface",
        "font-interface",
        "grob-interface",
        "inline-accidental-interface",
        "item-interface",
        "side-position-interface",
        "trill-pitch-accidental-interface",
    ],
    "TrillPitchGroup": [
        "axis-group-interface",
        "grob-interface",
        "item-interface",
        "side-position-interface",
    ],
    "TrillPitchHead": [
        "font-interface",
        "grob-interface",
        "item-interface",
        "ledgered-interface",
        "pitched-trill-interface",
        "rhythmic-head-interface",
        "staff-symbol-referencer-interface",
    ],
    "TrillPitchParentheses": [
        "font-interface",
        "grob-interface",
        "item-interface",
        "parentheses-interface",
        "pitched-trill-interface",
    ],
    "TrillSpanner": [
        "font-interface",
        "grob-interface",
        "horizontal-line-spanner-interface",
        "line-interface",
        "line-spanner-interface",
        "outside-staff-interface",
        "side-position-interface",
        "spanner-interface",
        "trill-spanner-interface",
    ],
    "TupletBracket": [
        "grob-interface",
        "line-interface",
        "outside-staff-interface",
        "spanner-interface",
        "tuplet-bracket-interface",
    ],
    "TupletNumber": [
        "font-interface",
        "grob-interface",
        "outside-staff-interface",
        "spanner-interface",
        "text-interface",
        "tuplet-number-interface",
    ],
    "UnaCordaPedal": [
        "font-interface",
        "grob-interface",
        "item-interface",
        "piano-pedal-script-interface",
        "self-alignment-interface",
        "text-interface",
    ],
    "UnaCordaPedalLineSpanner": [
        "axis-group-interface",
        "grob-interface",
        "outside-staff-interface",
        "piano-pedal-interface",
        "side-position-interface",
        "spanner-interface",
    ],
    "VaticanaLigature": [
        "font-interface",
        "grob-interface",
        "spanner-interface",
        "vaticana-ligature-interface",
    ],
    "VerticalAlignment": [
        "align-interface",
        "axis-group-interface",
        "grob-interface",
        "spanner-interface",
    ],
    "VerticalAxisGroup": [
        "axis-group-interface",
        "grob-interface",
        "hara-kiri-group-spanner-interface",
        "outside-staff-axis-group-interface",
        "spanner-interface",
    ],
    "VoiceFollower": [
        "grob-interface",
        "line-interface",
        "line-spanner-interface",
        "spanner-interface",
    ],
    "VoltaBracket": [
        "font-interface",
        "grob-interface",
        "horizontal-bracket-interface",
        "line-interface",
        "side-position-interface",
        "spanner-interface",
        "text-interface",
        "volta-bracket-interface",
        "volta-interface",
    ],
    "VoltaBracketSpanner": [
        "axis-group-interface",
        "grob-interface",
        "outside-staff-interface",
        "side-position-interface",
        "spanner-interface",
        "volta-interface",
    ],
    "VowelTransition": [
        "grob-interface",
        "horizontal-line-spanner-interface",
        "line-interface",
        "line-spanner-interface",
        "lyric-interface",
        "spanner-interface",
    ],
}


contextproperties = [
    "aDueText",
    "accidentalGrouping",
    "additionalBassStrings",
    "additionalPitchPrefix",
    "alignAboveContext",
    "alignBelowContext",
    "alterationGlyphs",
    "alternativeNumber",
    "alternativeNumberingStyle",
    "alternativeRestores",
    "associatedVoice",
    "associatedVoiceType",
    "autoAccidentals",
    "autoBeamCheck",
    "autoBeaming",
    "autoCautionaries",
    "barCheckSynchronize",
    "barExtraVelocity",
    "barNumberFormatter",
    "barNumberVisibility",
    "baseMoment",
    "beamExceptions",
    "beamHalfMeasure",
    "beatExtraVelocity",
    "beatStructure",
    "breathMarkType",
    "caesuraType",
    "caesuraTypeTransform",
    "centerBarNumbers",
    "chordChanges",
    "chordNameExceptions",
    "chordNameFunction",
    "chordNameLowercaseMinor",
    "chordNameSeparator",
    "chordNoteNamer",
    "chordPrefixSpacer",
    "chordRootNamer",
    "clefGlyph",
    "clefPosition",
    "clefTransposition",
    "clefTranspositionFormatter",
    "clefTranspositionStyle",
    "codaMarkFormatter",
    "completionBusy",
    "completionFactor",
    "completionUnit",
    "connectArpeggios",
    "countPercentRepeats",
    "createKeyOnClefChange",
    "createSpacing",
    "crescendoSpanner",
    "crescendoText",
    "cueClefGlyph",
    "cueClefPosition",
    "cueClefTransposition",
    "cueClefTranspositionFormatter",
    "cueClefTranspositionStyle",
    "currentBarNumber",
    "dalSegnoTextFormatter",
    "decrescendoSpanner",
    "decrescendoText",
    "defaultStrings",
    "doubleRepeatBarType",
    "doubleRepeatSegnoBarType",
    "doubleSlurs",
    "drumPitchTable",
    "drumStyleTable",
    "endAtSkip",
    "endRepeatBarType",
    "endRepeatSegnoBarType",
    "explicitClefVisibility",
    "explicitCueClefVisibility",
    "explicitKeySignatureVisibility",
    "extendersOverRests",
    "extraNatural",
    "figuredBassAlterationDirection",
    "figuredBassCenterContinuations",
    "figuredBassFormatter",
    "figuredBassLargeNumberAlignment",
    "figuredBassPlusDirection",
    "figuredBassPlusStrokedAlist",
    "finalFineTextVisibility",
    "fineBarType",
    "fineSegnoBarType",
    "fineStartRepeatSegnoBarType",
    "fineText",
    "fingeringOrientations",
    "firstClef",
    "followVoice",
    "fontSize",
    "forbidBreak",
    "forbidBreakBetweenBarLines",
    "forceClef",
    "fretLabels",
    "glissandoMap",
    "gridInterval",
    "handleNegativeFrets",
    "harmonicAccidentals",
    "harmonicDots",
    "highStringOne",
    "ignoreBarChecks",
    "ignoreBarNumberChecks",
    "ignoreFiguredBassRest",
    "ignoreMelismata",
    "implicitBassFigures",
    "includeGraceNotes",
    "initialTimeSignatureVisibility",
    "instrumentCueName",
    "instrumentEqualizer",
    "instrumentName",
    "instrumentTransposition",
    "internalBarNumber",
    "keepAliveInterfaces",
    "keyAlterationOrder",
    "keyAlterations",
    "lyricMelismaAlignment",
    "lyricRepeatCountFormatter",
    "magnifyStaffValue",
    "majorSevenSymbol",
    "maximumFretStretch",
    "measureBarType",
    "measureLength",
    "measurePosition",
    "measureStartNow",
    "melismaBusyProperties",
    "metronomeMarkFormatter",
    "middleCClefPosition",
    "middleCCuePosition",
    "middleCOffset",
    "middleCPosition",
    "midiBalance",
    "midiChannelMapping",
    "midiChorusLevel",
    "midiExpression",
    "midiInstrument",
    "midiMaximumVolume",
    "midiMergeUnisons",
    "midiMinimumVolume",
    "midiPanPosition",
    "midiReverbLevel",
    "minimumFret",
    "minimumPageTurnLength",
    "minimumRepeatLengthForPageTurn",
    "minorChordModifier",
    "noChordSymbol",
    "noteNameFunction",
    "noteNameSeparator",
    "noteToFretFunction",
    "nullAccidentals",
    "ottavaStartNow",
    "ottavation",
    "ottavationMarkups",
    "output",
    "partCombineForced",
    "partCombineTextsOnNote",
    "pedalSostenutoStrings",
    "pedalSostenutoStyle",
    "pedalSustainStrings",
    "pedalSustainStyle",
    "pedalUnaCordaStrings",
    "pedalUnaCordaStyle",
    "predefinedDiagramTable",
    "printAccidentalNames",
    "printKeyCancellation",
    "printNotesLanguage",
    "printOctaveNames",
    "printPartCombineTexts",
    "proportionalNotationDuration",
    "rehearsalMark",
    "rehearsalMarkFormatter",
    "repeatCommands",
    "repeatCountVisibility",
    "restCompletionBusy",
    "restNumberThreshold",
    "restrainOpenStrings",
    "searchForVoice",
    "sectionBarType",
    "segnoBarType",
    "segnoMarkFormatter",
    "segnoStyle",
    "shapeNoteStyles",
    "shortInstrumentName",
    "shortVocalName",
    "skipBars",
    "skipTypesetting",
    "slashChordSeparator",
    "soloIIText",
    "soloText",
    "squashedPosition",
    "staffLineLayoutFunction",
    "stanza",
    "startAtNoteColumn",
    "startAtSkip",
    "startRepeatBarType",
    "startRepeatSegnoBarType",
    "stemLeftBeamCount",
    "stemRightBeamCount",
    "strictBeatBeaming",
    "stringNumberOrientations",
    "stringOneTopmost",
    "stringTunings",
    "strokeFingerOrientations",
    "subdivideBeams",
    "suggestAccidentals",
    "supportNonIntegerFret",
    "suspendMelodyDecisions",
    "suspendRestMerging",
    "systemStartDelimiter",
    "systemStartDelimiterHierarchy",
    "tabStaffLineLayoutFunction",
    "tablatureFormat",
    "tempoHideNote",
    "tempoWholesPerMinute",
    "tieWaitForNote",
    "timeSignatureFraction",
    "timeSignatureSettings",
    "timing",
    "tonic",
    "topLevelAlignment",
    "tupletFullLength",
    "tupletFullLengthNote",
    "tupletSpannerDuration",
    "underlyingRepeatBarType",
    "useBassFigureExtenders",
    "vocalName",
    "voltaSpannerDuration",
    "whichBar",
]


engravers = [
    "Accidental_engraver",
    "Alteration_glyph_engraver",
    "Ambitus_engraver",
    "Arpeggio_engraver",
    "Auto_beam_engraver",
    "Axis_group_engraver",
    "Balloon_engraver",
    "Bar_engraver",
    "Bar_number_engraver",
    "Beam_collision_engraver",
    "Beam_engraver",
    "Beam_performer",
    "Beat_engraver",
    "Beat_performer",
    "Bend_engraver",
    "Bend_spanner_engraver",
    "Break_align_engraver",
    "Breathing_sign_engraver",
    "Caesura_engraver",
    "Centered_bar_number_align_engraver",
    "Chord_name_engraver",
    "Chord_square_engraver",
    "Chord_tremolo_engraver",
    "Clef_engraver",
    "Cluster_spanner_engraver",
    "Collision_engraver",
    "Completion_heads_engraver",
    "Completion_rest_engraver",
    "Concurrent_hairpin_engraver",
    "Control_track_performer",
    "Cue_clef_engraver",
    "Current_chord_text_engraver",
    "Custos_engraver",
    "Divisio_engraver",
    "Dot_column_engraver",
    "Dots_engraver",
    "Double_percent_repeat_engraver",
    "Drum_note_performer",
    "Drum_notes_engraver",
    "Duration_line_engraver",
    "Dynamic_align_engraver",
    "Dynamic_engraver",
    "Dynamic_performer",
    "Episema_engraver",
    "Extender_engraver",
    "Figured_bass_engraver",
    "Figured_bass_position_engraver",
    "Finger_glide_engraver",
    "Fingering_column_engraver",
    "Fingering_engraver",
    "Font_size_engraver",
    "Footnote_engraver",
    "Forbid_line_break_engraver",
    "Fretboard_engraver",
    "Glissando_engraver",
    "Grace_auto_beam_engraver",
    "Grace_beam_engraver",
    "Grace_engraver",
    "Grace_spacing_engraver",
    "Grid_chord_name_engraver",
    "Grid_line_span_engraver",
    "Grid_point_engraver",
    "Grob_pq_engraver",
    "Horizontal_bracket_engraver",
    "Hyphen_engraver",
    "Instrument_name_engraver",
    "Instrument_switch_engraver",
    "Jump_engraver",
    "Keep_alive_together_engraver",
    "Key_engraver",
    "Key_performer",
    "Kievan_ligature_engraver",
    "Laissez_vibrer_engraver",
    "Ledger_line_engraver",
    "Ligature_bracket_engraver",
    "Lyric_engraver",
    "Lyric_performer",
    "Lyric_repeat_count_engraver",
    "Mark_engraver",
    "Mark_performer",
    "Mark_tracking_translator",
    "Measure_counter_engraver",
    "Measure_grouping_engraver",
    "Measure_spanner_engraver",
    "Melody_engraver",
    "Mensural_ligature_engraver",
    "Merge_mmrest_numbers_engraver",
    "Merge_rests_engraver",
    "Metronome_mark_engraver",
    "Midi_control_change_performer",
    "Multi_measure_rest_engraver",
    "New_fingering_engraver",
    "Non_musical_script_column_engraver",
    "Note_head_line_engraver",
    "Note_heads_engraver",
    "Note_name_engraver",
    "Note_performer",
    "Note_spacing_engraver",
    "Ottava_spanner_engraver",
    "Output_property_engraver",
    "Page_turn_engraver",
    "Paper_column_engraver",
    "Parenthesis_engraver",
    "Part_combine_engraver",
    "Percent_repeat_engraver",
    "Phrasing_slur_engraver",
    "Piano_pedal_align_engraver",
    "Piano_pedal_engraver",
    "Piano_pedal_performer",
    "Pitch_squash_engraver",
    "Pitched_trill_engraver",
    "Pure_from_neighbor_engraver",
    "Repeat_acknowledge_engraver",
    "Repeat_tie_engraver",
    "Rest_collision_engraver",
    "Rest_engraver",
    "Rhythmic_column_engraver",
    "Script_column_engraver",
    "Script_engraver",
    "Script_row_engraver",
    "Separating_line_group_engraver",
    "Show_control_points_engraver",
    "Signum_repetitionis_engraver",
    "Skip_typesetting_engraver",
    "Slash_repeat_engraver",
    "Slur_engraver",
    "Slur_performer",
    "Spacing_engraver",
    "Span_arpeggio_engraver",
    "Span_bar_engraver",
    "Span_bar_stub_engraver",
    "Span_stem_engraver",
    "Spanner_break_forbid_engraver",
    "Spanner_tracking_engraver",
    "Staff_collecting_engraver",
    "Staff_highlight_engraver",
    "Staff_performer",
    "Staff_symbol_engraver",
    "Stanza_number_align_engraver",
    "Stanza_number_engraver",
    "Stem_engraver",
    "System_start_delimiter_engraver",
    "Tab_note_heads_engraver",
    "Tab_staff_symbol_engraver",
    "Tab_tie_follow_engraver",
    "Tempo_performer",
    "Text_engraver",
    "Text_mark_engraver",
    "Text_spanner_engraver",
    "Tie_engraver",
    "Tie_performer",
    "Time_signature_engraver",
    "Time_signature_performer",
    "Timing_translator",
    "Trill_spanner_engraver",
    "Tuplet_engraver",
    "Tweak_engraver",
    "Vaticana_ligature_engraver",
    "Vertical_align_engraver",
    "Volta_engraver",
]


musicglyphs = [
    "accidentals.doublesharp",
    "accidentals.doublesharp.figbass",
    "accidentals.flat",
    "accidentals.flat.arrowboth",
    "accidentals.flat.arrowdown",
    "accidentals.flat.arrowup",
    "accidentals.flat.figbass",
    "accidentals.flat.koron",
    "accidentals.flat.slash",
    "accidentals.flat.slashslash",
    "accidentals.flatflat",
    "accidentals.flatflat.figbass",
    "accidentals.flatflat.slash",
    "accidentals.hufnagelM1",
    "accidentals.kievan1",
    "accidentals.kievanM1",
    "accidentals.leftparen",
    "accidentals.medicaeaM1",
    "accidentals.mensural1",
    "accidentals.mensuralM1",
    "accidentals.mirroredflat",
    "accidentals.mirroredflat.backslash",
    "accidentals.mirroredflat.flat",
    "accidentals.natural",
    "accidentals.natural.arrowboth",
    "accidentals.natural.arrowdown",
    "accidentals.natural.arrowup",
    "accidentals.natural.figbass",
    "accidentals.rightparen",
    "accidentals.sharp",
    "accidentals.sharp.arrowboth",
    "accidentals.sharp.arrowdown",
    "accidentals.sharp.arrowup",
    "accidentals.sharp.figbass",
    "accidentals.sharp.slash.stem",
    "accidentals.sharp.slashslash.stem",
    "accidentals.sharp.slashslash.stemstemstem",
    "accidentals.sharp.slashslashslash.stem",
    "accidentals.sharp.slashslashslash.stemstem",
    "accidentals.sharp.sori",
    "accidentals.vaticana0",
    "accidentals.vaticanaM1",
    "accordion.bayanbass",
    "accordion.discant",
    "accordion.dot",
    "accordion.freebass",
    "accordion.oldEE",
    "accordion.pull",
    "accordion.push",
    "accordion.stdbass",
    "arrowheads.close.01",
    "arrowheads.close.0M1",
    "arrowheads.close.11",
    "arrowheads.close.1M1",
    "arrowheads.open.01",
    "arrowheads.open.0M1",
    "arrowheads.open.11",
    "arrowheads.open.1M1",
    "backslash",
    "brackettips.down",
    "brackettips.up",
    "clefs.C",
    "clefs.C_change",
    "clefs.F",
    "clefs.F_change",
    "clefs.G",
    "clefs.GG",
    "clefs.GG_change",
    "clefs.G_change",
    "clefs.blackmensural.c",
    "clefs.blackmensural.c_change",
    "clefs.hufnagel.do",
    "clefs.hufnagel.do.fa",
    "clefs.hufnagel.do.fa_change",
    "clefs.hufnagel.do_change",
    "clefs.hufnagel.fa",
    "clefs.hufnagel.fa_change",
    "clefs.kievan.do",
    "clefs.kievan.do_change",
    "clefs.medicaea.do",
    "clefs.medicaea.do_change",
    "clefs.medicaea.fa",
    "clefs.medicaea.fa_change",
    "clefs.mensural.c",
    "clefs.mensural.c_change",
    "clefs.mensural.f",
    "clefs.mensural.f_change",
    "clefs.mensural.g",
    "clefs.mensural.g_change",
    "clefs.neomensural.c",
    "clefs.neomensural.c_change",
    "clefs.percussion",
    "clefs.percussion_change",
    "clefs.petrucci.c1",
    "clefs.petrucci.c1_change",
    "clefs.petrucci.c2",
    "clefs.petrucci.c2_change",
    "clefs.petrucci.c3",
    "clefs.petrucci.c3_change",
    "clefs.petrucci.c4",
    "clefs.petrucci.c4_change",
    "clefs.petrucci.c5",
    "clefs.petrucci.c5_change",
    "clefs.petrucci.f",
    "clefs.petrucci.f_change",
    "clefs.petrucci.g",
    "clefs.petrucci.g_change",
    "clefs.tab",
    "clefs.tab_change",
    "clefs.tenorG",
    "clefs.tenorG_change",
    "clefs.varC",
    "clefs.varC_change",
    "clefs.varpercussion",
    "clefs.varpercussion_change",
    "clefs.vaticana.do",
    "clefs.vaticana.do_change",
    "clefs.vaticana.fa",
    "clefs.vaticana.fa_change",
    "comma",
    "custodes.hufnagel.d0",
    "custodes.hufnagel.d1",
    "custodes.hufnagel.d2",
    "custodes.hufnagel.u0",
    "custodes.hufnagel.u1",
    "custodes.hufnagel.u2",
    "custodes.medicaea.d0",
    "custodes.medicaea.d1",
    "custodes.medicaea.d2",
    "custodes.medicaea.u0",
    "custodes.medicaea.u1",
    "custodes.medicaea.u2",
    "custodes.mensural.d0",
    "custodes.mensural.d1",
    "custodes.mensural.d2",
    "custodes.mensural.u0",
    "custodes.mensural.u1",
    "custodes.mensural.u2",
    "custodes.vaticana.d0",
    "custodes.vaticana.d1",
    "custodes.vaticana.d2",
    "custodes.vaticana.u0",
    "custodes.vaticana.u1",
    "custodes.vaticana.u2",
    "dots.dot",
    "dots.dotkievan",
    "dots.dotvaticana",
    "eight",
    "f",
    "fattened.eight",
    "fattened.five",
    "fattened.fixedwidth.eight",
    "fattened.fixedwidth.five",
    "fattened.fixedwidth.four",
    "fattened.fixedwidth.four.alt",
    "fattened.fixedwidth.nine",
    "fattened.fixedwidth.one",
    "fattened.fixedwidth.seven",
    "fattened.fixedwidth.seven.alt",
    "fattened.fixedwidth.six",
    "fattened.fixedwidth.three",
    "fattened.fixedwidth.two",
    "fattened.fixedwidth.zero",
    "fattened.four",
    "fattened.four.alt",
    "fattened.nine",
    "fattened.one",
    "fattened.seven",
    "fattened.seven.alt",
    "fattened.six",
    "fattened.three",
    "fattened.two",
    "fattened.zero",
    "figbass.fiveplus",
    "figbass.fourplus",
    "figbass.ninestroked",
    "figbass.sevenstroked",
    "figbass.sixstroked",
    "figbass.twoplus",
    "five",
    "fixedwidth.eight",
    "fixedwidth.five",
    "fixedwidth.four",
    "fixedwidth.four.alt",
    "fixedwidth.nine",
    "fixedwidth.one",
    "fixedwidth.seven",
    "fixedwidth.seven.alt",
    "fixedwidth.six",
    "fixedwidth.three",
    "fixedwidth.two",
    "fixedwidth.zero",
    "flags.d10",
    "flags.d3",
    "flags.d4",
    "flags.d5",
    "flags.d6",
    "flags.d7",
    "flags.d8",
    "flags.d9",
    "flags.dgrace",
    "flags.mensurald03",
    "flags.mensurald04",
    "flags.mensurald05",
    "flags.mensurald06",
    "flags.mensurald13",
    "flags.mensurald14",
    "flags.mensurald15",
    "flags.mensurald16",
    "flags.mensurald23",
    "flags.mensurald24",
    "flags.mensurald25",
    "flags.mensurald26",
    "flags.mensuralu03",
    "flags.mensuralu04",
    "flags.mensuralu05",
    "flags.mensuralu06",
    "flags.mensuralu13",
    "flags.mensuralu14",
    "flags.mensuralu15",
    "flags.mensuralu16",
    "flags.mensuralu23",
    "flags.mensuralu24",
    "flags.mensuralu25",
    "flags.mensuralu26",
    "flags.u10",
    "flags.u3",
    "flags.u4",
    "flags.u5",
    "flags.u6",
    "flags.u7",
    "flags.u8",
    "flags.u9",
    "flags.ugrace",
    "four",
    "four.alt",
    "hyphen",
    "m",
    "n",
    "nine",
    "noteheads.d0doFunk",
    "noteheads.d0fa",
    "noteheads.d0faFunk",
    "noteheads.d0faThin",
    "noteheads.d0miFunk",
    "noteheads.d0reFunk",
    "noteheads.d0tiFunk",
    "noteheads.d1doFunk",
    "noteheads.d1doWalker",
    "noteheads.d1fa",
    "noteheads.d1faFunk",
    "noteheads.d1faThin",
    "noteheads.d1faWalker",
    "noteheads.d1miFunk",
    "noteheads.d1reFunk",
    "noteheads.d1reWalker",
    "noteheads.d1tiFunk",
    "noteheads.d1tiWalker",
    "noteheads.d2doFunk",
    "noteheads.d2doWalker",
    "noteheads.d2fa",
    "noteheads.d2faFunk",
    "noteheads.d2faThin",
    "noteheads.d2faWalker",
    "noteheads.d2kievan",
    "noteheads.d2reFunk",
    "noteheads.d2reWalker",
    "noteheads.d2tiFunk",
    "noteheads.d2tiWalker",
    "noteheads.d3kievan",
    "noteheads.dM2",
    "noteheads.dM2blackmensural",
    "noteheads.dM2mensural",
    "noteheads.dM2neomensural",
    "noteheads.dM2semimensural",
    "noteheads.dM3blackmensural",
    "noteheads.dM3mensural",
    "noteheads.dM3neomensural",
    "noteheads.dM3semimensural",
    "noteheads.drM2mensural",
    "noteheads.drM2neomensural",
    "noteheads.drM2semimensural",
    "noteheads.drM3mensural",
    "noteheads.drM3neomensural",
    "noteheads.drM3semimensural",
    "noteheads.s0",
    "noteheads.s0blackmensural",
    "noteheads.s0blackpetrucci",
    "noteheads.s0cross",
    "noteheads.s0diamond",
    "noteheads.s0do",
    "noteheads.s0doThin",
    "noteheads.s0doWalker",
    "noteheads.s0faWalker",
    "noteheads.s0harmonic",
    "noteheads.s0kievan",
    "noteheads.s0la",
    "noteheads.s0laFunk",
    "noteheads.s0laThin",
    "noteheads.s0laWalker",
    "noteheads.s0mensural",
    "noteheads.s0mi",
    "noteheads.s0miMirror",
    "noteheads.s0miThin",
    "noteheads.s0miWalker",
    "noteheads.s0neomensural",
    "noteheads.s0petrucci",
    "noteheads.s0re",
    "noteheads.s0reThin",
    "noteheads.s0reWalker",
    "noteheads.s0slash",
    "noteheads.s0sol",
    "noteheads.s0solFunk",
    "noteheads.s0ti",
    "noteheads.s0tiThin",
    "noteheads.s0tiWalker",
    "noteheads.s0triangle",
    "noteheads.s1",
    "noteheads.s1blackpetrucci",
    "noteheads.s1cross",
    "noteheads.s1diamond",
    "noteheads.s1do",
    "noteheads.s1doThin",
    "noteheads.s1kievan",
    "noteheads.s1la",
    "noteheads.s1laFunk",
    "noteheads.s1laThin",
    "noteheads.s1laWalker",
    "noteheads.s1mensural",
    "noteheads.s1mi",
    "noteheads.s1miMirror",
    "noteheads.s1miThin",
    "noteheads.s1miWalker",
    "noteheads.s1neomensural",
    "noteheads.s1petrucci",
    "noteheads.s1re",
    "noteheads.s1reThin",
    "noteheads.s1slash",
    "noteheads.s1sol",
    "noteheads.s1solFunk",
    "noteheads.s1ti",
    "noteheads.s1tiThin",
    "noteheads.s1triangle",
    "noteheads.s2",
    "noteheads.s2blackpetrucci",
    "noteheads.s2cross",
    "noteheads.s2diamond",
    "noteheads.s2do",
    "noteheads.s2doThin",
    "noteheads.s2harmonic",
    "noteheads.s2la",
    "noteheads.s2laFunk",
    "noteheads.s2laThin",
    "noteheads.s2laWalker",
    "noteheads.s2mensural",
    "noteheads.s2mi",
    "noteheads.s2miFunk",
    "noteheads.s2miMirror",
    "noteheads.s2miThin",
    "noteheads.s2miWalker",
    "noteheads.s2neomensural",
    "noteheads.s2petrucci",
    "noteheads.s2re",
    "noteheads.s2reThin",
    "noteheads.s2slash",
    "noteheads.s2sol",
    "noteheads.s2solFunk",
    "noteheads.s2ti",
    "noteheads.s2tiThin",
    "noteheads.s2triangle",
    "noteheads.s2xcircle",
    "noteheads.sM1",
    "noteheads.sM1blackmensural",
    "noteheads.sM1double",
    "noteheads.sM1kievan",
    "noteheads.sM1mensural",
    "noteheads.sM1neomensural",
    "noteheads.sM1semimensural",
    "noteheads.sM2blackligmensural",
    "noteheads.sM2kievan",
    "noteheads.sM2ligmensural",
    "noteheads.sM2semiligmensural",
    "noteheads.sM3blackligmensural",
    "noteheads.sM3ligmensural",
    "noteheads.sM3semiligmensural",
    "noteheads.shufnagel.lpes",
    "noteheads.shufnagel.punctum",
    "noteheads.shufnagel.virga",
    "noteheads.smedicaea.inclinatum",
    "noteheads.smedicaea.punctum",
    "noteheads.smedicaea.rvirga",
    "noteheads.smedicaea.virga",
    "noteheads.sr1kievan",
    "noteheads.srM1mensural",
    "noteheads.srM1neomensural",
    "noteheads.srM1semimensural",
    "noteheads.srM2ligmensural",
    "noteheads.srM2semiligmensural",
    "noteheads.srM3ligmensural",
    "noteheads.srM3semiligmensural",
    "noteheads.ssolesmes.auct.asc",
    "noteheads.ssolesmes.auct.desc",
    "noteheads.ssolesmes.incl.auctum",
    "noteheads.ssolesmes.incl.parvum",
    "noteheads.ssolesmes.oriscus",
    "noteheads.ssolesmes.stropha",
    "noteheads.ssolesmes.stropha.aucta",
    "noteheads.svaticana.cephalicus",
    "noteheads.svaticana.epiphonus",
    "noteheads.svaticana.inclinatum",
    "noteheads.svaticana.inner.cephalicus",
    "noteheads.svaticana.linea.punctum",
    "noteheads.svaticana.linea.punctum.cavum",
    "noteheads.svaticana.lpes",
    "noteheads.svaticana.plica",
    "noteheads.svaticana.punctum",
    "noteheads.svaticana.punctum.cavum",
    "noteheads.svaticana.quilisma",
    "noteheads.svaticana.reverse.plica",
    "noteheads.svaticana.reverse.vplica",
    "noteheads.svaticana.upes",
    "noteheads.svaticana.vepiphonus",
    "noteheads.svaticana.vlpes",
    "noteheads.svaticana.vplica",
    "noteheads.svaticana.vupes",
    "noteheads.u0doFunk",
    "noteheads.u0fa",
    "noteheads.u0faFunk",
    "noteheads.u0faThin",
    "noteheads.u0miFunk",
    "noteheads.u0reFunk",
    "noteheads.u0tiFunk",
    "noteheads.u1doFunk",
    "noteheads.u1doWalker",
    "noteheads.u1fa",
    "noteheads.u1faFunk",
    "noteheads.u1faThin",
    "noteheads.u1faWalker",
    "noteheads.u1miFunk",
    "noteheads.u1reFunk",
    "noteheads.u1reWalker",
    "noteheads.u1tiFunk",
    "noteheads.u1tiWalker",
    "noteheads.u2doFunk",
    "noteheads.u2doWalker",
    "noteheads.u2fa",
    "noteheads.u2faFunk",
    "noteheads.u2faThin",
    "noteheads.u2faWalker",
    "noteheads.u2kievan",
    "noteheads.u2reFunk",
    "noteheads.u2reWalker",
    "noteheads.u2tiFunk",
    "noteheads.u2tiWalker",
    "noteheads.u3kievan",
    "noteheads.uM2",
    "noteheads.uM2blackmensural",
    "noteheads.uM2mensural",
    "noteheads.uM2neomensural",
    "noteheads.uM2semimensural",
    "noteheads.uM3blackmensural",
    "noteheads.uM3mensural",
    "noteheads.uM3neomensural",
    "noteheads.uM3semimensural",
    "noteheads.urM2mensural",
    "noteheads.urM2neomensural",
    "noteheads.urM2semimensural",
    "noteheads.urM3mensural",
    "noteheads.urM3neomensural",
    "noteheads.urM3semimensural",
    "one",
    "p",
    "pedal.*",
    "pedal..",
    "pedal.M",
    "pedal.P",
    "pedal.Ped",
    "pedal.d",
    "pedal.e",
    "period",
    "plus",
    "r",
    "rests.0",
    "rests.0mensural",
    "rests.0neomensural",
    "rests.0o",
    "rests.1",
    "rests.10",
    "rests.1mensural",
    "rests.1neomensural",
    "rests.1o",
    "rests.2",
    "rests.2classical",
    "rests.2mensural",
    "rests.2neomensural",
    "rests.2z",
    "rests.3",
    "rests.3mensural",
    "rests.3neomensural",
    "rests.4",
    "rests.4mensural",
    "rests.4neomensural",
    "rests.5",
    "rests.6",
    "rests.7",
    "rests.8",
    "rests.9",
    "rests.M1",
    "rests.M1mensural",
    "rests.M1neomensural",
    "rests.M1o",
    "rests.M2",
    "rests.M2mensural",
    "rests.M2neomensural",
    "rests.M3",
    "rests.M3mensural",
    "rests.M3neomensural",
    "s",
    "scripts.arpeggio",
    "scripts.arpeggio.arrow.1",
    "scripts.arpeggio.arrow.M1",
    "scripts.barline.kievan",
    "scripts.caesura.curved",
    "scripts.caesura.straight",
    "scripts.circulus",
    "scripts.coda",
    "scripts.daccentus",
    "scripts.dfermata",
    "scripts.dhenzelongfermata",
    "scripts.dhenzeshortfermata",
    "scripts.dlongfermata",
    "scripts.dmarcato",
    "scripts.downbow",
    "scripts.downmordent",
    "scripts.downprall",
    "scripts.dpedalheel",
    "scripts.dpedaltoe",
    "scripts.dportato",
    "scripts.dsemicirculus",
    "scripts.dshortfermata",
    "scripts.dsignumcongruentiae",
    "scripts.dstaccatissimo",
    "scripts.dverylongfermata",
    "scripts.dveryshortfermata",
    "scripts.espr",
    "scripts.flageolet",
    "scripts.halfopen",
    "scripts.halfopenvertical",
    "scripts.haydnturn",
    "scripts.ictus",
    "scripts.laltcomma",
    "scripts.lcomma",
    "scripts.lineprall",
    "scripts.lvarcomma",
    "scripts.mordent",
    "scripts.open",
    "scripts.prall",
    "scripts.pralldown",
    "scripts.prallmordent",
    "scripts.prallprall",
    "scripts.prallup",
    "scripts.raltcomma",
    "scripts.rcomma",
    "scripts.reverseturn",
    "scripts.rvarcomma",
    "scripts.segno",
    "scripts.sforzato",
    "scripts.slashturn",
    "scripts.snappizzicato",
    "scripts.staccato",
    "scripts.stopped",
    "scripts.tenuto",
    "scripts.thumb",
    "scripts.tickmark",
    "scripts.trill",
    "scripts.trill_element",
    "scripts.turn",
    "scripts.uaccentus",
    "scripts.ufermata",
    "scripts.uhenzelongfermata",
    "scripts.uhenzeshortfermata",
    "scripts.ulongfermata",
    "scripts.umarcato",
    "scripts.upbow",
    "scripts.upedalheel",
    "scripts.upedaltoe",
    "scripts.upmordent",
    "scripts.uportato",
    "scripts.upprall",
    "scripts.usemicirculus",
    "scripts.ushortfermata",
    "scripts.usignumcongruentiae",
    "scripts.ustaccatissimo",
    "scripts.uverylongfermata",
    "scripts.uveryshortfermata",
    "scripts.varcoda",
    "scripts.varsegno",
    "seven",
    "seven.alt",
    "six",
    "space",
    "three",
    "ties.lyric.default",
    "ties.lyric.short",
    "timesig.C22",
    "timesig.C44",
    "timesig.mensural22",
    "timesig.mensural24",
    "timesig.mensural32",
    "timesig.mensural34",
    "timesig.mensural44",
    "timesig.mensural48",
    "timesig.mensural64",
    "timesig.mensural68",
    "timesig.mensural68alt",
    "timesig.mensural94",
    "timesig.mensural98",
    "timesig.neomensural22",
    "timesig.neomensural24",
    "timesig.neomensural32",
    "timesig.neomensural34",
    "timesig.neomensural44",
    "timesig.neomensural48",
    "timesig.neomensural64",
    "timesig.neomensural68",
    "timesig.neomensural68alt",
    "timesig.neomensural94",
    "timesig.neomensural98",
    "two",
    "z",
    "zero",
]


python_ly-0.9.9/ly/data/_scheme_data.py0000644000000000000000000032424113615410400015007 0ustar00#generated by makeschemedata.py

version="2.24"

scheme_keywords = [
    '&assertion',
    '&condition',
    '&error',
    '&i/o',
    '&i/o-decoding',
    '&i/o-encoding',
    '&i/o-file-already-exists',
    '&i/o-file-does-not-exist',
    '&i/o-file-is-read-only',
    '&i/o-file-protection',
    '&i/o-filename',
    '&i/o-invalid-position',
    '&i/o-port',
    '&i/o-read',
    '&i/o-write',
    '&implementation-restriction',
    '&irritants',
    '&lexical',
    '&message',
    '&no-infinities',
    '&no-nans',
    '&non-continuable',
    '&serious',
    '&syntax',
    '&undefined',
    '&violation',
    '&warning',
    '&who',
    '*',
    '+',
    '-',
    '->char-set',
    '/',
    '1+',
    '1-',
    '<',
    '<=',
    '=',
    '==',
    '>',
    '>=',
    'abandoned-mutex-exception?',
    'abort',
    'abort-to-prompt',
    'abs',
    'absolute-file-name?',
    'access?',
    'acons',
    'acos',
    'acosh',
    'activate-readline',
    'adapt-response-version',
    'add',
    'add-duration',
    'add-duration!',
    'add-ephemeral-stepping-trap!',
    'add-ephemeral-trap-at-frame-finish!',
    'add-fdes-finalizer!',
    'add-hook!',
    'add-method!',
    'add-ref-resolver!',
    'add-to-load-path',
    'add-trace-at-procedure-call!',
    'add-trap!',
    'add-trap-at-procedure-call!',
    'add-trap-at-source-location!',
    'add/immediate',
    'alignof',
    'alist->hash-table',
    'alist->hashq-table',
    'alist->hashv-table',
    'alist->hashx-table',
    'alist->vhash',
    'alist-cons',
    'alist-copy',
    'alist-delete',
    'alist-delete!',
    'all-mapped-elf-images',
    'alloc-frame',
    'allocate-struct',
    'allocate-struct/immediate',
    'allow-legacy-syntax-objects?',
    'and',
    'and-let*',
    'and=>',
    'angle',
    'any',
    'any->c32vector',
    'any->c64vector',
    'any->f32vector',
    'any->f64vector',
    'any->s16vector',
    'any->s32vector',
    'any->s64vector',
    'any->s8vector',
    'any->u16vector',
    'any->u32vector',
    'any->u64vector',
    'any->u8vector',
    'any-bits-set?',
    'append',
    'append!',
    'append-map',
    'append-map!',
    'append-reverse',
    'append-reverse!',
    'apply',
    'apply-non-program',
    'apply-templates',
    'apropos',
    'apropos-completion-function',
    'arithmetic-shift',
    'arity:allow-other-keys?',
    'arity:end',
    'arity:kw',
    'arity:nopt',
    'arity:nreq',
    'arity:rest?',
    'arity:start',
    'array->list',
    'array-cell-ref',
    'array-cell-set!',
    'array-contents',
    'array-copy',
    'array-copy!',
    'array-copy-in-order!',
    'array-dimensions',
    'array-equal?',
    'array-fill!',
    'array-for-each',
    'array-in-bounds?',
    'array-index-map!',
    'array-length',
    'array-map!',
    'array-map-in-order!',
    'array-rank',
    'array-ref',
    'array-set!',
    'array-shape',
    'array-slice',
    'array-slice-for-each',
    'array-slice-for-each-in-order',
    'array-type',
    'array?',
    'ash',
    'asin',
    'asinh',
    'assert',
    'assert-curr-char',
    'assert-nargs-ee',
    'assert-nargs-ee/locals',
    'assert-nargs-ge',
    'assert-nargs-le',
    'assertion-violation',
    'assertion-violation?',
    'assoc',
    'assoc-ref',
    'assoc-remove!',
    'assoc-set!',
    'assp',
    'assq',
    'assq-ref',
    'assq-remove!',
    'assq-set!',
    'assv',
    'assv-ref',
    'assv-remove!',
    'assv-set!',
    'atan',
    'atanh',
    'atomic-box-compare-and-swap!',
    'atomic-box-ref',
    'atomic-box-set!',
    'atomic-box-swap!',
    'atomic-box?',
    'attlist->alist',
    'attlist-add',
    'attlist-fold',
    'attlist-null?',
    'attlist-remove-top',
    'backtrace',
    'basename',
    'begin',
    'binary-port?',
    'bind-kwargs',
    'bind-rest',
    'bind-textdomain-codeset',
    'binding',
    'binding-index',
    'binding-name',
    'binding-ref',
    'binding-representation',
    'binding-set!',
    'binding-slot',
    'binding:boxed?',
    'binding:end',
    'binding:index',
    'binding:name',
    'binding:start',
    'bindtextdomain',
    'bit-count',
    'bit-count*',
    'bit-extract',
    'bit-field',
    'bit-invert!',
    'bit-position',
    'bit-set*!',
    'bit-set?',
    'bitvector',
    'bitvector->list',
    'bitvector-fill!',
    'bitvector-length',
    'bitvector-ref',
    'bitvector-set!',
    'bitvector?',
    'bitwise-and',
    'bitwise-arithmetic-shift',
    'bitwise-arithmetic-shift-left',
    'bitwise-arithmetic-shift-right',
    'bitwise-bit-count',
    'bitwise-bit-field',
    'bitwise-bit-set?',
    'bitwise-copy-bit',
    'bitwise-copy-bit-field',
    'bitwise-first-bit-set',
    'bitwise-if',
    'bitwise-ior',
    'bitwise-length',
    'bitwise-merge',
    'bitwise-not',
    'bitwise-reverse-bit-field',
    'bitwise-rotate-bit-field',
    'bitwise-xor',
    'boolean?',
    'booleans->integer',
    'bound-identifier=?',
    'box',
    'box-ref',
    'box-set!',
    'box?',
    'br',
    'br-if-<',
    'br-if-<=',
    'br-if-=',
    'br-if-char',
    'br-if-eq',
    'br-if-eqv',
    'br-if-f64-<',
    'br-if-f64-<=',
    'br-if-f64-=',
    'br-if-f64->',
    'br-if-f64->=',
    'br-if-logtest',
    'br-if-nargs-gt',
    'br-if-nargs-lt',
    'br-if-nargs-ne',
    'br-if-nil',
    'br-if-npos-gt',
    'br-if-null',
    'br-if-pair',
    'br-if-struct',
    'br-if-tc7',
    'br-if-true',
    'br-if-u64-<',
    'br-if-u64-<-scm',
    'br-if-u64-<=',
    'br-if-u64-<=-scm',
    'br-if-u64-=',
    'br-if-u64-=-scm',
    'break',
    'break!',
    'break-at-source',
    'broadcast-condition-variable',
    'buffer-mode',
    'buffer-mode?',
    'build-cont',
    'build-exp',
    'build-relative-ref',
    'build-request',
    'build-response',
    'build-term',
    'build-uri',
    'build-uri-reference',
    'builtin-ref',
    'bv-f32-ref',
    'bv-f32-set!',
    'bv-f64-ref',
    'bv-f64-set!',
    'bv-length',
    'bv-s16-ref',
    'bv-s16-set!',
    'bv-s32-ref',
    'bv-s32-set!',
    'bv-s64-ref',
    'bv-s64-set!',
    'bv-s8-ref',
    'bv-s8-set!',
    'bv-u16-ref',
    'bv-u16-set!',
    'bv-u32-ref',
    'bv-u32-set!',
    'bv-u64-ref',
    'bv-u64-set!',
    'bv-u8-ref',
    'bv-u8-set!',
    'bytevector->pointer',
    'bytevector->sint-list',
    'bytevector->string',
    'bytevector->u8-list',
    'bytevector->uint-list',
    'bytevector-copy',
    'bytevector-copy!',
    'bytevector-fill!',
    'bytevector-ieee-double-native-ref',
    'bytevector-ieee-double-native-set!',
    'bytevector-ieee-double-ref',
    'bytevector-ieee-double-set!',
    'bytevector-ieee-single-native-ref',
    'bytevector-ieee-single-native-set!',
    'bytevector-ieee-single-ref',
    'bytevector-ieee-single-set!',
    'bytevector-length',
    'bytevector-s16-native-ref',
    'bytevector-s16-native-set!',
    'bytevector-s16-ref',
    'bytevector-s16-set!',
    'bytevector-s32-native-ref',
    'bytevector-s32-native-set!',
    'bytevector-s32-ref',
    'bytevector-s32-set!',
    'bytevector-s64-native-ref',
    'bytevector-s64-native-set!',
    'bytevector-s64-ref',
    'bytevector-s64-set!',
    'bytevector-s8-ref',
    'bytevector-s8-set!',
    'bytevector-sint-ref',
    'bytevector-sint-set!',
    'bytevector-u16-native-ref',
    'bytevector-u16-native-set!',
    'bytevector-u16-ref',
    'bytevector-u16-set!',
    'bytevector-u32-native-ref',
    'bytevector-u32-native-set!',
    'bytevector-u32-ref',
    'bytevector-u32-set!',
    'bytevector-u64-native-ref',
    'bytevector-u64-native-set!',
    'bytevector-u64-ref',
    'bytevector-u64-set!',
    'bytevector-u8-ref',
    'bytevector-u8-set!',
    'bytevector-uint-ref',
    'bytevector-uint-set!',
    'bytevector=?',
    'bytevector?',
    'c32vector',
    'c32vector->list',
    'c32vector-length',
    'c32vector-ref',
    'c32vector-set!',
    'c32vector?',
    'c64vector',
    'c64vector->list',
    'c64vector-length',
    'c64vector-ref',
    'c64vector-set!',
    'c64vector?',
    'caaaar',
    'caaadr',
    'caaar',
    'caadar',
    'caaddr',
    'caadr',
    'caar',
    'cadaar',
    'cadadr',
    'cadar',
    'caddar',
    'cadddr',
    'caddr',
    'cadr',
    'call',
    'call-label',
    'call-with-allocation-limit',
    'call-with-blocked-asyncs',
    'call-with-current-continuation',
    'call-with-error-handling',
    'call-with-escape-continuation',
    'call-with-file-and-dir',
    'call-with-input-file',
    'call-with-input-string',
    'call-with-output-encoded-string',
    'call-with-output-file',
    'call-with-output-string',
    'call-with-port',
    'call-with-prompt',
    'call-with-stack-overflow-handler',
    'call-with-time-and-allocation-limits',
    'call-with-time-limit',
    'call-with-trace',
    'call-with-unblocked-asyncs',
    'call-with-values',
    'call/cc',
    'call/ec',
    'car',
    'car+cdr',
    'case',
    'case-lambda',
    'case-lambda*',
    'catch',
    'cd',
    'cdaaar',
    'cdaadr',
    'cdaar',
    'cdadar',
    'cdaddr',
    'cdadr',
    'cdar',
    'cddaar',
    'cddadr',
    'cddar',
    'cdddar',
    'cddddr',
    'cdddr',
    'cddr',
    'cdr',
    'ceiling',
    'ceiling-quotient',
    'ceiling-remainder',
    'ceiling/',
    'center-string',
    'centered-quotient',
    'centered-remainder',
    'centered/',
    'change-class',
    'char->formal-name',
    'char->integer',
    'char-alphabetic?',
    'char-ci<=?',
    'char-ci=?',
    'char-ci>?',
    'char-downcase',
    'char-foldcase',
    'char-general-category',
    'char-is-both?',
    'char-locale-ci?',
    'char-locale-downcase',
    'char-locale-titlecase',
    'char-locale-upcase',
    'char-locale?',
    'char-lower-case?',
    'char-numeric?',
    'char-ready?',
    'char-set',
    'char-set->list',
    'char-set->string',
    'char-set-adjoin',
    'char-set-adjoin!',
    'char-set-any',
    'char-set-complement',
    'char-set-complement!',
    'char-set-contains?',
    'char-set-copy',
    'char-set-count',
    'char-set-cursor',
    'char-set-cursor-next',
    'char-set-delete',
    'char-set-delete!',
    'char-set-diff+intersection',
    'char-set-diff+intersection!',
    'char-set-difference',
    'char-set-difference!',
    'char-set-every',
    'char-set-filter',
    'char-set-filter!',
    'char-set-fold',
    'char-set-for-each',
    'char-set-hash',
    'char-set-intersection',
    'char-set-intersection!',
    'char-set-map',
    'char-set-ref',
    'char-set-size',
    'char-set-unfold',
    'char-set-unfold!',
    'char-set-union',
    'char-set-union!',
    'char-set-xor',
    'char-set-xor!',
    'char-set<=',
    'char-set=',
    'char-set?',
    'char-title-case?',
    'char-titlecase',
    'char-upcase',
    'char-upper-case?',
    'char-whitespace?',
    'char<=?',
    'char=?',
    'char>?',
    'char?',
    'chdir',
    'chmod',
    'chown',
    'chroot',
    'circular-list',
    'circular-list?',
    'class',
    'class-direct-methods',
    'class-direct-slots',
    'class-direct-subclasses',
    'class-direct-supers',
    'class-methods',
    'class-name',
    'class-of',
    'class-precedence-list',
    'class-redefinition',
    'class-slot-definition',
    'class-slot-ref',
    'class-slot-set!',
    'class-slots',
    'class-subclasses',
    'clear-value-history!',
    'close',
    'close-fdes',
    'close-input-port',
    'close-output-port',
    'close-pipe',
    'close-port',
    'close-server',
    'closedir',
    'collapse-repeated-chars',
    'command-line',
    'compile',
    'compile-file',
    'compile-peg-pattern',
    'compiled-file-name',
    'complex?',
    'compose',
    'compose-continuation',
    'compute-std-cpl',
    'concatenate',
    'concatenate!',
    'cond',
    'cond-expand',
    'condition',
    'condition-accessor',
    'condition-has-type?',
    'condition-irritants',
    'condition-message',
    'condition-predicate',
    'condition-ref',
    'condition-type?',
    'condition-variable-broadcast!',
    'condition-variable-name',
    'condition-variable-signal!',
    'condition-variable-specific',
    'condition-variable-specific-set!',
    'condition-variable?',
    'condition-who',
    'condition?',
    'cons',
    'cons*',
    'cons-source',
    'const',
    'context-flatten',
    'continuation-call',
    'continue',
    'copy-bit',
    'copy-bit-field',
    'copy-file',
    'copy-random-state',
    'copy-time',
    'copy-tree',
    'cos',
    'cosh',
    'count',
    'coverage-data->lcov',
    'coverage-data?',
    'ctermid',
    'current-date',
    'current-dynamic-state',
    'current-error-port',
    'current-exception-handler',
    'current-filename',
    'current-http-proxy',
    'current-input-port',
    'current-julian-day',
    'current-load-port',
    'current-modified-julian-day',
    'current-module',
    'current-output-port',
    'current-read-waiter',
    'current-source-location',
    'current-ssax-error-port',
    'current-thread',
    'current-time',
    'current-write-waiter',
    'cut',
    'cute',
    'date->julian-day',
    'date->modified-julian-day',
    'date->string',
    'date->time-monotonic',
    'date->time-tai',
    'date->time-utc',
    'date-day',
    'date-hour',
    'date-minute',
    'date-month',
    'date-nanosecond',
    'date-second',
    'date-week-day',
    'date-week-number',
    'date-year',
    'date-year-day',
    'date-zone-offset',
    'date?',
    'datum->random-state',
    'datum->syntax',
    'debug-disable',
    'debug-enable',
    'debug-options',
    'debug-set!',
    'declare-default-port!',
    'declare-header!',
    'declare-opaque-header!',
    'deep-clone',
    'default-duplicate-binding-handler',
    'default-prompt-tag',
    'default-random-source',
    'define',
    'define!',
    'define*',
    'define*-public',
    'define-accessor',
    'define-class',
    'define-condition-type',
    'define-enumeration',
    'define-foreign-object-type',
    'define-generic',
    'define-immutable-record-type',
    'define-inlinable',
    'define-language',
    'define-macro',
    'define-method',
    'define-module',
    'define-once',
    'define-parsed-entity!',
    'define-peg-pattern',
    'define-peg-string-patterns',
    'define-public',
    'define-reader-ctor',
    'define-record-type',
    'define-server-impl',
    'define-stream',
    'define-syntax',
    'define-syntax-parameter',
    'define-syntax-rule',
    'define-values',
    'define-wrapped-pointer-type',
    'defined?',
    'defmacro',
    'defmacro*',
    'defmacro*-public',
    'defvar',
    'delay',
    'delete',
    'delete!',
    'delete-duplicates',
    'delete-duplicates!',
    'delete-file',
    'delete-trap!',
    'delete1!',
    'delq',
    'delq!',
    'delq1!',
    'delv',
    'delv!',
    'delv1!',
    'denominator',
    'deq!',
    'dereference-pointer',
    'describe',
    'directory-stream?',
    'dirname',
    'disable-trap!',
    'disable-value-history!',
    'disassemble',
    'disassemble-file',
    'display',
    'display-application',
    'display-backtrace',
    'display-error',
    'div',
    'div-and-mod',
    'div0',
    'div0-and-mod0',
    'do',
    'dotted-list?',
    'doubly-weak-hash-table?',
    'down',
    'drain-input',
    'drop',
    'drop-right',
    'drop-right!',
    'drop-while',
    'dup',
    'dup->fdes',
    'dup->inport',
    'dup->outport',
    'dup->port',
    'dup2',
    'duplicate-port',
    'dynamic-call',
    'dynamic-func',
    'dynamic-link',
    'dynamic-object?',
    'dynamic-pointer',
    'dynamic-state?',
    'dynamic-unlink',
    'dynamic-wind',
    'eager',
    'effective-version',
    'eighth',
    'else',
    'emit-begin-kw-arity',
    'emit-begin-opt-arity',
    'emit-begin-program',
    'emit-begin-standard-arity',
    'emit-br-if-bitvector',
    'emit-br-if-bytevector',
    'emit-br-if-string',
    'emit-br-if-symbol',
    'emit-br-if-variable',
    'emit-br-if-vector',
    'emit-cache-current-module!',
    'emit-cached-module-box',
    'emit-cached-toplevel-box',
    'emit-end-arity',
    'emit-end-program',
    'emit-label',
    'emit-load-constant',
    'emit-load-static-procedure',
    'emit-source',
    'emit-vector-length',
    'enable-primitive-generic!',
    'enable-trap!',
    'enable-value-history!',
    'encode-and-join-uri-path',
    'end-of-char-set?',
    'endianness',
    'enq!',
    'ensure-accessor',
    'ensure-generic',
    'ensure-metaclass',
    'enum-set->list',
    'enum-set-complement',
    'enum-set-constructor',
    'enum-set-difference',
    'enum-set-indexer',
    'enum-set-intersection',
    'enum-set-member?',
    'enum-set-projection',
    'enum-set-subset?',
    'enum-set-union',
    'enum-set-universe',
    'enum-set=?',
    'environ',
    'environment',
    'eof-object',
    'eof-object?',
    'eol-style',
    'eq?',
    'equal-hash',
    'equal?',
    'eqv?',
    'error',
    'error-handling-mode',
    'error-message',
    'error?',
    'escape-special-chars',
    'euclidean-quotient',
    'euclidean-remainder',
    'euclidean/',
    'eval',
    'eval-in-sandbox',
    'eval-string',
    'eval-when',
    'even?',
    'every',
    'exact',
    'exact->inexact',
    'exact-integer-sqrt',
    'exact-integer?',
    'exact?',
    'execl',
    'execle',
    'execlp',
    'exists',
    'exit',
    'exp',
    'expand',
    'expand-tabs',
    'expect',
    'expect-strings',
    'export',
    'export!',
    'expt',
    'extract-condition',
    'f32vector',
    'f32vector->list',
    'f32vector-length',
    'f32vector-ref',
    'f32vector-set!',
    'f32vector?',
    'f64->scm',
    'f64vector',
    'f64vector->list',
    'f64vector-length',
    'f64vector-ref',
    'f64vector-set!',
    'f64vector?',
    'fadd',
    'false-if-exception',
    'fchmod',
    'fchown',
    'fcntl',
    'fdes->inport',
    'fdes->outport',
    'fdes->ports',
    'fdiv',
    'fdopen',
    'feature?',
    'fflush',
    'fifth',
    'file-encoding',
    'file-exists?',
    'file-name-separator?',
    'file-options',
    'file-port?',
    'file-system-fold',
    'file-system-tree',
    'filename-completion-function',
    'fileno',
    'fill-string',
    'filter',
    'filter!',
    'filter-empty-elements',
    'filter-map',
    'find',
    'find-mapped-elf-image',
    'find-string-from-port?',
    'find-tail',
    'finish',
    'finite?',
    'first',
    'first-set-bit',
    'fixnum->flonum',
    'fixnum-width',
    'fixnum?',
    'fl*',
    'fl+',
    'fl-',
    'fl/',
    'fl<=?',
    'fl=?',
    'fl>?',
    'flabs',
    'flacos',
    'flasin',
    'flatan',
    'flceiling',
    'flcos',
    'fldenominator',
    'fldiv',
    'fldiv-and-mod',
    'fldiv0',
    'fldiv0-and-mod0',
    'fldmod',
    'fleven?',
    'flexp',
    'flexpt',
    'flfinite?',
    'flfloor',
    'flinfinite?',
    'flinteger?',
    'fllog',
    'flmax',
    'flmin',
    'flmod0',
    'flnan?',
    'flnegative?',
    'flnumerator',
    'flock',
    'flodd?',
    'flonum?',
    'floor',
    'floor-quotient',
    'floor-remainder',
    'floor/',
    'flpositive?',
    'flround',
    'flsin',
    'flsqrt',
    'fltan',
    'fltruncate',
    'fluid->parameter',
    'fluid-bound?',
    'fluid-ref',
    'fluid-ref*',
    'fluid-set!',
    'fluid-thread-local?',
    'fluid-unset!',
    'fluid?',
    'flush-all-ports',
    'flush-output-port',
    'flzero?',
    'fmul',
    'fold',
    'fold-layout',
    'fold-left',
    'fold-matches',
    'fold-right',
    'fold-values',
    'foldt',
    'foldts',
    'foldts*',
    'foldts*-values',
    'for-all',
    'for-each',
    'force',
    'force-output',
    'foreign-call',
    'formal-name->char',
    'format',
    'fourth',
    'frame',
    'frame-address',
    'frame-arguments',
    'frame-bindings',
    'frame-dynamic-link',
    'frame-instruction-pointer',
    'frame-lookup-binding',
    'frame-mv-return-address',
    'frame-previous',
    'frame-procedure-name',
    'frame-return-address',
    'frame-stack-pointer',
    'frame?',
    'free-identifier=?',
    'free-ref',
    'free-set!',
    'fstat',
    'fsub',
    'fsync',
    'ftell',
    'ftruncate',
    'ftw',
    'future',
    'future?',
    'fx*',
    'fx*/carry',
    'fx+',
    'fx+/carry',
    'fx-',
    'fx-/carry',
    'fx<=?',
    'fx=?',
    'fx>?',
    'fxand',
    'fxarithmetic-shift',
    'fxarithmetic-shift-left',
    'fxarithmetic-shift-right',
    'fxbit-count',
    'fxbit-field',
    'fxbit-set?',
    'fxcopy-bit',
    'fxcopy-bit-field',
    'fxdiv',
    'fxdiv-and-mod',
    'fxdiv0',
    'fxdiv0-and-mod0',
    'fxeven?',
    'fxfirst-bit-set',
    'fxif',
    'fxior',
    'fxlength',
    'fxmax',
    'fxmin',
    'fxmod',
    'fxmod0',
    'fxnegative?',
    'fxnot',
    'fxodd?',
    'fxpositive?',
    'fxreverse-bit-field',
    'fxrotate-bit-field',
    'fxxor',
    'fxzero?',
    'gc',
    'gcd',
    'gcprof',
    'generate-temporaries',
    'generic-function-methods',
    'generic-function-name',
    'gensym',
    'get-bytevector-all',
    'get-bytevector-n',
    'get-bytevector-n!',
    'get-bytevector-some',
    'get-bytevector-some!',
    'get-char',
    'get-datum',
    'get-environment-variable',
    'get-environment-variables',
    'get-internal-real-time',
    'get-internal-run-time',
    'get-line',
    'get-output-string',
    'get-string-all',
    'get-string-n',
    'get-string-n!',
    'get-u8',
    'getaffinity',
    'getcwd',
    'getegid',
    'getenv',
    'geteuid',
    'getgid',
    'getgroups',
    'getpgrp',
    'getpid',
    'getppid',
    'getpriority',
    'getsid',
    'getter-with-setter',
    'gettext',
    'gettimeofday',
    'getuid',
    'gmtime',
    'goops-error',
    'greatest-fixnum',
    'guard',
    'halt',
    'handle-interrupts',
    'handle-request',
    'hash',
    'hash-by-identity',
    'hash-clear!',
    'hash-count',
    'hash-create-handle!',
    'hash-fold',
    'hash-for-each',
    'hash-for-each-handle',
    'hash-get-handle',
    'hash-map->list',
    'hash-ref',
    'hash-remove!',
    'hash-set!',
    'hash-table->alist',
    'hash-table-delete!',
    'hash-table-equivalence-function',
    'hash-table-exists?',
    'hash-table-fold',
    'hash-table-hash-function',
    'hash-table-keys',
    'hash-table-ref',
    'hash-table-ref/default',
    'hash-table-set!',
    'hash-table-size',
    'hash-table-update!',
    'hash-table-update!/default',
    'hash-table-values',
    'hash-table-walk',
    'hash-table?',
    'hashq',
    'hashq-create-handle!',
    'hashq-get-handle',
    'hashq-ref',
    'hashq-remove!',
    'hashq-set!',
    'hashtable-clear!',
    'hashtable-contains?',
    'hashtable-copy',
    'hashtable-delete!',
    'hashtable-entries',
    'hashtable-equivalence-function',
    'hashtable-hash-function',
    'hashtable-keys',
    'hashtable-mutable?',
    'hashtable-ref',
    'hashtable-set!',
    'hashtable-size',
    'hashtable-update!',
    'hashtable?',
    'hashv',
    'hashv-create-handle!',
    'hashv-get-handle',
    'hashv-ref',
    'hashv-remove!',
    'hashv-set!',
    'hashx-create-handle!',
    'hashx-get-handle',
    'hashx-ref',
    'hashx-remove!',
    'hashx-set!',
    'header->string',
    'header-parser',
    'header-validator',
    'header-writer',
    'help',
    'hook->list',
    'hook-empty?',
    'hook?',
    'http',
    'http-delete',
    'http-get',
    'http-head',
    'http-options',
    'http-post',
    'http-put',
    'http-request',
    'http-trace',
    'i/o-decoding-error?',
    'i/o-encoding-error-char',
    'i/o-encoding-error?',
    'i/o-error-filename',
    'i/o-error-port',
    'i/o-error-position',
    'i/o-error?',
    'i/o-file-already-exists-error?',
    'i/o-file-does-not-exist-error?',
    'i/o-file-is-read-only-error?',
    'i/o-file-protection-error?',
    'i/o-filename-error?',
    'i/o-invalid-position-error?',
    'i/o-port-error?',
    'i/o-read-error?',
    'i/o-write-error?',
    'identifier-syntax',
    'identifier?',
    'identity',
    'if',
    'imag-part',
    'implementation-restriction-violation?',
    'import',
    'in',
    'include',
    'include-from-path',
    'inet-lnaof',
    'inet-makeaddr',
    'inet-netof',
    'inet-ntop',
    'inet-pton',
    'inexact',
    'inexact->exact',
    'inexact?',
    'inf',
    'inf?',
    'infinite?',
    'input-port?',
    'inspect',
    'install-suspendable-ports!',
    'install-trap-handler!',
    'instance?',
    'instrumented-source-files',
    'instrumented/executed-lines',
    'integer->char',
    'integer->list',
    'integer-expt',
    'integer-length',
    'integer-valued?',
    'integer?',
    'interaction-environment',
    'iota',
    'irritants-condition?',
    'is-a?',
    'isatty?',
    'join-timeout-exception?',
    'julian-day->date',
    'julian-day->time-monotonic',
    'julian-day->time-tai',
    'julian-day->time-utc',
    'keyword->string',
    'keyword->symbol',
    'keyword-flatten',
    'keyword?',
    'known-header?',
    'lalr-parser',
    'lambda',
    'lambda*',
    'language',
    'last',
    'last-pair',
    'latin-1-codec',
    'lazy',
    'lchown',
    'lcm',
    'least-fixnum',
    'left-justify-string',
    'length',
    'length+',
    'let',
    'let*',
    'let*-values',
    'let-escape-continuation',
    'let-keywords',
    'let-keywords*',
    'let-optional',
    'let-optional*',
    'let-syntax',
    'let-values',
    'let/ec',
    'letpar',
    'letrec',
    'letrec*',
    'letrec-syntax',
    'lexical-violation?',
    'library',
    'line-execution-counts',
    'link',
    'link-assembly',
    'list',
    'list->array',
    'list->bitvector',
    'list->c32vector',
    'list->c64vector',
    'list->char-set',
    'list->char-set!',
    'list->f32vector',
    'list->f64vector',
    'list->integer',
    'list->s16vector',
    'list->s32vector',
    'list->s64vector',
    'list->s8vector',
    'list->stream',
    'list->string',
    'list->symbol',
    'list->typed-array',
    'list->u16vector',
    'list->u32vector',
    'list->u64vector',
    'list->u8vector',
    'list->vector',
    'list->vlist',
    'list->weak-vector',
    'list-cdr-ref',
    'list-cdr-set!',
    'list-copy',
    'list-head',
    'list-index',
    'list-matches',
    'list-ref',
    'list-set!',
    'list-sort',
    'list-tabulate',
    'list-tail',
    'list-traps',
    'list=',
    'list?',
    'load',
    'load-compiled',
    'load-extension',
    'load-f64',
    'load-from-path',
    'load-s64',
    'load-thunk-from-file',
    'load-thunk-from-memory',
    'load-typed-array',
    'load-u64',
    'local-compile',
    'local-eval',
    'locale-am-string',
    'locale-currency-symbol',
    'locale-currency-symbol-precedes-negative?',
    'locale-currency-symbol-precedes-positive?',
    'locale-date+time-format',
    'locale-date-format',
    'locale-day',
    'locale-day-short',
    'locale-decimal-point',
    'locale-digit-grouping',
    'locale-encoding',
    'locale-era',
    'locale-era-date+time-format',
    'locale-era-date-format',
    'locale-era-time-format',
    'locale-era-year',
    'locale-monetary-decimal-point',
    'locale-monetary-fractional-digits',
    'locale-monetary-grouping',
    'locale-monetary-negative-sign',
    'locale-monetary-positive-sign',
    'locale-monetary-thousands-separator',
    'locale-month',
    'locale-month-short',
    'locale-negative-separated-by-space?',
    'locale-negative-sign-position',
    'locale-no-regexp',
    'locale-pm-string',
    'locale-positive-separated-by-space?',
    'locale-positive-sign-position',
    'locale-string->inexact',
    'locale-string->integer',
    'locale-thousands-separator',
    'locale-time+am/pm-format',
    'locale-time-format',
    'locale-yes-regexp',
    'locale?',
    'locals',
    'localtime',
    'lock-mutex',
    'log',
    'log10',
    'log2-binary-factors',
    'logand',
    'logbit?',
    'logcount',
    'logior',
    'lognot',
    'logsub',
    'logtest',
    'logxor',
    'long-fmov',
    'long-mov',
    'lookahead-char',
    'lookahead-u8',
    'lookup-compilation-order',
    'lookup-language',
    'lookup-server-impl',
    'lset-adjoin',
    'lset-diff+intersection',
    'lset-diff+intersection!',
    'lset-difference',
    'lset-difference!',
    'lset-intersection',
    'lset-intersection!',
    'lset-union',
    'lset-union!',
    'lset-xor',
    'lset-xor!',
    'lset<=',
    'lset=',
    'lstat',
    'macro-binding',
    'macro-name',
    'macro-transformer',
    'macro-type',
    'macro?',
    'magnitude',
    'major-version',
    'make',
    'make-accessor',
    'make-arity',
    'make-array',
    'make-assertion-violation',
    'make-atomic-box',
    'make-binding',
    'make-bitvector',
    'make-buffered-input-port',
    'make-bytevector',
    'make-c-struct',
    'make-c32vector',
    'make-c64vector',
    'make-chunked-input-port',
    'make-chunked-output-port',
    'make-class',
    'make-closure',
    'make-completion-function',
    'make-compound-condition',
    'make-condition',
    'make-condition-type',
    'make-condition-variable',
    'make-custom-binary-input-port',
    'make-custom-binary-input/output-port',
    'make-custom-binary-output-port',
    'make-date',
    'make-doubly-weak-hash-table',
    'make-empty-attlist',
    'make-enumeration',
    'make-eq-hashtable',
    'make-eqv-hashtable',
    'make-error',
    'make-f32vector',
    'make-f64vector',
    'make-fluid',
    'make-foreign-object-type',
    'make-future',
    'make-generic',
    'make-guardian',
    'make-hash-table',
    'make-hashtable',
    'make-hook',
    'make-i/o-decoding-error',
    'make-i/o-encoding-error',
    'make-i/o-error',
    'make-i/o-file-already-exists-error',
    'make-i/o-file-does-not-exist-error',
    'make-i/o-file-is-read-only-error',
    'make-i/o-file-protection-error',
    'make-i/o-invalid-position-error',
    'make-i/o-port-error',
    'make-i/o-read-error',
    'make-i/o-write-error',
    'make-implementation-restriction-violation',
    'make-instance',
    'make-io-filename-error',
    'make-irritants-condition',
    'make-lexical-violation',
    'make-line-buffered-input-port',
    'make-list',
    'make-locale',
    'make-long-immediate',
    'make-long-long-immediate',
    'make-message-condition',
    'make-method',
    'make-mutex',
    'make-no-infinities-violation',
    'make-no-nans-violation',
    'make-non-continuable-violation',
    'make-non-immediate',
    'make-object-property',
    'make-parameter',
    'make-pointer',
    'make-polar',
    'make-procedure-with-setter',
    'make-prompt-tag',
    'make-q',
    'make-random-source',
    'make-record-constructor-descriptor',
    'make-record-type',
    'make-record-type-descriptor',
    'make-rectangular',
    'make-recursive-mutex',
    'make-regexp',
    'make-s16vector',
    'make-s32vector',
    'make-s64vector',
    'make-s8vector',
    'make-sandbox-module',
    'make-serious-condition',
    'make-shared-array',
    'make-short-immediate',
    'make-soft-port',
    'make-stack',
    'make-stream',
    'make-string',
    'make-struct-layout',
    'make-struct/no-tail',
    'make-symbol',
    'make-syntax-transformer',
    'make-syntax-violation',
    'make-tcp-server-socket',
    'make-text-wrapper',
    'make-thread',
    'make-thread-local-fluid',
    'make-time',
    'make-transcoder',
    'make-typed-array',
    'make-u16vector',
    'make-u32vector',
    'make-u64vector',
    'make-u8vector',
    'make-unbound-fluid',
    'make-undefined-variable',
    'make-undefined-violation',
    'make-unix-domain-server-socket',
    'make-variable',
    'make-variable-transformer',
    'make-vector',
    'make-vector/immediate',
    'make-violation',
    'make-vtable',
    'make-warning',
    'make-weak-key-hash-table',
    'make-weak-value-hash-table',
    'make-weak-vector',
    'make-who-condition',
    'malloc-stats',
    'map',
    'map!',
    'map-in-order',
    'map-union',
    'match',
    'match-lambda',
    'match-lambda*',
    'match-let',
    'match-let*',
    'match-letrec',
    'match-pattern',
    'match:count',
    'match:end',
    'match:prefix',
    'match:start',
    'match:string',
    'match:substring',
    'match:suffix',
    'max',
    'member',
    'memp',
    'memq',
    'memv',
    'merge',
    'merge!',
    'message-condition?',
    'method',
    'method-generic-function',
    'method-procedure',
    'method-source',
    'method-specializers',
    'micro-version',
    'min',
    'minor-version',
    'mkdir',
    'mknod',
    'mkstemp!',
    'mktime',
    'mod',
    'mod0',
    'modified-julian-day->date',
    'modified-julian-day->time-monotonic',
    'modified-julian-day->time-tai',
    'modified-julian-day->time-utc',
    'module',
    'module-add!',
    'module-box',
    'module-define!',
    'module-ref',
    'module-set!',
    'module-stexi-documentation',
    'module-use!',
    'module-uses',
    'module-variable',
    'modulo',
    'modulo-expt',
    'monetary-amount->locale-string',
    'monitor',
    'mov',
    'move->fdes',
    'mul',
    'mutex-level',
    'mutex-lock!',
    'mutex-locked?',
    'mutex-name',
    'mutex-owner',
    'mutex-specific',
    'mutex-specific-set!',
    'mutex-state',
    'mutex-unlock!',
    'mutex?',
    'n-for-each-par-map',
    'n-par-for-each',
    'n-par-map',
    'nan',
    'nan?',
    'native-endianness',
    'native-eol-style',
    'native-transcoder',
    'negate',
    'negative?',
    'newline',
    'next',
    'next-token',
    'next-token-of',
    'nftw',
    'ngettext',
    'nice',
    'nil?',
    'ninth',
    'no-applicable-method',
    'no-infinities-violation?',
    'no-method',
    'no-nans-violation?',
    'no-next-method',
    'node-closure',
    'node-eq?',
    'node-equal?',
    'node-join',
    'node-or',
    'node-parent',
    'node-pos',
    'node-reduce',
    'node-reverse',
    'node-self',
    'node-trace',
    'node-typeof?',
    'nodeset?',
    'non-continuable-violation?',
    'not',
    'not-pair?',
    'null-environment',
    'null-list?',
    'null-pointer?',
    'null?',
    'number->locale-string',
    'number->string',
    'number?',
    'numerator',
    'object->string',
    'object-properties',
    'object-property',
    'object-stexi-documentation',
    'odd?',
    'open',
    'open-bytevector-input-port',
    'open-bytevector-output-port',
    'open-fdes',
    'open-file',
    'open-file-input-port',
    'open-file-output-port',
    'open-input-file',
    'open-input-output-pipe',
    'open-input-pipe',
    'open-input-string',
    'open-output-file',
    'open-output-pipe',
    'open-output-string',
    'open-pipe',
    'open-pipe*',
    'open-server',
    'open-socket-for-uri',
    'opendir',
    'optimize',
    'option',
    'option-ref',
    'or',
    'output-port?',
    'package-stexi-documentation',
    'package-stexi-documentation-for-include',
    'package-stexi-extended-menu',
    'package-stexi-generic-menu',
    'package-stexi-standard-copying',
    'package-stexi-standard-menu',
    'package-stexi-standard-prologue',
    'package-stexi-standard-titlepage',
    'pair-fold',
    'pair-fold-right',
    'pair-for-each',
    'pair?',
    'par-for-each',
    'par-map',
    'parallel',
    'parameterize',
    'parse-c-struct',
    'parse-header',
    'parse-http-method',
    'parse-http-version',
    'parse-path',
    'parse-path-with-ellipsis',
    'parse-request-uri',
    'partition',
    'partition!',
    'pclose',
    'peek-char',
    'peek-next-char',
    'peg-record?',
    'peg-string-compile',
    'peg:end',
    'peg:start',
    'peg:string',
    'peg:substring',
    'peg:tree',
    'pipe',
    'pointer->bytevector',
    'pointer->procedure',
    'pointer->scm',
    'pointer->string',
    'pointer-address',
    'pointer?',
    'poll-coop-repl-server',
    'pop',
    'pop-dynamic-state',
    'pop-fluid',
    'popen',
    'port->fdes',
    'port->stream',
    'port-closed?',
    'port-column',
    'port-conversion-strategy',
    'port-encoding',
    'port-eof?',
    'port-filename',
    'port-for-each',
    'port-has-port-position?',
    'port-has-set-port-position!?',
    'port-line',
    'port-mode',
    'port-position',
    'port-revealed',
    'port-transcoder',
    'port?',
    'positive?',
    'post-order',
    'pre-post-order',
    'pretty-print',
    'primitive-eval',
    'primitive-exit',
    'primitive-fork',
    'primitive-generic-generic',
    'primitive-load',
    'primitive-load-path',
    'primitive-move->fdes',
    'print-options',
    'print-set!',
    'procedure',
    'procedure->pointer',
    'procedure-documentation',
    'procedure-execution-count',
    'procedure-name',
    'procedure-properties',
    'procedure-property',
    'procedure-source',
    'procedure-with-setter?',
    'procedure?',
    'profile',
    'program-arguments',
    'program-arguments-alist',
    'program-arities',
    'program-arity',
    'program-bindings',
    'program-code',
    'program-free-variable-ref',
    'program-free-variable-set!',
    'program-lambda-list',
    'program-num-free-variable',
    'program-sources',
    'program?',
    'promise?',
    'prompt',
    'proper-list?',
    'provide',
    'provided?',
    'push',
    'push-dynamic-state',
    'push-fluid',
    'put-bytevector',
    'put-char',
    'put-datum',
    'put-string',
    'put-u8',
    'putenv',
    'pwd',
    'q-empty-check',
    'q-empty?',
    'q-front',
    'q-length',
    'q-pop!',
    'q-push!',
    'q-rear',
    'q-remove!',
    'q?',
    'quasiquote',
    'quasisyntax',
    'quit',
    'quo',
    'quote',
    'quotient',
    'raise',
    'raise-continuable',
    'random',
    'random-integer',
    'random-real',
    'random-source-make-integers',
    'random-source-make-reals',
    'random-source-pseudo-randomize!',
    'random-source-randomize!',
    'random-source-state-ref',
    'random-source-state-set!',
    'random-source?',
    'random-state->datum',
    'random-state-from-platform',
    'random:exp',
    'random:hollow-sphere!',
    'random:normal',
    'random:normal-vector!',
    'random:solid-sphere!',
    'random:uniform',
    'rational-valued?',
    'rational?',
    'rationalize',
    're-export',
    'read',
    'read-char',
    'read-client',
    'read-delimited',
    'read-delimited!',
    'read-disable',
    'read-enable',
    'read-hash-extend',
    'read-header',
    'read-headers',
    'read-line',
    'read-line!',
    'read-options',
    'read-request',
    'read-request-body',
    'read-request-line',
    'read-response',
    'read-response-body',
    'read-response-line',
    'read-set!',
    'read-string',
    'read-text-line',
    'read-with-shared-structure',
    'readdir',
    'readline',
    'readline-disable',
    'readline-enable',
    'readline-options',
    'readline-port',
    'readline-set!',
    'readlink',
    'real->flonum',
    'real-part',
    'real-valued?',
    'real?',
    'rec',
    'receive',
    'receive-values',
    'record-accessor',
    'record-constructor',
    'record-constructor-descriptor',
    'record-field-mutable?',
    'record-modifier',
    'record-mutator',
    'record-predicate',
    'record-rtd',
    'record-type-descriptor',
    'record-type-descriptor?',
    'record-type-field-names',
    'record-type-fields',
    'record-type-generative?',
    'record-type-name',
    'record-type-opaque?',
    'record-type-parent',
    'record-type-sealed?',
    'record-type-uid',
    'record?',
    'redirect-port',
    'reduce',
    'reduce-right',
    'regexp-exec',
    'regexp-match?',
    'regexp-quote',
    'regexp-substitute',
    'regexp-substitute/global',
    'regexp?',
    'registers',
    'relative-ref?',
    'release-port-handle',
    'reload',
    'reload-module',
    'rem',
    'remainder',
    'remove',
    'remove!',
    'remove-class-accessors!',
    'remove-fdes-finalizer!',
    'remove-hook!',
    'remp',
    'remq',
    'remv',
    'rename',
    'rename-file',
    'repl-default-option-set!',
    'replace-range',
    'replace-titles',
    'request-absolute-uri',
    'request-accept',
    'request-accept-charset',
    'request-accept-encoding',
    'request-accept-language',
    'request-allow',
    'request-authorization',
    'request-cache-control',
    'request-connection',
    'request-content-encoding',
    'request-content-language',
    'request-content-length',
    'request-content-location',
    'request-content-md5',
    'request-content-range',
    'request-content-type',
    'request-date',
    'request-expect',
    'request-expires',
    'request-from',
    'request-headers',
    'request-host',
    'request-if-match',
    'request-if-modified-since',
    'request-if-none-match',
    'request-if-range',
    'request-if-unmodified-since',
    'request-last-modified',
    'request-max-forwards',
    'request-meta',
    'request-method',
    'request-port',
    'request-pragma',
    'request-proxy-authorization',
    'request-range',
    'request-referer',
    'request-te',
    'request-trailer',
    'request-transfer-encoding',
    'request-upgrade',
    'request-uri',
    'request-user-agent',
    'request-version',
    'request-via',
    'request-warning',
    'request?',
    'require',
    'require-extension',
    'reset',
    'reset-frame',
    'reset-hook!',
    'reset-parsed-entity-definitions!',
    'resolve',
    'resolve-interface',
    'resolve-module',
    'response-accept-ranges',
    'response-age',
    'response-allow',
    'response-body-port',
    'response-cache-control',
    'response-code',
    'response-connection',
    'response-content-encoding',
    'response-content-language',
    'response-content-length',
    'response-content-location',
    'response-content-md5',
    'response-content-range',
    'response-content-type',
    'response-date',
    'response-etag',
    'response-expires',
    'response-headers',
    'response-last-modified',
    'response-location',
    'response-must-not-include-body?',
    'response-port',
    'response-pragma',
    'response-proxy-authenticate',
    'response-reason-phrase',
    'response-retry-after',
    'response-server',
    'response-trailer',
    'response-transfer-encoding',
    'response-upgrade',
    'response-vary',
    'response-version',
    'response-via',
    'response-warning',
    'response-www-authenticate',
    'response?',
    'restricted-vector-sort!',
    'return-from-interrupt',
    'return-values',
    'reverse',
    'reverse!',
    'reverse-bit-field',
    'reverse-list->string',
    'reverse-list->vector',
    'reverse-vector->list',
    'rewinddir',
    'rewrite-cont',
    'rewrite-exp',
    'rewrite-term',
    'right-justify-string',
    'rmdir',
    'rotate-bit-field',
    'round',
    'round-ash',
    'round-quotient',
    'round-remainder',
    'round/',
    'run-hook',
    'run-server',
    's16vector',
    's16vector->list',
    's16vector-length',
    's16vector-ref',
    's16vector-set!',
    's16vector?',
    's32vector',
    's32vector->list',
    's32vector-length',
    's32vector-ref',
    's32vector-set!',
    's32vector?',
    's64->scm',
    's64vector',
    's64vector->list',
    's64vector-length',
    's64vector-ref',
    's64vector-set!',
    's64vector?',
    's8vector',
    's8vector->list',
    's8vector-length',
    's8vector-ref',
    's8vector-set!',
    's8vector?',
    'sanitize-response',
    'save-module-excursion',
    'scandir',
    'scheme-report-environment',
    'scm->f64',
    'scm->pointer',
    'scm->s64',
    'scm->u64',
    'scm->u64/truncate',
    'scm-error',
    'script-stexi-documentation',
    'sdocbook-flatten',
    'search-for-pattern',
    'search-path',
    'second',
    'seconds->time',
    'seed->random-state',
    'seek',
    'select',
    'select-kids',
    'sendfile',
    'serious-condition?',
    'serve-one-client',
    'set!',
    'set-box!',
    'set-buffered-input-continuation?!',
    'set-car!',
    'set-cdr!',
    'set-current-dynamic-state',
    'set-current-error-port',
    'set-current-input-port',
    'set-current-module',
    'set-current-output-port',
    'set-field',
    'set-fields',
    'set-object-properties!',
    'set-object-property!',
    'set-port-column!',
    'set-port-conversion-strategy!',
    'set-port-encoding!',
    'set-port-filename!',
    'set-port-line!',
    'set-port-position!',
    'set-port-revealed!',
    'set-procedure-properties!',
    'set-procedure-property!',
    'set-program-arguments',
    'set-readline-input-port!',
    'set-readline-output-port!',
    'set-readline-prompt!',
    'set-record-type-printer!',
    'set-source-properties!',
    'set-source-property!',
    'set-struct-vtable-name!',
    'set-symbol-property!',
    'set-time-nanosecond!',
    'set-time-second!',
    'set-time-type!',
    'set-tm:gmtoff',
    'set-tm:hour',
    'set-tm:isdst',
    'set-tm:mday',
    'set-tm:min',
    'set-tm:mon',
    'set-tm:sec',
    'set-tm:wday',
    'set-tm:yday',
    'set-tm:year',
    'set-tm:zone',
    'set-vm-trace-level!',
    'setaffinity',
    'setegid',
    'setenv',
    'seteuid',
    'setgid',
    'setgroups',
    'setlocale',
    'setpgid',
    'setpriority',
    'setsid',
    'setter',
    'setuid',
    'setvbuf',
    'seventh',
    'shallow-clone',
    'shared-array-increments',
    'shared-array-offset',
    'shared-array-root',
    'shift',
    'show',
    'signal-condition-variable',
    'simple-conditions',
    'simple-format',
    'sin',
    'sinh',
    'sint-list->bytevector',
    'sixth',
    'sizeof',
    'skip-until',
    'skip-while',
    'sloppy-assoc',
    'sloppy-assq',
    'sloppy-assv',
    'slot-bound-using-class?',
    'slot-bound?',
    'slot-definition-accessor',
    'slot-definition-allocation',
    'slot-definition-getter',
    'slot-definition-init-form',
    'slot-definition-init-keyword',
    'slot-definition-init-thunk',
    'slot-definition-init-value',
    'slot-definition-name',
    'slot-definition-options',
    'slot-definition-setter',
    'slot-exists-using-class?',
    'slot-exists?',
    'slot-init-function',
    'slot-missing',
    'slot-ref',
    'slot-ref-using-class',
    'slot-set!',
    'slot-set-using-class!',
    'slot-unbound',
    'sort',
    'sort!',
    'sort-list',
    'sort-list!',
    'sorted?',
    'source-properties',
    'source-property',
    'source:addr',
    'source:column',
    'source:file',
    'source:line',
    'span',
    'span!',
    'spawn-coop-repl-server',
    'spawn-server',
    'split-and-decode-uri-path',
    'split-at',
    'split-at!',
    'sqrt',
    'ssax:complete-start-tag',
    'ssax:make-elem-parser',
    'ssax:make-parser',
    'ssax:make-pi-parser',
    'ssax:read-attributes',
    'ssax:read-cdata-body',
    'ssax:read-char-data',
    'ssax:read-char-ref',
    'ssax:read-external-id',
    'ssax:read-markup-token',
    'ssax:read-pi-body-as-string',
    'ssax:reverse-collect-str-drop-ws',
    'ssax:skip-internal-dtd',
    'ssax:uri-string->symbol',
    'ssax:xml->sxml',
    'stable-sort',
    'stable-sort!',
    'stack-id',
    'stack-length',
    'stack-ref',
    'stack?',
    'standard-error-port',
    'standard-input-port',
    'standard-output-port',
    'start-stack',
    'stat',
    'stat:atime',
    'stat:atimensec',
    'stat:blksize',
    'stat:blocks',
    'stat:ctime',
    'stat:ctimensec',
    'stat:dev',
    'stat:gid',
    'stat:ino',
    'stat:mode',
    'stat:mtime',
    'stat:mtimensec',
    'stat:nlink',
    'stat:perms',
    'stat:rdev',
    'stat:size',
    'stat:type',
    'stat:uid',
    'static-patch!',
    'static-ref',
    'static-set!',
    'statistics',
    'statprof',
    'statprof-accumulated-time',
    'statprof-active?',
    'statprof-call-data->stats',
    'statprof-call-data-calls',
    'statprof-call-data-cum-samples',
    'statprof-call-data-name',
    'statprof-call-data-self-samples',
    'statprof-display',
    'statprof-fetch-call-tree',
    'statprof-fetch-stacks',
    'statprof-fold-call-data',
    'statprof-proc-call-data',
    'statprof-reset',
    'statprof-sample-count',
    'statprof-start',
    'statprof-stats-calls',
    'statprof-stats-cum-secs-in-proc',
    'statprof-stats-cum-secs-per-call',
    'statprof-stats-proc-name',
    'statprof-stats-self-secs-in-proc',
    'statprof-stats-self-secs-per-call',
    'statprof-stop',
    'status:exit-val',
    'status:stop-sig',
    'status:term-sig',
    'step',
    'stexi->plain-text',
    'stexi->shtml',
    'stexi->sxml',
    'stexi->texi',
    'stexi-extract-index',
    'stop-server-and-clients!',
    'stream',
    'stream->list',
    'stream->list&length',
    'stream->reversed-list',
    'stream->reversed-list&length',
    'stream->vector',
    'stream-append',
    'stream-car',
    'stream-cdr',
    'stream-concat',
    'stream-cons',
    'stream-constant',
    'stream-drop',
    'stream-drop-while',
    'stream-filter',
    'stream-fold',
    'stream-for-each',
    'stream-from',
    'stream-iterate',
    'stream-lambda',
    'stream-length',
    'stream-let',
    'stream-map',
    'stream-match',
    'stream-null?',
    'stream-of',
    'stream-pair?',
    'stream-range',
    'stream-ref',
    'stream-reverse',
    'stream-scan',
    'stream-take',
    'stream-take-while',
    'stream-unfold',
    'stream-unfolds',
    'stream-zip',
    'stream?',
    'strerror',
    'strftime',
    'string',
    'string->bytevector',
    'string->char-set',
    'string->char-set!',
    'string->date',
    'string->header',
    'string->keyword',
    'string->list',
    'string->number',
    'string->pointer',
    'string->relative-ref',
    'string->symbol',
    'string->uri',
    'string->uri-reference',
    'string->utf16',
    'string->utf32',
    'string->utf8',
    'string->wrapped-lines',
    'string-any',
    'string-append',
    'string-append/shared',
    'string-bytes-per-char',
    'string-capitalize',
    'string-capitalize!',
    'string-ci->symbol',
    'string-ci-hash',
    'string-ci<',
    'string-ci<=',
    'string-ci<=?',
    'string-ci<>',
    'string-ci',
    'string-ci>=',
    'string-ci>=?',
    'string-ci>?',
    'string-compare',
    'string-compare-ci',
    'string-concatenate',
    'string-concatenate-reverse',
    'string-concatenate-reverse/shared',
    'string-concatenate/shared',
    'string-contains',
    'string-contains-ci',
    'string-copy',
    'string-copy!',
    'string-count',
    'string-delete',
    'string-downcase',
    'string-downcase!',
    'string-drop',
    'string-drop-right',
    'string-every',
    'string-fill!',
    'string-filter',
    'string-fold',
    'string-fold-right',
    'string-foldcase',
    'string-for-each',
    'string-for-each-index',
    'string-hash',
    'string-hash-ci',
    'string-index',
    'string-index-right',
    'string-join',
    'string-length',
    'string-locale-ci?',
    'string-locale-downcase',
    'string-locale-titlecase',
    'string-locale-upcase',
    'string-locale?',
    'string-map',
    'string-map!',
    'string-match',
    'string-normalize-nfc',
    'string-normalize-nfd',
    'string-normalize-nfkc',
    'string-normalize-nfkd',
    'string-null?',
    'string-pad',
    'string-pad-right',
    'string-prefix-ci?',
    'string-prefix-length',
    'string-prefix-length-ci',
    'string-prefix?',
    'string-ref',
    'string-replace',
    'string-reverse',
    'string-reverse!',
    'string-rindex',
    'string-set!',
    'string-skip',
    'string-skip-right',
    'string-split',
    'string-suffix-ci?',
    'string-suffix-length',
    'string-suffix-length-ci',
    'string-suffix?',
    'string-tabulate',
    'string-take',
    'string-take-right',
    'string-titlecase',
    'string-titlecase!',
    'string-tokenize',
    'string-trim',
    'string-trim-both',
    'string-trim-right',
    'string-unfold',
    'string-unfold-right',
    'string-upcase',
    'string-upcase!',
    'string-utf8-length',
    'string-xcopy!',
    'string<',
    'string<=',
    'string<=?',
    'string<>',
    'string',
    'string>=',
    'string>=?',
    'string>?',
    'string?',
    'strptime',
    'strtod',
    'struct-ref',
    'struct-ref/immediate',
    'struct-ref/unboxed',
    'struct-set!',
    'struct-set!/immediate',
    'struct-set!/unboxed',
    'struct-vtable',
    'struct-vtable-name',
    'struct-vtable?',
    'struct?',
    'sub',
    'sub/immediate',
    'subr-call',
    'substring',
    'substring-fill!',
    'substring-move!',
    'substring/copy',
    'substring/read-only',
    'substring/shared',
    'subtract-duration',
    'subtract-duration!',
    'supports-source-properties?',
    'suspendable-continuation?',
    'sxml->string',
    'sxml->xml',
    'sxml-match',
    'sxml-match-let',
    'sxml-match-let*',
    'sxpath',
    'symbol',
    'symbol->keyword',
    'symbol->string',
    'symbol-append',
    'symbol-fref',
    'symbol-fset!',
    'symbol-hash',
    'symbol-interned?',
    'symbol-pref',
    'symbol-prefix-proc',
    'symbol-property',
    'symbol-property-remove!',
    'symbol-pset!',
    'symbol=?',
    'symbol?',
    'symlink',
    'sync',
    'sync-q!',
    'syntax',
    'syntax->datum',
    'syntax-case',
    'syntax-error',
    'syntax-local-binding',
    'syntax-locally-bound-identifiers',
    'syntax-module',
    'syntax-parameterize',
    'syntax-rules',
    'syntax-source',
    'syntax-violation',
    'syntax-violation-form',
    'syntax-violation-subform',
    'syntax-violation?',
    'system',
    'system*',
    'system-async-mark',
    'system-error-errno',
    'system-file-name-convention',
    'tail-apply',
    'tail-call',
    'tail-call-label',
    'tail-call/shuffle',
    'take',
    'take!',
    'take-after',
    'take-right',
    'take-until',
    'take-while',
    'take-while!',
    'tan',
    'tanh',
    'tcgetpgrp',
    'tcsetpgrp',
    'tenth',
    'terminated-thread-exception?',
    'texi->stexi',
    'texi-command-depth',
    'texi-fragment->stexi',
    'text-content-type?',
    'textdomain',
    'textual-port?',
    'the-environment',
    'third',
    'thread-join!',
    'thread-name',
    'thread-sleep!',
    'thread-specific',
    'thread-specific-set!',
    'thread-start!',
    'thread-terminate!',
    'thread-yield!',
    'thread?',
    'throw',
    'thunk?',
    'time',
    'time->seconds',
    'time-difference',
    'time-difference!',
    'time-monotonic->date',
    'time-monotonic->time-tai',
    'time-monotonic->time-tai!',
    'time-monotonic->time-utc',
    'time-monotonic->time-utc!',
    'time-nanosecond',
    'time-resolution',
    'time-second',
    'time-tai->date',
    'time-tai->julian-day',
    'time-tai->modified-julian-day',
    'time-tai->time-monotonic',
    'time-tai->time-monotonic!',
    'time-tai->time-utc',
    'time-tai->time-utc!',
    'time-type',
    'time-utc->date',
    'time-utc->julian-day',
    'time-utc->modified-julian-day',
    'time-utc->time-monotonic',
    'time-utc->time-monotonic!',
    'time-utc->time-tai',
    'time-utc->time-tai!',
    'time<=?',
    'time=?',
    'time>?',
    'time?',
    'times',
    'tm:gmtoff',
    'tm:hour',
    'tm:isdst',
    'tm:mday',
    'tm:min',
    'tm:mon',
    'tm:sec',
    'tm:wday',
    'tm:yday',
    'tm:year',
    'tm:zone',
    'tmpfile',
    'tmpnam',
    'tms:clock',
    'tms:cstime',
    'tms:cutime',
    'tms:stime',
    'tms:utime',
    'toplevel-box',
    'touch',
    'trace',
    'trace-calls-in-procedure',
    'trace-calls-to-procedure',
    'trace-instructions-in-procedure',
    'tracepoint',
    'transcoded-port',
    'transcoder-codec',
    'transcoder-eol-style',
    'transcoder-error-handling-mode',
    'transform-string',
    'transpose-array',
    'trap-at-procedure-call',
    'trap-at-procedure-ip-in-range',
    'trap-at-source-location',
    'trap-calls-in-dynamic-extent',
    'trap-calls-to-procedure',
    'trap-enabled?',
    'trap-frame-finish',
    'trap-in-dynamic-extent',
    'trap-in-procedure',
    'trap-instructions-in-dynamic-extent',
    'trap-instructions-in-procedure',
    'trap-matching-instructions',
    'trap-name',
    'truncate',
    'truncate-file',
    'truncate-quotient',
    'truncate-remainder',
    'truncate/',
    'truncated-print',
    'try-mutex',
    'ttyname',
    'typed-array?',
    'tzset',
    'u16vector',
    'u16vector->list',
    'u16vector-length',
    'u16vector-ref',
    'u16vector-set!',
    'u16vector?',
    'u32vector',
    'u32vector->list',
    'u32vector-length',
    'u32vector-ref',
    'u32vector-set!',
    'u32vector?',
    'u64->scm',
    'u64vector',
    'u64vector->list',
    'u64vector-length',
    'u64vector-ref',
    'u64vector-set!',
    'u64vector?',
    'u8-list->bytevector',
    'u8vector',
    'u8vector->list',
    'u8vector-length',
    'u8vector-ref',
    'u8vector-set!',
    'u8vector?',
    'uadd',
    'uadd/immediate',
    'ucs-range->char-set',
    'ucs-range->char-set!',
    'uint-list->bytevector',
    'ulogand',
    'ulogior',
    'ulogsub',
    'ulogxor',
    'ulsh',
    'ulsh/immediate',
    'umask',
    'umul',
    'umul/immediate',
    'unbox',
    'uncaught-exception-reason',
    'uncaught-exception?',
    'undefined-violation?',
    'unfold',
    'unfold-right',
    'unget-bytevector',
    'unget-char',
    'unget-string',
    'uninstall-suspendable-ports!',
    'unless',
    'unlink',
    'unlock-mutex',
    'unquote',
    'unquote-splicing',
    'unread-char',
    'unread-string',
    'unsetenv',
    'unsyntax',
    'unsyntax-splicing',
    'unwind',
    'unzip1',
    'unzip2',
    'unzip3',
    'unzip4',
    'unzip5',
    'up',
    'update-direct-method!',
    'update-direct-subclass!',
    'update-instance-for-different-class',
    'uri->string',
    'uri-decode',
    'uri-encode',
    'uri-fragment',
    'uri-host',
    'uri-path',
    'uri-port',
    'uri-query',
    'uri-reference?',
    'uri-scheme',
    'uri-userinfo',
    'uri?',
    'urlify',
    'ursh',
    'ursh/immediate',
    'use-modules',
    'usub',
    'usub/immediate',
    'utf-16-codec',
    'utf-8-codec',
    'utf16->string',
    'utf32->string',
    'utf8->string',
    'utime',
    'valid-header?',
    'value-history-enabled?',
    'values',
    'variable-bound?',
    'variable-ref',
    'variable-set!',
    'variable-unset!',
    'variable?',
    'vector',
    'vector->list',
    'vector->stream',
    'vector-any',
    'vector-append',
    'vector-binary-search',
    'vector-concatenate',
    'vector-copy',
    'vector-copy!',
    'vector-count',
    'vector-empty?',
    'vector-every',
    'vector-fill!',
    'vector-fold',
    'vector-fold-right',
    'vector-for-each',
    'vector-index',
    'vector-index-right',
    'vector-length',
    'vector-map',
    'vector-map!',
    'vector-move-left!',
    'vector-move-right!',
    'vector-ref',
    'vector-ref/immediate',
    'vector-reverse!',
    'vector-reverse-copy',
    'vector-reverse-copy!',
    'vector-set!',
    'vector-set!/immediate',
    'vector-skip',
    'vector-skip-right',
    'vector-sort',
    'vector-sort!',
    'vector-swap!',
    'vector-unfold',
    'vector-unfold-right',
    'vector=',
    'vector?',
    'version',
    'vhash-assoc',
    'vhash-assq',
    'vhash-assv',
    'vhash-cons',
    'vhash-consq',
    'vhash-consv',
    'vhash-delete',
    'vhash-delq',
    'vhash-delv',
    'vhash-fold',
    'vhash-fold*',
    'vhash-fold-right',
    'vhash-foldq*',
    'vhash-foldv*',
    'vhash?',
    'violation?',
    'vlist->list',
    'vlist-append',
    'vlist-cons',
    'vlist-delete',
    'vlist-drop',
    'vlist-filter',
    'vlist-fold',
    'vlist-fold-right',
    'vlist-for-each',
    'vlist-head',
    'vlist-length',
    'vlist-map',
    'vlist-null?',
    'vlist-ref',
    'vlist-reverse',
    'vlist-tail',
    'vlist-take',
    'vlist-unfold',
    'vlist-unfold-right',
    'vlist?',
    'vm-abort-continuation-hook',
    'vm-apply-hook',
    'vm-next-hook',
    'vm-pop-continuation-hook',
    'vm-push-continuation-hook',
    'vm-restore-continuation-hook',
    'vm-trace-level',
    'wait-condition-variable',
    'waitpid',
    'warning?',
    'weak-key-hash-table?',
    'weak-value-hash-table?',
    'weak-vector',
    'weak-vector-ref',
    'weak-vector-set!',
    'weak-vector?',
    'when',
    'while',
    'who-condition?',
    'width',
    'wind',
    'with-code-coverage',
    'with-continuation-barrier',
    'with-default-trap-handler',
    'with-dynamic-state',
    'with-ellipsis',
    'with-error-to-file',
    'with-error-to-port',
    'with-exception-handler',
    'with-fluid*',
    'with-fluids',
    'with-fluids*',
    'with-input-from-file',
    'with-input-from-port',
    'with-input-from-string',
    'with-mutex',
    'with-output-to-file',
    'with-output-to-port',
    'with-output-to-string',
    'with-parameters*',
    'with-readline-completion-function',
    'with-ssax-error-to-port',
    'with-syntax',
    'with-throw-handler',
    'write',
    'write-char',
    'write-client',
    'write-header',
    'write-headers',
    'write-request',
    'write-request-body',
    'write-request-line',
    'write-response',
    'write-response-body',
    'write-response-line',
    'write-with-shared-structure',
    'xcons',
    'xml->sxml',
    'xml-token-head',
    'xml-token-kind',
    'xml-token?',
    'xsubstring',
    'zero?',
    'zip',
]

scheme_functions = [
    'accidental-interface::calc-alteration',
    'accidental-interface::calc-glyph-name',
    'add-bar-glyph-print-procedure',
    'add-grace-property',
    'add-lyrics',
    'add-music',
    'add-music-fonts',
    'add-new-clef',
    'add-pango-fonts',
    'add-point',
    'add-quotable',
    'add-score',
    'add-simple-time-signature-style',
    'add-stroke-glyph',
    'add-stroke-straight',
    'add-text',
    'adjust-slash-stencil',
    'alist->hash-table',
    'alisttext-accidental-markup',
    'alterations-in-key',
    'ambitus-line::calc-gap',
    'ambitus::print',
    'annotate-padding',
    'annotate-spacing-spec',
    'annotate-y-interval',
    'argument-error',
    'arrow-stencil',
    'arrow-stencil-maker',
    'attributes',
    'average',
    'bar-line::calc-break-visibility',
    'bar-line::calc-glyph-name',
    'bar-line::calc-glyph-name-for-direction',
    'bar-line::compound-bar-line',
    'bar-line::draw-filled-box',
    'bar-line::widen-bar-extent-on-span',
    'base-length',
    'beam-exceptions',
    'beam::align-with-broken-parts',
    'beam::get-kievan-positions',
    'beam::get-kievan-quantized-positions',
    'beam::place-broken-parts-individually',
    'beam::slope-like-broken-parts',
    'beat-structure',
    'bend-spanner::print',
    'bend::arrow-head-stencil',
    'bend::calc-bend-x-begin',
    'bend::calc-bend-x-end',
    'bend::print',
    'bend::target-cautionary',
    'bend::text-string',
    'binary-search',
    'book-first-page',
    'boolean-or-number?',
    'boolean-or-symbol?',
    'box-grob-stencil',
    'box-stencil',
    'bracketify-stencil',
    'break-alignable-interface::self-alignment-of-anchor',
    'break-alignable-interface::self-alignment-opposite-of-anchor',
    'break-alignment-list',
    'breathe::midi-length',
    'cached-file-contents',
    'caesura-script-interface::before-line-breaking',
    'caesura-to-bar-line-or-divisio',
    'caesura-to-divisio',
    'calc-harmonic-pitch',
    'calc-printable-height',
    'calculate-compound-base-beat',
    'calculate-compound-beat-grouping',
    'calculate-compound-measure-length',
    'call-after-session',
    'centered-spanner-interface::calc-x-offset',
    'centered-stencil',
    'change-pitches',
    'cheap-list?',
    'check-context-path',
    'check-grob-path',
    'check-music-path',
    'check-quant-callbacks',
    'check-slope-callbacks',
    'chord-square::height',
    'chord-square::print',
    'chord-square::width',
    'circle-stencil',
    'clef-transposition-markup',
    'clef::print-modern-tab-if-set',
    'close-port-rename',
    'collect-book-music-for-book',
    'collect-bookpart-for-book',
    'collect-music-aux',
    'collect-music-for-book',
    'collect-scores-for-book',
    'color?',
    'comment',
    'completize-formats',
    'composed-markup-list',
    'construct-chord-elements',
    'context-change',
    'context-create',
    'context-defs-from-music',
    'context-find-or-create',
    'context-mod-from-music',
    'context-spec-music',
    'control-polygon::calc-text',
    'convert-to-pdf',
    'convert-to-png',
    'convert-to-ps',
    'coord-rotate',
    'coord-rotated',
    'coord-scale',
    'coord-translate',
    'copy-binary-file',
    'copy-repeat-chord',
    'count-list',
    'create-file-exclusive',
    'create-glyph-flag',
    'create-script',
    'cross-staff-connect',
    'cue-substitute',
    'cyclic-base-value',
    'debugf',
    'def-grace-function',
    'default-auto-beam-check',
    'default-flag',
    'define-bar-line',
    'define-event-class',
    'define-event-function',
    'define-fonts',
    'define-markup-command',
    'define-markup-command-internal',
    'define-markup-list-command',
    'define-music-function',
    'define-scheme-function',
    'define-syntax-function',
    'define-tag-group',
    'define-void-function',
    'degrees->radians',
    'descend-to-context',
    'determine-frets',
    'determine-split-list',
    'determine-string-fret-finger',
    'dir-basename',
    'display-lily-music',
    'display-music',
    'display-scheme-music',
    'dodecaphonic-no-repeat-rule',
    'dot-column-interface::pad-by-one-dot-width',
    'dots::calc-dot-count',
    'dots::calc-dot-stencil',
    'dots::calc-glyph-name',
    'dots::calc-staff-position',
    'dump-stencil-as-EPS',
    'duration->lily-string',
    'duration-dot-factor',
    'duration-length',
    'duration-line::calc',
    'duration-line::calc-thickness',
    'duration-line::print',
    'duration-log-factor',
    'duration-of-note',
    'duration-or-music?',
    'duration-visual',
    'duration-visual-length',
    'dynamic-text-spanner::before-line-breaking',
    'ec',
    'ellipse-radius',
    'ellipse-stencil',
    'empty-music',
    'end-broken-spanner?',
    'entity',
    'eo',
    'eoc',
    'eps-file->stencil',
    'eval-carefully',
    'event-cause',
    'event-chord',
    'event-chord-notes',
    'event-chord-pitches',
    'event-chord-reduce',
    'event-class-cons',
    'event-has-articulation?',
    'exact-rational?',
    'extract-beam-exceptions',
    'extract-music',
    'extract-named-music',
    'extract-typed-music',
    'find-child',
    'find-child-named',
    'find-named-props',
    'find-pitch-entry',
    'fingering::calc-text',
    'first-assoc',
    'first-bar-number-invisible',
    'first-bar-number-invisible-and-no-parenthesized-bar-numbers',
    'first-bar-number-invisible-save-broken-bars',
    'first-broken-spanner?',
    'first-member',
    'flat-flag',
    'flatten-alist',
    'flatten-list',
    'flip-stencil',
    'fold-some-music',
    'font-name-split',
    'font-name-style',
    'for-some-music',
    'format-bass-figure',
    'format-dal-segno-text',
    'format-dal-segno-text-brief',
    'format-mark-generic',
    'format-metronome-markup',
    'format-segno-mark-considering-bar-lines',
    'fraction->moment',
    'fraction?',
    'fret->pitch',
    'fret-board::calc-stencil',
    'fret-letter-tablature-format',
    'fret-number-tablature-format',
    'fret-number-tablature-format-banjo',
    'fret-parse-terse-definition-string',
    'function-chain',
    'generate-crop-stencil',
    'generate-preview-stencil',
    'get-bound-note-heads',
    'get-chord-shape',
    'get-next-unique-voice-name',
    'get-postscript-bbox',
    'get-tweakable-music',
    'get-woodwind-key-list',
    'glissando::calc-tab-extra-dy',
    'glissando::draw-tab-glissando',
    'grace-spacing::calc-shortest-duration',
    'grob-interpret-markup',
    'grob-list?',
    'grob-transformer',
    'grob::all-objects',
    'grob::compose-function',
    'grob::display-objects',
    'grob::has-interface',
    'grob::is-live?',
    'grob::name',
    'grob::offset-function',
    'grob::rhythmic-location',
    'grob::show-skylines-if-debug-skylines-set',
    'grob::unpure-Y-extent-from-stencil',
    'grob::when',
    'gs-cmd-args',
    'gs-safe-run',
    'gulp-file',
    'hairpin::calc-grow-direction',
    'hash-table->alist',
    'headers-property-alist-chain',
    'hook-stencil',
    'horizontal-slash-interval',
    'identifiers-doc-string',
    'ignatzek-chord-names',
    'index-or-markup?',
    'index?',
    'interpret-markup-list',
    'interval-bound',
    'interval-center',
    'interval-contains?',
    'interval-empty?',
    'interval-index',
    'interval-intersection',
    'interval-length',
    'interval-sane?',
    'interval-scale',
    'interval-union',
    'interval-widen',
    'invalidate-alterations',
    'is-absolute?',
    'item::extra-spacing-height-including-staff',
    'key-list-or-music?',
    'key-list-or-symbol?',
    'key-list?',
    'key-signature-interface::alteration-position',
    'key-signature-interface::alteration-positions',
    'key?',
    'layout->page-init',
    'layout-extract-page-properties',
    'layout-line-thickness',
    'layout-set-absolute-staff-size',
    'layout-set-absolute-staff-size-in-module',
    'layout-set-staff-size',
    'lilypond-all',
    'lilypond-main',
    'lilypond-version',
    'lilypond-version-outdated?',
    'list-insert-separator',
    'list-join',
    'lookup-markup-command',
    'lookup-markup-list-command',
    'ly-getcwd',
    'ly:accidental-interface::height',
    'ly:accidental-interface::horizontal-skylines',
    'ly:accidental-interface::print',
    'ly:accidental-interface::remove-tied',
    'ly:accidental-placement::calc-positioning-done',
    'ly:add-context-mod',
    'ly:add-interface',
    'ly:add-listener',
    'ly:add-option',
    'ly:align-interface::align-to-ideal-distances',
    'ly:align-interface::align-to-minimum-distances',
    'ly:alist-cilisp-identifier',
    'ly:chain-assoc-get',
    'ly:change-iterator::constructor',
    'ly:char-cistring',
    'ly:duration-compress',
    'ly:duration-dot-count',
    'ly:duration-factor',
    'ly:duration-length',
    'ly:duration-log',
    'ly:duration-scale',
    'ly:durationlist',
    'ly:grob-array-length',
    'ly:grob-array-ref',
    'ly:grob-array?',
    'ly:grob-basic-properties',
    'ly:grob-chain-callback',
    'ly:grob-common-refpoint',
    'ly:grob-common-refpoint-of-array',
    'ly:grob-default-font',
    'ly:grob-extent',
    'ly:grob-get-vertical-axis-group-index',
    'ly:grob-interfaces',
    'ly:grob-layout',
    'ly:grob-list->grob-array',
    'ly:grob-object',
    'ly:grob-original',
    'ly:grob-parent',
    'ly:grob-pqoffsets',
    'ly:listened-event-class?',
    'ly:listened-event-types',
    'ly:listener?',
    'ly:load',
    'ly:lyric-combine-music-iterator::constructor',
    'ly:lyric-extender::print',
    'ly:lyric-hyphen::print',
    'ly:lyric-hyphen::set-spacing-rods',
    'ly:make-book',
    'ly:make-book-part',
    'ly:make-context-mod',
    'ly:make-dispatcher',
    'ly:make-duration',
    'ly:make-event-class',
    'ly:make-global-context',
    'ly:make-global-translator',
    'ly:make-grob-properties',
    'ly:make-listener',
    'ly:make-moment',
    'ly:make-music',
    'ly:make-music-function',
    'ly:make-music-relative!',
    'ly:make-output-def',
    'ly:make-page-label-marker',
    'ly:make-page-permission-marker',
    'ly:make-pango-description-string',
    'ly:make-paper-outputter',
    'ly:make-pitch',
    'ly:make-prob',
    'ly:make-rotation',
    'ly:make-scale',
    'ly:make-scaling',
    'ly:make-score',
    'ly:make-skyline',
    'ly:make-spring',
    'ly:make-stencil',
    'ly:make-stream-event',
    'ly:make-transform',
    'ly:make-translation',
    'ly:make-unpure-pure-container',
    'ly:measure-grouping::print',
    'ly:measure-spanner::calc-connect-to-neighbors',
    'ly:measure-spanner::print',
    'ly:mensural-ligature::print',
    'ly:message',
    'ly:minimal-breaking',
    'ly:mm',
    'ly:module->alist',
    'ly:module-copy',
    'ly:modules-lookup',
    'ly:moment->string',
    'ly:moment-add',
    'ly:moment-div',
    'ly:moment-grace',
    'ly:moment-grace-denominator',
    'ly:moment-grace-numerator',
    'ly:moment-main',
    'ly:moment-main-denominator',
    'ly:moment-main-numerator',
    'ly:moment-mod',
    'ly:moment-mul',
    'ly:moment-sub',
    'ly:momentstring',
    'ly:number-pair->string',
    'ly:one-line-auto-height-breaking',
    'ly:one-line-breaking',
    'ly:one-page-breaking',
    'ly:optimal-breaking',
    'ly:option-usage',
    'ly:otf->cff',
    'ly:otf-font-glyph-info',
    'ly:otf-font-table-data',
    'ly:otf-font?',
    'ly:otf-glyph-count',
    'ly:otf-glyph-list',
    'ly:ottava-bracket::print',
    'ly:output-def-clone',
    'ly:output-def-lookup',
    'ly:output-def-parent',
    'ly:output-def-scope',
    'ly:output-def-set-variable!',
    'ly:output-def?',
    'ly:output-description',
    'ly:output-find-context-def',
    'ly:outputter-close',
    'ly:outputter-dump-stencil',
    'ly:outputter-dump-string',
    'ly:outputter-output-scheme',
    'ly:outputter-port',
    'ly:page-marker?',
    'ly:page-turn-breaking',
    'ly:pango-font-physical-fonts',
    'ly:pango-font?',
    'ly:paper-book-header',
    'ly:paper-book-pages',
    'ly:paper-book-paper',
    'ly:paper-book-performances',
    'ly:paper-book-scopes',
    'ly:paper-book-systems',
    'ly:paper-book?',
    'ly:paper-column::break-align-width',
    'ly:paper-column::print',
    'ly:paper-fonts',
    'ly:paper-get-font',
    'ly:paper-get-number',
    'ly:paper-outputscale',
    'ly:paper-score-paper-systems',
    'ly:paper-system-minimum-distance',
    'ly:paper-system?',
    'ly:parse-file',
    'ly:parse-init',
    'ly:parse-string-expression',
    'ly:parsed-undead-list!',
    'ly:parser-clear-error',
    'ly:parser-clone',
    'ly:parser-define!',
    'ly:parser-error',
    'ly:parser-has-error?',
    'ly:parser-include-string',
    'ly:parser-lookup',
    'ly:parser-output-name',
    'ly:parser-parse-string',
    'ly:parser-set-note-names',
    'ly:part-combine-iterator::constructor',
    'ly:partial-iterator::constructor',
    'ly:percent-repeat-interface::beat-slash',
    'ly:percent-repeat-interface::double-percent',
    'ly:percent-repeat-interface::percent',
    'ly:percent-repeat-iterator::constructor',
    'ly:perform-text-replacements',
    'ly:performance-headers',
    'ly:performance-write',
    'ly:piano-pedal-bracket::print',
    'ly:pitch-alteration',
    'ly:pitch-diff',
    'ly:pitch-negate',
    'ly:pitch-notename',
    'ly:pitch-octave',
    'ly:pitch-quartertones',
    'ly:pitch-semitones',
    'ly:pitch-steps',
    'ly:pitch-tones',
    'ly:pitch-transpose',
    'ly:pitchpoints',
    'ly:skyline-distance',
    'ly:skyline-empty?',
    'ly:skyline-height',
    'ly:skyline-max-height',
    'ly:skyline-max-height-position',
    'ly:skyline-merge',
    'ly:skyline-pad',
    'ly:skyline-pair?',
    'ly:skyline-touching-point',
    'ly:skyline?',
    'ly:skylines-for-stencil',
    'ly:slur::calc-control-points',
    'ly:slur::calc-cross-staff',
    'ly:slur::calc-direction',
    'ly:slur::height',
    'ly:slur::print',
    'ly:slur::pure-height',
    'ly:smob-protects',
    'ly:solve-spring-rod-problem',
    'ly:source-file?',
    'ly:source-files',
    'ly:spacing-spanner::calc-common-shortest-duration',
    'ly:spacing-spanner::set-springs',
    'ly:span-bar::before-line-breaking',
    'ly:span-bar::calc-anchor',
    'ly:span-bar::calc-glyph-name',
    'ly:span-bar::choose-model-bar-line',
    'ly:span-bar::print',
    'ly:span-bar::width',
    'ly:spanner-bound',
    'ly:spanner-broken-into',
    'ly:spanner-set-bound!',
    'ly:spanner::calc-normalized-endpoints',
    'ly:spanner::kill-zero-spanned-time',
    'ly:spanner::set-spacing-rods',
    'ly:spanner?',
    'ly:spawn',
    'ly:spring-set-inverse-compress-strength!',
    'ly:spring-set-inverse-stretch-strength!',
    'ly:spring?',
    'ly:staff-symbol-line-thickness',
    'ly:staff-symbol-referencer::callback',
    'ly:staff-symbol-staff-radius',
    'ly:staff-symbol-staff-space',
    'ly:staff-symbol::height',
    'ly:staff-symbol::print',
    'ly:stderr-redirect',
    'ly:stem-tremolo::calc-cross-staff',
    'ly:stem-tremolo::calc-direction',
    'ly:stem-tremolo::calc-shape',
    'ly:stem-tremolo::calc-slope',
    'ly:stem-tremolo::calc-width',
    'ly:stem-tremolo::calc-y-offset',
    'ly:stem-tremolo::print',
    'ly:stem-tremolo::pure-calc-y-offset',
    'ly:stem-tremolo::pure-height',
    'ly:stem-tremolo::width',
    'ly:stem::calc-cross-staff',
    'ly:stem::calc-default-direction',
    'ly:stem::calc-direction',
    'ly:stem::calc-length',
    'ly:stem::calc-positioning-done',
    'ly:stem::calc-stem-begin-position',
    'ly:stem::calc-stem-info',
    'ly:stem::height',
    'ly:stem::offset-callback',
    'ly:stem::print',
    'ly:stem::pure-calc-length',
    'ly:stem::pure-calc-stem-begin-position',
    'ly:stem::pure-height',
    'ly:stem::width',
    'ly:stencil-add',
    'ly:stencil-aligned-to',
    'ly:stencil-combine-at-edge',
    'ly:stencil-empty?',
    'ly:stencil-expr',
    'ly:stencil-extent',
    'ly:stencil-in-color',
    'ly:stencil-outline',
    'ly:stencil-rotate',
    'ly:stencil-rotate-absolute',
    'ly:stencil-scale',
    'ly:stencil-stack',
    'ly:stencil-translate',
    'ly:stencil-translate-axis',
    'ly:stencil?',
    'ly:stream-event?',
    'ly:string-cilist',
    'ly:transform?',
    'ly:translate-cpp-warning-scheme',
    'ly:translator-context',
    'ly:translator-description',
    'ly:translator-group?',
    'ly:translator-name',
    'ly:translator?',
    'ly:transpose-key-alist',
    'ly:ttf->pfa',
    'ly:ttf-ps-name',
    'ly:tuplet-bracket::calc-connect-to-neighbors',
    'ly:tuplet-bracket::calc-cross-staff',
    'ly:tuplet-bracket::calc-direction',
    'ly:tuplet-bracket::calc-positions',
    'ly:tuplet-bracket::calc-x-positions',
    'ly:tuplet-bracket::print',
    'ly:tuplet-iterator::constructor',
    'ly:tuplet-number::calc-cross-staff',
    'ly:tuplet-number::calc-x-offset',
    'ly:tuplet-number::calc-y-offset',
    'ly:tuplet-number::print',
    'ly:type1->pfa',
    'ly:unit',
    'ly:unpure-call',
    'ly:unpure-pure-container-pure-part',
    'ly:unpure-pure-container-unpure-part',
    'ly:unpure-pure-container?',
    'ly:usage',
    'ly:vaticana-ligature::print',
    'ly:verbose-output?',
    'ly:version',
    'ly:version?',
    'ly:volta-bracket-interface::print',
    'ly:volta-bracket::calc-shorten-pair',
    'ly:volta-repeat-iterator::constructor',
    'ly:volta-specced-music-iterator::constructor',
    'ly:vowel-transition::set-spacing-rods',
    'ly:warning',
    'ly:warning-located',
    'ly:wide-char->utf-8',
    'lyric-combine',
    'lyric-event',
    'lyric-hyphen::vaticana-style',
    'lyric-text::print',
    'magnification->font-size',
    'magstep',
    'make-apply-context',
    'make-articulation',
    'make-autochange-music',
    'make-bow-stencil',
    'make-c-time-signature-markup',
    'make-circle-stencil',
    'make-clef-set',
    'make-connected-line',
    'make-connected-path-stencil',
    'make-cue-clef-set',
    'make-cue-clef-unset',
    'make-default-fonts-tree',
    'make-duration-of-length',
    'make-ellipse-stencil',
    'make-engraver',
    'make-event-chord',
    'make-filled-box-stencil',
    'make-glyph-time-signature-markup',
    'make-grace-music',
    'make-graceless-rhythmic-location',
    'make-grob-property-override',
    'make-grob-property-revert',
    'make-grob-property-set',
    'make-harmonic',
    'make-line-stencil',
    'make-lyric-event',
    'make-lyric-repeat-count-formatter',
    'make-modal-inverter',
    'make-modal-transposer',
    'make-multi-measure-rest',
    'make-music',
    'make-non-relative-music',
    'make-oval-stencil',
    'make-page',
    'make-pango-font-tree',
    'make-part-combine-context-changes',
    'make-part-combine-marks',
    'make-partial-ellipse-stencil',
    'make-path-stencil',
    'make-performer',
    'make-property-set',
    'make-property-unset',
    'make-ps-images',
    'make-relative',
    'make-repeat',
    'make-rhythmic-location',
    'make-semitone->pitch',
    'make-sequential-music',
    'make-setting',
    'make-simultaneous-music',
    'make-skip-music',
    'make-span-event',
    'make-stencil-boxer',
    'make-stencil-circler',
    'make-tie-stencil',
    'make-tmpfile',
    'make-translator',
    'make-transparent-box-stencil',
    'make-type-checker',
    'make-voice-props-override',
    'make-voice-props-revert',
    'make-voice-props-set',
    'map-selected-alist-keys',
    'map-some-music',
    'markup',
    'markup->lily-string',
    'markup->string',
    'markup-command-list?',
    'markup-default-to-string-method',
    'markup-function?',
    'markup-lambda',
    'markup-lambda-listify',
    'markup-lambda-worker',
    'markup-list-lambda',
    'markup-list?',
    'measure-counter::text',
    'memoize-clef-names',
    'mensural-flag',
    'middle-broken-spanner?',
    'midi-program',
    'mkdir-if-not-exist',
    'mmrest-of-length',
    'modern-straight-flag',
    'modified-font-metric-font-scaling',
    'moment->fraction',
    'moment-min',
    'moment-pair?',
    'move-chord-note',
    'multi-measure-rest',
    'music->lily-string',
    'music->make-music',
    'music-clone',
    'music-elements',
    'music-filter',
    'music-function',
    'music-function-call-error',
    'music-has-property?',
    'music-invert',
    'music-is-of-type?',
    'music-map',
    'music-name?',
    'music-pitches',
    'music-property-value?',
    'music-property?',
    'music-selective-filter',
    'music-selective-map',
    'music-separator?',
    'music-to-musicxml',
    'music-to-xml',
    'music-type-predicate',
    'neo-modern-accidental-rule',
    'no-flag',
    'normal-flag',
    'not-first-broken-spanner?',
    'not-last-broken-spanner?',
    'note-head::brew-ez-stencil',
    'note-head::calc-duration-log',
    'note-head::calc-glyph-name',
    'note-head::calc-kievan-duration-log',
    'note-name->german-markup',
    'note-name->lily-string',
    'note-name->markup',
    'note-name->string',
    'note-name-markup',
    'note-names-language',
    'note-to-cluster',
    'notes-to-clusters',
    'number-format',
    'number-list?',
    'number-or-grob?',
    'number-or-pair?',
    'number-or-string?',
    'number-pair-list?',
    'number-pair?',
    'numbered-footnotes',
    'object-type',
    'object-type-name',
    'octave->lily-string',
    'offset-add',
    'offset-flip-y',
    'offset-fret',
    'offset-scale',
    'offsetter',
    'old-straight-flag',
    'only-if-beamed',
    'ordered-cons',
    'other-axis',
    'output-file',
    'output-module?',
    'output-scopes',
    'output-stencil',
    'output-stencils',
    'oval-stencil',
    'override-head-style',
    'override-time-signature-setting',
    'page-stencil',
    'pango-pf-file-name',
    'pango-pf-font-name',
    'pango-pf-fontindex',
    'paper-system-annotate',
    'paper-system-annotate-last',
    'paper-system-extent',
    'paper-system-layout',
    'paper-system-staff-extents',
    'paper-system-stencil',
    'paper-system-system-grob',
    'paper-system-title?',
    'parentheses-interface::calc-angled-bracket-stencils',
    'parentheses-interface::calc-parenthesis-stencils',
    'parentheses-interface::print',
    'parentheses-interface::y-extent',
    'parenthesize-elements',
    'parenthesize-stencil',
    'parse-terse-string',
    'partial-markup',
    'partial-music-function',
    'partial-text-script',
    'percussion?',
    'pitch-invert',
    'pitch-of-note',
    'polar->rectangular',
    'postprocess-output',
    'postscript->pdf',
    'postscript->png',
    'postscript->ps',
    'prepend-alist-chain',
    'pretty-printable?',
    'print-book-with-defaults',
    'print-book-with-defaults-as-systems',
    'print-circled-text-callback',
    'print-keys',
    'print-keys-verbose',
    'process-music',
    'property-revert',
    'property-unset',
    'property-value',
    'ps-embed-cff',
    'ps-font-command',
    'ps-page-count',
    'pure-chain-offset-callback',
    'pure-from-neighbor-interface::account-for-span-bar',
    'pure-from-neighbor-interface::extra-spacing-height',
    'pure-from-neighbor-interface::extra-spacing-height-at-beginning-of-line',
    'pure-from-neighbor-interface::extra-spacing-height-including-staff',
    'pure-from-neighbor-interface::pure-height',
    'randomize-rand-seed',
    'ratio->fret',
    'ratio->pitch',
    'rational-or-procedure?',
    'read-lily-expression',
    'recording-group-emulate',
    'remove-grace-property',
    'remove-whitespace',
    'repeat-alt',
    'repeat-tie::handle-tab-note-head',
    'repetition-chord',
    'reset-stencil-colors',
    'retrieve-glyph-flag',
    'retrograde-music',
    'reverse-interval',
    'revert-fontSize',
    'revert-head-style',
    'revert-props',
    'revert-time-signature-setting',
    'rgb-color',
    'rhythmic-location->file-string',
    'rhythmic-location->string',
    'rhythmic-location?',
    'rhythmic-location?',
    'robust-bar-number-function',
    'rounded-box-stencil',
    'safe-car',
    'safe-last',
    'scale->factor',
    'scale-beam-thickness',
    'scale-by-font-size',
    'scale-fontSize',
    'scale-layout',
    'scale-props',
    'scale?',
    'scheme?',
    'scm->string',
    'scorify-music',
    'script-interface::calc-x-offset',
    'script-or-side-position-cross-staff',
    'search-executable',
    'seconds->moment',
    'select-head-glyph',
    'self-alignment-interface::self-aligned-on-breakable',
    'semi-tie::calc-cross-staff',
    'sequential-alternative-music',
    'sequential-music',
    'sequential-music-to-chord-exceptions',
    'session-replay',
    'session-save',
    'session-start-record',
    'set-accidental-style',
    'set-default-paper-size',
    'set-global-fonts',
    'set-global-staff-size',
    'set-paper-dimension-variables',
    'set-paper-size',
    'shift-duration-log',
    'shift-one-duration-log',
    'shift-right-at-line-begin',
    'sign',
    'simultaneous-music',
    'skip->rest',
    'skip-of-length',
    'skip-of-moment-span',
    'skyline-pair-and-non-empty?',
    'skyline-pair::empty?',
    'space-lines',
    'span-bar::compound-bar-line',
    'split-list-by-separator',
    'stack-lines',
    'stack-stencil-line',
    'stack-stencils',
    'stack-stencils-padding-list',
    'staff-ellipsis::calc-y-extent',
    'staff-ellipsis::print',
    'staff-symbol::calc-widened-extent',
    'stderr',
    'stem-stub::extra-spacing-height',
    'stem-stub::pure-height',
    'stem-stub::width',
    'stem-tremolo::calc-tab-width',
    'stem::calc-duration-log',
    'stem::kievan-offset-callback',
    'stencil-true-extent',
    'stencil-whiteout',
    'stencil-whiteout-box',
    'stencil-whiteout-outline',
    'stencil-with-color',
    'straight-flag',
    'string-encode-integer',
    'string-endswith',
    'string-number::calc-text',
    'string-or-music?',
    'string-or-pair?',
    'string-or-symbol?',
    'string-regexp-substitute',
    'string-startswith',
    'stroke-finger::calc-text',
    'style-note-heads',
    'suggest-convert-ly-message',
    'symbol-concatenate',
    'symbol-footnotes',
    'symbol-key-alist?',
    'symbol-list-or-music?',
    'symbol-list-or-symbol?',
    'symbol-list?',
    'symlink-if-not-exist',
    'symlink-or-copy-if-not-exist',
    'symmetric-interval',
    'system-clipped-x-extent',
    'system-start-text::calc-x-offset',
    'system-start-text::calc-y-offset',
    'system-start-text::print',
    'tab-note-head::calc-glyph-name',
    'tab-note-head::print',
    'tab-note-head::whiteout-if-style-set',
    'tablature-position-on-lines',
    'tabvoice::draw-double-stem-for-half-notes',
    'tabvoice::make-double-stem-width-for-half-notes',
    'tag-group-get',
    'tags-keep-predicate',
    'tags-remove-predicate',
    'teaching-accidental-rule',
    'tempo',
    'text-mark-interface::calc-break-visibility',
    'text-mark-interface::calc-self-alignment-X',
    'tie::handle-tab-note-head',
    'trill-pitch-group::pure-height',
    'tuplet-number::calc-denominator-text',
    'tuplet-number::calc-direction',
    'tuplet-number::calc-fraction-text',
    'type-name',
    'unbroken-or-first-broken-spanner?',
    'unbroken-or-last-broken-spanner?',
    'unbroken-spanner?',
    'unfold-repeats',
    'unfold-repeats-fully',
    'uniq-list',
    'uniqued-alist',
    'unity-if-multimeasure',
    'unrelativable-music',
    'value->lily-string',
    'value-for-spanner-piece',
    'vector-for-each',
    'version-not-seen-message',
    'voicify-music',
    'void-music',
    'void?',
    'volta-bracket-interface::pure-height',
    'volta-bracket::calc-hook-visibility',
    'volta-spec-music',
    'warning',
    'with-music-match',
    'write-me',
    'write-performances-midis',
]

scheme_variables = [
    'accidental-interface::height',
    'all-backend-properties',
    'all-internal-grob-properties',
    'all-internal-translation-properties',
    'all-invisible',
    'all-music-font-encodings',
    'all-music-properties',
    'all-text-font-encodings',
    'all-translation-properties',
    'all-user-grob-properties',
    'all-user-translation-properties',
    'all-visible',
    'alteration-default-glyph-name-alist',
    'alteration-hufnagel-glyph-name-alist',
    'alteration-kievan-glyph-name-alist',
    'alteration-medicaea-glyph-name-alist',
    'alteration-mensural-glyph-name-alist',
    'alteration-vaticana-glyph-name-alist',
    'assoc-get',
    'axis-group-interface::height',
    'balloon::height',
    'begin-of-line-invisible',
    'begin-of-line-visible',
    'black',
    'blue',
    'brace-encoding-table',
    'car<',
    'center-invisible',
    'center-visible',
    'chain-assoc-get',
    'constante-hairpin',
    'create-script-function',
    'css-color',
    'current-outfile-name',
    'cyan',
    'darkblue',
    'darkcyan',
    'darkgreen',
    'darkmagenta',
    'darkred',
    'darkyellow',
    'debug-gc-object-lifetimes-test-object',
    'default-breath-alist',
    'default-chord-modifier-list',
    'default-measure-division-chord-placement-alist',
    'default-measure-division-lines-alist',
    'default-melisma-properties',
    'default-part-combine-context-change-state-machine-one',
    'default-part-combine-context-change-state-machine-two',
    'default-part-combine-mark-state-machine',
    'default-script-alist',
    'default-slur-details',
    'default-time-signature-settings',
    'dimension-arrows',
    'documented-paper-alist',
    'dynamic-default-volume',
    'empty-interval',
    'empty-markup',
    'empty-stencil',
    'end-of-line-invisible',
    'end-of-line-visible',
    'feta-design-size-mapping',
    'finger-glide::print',
    'flared-hairpin',
    'format-coda-mark',
    'format-mark-alphabet',
    'format-mark-barnumbers',
    'format-mark-box-alphabet',
    'format-mark-box-barnumbers',
    'format-mark-box-letters',
    'format-mark-box-numbers',
    'format-mark-circle-alphabet',
    'format-mark-circle-barnumbers',
    'format-mark-circle-letters',
    'format-mark-circle-numbers',
    'format-mark-letters',
    'format-mark-numbers',
    'format-segno-mark',
    'format-varcoda-mark',
    'glyph-encoding-table',
    'green',
    'grey',
    'grid-chord-name::calc-X-offset',
    'grid-chord-name::calc-Y-offset',
    'grob::always-Y-extent-from-stencil',
    'grob::always-horizontal-skylines-from-element-stencils',
    'grob::always-horizontal-skylines-from-stencil',
    'grob::always-vertical-skylines-from-element-stencils',
    'grob::always-vertical-skylines-from-stencil',
    'grob::unpure-horizontal-skylines-from-stencil',
    'grob::unpure-vertical-skylines-from-stencil',
    'guile-predicates',
    'instrument-names-alist',
    'interpret-markup',
    'interval-end',
    'interval-start',
    'lily-unit->bigpoint-factor',
    'lily-unit->mm-factor',
    'lilypond-exported-predicates',
    'lilypond-scheme-predicates',
    'magenta',
    'makam-alteration-glyph-name-alist',
    'markup-command-signature',
    'markup-function-as-string-method',
    'markup-function-category',
    'markup-function-properties',
    'markup-list-function?',
    'markup?',
    'median-measure-division-chord-placement-alist',
    'median-measure-division-lines-alist',
    'music-descriptions',
    'music-name-to-property-table',
    'ottavation-numbers',
    'ottavation-ordinals',
    'ottavation-simple-ordinals',
    'page-property',
    'paper-alist',
    'paper-variable',
    'point-stencil',
    'property-override',
    'property-set',
    'pure-from-neighbor-interface::height-if-pure',
    'red',
    'repeat',
    'rhythmic-location-bar-number',
    'rhythmic-location-measure-position',
    'score-grace-settings',
    'self-alignment-interface::y-aligned-on-self',
    'set-symbol',
    'side-position-interface::y-aligned-side',
    'slur::height',
    'slur::move-closer-to-tab-note-heads',
    'staff-symbol-referencer::callback',
    'standard-alteration-glyph-name-alist',
    'stencil-dispatch-alist',
    'supported-clefs',
    'symbol-keystring s1)
                  (symbol->string s2)))))

  (define (hash-keys h)
    "returns the list of keys of a hash table"
    (hash-fold
     (lambda (k v p)
       (append p (list k)))
     '()
     h))

  ;; the list of properties we also want to complete, besides all
  ;; user properties
  (define accepted-properties
    '(
      cross-staff
      positioning-done
      ))

  (define (user-property? prop)
    "is the property a user property?"
    (or (memq prop accepted-properties)
        (memq prop all-user-grob-properties)))

  (define (format-string-list list indent)
    "formats a list of strings as a python list"
    (cond
     ((null? list) "[]")
     (else
      (string-append
       "[\n"
       (string-join
        (map (lambda (s)
               (string-append
                (make-string (+ 4 indent) #\space)
                "\""
                s
                "\",\n"))
          list)
        "")
       (make-string indent #\space)
       "]"))))

  (define (format-dict-entry k v indent)
    "formats a dictionary entry: key and value are string"
    (string-append
     (make-string indent #\space)
     "\"" k "\": " v ",\n"))

  (define (format-interfaces h)
    "formats the interfaces from ly:all-grob-interfaces as a Python dict"
    (string-append
     (fold (lambda (k p)
             (string-append
              p
              (format-dict-entry
               (symbol->string k)
               (format-string-list
                (sort
                 (map symbol->string
                   (filter user-property?
                           (list-ref (hashq-ref h k) 2)))
                 string<)
                4)
               4)))
       "interfaces = {\n"
       (sort-symbol-list (hash-keys h)))
     "}\n"))

  (define (alist-keys alist)
    "returns the list of keys of the specified alist"
    (fold
     (lambda (l p)
       (append p (list (car l))))
     '()
     alist))

  (define (format-grob-interfaces)
    "writes out all grob interfaces as a Python dict"
    (string-append
     (fold (lambda (k p)
             (string-append
              p
              (format-dict-entry
               (symbol->string k)
               (format-string-list
                (sort
                 (map symbol->string
                      (let* ((desc (assq-ref all-grob-descriptions k))
                             (meta (assq-ref desc 'meta))
                             (ifaces (assq-ref meta 'interfaces))
                             (classes (assq-ref meta 'classes))
                             (cls-iface (lambda (cls . ifaces)
                                          (if (memq cls classes)
                                              ifaces
                                              '()))))
                        (append
                         (cls-iface 'Item 'item-interface)
                         (cls-iface 'Spanner 'spanner-interface)
                         (cls-iface 'Paper_column 'paper-column-interface 'item-interface)
                         (cls-iface 'System 'system-interface 'spanner-interface)
                         ifaces)))
                 string<)
                4)
               4)))
       "grobs = {\n"
       (sort-symbol-list (alist-keys all-grob-descriptions)))
     "}\n"))

  (define (format-context-properties)
    "writes out the list of context (translation) properties"
    (string-append
     "contextproperties = "
     (format-string-list
      (sort
       (map symbol->string all-user-translation-properties)
       string<)
      0)
     "\n"))

  (define (get-translator-names)
    "returns the list of names of all engravers"
    (map
     (lambda (t)
       (symbol->string
        (ly:translator-name t)))
     (ly:get-all-translators)))

  (define (format-translators)
    "writes the list of engravers and performers"
    (string-append
     "engravers = "
     (format-string-list
      (sort (get-translator-names) string-ci')
    word = word.replace('&', '&')
    return word

guilePage = urlopen(GUILE_URL).read()
guilePat = re.compile(r"([a-z\d\+\?\!\*&;/=:-]+)(.+)")

lyFunctionPage = urlopen(LY_FUNCTION_URL).read()
lyFunctionPat = re.compile(r'Function: (ly:.+)')

defineFunc = re.compile(r'\((?:define\*?|define-safe)-public\s+\(([->>> import ly.lex
    >>> txt = r"\relative c' { c d e f-^ g }"
    >>> s = ly.lex.state("lilypond")
    >>> for t in s.tokens(txt):
    ...     print(t, t.__class__.__name__)
    \relative Command
      Space
    c Name
    ' Unparsed
      Space
    { SequentialStart
      Space
    c Note
      Space
    d Note
      Space
    e Note
      Space
    f Note
    - Direction
    ^ ScriptAbbreviation
      Space
    g Note
      Space
    } SequentialEnd

A State() is used to parse text. The text is given to the tokens() method, that
returns an iterator iterating over Token instances as they are found. Each token
has a 'pos' and an 'end' attribute describing its position in the original
string.

While iterating over the tokens(), the State maintains information about what
kind of text is parsed. (So don't iterate over more than one call to tokens() of
the same State object at the same time.)

Use ly.lex.state("name") to get a state for a specific mode to start parsing with.
If you don't know the type of text, you can use ly.lex.guessState(text), where
text is the text you want to parse. A quick heuristic is then used to determine
the type of the text.

See for more information the documentation of the slexer module.

"""

from __future__ import unicode_literals

import re

from .. import slexer
from ._token import *
from ._mode import extensions, modes, guessMode


__all__ = [
    'State',
    'Parser', 'FallthroughParser',
    'Fridge',
    'extensions', 'modes', 'guessMode',
    'state', 'guessState',
    'Token',
    'Unparsed',
    'Space',
    'Newline',
    'Comment',
    'LineComment',
    'BlockComment',
    'BlockCommentStart',
    'BlockCommentEnd',
    'String',
    'StringStart',
    'StringEnd',
    'Character',
    'Numeric',
    'Error',
    'MatchStart',
    'MatchEnd',
    'Indent',
    'Dedent',
]


class Parser(slexer.Parser):
    re_flags = re.MULTILINE | re.UNICODE
    argcount = 0
    default = Unparsed
    mode = None
    
    def __init__(self, argcount = None):
        if argcount is not None:
            self.argcount = argcount

    def freeze(self):
        return (self.argcount,)


class FallthroughParser(Parser, slexer.FallthroughParser):
    pass


class State(slexer.State):
    def endArgument(self):
        """Decrease argcount and leave the parser if it would reach 0."""
        while self.depth() > 1:
            p = self.parser()
            if p.argcount == 1:
                self.leave()
            else:
                if p.argcount > 0:
                    p.argcount -= 1
                return
    
    def mode(self):
        """Returns the mode attribute of the first parser (from current parser) that has it."""
        for parser in self.state[::-1]:
            if parser.mode:
                return parser.mode


class Fridge(slexer.Fridge):
    def __init__(self, stateClass = State):
        super(Fridge, self).__init__(stateClass)


def state(mode):
    """Returns a State instance for the given mode."""
    return State(modes[mode]())


def guessState(text):
    """Returns a State instance, guessing the type of text."""
    return State(modes[guessMode(text)]())


python_ly-0.9.9/ly/lex/_mode.py0000644000000000000000000000705013615410400013351 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Registry for the different modes used by the tokenizer.


There are two items in this module:

1. the modes dictionary.

   This maps a mode name to a function returning the base parser class for
   that mode.  (This way the corresponding module only needs to be imported
   when the mode is really needed.)

2. the guessMode function.

   This tries to guess the type of the given text and returns a mode name.


You can easily add more modes in separate modules and mention them here,

Don't use this module directly!  modes and guessMode are imported in the main
tokenize module.

"""

from __future__ import unicode_literals

__all__ = ['modes', 'guessMode']


def _modes():
    """Returns a dictionary mapping a mode name to a function.

    The function should return the initial Parser instance for that mode.

    """

    def lilypond():
        from . import lilypond
        return lilypond.ParseGlobal

    def scheme():
        from . import scheme
        return scheme.ParseScheme

    def docbook():
        from . import docbook
        return docbook.ParseDocBook

    def latex():
        from . import latex
        return latex.ParseLaTeX

    def texinfo():
        from . import texinfo
        return texinfo.ParseTexinfo

    def html():
        from . import html
        return html.ParseHTML

    def mup():
        from . import mup
        return mup.ParseMup

    # more modes can be added here
    return locals()


# dictionary mapping mode name to a function returning initial parser instance
# for that mode. Can also be used to test the existence of a mode
modes = _modes()
del _modes


def guessMode(text):
    """Tries to guess the type of the input text, using a quite fast heuristic.

    Returns one of the strings also present as key in the modes dictionary.

    """
    text = text.lstrip()
    if text.startswith(('%', '\\')):
        if '\\version' in text or '\\relative' in text or '\\score' in text:
            return "lilypond"
        if "\\documentclass" in text or "\\begin{document}" in text:
            return "latex"
        return "lilypond"
    if text.startswith("<<"):
        return "lilypond"
    if text.startswith("<"):
        if 'DOCTYPE book' in text or "'.format(module, name, contents, where)


class patternproperty(object):
    """Property that caches the return value of its function and returns that next time.
    
    Use this if the rx attribute (the pattern string to match tokens for) of a Token subclass
    is already costly to create and you want it created lazily (i.e. only when parsing starts):
    
    @patternproperty
    def rx():
        ...complicated function returning the regular expression string...
    
    """
    def __init__(self, func):
        self.func = func
        
    def __get__(self, instance, owner):
        try:
            return self.rx
        except AttributeError:
            self.rx = self.func()
            return self.rx


class Unparsed(Token):
    """Represents an unparsed piece of input text."""


# some token types with special behaviour:
class Item(Token):
    """A token that decreases the argument count of the current parser."""
    def update_state(self, state):
        state.endArgument()


class Leaver(Token):
    """A token that leaves the current parser."""
    def update_state(self, state):
        state.leave()


# some generic types:
class Space(Token):
    """A token containing whitespace."""
    rx = r'\s+'


class Newline(Space):
    """A token that is a single newline."""
    rx = r'\n'


# some base types that should be inherited:
class Comment(Token):
    """Base class for tokens that belong to a comment."""


class LineComment(Comment):
    """Base class for items that are a whole line comment."""
    
    
class BlockComment(Comment):
    """Base class for tokens that belong to a block/multiline comment."""


class BlockCommentStart(BlockComment):
    """Base class for tokens that start a block/multiline comment."""


class BlockCommentEnd(BlockComment):
    """Base class for tokens that end a block/multiline comment."""


class String(Token):
    """Base class for tokens that belong to a quote-delimited string."""
    
    
class StringStart(String):
    """Base class for tokens that start a quote-delimited string."""
    
    
class StringEnd(String):
    """Base class for tokens that end a quote-delimited string."""
    
    
class Character(Token):
    """Base class for tokens that are an (escaped) character."""
    
    
class Numeric(Token):
    """Base class for tokens that are a numerical value."""
    
    
class Error(Token):
    """Base class for tokens that represent erroneous input."""


# some mixin classes that make special handling of tokens possible besides correct parsing:

# MatchEnd and MatchStart can be used by parenthesis/brace matcher.
# the matchname class attribute defines the type, so that it is independent
# of the way other types could be nested.
class MatchStart(object):
    """Mixin class for tokens that have a matching token forward in the text.
    
    The matchname attribute should give a unique name.
    
    """
    matchname = ""


class MatchEnd(object):
    """Mixin class for tokens that have a matching token backward in the text.
    
    The matchname attribute should give a unique name.
    
    """
    matchname = ""


# Indent and Dedent can be used by an (auto) indenter.
class Indent(object):
    """Mixin class for tokens that have the text on the next line indent more."""


class Dedent(object):
    """Mixin class for tokens that have the text on the next line indent less."""


python_ly-0.9.9/ly/lex/docbook.py0000644000000000000000000000216413615410400013707 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Parses and tokenizes DocBook input, recognizing LilyPond in DocBook.
"""

from __future__ import unicode_literals

from . import _token
from . import Parser


class ParseDocBook(Parser):
    mode = "docbook"
    items = (
        _token.Space,
    )

python_ly-0.9.9/ly/lex/html.py0000644000000000000000000001137513615410400013237 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Parses and tokenizes HTML input, recognizing LilyPond in HTML.
"""

from __future__ import unicode_literals

from . import _token
from . import Parser, FallthroughParser

from . import lilypond


class Comment(_token.Comment):
    pass


class CommentStart(Comment, _token.BlockCommentStart):
    rx = r""


class String(_token.String):
    pass


class Tag(_token.Token):
    pass


class TagStart(Tag):
    rx = r""
    

class AttrName(_token.Token):
    rx = r"\w+([-_:]\w+)?"
    
    
class EqualSign(_token.Token):
    rx = "="
    def update_state(self, state):
        state.enter(ParseValue())


class Value(_token.Leaver):
    rx = r"\w+"
    

class StringDQStart(String, _token.StringStart):
    rx = r'"'
    def update_state(self, state):
        state.enter(ParseStringDQ())


class StringSQStart(String, _token.StringStart):
    rx = r"'"
    def update_state(self, state):
        state.enter(ParseStringSQ())
    

class StringDQEnd(String, _token.StringEnd, _token.Leaver):
    rx = r'"'
    

class StringSQEnd(String, _token.StringEnd, _token.Leaver):
    rx = r"'"


class EntityRef(_token.Character):
    rx = r"\&(#\d+|#[xX][0-9A-Fa-f]+|[A-Za-z_:][\w.:_-]*);"


class LilyPondTag(Tag):
    pass


class LilyPondVersionTag(LilyPondTag):
    rx = r""


class LilyPondFileTag(LilyPondTag):
    rx = r""


class LilyPondInlineTag(LilyPondTag):
    rx = r""
    
    
class LilyPondTagEnd(LilyPondTag):
    rx = r">"
    def update_state(self, state):
        state.replace(ParseLilyPond())


class LilyPondInlineTagEnd(LilyPondTag, _token.Leaver):
    rx = r"/?>"
    

class SemiColon(_token.Token):
    rx = r":"
    def update_state(self, state):
        state.replace(ParseLilyPondInline())



# Parsers:

class ParseHTML(Parser):
    mode = "html"
    items = (
        _token.Space,
        LilyPondVersionTag,
        LilyPondFileTag,
        LilyPondInlineTag,
        CommentStart,
        TagStart,
        EntityRef,
    )


class ParseAttr(Parser):
    items = (
        _token.Space,
        TagEnd,
        AttrName,
        EqualSign,
        StringDQStart,
        StringSQStart,
    )


class ParseStringDQ(Parser):
    default = String
    items = (
        StringDQEnd,
        EntityRef,
    )
    

class ParseStringSQ(Parser):
    default = String
    items = (
        StringSQEnd,
        EntityRef,
    )
    

class ParseComment(Parser):
    default = Comment
    items = (
        CommentEnd,
    )


class ParseValue(FallthroughParser):
    """Finds a value or drops back."""
    items = (
        _token.Space,
        Value,
    )
    def fallthrough(self, state):
        state.leave()


class ParseLilyPondAttr(Parser):
    items = (
        _token.Space,
        AttrName,
        EqualSign,
        StringDQStart,
        StringSQStart,
        LilyPondTagEnd,
        SemiColon,
    )
    

class ParseLilyPondFileOptions(Parser):
    items = (
        _token.Space,
        AttrName,
        EqualSign,
        StringDQStart,
        StringSQStart,
        LilyPondFileTagEnd,
    )


class ParseLilyPond(lilypond.ParseGlobal):
    items = (
        LilyPondCloseTag,
    ) + lilypond.ParseGlobal.items
    

class ParseLilyPondInline(lilypond.ParseMusic):
    items = (
        LilyPondInlineTagEnd,
    ) + lilypond.ParseMusic.items
    

python_ly-0.9.9/ly/lex/latex.py0000644000000000000000000000215513615410400013404 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Parses and tokenizes LaTeX input, recognizing LilyPond in LaTeX.
"""

from __future__ import unicode_literals

from . import _token
from . import Parser


class ParseLaTeX(Parser):
    mode = "latex"
    items = (
        _token.Space,
    )


python_ly-0.9.9/ly/lex/lilypond.py0000644000000000000000000010703713615410400014126 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Parses and tokenizes LilyPond input.
"""

from __future__ import unicode_literals

import itertools

from . import _token
from . import Parser, FallthroughParser

# an identifier allowing letters and single hyphens in between
re_identifier = r"[^\W\d_]+([_-][^\W\d_]+)*"

# the lookahead pattern for the end of an identifier (ref)
re_identifier_end = r"(?![_-]?[^\W\d])"

re_articulation = r"[-_^][_.>|!+^-]"
re_dynamic = (
    r"\\[]|"
    r"\\(f{1,5}|p{1,5}"
    r"|mf|mp|fp|spp?|sff?|sfz|rfz|n"
    r"|cresc|decresc|dim|cr|decr"
    r")(?![A-Za-z])")

re_duration = rf"(\\(maxima|longa|breve){re_identifier_end}|(1|2|4|8|16|32|64|128|256|512|1024|2048)(?!\d))"

re_dot = r"\."
re_scaling = r"\*[\t ]*\d+(/\d+)?"



class Identifier(_token.Token):
    """A variable name, like ``some-variable``."""
    rx = r"(?>"
    matchname = "simultaneous"
    def update_state(self, state):
        state.leave()
        state.endArgument()


class SequentialStart(OpenBracket):
    def update_state(self, state):
        state.enter(ParseMusic())


class SequentialEnd(CloseBracket):
    pass


class SimultaneousStart(OpenSimultaneous):
    def update_state(self, state):
        state.enter(ParseMusic())


class SimultaneousEnd(CloseSimultaneous):
    pass


class PipeSymbol(Delimiter):
    rx = r"\|"


class Articulation(_token.Token):
    """Base class for articulation things."""


class ArticulationCommand(Articulation, IdentifierRef):
    @classmethod
    def test_match(cls, match):
        s = match.group()[1:]
        if '-' not in s:
            from .. import words
            for l in (
                words.articulations,
                words.ornaments,
                words.fermatas,
                words.instrument_scripts,
                words.repeat_scripts,
                words.ancient_scripts,
            ):
                if s in l:
                    return True
        return False


class Direction(_token.Token):
    rx = r"[-_^]"
    def update_state(self, state):
        state.enter(ParseScriptAbbreviationOrFingering())


class ScriptAbbreviation(Articulation, _token.Leaver):
    rx = r"[+|!>._^-]"


class Fingering(Articulation, _token.Leaver):
    rx = r"\d+"


class StringNumber(Articulation):
    rx = r"\\\d+"


class Slur(_token.Token):
    pass


class SlurStart(Slur, _token.MatchStart):
    rx = r"\("
    matchname = "slur"


class SlurEnd(Slur, _token.MatchEnd):
    rx = r"\)"
    matchname = "slur"


class PhrasingSlurStart(SlurStart):
    rx = r"\\\("
    matchname = "phrasingslur"


class PhrasingSlurEnd(SlurEnd):
    rx = r"\\\)"
    matchname = "phrasingslur"


class Tie(Slur):
    rx = r"~"


class Beam(_token.Token):
    pass


class BeamStart(Beam, _token.MatchStart):
    rx = r"\["
    matchname = "beam"


class BeamEnd(Beam, _token.MatchEnd):
    rx = r"\]"
    matchname = "beam"


class Ligature(_token.Token):
    pass


class LigatureStart(Ligature, _token.MatchStart):
    rx = r"\\\["
    matchname = "ligature"


class LigatureEnd(Ligature, _token.MatchEnd):
    rx = r"\\\]"
    matchname = "ligature"


class Tremolo(_token.Token):
    pass


class TremoloColon(Tremolo):
    rx = r":"
    def update_state(self, state):
        state.enter(ParseTremolo())


class TremoloDuration(Tremolo, _token.Leaver):
    rx = r"\b(8|16|32|64|128|256|512|1024|2048)(?!\d)"


class ChordItem(_token.Token):
    """Base class for chordmode items."""


class ChordModifier(ChordItem):
    rx = r"((? 0:
            state.leave()
        state.leave()
        state.endArgument()


class Repeat(Command):
    rx = r"\\repeat" + re_identifier_end
    def update_state(self, state):
        state.enter(ParseRepeat())


class RepeatSpecifier(Specifier):
    @_token.patternproperty
    def rx():
        from .. import words
        return r"\b({0})(?![A-Za-z])".format("|".join(words.repeat_types))


class RepeatCount(IntegerValue, _token.Leaver):
    pass


class Tempo(Command):
    rx = r"\\tempo" + re_identifier_end
    def update_state(self, state):
        state.enter(ParseTempo())


class TempoSeparator(Delimiter):
    rx = r"[-~](?=\s*\d)"


class Partial(Command):
    rx = r"\\partial" + re_identifier_end


class Override(Keyword):
    rx = r"\\override" + re_identifier_end
    def update_state(self, state):
        state.enter(ParseOverride())


class Set(Override):
    rx = r"\\set" + re_identifier_end
    def update_state(self, state):
        state.enter(ParseSet())


class Revert(Override):
    rx = r"\\revert" + re_identifier_end
    def update_state(self, state):
        state.enter(ParseRevert())


class Unset(Keyword):
    rx = r"\\unset" + re_identifier_end
    def update_state(self, state):
        state.enter(ParseUnset())


class Tweak(Keyword):
    rx = r"\\tweak" + re_identifier_end
    def update_state(self, state):
        state.enter(ParseTweak())


class Translator(Command):
    def update_state(self, state):
        state.enter(ParseTranslator())


class New(Translator):
    rx = r"\\new" + re_identifier_end


class Context(Translator):
    rx = r"\\context" + re_identifier_end


class Change(Translator):
    rx = r"\\change" + re_identifier_end


class AccidentalStyle(Command):
    rx = r"\\accidentalStyle" + re_identifier_end
    def update_state(self, state):
        state.enter(ParseAccidentalStyle())


class AccidentalStyleSpecifier(Specifier):
    @_token.patternproperty
    def rx():
        from .. import words
        return r"\b({0})(?!-?\w)".format("|".join(words.accidentalstyles))


class AlterBroken(Command):
    rx = r"\\alterBroken" + re_identifier_end
    def update_state(self, state):
        state.enter(ParseAlterBroken())


class Clef(Command):
    rx = r"\\clef" + re_identifier_end
    def update_state(self, state):
        state.enter(ParseClef())


class ClefSpecifier(Specifier):
    @_token.patternproperty
    def rx():
        from .. import words
        return r"\b({0})\b".format("|".join(words.clefs_plain))

    def update_state(self, state):
        state.leave()


class PitchCommand(Command):
    rx = r"\\(relative|transpose|transposition|key|octaveCheck)" + re_identifier_end
    def update_state(self, state):
        argcount = 2 if self == '\\transpose' else 1
        state.enter(ParsePitchCommand(argcount))


class KeySignatureMode(Command):
    @_token.patternproperty
    def rx():
        from .. import words
        return r"\\({0})(?![A-Za-z])".format("|".join(words.modes))


class Hide(Keyword):
    rx = r"\\hide" + re_identifier_end
    def update_state(self, state):
        state.enter(ParseHideOmit())


class Omit(Keyword):
    rx = r"\\omit" + re_identifier_end
    def update_state(self, state):
        state.enter(ParseHideOmit())


class Unit(Command):
    rx = r"\\(mm|cm|in|pt|bp)" + re_identifier_end


class InputMode(Command):
    pass


class LyricMode(InputMode):
    rx = r"\\(lyricmode|((old)?add)?lyrics|lyricsto)" + re_identifier_end
    def update_state(self, state):
        state.enter(ExpectLyricMode())


class Lyric(_token.Item):
    """Base class for Lyric items."""


class LyricText(Lyric):
    rx = r"[^\\\s\d\"]+"


class LyricHyphen(Lyric):
    rx = r"--(?=($|[\s\\]))"


class LyricExtender(Lyric):
    rx = r"__(?=($|[\s\\]))"


class LyricSkip(Lyric):
    rx = r"_(?=($|[\s\\]))"


class Figure(_token.Token):
    """Base class for Figure items."""


class FigureStart(Figure):
    rx = r"<"
    def update_state(self, state):
        state.enter(ParseFigure())


class FigureEnd(Figure, _token.Leaver):
    rx = r">"


class FigureBracket(Figure):
    rx = r"[][]"


class FigureStep(Figure):
    """A step figure number or the underscore."""
    rx = r"_|\d+"


class FigureAccidental(Figure):
    """A figure accidental."""
    rx = r"[-+!]+"


class FigureModifier(Figure):
    """A figure modifier."""
    rx = r"\\[\\!+]|/"


class NoteMode(InputMode):
    rx = r"\\(notes|notemode)" + re_identifier_end
    def update_state(self, state):
        state.enter(ExpectNoteMode())


class ChordMode(InputMode):
    rx = r"\\(chords|chordmode)" + re_identifier_end
    def update_state(self, state):
        state.enter(ExpectChordMode())


class DrumMode(InputMode):
    rx = r"\\(drums|drummode)" + re_identifier_end
    def update_state(self, state):
        state.enter(ExpectDrumMode())


class FigureMode(InputMode):
    rx = r"\\(figures|figuremode)"+ re_identifier_end
    def update_state(self, state):
        state.enter(ExpectFigureMode())


class UserCommand(IdentifierRef):
    pass


class SimultaneousOrSequentialCommand(Keyword):
    rx = r"\\(simultaneous|sequential)" + re_identifier_end


class SchemeStart(_token.Item):
    rx = "[#$](?![{}])"
    def update_state(self, state):
        from . import scheme
        state.enter(scheme.ParseScheme(1))


class ContextName(_token.Token):
    @_token.patternproperty
    def rx():
        from .. import words
        return r"\b({0})\b".format("|".join(words.contexts))


class BackSlashedContextName(ContextName):
    @_token.patternproperty
    def rx():
        from .. import words
        return r"\\({0})\b".format("|".join(words.contexts))


class GrobName(_token.Token):
    @_token.patternproperty
    def rx():
        from .. import data
        return r"\b({0})\b".format("|".join(data.grobs()))


class GrobProperty(Variable):
    rx = r"\b([a-z]+|[XY])(-([a-z]+|[XY]))*(?![\w])"


class ContextProperty(Variable):
    @_token.patternproperty
    def rx():
        from .. import data
        return r"\b({0})\b".format("|".join(data.context_properties()))


class PaperVariable(Variable):
    """A variable inside Paper. Always follow this one by UserVariable."""
    @classmethod
    def test_match(cls, match):
        from .. import words
        return match.group() in words.papervariables


class HeaderVariable(Variable):
    """A variable inside Header. Always follow this one by UserVariable."""
    @classmethod
    def test_match(cls, match):
        from .. import words
        return match.group() in words.headervariables


class LayoutVariable(Variable):
    """A variable inside Header. Always follow this one by UserVariable."""
    @classmethod
    def test_match(cls, match):
        from .. import words
        return match.group() in words.layoutvariables


class Chord(_token.Token):
    """Base class for Chord delimiters."""
    pass


class ChordStart(Chord):
    rx = r"<"
    def update_state(self, state):
        state.enter(ParseChord())


class ChordEnd(Chord, _token.Leaver):
    rx = r">"


class DrumChordStart(ChordStart):
    def update_state(self, state):
        state.enter(ParseDrumChord())


class DrumChordEnd(ChordEnd):
    pass


class ErrorInChord(Error):
    rx = "|".join((
        re_articulation, # articulation
        r"<<|>>", # double french quotes
        r"\\[\\\]\[\(\)()]", # slurs beams
        re_duration, # duration
        re_scaling, # scaling
    ))


class Name(UserVariable):
    r"""A variable name without \ prefix."""


class EqualSign(_token.Token):
    rx = r"="


# Parsers
class ParseLilyPond(Parser):
    mode = 'lilypond'

# basic stuff that can appear everywhere
space_items = (
    _token.Space,
    BlockCommentStart,
    LineComment,
)


base_items = space_items + (
    SchemeStart,
    StringQuotedStart,
)


# items that represent commands in both toplevel and music mode
command_items = (
    Repeat,
    PitchCommand,
    Override, Revert,
    Set, Unset,
    Hide, Omit,
    Tweak,
    New, Context, Change,
    With,
    Clef,
    Tempo,
    Partial,
    KeySignatureMode,
    AccidentalStyle,
    AlterBroken,
    SimultaneousOrSequentialCommand,
    ChordMode, DrumMode, FigureMode, LyricMode, NoteMode,
    MarkupStart, MarkupLines, MarkupList,
    ArticulationCommand,
    Keyword,
    Command,
    SimultaneousOrSequentialCommand,
    UserCommand,
)


# items that occur in toplevel, book, bookpart or score
# no Leave-tokens!
toplevel_base_items = base_items + (
    SequentialStart,
    SimultaneousStart,
) + command_items


# items that occur in music expressions
music_items = base_items + (
    Dynamic,
    Skip,
    Spacer,
    Q,
    Rest,
    Note,
    Fraction,
    Length,
    Octave,
    OctaveCheck,
    AccidentalCautionary,
    AccidentalReminder,
    PipeSymbol,
    VoiceSeparator,
    SequentialStart, SequentialEnd,
    SimultaneousStart, SimultaneousEnd,
    ChordStart,
    ContextName,
    GrobName,
    SlurStart, SlurEnd,
    PhrasingSlurStart, PhrasingSlurEnd,
    Tie,
    BeamStart, BeamEnd,
    LigatureStart, LigatureEnd,
    Direction,
    StringNumber,
    IntegerValue,
) + command_items


# items that occur inside chords
music_chord_items = (
    ErrorInChord,
    ChordEnd,
) + music_items



class ParseGlobal(ParseLilyPond):
    """Parses LilyPond from the toplevel of a file."""
    items = (
        Book,
        BookPart,
        Score,
        MarkupStart, MarkupLines, MarkupList,
        Paper, Header, Layout,
    ) + toplevel_base_items + (
        Name,
        DotPath,
        EqualSign,
        Fraction,
        DecimalValue,
    )
    def update_state(self, state, token):
        if isinstance(token, EqualSign):
            state.enter(ParseGlobalAssignment())


class ParseGlobalAssignment(FallthroughParser, ParseLilyPond):
    items = space_items + (
        Skip,
        Spacer,
        Q,
        Rest,
        Note,
        Length,
        Fraction,
        DecimalValue,
        Direction,
        StringNumber,
        Dynamic,
    )


class ExpectOpenBracket(FallthroughParser, ParseLilyPond):
    """Waits for an OpenBracket and then replaces the parser with the class set in the replace attribute.

    Subclass this to set the destination for the OpenBracket.

    """
    default = Error
    items = space_items + (
        OpenBracket,
    )
    def update_state(self, state, token):
        if isinstance(token, OpenBracket):
            state.replace(self.replace())


class ExpectMusicList(FallthroughParser, ParseLilyPond):
    """Waits for an OpenBracket or << and then replaces the parser with the class set in the replace attribute.

    Subclass this to set the destination for the OpenBracket.

    """
    items = space_items + (
        OpenBracket,
        OpenSimultaneous,
        SimultaneousOrSequentialCommand,
    )
    def update_state(self, state, token):
        if isinstance(token, (OpenBracket, OpenSimultaneous)):
            state.replace(self.replace())


class ParseScore(ParseLilyPond):
    r"""Parses the expression after ``\score {``, leaving at ``}`` """
    items = (
        CloseBracket,
        Header, Layout, Midi, With,
    ) + toplevel_base_items


class ExpectScore(ExpectOpenBracket):
    replace = ParseScore


class ParseBook(ParseLilyPond):
    r"""Parses the expression after ``\book {``, leaving at ``}`` """
    items = (
        CloseBracket,
        MarkupStart, MarkupLines, MarkupList,
        BookPart,
        Score,
        Paper, Header, Layout,
    ) + toplevel_base_items



class ExpectBook(ExpectOpenBracket):
    replace = ParseBook


class ParseBookPart(ParseLilyPond):
    r"""Parses the expression after ``\bookpart {``, leaving at ``}`` """
    items = (
        CloseBracket,
        MarkupStart, MarkupLines, MarkupList,
        Score,
        Paper, Header, Layout,
    ) + toplevel_base_items


class ExpectBookPart(ExpectOpenBracket):
    replace = ParseBookPart


class ParsePaper(ParseLilyPond):
    r"""Parses the expression after ``\paper {``, leaving at ``}`` """
    items = base_items + (
        CloseBracket,
        MarkupStart, MarkupLines, MarkupList,
        PaperVariable,
        UserVariable,
        EqualSign,
        DotPath,
        DecimalValue,
        Unit,
    )


class ExpectPaper(ExpectOpenBracket):
    replace = ParsePaper


class ParseHeader(ParseLilyPond):
    r"""Parses the expression after ``\header {``, leaving at ``}`` """
    items = (
        CloseBracket,
        MarkupStart, MarkupLines, MarkupList,
        HeaderVariable,
        UserVariable,
        EqualSign,
        DotPath,
    ) + toplevel_base_items


class ExpectHeader(ExpectOpenBracket):
    replace = ParseHeader


class ParseLayout(ParseLilyPond):
    r"""Parses the expression after ``\layout {``, leaving at ``}`` """
    items = base_items + (
        CloseBracket,
        LayoutContext,
        LayoutVariable,
        UserVariable,
        EqualSign,
        DotPath,
        DecimalValue,
        Unit,
        ContextName,
        GrobName,
    ) + command_items


class ExpectLayout(ExpectOpenBracket):
    replace = ParseLayout


class ParseMidi(ParseLilyPond):
    r"""Parses the expression after ``\midi {``, leaving at ``}`` """
    items = base_items + (
        CloseBracket,
        LayoutContext,
        LayoutVariable,
        UserVariable,
        EqualSign,
        DotPath,
        DecimalValue,
        Unit,
        ContextName,
        GrobName,
    ) + command_items


class ExpectMidi(ExpectOpenBracket):
    replace = ParseMidi


class ParseWith(ParseLilyPond):
    r"""Parses the expression after ``\with {``, leaving at ``}`` """
    items = (
        CloseBracket,
        ContextName,
        GrobName,
        ContextProperty,
        EqualSign,
        DotPath,
    ) + toplevel_base_items


class ExpectWith(ExpectOpenBracket):
    replace = ParseWith


class ParseContext(ParseLilyPond):
    r"""Parses the expression after (``\layout {``) ``\context {``, leaving at ``}`` """
    items = (
        CloseBracket,
        BackSlashedContextName,
        ContextProperty,
        EqualSign,
        DotPath,
    ) + toplevel_base_items


class ExpectContext(ExpectOpenBracket):
    replace = ParseContext


class ParseMusic(ParseLilyPond):
    """Parses LilyPond music expressions."""
    items = music_items + (
        TremoloColon,
    )


class ParseChord(ParseMusic):
    """LilyPond inside chords ``< >``"""
    items = music_chord_items


class ParseString(Parser):
    default = String
    items = (
        StringQuotedEnd,
        StringQuoteEscape,
    )


class ParseBlockComment(Parser):
    default = BlockComment
    items = (
        BlockCommentEnd,
    )


class ParseMarkup(Parser):
    items =  (
        MarkupScore,
        MarkupCommand,
        MarkupUserCommand,
        OpenBracketMarkup,
        CloseBracketMarkup,
        MarkupWord,
    ) + base_items


class ParseRepeat(FallthroughParser):
    items = space_items + (
        RepeatSpecifier,
        StringQuotedStart,
        RepeatCount,
    )


class ParseTempo(FallthroughParser):
    items = space_items + (
        MarkupStart,
        StringQuotedStart,
        SchemeStart,
        Length,
        EqualSign,
    )
    def update_state(self, state, token):
        if isinstance(token, EqualSign):
            state.replace(ParseTempoAfterEqualSign())


class ParseTempoAfterEqualSign(FallthroughParser):
    items = space_items + (
        IntegerValue,
        TempoSeparator,
    )


class ParseDuration(FallthroughParser):
    items = space_items + (
        Dot,
    )
    def fallthrough(self, state):
        state.replace(ParseDurationScaling())


class ParseDurationScaling(ParseDuration):
    items = space_items + (
        Scaling,
    )
    def fallthrough(self, state):
        state.leave()


class ParseOverride(ParseLilyPond):
    argcount = 0
    items = (
        ContextName,
        DotPath,
        GrobName,
        GrobProperty,
        EqualSign,
    ) + base_items
    def update_state(self, state, token):
        if isinstance(token, EqualSign):
            state.replace(ParseDecimalValue())


class ParseRevert(FallthroughParser):
    r"""parse the arguments of ``\revert``"""
    # allow both the old scheme syntax but also the dotted 2.18+ syntax
    # allow either a dot between the GrobName and the property path or not
    # correctly fall through when one property path has been parsed
    # (uses ParseGrobPropertyPath and ExpectGrobProperty)
    # (When the old scheme syntax is used this parser also falls through,
    # assuming that the previous parser will handle it)
    items = space_items + (
        ContextName,
        DotPath,
        GrobName,
        GrobProperty,
    )
    def update_state(self, state, token):
        if isinstance(token, GrobProperty):
            state.replace(ParseGrobPropertyPath())


class ParseGrobPropertyPath(FallthroughParser):
    items = space_items + (
        DotPath,
    )
    def update_state(self, state, token):
        if isinstance(token, DotPath):
            state.enter(ExpectGrobProperty())


class ExpectGrobProperty(FallthroughParser):
    items = space_items + (
        GrobProperty,
    )
    def update_state(self, state, token):
        if isinstance(token, GrobProperty):
            state.leave()


class ParseSet(ParseLilyPond):
    argcount = 0
    items = (
        ContextName,
        DotPath,
        ContextProperty,
        EqualSign,
        Name,
    ) + base_items
    def update_state(self, state, token):
        if isinstance(token, EqualSign):
            state.replace(ParseDecimalValue())


class ParseUnset(FallthroughParser):
    items = space_items + (
        ContextName,
        DotPath,
        ContextProperty,
        Name,
    )
    def update_state(self, state, token):
        if isinstance(token, ContextProperty) or token[:1].islower():
            state.leave()


class ParseTweak(FallthroughParser):
    items = space_items + (
        GrobName,
        DotPath,
        GrobProperty,
    )
    def update_state(self, state, token):
        if isinstance(token, GrobProperty):
            state.replace(ParseTweakGrobProperty())


class ParseTweakGrobProperty(FallthroughParser):
    items = space_items + (
        DotPath,
        DecimalValue,
    )
    def update_state(self, state, token):
        if isinstance(token, DotPath):
            state.enter(ExpectGrobProperty())
        elif isinstance(token, DecimalValue):
            state.leave()


class ParseTranslator(FallthroughParser):
    items = space_items + (
        ContextName,
        Name,
    )

    def update_state(self, state, token):
        if isinstance(token, (Name, ContextName)):
            state.replace(ExpectTranslatorId())


class ExpectTranslatorId(FallthroughParser):
    items = space_items + (
        EqualSign,
    )

    def update_state(self, state, token):
        if token == '=':
            state.replace(ParseTranslatorId())


class ParseTranslatorId(FallthroughParser):
    argcount = 1
    items = space_items + (
        Name,
        StringQuotedStart,
    )

    def update_state(self, state, token):
        if isinstance(token, Name):
            state.leave()


class ParseClef(FallthroughParser):
    argcount = 1
    items = space_items + (
        ClefSpecifier,
        StringQuotedStart,
    )


class ParseHideOmit(FallthroughParser):
    items = space_items + (
        ContextName,
        DotPath,
        GrobName,
    )
    def update_state(self, state, token):
        if isinstance(token, GrobName):
            state.leave()


class ParseAccidentalStyle(FallthroughParser):
    items = space_items + (
        ContextName,
        DotPath,
        AccidentalStyleSpecifier,
    )
    def update_state(self, state, token):
        if isinstance(token, AccidentalStyleSpecifier):
            state.leave()


class ParseAlterBroken(FallthroughParser):
    items = space_items + (
        GrobProperty,
    )
    def update_state(self, state, token):
        if isinstance(token, GrobProperty):
            state.replace(ParseGrobPropertyPath())


class ParseScriptAbbreviationOrFingering(FallthroughParser):
    argcount = 1
    items = space_items + (
        ScriptAbbreviation,
        Fingering,
    )


class ParseInputMode(ParseLilyPond):
    """Base class for parser for mode-changing music commands."""
    @classmethod
    def update_state(cls, state, token):
        if isinstance(token, (OpenSimultaneous, OpenBracket)):
            state.enter(cls())


class ParseLyricMode(ParseInputMode):
    r"""Parser for ``\lyrics``, ``\lyricmode``, ``\addlyrics``, etc."""
    items = base_items + (
        CloseBracket,
        CloseSimultaneous,
        OpenBracket,
        OpenSimultaneous,
        PipeSymbol,
        LyricHyphen,
        LyricExtender,
        LyricSkip,
        LyricText,
        Dynamic,
        Skip,
        Length,
        MarkupStart, MarkupLines, MarkupList,
    ) + command_items


class ExpectLyricMode(ExpectMusicList):
    replace = ParseLyricMode
    items = space_items + (
        OpenBracket,
        OpenSimultaneous,
        SchemeStart,
        StringQuotedStart,
        Name,
        SimultaneousOrSequentialCommand,
    )


class ParseChordMode(ParseInputMode, ParseMusic):
    r"""Parser for ``\chords`` and ``\chordmode``."""
    items = (
        OpenBracket,
        OpenSimultaneous,
    ) + music_items + ( # TODO: specify items exactly, e.g. < > is not allowed
        ChordSeparator,
    )
    def update_state(self, state, token):
        if isinstance(token, ChordSeparator):
            state.enter(ParseChordItems())
        else:
            super(ParseChordMode, self).update_state(state, token)


class ExpectChordMode(ExpectMusicList):
    replace = ParseChordMode


class ParseNoteMode(ParseMusic):
    r"""Parser for ``\notes`` and ``\notemode``. Same as Music itself."""


class ExpectNoteMode(ExpectMusicList):
    replace = ParseNoteMode


class ParseDrumChord(ParseMusic):
    """LilyPond inside chords in drummode ``< >``"""
    items = base_items + (
        ErrorInChord,
        DrumChordEnd,
        Dynamic,
        Skip,
        Spacer,
        Q,
        Rest,
        DrumNote,
        Fraction,
        Length,
        PipeSymbol,
        VoiceSeparator,
        SequentialStart, SequentialEnd,
        SimultaneousStart, SimultaneousEnd,
        ChordStart,
        ContextName,
        GrobName,
        SlurStart, SlurEnd,
        PhrasingSlurStart, PhrasingSlurEnd,
        Tie,
        BeamStart, BeamEnd,
        LigatureStart, LigatureEnd,
        Direction,
        StringNumber,
        IntegerValue,
    ) + command_items


class ParseDrumMode(ParseInputMode, ParseMusic):
    r"""Parser for ``\drums`` and ``\drummode``."""
    items = (
        OpenBracket,
        OpenSimultaneous,
    ) + base_items + (
        Dynamic,
        Skip,
        Spacer,
        Q,
        Rest,
        DrumNote,
        Fraction,
        Length,
        PipeSymbol,
        VoiceSeparator,
        SequentialStart, SequentialEnd,
        SimultaneousStart, SimultaneousEnd,
        DrumChordStart,
        ContextName,
        GrobName,
        SlurStart, SlurEnd,
        PhrasingSlurStart, PhrasingSlurEnd,
        Tie,
        BeamStart, BeamEnd,
        LigatureStart, LigatureEnd,
        Direction,
        StringNumber,
        IntegerValue,
    ) + command_items


class ExpectDrumMode(ExpectMusicList):
    replace = ParseDrumMode


class ParseFigureMode(ParseInputMode, ParseMusic):
    r"""Parser for ``\figures`` and ``\figuremode``."""
    items = base_items + (
        CloseBracket,
        CloseSimultaneous,
        OpenBracket,
        OpenSimultaneous,
        PipeSymbol,
        FigureStart,
        Skip, Spacer, Rest,
        Length,
    ) + command_items


class ParseFigure(Parser):
    """Parse inside ``< >`` in figure mode."""
    items = base_items + (
        FigureEnd,
        FigureBracket,
        FigureStep,
        FigureAccidental,
        FigureModifier,
        MarkupStart, MarkupLines, MarkupList,
    )


class ExpectFigureMode(ExpectMusicList):
    replace = ParseFigureMode


class ParsePitchCommand(FallthroughParser):
    argcount = 1
    items = space_items + (
        Note,
        Octave,
    )
    def update_state(self, state, token):
        if isinstance(token, Note):
            self.argcount -= 1
        elif isinstance(token, _token.Space) and self.argcount <= 0:
            state.leave()


class ParseTremolo(FallthroughParser):
    items = (TremoloDuration,)


class ParseChordItems(FallthroughParser):
    items = (
        ChordSeparator,
        ChordModifier,
        ChordStepNumber,
        DotChord,
        Note,
    )


class ParseDecimalValue(FallthroughParser):
    """Parses a decimal value without a # before it (if present)."""
    items = space_items + (
        Fraction,
        DecimalValue,
    )
python_ly-0.9.9/ly/lex/mup.py0000644000000000000000000000411113615410400013062 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Parses and tokenizes MUP input.

MUP (www.arkkra.com) is an open source music typesetter (formerly shareware).

We add a tokenizer here, to enable a decent mup2ly conversion.

"""

from __future__ import unicode_literals


from . import _token
from . import Parser, FallthroughParser


class Comment(_token.Comment):
    pass


class LineComment(Comment):
    rx = r"//.*$"


class String(_token.String):
    pass


class StringQuotedStart(String, _token.StringStart):
    rx = r'"'
    def update_state(self, state):
        state.enter(ParseString())
        

class StringQuotedEnd(String, _token.StringEnd):
    rx = r'"'
    def update_state(self, state):
        state.leave()
        state.endArgument()


class StringQuoteEscape(_token.Character):
    rx = r'\\[\\"]'


class Macro(_token.Token):
    rx = r'\b[A-Z][A-Z0-9_]*'


class Preprocessor(_token.Token):
    rx = (r'\b('
        'if|then|else|endif|define|undef|ifdef|ifndef'
        r')\b|@')


class ParseMup(Parser):
    mode = "mup"
    items = (
        LineComment,
        StringQuotedStart,
        Macro,
        Preprocessor,
    )


class ParseString(Parser):
    default = String
    items = (
        StringQuotedEnd,
        StringQuoteEscape,
    )

python_ly-0.9.9/ly/lex/scheme.py0000644000000000000000000001121313615410400013526 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Parses and tokenizes Scheme input.
"""

from __future__ import unicode_literals

from . import _token
from . import Parser, FallthroughParser


class Scheme(_token.Token):
    """Baseclass for Scheme tokens."""
    pass


class String(_token.String):
    pass


class StringQuotedStart(String, _token.StringStart):
    rx = r'"'
    def update_state(self, state):
        state.enter(ParseString())
        

class StringQuotedEnd(String, _token.StringEnd):
    rx = r'"'
    def update_state(self, state):
        state.leave()
        state.endArgument()
    

class StringQuoteEscape(_token.Character):
    rx = r'\\[\\"]'


class Comment(_token.Comment):
    pass


class LineComment(Comment, _token.LineComment):
    rx = r";.*$"
    

class BlockCommentStart(Comment, _token.BlockCommentStart):
    rx = r"#!"
    def update_state(self, state):
        state.enter(ParseBlockComment())
        

class BlockCommentEnd(Comment, _token.BlockCommentEnd, _token.Leaver):
    rx = "!#"


class BlockComment(Comment, _token.BlockComment):
    pass


class OpenParen(Scheme, _token.MatchStart, _token.Indent):
    rx = r"\("
    matchname = "schemeparen"
    def update_state(self, state):
        state.enter(ParseScheme())


class CloseParen(Scheme, _token.MatchEnd, _token.Dedent):
    rx = r"\)"
    matchname = "schemeparen"
    def update_state(self, state):
        state.leave()
        state.endArgument()
        

class Quote(Scheme):
    rx = r"['`,]"
    
    
class Dot(Scheme):
    rx = r"\.(?!\S)"


class Bool(Scheme, _token.Item):
    rx = r"#[tf]\b"
    
    
class Char(Scheme, _token.Item):
    rx = r"#\\([a-z]+|.)"


class Word(Scheme, _token.Item):
    rx = r'[^()"{}\s]+'


class Keyword(Word):
    @classmethod
    def test_match(cls, match):
        from .. import data
        return match.group() in data.scheme_keywords()


class Function(Word):
    @classmethod
    def test_match(cls, match):
        from .. import data
        return match.group() in data.scheme_functions()


class Variable(Word):
    @classmethod
    def test_match(cls, match):
        from .. import data
        return match.group() in data.scheme_variables()


class Constant(Word):
    @classmethod
    def test_match(cls, match):
        from .. import data
        return match.group() in data.scheme_constants()


class Number(_token.Item, _token.Numeric):
    rx = (r"("
          r"-?\d+|"
          r"#(b[0-1]+|o[0-7]+|x[0-9a-fA-F]+)|"
          r"[-+]inf.0|[-+]?nan.0"
          r")(?=$|[)\s])")


class Fraction(Number):
    rx = r"-?\d+/\d+(?=$|[)\s])"


class Float(Number):
    rx = r"-?((\d+(\.\d*)|\.\d+)(E\d+)?)(?=$|[)\s])"


class VectorStart(OpenParen):
    rx = r"#\("


class LilyPond(_token.Token):
    pass


class LilyPondStart(LilyPond, _token.MatchStart, _token.Indent):
    rx = r"#{"
    matchname = "schemelily"
    def update_state(self, state):
        state.enter(ParseLilyPond())
        

class LilyPondEnd(LilyPond, _token.Leaver, _token.MatchEnd, _token.Dedent):
    rx = r"#}"
    matchname = "schemelily"


# Parsers

class ParseScheme(Parser):
    mode = 'scheme'
    items = (
        _token.Space,
        OpenParen,
        CloseParen,
        LineComment,
        BlockCommentStart,
        LilyPondStart,
        VectorStart,
        Dot,
        Bool,
        Char,
        Quote,
        Fraction,
        Float,
        Number,
        Constant,
        Keyword,
        Function,
        Variable,
        Word,
        StringQuotedStart,
    )
    

class ParseString(Parser):
    default = String
    items = (
        StringQuotedEnd,
        StringQuoteEscape,
    )
    

class ParseBlockComment(Parser):
    default = BlockComment
    items = (
        BlockCommentEnd,
    )


from . import lilypond

class ParseLilyPond(lilypond.ParseMusic):
    items = (LilyPondEnd,) + lilypond.ParseMusic.items

python_ly-0.9.9/ly/lex/texinfo.py0000644000000000000000000001104113615410400013735 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Parses and tokenizes Texinfo input, recognizing LilyPond in Texinfo.
"""

from __future__ import unicode_literals

from . import _token
from . import Parser, FallthroughParser


class Comment(_token.Comment):
    pass


class LineComment(Comment, _token.LineComment):
    rx = r"@c\b.*$"


class BlockCommentStart(Comment, _token.BlockCommentStart):
    rx = r"@ignore\b"
    def update_state(self, state):
        state.enter(ParseComment())
        
        
class BlockCommentEnd(Comment, _token.Leaver, _token.BlockCommentEnd):
    rx = r"@end\s+ignore\b"


class Attribute(_token.Token):
    pass


class Keyword(_token.Token):
    rx = r"@[a-zA-Z]+"


class Block(_token.Token):
    pass


class BlockStart(Block):
    rx = r"@[a-zA-Z]+\{"
    def update_state(self, state):
        state.enter(ParseBlock())


class BlockEnd(Block, _token.Leaver):
    rx = r"\}"


class EscapeChar(_token.Character):
    rx = r"@[@{}]"
    

class Accent(EscapeChar):
    rx = "@['\"',=^`~](\\{[a-zA-Z]\\}|[a-zA-Z]\\b)"


class Verbatim(_token.Token):
    pass


class VerbatimStart(Keyword):
    rx = r"@verbatim\b"
    def update_state(self, state):
        state.enter(ParseVerbatim())


class VerbatimEnd(Keyword, _token.Leaver):
    rx = r"@end\s+verbatim\b"
    
    
class LilyPondBlockStart(Block):
    rx = r"@lilypond(?=(\[[a-zA-Z,=0-9\\\s]+\])?\{)"
    def update_state(self, state):
        state.enter(ParseLilyPondBlockAttr())


class LilyPondBlockStartBrace(Block):
    rx = r"\{"
    def update_state(self, state):
        state.replace(ParseLilyPondBlock())


class LilyPondBlockEnd(Block, _token.Leaver):
    rx = r"\}"
    
    
class LilyPondEnvStart(Keyword):
    rx = r"@lilypond\b"
    def update_state(self, state):
        state.enter(ParseLilyPondEnvAttr())
    
    
class LilyPondEnvEnd(Keyword, _token.Leaver):
    rx = r"@end\s+lilypond\b"


class LilyPondFileStart(Block):
    rx = r"@lilypondfile\b"
    def update_state(self, state):
        state.enter(ParseLilyPondFile())


class LilyPondFileStartBrace(Block):
    rx = r"\{"
    def update_state(self, state):
        state.replace(ParseBlock())


class LilyPondAttrStart(Attribute):
    rx = r"\["
    def update_state(self, state):
        state.enter(ParseLilyPondAttr())
    
    
class LilyPondAttrEnd(Attribute, _token.Leaver):
    rx = r"\]"


# Parsers:

class ParseTexinfo(Parser):
    mode = "texinfo"
    items = (
        LineComment,
        BlockCommentStart,
        Accent,
        EscapeChar,
        LilyPondBlockStart,
        LilyPondEnvStart,
        LilyPondFileStart,
        BlockStart,
        VerbatimStart,
        Keyword,
    )


class ParseComment(Parser):
    default = Comment
    items = (
        BlockCommentEnd,
    )


class ParseBlock(Parser):
    items = (
        BlockEnd,
        Accent,
        EscapeChar,
        BlockStart,
        Keyword,
    )


class ParseVerbatim(Parser):
    default = Verbatim
    items = (
        VerbatimEnd,
    )


class ParseLilyPondBlockAttr(Parser):
    items = (
        LilyPondAttrStart,
        LilyPondBlockStartBrace,
    )


class ParseLilyPondEnvAttr(FallthroughParser):
    items = (
        LilyPondAttrStart,
    )
    def fallthrough(self, state):
        state.replace(ParseLilyPondEnv())


class ParseLilyPondAttr(Parser):
    default = Attribute
    items = (
        LilyPondAttrEnd,
    )


class ParseLilyPondFile(Parser):
    items = (
        LilyPondAttrStart,
        LilyPondFileStartBrace,
    )


from . import lilypond

class ParseLilyPondBlock(lilypond.ParseGlobal):
    items = (
        LilyPondBlockEnd,
    ) + lilypond.ParseGlobal.items


class ParseLilyPondEnv(lilypond.ParseGlobal):
    items = (
        LilyPondEnvEnd,
    ) + lilypond.ParseGlobal.items
    

python_ly-0.9.9/ly/music/__init__.py0000644000000000000000000000627213615410400014362 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2014 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

r"""
An api to read music from the tokens of a ly.document.Document into a tree
structure.

This is meant to quickly read music from a document, to perform
modifications on the document, and to interpret music and markup and to
convert or export it to other formats.

All nodes are a subclass of items.Item, (which inherits from node.WeakNode).

Tree structures are created from nested LilyPond structures, markup and
scheme code. Some Item types have special methods to query information. The
Music type, for example, has a length() method that returns the duration of
the music fragment.

Using the Music.events() method and the events module, it is possible to
iterate in musical time over the music tree, e.g. to convert music to
another format.

This package is not yet capable to construct documents entirely from scratch.
This needs to be developed. Until that time, the ly.dom module can be used
instead.

Some Item types can have a list of child items, but the tree structure is as
linear as possible.

A convenience function is available to create a ly.music.items.Document
instance for the specified ly.document.Document.

Here is an example::

    >>> import ly.document
    >>> import ly.music
    >>> d=ly.document.Document(r'''
    \version "2.18.0"

    music = \relative {
      \time 4/4
      \key d \minor
      d4 e f g
      a g f e
      d2
    }

    \score {
      \new Staff <<
        \music
      >>
    }
    ''')
    >>> m=ly.music.document(d)
    >>> print(m.dump())
    
      
        
      
        
          
            
            
              
              
            
            
            
            
            
            
            
            
            
      
        
          
            
    >>> m[2][0][0]
    
    >>> m[2][0][0].length()
    Fraction(5, 2)
    >>>

"""

import ly.document


def document(doc):
    """Return a music.items.Document instance for the ly.document.Document."""
    from . import items
    return items.Document(doc)
python_ly-0.9.9/ly/music/event.py0000644000000000000000000000270113615410400013735 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2014 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Translates a music.items.Document tree into lists of events.

"""

from __future__ import unicode_literals


class Events(object):
    """Traverses a music tree and records music events from it."""
    unfold_repeats = False
    
    def read(self, node, time=0, scaling=1):
        """Read events from the node and all its child nodes; return time."""
        return self.traverse(node, time, scaling)
    
    def traverse(self, node, time, scaling):
        """Traverse node and call event handlers; record and return the time."""
        return node.events(self, time, scaling)


python_ly-0.9.9/ly/music/items.py0000644000000000000000000011322613615410400013742 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2014 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
The items a music expression is constructed with in a tree structure.

Whitespace and comments are left out.

All nodes (instances of Item) have a 'position' attribute that indicates 
where the item starts in the source text. Almost all items have the token 
that starts the expression in the 'token' attribute and possibly other 
tokens in the 'tokens' attribute, as a tuple. 

The 'end_position()' method returns the position where the node (including 
its child nodes) ends.

You can get the whole tree structure of a LilyPond document by instantiating
a Document with the ly.document.Document instance. (It will read all the tokens
from the document using the Reader from the read module.) As a convenience,
the ly.music.document(doc) function does this.

If you want to add new Item types, you should also add a method to read.Reader
to construct those items.

"""

from __future__ import unicode_literals

from fractions import Fraction
import re

import ly.node
from ly import lex
from ly.lex import lilypond
from ly.lex import scheme


class Item(ly.node.WeakNode):
    """Represents any item in the music of a document.
    
    This can be just a token, or an interpreted construct such as a note,
    rest or sequential or simultaneous construct , etc.
    
    Some Item instances just have one responsible token, but others have a
    list or tuple to tokens.
    
    An Item also has a pointer to the Document it originates from.
    
    """
    document = None
    tokens = ()
    token = None
    position = -1

    def __repr__(self):
        s = ' ' + repr(self.token[:]) if self.token else ''
        return '<{0}{1}>'.format(self.__class__.__name__, s)
    
    def plaintext(self):
        """Return a plaintext value for this node.
        
        This only makes sense for items like Markup or String. For other types,
        an empty string is returned
        
        """
        return ""
     
    def end_position(self):
        """Return the end position of this node."""
        def ends():
            if self.tokens:
                yield self.tokens[-1].end
            elif self.token:
                yield self.token.end
            else:
                yield self.position
            if len(self):
                # end pos of the last child
                yield self[-1].end_position()
            # end pos of Item or Token instances in attributes, such as duration etc
            for i in vars(self).values():
                if isinstance(i, Item):
                    yield i.end_position()
                elif isinstance(i, lex.Token):
                    yield i.end
        return max(ends())
    
    def events(self, e, time, scaling):
        """Let the event.Events instance handle the events. Return the time."""
        return time
    
    def length(self):
        """Return the musical duration."""
        return 0
    
    def iter_toplevel_items(self):
        """Yield the toplevel items of our Document node in backward direction.
        
        Iteration starts with the node just before the node "self" is a 
        descendant of.
        
        """
        node = self
        for doc in self.ancestors():
            if isinstance(doc, Document):
                break
            node = doc
        else:
            return
        
        # now, doc is the Document node, and node is the child of the Document
        # node we are a (far) descendant of
        for i in node.backward():
            yield i
        
        # look in parent Document before the place we were included
        while doc.include_node:
            p = doc.include_node.parent()
            if isinstance(p, Document):
                for i in doc.include_node.backward():
                    yield i
                doc = p
            else:
                break
                
    def iter_toplevel_items_include(self):
        r"""Same as iter_toplevel_items(), but follows \include commands."""
        def follow(it):
            for i in it:
                if isinstance(i, Include):
                    doc = i.parent().get_included_document_node(i)
                    if doc:
                        for i in follow(doc[::-1]):
                            yield i
                else:
                    yield i
        return follow(self.iter_toplevel_items())
    
    def music_parent(self):
        """Walk up the parent tree until Music is found; return the outermost Music node.
        
        Returns None is the node does not belong to any music expression (e.g.
        a toplevel Markup or Scheme object).
        
        """
        node = self
        mus = isinstance(node, Music)
        for p in self.ancestors():
            pmus = isinstance(p, Music)
            if mus and not pmus:
                return node
            mus = pmus
            node = p
    
    def music_children(self, depth=-1):
        """Yield all the children that are new music expressions
        
        (i.e. that are inside other constructions).
        
        """
        def find(node, depth):
            if depth != 0:
                if isinstance(node, Music):
                    for i in node:
                        for i in find(i, depth-1):
                            yield i
                else:
                    for i in node:
                        if isinstance(i, Music):
                            yield i
                        else:
                            for i in find(i, depth-1):
                                yield i
        return find(self, depth)
    
    def has_output(self, _seen_docs=None):
        """Return True if this node has toplevel music, markup, book etc.
        
        I.e. returns True when LilyPond would likely generate output. Usually
        you'll call this method on a Document, Score, BookPart or Book node.
        
        You should not supply the _seen_docs argument; it is used internally 
        to avoid traversing recursively nested include files.
        
        """
        if _seen_docs is None:
            _seen_docs = set()
        _seen_docs.add(self)
        for n in self:
            if isinstance(n, (Music, Markup)):
                return True
            elif isinstance(n, (Book, BookPart, Score)):
                if n.has_output(_seen_docs):
                    return True
            elif isinstance(n, Include):
                doc = self.toplevel().get_included_document_node(n)
                if doc and doc not in _seen_docs and doc.has_output(_seen_docs):
                    return True


class Document(Item):
    """A toplevel item representing a ly.document.Document."""
    
    def __init__(self, doc):
        super(Document, self).__init__()
        self.document = doc
        self.include_node = None
        self.include_path = []
        self.relative_includes = True
        import ly.document
        c = ly.document.Cursor(doc)
        s = ly.document.Source(c, True, tokens_with_position=True)
        from .read import Reader
        r = Reader(s)
        self.extend(r.read())
    
    def node(self, position, depth=-1):
        """Return the node at or just before the specified position."""
        def bisect(n, depth):
            end = len(n)
            if depth == 0 or end == 0:
                return n
            pos = 0
            while pos < end:
                mid = (pos + end) // 2
                if position < n[mid].position:
                    end = mid
                else:
                    pos = mid + 1
            pos -= 1
            if n[pos].position == position:
                return n[pos]
            elif n[pos].position > position:
                return n
            return bisect(n[pos], depth - 1)
        return bisect(self, depth)
    
    def music_events_til_position(self, position):
        """Return a list of tuples.
        
        Every tuple is a (parent, nodes, scaling). If an empty list is 
        returned, there is no music expression at this position.
        
        """
        node = self.node(position)
        # be nice and allow including an assignment
        if (isinstance(node, Assignment) and node.parent() is self
            and isinstance(node.value(), Music)):
            return [(node, [], 1)]
        
        if isinstance(node.parent(), Chord):
            node = node.parent()
        
        l = []
        mus = isinstance(node, (Music, Durable))
        if mus:
            l.append((node, [], 1))
        for p in node.ancestors():
            pmus = isinstance(p, Music)
            end = node.end_position()
            if pmus:
                if position > end:
                    preceding, s = p.preceding(node.next_sibling())
                    l = [(p, preceding, s)]
                elif position == end:
                    preceding, s = p.preceding(node)
                    l = [(p, preceding + [node], s)]
                else:
                    preceding, s = p.preceding(node)
                    l.append((p, preceding, s))
            elif mus:
                # we are at the musical top
                if position > end:
                    return []
                elif position == end:
                    l = [(p, [node], 1)]
                else:
                    l.append((p, [], 1))
                break
            node = p
            mus = pmus
        l.reverse()
        return l
    
    def time_position(self, position):
        """Return the time position in the music at the specified cursor position.
        
        The value is a fraction. If None is returned, we are not in a music 
        expression.
        
        """
        events = self.music_events_til_position(position)
        if events:
            from . import event
            e = event.Events()
            time = 0
            scaling = 1
            for parent, nodes, s in events:
                scaling *= s
                for n in nodes:
                    time = e.traverse(n, time, scaling)
            return time
    
    def time_length(self, start, end):
        """Return the length of the music between start and end positions.
        
        Returns None if start and end are not in the same expression.
        
        """
        def mk_list(evts):
            """Make a flat list of all the events."""
            l = []
            scaling = 1
            for p, nodes, s in evts:
                scaling *= s
                for n in nodes:
                    l.append((n, scaling))
            return l
        
        if start > end:
            start, end = end, start
        
        start_evts = self.music_events_til_position(start)
        if start_evts:
            end_evts = self.music_events_til_position(end)
            if end_evts and start_evts[0][0] is end_evts[0][0]:
                # yes, we have the same toplevel expression.
                start_evts = mk_list(start_evts)
                end_evts = mk_list(end_evts)
                from . import event
                e = event.Events()
                time = 0
                i = 0
                # traverse the common events only once
                for i, ((evt, s), (end_evt, end_s)) in enumerate(zip(start_evts, end_evts)):
                    if evt is end_evt:
                        time = e.traverse(evt, time, s)
                    else:
                        break
                end_time = time
                # handle the remaining events for the start position
                for evt, s in start_evts[i::]:
                    time = e.traverse(evt, time, s)
                # handle the remaining events for the end position
                for evt, s in end_evts[i::]:
                    end_time = e.traverse(evt, end_time, s)
                return end_time - time
        
    def substitute_for_node(self, node):
        """Returns a node that replaces the specified node (e.g. in music).
        
        For example: a variable reference returns its value.
        Returns nothing if the node is not substitutable.
        Returns the node itself if it was substitutable, but the substitution
        failed.
        
        """
        if isinstance(node, UserCommand):
            value = node.value()
            if value:
                return self.substitute_for_node(value) or value
            return node
        elif isinstance(node, Include):
            return self.get_included_document_node(node) or node
        
        # maybe other substitutions
    
    def iter_music(self, node=None):
        """Iter over the music, following references to other assignments."""
        for n in node or self:
            n = self.substitute_for_node(n) or n
            yield n
            for n in self.iter_music(n):
                yield n
    
    def get_included_document_node(self, node):
        """Return a Document for the Include node. May return None."""
        try:
            return node._document
        except AttributeError:
            node._document = None
            filename = node.filename()
            if filename:
                resolved = self.resolve_filename(filename)
                if resolved:
                    docnode = self.get_music(resolved)
                    docnode.include_node = node
                    docnode.include_path = self.include_path
                    node._document = docnode
            return node._document
    
    def resolve_filename(self, filename):
        """Resolve filename against our document and include_path."""
        import os
        if os.path.isabs(filename):
            return filename
        path = list(self.include_path)
        if self.document.filename:
            basedir = os.path.dirname(self.document.filename)
            try:
                path.remove(basedir)
            except ValueError:
                pass
            path.insert(0, basedir)
        for p in path:
            fullpath = os.path.join(p, filename)
            if os.path.exists(fullpath):
                return fullpath
    
    def get_music(self, filename):
        """Return the music Document for the specified filename.
        
        This implementation loads a ly.document.Document using utf-8 
        encoding. Inherit from this class to implement other loading 
        mechanisms or caching.
        
        """
        import ly.document
        return type(self)(ly.document.Document.load(filename))


class Token(Item):
    """Any token that is not otherwise recognized""" 


class Container(Item):
    """An item having a list of child items."""


class Duration(Item):
    """A written duration"""


class Durable(Item):
    """An Item that has a musical duration, in the duration attribute."""
    duration = 0, 1 # two Fractions: (base, scaling)
    
    def length(self):
        """Return the musical duration (our base * our scaling)."""
        base, scaling = self.duration
        return base * scaling
    
    def events(self, e, time, scaling):
        """Let the event.Events instance handle the events. Return the time."""
        return time + self.duration[0] * self.duration[1] * scaling


class Chord(Durable, Container):
    pass


class Unpitched(Durable):
    """A "note" without pitch, just a standalone duration."""
    pitch = None


class Note(Durable):
    """A Note that has a ly.pitch.Pitch"""
    pitch = None
    octave_token = None
    accidental_token = None
    octavecheck_token = None


class Skip(Durable):
    pass


class Rest(Durable):
    pass


class Q(Durable):
    pass


class DrumNote(Durable):
    pass


class Music(Container):
    """Any music expression, to be inherited of."""
    def events(self, e, time, scaling):
        """Let the event.Events instance handle the events. Return the time."""
        for node in self:
            time = e.traverse(node, time, scaling)
        return time
    
    def length(self):
        """Return the musical duration."""
        from . import event
        return event.Events().read(self)
    
    def preceding(self, node=None):
        """Return a two-tuple (nodes, scaling).
        
        The nodes are the nodes in time before the node (which must be a
        child), and the scaling is the scaling this node applies (normally 1).
        
        If node is None, all nodes that would precede a fictive node at the
        end are returned.
        
        """
        i = self.index(node) if node else None
        return self[:i:], 1


class MusicList(Music):
    """A music expression, either << >> or { }."""
    simultaneous = False
    
    def events(self, e, time, scaling):
        """Let the event.Events instance handle the events. Return the time."""
        if self.simultaneous:
            if len(self):
                time = max(e.traverse(node, time, scaling) for node in self)
        else:
            time = super(MusicList, self).events(e, time, scaling)
        return time

    def preceding(self, node=None):
        """Return a two-tuple (nodes, scaling).
        
        The nodes are the nodes in time before the node (which must be a
        child), and the scaling is the scaling this node applies (normally 1).
        
        If node is None, all nodes that would precede a fictive node at the
        end are returned.
        
        """
        if self.simultaneous:
            return [], 1
        return super(MusicList, self).preceding(node)


class Tag(Music):
    r"""A \tag, \keepWithTag or \removeWithTag command."""
    
    def events(self, e, time, scaling):
        """Let the event.Events instance handle the events. Return the time."""
        for node in self[-1:]:
            time = e.traverse(node, time, scaling)
        return time
        
    def preceding(self, node=None):
        """Return a two-tuple (nodes, scaling).
        
        The nodes are the nodes in time before the node (which must be a
        child), and the scaling is the scaling this node applies (normally 1).
        
        If node is None, all nodes that would precede a fictive node at the
        end are returned.
        
        """
        return [], 1


class Scaler(Music):
    r"""A music construct that scales the duration of its contents.
    
    In the numerator and denominator attributes the values specified for
    LilyPond are stored, e.g. with \times 3/2 { c d e }, the numerator is
    integer 3 and the denominator is integer 2. Note that for \tuplet and
    \times the meaning of these numbers is reversed.
    
    The algebraic scaling is stored in the scaling attribute.
    
    """
    scaling = 1
    
    numerator = 0
    denominator = 0
    
    def events(self, e, time, scaling):
        """Let the event.Events instance handle the events. Return the time."""
        return super(Scaler, self).events(e, time, scaling * self.scaling)
    
    def preceding(self, node=None):
        """Return a two-tuple (nodes, scaling).
        
        The nodes are the nodes in time before the node (which must be a
        child), and the scaling is the scaling this node applies.
        
        If node is None, all nodes that would precede a fictive node at the
        end are returned.
        
        """
        i = self.index(node) if node else None
        return self[:i:], self.scaling


class Grace(Music):
    """Music that has grace timing, i.e. 0 as far as computation is concerned."""
    
    def events(self, e, time, scaling):
        """Let the event.Events instance handle the events. Return the time."""
        return super(Grace, self).events(e, time, 0)
    
    def preceding(self, node=None):
        """Return a two-tuple (nodes, scaling).
        
        The nodes are the nodes in time before the node (which must be a
        child), and the scaling is 0 for (because we have grace notes).
        
        If node is None, all nodes that would precede a fictive node at the
        end are returned.
        
        """
        i = self.index(node) if node else None
        return self[:i:], 0


class AfterGrace(Music):
    r"""The \afterGrace function with its two arguments.
    
    Only the duration of the first is counted.
    
    """


class PartCombine(Music):
    r"""The \partcombine command with 2 music arguments."""
    def events(self, e, time, scaling):
        """Let the event.Events instance handle the events. Return the time."""
        if len(self):
            time = max(e.traverse(node, time, scaling) for node in self)
        return time
    
    def preceding(self, node=None):
        """Return a two-tuple (nodes, scaling).
        
        The nodes are the nodes in time before the node (which must be a
        child), and the scaling is the scaling this node applies (normally 1).
        
        If node is None, all nodes that would precede a fictive node at the
        end are returned.
        
        """
        return [], 1


class Relative(Music):
    r"""A \relative music expression. Has one or two children (Note, Music)."""
    pass


class Absolute(Music):
    r"""An \absolute music expression. Has one child (normally Music)."""
    pass


class Transpose(Music):
    r"""A \transpose music expression. Has normally three children (Note, Note, Music)."""


class Repeat(Music):
    r"""A \repeat expression."""
    def specifier(self):
        if isinstance(self._specifier, Scheme):
            return self._specifier.get_string()
        elif isinstance(self._specifier, String):
            return self._specifier.value()
        return self._specifier
    
    def repeat_count(self):
        if isinstance(self._repeat_count, Scheme):
            return self._repeat_count.get_int() or 1
        return int(self._repeat_count or '1') or 1

    def events(self, e, time, scaling):
        """Let the event.Events instance handle the events. Return the time."""
        if len(self) and isinstance(self[-1], Alternative):
            alt = self[-1]
            children = self[:-1]
        else:
            alt = None
            children = self[:]
        
        if e.unfold_repeats or self.specifier() != "volta":
            count = self.repeat_count()
            if alt and len(alt) and len(alt[0]):
                alts = list(alt[0])[:count+1]
                alts[0:0] = [alts[0]] * (count - len(alts))
                for a in alts:
                    for n in children:
                        time = e.traverse(n, time, scaling)
                    time = e.traverse(a, time, scaling)
            else:
                for i in range(count):
                    for n in children:
                        time = e.traverse(n, time, scaling)
        else:
            for n in children:
                time = e.traverse(n, time, scaling)
            if alt:
                time = e.traverse(alt, time, scaling)
        return time


class Alternative(Music):
    r"""An \alternative expression."""


class InputMode(Music):
    """Base class for inputmode-changing commands."""


class NoteMode(InputMode):
    r"""A \notemode or \notes expression."""


class ChordMode(InputMode):
    r"""A \chordmode or \chords expression."""


class DrumMode(InputMode):
    r"""A \drummode or \drums expression."""


class FigureMode(InputMode):
    r"""A \figuremode or \figures expression."""


class LyricMode(InputMode):
    r"""A \lyricmode, \lyrics or \addlyrics expression."""


class LyricsTo(InputMode):
    r"""A \lyricsto expression."""
    _context_id = None
    
    def context_id(self):
        if isinstance(self._context_id, String):
            return self._context_id.value()
        elif isinstance(self._context_id, Scheme):
            return self._context_id.get_string()
        return self._context_id


class LyricText(Durable):
    """A lyric text (word, markup or string), with a Duration."""


class LyricItem(Item):
    """Another lyric item (skip, extender, hyphen or tie)."""


class ChordSpecifier(Item):
    """Chord specifications after a note in chord mode.
    
    Has children of Note or ChordItem class.
    
    """


class ChordItem(Item):
    """An item inside a ChordSpecifier, e.g. a number or modifier."""


class Tremolo(Item):
    """A tremolo item ":". The duration attribute is a tuple (base, scaling)."""
    duration = 0, 1


class Translator(Item):
    r"""Base class for a \change, \new, or \context music expression."""
    _context = None
    _context_id = None
    
    def context(self):
        return self._context
    
    def context_id(self):
        """The context id, if specified after an equal sign."""
        if isinstance(self._context_id, String):
            return self._context_id.value()
        return self._context_id


class Context(Translator, Music):
    r"""A \new or \context music expression."""


class Change(Translator):
    r"""A \change music expression."""


class Tempo(Item):
    duration = 0, 1
    
    def fraction(self):
        """Return the note value as a fraction given before the equal sign."""
        base, scaling = self.duration   # (scaling will normally be 1)
        return base * scaling
            
    def text(self):
        """Return the text, if set. Can be Markup, Scheme, or String."""
        for i in self:
            if isinstance(i, (Markup, Scheme, String)):
                return i
            return
    
    def tempo(self):
        """Return a list of integer values describing the tempo or range."""
        nodes = iter(self)
        result = []
        for i in nodes:
            if isinstance(i, Duration):
                for i in nodes:
                    if isinstance(i, Scheme):
                        v = i.get_int()
                        if v is not None:
                            result.append(v)
                    elif isinstance(i, Number):
                        result.append(i.value())
        return result


class TimeSignature(Item):
    r"""A \time command."""
    _num = 4
    _fraction = Fraction(1, 4)
    _beatstructure = None

    def measure_length(self):
        """The length of one measure in this time signature as a Fraction."""
        return self._num * self._fraction
    
    def numerator(self):
        """The upper number (e.g. for 3/2 it returns 3)."""
        return self._num
    
    def fraction(self):
        """The lower number as a Fraction (e.g. for 3/2 it returns 1/2)."""
        return self._fraction
    
    def beatstructure(self):
        """The scheme expressions denoting the beat structure, if specified."""
        return self._beatstructure


class Partial(Item):
    r"""A \partial command."""
    duration = 0, 1

    def partial_length(self):
        """Return the duration given as argument as a Fraction."""
        base, scaling = self.duration
        return base * scaling


class Clef(Item):
    r"""A \clef item."""
    _specifier = None
    
    def specifier(self):
        if isinstance(self._specifier, String):
            return self._specifier.value()
        return self._specifier

        
class KeySignature(Item):
    r"""A \key pitch \mode command."""
    def pitch(self):
        """The ly.pitch.Pitch that denotes the pitch."""
        for i in self.find(Note):
            return i.pitch
    
    def mode(self):
        """The mode, e.g. "major", "minor", etc."""
        for i in self.find(Command):
            return i.token[1:]


class PipeSymbol(Item):
    r"""A pipe symbol: |"""


class VoiceSeparator(Item):
    r"""A voice separator: \\"""


class Postfix(Item):
    """Any item that is prefixed with a _, - or ^ direction token."""


class Tie(Item):
    """A tie."""


class Slur(Item):
    """A ( or )."""
    event = None


class PhrasingSlur(Item):
    r"""A \( or \)."""
    event = None


class Beam(Item):
    """A [ or ]."""
    event = None


class Dynamic(Item):
    """Any dynamic symbol."""


class Articulation(Item):
    """An articulation, fingering, string number, or other symbol."""


class StringTuning(Item):
    r"""A \stringTuning command (with a chord as argument)."""


class Keyword(Item):
    """A LilyPond keyword."""


class Command(Item):
    """A LilyPond command."""


class UserCommand(Music):
    """A user command, most probably referring to music."""
    def name(self):
        """Return the name of this user command (without the leading backslash)."""
        return self.token[1:]
    
    def value(self):
        """Find the value assigned to this variable."""
        for i in self.iter_toplevel_items_include():
            if isinstance(i, Assignment) and i.name() == self.name():
                return i.value()
    
    def events(self, e, time, scaling):
        """Let the event.Events instance handle the events. Return the time."""
        value = self.value()
        if value:
            time = e.traverse(value, time, scaling)
        return time


class Version(Item):
    r"""A \version command."""
    def version_string(self):
        """The version as a string."""
        for i in self:
            if isinstance(i, String):
                return i.value()
            elif isinstance(i, Scheme):
                return i.get_string()
        return ''

    def version(self):
        """The version as a tuple of ints."""
        return tuple(map(int, re.findall(r'\d+', self.version_string())))


class Include(Item):
    r"""An \include command (not changing the language)."""
    def filename(self):
        """Returns the filename."""
        for i in self:
            if isinstance(i, String):
                return i.value()
            elif isinstance(i, Scheme):
                return i.get_string()


class Language(Item):
    r"""A command (\language or certain \include commands) that changes the pitch language."""
    language = None


class Markup(Item):
    r"""A command starting markup (\markup, -lines and -list)."""
    def plaintext(self):
        """Return the plain text value of this node."""
        return ' '.join(n.plaintext() for n in self)


class MarkupCommand(Item):
    r"""A markup command, such as \italic etc."""
    def plaintext(self):
        """Return the plain text value of this node."""
        if self.token == '\\concat':
            joiner = ''
        #elif 'column' in self.token:
            #joiner = '\n'
        else:
            joiner = ' '
        if len(self) == 1 and isinstance(self[0], MarkupList):
            node = self[0]
        else:
            node = self
        return joiner.join(n.plaintext() for n in node)


class MarkupUserCommand(Item):
    """A user-defined markup command"""
    def name(self):
        """Return the name of this user command (without the leading backslash)."""
        return self.token[1:]
    
    def value(self):
        """Find the value assigned to this variable."""
        for i in self.iter_toplevel_items_include():
            if isinstance(i, Assignment) and i.name() == self.name():
                return i.value()
            elif isinstance(i, Scheme):
                for j in i:
                    if isinstance(j, SchemeList):
                        for k in j:
                            if isinstance(k, SchemeItem) and k.token == 'define-markup-command':
                                for l in j[1::]:
                                    if isinstance(l, SchemeList):
                                        for m in l:
                                            if isinstance(m, SchemeItem) and m.token == self.name():
                                                return i
                                            break
                                    break
                            break
                    break


class MarkupScore(Item):
    r"""A \score inside Markup."""


class MarkupList(Item):
    r"""The group of markup items inside { and }. NOTE: *not* a \markuplist."""
    def plaintext(self):
        """Return the plain text value of this node."""
        return ' '.join(n.plaintext() for n in self)


class MarkupWord(Item):
    """A MarkupWord token."""
    def plaintext(self):
        return self.token


class Assignment(Item):
    """A variable = value construct."""
    def name(self):
        """The variable name."""
        return self.token
    
    def value(self):
        """The assigned value."""
        if len(self):
            return self[-1]


class Book(Container):
    r"""A \book { ... } construct."""


class BookPart(Container):
    r"""A \bookpart { ... } construct."""


class Score(Container):
    r"""A \score { ... } construct."""


class Header(Container):
    r"""A \header { ... } construct."""


class Paper(Container):
    r"""A \paper { ... } construct."""


class Layout(Container):
    r"""A \layout { ... } construct."""


class Midi(Container):
    r"""A \midi { ... } construct."""


class LayoutContext(Container):
    r"""A \context { ... } construct within Layout or Midi."""


class With(Container):
    r"""A \with ... construct."""


class Set(Item):
    r"""A \set command."""
    def context(self):
        """The context, if specified."""
        for t in self.tokens:
            if isinstance(t, lilypond.ContextName):
                return t
    
    def property(self):
        """The property."""
        for t in self.tokens:
            if isinstance(t, lilypond.ContextProperty):
                return t
        for t in self.tokens[::-1]:
            if isinstance(t, lilypond.Name):
                return t
        
    def value(self):
        """The value, given as argument. This is simply the child element."""
        for i in self:
            return i


class Unset(Item):
    """An \\unset command."""
    def context(self):
        """The context, if specified."""
        for t in self.tokens:
            if isinstance(t, lilypond.ContextName):
                return t
    
    def property(self):
        """The property."""
        for t in self.tokens:
            if isinstance(t, lilypond.ContextProperty):
                return t
        for t in self.tokens[::-1]:
            if isinstance(t, lilypond.Name):
                return t


class Override(Item):
    r"""An \override command."""
    def context(self):
        for i in self:
            if isinstance(i.token, lilypond.ContextName):
                return i.token
    
    def grob(self):
        for i in self:
            if isinstance(i.token, lilypond.GrobName):
                return i.token


class Revert(Item):
    r"""A \revert command."""
    def context(self):
        for i in self:
            if isinstance(i.token, lilypond.ContextName):
                return i.token
    
    def grob(self):
        for i in self:
            if isinstance(i.token, lilypond.GrobName):
                return i.token


class Tweak(Item):
    r"""A \tweak command."""


class PathItem(Item):
    r"""An item in the path of an \override or \revert command."""


class String(Item):
    """A double-quoted string."""
    
    def plaintext(self):
        """Return the plaintext value of this string, without escapes and quotes."""
        # TEMP use the value(), must become token independent.
        return self.value()
    
    def value(self):
        return ''.join(
            t[1:] if isinstance(t, lex.Character) and t.startswith('\\') else t
            for t in self.tokens[:-1])


class Number(Item):
    """A numerical value, directly entered."""
    def value(self):
        if isinstance(self.token, lilypond.IntegerValue):
            return int(self.token)
        elif isinstance(self.token, lilypond.DecimalValue):
            return float(self.token)
        elif isinstance(self.token, lilypond.Fraction):
            return Fraction(self.token)
        elif self.token.isdigit():
            return int(self.token)


class Scheme(Item):
    """A Scheme expression inside LilyPond."""
    def plaintext(self):
        """A crude way to get the plain text in this node."""
        # TEMP use get_string()
        return self.get_string()
    
    def get_pair_ints(self):
        """Very basic way to get two integers specified as a pair."""
        result = [int(i.token) for i in self.find(SchemeItem) if i.token.isdigit()]
        if len(result) >= 2:
            return tuple(result[:2])
    
    def get_list_ints(self):
        """A basic way to get a list of integer values."""
        return [int(i.token) for i in self.find(SchemeItem) if i.token.isdigit()]
    
    def get_int(self):
        """A basic way to get one integer value."""
        for i in self.find(SchemeItem):
            if i.token.isdigit():
                return int(i.token)
    
    def get_fraction(self):
        """A basic way to get one (may be fractional) numerical value."""
        for i in self.find(SchemeItem):
            if i.token.isdigit():
                return int(i.token)
            elif isinstance(i.token, scheme.Fraction):
                return Fraction(i.token)
    
    def get_string(self):
        """A basic way to get a quoted string value (without the quotes)."""
        return ''.join(i.value() for i in self.find(String))

    def get_ly_make_moment(self):
        """A basic way to get a ly:make-moment fraction."""
        tokens = [i.token for i in self.find(SchemeItem)]
        if len(tokens) == 3 and tokens[0] == 'ly:make-moment':
            if tokens[1].isdigit() and tokens[2].isdigit():
                return Fraction(int(tokens[1]), int(tokens[2]))


class SchemeItem(Item):
    """Any scheme token."""


class SchemeList(Container):
    """A ( ... ) expression."""


class SchemeQuote(Item):
    """A ' in scheme."""


class SchemeLily(Container):
    """A music expression inside #{ and #}."""



python_ly-0.9.9/ly/music/read.py0000644000000000000000000011353013615410400013532 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2014 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
The Reader is used to construct a tree structure of (musical and other)
items in a LilyPond document. The item types that are used are in the items
module.

You instantiate a Reader with a ly.document.Source that reads tokens from
any (part of a) ly.document.Document.

Whitespace and comments are left out.

All nodes (instances of Item) have a 'position' attribute that indicates 
where the item starts in the source text. Almost all items have the token 
that starts the expression in the 'token' attribute and possibly other 
tokens in the 'tokens' attribute, as a tuple. 

The 'end_position()' method returns the position where the node (including 
its child nodes) ends.


"""

from __future__ import unicode_literals
from __future__ import division

import itertools
from fractions import Fraction

import ly.duration
import ly.pitch

from ly import lex
from ly.lex import lilypond
from ly.lex import scheme

from .items import *


def skip(source, what=(lex.Space, lex.Comment)):
    """Yield tokens from source, skipping items of classes specified in what.
    
    By default, comments and whitespace are skipped.
    
    """
    for t in source:
        if not isinstance(t, what):
            yield t


class dispatcher(object):
    """Decorator creator to dispatch commands, keywords, etc. to a method."""
    def __init__(self):
        self.d = {}
    
    def read_arg(self, a):
        return a
    
    def __call__(self, *args):
        d = self.d
        def wrapper(func):
            for a in args:
                d[a] = func
            doc = "handle " + ", ".join(map(self.read_arg, args))
            func.__doc__ = doc if not func.__doc__ else func.__doc__ + '\n\n' + doc
            return func
        return wrapper
    
    def method(self, token):
        """The registered method to call for the token. May return None."""
        return self.d.get(token)


class dispatcher_class(dispatcher):
    """Decorator creator to dispatch the class of a token to a method."""
    def read_arg(self, a):
        return a.__name__
    
    def method(self, token):
        """The registered method to call for the token's class. May return None."""
        cls = token.__class__
        d = self.d
        try:
            return d[cls]
        except KeyError:
            for c in cls.__mro__[1:]:
                try:
                    meth = d[cls] = d[c]
                except KeyError:
                    if c is not lex.Token:
                        continue
                    meth = d[cls] = None
                return meth


class Reader(object):
    """Reads tokens from a Source and builds a meaningful tree structure."""
    
    _commands = dispatcher()
    _keywords = dispatcher()
    _tokencls = dispatcher_class()
    _markup = dispatcher_class()
    _scheme = dispatcher_class()
    
    def __init__(self, source):
        """Initialize with a ly.document.Source.
        
        The language is set to "nederlands".
        
        """
        self.source = source
        self.language = "nederlands"
        self.in_chord = False
        self.prev_duration = Fraction(1, 4), 1
    
    def set_language(self, lang):
        r"""Changes the pitch name language to use.
        
        Called internally when \language or \include tokens are encountered
        with a valid language name/file.
        
        Sets the language attribute to the language name.
        
        """
        if lang in ly.pitch.pitchInfo:
            self.language = lang
            return True

    def add_duration(self, item, token=None, source=None):
        """Add a duration attribute to the item.
        
        When there are tokens, a Duration item is also appended to the item.
        
        """
        source = source or self.source
        tokens = []
        if not token or isinstance(token, lilypond.Duration):
            if token:
                tokens.append(token)
            for token in source:
                if isinstance(token, lilypond.Duration):
                    if tokens and isinstance(token, lilypond.Length):
                        self.source.pushback()
                        break
                    tokens.append(token)
                elif not isinstance(token, lex.Space):
                    self.source.pushback()
                    break
        if tokens:
            d = self.factory(Duration, tokens[0])
            d.tokens = tuple(tokens[1:])
            item.append(d)
            item.duration = self.prev_duration = ly.duration.base_scaling(tokens)
        else:
            item.duration = self.prev_duration
    
    def consume(self, last_token=None):
        """Yield the tokens from our source until a parser is exit.
        
        If last_token is given, it is called with the last token that is read.
        
        """
        t = None
        for t in self.source.until_parser_end():
            yield t
        if last_token and t is not None:
            last_token(t)

    def factory(self, cls, token=None, consume=False, position=None):
        """Create Item instance for token.
        
        If consume is True, consume()s the source into item.tokens.
        If you don't specify a token, you must specify the position (>= 0).
        
        """
        item = cls()
        item.document = self.source.document
        if token:
            item.token = token
            item.position = token.pos
        elif position is None:
            raise ValueError("position must be specified if no token")
        else:
            item.position = position
        if consume:
            item.tokens = tuple(self.consume())
            if not token and item.tokens:
                item.position = item.tokens[0].pos
        return item
    
    def add_bracketed(self, item, source):
        """Append the arguments between brackets to the item.
        
        Returns True if that succeeded, else False.
        
        """
        for t in source:
            if isinstance(t, lilypond.OpenBracket):
                tokens = [t]
                item.extend(self.read(self.consume(tokens.append)))
                item.tokens = tuple(tokens)
                return True
            elif not isinstance(t, lex.Space):
                self.source.pushback()
                break
        return False
        
    def read(self, source=None):
        """Yield Item instances reading from source."""
        source = source or self.source
        for t in skip(source):
            item = self.read_item(t, source)
            if item:
                yield item
    
    def read_item(self, t, source=None):
        """Return one Item that starts with token t. May return None."""
        meth = self._tokencls.method(t)
        if meth:
            return meth(self, t, source or self.source)
    
    @_tokencls(lilypond.SchemeStart)
    @_markup(lilypond.SchemeStart)
    def handle_scheme_start(self, t, source=None):
        return self.read_scheme_item(t)
    
    @_tokencls(lex.StringStart)
    @_markup(lex.StringStart)
    @_scheme(lex.StringStart)
    def handle_string_start(self, t, source=None):
        return self.factory(String, t, True)
    
    @_tokencls(
        lilypond.DecimalValue,
        lilypond.IntegerValue,
        lilypond.Fraction,
    )
    def handle_number_class(self, t, source=None):
        return self.factory(Number, t)
    
    @_tokencls(lilypond.MusicItem)
    def handle_music_item(self, t, source):
        return self.read_music_item(t, source)
    
    @_tokencls(lilypond.Length)
    def handle_length(self, t, source):
        item = self.factory(Unpitched, position=t.pos)
        self.add_duration(item, t, source)
        return item
    
    @_tokencls(lilypond.ChordStart)
    def handle_chord_start(self, t, source):
        if not self.in_chord:
            self.in_chord = True
            chord = self.factory(Chord, t)
            def last(t): chord.tokens += (t,)
            chord.extend(self.read(self.consume(last)))
            self.in_chord = False
            self.add_duration(chord, None, source)
            return chord
    
    @_tokencls(
        lilypond.OpenBracket, lilypond.OpenSimultaneous,
        lilypond.SimultaneousOrSequentialCommand,
    )
    def handle_music_list(self, t, source):
        item, it = self.test_music_list(t)
        if item:
            if it:
                item.extend(self.read(it))
            return item
    
    @_tokencls(lilypond.Command)
    def read_command(self, t, source):
        """Read the rest of a command given in t from the source."""
        meth = self._commands.method(t)
        if meth:
            return meth(self, t, source)
        return self.factory(Command, t)
    
    @_tokencls(lilypond.Keyword)
    def read_keyword(self, t, source):
        """Read the rest of a keyword given in t from the source."""
        meth = self._keywords.method(t)
        if meth:
            return meth(self, t, source)
        return self.factory(Keyword, t)
    
    @_tokencls(lilypond.UserCommand)
    def read_user_command(self, t, source):
        """Read a user command, this can be a variable reference."""
        return self.factory(UserCommand, t)
    
    @_tokencls(lilypond.ChordSeparator)
    def read_chord_specifier(self, t, source=None):
        """Read stuff behind notes in chordmode."""
        item = self.factory(ChordSpecifier, position=t.pos)
        item.append(self.factory(ChordItem, t))
        for t in self.consume():
            if isinstance(t, lilypond.ChordItem):
                item.append(self.factory(ChordItem, t))
            elif isinstance(t, lilypond.Note):
                r = ly.pitch.pitchReader(self.language)(t)
                if r:
                    note = self.factory(Note, t)
                    note.pitch = ly.pitch.Pitch(*r)
                    item.append(note)
        return item
    
    @_tokencls(lilypond.TremoloColon)
    def read_tremolo(self, t, source=None):
        """Read a tremolo."""
        item = self.factory(Tremolo, t)
        for t in self.source:
            if isinstance(t, lilypond.TremoloDuration):
                item.append(self.factory(Duration, t))
                item.duration = ly.duration.base_scaling_string(t)
            else:
                self.source.pushback()
            break
        return item
    
    @_tokencls(lilypond.Name, lilypond.ContextProperty)
    def handle_name(self, t, source):
        return self.read_assignment(t)
    
    @_tokencls(
        lilypond.PaperVariable,
        lilypond.LayoutVariable,
        lilypond.HeaderVariable,
        lilypond.UserVariable,
    )
    def handle_variable_assignment(self, t, source):
        item = self.read_assignment(t)
        if item:
            # handle \pt, \in etc.
            for t in skip(self.source):
                if isinstance(t, lilypond.Unit):
                    item.append(self.factory(Command, t))
                else:
                    self.source.pushback()
                break
            return item
    
    _direct_items = {
        lilypond.VoiceSeparator: VoiceSeparator,
        lilypond.PipeSymbol: PipeSymbol,
        lilypond.Dynamic: Dynamic,
        lilypond.Tie: Tie,
    }
    @_tokencls(*_direct_items)
    def handle_direct_items(self, t, source):
        """Tokens that directly translate to an Item."""
        return self.factory(self._direct_items[t.__class__], t)
    
    @_tokencls(lilypond.Direction)
    def handle_direction(self, t, source):
        item = self.factory(Postfix, t)
        item.direction = '_-^'.index(t) - 1
        for t in skip(source):
            if isinstance(t, (
                lex.StringStart,
                lilypond.MarkupStart,
                lilypond.Articulation,
                lilypond.Slur,
                lilypond.Beam,
                lilypond.Dynamic,
                )):
                item.append(self.read_item(t))
            elif isinstance(t, lilypond.Command) and t in ('\\tag'):
                item.append(self.read_item(t))
            elif isinstance(t, lilypond.Keyword) and t in ('\\tweak'):
                item.append(self.read_item(t))
            else:
                self.source.pushback()
            break
        return item
    
    @_tokencls(lilypond.Slur)
    def handle_slurs(self, t, source=None):
        cls = PhrasingSlur if t.startswith('\\') else Slur
        item = self.factory(cls, t)
        item.event = 'start' if t.endswith('(') else 'stop'
        return item
    
    @_tokencls(lilypond.Beam)
    def handle_beam(self, t, source=None):
        item = self.factory(Beam, t)
        item.event = 'start' if t == '[' else 'stop'
        return item
    
    @_tokencls(lilypond.Articulation)
    def handle_articulation(self, t, source=None):
        return self.factory(Articulation, t)
    
    def read_assignment(self, t):
        """Read an assignment from the variable name. May return None."""
        item = self.factory(Assignment, t)
        for t in skip(self.source):
            if isinstance(t, (lilypond.Variable, lilypond.UserVariable, lilypond.DotPath)):
                item.append(self.factory(PathItem, t))
            elif isinstance(t, lilypond.EqualSign):
                item.tokens = (t,)
                for i in self.read():
                    item.append(i)
                    break
                return item
            elif isinstance(t, lilypond.SchemeStart):
                # accept only one scheme item, if another one is found,
                # return the first, and discard the Assignment item
                # (should not normally happen)
                for s in item.find(Scheme):
                    self.source.pushback()
                    return s
                item.append(self.read_scheme_item(t))
            else:
                self.source.pushback()
                return
    
    def test_music_list(self, t):
        r"""Test whether a music list ({ ... }, << ... >>, starts here.
        
        Also handles \simultaneous { ... } and \sequential { ... }
        correctly. These obscure commands are not even highlighted by 
        lex, but they exist in LilyPond... \simultaneous { ... } is
        like << ... >> but \sequential << ... >> just behaves like << ... >>

        Returns a two-tuple(item; iterable), both may be None. If 
        item is not None, it can be either a UserCommand or a MusicList.  If 
        iterable is None, the item is a UserCommand (namely \simultaneous
        or \sequential, but not followed by a { or <<); else the item is a
        MusicList, and the iterable should be read fully to get all the 
        tokens inside the MusicList. If item is None, there is no MusicList 
        and no token is read.
        
        This way you can handle the { ... } and << ... >> transparently in every
        input mode.
        
        """
        def make_music_list(t, simultaneous, tokens=()):
            """Make the MusicList item."""
            item = self.factory(MusicList, t)
            item.simultaneous = simultaneous
            item.tokens = tokens
            def last(t): item.tokens += (t,)
            return item, self.consume(last)
            
        if isinstance(t, (lilypond.OpenBracket, lilypond.OpenSimultaneous)):
            return make_music_list(t, t == '<<')
        elif isinstance(t, lilypond.SimultaneousOrSequentialCommand):
            for t1 in skip(self.source):
                if isinstance(t1, (lilypond.OpenBracket, lilypond.OpenSimultaneous)):
                    return make_music_list(t, t == '\\simultaneous' or t1 == '<<', (t1,))
                else:
                    self.source.pushback()
                    return self.factory(Keyword, t), None
        return None, None
                    
    def read_music_item(self, t, source):
        r"""Read one music item (note, rest, s, \skip, or q) from t and source."""
        item = None
        in_pitch_command = isinstance(self.source.state.parser(), lilypond.ParsePitchCommand)
        if t.__class__ == lilypond.Note:
            r = ly.pitch.pitchReader(self.language)(t)
            if r:
                item = self.factory(Note, t)
                p = item.pitch = ly.pitch.Pitch(*r)
                for t in source:
                    if isinstance(t, lilypond.Octave):
                        p.octave = ly.pitch.octaveToNum(t)
                        item.octave_token = t
                    elif isinstance(t, lilypond.Accidental):
                        item.accidental_token = p.accidental = t
                    elif isinstance(t, lilypond.OctaveCheck):
                        p.octavecheck = ly.pitch.octaveToNum(t)
                        item.octavecheck_token = t
                        break
                    elif not isinstance(t, lex.Space):
                        self.source.pushback()
                        break
        else:
            cls = {
                lilypond.Rest: Rest,
                lilypond.Skip: Skip,
                lilypond.Spacer: Skip,
                lilypond.Q: Q,
                lilypond.DrumNote: DrumNote,
            }[t.__class__]
            item = self.factory(cls, t)
        if item:
            if not self.in_chord and not in_pitch_command:
                self.add_duration(item, None, source)
        return item
    
    @_commands('\\relative')
    def handle_relative(self, t, source):
        item = self.factory(Relative, t)
        # get one pitch and exit on a non-comment
        pitch_found = False
        for i in self.read(source):
            item.append(i)
            if not pitch_found and isinstance(i, Note):
                pitch_found = True
                continue
            break
        return item
    
    @_commands('\\absolute')
    def handle_absolute(self, t, source):
        item = self.factory(Absolute, t)
        for i in self.read(source):
            item.append(i)
            break
        return item
    
    @_commands('\\transpose')
    def handle_transpose(self, t, source):
        item = self.factory(Transpose, t)
        # get two pitches
        pitches_found = 0
        for i in self.read(source):
            item.append(i)
            if pitches_found < 2 and isinstance(i, Note):
                pitches_found += 1
                continue
            break
        return item
    
    @_commands('\\clef')
    def handle_clef(self, t, source):
        item = self.factory(Clef, t)
        for t in skip(source):
            if isinstance(t, lilypond.ClefSpecifier):
                item._specifier = t
            elif isinstance(t, lex.StringStart):
                item._specifier = self.factory(String, t, True)
            break
        return item
    
    @_commands('\\key')
    def handle_key(self, t, source):
        item = self.factory(KeySignature, t)
        item.extend(itertools.islice(self.read(source), 2))
        return item
    
    @_commands('\\times', '\\tuplet', '\\scaleDurations')
    def handle_scaler(self, t, source):
        item = self.factory(Scaler, t)
        item.scaling = 1
        if t == '\\scaleDurations':
            for i in self.read(source):
                item.append(i)
                if isinstance(i, Number):
                    item.scaling = i.value()
                elif isinstance(i, Scheme):
                    try:
                        pair = i.get_pair_ints()
                        if pair:
                            item.scaling = Fraction(*pair)
                        else:
                            val = i.get_fraction()
                            if val is not None:
                                item.scaling = val
                    except ZeroDivisionError:
                        pass
                break
        elif t == '\\tuplet':
            for t in source:
                if isinstance(t, lilypond.Fraction):
                    item.append(self.factory(Number, t))
                    item.numerator, item.denominator = map(int, t.split('/'))
                    item.scaling = 1 / Fraction(t)
                elif isinstance(t, lilypond.Duration):
                    self.add_duration(item, t, source)
                    break
                elif not isinstance(t, lex.Space):
                    self.source.pushback()
                    break
        else: # t == '\\times'
            for t in source:
                if isinstance(t, lilypond.Fraction):
                    item.append(self.factory(Number, t))
                    item.numerator, item.denominator = map(int, t.split('/'))
                    item.scaling = Fraction(t)
                    break
                elif not isinstance(t, lex.Space):
                    self.source.pushback()
                    break
        for i in self.read(source):
            item.append(i)
            break
        return item
    
    @_commands('\\tag', '\\keepWithTag', '\\removeWithTag', '\\appendToTag', '\\pushToTag')
    def handle_tag(self, t, source):
        item = self.factory(Tag, t)
        argcount = 3 if t in ('\\appendToTag', '\\pushToTag') else 2
        item.extend(itertools.islice(self.read(), argcount))
        return item
    
    @_commands('\\grace', '\\acciaccatura', '\\appoggiatura', '\\slashedGrace')
    def handle_grace(self, t, source):
        item = self.factory(Grace, t)
        for i in self.read(source):
            item.append(i)
            break
        return item
    
    @_commands('\\afterGrace')
    def handle_after_grace(self, t, source):
        item = self.factory(AfterGrace, t)
        for i in itertools.islice(self.read(source), 2):
            item.append(i)
        # put the grace music in a Grace item
        if len(item) > 1:
            i = self.factory(Grace, position=item[-1].position)
            i.append(item[-1])
            item.append(i)
        return item
    
    @_commands('\\repeat')
    def handle_repeat(self, t, source):
        item = self.factory(Repeat, t)
        item._specifier = None
        item._repeat_count = None
        for t in skip(source):
            if isinstance(t, lilypond.RepeatSpecifier):
                item._specifier = t
            elif not item.specifier and isinstance(t, lex.StringStart):
                item._specifier = self.factory(String, t, True)
            elif isinstance(t, lilypond.RepeatCount):
                item._repeat_count = t
            elif isinstance(t, lilypond.SchemeStart):
                # the specifier or count may be specified using scheme
                s = self.read_scheme_item(t)
                if item._specifier:
                    if item._repeat_count:
                        item.append(s)
                        break
                    item._repeat_count = s
                else:
                    item._specifier = s
            else:
                self.source.pushback()
                for i in self.read(source):
                    item.append(i)
                    break
                for t in skip(source):
                    if t == '\\alternative' and isinstance(t, lilypond.Command):
                        item.append(self.handle_alternative(t, source))
                    else:
                        self.source.pushback()
                    break
                break
        return item
    
    @_commands('\\alternative')
    def handle_alternative(self, t, source):
        item = self.factory(Alternative, t)
        for i in self.read(source):
            item.append(i)
            break
        return item
    
    @_commands('\\tempo')
    def handle_tempo(self, t, source):
        item = self.factory(Tempo, t)
        source = self.consume()
        equal_sign_seen = False
        text_seen = False
        t = None
        for t in source:
            if not equal_sign_seen:
                if (not text_seen and isinstance(t,
                        (lilypond.SchemeStart, lex.StringStart, lilypond.Markup))):
                    item.append(self.read_item(t))
                    t = None
                    text_seen = True
                elif isinstance(t, lilypond.Length):
                    self.add_duration(item, t, source)
                    t = None
                elif isinstance(t, lilypond.EqualSign):
                    item.tokens = (t,)
                    equal_sign_seen = True
                    t = None
            elif isinstance(t, (lilypond.IntegerValue, lilypond.SchemeStart)):
                item.append(self.read_item(t))
            elif t == "-":
                item.tokens += (t,)
        ## if the last token does not belong to the \\tempo expression anymore,
        ## push it back
        if t and not isinstance(t, (lex.Space, lex.Comment)):
            self.source.pushback()
        return item
    
    @_commands('\\time')
    def handle_time(self, t, source):
        item = self.factory(TimeSignature, t)
        for t in skip(source):
            if isinstance(t, lilypond.SchemeStart):
                item._beatstructure = self.read_scheme_item(t)
                continue
            elif isinstance(t, lilypond.Fraction):
                item._num, den = map(int, t.split('/'))
                item._fraction = Fraction(1, den)
            else:
                self.source.pushback()
            break
        return item
    
    @_commands('\\partial')
    def handle_partial(self, t, source):
        item = self.factory(Partial, t)
        self.add_duration(item, None, source)
        return item
    
    @_commands('\\new', '\\context', '\\change')
    def handle_translator(self, t, source):
        cls = Change if t == '\\change' else Context 
        item = self.factory(cls, t)
        isource = self.consume()
        for t in skip(isource):
            if isinstance(t, (lilypond.ContextName, lilypond.Name)):
                item._context = t
                for t in isource:
                    if isinstance(t, lilypond.EqualSign):
                        for t in isource:
                            if isinstance(t, lex.StringStart):
                                item._context_id = self.factory(String, t, True)
                                break
                            elif isinstance(t, lilypond.Name):
                                item._context_id = t
                                break
                            elif not isinstance(t, lex.Space):
                                self.source.pushback()
                                break
                    elif not isinstance(t, lex.Space):
                        self.source.pushback()
                        break
            else:
                self.source.pushback()
            break
        if cls is not Change:
            for i in self.read(source):
                item.append(i)
                if not isinstance(i, With):
                    break
        return item
    
    _inputmode_commands = {
        '\\notemode': NoteMode,
        '\\notes': NoteMode,
        '\\chordmode': ChordMode,
        '\\chords': ChordMode,
        '\\figuremode': FigureMode,
        '\\figures': FigureMode,
        '\\drummode': DrumMode,
        '\\drums': DrumMode,
    }
    @_commands(*_inputmode_commands)
    def handle_inputmode(self, t, source):
        cls = self._inputmode_commands[t]
        item = self.factory(cls, t)
        for i in self.read():
            item.append(i)
            break
        return item
    
    _lyricmode_commands = {
        '\\lyricmode': LyricMode,
        '\\lyrics': LyricMode,
        '\\oldaddlyrics': LyricMode,
        '\\addlyrics': LyricMode,
        '\\lyricsto': LyricsTo,
    }
    @_commands(*_lyricmode_commands)
    def handle_lyricmode(self, t, source):
        cls = self._lyricmode_commands[t]
        item = self.factory(cls, t)
        if cls is LyricsTo:
            for t in skip(source):
                if isinstance(t, lilypond.Name):
                    item._context_id = t
                elif isinstance(t, (lex.String, lilypond.SchemeStart)):
                    item._context_id = self.read_item(t)
                else:
                    self.source.pushback()
                break
        for t in skip(self.consume()):
            i = self.read_lyric_item(t) or self.read_item(t)
            if i:
                item.append(i)
            break
        return item
    
    def read_lyric_item(self, t):
        """Read one lyric item. Returns None for tokens it does not handle."""
        if isinstance(t, (lex.StringStart, lilypond.MarkupStart)):
            item = self.factory(LyricText, position=t.pos)
            item.append(self.read_item(t))
            self.add_duration(item)
            return item
        elif isinstance(t, lilypond.LyricText):
            item = self.factory(LyricText, t)
            self.add_duration(item)
            return item
        elif isinstance(t, lilypond.Lyric):
            return self.factory(LyricItem, t)
        else:
            item, source = self.test_music_list(t)
            if item:
                if source:
                    for t in skip(source):
                        i = self.read_lyric_item(t) or self.read_item(t)
                        if i:
                            item.append(i)
                return item
    
    @_commands('\\stringTuning')
    def handle_string_tuning(self, t, source):
        item = self.factory(StringTuning, t)
        for arg in self.read(source):
            item.append(arg)
            break
        return item
    
    @_commands('\\partcombine')
    def handle_partcombine(self, t, source=None):
        item = self.factory(PartCombine, t)
        item.extend(itertools.islice(self.read(), 2))
        return item
    
    @_keywords('\\language')
    def handle_language(self, t, source):
        item = self.factory(Language, t)
        for name in self.read(source):
            item.append(name)
            if isinstance(name, String):
                value = item.language = name.value()
                if value in ly.pitch.pitchInfo:
                    self.language = value
            break
        return item
    
    @_keywords('\\include')
    def handle_include(self, t, source):
        item = None
        name = None
        for name in self.read(source):
            if isinstance(name, String):
                value = name.value()
                if value.endswith('.ly') and value[:-3] in ly.pitch.pitchInfo:
                    item = self.factory(Language, t)
                    item.language = self.language = value[:-3]
                    item.append(name)
            break
        if not item:
            item = self.factory(Include, t)
            if name:
                item.append(name)
        return item
    
    @_keywords('\\version')
    def handle_version(self, t, source):
        item = self.factory(Version, t)
        for arg in self.read(source):
            item.append(arg)
            break
        return item
    
    _bracketed_keywords = {
        '\\header': Header,
        '\\score': Score,
        '\\bookpart': BookPart,
        '\\book': Book,
        '\\paper': Paper,
        '\\layout': Layout,
        '\\midi': Midi,
        '\\with': With,
        '\\context': LayoutContext,
    }
    @_keywords(*_bracketed_keywords)
    def handle_bracketed(self, t, source):
        cls = self._bracketed_keywords[t]
        item = self.factory(cls, t)
        if not self.add_bracketed(item, source) and t == '\\with':
            # \with also supports one other argument instead of { ... }
            for i in self.read(source):
                item.append(i)
                break
        return item
    
    @_keywords('\\set')
    def handle_set(self, t, source):
        item = self.factory(Set, t)
        tokens = []
        for t in skip(source):
            tokens.append(t)
            if isinstance(t, lilypond.EqualSign):
                item.tokens = tuple(tokens)
                for i in self.read(source):
                    item.append(i)
                    break
                break
        return item
    
    @_keywords('\\unset')
    def handle_unset(self, t, source):
        item = self.factory(Unset, t)
        tokens = []
        for t in skip(self.consume()):
            if type(t) not in lilypond.ParseUnset.items:
                self.source.pushback()
                break
            tokens.append(t)
        item.tokens = tuple(tokens)
        return item
    
    @_keywords('\\override')
    def handle_override(self, t, source):
        item = self.factory(Override, t)
        for t in skip(self.consume()):
            if isinstance(t, (lex.StringStart, lilypond.SchemeStart)):
                item.append(self.read_item(t))
            elif isinstance(t, lilypond.EqualSign):
                item.tokens = (t,)
                for i in self.read():
                    item.append(i)
                    break
                break
            else:
                item.append(self.factory(PathItem, t))
        return item
    
    @_keywords('\\revert')
    def handle_revert(self, t, source):
        item = self.factory(Revert, t)
        t = None
        for t in skip(self.consume()):
            if type(t) in lilypond.ParseRevert.items:
                item.append(self.factory(PathItem, t))
            else:
                break
        if isinstance(t, lilypond.SchemeStart) and not any(
                isinstance(i.token, lilypond.GrobProperty) for i in item):
            item.append(self.read_scheme_item(t))
        else:
            self.source.pushback()
        return item
    
    @_keywords('\\tweak')
    def handle_tweak(self, t, source):
        item = self.factory(Tweak, t)
        t = None
        for t in skip(self.consume()):
            if type(t) in lilypond.ParseTweak.items:
                item.append(self.factory(PathItem, t))
            else:
                self.source.pushback()
                break
        if len(item) == 0 and isinstance(t, lilypond.SchemeStart):
            item.append(self.read_scheme_item(t))
        for i in self.read():
            item.append(i)
            break
        return item
    
    @_commands('\\markup', '\\markuplist', '\\markuplines')
    def handle_markup(self, t, source=None):
        item = self.factory(Markup, t)
        self.add_markup_arguments(item)
        return item
        
    def read_markup(self, t):
        """Read LilyPond markup (recursively)."""
        meth = self._markup.method(t)
        if meth:
            return meth(self, t)
    
    @_markup(lilypond.MarkupScore)
    def handle_markup_score(self, t):
        item = self.factory(MarkupScore, t)
        for t in self.consume():
            if isinstance(t, lilypond.OpenBracket):
                item.tokens = (t,)
                def last(t): item.tokens += (t,)
                item.extend(self.read(self.consume(last)))
                return item
            elif not isinstance(t, lex.Space):
                self.source.pushback()
                break
        return item
    
    @_markup(lilypond.MarkupCommand)
    def handle_markup_command(self, t):
        item = self.factory(MarkupCommand, t)
        self.add_markup_arguments(item)
        return item
    
    @_markup(lilypond.MarkupUserCommand)
    def handle_markup_user_command(self, t):
        item = self.factory(MarkupUserCommand, t)
        return item
    
    @_markup(lilypond.OpenBracketMarkup)
    def handle_markup_open_bracket(self, t):
        item = self.factory(MarkupList, t)
        self.add_markup_arguments(item)
        return item
    
    @_markup(lilypond.MarkupWord)
    def handle_markup_word(self, t):
        return self.factory(MarkupWord, t)
    
    def add_markup_arguments(self, item):
        """Add markup arguments to the item."""
        for t in self.consume():
            i = self.read_markup(t)
            if i:
                item.append(i)
            elif isinstance(item, MarkupList) and isinstance(t, lilypond.CloseBracketMarkup):
                item.tokens = (t,)
        return item
    
    def read_scheme_item(self, t):
        """Reads a Scheme expression (just after the # in LilyPond mode)."""
        item = self.factory(Scheme, t)
        for t in self.consume():
            if not isinstance(t, lex.Space):
                i = self.read_scheme(t)
                if i:
                    item.append(i)
                    break
        return item

    def read_scheme(self, t):
        """Return a Scheme item from the token t."""
        meth = self._scheme.method(t)
        if meth:
            return meth(self, t)
        
    @_scheme(scheme.Quote)
    def handle_scheme_quote(self, t):
        item = self.factory(SchemeQuote, t)
        for t in self.consume():
            if not isinstance(t, lex.Space):
                i = self.read_scheme(t)
                if i:
                    item.append(i)
                    break
        return item
    
    @_scheme(scheme.OpenParen)
    def handle_scheme_open_parenthesis(self, t):
        item = self.factory(SchemeList, t)
        def last(t): item.tokens = (t,)
        for t in self.consume(last):
            if not isinstance(t, lex.Space):
                i = self.read_scheme(t)
                if i:
                    item.append(i)
        return item
    
    @_scheme(
        scheme.Dot,
        scheme.Bool,
        scheme.Char,
        scheme.Word,
        scheme.Number,
        scheme.Fraction,
        scheme.Float,
    )
    def handle_scheme_token(self, t):
        return self.factory(SchemeItem, t)
    
    @_scheme(scheme.LilyPondStart)
    def handle_scheme_lilypond_start(self, t):
        item = self.factory(SchemeLily, t)
        def last(t): item.tokens = (t,)
        item.extend(self.read(self.consume(last)))
        return item


python_ly-0.9.9/ly/musicxml/__init__.py0000644000000000000000000000306113615410400015074 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
MusicXML functionality.

This subpackage is created to convert LilyPond text to MusicXML with the help
of the tree structure created by ly.music. But it is constructed in such a way
that you can use some of the submodules for generic MusicXML creation and manipulation.
"""

from __future__ import unicode_literals

def writer():
    """Convert LilyPond text to MusicXML

    Example::

        import ly.musicxml
        e = ly.musicxml.writer()
        e.parse_text(lilypond_text)
        xml = e.musicxml()
        xml.write(filename)         # or: xml.tostring()
        # xml.tree is the ElementTree xml tree.

    """

    from . import lymus2musxml
    return lymus2musxml.ParseSource()


python_ly-0.9.9/ly/musicxml/create_musicxml.py0000644000000000000000000006476413615410400016542 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Uses xml.etree to create a Music XML document.

Example::

    musxml = create_musicxml.CreateMusicXML()
    musxml.create_part()
    musxml.create_measure(divs=1)
    musxml.new_note('C', 4, 'whole', 4)
    xml = musxml.musicxml()
    xml.write(filename)

"""

from __future__ import unicode_literals
from __future__ import division

import sys
try:
    import xml.etree.cElementTree as etree
except ImportError:
    import xml.etree.ElementTree as etree


import ly.pkginfo

from .midi_sound_map import midi_sound_map

class CreateMusicXML():
    """ Creates the XML nodes according to the Music XML standard."""

    def __init__(self):
        """Creates the basic structure of the XML without any music."""
        self.root = etree.Element("score-partwise", version="3.0")
        self.tree = etree.ElementTree(self.root)
        self.score_info = etree.SubElement(self.root, "identification")
        encoding = etree.SubElement(self.score_info, "encoding")
        software = etree.SubElement(encoding, "software")
        software.text = "python-ly " + ly.pkginfo.version
        encoding_date = etree.SubElement(encoding, "encoding-date")
        import datetime
        encoding_date.text = str(datetime.date.today())
        self.partlist = etree.SubElement(self.root, "part-list")
        self.part_count = 1

    ##
    # Building the basic Elements
    ##

    def create_title(self, title):
        """Create score title."""
        mov_title = etree.Element("movement-title")
        mov_title.text = title
        self.root.insert(0, mov_title)

    def create_score_info(self, tag, info, attr={}):
        """Create score info."""
        info_node = etree.SubElement(self.score_info, tag, attr)
        info_node.text = info

    def create_partgroup(self, gr_type, num, name=None, abbr=None, symbol=None):
        """Create a new part group."""
        attr_dict = {"type": gr_type, "number": str(num)}
        partgroup = etree.SubElement(self.partlist, "part-group", attr_dict)
        if name:
            group_name = etree.SubElement(partgroup, "group-name")
            group_name.text = name
        if abbr:
            group_abbr = etree.SubElement(partgroup, "group-abbreviation")
            group_abbr.text = abbr
        if symbol:
            group_symbol = etree.SubElement(partgroup, "group-symbol")
            group_symbol.text = symbol

    def create_part(self, name="unnamed", abbr=False, midi=False):
        """Create a new part """
        strnr = str(self.part_count)
        part = etree.SubElement(self.partlist, "score-part", id="P"+strnr)
        partname = etree.SubElement(part, "part-name")
        partname.text = name
        if abbr:
            partabbr = etree.SubElement(part, "part-abbreviation")
            partabbr.text = abbr
        if midi:
            scoreinstr = etree.SubElement(part, "score-instrument", id="P"+strnr+"-I"+strnr)
            instrname = etree.SubElement(scoreinstr, "instrument-name")
            instrname.text = midi

            if midi in midi_sound_map and midi_sound_map[midi]:
                instrsound = etree.SubElement(scoreinstr, "instrument-sound")
                instrsound.text = midi_sound_map[midi]

            midiinstr = etree.SubElement(part, "midi-instrument", id="P"+strnr+"-I"+strnr)
            midich = etree.SubElement(midiinstr, "midi-channel")
            midich.text = strnr
            midiname = etree.SubElement(midiinstr, "midi-name")
            midiname.text = midi
        self.current_part = etree.SubElement(self.root, "part", id="P"+strnr)
        self.part_count += 1
        self.bar_nr = 1

    def create_measure(self, pickup = False, **bar_attrs):
        """Create new measure """
        if pickup and self.bar_nr == 1:
            self.bar_nr = 0
        self.current_bar = etree.SubElement(self.current_part, "measure", number=str(self.bar_nr))
        self.bar_nr +=1
        if bar_attrs:
            self.new_bar_attr(**bar_attrs)

    ##
    # High-level node creation
    ##

    def new_note(self, step, octave, durtype, divdur, alter=0,
                 acc_token=0, voice=1, dot=0, chord=0, grace=(0, 0), stem_dir=0):
        """Create all nodes needed for a normal note. """
        self.create_note()
        if grace[0]:
            self.add_grace(grace[1])
        if chord:
            self.add_chord()
        self.add_pitch(step, alter, octave)
        if not grace[0]:
            self.add_div_duration(divdur)
        self.add_voice(voice)
        self.add_duration_type(durtype)
        if dot:
            for i in range(dot):
                self.add_dot()
        if alter or acc_token:
            if acc_token == '!': # cautionary
                self.add_accidental(alter, caut=True)
            elif acc_token == '?': # parentheses
                self.add_accidental(alter, parenth=True)
            else:
                self.add_accidental(alter)
        if stem_dir:
            self.set_stem_dir(stem_dir)

    def new_unpitched_note(self, step, octave, durtype, divdur, voice=1,
                            dot=0, chord=0, grace=(0, 0)):
        """Create all nodes needed for an unpitched note. """
        self.create_note()
        if grace[0]:
            self.add_grace(grace[1])
        if chord:
            self.add_chord()
        self.add_unpitched(step, octave)
        if not grace[0]:
            self.add_div_duration(divdur)
        self.add_duration_type(durtype)
        self.add_voice(voice)
        if dot:
            for i in range(dot):
                self.add_dot()

    def tuplet_note(self, fraction, bs, ttype, nr, divs, atyp='', ntyp=''):
        """Convert current note to tuplet """
        base = self.mult * bs[0]
        scaling = bs[1]
        a = divs*4*fraction[1]
        b = (1/base)*fraction[0]
        duration = (a/b)*scaling
        self.change_div_duration(duration)
        from fractions import Fraction
        self.mult = Fraction(fraction[1], fraction[0])
        timemod_node = self.get_time_modify()
        if timemod_node:
            self.adjust_time_modify(timemod_node, fraction)
        else:
            self.add_time_modify(fraction)
        if ttype:
            self.add_notations()
            if atyp and ttype != "stop":
                self.add_tuplet_type(nr, ttype, fraction[0], atyp, fraction[1], ntyp)
            else:
                self.add_tuplet_type(nr, ttype)

    def tie_note(self, tie_type):
        self.add_tie(tie_type)
        self.add_notations()
        self.add_tied(tie_type)

    def new_rest(self, duration, durtype, pos, dot, voice):
        """Create all nodes needed for a rest. """
        self.create_note()
        if pos:
            self.add_rest_w_pos(pos[0], pos[1])
        else:
            self.add_rest()
        self.add_div_duration(duration)
        self.add_voice(voice)
        if durtype:
            self.add_duration_type(durtype)
        if dot:
            for i in range(dot):
                self.add_dot()

    def new_articulation(self, artic):
        """Add specified articulation. """
        self.add_notations()
        self.add_articulations()
        self.add_named_artic(artic)

    def new_simple_ornament(self, ornament):
        """Add specified ornament. """
        self.add_notations()
        self.add_ornaments()
        func_call = getattr(self, 'add_'+ornament)
        func_call()

    def new_adv_ornament(self, ornament, args):
        """Add more complex ornament."""
        self.add_notations()
        self.add_ornaments()
        if ornament == "wavy-line":
            self.add_wavyline(args['type'])

    def new_bar_attr(self, clef=0, mustime=0, key=None, mode=0, divs=0, multirest=0):
        """Create all bar attributes set. """
        self.create_bar_attr()
        if divs:
            self.add_divisions(divs)
        if key is not None:
            self.add_key(key, mode)
        if mustime:
            self.add_time(mustime)
        if clef:
            sign, line, octch = clef
            self.add_clef(sign, line, oct_ch=octch)
        if multirest:
            self.add_bar_style(multirest)

    def create_tempo(self, words, metronome, sound, dots):
        self.add_direction()
        if words:
            self.add_dirwords(words)
        if metronome:
            self.add_metron_dir(metronome[0], metronome[1], dots)
            self.add_sound_dir(sound)

    def create_new_node(self, parentnode, nodename, txt):
        """ The Music XML language is extensive.
        This function can be used to create
        a non basic node not covered elsewhere in this script.

        TODO: add attributes
        """
        new_node = etree.SubElement(parentnode, nodename)
        new_node.text = str(txt)


    ##
    # Low-level node creation
    ##

    def add_creator(self, creator, name):
        """Add creator to score info."""
        attr = {'type': creator }
        self.create_score_info("creator", name, attr)

    def add_rights(self, rights, type=None):
        """Add rights to score info."""
        attr = {'type': type} if type else {}
        self.create_score_info("rights", rights, attr)

    def create_note(self):
        """Create new note."""
        self.current_note = etree.SubElement(self.current_bar, "note")
        self.current_notation = None
        self.current_artic = None
        self.current_ornament = None
        self.current_tech = None

    def add_pitch(self, step, alter, octave):
        """Create new pitch."""
        pitch = etree.SubElement(self.current_note, "pitch")
        stepnode = etree.SubElement(pitch, "step")
        stepnode.text = str(step)
        if alter:
            altnode = etree.SubElement(pitch, "alter")
            altnode.text = str(alter)
        octnode = etree.SubElement(pitch, "octave")
        octnode.text = str(octave)

    def add_unpitched(self, step, octave):
        """Create unpitched."""
        unpitched = etree.SubElement(self.current_note, "unpitched")
        stepnode = etree.SubElement(unpitched, "display-step")
        stepnode.text = str(step)
        octnode = etree.SubElement(unpitched, "display-octave")
        octnode.text = str(octave)

    def add_accidental(self, alter, caut=False, parenth=False):
        """Create accidental."""
        attrib = {}
        if caut:
            attrib['cautionary'] = 'yes'
        if parenth:
            attrib['parentheses'] = 'yes'
        acc = etree.SubElement(self.current_note, "accidental", attrib)
        acc_dict = {
        0: 'natural',
        1: 'sharp', -1: 'flat',
        2: 'sharp-sharp', -2: 'flat-flat',
        0.5: 'natural-up', -0.5: 'natural-down',
        1.5: 'sharp-up', -1.5: 'flat-down'
        }
        acc.text = acc_dict[alter]

    def set_stem_dir(self, dir):
        stem_dir = etree.SubElement(self.current_note, "stem")
        stem_dir.text = dir

    def add_rest(self):
        """Create rest."""
        etree.SubElement(self.current_note, "rest")

    def add_rest_w_pos(self, step, octave):
        """Create rest with display position."""
        restnode = etree.SubElement(self.current_note, "rest")
        stepnode = etree.SubElement(restnode, "display-step")
        octnode = etree.SubElement(restnode, "display-octave")
        stepnode.text = str(step)
        octnode.text = str(octave)

    def add_skip(self, duration, forward=True):
        if forward:
            skip = etree.SubElement(self.current_bar, "forward")
        else:
            skip = etree.SubElement(self.current_bar, "backward")
        dura_node = etree.SubElement(skip, "duration")
        dura_node.text = str(duration)

    def add_div_duration(self, divdur):
        """Create new duration """
        self.duration = etree.SubElement(self.current_note, "duration")
        self.duration.text = str(divdur)
        self.mult = 1

    def change_div_duration(self, newdura):
        """Set new duration when tuplet """
        self.duration.text = str(newdura)

    def add_duration_type(self, durtype):
        """Create new type """
        typenode = etree.SubElement(self.current_note, "type")
        typenode.text = str(durtype)

    def add_dot(self):
        """Create a dot """
        etree.SubElement(self.current_note, "dot")

    def add_beam(self, nr, beam_type):
        """Add beam. """
        beam_node = etree.SubElement(self.current_notation, "beam", number=str(nr))
        beam_node.text = beam_type

    def add_tie(self, tie_type):
        """Create node tie (used for sound of tie) """
        # A tie must be directly after a duration
        insert_at = get_tag_index(self.current_note, "duration") + 1
        tie_element = etree.Element("tie", type=tie_type)
        self.current_note.insert(insert_at, tie_element)

    def add_grace(self, slash):
        """Create grace node """
        if slash:
            etree.SubElement(self.current_note, "grace", slash="yes")
        else:
            etree.SubElement(self.current_note, "grace")

    def add_notations(self):
        if not self.current_notation:
            self.current_notation = etree.SubElement(self.current_note, "notations")

    def add_tied(self, tie_type):
        """Create node tied (used for notation of tie) """
        etree.SubElement(self.current_notation, "tied", type=tie_type)

    def add_time_modify(self, fraction):
        """Create time modification """
        index = get_tag_index(self.current_note, "accidental")
        if index == -1:
            index = get_tag_index(self.current_note, "dot")
        if index == -1:
            index = get_tag_index(self.current_note, "type")
        timemod_node = etree.Element("time-modification")
        actual_notes = etree.SubElement(timemod_node, "actual-notes")
        actual_notes.text = str(fraction[0])
        norm_notes = etree.SubElement(timemod_node, "normal-notes")
        norm_notes.text = str(fraction[1])
        self.current_note.insert(index + 1, timemod_node)

    def get_time_modify(self):
        """Check if time-modification node already exists."""
        return self.current_note.find("time-modification")

    def adjust_time_modify(self, timemod_node, fraction):
        """Adjust existing time-modification node."""
        actual_notes = timemod_node.find("actual-notes")
        an = int(actual_notes.text) * fraction[0]
        actual_notes.text = str(an)
        norm_notes = timemod_node.find("normal-notes")
        nn = int(norm_notes.text) * fraction[1]
        norm_notes.text = str(nn)

    def add_tuplet_type(self, nr, ttype, actnr=0, acttype='', normnr=0, normtype=''):
        """Create tuplet with type attribute """
        tuplnode = etree.SubElement(self.current_notation, "tuplet",
                                    {'number': str(nr), 'type': ttype })
        if actnr:
            actnode = etree.SubElement(tuplnode, "tuplet-actual")
            atn = etree.SubElement(actnode, "tuplet-number")
            atn.text = str(actnr)
            att = etree.SubElement(actnode, "tuplet-type")
            if not acttype:
                acttype = self.current_note.find("type").text
            att.text = acttype
        if normnr:
            normnode = etree.SubElement(tuplnode, "tuplet-normal")
            ntn = etree.SubElement(normnode, "tuplet-number")
            ntn.text = str(normnr)
            ntt = etree.SubElement(normnode, "tuplet-type")
            if not normtype:
                normtype = self.current_note.find("type").text
            ntt.text = normtype

    def add_slur(self, nr, sl_type):
        """Add slur. """
        self.add_notations()
        etree.SubElement(self.current_notation, "slur", {'number': str(nr), 'type': sl_type })

    def add_named_notation(self, notate):
        """Fermata, etc. """
        self.add_notations()
        etree.SubElement(self.current_notation, notate)

    def add_articulations(self):
        """Common function for creating all types of articulations. """
        if not self.current_artic:
            self.current_artic = etree.SubElement(self.current_notation, "articulations")

    def add_named_artic(self, artic):
        """Add articulation with specified name. """
        etree.SubElement(self.current_artic, artic)

    def add_ornaments(self):
        if not self.current_ornament:
            self.add_notations()
            self.current_ornament = etree.SubElement(self.current_notation, "ornaments")

    def add_tremolo(self, trem_type, lines):
        self.add_ornaments()
        trem_node = etree.SubElement(self.current_ornament, "tremolo", type=trem_type)
        trem_node.text = str(lines)

    def add_trill(self):
        etree.SubElement(self.current_ornament, "trill-mark")

    def add_turn(self):
        etree.SubElement(self.current_ornament, "turn")

    def add_mordent(self):
        etree.SubElement(self.current_ornament, "mordent")

    def add_prall(self):
        etree.SubElement(self.current_ornament, "inverted-mordent")

    def add_wavyline(self, end_type):
        self.add_ornaments
        etree.SubElement(self.current_ornament, "wavy-line", type=end_type)

    def add_gliss(self, linetype, endtype, nr):
        nodedict = { "line-type": linetype, "number": str(nr), "type": endtype }
        self.add_notations()
        etree.SubElement(self.current_notation, "glissando", nodedict)

    def add_technical(self):
        if not self.current_tech:
            self.add_notations()
            self.current_tech = etree.SubElement(self.current_notation, "technical")

    def add_fingering(self, finger_nr):
        self.add_technical()
        fing_node = etree.SubElement(self.current_tech, "fingering")
        fing_node.text = str(finger_nr)

    def create_bar_attr(self):
        """Create node attributes """
        self.bar_attr = etree.SubElement(self.current_bar, "attributes")

    def add_divisions(self, div):
        division = etree.SubElement(self.bar_attr, "divisions")
        division.text = str(div)

    def add_key(self, key, mode):
        keynode = etree.SubElement(self.bar_attr, "key")
        fifths = etree.SubElement(keynode, "fifths")
        fifths.text = str(key)
        modenode = etree.SubElement(keynode, "mode")
        modenode.text = str(mode)

    def add_time(self, timesign):
        if len(timesign)==3:
            timenode = etree.SubElement(self.bar_attr, "time", symbol=timesign[2])
        else:
            timenode = etree.SubElement(self.bar_attr, "time")
        beatnode = etree.SubElement(timenode, "beats")
        beatnode.text = str(timesign[0])
        typenode = etree.SubElement(timenode, "beat-type")
        typenode.text = str(timesign[1])

    def add_clef(self, sign, line, nr=0, oct_ch=0):
        if nr:
            clefnode = etree.SubElement(self.bar_attr, "clef", number=str(nr))
        else:
            clefnode = etree.SubElement(self.bar_attr, "clef")
        signnode = etree.SubElement(clefnode, "sign")
        signnode.text = str(sign)
        if line:
            linenode = etree.SubElement(clefnode, "line")
            linenode.text = str(line)
        if oct_ch:
            octchnode = etree.SubElement(clefnode, "clef-octave-change")
            octchnode.text = str(oct_ch)

    def add_bar_style(self, multirest=None):
        bar_style = etree.SubElement(self.bar_attr, "measure-style")
        if multirest:
            multirestnode = etree.SubElement(bar_style, "multiple-rest")
            multirestnode.text = str(multirest)

    def new_system(self, force_break):
        etree.SubElement(self.current_bar, "print", {'new-system':force_break})

    def add_barline(self, bl_type, repeat=None):
        barnode = etree.SubElement(self.current_bar, "barline", location="right")
        barstyle = etree.SubElement(barnode, "bar-style")
        barstyle.text = bl_type
        if repeat:
            repeatnode = etree.SubElement(barnode, "repeat", direction=repeat)

    def add_backup(self, duration):
        if duration <= 0:
            return
        backupnode = etree.SubElement(self.current_bar, "backup")
        durnode = etree.SubElement(backupnode, "duration")
        durnode.text = str(duration)

    def add_voice(self, voice):
        voicenode = etree.SubElement(self.current_note, "voice")
        voicenode.text = str(voice)

    def add_staff(self, staff):
        staffnode = etree.SubElement(self.current_note, "staff")
        staffnode.text = str(staff)

    def add_staves(self, staves):
        index = get_tag_index(self.bar_attr, "time")
        stavesnode = etree.Element("staves")
        stavesnode.text = str(staves)
        self.bar_attr.insert(index + 1, stavesnode)

    def add_chord(self):
        etree.SubElement(self.current_note, "chord")

    def add_direction(self, pos="above"):
        self.direction = etree.SubElement(self.current_bar, "direction", placement=pos)

    def add_dynamic_mark(self, dyn):
        """Add specified dynamic mark."""
        direction = etree.SubElement(self.current_bar, "direction", placement='below')
        dirtypenode = etree.SubElement(direction, "direction-type")
        dyn_node = etree.SubElement(dirtypenode, "dynamics")
        dynexpr_node = etree.SubElement(dyn_node, dyn)

    def add_dynamic_wedge(self, wedge_type):
        """Add dynamic wedge/hairpin."""
        direction = etree.SubElement(self.current_bar, "direction", placement='below')
        dirtypenode = etree.SubElement(direction, "direction-type")
        dyn_node = etree.SubElement(dirtypenode, "wedge", type=wedge_type)

    def add_dynamic_text(self, text):
        """Add dynamic text."""
        direction = etree.SubElement(self.current_bar, "direction", placement='below')
        dirtypenode = etree.SubElement(direction, "direction-type")
        dyn_node = etree.SubElement(dirtypenode, "words")
        dyn_node.attrib['font-style'] = 'italic'
        dyn_node.text = text

    def add_dynamic_dashes(self, text):
        """Add dynamics dashes."""
        direction = etree.SubElement(self.current_bar, "direction", placement='below')
        dirtypenode = etree.SubElement(direction, "direction-type")
        dyn_node = etree.SubElement(dirtypenode, "dashes", type=text)

    def add_octave_shift(self, plac, octdir, size):
        """Add octave shift."""
        oct_dict = {"type": octdir, "size": str(size) }
        direction = etree.SubElement(self.current_bar, "direction", placement=plac)
        dirtypenode = etree.SubElement(direction, "direction-type")
        dyn_node = etree.SubElement(dirtypenode, "octave-shift", oct_dict)

    def add_dirwords(self, words):
        """Add words in direction, e. g. a tempo mark."""
        if self.current_bar.find('direction') == None:
            self.add_direction()
        dirtypenode = etree.SubElement(self.direction, "direction-type")
        wordsnode = etree.SubElement(dirtypenode, "words")
        wordsnode.text = words

    def add_mark(self, mark):
        """Add rehearsal mark in direction"""
        if self.current_bar.find('direction') == None:
            self.add_direction()
        dirtypenode = etree.SubElement(self.direction, "direction-type")
        rehearsalnode = etree.SubElement(dirtypenode, "rehearsal")
        rehearsalnode.text = mark

    def add_metron_dir(self, unit, beats, dots):
        dirtypenode = etree.SubElement(self.direction, "direction-type")
        metrnode = etree.SubElement(dirtypenode, "metronome")
        bunode = etree.SubElement(metrnode, "beat-unit")
        bunode.text = unit
        if dots:
            for d in range(dots):
                etree.SubElement(metrnode, "beat-unit-dot")
        pmnode = etree.SubElement(metrnode, "per-minute")
        pmnode.text = str(beats)

    def add_sound_dir(self, midi_tempo):
        # FIXME: remove the int conversion once LilyPond accepts decimal tempo
        soundnode = etree.SubElement(self.direction, "sound", tempo=str(int(midi_tempo)))

    def add_lyric(self, txt, syll, nr, ext=False):
        """ Add lyric element. """
        lyricnode = etree.SubElement(self.current_note, "lyric", number=str(nr))
        syllnode = etree.SubElement(lyricnode, "syllabic")
        syllnode.text = syll
        txtnode = etree.SubElement(lyricnode, "text")
        txtnode.text = txt
        if ext:
            etree.SubElement(lyricnode, "extend")


    ##
    # Create the XML document
    ##

    def musicxml(self, prettyprint=True):
        xml = MusicXML(self.tree)
        if prettyprint:
            xml.indent("  ")
        return xml


class MusicXML(object):
    """Represent a generated MusicXML tree."""
    def __init__(self, tree):
        self.tree = tree
        self.root = tree.getroot()

    def indent(self, indent="  "):
        """Add indent and linebreaks to the created XML tree."""
        import ly.etreeutil
        ly.etreeutil.indent(self.root, indent)

    def tostring(self, encoding='UTF-8'):
        """Output etree as a XML document."""
        return etree.tostring(self.root, encoding=encoding, method="xml")

    def write(self, file, encoding='UTF-8', doctype=True):
        """Write XML to a file (file obj or filename)."""
        def write(f):
            if doctype:
                f.write((xml_decl_txt + "\n").format(encoding=encoding).encode(encoding))
                f.write((doctype_txt + "\n").encode(encoding))
                self.tree.write(f, encoding=encoding, xml_declaration=False)
            else:
                self.tree.write(f, encoding=encoding, xml_declaration=True, method="xml")
        if hasattr(file, 'write'):
            write(file)
            # do not close if it already was a file object
        else:
            # it is not a file object
            with open(file, 'wb') as f:
                write(f)


def get_tag_index(node, tag):
    """Return the (first) index of tag in node.

    If tag is not found, -1 is returned.
    """
    for i, elem in enumerate(list(node)):
        if elem.tag == tag:
            return i
    return -1


xml_decl_txt = """"""

doctype_txt = """"""
python_ly-0.9.9/ly/musicxml/ly2xml_mediator.py0000644000000000000000000011352613615410400016460 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
The information of the parsed source is organised into an object
structure with help of the classes in ly.musicxml.xml_objs.
"""

from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division

from fractions import Fraction

import ly.duration
import ly.pitch

from . import xml_objs


class Mediator():
    """Help class that acts as mediator between the ly source parser
    and the XML creating modules."""

    def __init__(self):
        """ create global lists """
        self.score = xml_objs.Score()
        self.sections = []
        """ default and initial values """
        self.insert_into = None
        self.current_note = None
        self.current_lynote = None
        self.current_is_rest = False
        self.current_time = Fraction(4, 4)
        self.bar_dura = Fraction(0, 4)
        self.action_onnext = []
        self.divisions = 1
        self.dur_token = "4"
        self.dur_tokens = ()
        self.dots = 0
        self.tied = False
        self.voice = 1
        self.staff = 0
        self.part = None
        self.group = None
        self.group_num = 0
        self.current_chord = []
        self.q_chord = []
        self.prev_pitch = None
        self.prev_chord_pitch = None
        self.store_voicenr = 0
        self.staff_id_dict = {}
        self.store_unset_staff = False
        self.staff_unset_notes = {}
        self.lyric_sections = {}
        self.lyric = None
        self.lyric_syll = False
        self.lyric_nr = 1
        self.ongoing_wedge = False
        self.ongoing_dashes = False
        self.octdiff = 0
        self.prev_tremolo = 8
        self.tupl_dur = 0
        self.tupl_sum = 0
        self.slur_stack = []
        self.multiple_rest = False
        self.multiple_rest_bar = None
        self.current_mark = 1
        self.bar_is_pickup = False
        self.stem_dir = None

    def new_header_assignment(self, name, value):
        """Distributing header information."""
        creators = ['composer', 'arranger', 'poet', 'lyricist']
        if name == 'title':
            self.score.title = value
        elif name in ['copyright', 'tagline']:
            self.score.add_right(value, name)
        elif name in creators:
            self.score.creators[name] = value
        else:
            self.score.info[name] = value

    def new_section(self, name, glob=False):
        name = self.check_name(name)
        section = xml_objs.ScoreSection(name, glob)
        self.insert_into = section
        self.sections.append(section)
        self.bar = None

    def new_snippet(self, name):
        name = self.check_name(name)
        snippet = xml_objs.Snippet(name, self.insert_into)
        self.insert_into = snippet
        self.sections.append(snippet)
        self.bar = None

    def new_lyric_section(self, name, voice_id):
        name = self.check_name(name)
        lyrics = xml_objs.LyricsSection(name, voice_id)
        self.insert_into = lyrics
        self.lyric_sections[name] = lyrics

    def check_name(self, name, nr=1):
        n = self.get_var_byname(name)
        if n:
            name = name+str(nr)
            name = self.check_name(name, nr+1)
        return name

    def get_var_byname(self, name):
        for n in self.sections:
            if n.name == name:
                return n

    def new_group(self):
        parent = self.group
        self.group_num += 1
        self.group = xml_objs.ScorePartGroup(self.group_num, "bracket")
        if parent: #nested group
            self.group.parent = parent
            parent.partlist.append(self.group)
        else:
            self.score.partlist.append(self.group)

    def close_group(self):
        if self.group.parent:
            self.group = self.group.parent
        else:
            self.group = None

    def change_group_bracket(self, system_start):
        self.group.set_bracket(get_group_symbol(system_start))

    def new_part(self, pid=None, to_part=None, piano=False):
        if piano:
            self.part = xml_objs.ScorePart(2, pid, to_part)
        else:
            self.part = xml_objs.ScorePart(part_id=pid, to_part=to_part)
        if not to_part:
            if self.group:
                self.group.partlist.append(self.part)
            else:
                self.score.partlist.append(self.part)
        self.insert_into = self.part
        self.bar = None

    def part_not_empty(self):
        return self.part and self.part.barlist

    def get_part_by_id(self, pid, partholder=None):
        if not partholder:
            partholder = self.score
        ret = False
        for part in partholder.partlist:
            if isinstance(part, xml_objs.ScorePartGroup):
                ret = self.get_part_by_id(pid, part)
            else:
                if part.part_id == pid:
                    ret = part
        return ret

    def set_voicenr(self, command=None, add=False, nr=0, piano=0):
        if add:
            if not self.store_voicenr:
                self.store_voicenr = self.voice
            self.voice += 1
        elif nr:
            self.voice = nr
        else:
            self.voice = get_voice(command)
            if piano>2:
                self.voice += piano+1

    def revert_voicenr(self):
        self.voice = self.store_voicenr
        self.store_voicenr = 0

    def set_staffnr(self, staffnr, staff_id=None):
        self.store_unset_staff = False
        if staffnr:
            self.staff = staffnr
        elif staff_id in self.staff_id_dict:
            self.staff = self.staff_id_dict[staff_id]
        elif staff_id:
            self.store_unset_staff = True
            self.staff = staff_id

    def add_staff_id(self, staff_id):
        self.store_unset_staff = False
        if staff_id:
            if staff_id in self.staff_id_dict:
                self.staff = self.staff_id_dict[staff_id]
            else:
                self.staff_id_dict[staff_id] = self.staff
            if staff_id in self.staff_unset_notes:
                for n in self.staff_unset_notes[staff_id]:
                    n.staff = self.staff

    def add_snippet(self, snippet_name):
        """ Adds snippet to previous barlist.
        A snippet can be shorter than a full bar,
        so this can also mean continuing a previous bar."""
        def continue_barlist(insert_into):
            self.insert_into = insert_into
            if insert_into.barlist:
                self.bar = insert_into.barlist[-1]
            else:
                self.new_bar(False)

        snippet = self.get_var_byname(snippet_name)
        continue_barlist(snippet.merge_barlist)
        for bb in snippet.barlist:
            for b in bb.obj_list:
                self.bar.add(b)
            if bb.list_full:
                self.new_bar()

    def check_voices(self):
        """ Checks active sections. The two latest created are merged.
        Also checks for empty sections. """
        if self.sections[-1].glob:
            self.score.merge_globally(self.sections[-1])
            self.score.glob_section.merge_voice(self.section[-1])
        if len(self.sections)>2:
            if not self.sections[-2].barlist:
                self.sections.pop(-2)
                self.check_voices()
            elif not self.sections[-1].barlist:
                self.sections.pop()
                self.check_voices()
            else:
                self.sections[-2].merge_voice(self.sections[-1])
                self.sections.pop()

    def check_voices_by_nr(self):
        """ Used for snippets. Merges all active snippets
        created after the stored voice number."""
        sect_len = len(self.sections)
        if sect_len>2:
            if self.voice>1:
                for n in range(self.store_voicenr, self.voice):
                    self.check_voices()
                if isinstance(self.sections[-1], xml_objs.Snippet):
                    self.add_snippet(self.sections[-1].name)
                    self.sections.pop()
                else:
                    print("WARNING: problem adding snippet!")

    def check_lyrics(self, voice_id):
        """Check the finished lyrics section and merge it into
        the referenced voice."""
        if self.lyric[1] == 'middle':
            self.lyric[1] = 'end'
        lyrics_section = self.lyric_sections['lyricsto'+voice_id]
        voice_section = self.get_var_byname(lyrics_section.voice_id)
        if voice_section:
            voice_section.merge_lyrics(lyrics_section)
        else:
            print("Warning can't merge in lyrics!", voice_section)

    def check_part(self):
        """Adds the latest active section to the part."""
        if len(self.sections)>1:
            if self.score.is_empty():
                self.new_part()
            if self.sections[-1].glob:
                self.part.merge_voice(self.sections[-1])
            else:
                self.part.barlist.extend(self.sections[-1].barlist)
                self.sections.pop()
        if self.part and self.part.to_part:
            self.part.merge_part_to_part()
        self.part.merge_voice(self.score.glob_section)
        name = self.check_name("glob")
        self.score.glob_section = self.part.extract_global_to_section(name)
        self.part = None

    def check_simultan(self):
        """Check done after simultanoues (<< >>) section."""
        if self.part:
            self.part.merge_voice(self.sections[-1])
        elif len(self.sections)>1:
             self.sections[-2].merge_voice(self.sections[-1])
        self.sections.pop()

    def check_score(self):
        """
        Check score

        If no part were created, place first variable (fallback) as part.

        Apply the latest global section.
        """
        if self.score.is_empty():
            self.new_part()
            self.part.barlist.extend(self.get_first_var())
        self.score.merge_globally(self.score.glob_section, override=True)

    def get_first_var(self):
        if self.sections:
            return self.sections[0].barlist

    def set_pickup(self):
        self.bar_is_pickup = True

    def new_bar(self, fill_prev=True):
        if self.bar and fill_prev:
            self.bar.list_full = True
        self.current_attr = xml_objs.BarAttr()
        self.bar = xml_objs.Bar()
        if self.bar_is_pickup:
            self.bar.pickup = True
            self.bar_is_pickup = False
        self.bar.obj_list = [self.current_attr]
        self.insert_into.barlist.append(self.bar)

    def add_to_bar(self, obj):
        if self.bar is None:
            self.new_bar()
        self.bar.add(obj)

    def create_barline(self, bl):
        barline = xml_objs.BarAttr()
        barline.set_barline(bl)
        self.bar.add(barline)
        self.new_bar()

    def new_repeat(self, rep):
        barline = xml_objs.BarAttr()
        barline.set_barline(rep)
        barline.repeat = rep
        if self.bar is None:
            self.new_bar()
        self.bar.add(barline)

    def new_key(self, key_name, mode):
        if self.bar is None:
            self.new_bar()
        if self.bar.has_music():
            new_bar_attr = xml_objs.BarAttr()
            new_bar_attr.set_key(get_fifths(key_name, mode), mode)
            self.add_to_bar(new_bar_attr)
        else:
            self.current_attr.set_key(get_fifths(key_name, mode), mode)

    def bijective(self, n):
        '''encodes an int to a sequence of letters'''
        import string
        digits = string.ascii_uppercase.replace("I","")
        result = []
        while n > 0:
            n, mod = divmod(n - 1, len(digits))
            result += digits[mod]
        return ''.join(reversed(result))

    def new_mark(self, num_mark = None):
        if num_mark == None:
            if self.bar is None:
                self.new_bar()
            if self.bar.has_attr():
                self.current_attr.set_mark(self.bijective(self.current_mark))
            else:
                new_bar_attr = xml_objs.BarAttr()
                new_bar_attr.set_mark(self.bijective(self.current_mark))
                self.add_to_bar(new_bar_attr)
        elif num_mark <= 0:
            print("Mark value out of range")
        else:
            self.current_mark = num_mark
            self.current_attr.set_mark(self.bijective(self.current_mark))
        self.current_mark += 1

    def new_word(self, word):
        if self.bar is None:
            self.new_bar()
        if self.bar.has_attr():
            self.current_attr.set_word(word)
        else:
            new_bar_attr = xml_objs.BarAttr()
            new_bar_attr.set_word(word)
            self.add_to_bar(new_bar_attr)

    def new_time(self, num, den, numeric=False):
        self.current_time = Fraction(num, den.denominator)
        if self.bar is None:
            self.new_bar()
        self.current_attr.set_time([num, den.denominator], numeric)

    def new_clef(self, clefname):
        self.clef = clefname2clef(clefname)
        if self.bar is None:
            self.new_bar()
        if self.bar.has_music():
            new_bar_attr = xml_objs.BarAttr()
            new_bar_attr.set_clef(self.clef)
            self.add_to_bar(new_bar_attr)
        else:
            if self.staff:
                self.current_attr.multiclef.append((self.clef, self.staff))
            else:
                self.current_attr.set_clef(self.clef)

    def set_relative(self, note):
        self.prev_pitch = note.pitch

    def increase_bar_dura(self, duration):
        self.bar_dura += duration[0] * duration[1]
        if self.bar_dura >= self.current_time:
            self.bar_dura = 0
            self.new_bar()

    def new_note(self, note, rel=False, is_unpitched=False):
        self.current_is_rest = False
        self.clear_chord()
        if is_unpitched:
            self.current_note = self.create_unpitched(note)
            self.check_current_note(is_unpitched=True)
        else:
            self.current_note = self.create_barnote_from_note(note)
            self.current_lynote = note
            self.check_current_note(rel)
        if self.stem_dir:
            self.current_note.set_stem_direction(self.stem_dir)
        self.do_action_onnext(self.current_note)
        self.action_onnext = []
        self.increase_bar_dura(note.duration)

    def new_iso_dura(self, note, rel=False, is_unpitched=False):
        """
        Isolated durations in music sequences.

        An isolated duration in LilyPond is rendered as a normal note but the
        pitch information is missing and has to be filled in by some other
        means, usually by the previous pitch. (RhythmicStaff is an exception
        since it ignores specified pitches anyway).

        """
        if self.current_chord:
            self.copy_prev_chord(note.duration)
        else:
            if not is_unpitched:
                note.pitch = self.current_lynote.pitch
            self.new_note(note, rel, is_unpitched)

    def create_unpitched(self, unpitched):
        """Create a xml_objs.Unpitched from ly.music.items.Unpitched."""
        dura = unpitched.duration
        return xml_objs.Unpitched(dura)

    def create_barnote_from_note(self, note):
        """Create a xml_objs.BarNote from ly.music.items.Note."""
        p = getNoteName(note.pitch.note)
        alt = get_xml_alter(note.pitch.alter)
        try:
            acc = note.accidental_token
        except AttributeError:
            acc = ""
        dura = note.duration
        return xml_objs.BarNote(p, alt, acc, dura, self.voice)

    def copy_barnote_basics(self, bar_note):
        """Create a copy of a xml_objs.BarNote."""
        p = bar_note.base_note
        alt = bar_note.alter
        acc = bar_note.accidental_token
        dura = bar_note.duration
        voc = bar_note.voice
        copy = xml_objs.BarNote(p, alt, acc, dura, voc)
        copy.octave = bar_note.octave
        copy.chord = bar_note.chord
        return copy

    def new_duration_token(self, token, tokens):
        self.dur_token = token
        self.dur_tokens = tokens
        self.check_duration(self.current_is_rest)

    def check_current_note(self, rel=False, rest=False, is_unpitched=False):
        """ Perform checks common for all new notes and rests. """
        if not rest and not is_unpitched:
            self.set_octave(rel)
        if not rest:
            if self.tied:
                self.current_note.set_tie('stop')
                self.tied = False
        self.check_duration(rest)
        self.check_divs()
        if self.staff:
            self.current_note.set_staff(self.staff)
            if self.store_unset_staff:
                if self.staff in self.staff_unset_notes:
                    self.staff_unset_notes[self.staff].append(self.current_note)
                else:
                    self.staff_unset_notes[self.staff] = [self.current_note]
        self.add_to_bar(self.current_note)

    def stem_direction(self, direction):
        if direction == '\\stemUp':
            self.stem_dir = 'up'
        elif direction == '\\stemDown':
            self.stem_dir = 'down'
        elif direction == '\\stemNeutral':
            self.stem_dir = None

    def set_octave(self, relative):
        """Set octave by getting the octave of an absolute note + 3."""
        p = self.current_lynote.pitch.copy()
        if relative:
            p.makeAbsolute(self.prev_pitch)
        self.prev_pitch = p
        self.current_note.set_octave(p.octave + 3)

    def do_action_onnext(self, note):
        """Perform the stored action on the next note."""
        for action in self.action_onnext:
            func_call = getattr(self, action[0])
            func_call(note, *action[1])

    def check_duration(self, rest):
        """Check the duration for the current note."""
        dots, rs = self.duration_from_tokens(self.dur_tokens)
        if rest and rs: # special case of multibar rest
            if not self.current_note.show_type or self.current_note.skip:
                bs = self.current_note.duration
                if rs == bs[1]:
                    self.current_note.duration = (bs[0], 1)
                    self.current_note.dot = 0
                    self.scale_rest(bs)
                    return
        self.current_note.dot = dots
        self.dots = dots
        self.current_note.set_durtype(durval2type(self.dur_token))
        if self.current_chord:
            for c in self.current_chord:
                c.set_durtype(durval2type(self.dur_token))

    def new_chord(self, note, duration=None, rel=False, chord_base=True):
        if chord_base:
            self.new_chordbase(note, duration, rel)
            self.current_chord.append(self.current_note)
        else:
            self.current_chord.append(self.new_chordnote(note, rel))
        self.do_action_onnext(self.current_chord[-1])

    def new_chordbase(self, note, duration, rel=False):
        self.current_note = self.create_barnote_from_note(note)
        self.current_note.set_duration(duration)
        self.current_lynote = note
        self.check_current_note(rel)

    def new_chordnote(self, note, rel):
        chord_note = self.create_barnote_from_note(note)
        chord_note.set_duration(self.current_note.duration)
        chord_note.set_durtype(durval2type(self.dur_token))
        chord_note.dots = self.dots
        chord_note.tie = self.current_note.tie
        chord_note.tuplet = self.current_note.tuplet
        if not self.prev_chord_pitch:
            self.prev_chord_pitch = self.prev_pitch
        p = note.pitch.copy()
        if(rel):
            p.makeAbsolute(self.prev_chord_pitch)
        chord_note.set_octave(p.octave + 3)
        self.prev_chord_pitch = p
        chord_note.chord = True
        self.bar.add(chord_note)
        return chord_note

    def copy_prev_chord(self, duration):
        if self.current_chord:
            prev_chord = self.current_chord
            self.clear_chord()
        else:
            prev_chord = self.q_chord
        for i, pc in enumerate(prev_chord):
            cn = self.copy_barnote_basics(pc)
            cn.set_duration(duration)
            cn.set_durtype(durval2type(self.dur_token))
            if i == 0:
                self.current_note = cn
            self.current_chord.append(cn)
            if self.tied:
                cn.set_tie('stop')
            self.bar.add(cn)
        self.tied = False

    def clear_chord(self):
        self.q_chord = self.current_chord
        self.current_chord = []
        self.prev_chord_pitch = None

    def chord_end(self):
        """Actions when chord is parsed."""
        self.action_onnext = []

    def new_rest(self, rest):
        self.current_is_rest = True
        self.clear_chord()
        rtype = rest.token
        dur = rest.duration
        if rtype == 'r':
            self.current_note = xml_objs.BarRest(dur, self.voice)
        elif rtype == 'R':
            self.current_note = xml_objs.BarRest(dur, self.voice, show_type=False)
            if self.multiple_rest:
                self.set_mult_rest_bar(dur)
        elif rtype == 's' or rtype == '\\skip':
            self.current_note = xml_objs.BarRest(dur, self.voice, skip=True)
        self.check_current_note(rest=True)
        self.increase_bar_dura(dur)

    def note2rest(self):
        """Note used as rest position transformed to rest."""
        dur = self.current_note.duration
        voice = self.current_note.voice
        pos = [self.current_note.base_note, self.current_note.octave]
        self.current_note = xml_objs.BarRest(dur, voice, pos=pos)
        self.check_duration(rest=True)
        self.bar.obj_list.pop()
        self.bar.add(self.current_note)

    def set_mult_rest(self):
        self.multiple_rest = True

    def set_mult_rest_bar(self, dur):
        """ add multiple-rest attribute to bar """
        if self.bar is None:
            self.new_bar()
        multp = dur[1]
        rest_size = int(multp * (dur[0]/self.current_time))
        new_bar_attr = xml_objs.BarAttr()
        new_bar_attr.set_multp_rest(rest_size)
        self.bar.add(new_bar_attr)

    def scale_rest(self, bs):
        """ create multiple whole bar rests """
        dur = self.current_note.duration
        voc = self.current_note.voice
        st = self.current_note.show_type
        sk = self.current_note.skip
        multp = int(bs[1] * (bs[0]/self.current_time))
        for i in range(1, int(multp)):
            self.new_bar()
            rest_copy = xml_objs.BarRest(dur, voice=voc, show_type=st, skip=sk)
            self.add_to_bar(rest_copy)

    def change_to_tuplet(self, tfraction, ttype, nr, length=None):
        """Change the current note into a tuplet note."""
        tuplscaling = Fraction(tfraction[0], tfraction[1])
        if self.tupl_dur:
            if self.tupl_sum == 0:
                ttype = "start"
            base, scaling = self.current_lynote.duration
            self.tupl_sum += (1 / tuplscaling) * base * scaling
            if self.tupl_sum == self.tupl_dur:
                ttype = "stop"
                self.tupl_sum = 0
        if length:
            acttype = normtype = durval2type(self.calc_tupl_den(tfraction, length))
            self.current_note.set_tuplet(tfraction, ttype, nr, acttype, normtype)
        else:
            self.current_note.set_tuplet(tfraction, ttype, nr)

    def change_tuplet_type(self, index, newtype):
        self.current_note.tuplet[index].ttype = newtype

    def set_tuplspan_dur(self, token=None, tokens=None, fraction=None):
        """
        Catch duration set by the tupletSpannerDuration property.

        Set the fraction directly or calculate it from tokens.
        """
        if fraction:
            self.tupl_dur = fraction
        else:
            base, scaling = ly.duration.base_scaling((token,) + tokens)
            self.tupl_dur = base * scaling

    def unset_tuplspan_dur(self):
        """Reset tuplet duration sum and tuplet spanner duration."""
        self.tupl_sum = 0
        self.tupl_dur = 0

    def calc_tupl_den(self, tfraction, length):
        """Calculate the tuplet denominator from
        fraction and duration of tuplet."""
        return tfraction[1] / length

    def tie_to_next(self):
        tie_type = 'start'
        self.tied = True
        self.current_note.set_tie(tie_type)

    def set_slur(self, nr, slur_type, phrasing=False):
        """
        Set the slur start or stop for the current note.
        phrasing should be set to True if the slur is meant to be a phrasing mark.
        """

        slur_start = None

        if slur_type == 'stop':
            slur_start = self.slur_stack.pop()

        self.current_note.set_slur(nr, slur_type, phrasing, slur_start)

        if slur_type == 'start':
            self.slur_stack.append(self.current_note.slur[-1])

    def new_articulation(self, art_token):
        """
        An articulation, fingering, string number, or other symbol.

        Grouped as articulations, ornaments, technical and others.
        """
        if isinstance(art_token, ly.lex.lilypond.Fingering):
            self.current_note.add_fingering(art_token)
        else:
            ret = artic_token2xml_name(art_token)
            if ret == 'ornament':
                self.current_note.add_ornament(art_token[1:])
            elif ret == 'other':
                self.current_note.add_other_notation(art_token[1:])
            elif ret:
                self.current_note.add_articulation(ret)

    def new_dynamics(self, dynamics):
        hairpins = {'<': 'crescendo', '>': 'diminuendo'}
        text_dyn = {'cresc': 'cresc.', 'decresc': 'descresc.',
                    'dim': 'dim.'}
        if dynamics == '!':
            if self.ongoing_wedge:
                self.current_note.set_dynamics_wedge('stop')
                self.ongoing_wedge = False
            if self.ongoing_dashes:
                self.current_note.set_dynamics_dashes('stop')
                self.ongoing_dashes = False
        elif dynamics in hairpins:
            self.current_note.set_dynamics_wedge(hairpins[dynamics])
            self.ongoing_wedge = True
        elif dynamics in text_dyn:
            self.current_note.set_dynamics_text(text_dyn[dynamics])
            self.current_note.set_dynamics_dashes('start', before=False)
            self.ongoing_dashes = True
        elif self.ongoing_wedge:
            self.current_note.set_dynamics_wedge('stop')
            self.current_note.set_dynamics_mark(dynamics)
            self.ongoing_wedge = False
        elif self.ongoing_dashes:
            self.current_note.set_dynamics_dashes('stop')
            self.current_note.set_dynamics_mark(dynamics)
            self.ongoing_dashes = False
        else:
            self.current_note.set_dynamics_mark(dynamics)

    def new_grace(self, slash=0):
        self.current_note.set_grace(slash)

    def new_chord_grace(self, slash=0):
        self.current_chord[-1].set_grace(slash)

    def new_gliss(self, line=None):
        if line:
            line = get_line_style(line)
        if self.current_chord:
            for n, c in enumerate(self.current_chord):
                c.set_gliss(line, nr=n+1)
        else:
            self.current_note.set_gliss(line)
        self.action_onnext.append(("end_gliss", (line, )))

    def end_gliss(self, note, line):
        if self.current_chord:
            n = len(self.current_chord)
        else:
            n = 1
        note.set_gliss(line, endtype="stop", nr=n)

    def set_tremolo(self, trem_type='single', duration=0, repeats=0):
        if self.current_note.tremolo[1]: #tremolo already set
            self.current_note.set_tremolo(trem_type)
        else:
            if repeats:
                duration = int(self.dur_token)
                bs, durtype = calc_trem_dur(repeats, self.current_note.duration, duration)
                self.current_note.duration = bs
                self.current_note.type = durtype
            elif not duration:
                duration = self.prev_tremolo
            else:
                self.prev_tremolo = duration
            self.current_note.set_tremolo(trem_type, duration)

    def new_trill_spanner(self, end=None):
        if not end:
            self.current_note.add_ornament('trill')
            end = "start"
        self.current_note.add_adv_ornament('wavy-line', end)

    def new_ottava(self, octdiff):
        octdiff = int(octdiff)
        if self.octdiff == octdiff:
            return
        if self.octdiff:
            if self.octdiff < 0:
                plac = "below"
            else:
                plac = "above"
            size = abs(self.octdiff) * 7 + 1
            self.current_note.set_oct_shift(plac, "stop", size)
        if octdiff:
            if octdiff < 0:
                plac = "below"
                octdir = "up"
            else:
                plac = "above"
                octdir = "down"
            size = abs(octdiff) * 7 + 1
            self.action_onnext.append(("set_ottava", (plac, octdir, size)))
        self.octdiff = octdiff

    def set_ottava(self, note, plac, octdir, size):
        note.set_oct_shift(plac, octdir, size)

    def new_tempo(self, unit, dur_tokens, tempo, string):
        dots, rs = self.duration_from_tokens(dur_tokens)
        if tempo:
            beats = tempo[0]
        else:
            beats = 0
        try:
            text = string.value()
        except AttributeError:
            text = None
        tempo = xml_objs.BarAttr()
        unittype = durval2type(unit) if unit else ''
        tempo.set_tempo(unit, unittype, beats, dots, text)
        if self.bar is None:
            self.new_bar()
        self.bar.add(tempo)

    def set_by_property(self, prprty, value, group=False):
        """Generic setter for different properties."""
        if prprty == 'instrumentName':
            if group:
                self.set_groupname(value)
            else:
                self.set_partname(value)
        elif prprty == 'shortInstrumentName':
            if group:
                self.set_groupabbr(value)
            else:
                self.set_partabbr(value)
        elif prprty == 'midiInstrument':
            self.set_partmidi(value)
        elif prprty == 'stanza':
            self.new_lyric_nr(value)
        elif prprty == 'systemStartDelimiter':
            self.change_group_bracket(value)

    def set_partname(self, name):
        if self.score.is_empty():
            self.new_part()
        self.part.name = name

    def set_partabbr(self, abbr):
        if self.score.is_empty():
            self.new_part()
        self.part.abbr = abbr

    def set_groupname(self, name):
        if self.group:
            self.group.name = name

    def set_groupabbr(self, abbr):
        if self.group:
            self.group.abbr = abbr

    def set_partmidi(self, midi):
        if self.score.is_empty():
            self.new_part()
        self.part.midi = midi

    def new_lyric_nr(self, num):
        self.lyric_nr = num

    def new_lyrics_text(self, txt):
        if self.lyric:
            if self.lyric_syll:
                if self.lyric[1] in ['begin', 'middle']:
                    self.lyric = [txt, 'middle', self.lyric_nr]
            else:
                if self.lyric[1] in ['begin', 'middle']:
                    self.lyric[1] = 'end'
                self.lyric = [txt, 'single', self.lyric_nr]
        else:
            self.lyric = [txt, 'single', self.lyric_nr]
        self.insert_into.barlist.append(self.lyric)
        self.lyric_syll = False

    def new_lyrics_item(self, item):
        if item == '--':
            if self.lyric:
                if self.lyric[1] == 'single':
                    self.lyric[1] = 'begin'
                self.lyric_syll = True
        elif item == '__':
            self.lyric.append("extend")
        elif item == '\\skip':
            self.insert_into.barlist.append("skip")

    def duration_from_tokens(self, tokens):
        """Calculate dots and multibar rests from tokens."""
        dots = 0
        rs = 0
        for t in tokens:
            if t == '.':
                dots += 1
            elif '*' in t and '/' not in t:
                rs = int(t[1:])
        return (dots, rs)

    def check_divs(self):
        """ The new duration is checked against current divisions """
        base = self.current_note.duration[0]
        scaling = self.current_note.duration[1]
        divs = self.divisions
        tupl = self.current_note.tuplet
        if not tupl:
            a = 4
            if base:
                b = 1/base
            else:
                b = 1
                print("Warning problem checking duration!")
        else:
            num = 1
            den = 1
            for t in tupl:
                num *= t.fraction[0]
                den *= t.fraction[1]
            a = 4*den
            b = (1/base)*num
        c = a * divs * scaling
        predur, mod = divmod(c, b)
        if mod > 0:
            mult = get_mult(a, b)
            self.divisions = divs*mult

    def add_break(self):
        if self.bar is None:
            self.new_bar()
        self.current_attr.add_break('yes')


##
# Translation functions
##

def getNoteName(index):
    noteNames = ['C', 'D', 'E', 'F', 'G', 'A', 'B']
    return noteNames[index]

def get_xml_alter(alter):
    """ Convert alter to the specified format,
    i e int if it's int and float otherwise.
    Also multiply with 2."""
    alter *= 2
    if float(alter).is_integer():
        return alter
    else:
        return float(alter)

def durval2type(durval):
    """Convert LilyPond duration to MusicXML duration type."""
    xml_types = [
        "maxima", "long", "breve", "whole",
        "half", "quarter", "eighth",
        "16th", "32nd", "64th",
        "128th", "256th", "512th", "1024th", "2048th"
    ] # Note: 2048 is supported by ly but not by MusicXML!
    try:
        type_index = ly.duration.durations.index(str(durval))
    except ValueError:
        type_index = 5
    return xml_types[type_index]

def get_fifths(key, mode):
    fifths = 0
    sharpkeys = ['c', 'g', 'd', 'a', 'e', 'b', 'fis', 'cis', 'gis',
    'dis', 'ais', 'eis', 'bis', 'fisis', 'cisis']
    flatkeys = ['c', 'f', 'bes', 'es', 'as', 'des', 'ges', 'ces', 'fes',
    'beses', 'eses', 'ases']
    if key in sharpkeys:
        fifths = sharpkeys.index(key)
    elif key in flatkeys:
        fifths = -flatkeys.index(key)
    if mode=='minor':
        return fifths-3
    elif mode=='major':
        return fifths
    elif mode=='dorian':
        return fifths-2

def clefname2clef(clefname):
    """
    To add a clef look up the clef name in LilyPond
    and the corresponding definition in musicXML.
    Add it to the python dictionary below.
    """
    clef_dict = {
    "treble": ('G', 2, 0),
    "violin": ('G', 2, 0),
    "G": ('G', 2, 0),
    "bass": ('F', 4, 0),
    "F": ('F', 4, 0),
    "alto": ('C', 3, 0),
    "C": ('C', 3, 0),
    "tenor": ('C', 4, 0),
    "treble_8": ('G', 2, -1),
    "treble_15": ('G', 2, -2),
    "bass_8": ('F', 4, -1),
    "bass_15": ('F', 4, -2),
    "treble^8": ('G', 2, 1),
    "treble^15": ('G', 2, 2),
    "bass^8": ('F', 4, 1),
    "bass^15": ('F', 4, 2),
    "percussion": ('percussion', 0, 0),
    "tab": ('TAB', 5, 0),
    "soprano": ('C', 1, 0),
    "mezzosoprano": ('C', 2, 0),
    "baritone": ('C', 5, 0),
    "varbaritone": ('F', 3, 0),
    "baritonevarF": ('F', 3, 0),
    "french": ('G', 1, 0),
    "subbass": ('F', 5, 0),
    # From here on the clefs will end up with wrong symbols
    "GG": ('G', 2, -1),
    "tenorG": ('G', 2, -1),
    "varC": ('C', 3, 0),
    "altovarC": ('C', 3, 0),
    "tenorvarC": ('C', 4, 0),
    "baritonevarC": ('C', 5, 0),

    }
    try:
        clef = clef_dict[clefname]
    except KeyError:
        clef = 0
    return clef

def get_mult(num, den):
    simple = Fraction(num, den)
    return simple.denominator

def get_voice(c):
    voices = ["voiceOne", "voiceTwo", "voiceThree", "voiceFour"]
    return voices.index(c)+1

def artic_token2xml_name(art_token):
    """
    From Articulations in ly.music.items.
    Grouped as articulations, ornaments and others.

    To add an articulation look up the name or abbreviation
    in LilyPond and the corresponding node name in musicXML.
    Add it to the python dictionary below.
    """
    artic_dict = {
    ".": "staccato", "-": "tenuto", ">": "accent",
    "_": "detached-legato", "!": "staccatissimo",
    "\\staccatissimo": "staccatissimo", "\\breathe":"breath-mark"
    }
    ornaments = ['\\trill', '\\prall', '\\mordent', '\\turn']
    others = ['\\fermata']
    try:
        return artic_dict[art_token]
    except KeyError:
        if art_token in ornaments:
            return "ornament"
        elif art_token in others:
            return "other"
        else:
            return False

def calc_trem_dur(repeats, base_scaling, duration):
    """ Calculate tremolo duration from number of
    repeats and initial duration. """
    base = base_scaling[0]
    scale = base_scaling[1]
    new_base = base * repeats
    if repeats > duration:
        import ly.duration
        trem_length = ly.duration.tostring(int((repeats // duration) * -0.5))
    else:
        trem_length = str(duration // repeats)
    new_type = xml_objs.durval2type(trem_length)
    return (new_base, scale), new_type

def get_line_style(style):
    style_dict = {
    "dashed-line": "dashed",
    "dotted-line": "dotted",
    "trill": "wavy",
    "zigzag": "wavy"
    }
    try:
        return style_dict[style]
    except KeyError:
        return False

def get_group_symbol(lily_sys_start):
    symbol_dict = {
        "SystemStartBrace": "brace",
        "SystemStartSquare": "square"
        }
    try:
        return symbol_dict[lily_sys_start]
    except KeyError:
        return False
python_ly-0.9.9/ly/musicxml/lymus2musxml.py0000644000000000000000000006743313615410400016053 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Using the tree structure from ly.music to initiate the conversion to MusicXML.

Uses functions similar to ly.music.items.Document.iter_music() to iter through
the node tree. But information about where a node branch ends
is also added. During the iteration the information needed for the conversion
is captured.
"""

from __future__ import unicode_literals
from __future__ import print_function

import ly.document
import ly.music

from . import create_musicxml
from . import ly2xml_mediator
from . import xml_objs

#excluded from parsing
excl_list = ['Version', 'Midi', 'Layout']


# Defining contexts in relation to musicXML
group_contexts = ['StaffGroup', 'ChoirStaff']

pno_contexts = ['PianoStaff', 'GrandStaff']

staff_contexts = ['Staff', 'RhythmicStaff', 'TabStaff',
    'DrumStaff', 'VaticanaStaff', 'MensuralStaff']

part_contexts = pno_contexts + staff_contexts


class End():
    """ Extra class that gives information about the end of Container
    elements in the node list. """
    def __init__(self, node):
        self.node = node

    def __repr__(self):
        return '<{0} {1}>'.format(self.__class__.__name__, self.node)


class ParseSource():
    """ creates the XML-file from the source code according to the Music XML standard """

    def __init__(self):
        self.musxml = create_musicxml.CreateMusicXML()
        self.mediator = ly2xml_mediator.Mediator()
        self.relative = False
        self.tuplet = []
        self.scale = ''
        self.grace_seq = False
        self.trem_rep = 0
        self.piano_staff = 0
        self.numericTime = False
        self.voice_sep = False
        self.sims_and_seqs = []
        self.override_dict = {}
        self.ottava = False
        self.with_contxt = None
        self.schm_assignm = None
        self.tempo = ()
        self.tremolo = False
        self.tupl_span = False
        self.unset_tuplspan = False
        self.alt_mode = None
        self.rel_pitch_isset = False
        self.slurcount = 0
        self.slurnr = 0
        self.phrslurnr = 0
        self.mark = False
        self.pickup = False

    def parse_text(self, ly_text, filename=None):
        """Parse the LilyPond source specified as text.
        
        If you specify a filename, it can be used to resolve \\include commands
        correctly.
        
        """
        doc = ly.document.Document(ly_text)
        doc.filename = filename
        self.parse_document(doc)

    def parse_document(self, ly_doc, relative_first_pitch_absolute=False):
        """Parse the LilyPond source specified as a ly.document document.
        
        If relative_first_pitch_absolute is set to True, the first pitch in a
        \relative expression without startpitch is considered to be absolute
        (LilyPond 2.18+ behaviour).
        
        """
        # The document is copied and the copy is converted to absolute mode to
        # facilitate the export. The original document is unchanged.
        doc = ly_doc.copy()
        import ly.pitch.rel2abs
        cursor = ly.document.Cursor(doc)
        ly.pitch.rel2abs.rel2abs(cursor, first_pitch_absolute=relative_first_pitch_absolute)
        mustree = ly.music.document(doc)
        self.parse_tree(mustree)

    def parse_tree(self, mustree):
        """Parse the LilyPond source as a ly.music node tree."""
        # print(mustree.dump())
        header_nodes = self.iter_header(mustree)
        if header_nodes:
            self.parse_nodes(header_nodes)
        score = self.get_score(mustree)
        if score:
            mus_nodes = self.iter_score(score, mustree)
        else:
            mus_nodes = self.find_score_sub(mustree)
        self.mediator.new_section("fallback") #fallback/default section
        self.parse_nodes(mus_nodes)

    def parse_nodes(self, nodes):
        """Work through all nodes by calling the function with the
        same name as the nodes class."""
        if nodes:
            for m in nodes:
                # print(m)
                func_name = m.__class__.__name__ #get instance name
                if func_name not in excl_list:
                    try:
                        func_call = getattr(self, func_name)
                        func_call(m)
                    except AttributeError as ae:
                        print("Warning:", func_name, "not implemented!")
                        print(ae)
                        pass
        else:
            print("Warning! Couldn't parse source!")

    def musicxml(self, prettyprint=True):
        self.mediator.check_score()
        xml_objs.IterateXmlObjs(
            self.mediator.score, self.musxml, self.mediator.divisions)
        xml = self.musxml.musicxml(prettyprint)
        return xml

    ##
    # The different source types from ly.music are here sent to translation.
    ##

    def Assignment(self, a):
        """
        Variables should already have been substituted
        so this need only cover other types of assignments.
        """
        if isinstance(a.value(), ly.music.items.Markup):
            val = a.value().plaintext()
        elif isinstance(a.value(), ly.music.items.String):
            val = a.value().value()
        elif isinstance(a.value(), ly.music.items.Scheme):
            val = a.value().get_string()
            if not val:
                self.schm_assignm = a.name()
        elif isinstance(a.value(), ly.music.items.UserCommand):
            # Don't know what to do with this:
            return
        if self.look_behind(a, ly.music.items.With):
            if self.with_contxt in group_contexts:
                self.mediator.set_by_property(a.name(), val, True)
            else:
                self.mediator.set_by_property(a.name(), val)
        else:
            self.mediator.new_header_assignment(a.name(), val)

    def MusicList(self, musicList):
        if musicList.token == '<<':
            if self.look_ahead(musicList, ly.music.items.VoiceSeparator):
                self.mediator.new_snippet('sim-snip')
                self.voice_sep = True
            else:
                self.mediator.new_section('simultan')
                self.sims_and_seqs.append('sim')
        elif musicList.token == '{':
            self.sims_and_seqs.append('seq')

    def Chord(self, chord):
        self.mediator.clear_chord()

    def Q(self, q):
        self.mediator.copy_prev_chord(q.duration)

    def Context(self, context):
        r""" \context """
        self.in_context = True
        self.check_context(context.context(), context.context_id(), context.token)

    def check_context(self, context, context_id=None, token=""):
        """Check context and do appropriate action (e.g. create new part)."""
        # Check first if part already exists
        if context_id:
            match = self.mediator.get_part_by_id(context_id)
            if match:
                self.mediator.new_part(to_part=match)
                return
        if context in pno_contexts:
            self.mediator.new_part(context_id, piano=True)
            self.piano_staff = 1
        elif context in group_contexts:
            self.mediator.new_group()
        elif context in staff_contexts:
            if self.piano_staff:
                if self.piano_staff > 1:
                    self.mediator.set_voicenr(nr=self.piano_staff+3)
                self.mediator.new_section('piano-staff'+str(self.piano_staff))
                self.mediator.set_staffnr(self.piano_staff)
                self.piano_staff += 1
            else:
                if token != '\\context' or self.mediator.part_not_empty():
                    self.mediator.new_part(context_id)
            self.mediator.add_staff_id(context_id)
        elif context == 'Voice':
            self.sims_and_seqs.append('voice')
            if context_id:
                self.mediator.new_section(context_id)
            else:
                self.mediator.new_section('voice')
        elif context == 'Devnull':
            self.mediator.new_section('devnull', True)
        else:
            print("Context not implemented:", context)

    def VoiceSeparator(self, voice_sep):
        self.mediator.new_snippet('sim')
        self.mediator.set_voicenr(add=True)

    def Change(self, change):
        r""" A \change music expression. Changes the staff number. """
        if change.context() == 'Staff':
            self.mediator.set_staffnr(0, staff_id=change.context_id())

    def PipeSymbol(self, barcheck):
        """ PipeSymbol = | """
        pass

    def Clef(self, clef):
        r""" Clef \clef"""
        self.mediator.new_clef(clef.specifier())

    def KeySignature(self, key):
        self.mediator.new_key(key.pitch().output(), key.mode())

    def Relative(self, relative):
        r"""A \relative music expression."""
        self.relative = True

    def Partial(self, partial):
        self.pickup = True

    def Note(self, note):
        """ notename, e.g. c, cis, a bes ... """
        #print(note.token)
        if note.length():
            if self.relative and not self.rel_pitch_isset:
                self.mediator.new_note(note, False)
                self.mediator.set_relative(note)
                self.rel_pitch_isset = True
            else:
                self.mediator.new_note(note, self.relative)
            self.check_note(note)
        else:
            if isinstance(note.parent(), ly.music.items.Relative):
                self.mediator.set_relative(note)
                self.rel_pitch_isset = True
            elif isinstance(note.parent(), ly.music.items.Chord):
                if self.mediator.current_chord:
                    self.mediator.new_chord(note, chord_base=False)
                else:
                    self.mediator.new_chord(note, note.parent().duration, self.relative)
                    self.check_tuplet()
                # chord as grace note
                if self.grace_seq:
                    self.mediator.new_chord_grace()

    def Unpitched(self, unpitched):
        """A note without pitch, just a standalone duration."""
        if unpitched.length():
            if self.alt_mode == 'drum':
                self.mediator.new_iso_dura(unpitched, self.relative, True)
            else:
                self.mediator.new_iso_dura(unpitched, self.relative)
            self.check_note(unpitched)

    def DrumNote(self, drumnote):
        """A note in DrumMode."""
        if drumnote.length():
            self.mediator.new_note(drumnote, is_unpitched=True)
            self.check_note(drumnote)

    def check_note(self, note):
        """Generic check for all notes, both pitched and unpitched."""
        self.check_tuplet()
        if self.grace_seq:
            self.mediator.new_grace()
        if self.trem_rep and not self.look_ahead(note, ly.music.items.Duration):
            self.mediator.set_tremolo(trem_type='start', repeats=self.trem_rep)

    def check_tuplet(self):
        """Generic tuplet check."""
        if self.tuplet:
            tlevels = len(self.tuplet)
            nested = True if tlevels > 1 else False
            for td in self.tuplet:
                if nested:
                    self.mediator.change_to_tuplet(td['fraction'], td['ttype'],
                                                td['nr'], td['length'])
                else:
                    self.mediator.change_to_tuplet(td['fraction'], td['ttype'],
                                                td['nr'])
                td['ttype'] = ""
            self.mediator.check_divs()

    def Duration(self, duration):
        """A written duration"""
        if self.tempo:
            self.mediator.new_tempo(duration.token, duration.tokens, *self.tempo)
            self.tempo = ()
        elif self.tremolo:
            self.mediator.set_tremolo(duration=int(duration.token))
            self.tremolo = False
        elif self.tupl_span:
            self.mediator.set_tuplspan_dur(duration.token, duration.tokens)
            self.tupl_span = False
        elif self.pickup:
            self.mediator.set_pickup()
            self.pickup = False
        else:
            self.mediator.new_duration_token(duration.token, duration.tokens)
            if self.trem_rep:
                self.mediator.set_tremolo(trem_type='start', repeats=self.trem_rep)

    def Tempo(self, tempo):
        """ Tempo direction, e g '4 = 80' """
        if self.look_ahead(tempo, ly.music.items.Duration):
            self.tempo = (tempo.tempo(), tempo.text())
        else:
            self.mediator.new_tempo(0, (), tempo.tempo(), tempo.text())

    def Tie(self, tie):
        """ tie ~ """
        self.mediator.tie_to_next()

    def Rest(self, rest):
        r""" rest, r or R. Note: NOT by command, i.e. \rest """
        if rest.token == 'R':
            self.scale = 'R'
        self.mediator.new_rest(rest)

    def Skip(self, skip):
        r""" invisible rest/spacer rest (s or command \skip)"""
        if 'lyrics' in self.sims_and_seqs:
            self.mediator.new_lyrics_item(skip.token)
        else:
            self.mediator.new_rest(skip)

    def Scaler(self, scaler):
        r"""
        \times \tuplet \scaleDurations

        """
        if scaler.token == '\\scaleDurations':
            ttype = ""
            fraction = (scaler.denominator, scaler.numerator)
        elif scaler.token == '\\times':
            ttype = "start"
            fraction = (scaler.denominator, scaler.numerator)
        elif scaler.token == '\\tuplet':
            ttype = "start"
            fraction = (scaler.numerator, scaler.denominator)
        nr = len(self.tuplet) + 1
        self.tuplet.append({'set': False,
                            'fraction': fraction,
                            'ttype': ttype,
                            'length': scaler.length(),
                            'nr': nr})
        if self.look_ahead(scaler, ly.music.items.Duration):
            self.tupl_span = True
            self.unset_tuplspan = True

    def Number(self, number):
        pass

    def Articulation(self, art):
        """An articulation, fingering, string number, or other symbol."""
        self.mediator.new_articulation(art.token)

    def Postfix(self, postfix):
        pass

    def Beam(self, beam):
        pass

    def Slur(self, slur):
        """ Slur, '(' = start, ')' = stop. """
        if slur.token == '(':
            self.slurcount += 1
            self.slurnr = self.slurcount
            self.mediator.set_slur(self.slurnr, "start")
        elif slur.token == ')':
            self.mediator.set_slur(self.slurnr, "stop")
            self.slurcount -= 1

    def PhrasingSlur(self, phrslur):
        r"""A \( or \)."""
        if phrslur.token == '\(':
            self.slurcount += 1
            self.phrslurnr = self.slurcount
            self.mediator.set_slur(self.phrslurnr, "start", phrasing=True)
        elif phrslur.token == '\)':
            self.mediator.set_slur(self.phrslurnr, "stop", phrasing=True)
            self.slurcount -= 1

    def Dynamic(self, dynamic):
        """Any dynamic symbol."""
        self.mediator.new_dynamics(dynamic.token[1:])

    def Grace(self, grace):
        self.grace_seq = True

    def TimeSignature(self, timeSign):
        self.mediator.new_time(timeSign.numerator(), timeSign.fraction(), self.numericTime)

    def Repeat(self, repeat):
        if repeat.specifier() == 'volta':
            self.mediator.new_repeat('forward')
        elif repeat.specifier() == 'tremolo':
            self.trem_rep = repeat.repeat_count()

    def Tremolo(self, tremolo):
        """A tremolo item ":"."""
        if self.look_ahead(tremolo, ly.music.items.Duration):
            self.tremolo = True
        else:
            self.mediator.set_tremolo()

    def With(self, cont_with):
        r"""A \with ... construct."""
        self.with_contxt = cont_with.parent().context()

    def Set(self, cont_set):
        r"""A \set command."""
        if isinstance(cont_set.value(), ly.music.items.Scheme):
            if cont_set.property() == 'tupletSpannerDuration':
                moment = cont_set.value().get_ly_make_moment()
                if moment:
                    self.mediator.set_tuplspan_dur(fraction=moment)
                else:
                    self.mediator.unset_tuplspan_dur()
                return
            val = cont_set.value().get_string()
        else:
            val = cont_set.value().value()
        if cont_set.context() in part_contexts:
            self.mediator.set_by_property(cont_set.property(), val)
        elif cont_set.context() in group_contexts:
            self.mediator.set_by_property(cont_set.property(), val, group=True)

    def Command(self, command):
        r""" \bar, \rest etc """
        excls = ['\\major', '\\minor', '\\dorian', '\\bar']
        if command.token == '\\rest':
            self.mediator.note2rest()
        elif command.token == '\\numericTimeSignature':
            self.numericTime = True
        elif command.token == '\\defaultTimeSignature':
            self.numericTime = False
        elif command.token.find('voice') == 1:
            self.mediator.set_voicenr(command.token[1:], piano=self.piano_staff)
        elif command.token == '\\glissando':
            try:
                self.mediator.new_gliss(self.override_dict["Glissando.style"])
            except KeyError:
                self.mediator.new_gliss()
        elif command.token == '\\startTrillSpan':
            self.mediator.new_trill_spanner()
        elif command.token == '\\stopTrillSpan':
            self.mediator.new_trill_spanner("stop")
        elif command.token == '\\ottava':
            self.ottava = True
        elif command.token == '\\mark':
            self.mark = True
            self.mediator.new_mark()
        elif command.token == '\\breathe':
            art = type('',(object,),{"token": "\\breathe"})()
            self.Articulation(art)
        elif command.token == '\\stemUp' or command.token == '\\stemDown' or command.token == '\\stemNeutral':
            self.mediator.stem_direction(command.token)
        elif command.token == '\\default':
            if self.tupl_span:
                self.mediator.unset_tuplspan_dur()
                self.tupl_span = False
            elif self.mark:
                self.mark = False
        elif command.token == '\\compressFullBarRests':
            self.mediator.set_mult_rest()
        elif command.token == '\\break':
            self.mediator.add_break()
        else:
            if command.token not in excls:
                print("Unknown command:", command.token)

    def UserCommand(self, usercommand):
        """Music variables are substituted so this must be something else."""
        if usercommand.name() == 'tupletSpan':
            self.tupl_span = True

    def Markup(self, markup):
        pass

    def MarkupWord(self, markupWord):
        self.mediator.new_word(markupWord.token)

    def MarkupList(self, markuplist):
        pass

    def String(self, string):
        prev = self.get_previous_node(string)
        if prev and prev.token == '\\bar':
            self.mediator.create_barline(string.value())

    def LyricsTo(self, lyrics_to):
        r"""A \lyricsto expression. """
        self.mediator.new_lyric_section('lyricsto'+lyrics_to.context_id(), lyrics_to.context_id())
        self.sims_and_seqs.append('lyrics')

    def LyricText(self, lyrics_text):
        """A lyric text (word, markup or string), with a Duration."""
        self.mediator.new_lyrics_text(lyrics_text.token)

    def LyricItem(self, lyrics_item):
        """Another lyric item (skip, extender, hyphen or tie)."""
        self.mediator.new_lyrics_item(lyrics_item.token)

    def NoteMode(self, notemode):
        r"""A \notemode or \notes expression."""
        self.alt_mode = 'note'

    def ChordMode(self, chordmode):
        r"""A \chordmode or \chords expression."""
        self.alt_mode = 'chord'

    def DrumMode(self, drummode):
        r"""A \drummode or \drums expression.

        If the shorthand form \drums is found, DrumStaff is implicit.

        """
        if drummode.token == '\\drums':
            self.check_context('DrumStaff')
        self.alt_mode = 'drum'

    def FigureMode(self, figmode):
        r"""A \figuremode or \figures expression."""
        self.alt_mode = 'figure'

    def LyricMode(self, lyricmode):
        r"""A \lyricmode, \lyrics or \addlyrics expression."""
        self.alt_mode = 'lyric'

    def Override(self, override):
        r"""An \override command."""
        self.override_key = ''

    def PathItem(self, item):
        r"""An item in the path of an \override or \revert command."""
        self.override_key += item.token

    def Scheme(self, scheme):
        """A Scheme expression inside LilyPond."""
        pass

    def SchemeItem(self, item):
        """Any scheme token."""
        if self.ottava:
            self.mediator.new_ottava(item.token)
            self.ottava = False
        elif self.look_behind(item, ly.music.items.Override):
            self.override_dict[self.override_key] = item.token
        elif self.schm_assignm:
            self.mediator.set_by_property(self.schm_assignm, item.token)
        elif self.mark:
            self.mediator.new_mark(int(item.token))
        else:
            print("SchemeItem not implemented:", item.token)

    def SchemeQuote(self, quote):
        """A ' in scheme."""
        pass

    def End(self, end):
        if isinstance(end.node, ly.music.items.Scaler):
            if self.unset_tuplspan:
                self.mediator.unset_tuplspan_dur()
                self.unset_tuplspan = False
            if end.node.token != '\\scaleDurations':
                self.mediator.change_tuplet_type(len(self.tuplet) - 1, "stop")
            self.tuplet.pop()
            self.fraction = None
        elif isinstance(end.node, ly.music.items.Grace): #Grace
            self.grace_seq = False
        elif end.node.token == '\\repeat':
            if end.node.specifier() == 'volta':
                self.mediator.new_repeat('backward')
            elif end.node.specifier() == 'tremolo':
                if self.look_ahead(end.node, ly.music.items.MusicList):
                    self.mediator.set_tremolo(trem_type="stop")
                else:
                    self.mediator.set_tremolo(trem_type="single")
                self.trem_rep = 0
        elif isinstance(end.node, ly.music.items.Context):
            self.in_context = False
            if end.node.context() == 'Voice':
                self.mediator.check_voices()
                self.sims_and_seqs.pop()
            elif end.node.context() in group_contexts:
                self.mediator.close_group()
            elif end.node.context() in staff_contexts:
                if not self.piano_staff:
                    self.mediator.check_part()
            elif end.node.context() in pno_contexts:
                self.mediator.check_voices()
                self.mediator.check_part()
                self.piano_staff = 0
                self.mediator.set_voicenr(nr=1)
            elif end.node.context() == 'Devnull':
                self.mediator.check_voices()
        elif end.node.token == '<<':
            if self.voice_sep:
                self.mediator.check_voices_by_nr()
                self.mediator.revert_voicenr()
                self.voice_sep = False
            elif not self.piano_staff:
                self.mediator.check_simultan()
                if self.sims_and_seqs:
                    self.sims_and_seqs.pop()
        elif end.node.token == '{':
            if self.sims_and_seqs:
                self.sims_and_seqs.pop()
        elif end.node.token == '<': #chord
            self.mediator.chord_end()
        elif end.node.token == '\\lyricsto':
            self.mediator.check_lyrics(end.node.context_id())
            self.sims_and_seqs.pop()
        elif end.node.token == '\\with':
            self.with_contxt = None
        elif end.node.token == '\\drums':
            self.mediator.check_part()
        elif isinstance(end.node, ly.music.items.Relative):
            self.relative = False
            self.rel_pitch_isset = False
        else:
            # print("end:", end.node.token)
            pass

    ##
    # Additional node manipulation
    ##

    def get_previous_node(self, node):
        """ Returns the nodes previous node
        or false if the node is first in its branch. """
        parent = node.parent()
        i = parent.index(node)
        if i > 0:
            return parent[i-1]
        else:
            return False

    def simple_node_gen(self, node):
        """Unlike iter_score are the subnodes yielded without substitution."""
        for n in node:
            yield n
            for s in self.simple_node_gen(n):
                yield s

    def iter_header(self, tree):
        """Iter only over header nodes."""
        for t in tree:
            if isinstance(t, ly.music.items.Header):
                return self.simple_node_gen(t)

    def get_score(self, node):
        """ Returns (first) Score node or false if no Score is found. """
        for n in node:
            if isinstance(n, ly.music.items.Score) or isinstance(n, ly.music.items.Book):
                return n
        return False

    def iter_score(self, scorenode, doc):
        r"""
        Iter over score.

        Similarly to items.Document.iter_music user commands are substituted.

        Furthermore \repeat unfold expressions are unfolded.
        """
        for s in scorenode:
            if isinstance(s, ly.music.items.Repeat) and s.specifier() == 'unfold':
                for u in self.unfold_repeat(s, s.repeat_count(), doc):
                    yield u
            else:
                n = doc.substitute_for_node(s) or s
                yield n
                for c in self.iter_score(n, doc):
                    yield c
                if isinstance(s, ly.music.items.Container):
                    yield End(s)

    def unfold_repeat(self, repeat_node, repeat_count, doc):
        r"""
        Iter over node which represent a \repeat unfold expression
        and do the unfolding directly.
        """
        for r in range(repeat_count):
            for n in repeat_node:
                for c in self.iter_score(n, doc):
                    yield c

    def find_score_sub(self, doc):
        """Find substitute for scorenode. Takes first music node that isn't
        an assignment."""
        for n in doc:
            if not isinstance(n, ly.music.items.Assignment):
                if isinstance(n, ly.music.items.Music):
                    return self.iter_score(n, doc)

    def look_ahead(self, node, find_node):
        """Looks ahead in a container node and returns True
        if the search is successful."""
        for n in node:
            if isinstance(n, find_node):
                return True
        return False

    def look_behind(self, node, find_node):
        """Looks behind on the parent node(s) and returns True
        if the search is successful."""
        parent = node.parent()
        if parent:
            if isinstance(parent, find_node):
                ret = True
            else:
                ret = self.look_behind(parent, find_node)
            return ret
        else:
            return False

    ##
    # Other functions
    ##
    def gen_med_caller(self, func_name, *args):
        """Call any function in the mediator object."""
        func_call = getattr(self.mediator, func_name)
        func_call(*args)
python_ly-0.9.9/ly/musicxml/midi_sound_map.py0000644000000000000000000001263013615410400016326 0ustar00
# A mapping between standard midi instrument names and standard musicxml sound names

# see http://lilypond.org/doc/v2.19/Documentation/notation/midi-instruments
# see http://www.musicxml.com/for-developers/standard-sounds/
midi_sound_map = {
    'accordion': 'keyboard.accordion',
    'acoustic bass': 'pluck.bass.acoustic',
    'acoustic grand': 'keyboard.piano.grand',
    'acoustic guitar (nylon)': 'pluck.guitar.nylon-string',
    'acoustic guitar (steel)': 'pluck.guitar.steel-string',
    'agogo': 'wood.agogo-block',
    'alto sax': 'wind.reed.saxophone.alto',
    'applause': 'effect.applause',
    'bagpipe': 'wind.pipes.bagpipes',
    'banjo': 'pluck.banjo',
    'baritone sax': 'wind.reed.saxophone.baritone',
    'bassoon': 'brass.trombone',
    'bird tweet': 'effect.bird.tweet',
    'blown bottle': 'wind.flutes.blown-bottle',
    'brass section': 'brass.helicon',
    'breath noise': 'effect.breath',
    'bright acoustic': 'keyboard.piano',
    'celesta': 'keyboard.celesta',
    'cello': 'string.cello',
    'choir aahs': 'voice.aa',  # ? voice.vocals?
    'church organ': 'keyboard.organ',
    'clarinet': 'wind.reed.clarinet',
    'clav': 'keyboard.clavichord',  # ?
    'concertina': 'keyboard.concertina',
    'contrabass': 'strings.contrabass',
    'distorted guitar': None,
    'drawbar organ': 'keyboard.organ.drawbar',
    'dulcimer': 'pluck.dulcimer',
    'electric bass (finger)': None,
    'electric bass (pick)': None,
    'electric grand': 'keyboard.electric',  # ?
    'electric guitar (clean)': None,
    'electric guitar (jazz)': None,
    'electric guitar (muted)': None,
    'electric piano 1': 'keyboard.electric',  # ?
    'electric piano 2': 'keyboard.electric',  # ?
    'english horn': 'wind.reed.english-horn',
    'fiddle': 'strings.fiddle',
    'flute': 'wind.flutes.flute',
    'french horn': 'brass.french-horn',
    'fretless bass': 'pluck.bass.fretless',
    'fx 1 (rain)': 'synth.effects.rain',
    'fx 2 (soundtrack)': 'synth.effects.soundtrack',
    'fx 3 (crystal)': 'synth.effects.crystal',
    'fx 4 (atmosphere)': 'synth.effects.atmosphere',
    'fx 5 (brightness)': 'synth.effects.brightness',
    'fx 6 (goblins)': 'synth.effects.goblins',
    'fx 7 (echoes)': 'synth.effects.echoes',
    'fx 8 (sci-fi)': 'synth.effects.sci-fi',
    'glockenspiel': 'pitched-percusstion.glockenspiel',
    'guitar fret noise': 'effect.guitar-fret',
    'guitar harmonics': None,
    'gunshot': 'effect.gunshot',
    'harmonica': 'wind.reed.harmonica',
    'harpsichord': 'keyboard.harpsichord',
    'helicopter': 'effect.helicopter',
    'honky-tonk': 'keyboard.piano.honky-tonk',
    'kalimba': 'pitched-percussion.kalimba',
    'koto': 'pluck.koto',
    'lead 1 (square)': 'synth.tone.square',
    'lead 2 (sawtooth)': 'synth.tone.sawtooth',
    'lead 3 (calliope)': 'wind.flutes.calliope',
    'lead 4 (chiff)': 'pluck.synth.chiff',
    'lead 5 (charang)': 'pluck.synth.charang',
    'lead 6 (voice)': 'voice.synth',
    'lead 7 (fifths)': 'synth.group.fifths',
    'lead 8 (bass+lead)': 'pluck.bass.lead',
    'marimba': 'pitched-percusstion.marimba',
    'melodic tom': 'drum.tom-tom',  # ?
    'music box': 'pitched-percussion.music-box',
    'muted trumpet': 'barss.trumpet',  # problematic
    'oboe': 'wind.reed.oboe',
    'ocarina': 'wind.flutes.ocarina',
    'orchestra hit': 'synth.group.orchestra',  # problematic?
    'orchestral harp': 'pluck.harp',  # ?
    'overdriven guitar': None,
    'pad 1 (new age)': 'synth.pad.polysynth',
    'pad 2 (warm)': 'synth.pad.warm',
    'pad 3 (polysynth)': 'synth.pad.polysynth',
    'pad 4 (choir)': 'synth.pad.choir',
    'pad 5 (bowed)': 'synth.pad.bowed',
    'pad 6 (metallic)': 'synth.pad.metallic',
    'pad 7 (halo)': 'synth.pad.halo',
    'pad 8 (sweep)': 'synth.pad.sweep',
    'pan flute': 'wind.flutes.panpipes',
    'percussive organ': 'voice.percussion',
    'piccolo': 'wind.flutes.flute.piccolo',
    'pizzicato strings': 'pluck.bass',  # problematic
    'recorder': 'wind.flutes.recorder',
    'reed organ': 'keyboard.organ.reed',
    'reverse cymbal': 'metal.cymbal.reverse',
    'rock organ': None,
    'seashore': 'effect.seashore',
    'shakuhachi': 'wind.flutes.shakuhachi',
    'shamisen': 'pluck.shamisen',
    'shanai': 'wind.reed.shenai',
    'sitar': 'pluck.sitar',
    'slap bass 1': 'effect.bass-string-slap',
    'slap bass 2': 'effect.bass-string-slap',  # ?
    'soprano sax': 'wind.reed.saxophone.soprano',
    'steel drums': 'metal.steel-drums',
    'string ensemble 1': 'strings.group',  # ?
    'string ensemble 2': 'strings.group',  # ?
    'synth bass 1': None,
    'synth bass 2': None,
    'synth drum': 'drum.tom-tom.synth',  # ?
    'synth voice': 'voice.synth',
    'synthbrass 1': 'synth.brass.group',  # ?
    'synthbrass 2': 'synth.brass.group',  # ?
    'synthstrings 1': 'strings.group.synth',
    'synthstrings 2': 'strings.group.synth',
    'taiko drum': 'deum.taiko',
    'telephone ring': 'effect.telephone-ring',
    'tenor sax': 'wind.reed.saxophone.tenor',
    'timpani': 'drum.timpani',
    'tinkle bell': 'metal.bells.tinklebell',
    'tremolo strings': None,  # ?
    'trombone': 'brass.trombone',
    'trumpet': 'brass.trumpet',
    'tuba': 'brass.tuba',
    'tubular bells': 'pitched-percussion.tubular-bells',
    'vibraphone': 'pitched-percussion.vibraphone',
    'viola': 'strings.viola',
    'violin': 'strings.violin',
    'voice oohs': 'voice.oo',
    'whistle': 'effect.whistle',
    'woodblock': 'wood.wood-block',
    'xylophone': 'pitched-percussion.xylophone'
}
python_ly-0.9.9/ly/musicxml/xml_objs.py0000644000000000000000000007332313615410400015162 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Classes that holds information about a musical score,
suitable for converting to musicXML.

When the score structure is built, it can easily be used to create a musicXML.

Example::

    from ly.musicxml import create_musicxml, xml_objs

    musxml = create_musicxml.CreateMusicXML()

    score = xml_objs.Score()
    part = xml_objs.ScorePart()
    score.partlist.append(part)
    bar = xml_objs.Bar()
    part.barlist.append(bar)
    ba = xml_objs.BarAttr()
    ba.set_time([4,4])
    bar.obj_list.append(ba)
    c = xml_objs.BarNote('c', 0, 0, (1,1))
    c.set_octave(4)
    c.set_durtype(1)
    bar.obj_list.append(c)

    xml_objs.IterateXmlObjs(score, musxml, 1)
    xml = musxml.musicxml()
    xml.write(filename)

"""

from __future__ import unicode_literals
from __future__ import print_function

from fractions import Fraction

class IterateXmlObjs():
    """
    A ly.musicxml.xml_objs.Score object is iterated and the Music XML node tree
    is constructed.

    """
    def __init__(self, score, musxml, div):
        """Create the basic score information, and initiate the
        iteration of the parts."""
        # score.debug_score([])
        self.musxml = musxml
        self.divisions = div
        if score.title:
            self.musxml.create_title(score.title)
        for ctag in score.creators:
            self.musxml.add_creator(ctag, score.creators[ctag])
        for itag in score.info:
            self.musxml.create_score_info(itag, score.info[itag])
        if score.rights:
            if len(score.rights) > 1:
                for right in score.rights:
                    self.musxml.add_rights(right[0], right[1])
            else:
                self.musxml.add_rights(score.rights[0][0])
        for p in score.partlist:
            if isinstance(p, ScorePart):
                self.iterate_part(p)
            elif isinstance(p, ScorePartGroup):
                self.iterate_partgroup(p)

    def iterate_partgroup(self, group):
        """Loop through a group, recursively if nested."""
        self.musxml.create_partgroup(
            'start', group.num, group.name, group.abbr, group.bracket)
        for p in group.partlist:
            if isinstance(p, ScorePart):
                self.iterate_part(p)
            elif isinstance(p, ScorePartGroup):
                self.iterate_partgroup(p)
        self.musxml.create_partgroup('stop', group.num)

    def iterate_part(self, part):
        """The part is iterated."""
        if part.barlist:
            last_bar = part.barlist[-1]
            last_bar_objs = last_bar.obj_list
            part.set_first_bar(self.divisions)
            self.musxml.create_part(part.name, part.abbr, part.midi)
            for bar in part.barlist[:-1]:
                self.iterate_bar(bar)
            if len(last_bar_objs) > 1 or last_bar_objs[0].has_attr():
                self.iterate_bar(last_bar)
        else:
            print("Warning: empty part:", part.name)

    def iterate_bar(self, bar):
        """The objects in the bar are output to the xml-file."""
        self.musxml.create_measure(pickup = bar.pickup)
        for obj in bar.obj_list:
            if isinstance(obj, BarAttr):
                self.new_xml_bar_attr(obj)
            elif isinstance(obj, BarMus):
                self.before_note(obj)
                if isinstance(obj, BarNote):
                    self.new_xml_note(obj)
                elif isinstance(obj, BarRest):
                    self.new_xml_rest(obj)
                self.gener_xml_mus(obj)
                self.after_note(obj)
            elif isinstance(obj, BarBackup):
                divdur = self.count_duration(obj.duration, self.divisions)
                self.musxml.add_backup(divdur)

    def new_xml_bar_attr(self, obj):
        """Create bar attribute xml-nodes."""
        if obj.has_attr():
            self.musxml.new_bar_attr(obj.clef, obj.time, obj.key, obj.mode, 
                obj.divs, obj.multirest)
        if obj.new_system:
            self.musxml.new_system(obj.new_system)
        if obj.repeat:
            self.musxml.add_barline(obj.barline, obj.repeat)
        elif obj.barline:
            self.musxml.add_barline(obj.barline)
        if obj.staves:
            self.musxml.add_staves(obj.staves)
        if obj.multiclef:
            for mc in obj.multiclef:
                self.musxml.add_clef(sign=mc[0][0], line=mc[0][1], nr=mc[1], oct_ch=mc[0][2])
        if obj.tempo:
            self.musxml.create_tempo(obj.tempo.text, obj.tempo.metr,
                                     obj.tempo.midi, obj.tempo.dots)
        if obj.mark:
            self.musxml.add_mark(obj.mark)
        if obj.word:
            self.musxml.add_dirwords(obj.word)

    def before_note(self, obj):
        """Xml-nodes before note."""
        self._add_dynamics([d for d in obj.dynamic if d.before])
        if obj.oct_shift and not obj.oct_shift.octdir == 'stop':
            self.musxml.add_octave_shift(obj.oct_shift.plac, obj.oct_shift.octdir, obj.oct_shift.size)

    def after_note(self, obj):
        """Xml-nodes after note."""
        self._add_dynamics([d for d in obj.dynamic if not d.before])
        if obj.oct_shift and obj.oct_shift.octdir == 'stop':
            self.musxml.add_octave_shift(obj.oct_shift.plac, obj.oct_shift.octdir, obj.oct_shift.size)

    def _add_dynamics(self, dyns):
        """Add XML nodes for list of Dynamics objects."""
        for d in dyns:
            if isinstance(d, DynamicsMark):
                self.musxml.add_dynamic_mark(d.sign)
            elif isinstance(d, DynamicsWedge):
                self.musxml.add_dynamic_wedge(d.sign)
            elif isinstance(d, DynamicsText):
                self.musxml.add_dynamic_text(d.sign)
            elif isinstance(d, DynamicsDashes):
                self.musxml.add_dynamic_dashes(d.sign)

    def gener_xml_mus(self, obj):
        """Nodes generic for both notes and rests."""
        if obj.tuplet:
            for t in obj.tuplet:
                self.musxml.tuplet_note(t.fraction, obj.duration, t.ttype, t.nr,
                                        self.divisions, t.acttype, t.normtype)
        if obj.staff and not obj.skip:
            self.musxml.add_staff(obj.staff)
        if obj.other_notation:
            self.musxml.add_named_notation(obj.other_notation)

    def new_xml_note(self, obj):
        """Create note specific xml-nodes."""
        divdur = self.count_duration(obj.duration, self.divisions)
        if isinstance(obj, Unpitched):
            self.musxml.new_unpitched_note(obj.base_note, obj.octave, obj.type, divdur,
                obj.voice, obj.dot, obj.chord, obj.grace)
        else:
            self.musxml.new_note(obj.base_note, obj.octave, obj.type, divdur,
                obj.alter, obj.accidental_token, obj.voice, obj.dot, obj.chord,
                obj.grace, obj.stem_direction)
        for t in obj.tie:
            self.musxml.tie_note(t)
        for s in obj.slur:
            self.musxml.add_slur(s.nr, s.slurtype)
        for a in obj.artic:
            self.musxml.new_articulation(a)
        if obj.ornament:
            self.musxml.new_simple_ornament(obj.ornament)
        if obj.adv_ornament:
            self.musxml.new_adv_ornament(obj.adv_ornament[0], obj.adv_ornament[1])
        if obj.tremolo[1]:
            self.musxml.add_tremolo(obj.tremolo[0], obj.tremolo[1])
        if obj.gliss:
            self.musxml.add_gliss(obj.gliss[0], obj.gliss[1], obj.gliss[2])
        if obj.fingering:
            self.musxml.add_fingering(obj.fingering)
        if obj.lyric:
            for l in obj.lyric:
                try:
                    self.musxml.add_lyric(l[0], l[1], l[2], l[3])
                except IndexError:
                    self.musxml.add_lyric(l[0], l[1], l[2])

    def new_xml_rest(self, obj):
        """Create rest specific xml-nodes."""
        divdur = self.count_duration(obj.duration, self.divisions)
        if obj.skip:
            self.musxml.add_skip(divdur)
        else:
            self.musxml.new_rest(divdur, obj.type, obj.pos,
            obj.dot, obj.voice)

    def count_duration(self, base_scaling, divs):
        base = base_scaling[0]
        scaling = base_scaling[1]
        duration = divs*4*base
        duration = duration * scaling
        return int(duration)


class Score():
    """Object that keep track of a whole score."""
    def __init__(self):
        self.partlist = []
        self.title = None
        self.creators = {}
        self.info = {}
        self.rights = []
        self.glob_section = ScoreSection('global', True)

    def add_right(self, value, type):
        self.rights.append((value, type))

    def is_empty(self):
        """Check if score is empty."""
        if self.partlist:
            return False
        else:
            return True

    def merge_globally(self, section, override=False):
        """Merge section to all parts."""
        for p in self.partlist:
            p.merge_voice(section, override)

    def debug_score(self, attr=[]):
        """
        Loop through score and print all elements for debugging purposes.

        Additionally print element attributes by adding them to the
        argument 'attr' list.

        """
        ind = "  "
        def debug_part(p):
            print("Score part:"+p.name)
            for n, b in enumerate(p.barlist):
                print(ind+"Bar nr: "+str(n+1))
                for obj in b.obj_list:
                    print(ind+ind+repr(obj))
                    for a in attr:
                        try:
                            print(ind+ind+ind+a+':'+repr(getattr(obj, a)))
                        except AttributeError:
                            pass

        def debug_group(g):
            if hasattr(g, 'barlist'):
                debug_part(g)
            else:
                print("Score group:"+g.name)
                for pg in g.partlist:
                    debug_group(pg)

        for i in self.partlist:
            debug_group(i)


class ScorePartGroup():
    """Object to keep track of part group."""
    def __init__(self, num, bracket):
        self.bracket = bracket
        self.partlist = []
        self.name = ''
        self.abbr = ''
        self.parent = None
        self.num = num

    def set_bracket(self, bracket):
        self.bracket = bracket

    def merge_voice(self, voice, override=False):
        """Merge in a ScoreSection into all parts."""
        for part in self.partlist:
            part.merge_voice(voice, override)


class SlurCount:
    """Utility class meant for keeping count of started slurs in a section"""
    def __init__(self):
        self.count = 0

    def inc(self):
        self.count += 1

    def dec(self):
        self.count -= 1

class ScoreSection():
    """ object to keep track of music section """
    def __init__(self, name, glob=False):
        self.name = name
        self.barlist = []
        self.glob = glob

        # Keeps track of the number of started slurs in the section
        self.active_slur_count = SlurCount()

    def __repr__(self):
        return '<{0} {1}>'.format(self.__class__.__name__, self.name)

    def merge_voice(self, voice, override=False):
        """Merge in other ScoreSection."""
        for org_v, add_v in zip(self.barlist, voice.barlist):
            org_v.inject_voice(add_v, override, self.active_slur_count)
        bl_len = len(self.barlist)
        if len(voice.barlist) > bl_len:
            self.barlist += voice.barlist[bl_len:]

    def merge_lyrics(self, lyrics):
        """Merge in lyrics in music section."""
        i = 0
        ext = False
        for bar in self.barlist:
            for obj in bar.obj_list:
                if isinstance(obj, BarNote):
                    if ext:
                        if obj.slur:
                            ext = False
                    else:
                        try:
                            l = lyrics.barlist[i]
                        except IndexError:
                            break
                        if l != 'skip':
                            try:
                                if l[3] == "extend" and obj.slur:
                                    ext = True
                            except IndexError:
                                pass
                            obj.add_lyric(l)
                        i += 1


class Snippet(ScoreSection):
    """ Short section intended to be merged.
    Holds reference to the barlist to be merged into."""
    def __init__(self, name, merge_into):
        ScoreSection.__init__(self, name)
        self.merge_barlist = merge_into


class LyricsSection(ScoreSection):
    """ Holds the lyrics information. Will eventually be merged to
    the corresponding note in the section set by the voice id. """
    def __init__(self, name, voice_id):
        ScoreSection.__init__(self, name)
        self.voice_id = voice_id


class ScorePart(ScoreSection):
    """ object to keep track of part """
    def __init__(self, staves=0, part_id=None, to_part=None, name=''):
        ScoreSection.__init__(self, name)
        self.part_id = part_id
        self.to_part = to_part
        self.abbr = ''
        self.midi = ''
        self.staves = staves

    def __repr__(self):
        return '<{0} {1} {2}>'.format(
            self.__class__.__name__, self.name, self.part_id)

    def set_first_bar(self, divisions):
        initime = [4, 4]
        iniclef = ('G', 2, 0)

        def check_time(bar):
            for obj in bar.obj_list:
                if isinstance(obj, BarAttr):
                    if obj.time:
                        return True
                if isinstance(obj, BarMus):
                    return False

        def check_clef(bar):
            for obj in bar.obj_list:
                if isinstance(obj, BarAttr):
                    if obj.clef or obj.multiclef:
                        return True
                if isinstance(obj, BarMus):
                    return False

        if not check_time(self.barlist[0]):
            try:
                self.barlist[0].obj_list[0].set_time(initime, False)
            except AttributeError:
                print("Warning can't set initial time sign!")
        if not check_clef(self.barlist[0]):
            try:
                self.barlist[0].obj_list[0].set_clef(iniclef)
            except AttributeError:
                print("Warning can't set initial clef sign!")
        self.barlist[0].obj_list[0].divs = divisions
        if self.staves:
            self.barlist[0].obj_list[0].staves = self.staves

    def merge_part_to_part(self):
        """Merge the part with the one indicated."""
        if self.to_part.barlist:
            self.to_part.merge_voice(self)
        else:
            self.to_part.barlist.extend(self.barlist)

    def extract_global_to_section(self, name):
        """Extract only elements that is relevant for the score globally into a given section."""
        section = ScoreSection(name, True)
        for bar in self.barlist:
            section_bar = Bar()
            for obj in bar.obj_list:
                if isinstance(obj, BarAttr):
                    glob_barattr = BarAttr()
                    glob_barattr.key = obj.key
                    glob_barattr.time = obj.time
                    glob_barattr.mode = obj.mode
                    glob_barattr.barline = obj.barline
                    glob_barattr.repeat = obj.repeat
                    glob_barattr.tempo = obj.tempo
                    section_bar.obj_list.append(glob_barattr)
            section.barlist.append(section_bar)
        return section


class Bar():
    """ Representing the bar/measure.
    Contains also information about how complete it is."""
    def __init__(self):
        self.obj_list = []
        self.pickup = False
        self.list_full = False

    def __repr__(self):
        return '<{0} {1}>'.format(self.__class__.__name__, self.obj_list)

    def add(self, obj):
        self.obj_list.append(obj)

    def has_music(self):
        """ Check if bar contains music. """
        for obj in self.obj_list:
            if isinstance(obj, BarMus):
                return True
        return False

    def has_attr(self):
        """ Check if bar contains attribute. """
        for obj in self.obj_list:
            if isinstance(obj, BarAttr):
                return True
        return False

    def create_backup(self):
        """ Calculate and create backup object."""
        b = 0
        s = 1
        for obj in self.obj_list:
            if isinstance(obj, BarMus):
                if not obj.chord:
                    b += obj.duration[0]
                    s *= obj.duration[1]
            elif isinstance(obj, BarBackup):
                break
        self.add(BarBackup((b, s)))

    def is_skip(self, obj_list=None):
        """ Check if bar has nothing but skips. """
        if not obj_list:
            obj_list = self.obj_list
        for obj in obj_list:
            if obj.has_attr():
                return False
            if isinstance(obj, BarNote):
                return False
            elif isinstance(obj, BarRest):
                if not obj.skip:
                    return False
        return True

    def inject_voice(self, new_voice, override=False, active_slur_count=None):
        """ Adding new voice to bar.
        Omitting double or conflicting bar attributes as long as override is false.
        Omitting also bars with only skips."""
        if new_voice.obj_list[0].has_attr():
            if self.obj_list[0].has_attr():
                self.obj_list[0].merge_attr(new_voice.obj_list[0], override)
            else:
                self.obj_list.insert(0, new_voice.obj_list[0])
            backup_list = new_voice.obj_list[1:]
        else:
            backup_list = new_voice.obj_list
        try:
            if self.obj_list[-1].barline and new_voice.obj_list[-1].barline:
                self.obj_list.pop()
        except AttributeError:
            pass
        if not self.is_skip(backup_list):
            self.create_backup()

            if active_slur_count:
                # Update active_slur_count wrt to already existing slur starts
                # and slur ends in the bar, before we add backup_list

                for n in self.obj_list:
                    if isinstance(n, BarNote):
                        for slur in n.slur:
                            if slur.slurtype == 'start':
                                active_slur_count.inc()
                            elif slur.slurtype == 'stop':
                                active_slur_count.dec()

            for bl in backup_list:
                self.add(bl)

                if active_slur_count and isinstance(bl, BarNote):
                    # If the slur is starting: increase active_slur_count and set slur number
                    # to that value.
                    # If the slur is ending: set slur number to be the same as the origin slur number.

                    for slur in bl.slur:
                        if slur.slurtype == 'start':
                            active_slur_count.inc()
                            slur.nr = active_slur_count.count
                        elif slur.slurtype == 'stop':
                            active_slur_count.dec()

                            if slur.start_node:
                                slur.nr = slur.start_node.nr

class BarMus():
    """ Common class for notes and rests. """
    def __init__(self, duration, voice=1):
        self.duration = duration
        self.type = None
        self.tuplet = []
        self.dot = 0
        self.voice = voice
        self.staff = 0
        self.chord = False
        self.other_notation = None
        self.dynamic = []
        self.oct_shift = None

    def __repr__(self):
        return '<{0} {1}>'.format(self.__class__.__name__, self.duration)

    def set_tuplet(self, fraction, ttype, nr, acttype='', normtype=''):
        self.tuplet.append(Tuplet(fraction, ttype, nr, acttype, normtype))

    def set_staff(self, staff):
        self.staff = staff

    def add_dot(self):
        self.dot += 1

    def add_other_notation(self, other):
        self.other_notation = other

    def set_dynamics_mark(self, sign, before=True):
        self.dynamic.append(DynamicsMark(sign, before))

    def set_dynamics_wedge(self, sign, before=True):
        self.dynamic.append(DynamicsWedge(sign, before))

    def set_dynamics_text(self, sign, before=True):
        self.dynamic.append(DynamicsText(sign, before))

    def set_dynamics_dashes(self, sign, before=True):
        self.dynamic.append(DynamicsDashes(sign, before))

    def set_oct_shift(self, plac, octdir, size):
        self.oct_shift = OctaveShift(plac, octdir, size)

    def has_attr(self):
        return False


##
# Classes that are used by BarMus
##


class OctaveShift():
    """Class for octave shifts."""
    def __init__(self, plac, octdir, size):
        self.plac = plac
        self.octdir = octdir
        self.size = size


class Dynamics():
    """Stores information about dynamics. """
    def __init__(self, sign, before=True):
        self.before = before
        self.sign = sign


class DynamicsMark(Dynamics):
    """A dynamics mark."""
    pass


class DynamicsWedge(Dynamics):
    """A dynamics wedge/hairpin."""
    pass


class DynamicsText(Dynamics):
    """A dynamics text."""
    pass


class DynamicsDashes(Dynamics):
    """Dynamics dashes."""
    pass


class Tuplet():
    """Stores information about tuplet."""
    def __init__(self, fraction, ttype, nr, acttype, normtype):
        self.fraction = fraction
        self.ttype = ttype
        self.nr = nr
        self.acttype = acttype
        self.normtype = normtype

class Slur():
    """Stores information about slur. start_node is only interesting if slurtype is 'stop'.
    start_node must be None or a Slur instance."""
    def __init__(self, nr, slurtype, phrasing=False, start_node=None):
        self.nr = nr
        self.slurtype = slurtype
        self.phrasing = phrasing
        self.start_node = start_node

##
# Subclasses of BarMus
##


class BarNote(BarMus):
    """ object to keep track of note parameters """
    def __init__(self, pitch_note, alter, accidental, duration, voice=1):
        BarMus.__init__(self, duration, voice)
        self.base_note = pitch_note.upper()
        self.alter = alter
        self.octave = None
        self.accidental_token = accidental
        self.tie = []
        self.grace = (0, 0)
        self.gliss = None
        self.tremolo = ('', 0)
        self.skip = False
        self.slur = []
        self.artic = []
        self.ornament = None
        self.adv_ornament = None
        self.fingering = None
        self.lyric = None
        self.stem_direction = None

    def set_duration(self, duration, durtype=''):
        self.duration = duration
        self.dot = 0
        if durtype:
            self.type = durtype

    def set_durtype(self, durtype):
        self.type = durtype

    def set_octave(self, octave):
        self.octave = octave

    def set_tie(self, tie_type):
        self.tie.append(tie_type)

    def set_slur(self, nr, slur_type, phrasing=False, slur_start_node=None):
        self.slur.append(Slur(nr, slur_type, phrasing, slur_start_node))

    def add_articulation(self, art_name):
        self.artic.append(art_name)

    def add_ornament(self, ornament):
        self.ornament = ornament

    def add_adv_ornament(self, ornament, end_type="start"):
        self.adv_ornament = (ornament, {"type": end_type})

    def set_grace(self, slash):
        self.grace = (1, slash)

    def set_gliss(self, line, endtype = "start", nr=1):
        if not line:
            line = "solid"
        self.gliss = (line, endtype, nr)

    def set_tremolo(self, trem_type, duration=False):
        if duration:
            self.tremolo = (trem_type, dur2lines(duration))
        else:
            self.tremolo = (trem_type, self.tremolo[1])

    def set_stem_direction(self, direction):
        self.stem_direction = direction

    def add_fingering(self, finger_nr):
        self.fingering = finger_nr

    def add_lyric(self, lyric_list):
        if not self.lyric:
            self.lyric = []
        self.lyric.append(lyric_list)

    def change_lyric_syll(self, index, syll):
        self.lyric[index][1] = syll

    def change_lyric_nr(self, index, nr):
        self.lyric[index][2] = nr


class Unpitched(BarNote):
    """Object to keep track of unpitched notes."""
    def __init__(self, duration, step=None, voice=1):
        BarNote.__init__(self, 'B', 0, "", duration, voice=1)
        self.octave = 4
        if step:
            self.base_note = step.upper()


class BarRest(BarMus):
    """ object to keep track of different rests and skips """
    def __init__(self, duration, voice=1, show_type=True, skip=False, pos=0):
        BarMus.__init__(self, duration, voice)
        self.show_type = show_type
        self.type = None
        self.skip = skip
        self.pos = pos

    def set_duration(self, duration, durtype=''):
        self.duration = duration
        if durtype:
            if self.show_type:
                self.type = durtype
            else:
                self.type = None

    def set_durtype(self, durtype):
        if self.show_type:
            self.type = durtype


class BarAttr():
    """ object that keep track of bar attributes, e.g. time sign, clef, key etc """
    def __init__(self):
        self.key = None
        self.time = 0
        self.clef = 0
        self.mode = ''
        self.divs = 0
        self.barline = None
        self.repeat = None
        self.staves = 0
        self.multiclef = []
        self.tempo = None
        self.multirest = None
        self.mark = None
        self.word = None
        self.new_system = None

    def __repr__(self):
        return '<{0} {1}>'.format(self.__class__.__name__, self.time)

    def add_break(self, force_break):
        self.new_system = force_break

    def set_key(self, muskey, mode):
        self.key = muskey
        self.mode = mode

    def set_time(self, fractlist, numeric=True):
        self.time = fractlist
        if not numeric and (fractlist == [2, 2] or fractlist == [4, 4]):
            self.time.append('common')

    def set_clef(self, clef):
        self.clef = clef

    def set_barline(self, bl):
        self.barline = convert_barl(bl)

    def set_tempo(self, unit=0, unittype='', beats=0, dots=0, text=""):
        self.tempo = TempoDir(unit, unittype, beats, dots, text)

    def set_multp_rest(self, size=0):
        self.multirest = size

    def set_mark(self, mark):
        self.mark = mark

    def set_word(self, words):
        if self.word == None:
            self.word = ''
        self.word += words + ' '

    def has_attr(self):
        check = False
        if self.key is not None:
            check = True
        elif self.time != 0:
            check = True
        elif self.clef != 0:
            check = True
        elif self.multiclef:
            check = True
        elif self.divs != 0:
            check = True
        elif self.multirest is not None:
            check = True
        elif self.mark:
            check = True
        return check

    def merge_attr(self, barattr, override=False):
        """Merge in attributes (from another bar).
        Existing attributes will only be replaced when override is set to true.
        """
        if barattr.key is not None and (override or self.key is None):
            self.key = barattr.key
            self.mode = barattr.mode
        if barattr.time != 0 and (override or self.time == 0):
            self.time = barattr.time
        if barattr.clef != 0 and (override or self.clef == 0):
            self.clef = barattr.clef
        if barattr.multiclef:
            self.multiclef += barattr.multiclef
        if barattr.tempo is not None and (override or self.tempo is None):
            self.tempo = barattr.tempo


class BarBackup():
    """ Object that stores duration for backup """
    def __init__(self, duration):
        self.duration = duration


class TempoDir():
    """ Object that stores tempo direction information """
    def __init__(self, unit, unittype, beats, dots, text):
        if unittype:
            self.metr = unittype, beats
            self.midi = self.set_midi_tempo(unit, beats, dots)
        else:
            self.metr = 0
            self.midi = 0
        self.dots = dots
        self.text = text

    def set_midi_tempo(self, unit, beats, dots):
        u = Fraction(1, int(unit))
        if dots:
            import math
            den = int(math.pow(2, dots))
            num = int(math.pow(2, dots+1)-1)
            u *= Fraction(num, den)
        mult = 4*u
        return float(Fraction(beats)*mult)


##
# Translation functions
##

def dur2lines(dur):
    if dur == 8:
        return 1
    elif dur == 16:
        return 2
    elif dur == 32:
        return 3
    else:
        return 0

def convert_barl(bl):
    if bl == '|':
        return 'regular'
    elif bl == ':':
        return 'dotted'
    elif bl == 'dashed':
        return bl
    elif bl == '.':
        return 'heavy'
    elif bl == '||':
        return 'light-light'
    elif bl == '.|' or bl == 'forward':
        return 'heavy-light'
    elif bl == '.|.':
        return 'heavy-heavy'
    elif bl == '|.' or bl == 'backward':
        return 'light-heavy'
    elif bl == "'":
        return 'tick'
python_ly-0.9.9/ly/pitch/__init__.py0000644000000000000000000003061713615410400014351 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Pitch manipulation.
"""

from __future__ import unicode_literals

import re
from fractions import Fraction

import ly.lex.lilypond


pitchInfo = {
    'nederlands': (
        ('c', 'd', 'e', 'f', 'g', 'a', 'b'),
        ('eses', 'eseh', 'es', 'eh', '', 'ih', 'is', 'isih', 'isis'),
        (('ees', 'es'), ('aes', 'as'))
    ),
    'english': (
        ('c', 'd', 'e', 'f', 'g', 'a', 'b'),
        ('ff', 'tqf', 'f', 'qf', '', 'qs', 's', 'tqs', 'ss'),
    ),
    'deutsch': (
        ('c', 'd', 'e', 'f', 'g', 'a', 'h'),
        ('eses', 'eseh', 'es', 'eh', '', 'ih', 'is', 'isih', 'isis'),
        (('ases', 'asas'), ('ees', 'es'), ('aes', 'as'), ('heses', 'heses'), ('hes', 'b'))
    ),
    'svenska': (
        ('c', 'd', 'e', 'f', 'g', 'a', 'h'),
        ('essess', '', 'ess', '', '', '', 'iss', '', 'ississ'),
        (('ees', 'es'), ('aes', 'as'), ('hessess', 'hessess'), ('hess', 'b'))
    ),
    'italiano': (
        ('do', 're', 'mi', 'fa', 'sol', 'la', 'si'),
        ('bb', 'bsb', 'b', 'sb', '', 'sd', 'd', 'dsd', 'dd')
    ),
    'espanol': (
        ('do', 're', 'mi', 'fa', 'sol', 'la', 'si'),
        ('bb', '', 'b', '', '', '', 's', '', 'ss')
    ),
    'portugues': (
        ('do', 're', 'mi', 'fa', 'sol', 'la', 'si'),
        ('bb', 'btqt', 'b', 'bqt', '', 'sqt', 's', 'stqt', 'ss')
    ),
    'vlaams': (
        ('do', 're', 'mi', 'fa', 'sol', 'la', 'si'),
        ('bb', '', 'b', '', '', '', 'k', '', 'kk')
    ),
}
pitchInfo['norsk'] = pitchInfo['deutsch']
pitchInfo['suomi'] = pitchInfo['deutsch']
pitchInfo['catalan'] = pitchInfo['italiano']


class PitchNameNotAvailable(Exception):
    """Exception raised when there is no name for a pitch.
    
    Can occur when translating pitch names, if the target language e.g.
    does not have quarter-tone names.
    
    """
    def __init__(self, language):
        super(PitchNameNotAvailable, self).__init__()
        self.language = language


class Pitch(object):
    """A pitch with note, alter and octave attributes.
    
    Attributes may be manipulated directly.
    
    """
    def __init__(self, note=0, alter=0, octave=0, accidental="", octavecheck=None):
        self.note = note                # base note (c, d, e, f, g, a, b)
                                        # as integer (0 to 6)
        self.alter = alter              # # = .5; b = -.5; natural = 0
        self.octave = octave            # '' = 2; ,, = -2
        self.accidental = accidental    # "", "?" or "!"
        self.octavecheck = octavecheck  # a number is an octave check
    
    def __repr__(self):
        return ''.format(self.output())
    
    def output(self, language="nederlands"):
        """Returns our string representation."""
        res = []
        res.append(pitchWriter(language)(self.note, self.alter))
        res.append(octaveToString(self.octave))
        res.append(self.accidental)
        if self.octavecheck is not None:
            res.append('=')
            res.append(octaveToString(self.octavecheck))
        return ''.join(res)
        
    @classmethod
    def c1(cls):
        """Returns a pitch c'."""
        return cls(octave=1)

    @classmethod
    def c0(cls):
        """Returns a pitch c."""
        return cls()

    @classmethod
    def f0(cls):
        """Return a pitch f."""
        return cls(3)

    def copy(self):
        """Returns a new instance with our attributes."""
        return self.__class__(self.note, self.alter, self.octave)
        
    def makeAbsolute(self, lastPitch):
        """Makes ourselves absolute, i.e. sets our octave from lastPitch."""
        self.octave += lastPitch.octave - (self.note - lastPitch.note + 3) // 7
        
    def makeRelative(self, lastPitch):
        """Makes ourselves relative, i.e. changes our octave from lastPitch."""
        self.octave -= lastPitch.octave - (self.note - lastPitch.note + 3) // 7


class PitchWriter(object):
    language = "unknown"
    def __init__(self, names, accs, replacements=()):
        self.names = names
        self.accs = accs
        self.replacements = replacements

    def __call__(self, note, alter = 0):
        """
        Returns a string representing the pitch in our language.
        Raises PitchNameNotAvailable if the requested pitch
        has an alteration that is not available in the current language.
        """
        pitch = self.names[note]
        if alter:
            acc = self.accs[int(alter * 4 + 4)]
            if not acc:
                raise PitchNameNotAvailable(self.language)
            pitch += acc
        for s, r in self.replacements:
            if pitch.startswith(s):
                pitch = r + pitch[len(s):]
                break
        return pitch


class PitchReader(object):
    def __init__(self, names, accs, replacements=()):
        self.names = list(names)
        self.accs = list(accs)
        self.replacements = replacements
        self.rx = re.compile("({0})({1})?$".format("|".join(names),
            "|".join(acc for acc in accs if acc)))

    def __call__(self, text):
        for s, r in self.replacements:
            if text.startswith(r):
                text = s + text[len(r):]
        for dummy in 1, 2:
            m = self.rx.match(text)
            if m:
                note = self.names.index(m.group(1))
                if m.group(2):
                    alter = Fraction(self.accs.index(m.group(2)) - 4, 4)
                else:
                    alter = 0
                return note, alter
            # HACK: were we using (rarely used) long english syntax?
            text = text.replace('flat', 'f').replace('sharp', 's')
        return False
            
            
def octaveToString(octave):
    """Converts numeric octave to a string with apostrophes or commas.
    
    0 -> "" ; 1 -> "'" ; -1 -> "," ; etc.
    
    """
    return octave < 0 and ',' * -octave or "'" * octave


def octaveToNum(octave):
    """Converts string octave to an integer:
    
    "" -> 0 ; "," -> -1 ; "'''" -> 3 ; etc.
    
    """
    return octave.count("'") - octave.count(",")


_pitchReaders = {}
_pitchWriters = {}


def pitchReader(language):
    """Returns a PitchReader for the specified language."""
    try:
        return _pitchReaders[language]
    except KeyError:
        res = _pitchReaders[language] = PitchReader(*pitchInfo[language])
        return res


def pitchWriter(language):
    """Returns a PitchWriter for the specified language."""
    try:
        return _pitchWriters[language]
    except KeyError:
        res = _pitchWriters[language] = PitchWriter(*pitchInfo[language])
        res.language = language
        return res


class PitchIterator(object):
    """Iterate over notes or pitches in a source."""
    
    def __init__(self, source, language="nederlands"):
        """Initialize with a ly.document.Source.
        
        The language is by default set to "nederlands".
        
        """
        self.source = source
        self.setLanguage(language)
    
    def setLanguage(self, lang):
        r"""Changes the pitch name language to use.
        
        Called internally when \language or \include tokens are encountered
        with a valid language name/file.
        
        Sets the language attribute to the language name and the read attribute
        to an instance of ly.pitch.PitchReader.
        
        """
        if lang in pitchInfo.keys():
            self.language = lang
            return True
    
    def tokens(self):
        """Yield all the tokens from the source, following the language."""
        for t in self.source:
            yield t
            if isinstance(t, ly.lex.lilypond.Keyword):
                if t in ("\\include", "\\language"):
                    for t in self.source:
                        if not isinstance(t, ly.lex.Space) and t != '"':
                            lang = t[:-3] if t.endswith('.ly') else t[:]
                            if self.setLanguage(lang):
                                yield LanguageName(lang, t.pos)
                            break
                        yield t
    
    def read(self, token):
        """Reads the token and returns (note, alter) or None."""
        return pitchReader(self.language)(token)
    
    def pitches(self):
        """Yields all tokens, but collects Note and Octave tokens.
        
        When a Note is encountered, also reads octave and octave check and then
        a Pitch is yielded instead of the tokens.
        
        """
        tokens = self.tokens()
        for t in tokens:
            while isinstance(t, ly.lex.lilypond.Note):
                p = self.read(t)
                if not p:
                    break
                p = Pitch(*p)
                
                p.note_token = t
                p.octave_token = None
                p.accidental_token = None
                p.octavecheck_token = None
                
                t = None # prevent hang in this loop
                for t in tokens:
                    if isinstance(t, ly.lex.lilypond.Octave):
                        p.octave = octaveToNum(t)
                        p.octave_token = t
                    elif isinstance(t, ly.lex.lilypond.Accidental):
                        p.accidental_token = p.accidental = t
                    elif isinstance(t, ly.lex.lilypond.OctaveCheck):
                        p.octavecheck = octaveToNum(t)
                        p.octavecheck_token = t
                        break
                    elif not isinstance(t, ly.lex.Space):
                        break
                yield p
                if t is None:
                    break
            else:
                yield t
        
    def position(self, t):
        """Returns the cursor position for the given token or Pitch."""
        if isinstance(t, Pitch):
            t = t.note_token
        return self.source.position(t)
    
    def write(self, pitch, language=None):
        """Output a changed Pitch.
        
        The Pitch is written in the Source's document.
        
        To use this method reliably, you must instantiate the PitchIterator
        with a ly.document.Source that has tokens_with_position set to True.
        
        """
        document = self.source.document
        pwriter = pitchWriter(language or self.language)
        note = pwriter(pitch.note, pitch.alter)
        end = pitch.note_token.end
        if note != pitch.note_token:
            document[pitch.note_token.pos:end] = note
        octave = octaveToString(pitch.octave)
        if octave != pitch.octave_token:
            if pitch.octave_token is None:
                document[end:end] = octave
            else:
                end = pitch.octave_token.end
                document[pitch.octave_token.pos:end] = octave
        if pitch.accidental:
            if pitch.accidental_token is None:
                document[end:end] = pitch.accidental
            elif pitch.accidental != pitch.accidental_token:
                end = pitch.accidental_token.end
                document[pitch.accidental_token.pos:end] = pitch.accidental
        elif pitch.accidental_token:
            del document[pitch.accidental_token.pos:pitch.accidental_token.end]
        if pitch.octavecheck is not None:
            octavecheck = '=' + octaveToString(pitch.octavecheck)
            if pitch.octavecheck_token is None:
                document[end:end] = octavecheck
            elif octavecheck != pitch.octavecheck_token:
                document[pitch.octavecheck_token.pos:pitch.octavecheck_token.end] = octavecheck
        elif pitch.octavecheck_token:
            del document[pitch.octavecheck_token.pos:pitch.octavecheck_token.end]


class LanguageName(ly.lex.Token):
    """A Token that denotes a language name."""
    pass


python_ly-0.9.9/ly/pitch/abs2rel.py0000644000000000000000000001447013615410400014143 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2011 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Convert absolute music to relative music.
"""

from __future__ import unicode_literals

import itertools

import ly.lex.lilypond


def abs2rel(cursor, language="nederlands", startpitch=True, first_pitch_absolute=False):
    """Converts pitches from absolute to relative.
    
    language: language to start reading pitch names in
    
    startpitch: if True, write a starting pitch before the opening bracket of
        a relative expression.
        
    first_pitch_absolute: this option only makes sense when startpitch is False.
        If first_pitch_absolute is True, the first pitch of a \\relative
        expression is written as absolute. This mimics the behaviour of
        LilyPond >= 2.18. (In fact, the starting pitch is then assumed to be f.)
        
        If False, the first pitch is written as relative to c'
        (LilyPond < 2.18 behaviour).
    
    Existing \\relative expressions are not changed.
    
    """
    start = cursor.start
    cursor.start = 0
    
    source = ly.document.Source(cursor, True, tokens_with_position=True)

    pitches = ly.pitch.PitchIterator(source, language)
    psource = pitches.pitches()
    
    if start > 0:
        # consume tokens before the selection, following the language
        t = source.consume(pitches.tokens(), start)
        if t:
            psource = itertools.chain((t,), psource)
    
    # this class dispatches the tokens. we can't use a generator function
    # as that doesn't like to be called again while there is already a body
    # running.
    class gen(object):
        def __iter__(self):
            return self
        
        def __next__(self):
            t = next(psource)
            while isinstance(t, (ly.lex.Space, ly.lex.Comment)):
                t = next(psource)
            if t == '\\relative' and isinstance(t, ly.lex.lilypond.Command):
                relative()
                t = next(psource)
            elif isinstance(t, ly.lex.lilypond.ChordMode):
                consume() # do not change chords
                t = next(psource)
            elif isinstance(t, ly.lex.lilypond.MarkupScore):
                consume()
                t = next(psource)
            return t
        
        next = __next__
            
    tsource = gen()

    def getpitches(iterable):
        """Consumes iterable but only yields Pitch instances."""
        for p in iterable:
            if isinstance(p, ly.pitch.Pitch):
                yield p

    def context():
        """Consume tokens till the level drops (we exit a construct)."""
        depth = source.state.depth()
        for t in tsource:
            yield t
            if source.state.depth() < depth:
                return
    
    def consume():
        """Consume tokens from context() returning the last token, if any."""
        t = None
        for t in context():
            pass
        return t
    
    def relative():
        r"""Consume the whole \relative expression without doing anything. """
        # skip pitch argument
        t = next(tsource)
        if isinstance(t, ly.pitch.Pitch):
            t = next(tsource)
        
        while True:
            # eat stuff like \new Staff == "bla" \new Voice \notes etc.
            if isinstance(source.state.parser(), ly.lex.lilypond.ParseTranslator):
                t = consume()
            elif isinstance(t, ly.lex.lilypond.NoteMode):
                t = next(tsource)
            else:
                break
        
        if t in ('{', '<<', '<'):
            consume()
    
    # Do it!
    with cursor.document as document:
        for t in tsource:
            if t in ('{', '<<'):
                # Ok, parse current expression.
                pos = t.pos     # where to insert the \relative command
                lastPitch = None
                chord = None
                for t in context():
                    # skip commands with pitches that do not count
                    if isinstance(t, ly.lex.lilypond.PitchCommand):
                        consume()
                    elif isinstance(t, ly.lex.lilypond.ChordStart):
                        # Handle chord
                        chord = []
                    elif isinstance(t, ly.lex.lilypond.ChordEnd):
                        if chord:
                            lastPitch = chord[0]
                        chord = None
                    elif isinstance(t, ly.pitch.Pitch):
                        # Handle pitch
                        if lastPitch is None:
                            if startpitch:
                                lastPitch = ly.pitch.Pitch.c1()
                                lastPitch.octave = t.octave
                                if t.note > 3:
                                    lastPitch.octave += 1
                                document[pos:pos] = "\\relative {0} ".format(
                                        lastPitch.output(pitches.language))
                            else:
                                if first_pitch_absolute:
                                    lastPitch = ly.pitch.Pitch.f0()
                                else:
                                    lastPitch = ly.pitch.Pitch.c1()
                                document[pos:pos] = "\\relative "
                        p = t.copy()
                        t.makeRelative(lastPitch)
                        pitches.write(t)
                        lastPitch = p
                        # remember the first pitch of a chord
                        if chord == []:
                            chord.append(p)


python_ly-0.9.9/ly/pitch/rel2abs.py0000644000000000000000000001411113615410400014133 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2011 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Convert relative music to absolute music.
"""

from __future__ import unicode_literals

import itertools

import ly.lex.lilypond


def rel2abs(cursor, language="nederlands", first_pitch_absolute=False):
    """Converts pitches from relative to absolute.
    
    language: language to start reading pitch names in
    
    first_pitch_absolute: if True, the first pitch of a \\relative expression
        is regarded as absolute, when no starting pitch was given. This mimics
        the behaviour of LilyPond >= 2.18.
        (In fact, the starting pitch is then assumed to be f.)
        
        If False, the starting pitch, when not given, is assumed to be c'
        (LilyPond < 2.18 behaviour).
        
    """
    start = cursor.start
    cursor.start = 0
    
    source = ly.document.Source(cursor, True, tokens_with_position=True)

    pitches = ly.pitch.PitchIterator(source, language)
    psource = pitches.pitches()
    
    if start > 0:
        # consume tokens before the selection, following the language
        t = source.consume(pitches.tokens(), start)
        if t:
            psource = itertools.chain((t,), psource)
    
    # this class dispatches the tokens. we can't use a generator function
    # as that doesn't like to be called again while there is already a body
    # running.
    class gen(object):
        def __iter__(self):
            return self
        
        def __next__(self):
            t = next(psource)
            while isinstance(t, (ly.lex.Space, ly.lex.Comment)):
                t = next(psource)
            if t == '\\relative' and isinstance(t, ly.lex.lilypond.Command):
                relative(t)
                t = next(psource)
            elif isinstance(t, ly.lex.lilypond.MarkupScore):
                consume()
                t = next(psource)
            return t
        
        next = __next__
            
    tsource = gen()
    
    def makeAbsolute(p, lastPitch):
        """Makes pitch absolute (honoring and removing possible octaveCheck)."""
        if p.octavecheck is not None:
            p.octave = p.octavecheck
            p.octavecheck = None
        else:
            p.makeAbsolute(lastPitch)
        pitches.write(p)
    
    def getpitches(iterable):
        """Consumes iterable but only yields Pitch instances."""
        for p in iterable:
            if isinstance(p, ly.pitch.Pitch):
                yield p

    def context():
        """Consume tokens till the level drops (we exit a construct)."""
        depth = source.state.depth()
        for t in tsource:
            yield t
            if source.state.depth() < depth:
                return
    
    def consume():
        """Consume tokens from context() returning the last token, if any."""
        t = None
        for t in context():
            pass
        return t
    
    def relative(t):
        pos = t.pos
        lastPitch = None
        
        t = next(tsource)
        if isinstance(t, ly.pitch.Pitch):
            lastPitch = t
            t = next(tsource)
        elif first_pitch_absolute:
            lastPitch = ly.pitch.Pitch.f0()
        else:
            lastPitch = ly.pitch.Pitch.c1()
        
        # remove the \relative  tokens
        del document[pos:t.pos]
        
        while True:
            # eat stuff like \new Staff == "bla" \new Voice \notes etc.
            if isinstance(source.state.parser(), ly.lex.lilypond.ParseTranslator):
                t = consume()
            elif isinstance(t, (ly.lex.lilypond.ChordMode, ly.lex.lilypond.NoteMode)):
                t = next(tsource)
            else:
                break
        
        # now convert the relative expression to absolute
        if t in ('{', '<<'):
            # Handle full music expression { ... } or << ... >>
            for t in context():
                # skip commands with pitches that do not count
                if isinstance(t, ly.lex.lilypond.PitchCommand):
                    if t == '\\octaveCheck':
                        pos = t.pos
                        for p in getpitches(context()):
                            # remove the \octaveCheck
                            lastPitch = p
                            end = (p.accidental_token or p.octave_token or p.note_token).end
                            del document[pos:end]
                            break
                    else:
                        consume()
                elif isinstance(t, ly.lex.lilypond.ChordStart):
                    # handle chord
                    chord = [lastPitch]
                    for p in getpitches(context()):
                        makeAbsolute(p, chord[-1])
                        chord.append(p)
                    lastPitch = chord[:2][-1] # same or first
                elif isinstance(t, ly.pitch.Pitch):
                    makeAbsolute(t, lastPitch)
                    lastPitch = t
        elif isinstance(t, ly.lex.lilypond.ChordStart):
            # Handle just one chord
            for p in getpitches(context()):
                makeAbsolute(p, lastPitch)
                lastPitch = p
        elif isinstance(t, ly.pitch.Pitch):
            # Handle just one pitch
            makeAbsolute(t, lastPitch)
    
    # Do it!
    with cursor.document as document:
        for t in tsource:
            pass


python_ly-0.9.9/ly/pitch/transform.py0000644000000000000000000000464113615410400014623 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2011 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Transforming music by pitch manipulation.
"""

from __future__ import unicode_literals

import ly.lex.lilypond


def retrograde(cursor, language="nederlands"):
    """Reverses pitches."""    
    source = ly.document.Source(cursor, True, tokens_with_position=True)

    pitches = ly.pitch.PitchIterator(source, language)
    psource = pitches.pitches()

    plist = [p for p in psource if isinstance(p, ly.pitch.Pitch)]
    rlist = [r.copy() for r in reversed(plist)]
    
    with cursor.document as d:
        for p, r in zip(plist, rlist):
            p.note = r.note   
            p.alter = r.alter            
            p.octave = r.octave          
            pitches.write(p)

def inversion(cursor, language="nederlands"):
    """Inversion of the intervals between pitches."""
    import ly.pitch.transpose
     
    source = ly.document.Source(cursor, True, tokens_with_position=True)

    pitches = ly.pitch.PitchIterator(source, language)
    psource = pitches.pitches()

    prev_note = None

    with cursor.document as d:
        for p in psource:
            if isinstance(p, ly.pitch.Pitch):
                if prev_note is None:
                    prev_note = refp = p
                    continue
                transposer = ly.pitch.transpose.Transposer(p, prev_note)
                prev_note = p.copy()
                p.note = refp.note
                p.alter = refp.alter
                p.octave = refp.octave               
                transposer.transpose(p)
                refp = p
                pitches.write(p)
                
     
python_ly-0.9.9/ly/pitch/translate.py0000644000000000000000000000677613615410400014620 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Translating the language of pitch names
"""

from __future__ import unicode_literals

import ly.document
import ly.pitch


def translate(cursor, language, default_language="nederlands"):
    r"""Changes the language of the pitch names.
    
    May raise ly.pitch.PitchNameNotAvailable if the current pitch language
    has no quarter tones.
    
    Returns True if there also was a \language or \include language command 
    that was changed. If not and the cursor specified only a part of the 
    document, you could warn the user that a language or include command
    should be added to the document. Or you could call insert_language to 
    add a language command to the top of the document.
    
    """
    start = cursor.start
    cursor.start = 0
    
    source = ly.document.Source(cursor, tokens_with_position=True)

    pitches = ly.pitch.PitchIterator(source, default_language)
    tokens = pitches.tokens()
    writer = ly.pitch.pitchWriter(language)
    
    if start > 0:
        # consume tokens before the selection, following the language
        source.consume(tokens, start)
        cursor.start = start
    
    changed = False # track change of \language or \include language command
    with cursor.document as d:
        for t in tokens:
            if isinstance(t, ly.lex.lilypond.Note):
                # translate the pitch name
                p = pitches.read(t)
                if p:
                    n = writer(*p)
                    if n != t:
                        d[t.pos:t.end] = n
            elif isinstance(t, ly.pitch.LanguageName):
                if t != language:
                    # change the language name in a command
                    d[t.pos:t.end] = language
                changed = True
    return changed


def insert_language(document, language, version=None):
    r"""Inserts a language command in the document.
    
    The command is inserted at the top or just below the version line.
    
    If the LilyPond version specified < (2, 13, 38), the \include command
    is used, otherwise the newer \language command.
    
    """
    # maybe TODO: determine version automatically from document
    if version and version < (2, 13, 38):
        text = '\\include "{0}.ly"\n'
    else:
        text = '\\language "{0}"\n'
    text = text.format(language)
    # insert language command on top of file, but below version
    with document:
        for b in document:
            if '\\version' not in document.tokens(b):
                pos = document.position(b)
                document[pos:pos] = text
                break
        else:
            pos = document.size()
            document[pos:pos] = '\n\n' + text


python_ly-0.9.9/ly/pitch/transpose.py0000644000000000000000000003752013615410400014630 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Transposing music.
"""

from __future__ import unicode_literals

from fractions import Fraction

import ly.lex.lilypond


class Transposer(object):
    """Transpose pitches.
    
    Instantiate with a from- and to-Pitch, and optionally a scale.
    The scale is a list with the pitch height of the unaltered step (0 .. 6).
    The default scale is the normal scale: C, D, E, F, G, A, B.
    
    """
    scale = (0, 1, 2, Fraction(5, 2), Fraction(7, 2), Fraction(9, 2), Fraction(11, 2))
        
    def __init__(self, fromPitch, toPitch, scale = None):
        if scale is not None:
            self.scale = scale
        
        # the number of octaves we need to transpose
        self.octave = toPitch.octave - fromPitch.octave
        
        # the number of base note steps (c->d == 1, e->f == 1, etc.)
        self.steps = toPitch.note - fromPitch.note
        
        # the number (fraction) of real whole steps
        self.alter = (self.scale[toPitch.note] + toPitch.alter -
                      self.scale[fromPitch.note] - fromPitch.alter)
                  
    def transpose(self, pitch):
        doct, note = divmod(pitch.note + self.steps, 7)
        pitch.alter += self.alter - doct * 6 - self.scale[note] + self.scale[pitch.note]
        pitch.octave += self.octave + doct
        pitch.note = note
        # change the step if alterations fall outside -1 .. 1
        while pitch.alter > 1:
            doct, note = divmod(pitch.note + 1, 7)
            pitch.alter -= doct * 6 + self.scale[note] - self.scale[pitch.note]
            pitch.octave += doct
            pitch.note = note
        while pitch.alter < -1:
            doct, note = divmod(pitch.note - 1, 7)
            pitch.alter += doct * -6 + self.scale[pitch.note] - self.scale[note]
            pitch.octave += doct
            pitch.note = note
            
            
class Simplifier(Transposer):
    """Make complicated accidentals simpler by substituting naturals where possible.
    
    """
    def __init__(self, scale=None):
        if scale is not None:
            self.scale = scale
    
    def transpose(self, pitch):
        if pitch.alter == 1:
            doct, note = divmod(pitch.note + 1, 7)
            pitch.alter -= doct * 6 + self.scale[note] - self.scale[pitch.note]
            pitch.octave += doct
            pitch.note = note
        elif pitch.alter == -1:
            doct, note = divmod(pitch.note - 1, 7)
            pitch.alter += doct * -6 + self.scale[pitch.note] - self.scale[note]
            pitch.octave += doct
            pitch.note = note
        if pitch.alter == Fraction(1, 2):
            doct, note = divmod(pitch.note + 1, 7)
            alter = doct * 6 + self.scale[note] - self.scale[pitch.note]
            if alter == Fraction(1, 2):
                pitch.alter = 0
                pitch.octave += doct
                pitch.note = note
        elif pitch.alter == Fraction(-1, 2):
            doct, note = divmod(pitch.note - 1, 7)
            alter = doct * -6 + self.scale[pitch.note] - self.scale[note]
            if alter == Fraction(1, 2):
                pitch.alter = 0
                pitch.octave += doct
                pitch.note = note


class ModeShifter(Transposer):
    """
    Shift pitches to optional mode/scale.
    
    The scale should be formatted in analogy to the scale in the Transposer
    parent class.
    
    The key should be an instance of ly.pitch.Pitch. 
    """
    def __init__(self, key, scale):
        """
        Create scale of pitches from given scale definition.
        """
        import math
        self.octave = 0
        self.modpitches = [0] * 7
        for s, a in scale:
            p = key.copy()
            self.steps = s 
            self.alter = a
            super(ModeShifter, self).transpose(p)
            if self.modpitches[p.note]:
                self.modpitches[p.note].append(p)
            else:
                self.modpitches[p.note] = [p]
        
    def closestPitch(self, pitch):
        """
        Get closest pitch from scale. 
        
        If only one scale note with the same base step exist that is returned.
        Otherwise the closest is calculated.
        """
        def getNextPitch(step, up=True):
            modepitch = self.modpitches[step]
            if modepitch:
                return modepitch
            else:
                if up:
                    step = (step + 1) % 7
                else:
                    step = (step - 1) % 7
                return getNextPitch(step, up)
                
        def comparePitch(pitch, uppitch, dwnpitch):
            upnum = self.scale[uppitch.note] + uppitch.alter
            dwnnum = self.scale[dwnpitch.note] + dwnpitch.alter
            pnum = self.scale[pitch.note] + pitch.alter
            if upnum - pnum < pnum - dwnnum:
                return uppitch
            else: 
                return dwnpitch
            
        step = pitch.note
        modepitch = self.modpitches[step]
        if modepitch and len(modepitch) == 2:
            return comparePitch(pitch, modepitch[0], modepitch[1])
        else:
            uppitch = getNextPitch(step)[0] 
            dwnpitch = getNextPitch(step, False)[-1]
            return comparePitch(pitch, uppitch, dwnpitch)
            
        
    def transpose(self, pitch):
        """
        Shift to closest scale pitch if not already in scale.
        """
        modpitch = self.modpitches[pitch.note]
        if modpitch:
            for mp in modpitch:
                if pitch.note == mp.note and pitch.alter == mp.alter:
                    return
        clp = self.closestPitch(pitch)
        self.steps = clp.note - pitch.note
        if self.steps > 3:
            self.octave = -1
        elif self.steps < -3:
            self.octave = 1
        else:
            self.octave = 0
        self.alter = (self.scale[clp.note] + clp.alter -
                      self.scale[pitch.note] - pitch.alter)
        super(ModeShifter, self).transpose(pitch)


class ModalTransposer(object):
    """Transpose pitches by number of steps within a given scale.
    
    Instantiate with the number of steps (+/-) in the scale to transpose by, and a mode index.
    The mode index is the index of the major scale in the circle of fifths (C Major = 0).
    """        
    def __init__(self, numSteps = 1, scaleIndex = 0):
        self.numSteps = numSteps
        self.notes = [0, 1, 2, 3, 4, 5, 6]
        self.alter = [-0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5]
        # Initialize to Db, then update to desired mode
        
        for i in range(0, scaleIndex):
            keyNameIndex = ((i+1)*4)%len(self.notes)
            accidentalIndex = (keyNameIndex-1)%len(self.notes)
            self.alter[accidentalIndex] += .5
            
    @staticmethod
    def getKeyIndex(text):
        """Get the index of the key in the circle of fifths.
        
        'Cb' returns 0, 'C' returns 7, 'B#' returns 14.
        """
        circleOfFifths = ['Cb', 'Gb', 'Db', 'Ab', 'Eb', 'Bb', 'F',
                          'C', 'G', 'D', 'A', 'E', 'B', 'F#', 'C#']
        return circleOfFifths.index(text.capitalize())
                  
    def transpose(self, pitch):
        # Look for an exact match: otherwise,
        # look for the letter name and save the accidental
        for i in range(len(self.notes)):
            if pitch.note == self.notes[i] and pitch.alter == self.alter:
                fromScaleDeg = i
                accidental = 0
                break
        else:
            fromScaleDeg = self.notes.index(pitch.note)
            accidental = pitch.alter - self.alter[fromScaleDeg]
        
        toOctaveMod, toScaleDeg = divmod(fromScaleDeg + self.numSteps, 7)
        pitch.note = self.notes[toScaleDeg]
        pitch.alter = self.alter[toScaleDeg] + accidental
        pitch.octave += toOctaveMod


def transpose(cursor, transposer, language="nederlands", relative_first_pitch_absolute=False):
    """Transpose pitches using the specified transposer.
    
    If relative_first_pitch_absolute is True, the first pitch in a \\relative
    expression is considered to be absolute, when a startpitch is not given.
    This is LilyPond >= 2.18 behaviour.
    
    If relative_first_pitch_absolute is False, the first pitch in a \\relative
    expression is considered to be relative to c', is no startpitch is given.
    This is LilyPond < 2.18 behaviour.
    
    Currently, relative_first_pitch_absolute defaults to False.
    
    """
    start = cursor.start
    cursor.start = 0
    
    source = ly.document.Source(cursor, True, tokens_with_position=True)

    pitches = ly.pitch.PitchIterator(source, language)
    psource = pitches.pitches()

    class gen(object):
        def __iter__(self):
            return self
        
        def __next__(self):
            while True:
                t = next(psource)
                if isinstance(t, (ly.lex.Space, ly.lex.Comment)):
                    continue
                # Handle stuff that's the same in relative and absolute here
                if t == "\\relative":
                    relative()
                elif isinstance(t, ly.lex.lilypond.MarkupScore):
                    absolute(context())
                elif isinstance(t, ly.lex.lilypond.ChordMode):
                    chordmode()
                elif isinstance(t, ly.lex.lilypond.Command) and t == '\\stringTuning':
                    string_tuning()
                elif isinstance(t, ly.lex.lilypond.PitchCommand):
                    if t == "\\transposition":
                        next(psource) # skip pitch
                    elif t == "\\transpose":
                        for p in getpitches(context()):
                            transpose(p)
                    elif t == "\\key":
                        for p in getpitches(context()):
                            transpose(p, 0)
                    else:
                        return t
                else:
                    return t
        
        next = __next__
    
    tsource = gen()
    
    def in_selection(p):
        """Return True if the pitch or token p may be replaced, i.e. was selected."""
        return start == 0 or pitches.position(p) >= start
    
    def getpitches(iterable):
        """Consumes iterable but only yields Pitch instances."""
        for p in iterable:
            if isinstance(p, ly.pitch.Pitch):
                yield p

    def context():
        """Consume tokens till the level drops (we exit a construct)."""
        depth = source.state.depth()
        for t in tsource:
            yield t
            if source.state.depth() < depth:
                return
    
    def consume():
        """Consume tokens from context() returning the last token, if any."""
        t = None
        for t in context():
            pass
        return t
        
    def transpose(p, resetOctave = None):
        """Transpose absolute pitch, using octave if given."""
        transposer.transpose(p)
        if resetOctave is not None:
            p.octave = resetOctave
        if in_selection(p):
            pitches.write(p)

    def chordmode():
        r"""Called inside \chordmode or \chords."""
        for p in getpitches(context()):
            transpose(p, 0)
            
    def string_tuning():
        r"""Called after \stringTuning. Ignores the following chord expression."""
        for t in tsource:
            if isinstance(t, ly.lex.lilypond.ChordStart):
                consume()
            break
    
    def absolute(tokens):
        r"""Called when outside a possible \relative environment."""
        for p in getpitches(tokens):
            transpose(p)
    
    def relative():
        r"""Called when \relative is encountered."""
        def transposeRelative(p, lastPitch):
            """Transposes a relative pitch; returns the pitch in absolute form."""
            # absolute pitch determined from untransposed pitch of lastPitch
            p.makeAbsolute(lastPitch)
            if not in_selection(p):
                return p
            # we may change this pitch. Make it relative against the
            # transposed lastPitch.
            try:
                last = lastPitch.transposed
            except AttributeError:
                last = lastPitch
            # transpose a copy and store that in the transposed
            # attribute of lastPitch. Next time that is used for
            # making the next pitch relative correctly.
            newLastPitch = p.copy()
            transposer.transpose(p)
            newLastPitch.transposed = p.copy()
            if p.octavecheck is not None:
                p.octavecheck = p.octave
            p.makeRelative(last)
            if relPitch:
                # we are allowed to change the pitch after the
                # \relative command. lastPitch contains this pitch.
                lastPitch.octave += p.octave
                p.octave = 0
                pitches.write(lastPitch)
                del relPitch[:]
            pitches.write(p)
            return newLastPitch

        lastPitch = None
        relPitch = [] # we use a list so it can be changed from inside functions
        
        # find the pitch after the \relative command
        t = next(tsource)
        if isinstance(t, ly.pitch.Pitch):
            lastPitch = t
            if in_selection(t):
                relPitch.append(lastPitch)
            t = next(tsource)
        elif relative_first_pitch_absolute:
            lastPitch = ly.pitch.Pitch.f0()
        else:
            lastPitch = ly.pitch.Pitch.c1()
        
        while True:
            # eat stuff like \new Staff == "bla" \new Voice \notes etc.
            if isinstance(source.state.parser(), ly.lex.lilypond.ParseTranslator):
                t = consume()
            elif isinstance(t, ly.lex.lilypond.NoteMode):
                t = next(tsource)
            else:
                break
        
        # now transpose the relative expression
        if t in ('{', '<<'):
            # Handle full music expression { ... } or << ... >>
            for t in context():
                if t == '\\octaveCheck':
                    for p in getpitches(context()):
                        lastPitch = p.copy()
                        del relPitch[:]
                        if in_selection(p):
                            transposer.transpose(p)
                            lastPitch.transposed = p
                            pitches.write(p)
                elif isinstance(t, ly.lex.lilypond.ChordStart):
                    chord = [lastPitch]
                    for p in getpitches(context()):
                        chord.append(transposeRelative(p, chord[-1]))
                    lastPitch = chord[:2][-1] # same or first
                elif isinstance(t, ly.pitch.Pitch):
                    lastPitch = transposeRelative(t, lastPitch)
        elif isinstance(t, ly.lex.lilypond.ChordStart):
            # Handle just one chord
            for p in getpitches(context()):
                lastPitch = transposeRelative(p, lastPitch)
        elif isinstance(t, ly.pitch.Pitch):
            # Handle just one pitch
            transposeRelative(t, lastPitch)

    # Do it!
    with cursor.document as document:
        absolute(tsource)

python_ly-0.9.9/ly/server/__init__.py0000644000000000000000000000170413615410400014543 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
A package implementing an HTTP server to process LilyPond input code.
"""

python_ly-0.9.9/ly/server/command.py0000644000000000000000000002110013615410400014412 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2014 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
The commands that are available to the command line.
"""

from __future__ import unicode_literals

import re
import sys

import ly

known_commands = [
    'mode',
    'version',
    'language',
    'indent',
    'reformat',
    'translate',
    'transpose',
    'rel2abs',
    'abs2rel',
    'musicxml',
    'highlight'
]

class _command(object):
    """Base class for commands.

    If the __init__() fails with TypeError or ValueError, the command is
    considered invalid and an error message will be written to the console
    in the parse_command() function in main.py.

    By default, __init__() expects no arguments. If your command does accept
    arguments, they are provided in a single argument that you should parse
    yourself.

    """
    def __init__(self):
        pass

    def run(self, opts, data):
        pass


class set_variable(_command):
    """set a configuration variable to a value"""
    def __init__(self, arg):
        self.name, self.value = arg.split('=', 1)

    def run(self, opts, data):
        opts.set_variable(self.name, self.value)


#################################
### Base classes for commands ###
#################################

# The command classes have a run() method that serves as a common structure
# for each command type.  From within run() a function is called to perform
# the actual, command-specific funcionality.
# The run() method also takes care of updating the data object with the correct
# nesting structure and metadata.
class _info_command(_command):
    """
    Base class for commands that retrieve some info about the document.
    The result is appended to the data['info'] array as a dict with 'command'
    and 'info' fields.
    """
    def run(self, opts, data):
        import ly.docinfo
        info = ly.docinfo.DocInfo(data['doc']['content'].document)
        text = self.get_info(info)
        data['info'].append({
            'command': self.__class__.__name__,
            'info': text or ""
        })

    def get_info(self, info):
        """
        Should return the desired information from the docinfo object.
        """
        raise NotImplementedError()


class _edit_command(_command):
    """
    Base class for commands that modify the input.
    The modifications overwrite the content of data['doc']['content'], so a
    subsequent edit commands builds on the modified content. The command name is
    added to the data['doc']['commands'] dict so it is possible to retrace which
    commands have been applied to the final result.
    """
    def run(self, opts, data):
        self.edit(opts, data['doc']['content'])
        data['doc']['commands'].append(self.__class__.__name__)
    
    def edit(self, opts, cursor):
        """Should edit the cursor in-place."""
        raise NotImplementedError()


class _export_command(_command):
    """
    Base class for commands that convert the input to another format.
    For each command an entry will be appended to data['exports'] field of the
    'data' dict, leaving data['doc'] untouched. Each entry in data['exports']
    has a ['doc'] and a ['command'] field, allowing the client to identify the
    
    """
    def run(self, opts, data):
        export = self.export(opts, data['doc']['content'], data['exports'])
        data['exports'].append({
            'command': self.__class__.__name__,
            'doc': export
        })
    
    def export(self, opts, cursor, exports):
        """Should return the converted document as string."""
        raise NotImplementedError()


#####################
### Info commands ###
#####################

class mode(_info_command):
    """retrieve mode from document"""
    def get_info(self, info):
        return info.mode()


class version(_info_command):
    """retrieve version from document"""
    def get_info(self, info):
        return info.version_string()


class language(_info_command):
    """retrieve language from document"""
    def get_info(self, info):
        return info.language()


#####################
### Edit commands ###
#####################

class indent(_edit_command):
    """run the indenter"""
    def indenter(self, opts):
        """Get a ly.indent.Indenter initialized with our options."""
        import ly.indent
        i = ly.indent.Indenter()
        i.indent_tabs = opts.indent_tabs
        i.indent_width = opts.indent_width
        return i
    
    def edit(self, opts, cursor):
        self.indenter(opts).indent(cursor)


class reformat(indent):
    """reformat the document"""
    def edit(self, opts, cursor):
        import ly.reformat
        ly.reformat.reformat(cursor, self.indenter(opts))


class translate(_edit_command):
    """translate pitch names"""
    def __init__(self, language):
        if language not in ly.pitch.pitchInfo:
            raise ValueError()
        self.language = language
    
    def edit(self, opts, cursor):
        import ly.pitch.translate
        try:
            changed = ly.pitch.translate.translate(cursor, self.language, opts.default_language)
        except ly.pitch.PitchNameNotAvailable as pna:
            raise ValueError(format(pna))
        if not changed:
            version = ly.docinfo.DocInfo(cursor.document).version()
            ly.pitch.translate.insert_language(cursor.document, self.language, version)
    

class transpose(_edit_command):
    """transpose music"""
    def __init__(self, arg):
        import re
        result = []
        for pitch, octave in re.findall(r"([a-z]+)([,']*)", arg):
            r = ly.pitch.pitchReader("nederlands")(pitch)
            if r:
                result.append(ly.pitch.Pitch(*r, octave=ly.pitch.octaveToNum(octave)))
        self.from_pitch, self.to_pitch = result

    def edit(self, opts, cursor):
        import ly.pitch.transpose
        transposer = ly.pitch.transpose.Transposer(self.from_pitch, self.to_pitch)
        try:
            ly.pitch.transpose.transpose(cursor, transposer, opts.default_language)
        except ly.pitch.PitchNameNotAvailable as pna:
            language = ly.docinfo.DocInfo(cursor.document).language() or opts.default_language
            raise ValueError(format(pna))


class rel2abs(_edit_command):
    """convert relative music to absolute"""
    def edit(self, opts, cursor):
        import ly.pitch.rel2abs
        ly.pitch.rel2abs.rel2abs(cursor, opts.default_language)


class abs2rel(_edit_command):
    """convert absolute music to relative"""
    def edit(self, opts, cursor):
        import ly.pitch.abs2rel
        ly.pitch.abs2rel.abs2rel(cursor, opts.default_language)


#######################
### Export commands ###
#######################

class musicxml(_export_command):
    """convert source to MusicXML"""
    def export(self, opts, cursor, exports):
        import ly.musicxml
        writer = ly.musicxml.writer()
        writer.parse_document(cursor.document)
        #TODO!!!
        # In Python3 this incorrectly escapes the \n characters,
        # but leaving out the str() conversion returns a Bytes object,
        # which will in turn trigger an "object is not JSON serializable" error
        return str(writer.musicxml().tostring())


class highlight(_export_command):
    """convert source to syntax colored HTML."""
    def export(self, opts, cursor, exports):
        import ly.colorize
        w = ly.colorize.HtmlWriter()
    
        # set configuration options
        w.full_html = opts.full_html
        w.inline_style = opts.inline_style
        w.stylesheet_ref = opts.stylesheet
        w.number_lines = opts.number_lines
        w.title = cursor.document.filename
        w.encoding = opts.output_encoding or "utf-8"
        w.wrapper_tag = opts.wrapper_tag
        w.wrapper_attribute = opts.wrapper_attribute
        w.document_id = opts.document_id
        w.linenumbers_id = opts.linenumbers_id

        return w.html(cursor)
python_ly-0.9.9/ly/server/doc.py0000644000000000000000000002350513615410400013554 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2015 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

# this module only contains a doc string, which is printed when using
# ly -h .

"""
Usage::

  ly-server [options]

An HTTP server for manipulating LilyPond input code

Server Options
==============

  -v, --version          show version number and exit
  -h, --help             show this help text and exit
  -p, --port PORT        port server listens to (default 5432)
  -t, --timeout TIME     If set, server shuts down automatically
                         after -t seconds of inactivity
                         NOT IMPLEMENTED YET!
  
Command Options
===============

  -e, --encoding ENC     (input) encoding (default UTF-8)
  --output-encoding ENC  output encoding (default to input encoding)
  -l, --language NAME    default pitch name language (default to "nederlands")
  -d     set a variable (see below)


Command options define defaults for the execution of commands triggered by HTTP
requests. These options can be overridden by the individual HTTP request.


HTTP Requests
=============

GET Requests
------------

Some GET requests will be implemented later to retrieve values
or change some server settings based on the URL path.


POST Requests
-------------

The server accepts POST requests without (currently) making use of the URL path.
As the request body it expects a single JSON string with the following elements:

  ``commands`` (mandatory)
         An array with one or more commands to be executed subsequently. 
         Each entry contains:
    
         ``command`` (mandatory): 
               A name for the command. It has to be one out of the list of
               available commands below.
        
         ``args`` (optional):
                If a command requires arguments (e.g. the ``transpose`` command)
                they are given as a single string value.

         ``variables`` (optional): 
                A dictionary of variable assignments. Keys have to be from the 
                list below, and proper value types are checked. If one or more
                variables are given they will be set *before* the command is
                executed. A variable may be modified again before the execution
                of the next command but it is not reset automatically. Giving a
                variable with a value of '' unsets the variable.

  ``options`` (optional)
         A dictionary of option assignments. Keys have to be from the above list 
         of Command Options, taking the long name without the leading hyphens, 
         e.g. ``{ "encoding": "UTF-16" }``.
         If an option is given here it overrides the default option given on the
         command line, but only for the current command.
         
  ``data`` (mandatory)
         A single string containing the LilyPond input document.

The server will try to construct a series of commands from the request, and if
anything is wrong with it send a "Bad Request" message with HTTP response code 400.

Response Object
---------------

If the commands execute successfully the response body will contain a serialized
JSON object with the following elements:

  ``info``
         An array of entries with the result of "info" commands (see below).
         Each entry has a ``command`` and an ``info`` field.
         
  ``doc``
         An object with two fields:
         
         ``content``
                A string with the content of the document with all "edit" commands applied
                consecutively. (If no edit commands have been specified this contains the
                original input.
         
         ``commands``
                An array with the names of the commands that have been applied.
  
  ``exports``
         An array with entries for each applied "export" command.
         Each entry has the following fields:
  
         ``doc``
                A string with the content of the converted/exported document
  
         ``command``
                The name of the applied command 

Commands
--------

There are three types of commands whose results are handled independently:

    - "info" commands retrieve metadata from the input document
    - "edit" commands modify the document, subsequent edit commands cascade the
      modifications
    - "export" commands that convert the input to another format.
      Subsequent commands are not affected by the result of export commands.

  
Informative commands that return information and do not change the file:

  ``mode``
         print the mode (guessing if not given) of the document
  
  ``version``
         print the LilyPond version, if set in the document

  ``language``
         print the pitch name language, if set in the document
  
Commands that modify the input:

  ``indent``
         re-indent the file
  
  ``reformat``
         reformat the file

  ``translate ``
         translate the pitch names to the language

  ``transpose  ``
         transpose the file like LilyPond would do, pitches
         are given in the 'nederlands' language

  ``abs2rel``
         convert absolute music to relative

  ``rel2abs``
         convert relative music to absolute


Commands that convert the input to another format:

  ``musicxml``
         convert to MusicXML (in development, far from complete)

  ``highlight``
         export the document as syntax colored HTML



Variables
---------

The following variables can be set to influence the behaviour of commands.
If there is a default value, it is written between brackets:

  ``mode`` 
         mode of the input to read (default automatic) can be one
         of: lilypond, scheme, latex, html, docbook, texinfo.
  
  ``encoding`` [UTF-8]
         encoding to read (also set by -e argument)

  ``default-language`` [nederlands]
         the pitch names language to use by default, when not specified
         otherwise in the document

  ``output-encoding``
         encoding to write (defaults to ``encoding``, also
         set by the ``--output-encoding`` argument)

  ``indent-tabs`` [``false``]
         whether to use tabs for indent

  ``indent-width`` [2]
         how many spaces for each indent level (if not using tabs)

  ``full-html`` [``True``]
        if set to True a full document with syntax-highlighted HTML
        will be exported, otherwise only the bare content wrapped in an
        element configured by the ``wrapper-`` variables.        

  ``stylesheet``
         filename to reference as an external stylesheet for
         syntax-highlighted HTML. This filename is literally used
         in the ```` tag.

  ``inline-style`` [``false``]
         whether to use inline style attributes for syntax-highlighted HTML.
         By default a css stylesheet is embedded.

  ``number-lines`` [``false``]
         whether to add line numbers when creating syntax-highlighted HTML.

  ``wrapper-tag`` [``pre``]
         which tag syntax highlighted HTML will be wrapped in. Possible values:
         ``div``, ``pre``, ``id`` and ``code``

  ``wrapper-attribute`` [``class``]
        attribute used for the wrapper tag. Possible values: ``id`` and ``class``.

  ``document-id`` [``lilypond``]
        name applied to the wrapper-attribute.
        If the three last options use their default settings
        the highlighted HTML elements are wrapped in an element
        ``
``

  ``linenumbers-id`` [``linenumbers``]
        if linenumbers are exported this is the name used for the ```` elements



Examples
========

Here is the basic invocation, listening on port 5432::

  ly-server

Specifying port and a timeout::

  ly-server -p 4000 -t 5000
  
Sample Requests
---------------

The simplest request, just applying one edit command. In this case the result
will be in ``result['doc']['content']``::

    {
        'commands': [
            {
                'command': 'indent'
            }
        ],
        'data' : "\\relative c' { c ( d e f ) }"
    }

Another simple request, this time applying an "info" command. The result will
be in ``result['info']``, containing ``lilypond`` in the ``info`` field and
``mode`` in the ``command`` field::

    {
        'commands': [
            {
                'command': 'mode'
            }
        ],
        'data' : "\\relative c' { c ( d e f ) }"
    }
    
And a more complex example. This will first transpose the document and then
convert the transposed version independently to highlighted HTML and MusicXML.
Additionally it will retrieve the mode. This time the result will be in all
three places: the transposed document in ``doc.content``, the mode in 
``info.info``, and HTML and MusicXML in ``exports[0].doc`` and ``exports[1].doc``.::

    {
        'commands': [
            {
                'command': 'transpose',
                'args': 'c d'
            },
            {
                'command': 'highlight',
                'variables': { 'full-html': 'false' }
            },
            { 'command': 'musicxml' },
            { 'command': 'mode' },
        ],
        'options': {
            'language': "deutsch"
        },
        'data': "\\relative c' { c4 ( d e ) }"
    }

"""
python_ly-0.9.9/ly/server/handler.py0000644000000000000000000001501213615410400014416 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2014 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
HTTP request handler
"""

from __future__ import unicode_literals
try:
    from BaseHTTPServer import BaseHTTPRequestHandler
except ImportError:
    from http.server import BaseHTTPRequestHandler

import json
import copy

# Prototype (in JavaScript sense) from which each command copies its options
default_opts = None

class RequestHandler(BaseHTTPRequestHandler):
    
    def create_command(self, cmd):
        """
        Parse one command from the JSON data, plus optionally some commands to
        set variables. Returns an array with command._command instances.
        Raises exceptions upon faulty data.
        """
        from . import command
        
        result = []
        
        # set variables before executing the command
        if 'variables' in cmd:
            for v in cmd['variables']:
                result.append(command.set_variable(
                    v + "=" + cmd['variables'][v]))
        
        # instantiate the command.
        if not 'command' in cmd:
            raise ValueError("Malformed JSON data in request body (missing 'command' field).\n" +
                            "Object:\n" + json.dumps(cmd))
        cmd_name = cmd['command'].replace('-', '_')
        if not cmd_name in command.known_commands:
            raise ValueError("unknown command: " + cmd_name)
        
        # add arguments to command if present.
        args = cmd.get('args', '')
        args = [args] if args else []
        try:
            result.append(getattr(command, cmd_name)(*args))
        except TypeError as ae:
            raise ValueError("Error creating command {cmd} with args {args}.\n{msg}".format(
                            cmd = cmd_name,
                            args = ", ".join(args),
                            msg = str(ae)))
        return result
        

    def process_options(self, opts):
        """
        Instantiate a copy of the default options and
        update with the given opts
        """
        result = copy.deepcopy(default_opts)
        for opt in opts:
            # handle special case where option name doesn't match CL interface
            if opt == 'language':
                result.set_variable('default-language', opts[opt])
            else:
                result.set_variable(opt, opts[opt])
        return result
        
        
    def process_json_request(self, request):
        """
        Configure the action(s) to be taken, based on the JSON object.
        Raise errors when the JSON object can't be properly understood.
        Run the commands and return a string (from cursor.text() ).
        """

        # set up an Options object and
        # override defaults with given options
        opts = self.process_options(request.get('options', []))
        
        # set up commands
        commands = []
        for c in request['commands']:
            commands.extend(self.create_command(c))        
        
        # create document from passed data
        import ly.document
        doc = ly.document.Document(request['data'], opts.mode)
        doc.filename = ""

        # data structure for the results
        data = {
            'doc': {
                'commands': [],
                'content': ly.document.Cursor(doc)
            },
            'info': [],
            'exports': []
        }
        
        # run commands, which modify data in-place
        for c in commands:
            c.run(opts, data)
        
        data['doc']['content'] = data['doc']['content'].text()
        return data

        
    def read_json_request(self):
        """
        Returns the message body parsed to a dictionary
        from JSON data. Raises 
        - RuntimeWarning when no JSON data is present
        - ValueError when JSON parsing fails
        """
        
        content_len = int(self.headers['content-length'])
        if content_len == 0:
            #TODO: When testing is over remove (or comment out)
            # the following two lines and raise the exception instead.
            from . import testjson
            return testjson.test_request
            raise RuntimeWarning("No JSON data in request body")
        
        req_body = self.rfile.read(content_len)
        # Python2 has string, Python3 has bytestream
        if not isinstance(req_body, str):
            req_body = req_body.decode('utf-8')

        # parse body, initial validation
        try:
            request = json.loads(req_body)
        except Exception as e:
            raise ValueError("Malformed JSON data in request body:\n" + str(e))
        if not 'commands' in request:
            raise ValueError("Malformed JSON request. Missing 'commands' property")
        if not 'data' in request:
            raise ValueError("Malformed JSON request. Missing 'data' property")
        return request


    
    ########################
    ### Request handlers ###
    ########################

    def do_POST(self):
        """
        A POST request is expected to contain the task to be executed 
        as a JSON object in the request body.
        The POST handler (currently) ignores the URL.
        """
        try:
            request = self.read_json_request()
            result = self.process_json_request(request)
        except Exception as e:
            # TODO: should we disambiguate (ValueError, RuntimeWarning, others)?
            # use HTML templates
            self.send_error(400, format(e))
            return
        
        # Send successful response
        self.send_response(200)
        self.send_header('Content-type', 'application/json')
        self.end_headers()
        res_body = json.dumps(result)
        if isinstance(res_body, str):
            res_body = res_body.encode()
        self.wfile.write(res_body)
python_ly-0.9.9/ly/server/main.py0000644000000000000000000001051513615410400013730 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2014 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
The entry point for the 'ly-server' command.
"""

from __future__ import unicode_literals
from __future__ import print_function

from http.server import HTTPServer

import copy
import sys

import ly.pkginfo
from . import options
from . import handler


def usage():
    """Print usage info."""
    from . import doc
    sys.stdout.write(doc.__doc__)


def usage_short():
    """Print short usage info."""
    sys.stdout.write("""\
Usage: ly-server [options]

An HTTP server for manipulating LilyPond input code

See ly-server -h for a full list of commands and options.
""")


def version():
    """Print version info."""
    sys.stdout.write("ly-server {0}\n".format(ly.pkginfo.version))


def die(message):
    """Exit with message to STDERR.
    In ly-server this should only be called upon startup, not while processing
    requests. Then the error should be sent back to the client."""
    sys.stderr.write("error: " + message + '\n')
    sys.stderr.write(
        "See ly-server -h for a full list of commands and options.\n")
    sys.exit(1)


def parse_command_line():
    """Returns a two-tuple(server_opts, cmd_opts)

    server_opts is a ServerOptions instance configuring the server behaviour
    cmd_opts is an Options instance with default options for future command
    executions triggered by HTTP requests.

    Also performs error handling and may exit on certain circumstances.

    """

    args = iter(sys.argv[1:])

    server_opts = options.ServerOptions()
    cmd_opts = options.Options()

    def next_arg(message):
        """Get the next argument, if missing, die with message."""
        try:
            return next(args)
        except StopIteration:
            die(message)

    for arg in args:
        if arg in ('-h', '--help'):
            usage()
            sys.exit(0)
        elif arg in ('-v', '--version'):
            version()
            sys.exit(0)

        # Server Options
        elif arg in ('-p', '--port'):
            server_opts.port = int(next_arg("missing port number"))
        elif arg in ('-t', '--timeout'):
            server_opts.timeout = int(next_arg("missing timeout (in ms)"))

        # Command Options
        elif arg in ('-e', '--encoding'):
            cmd_opts.encoding = next_arg("missing encoding name")
        elif arg == '--output-encoding':
            cmd_opts.output_encoding = next_arg("missing output encoding name")
        elif arg in ('-l', '--language'):
            s = next_arg("missing language name")
            cmd_opts.set_variable("default-language", s)

        # Command configuration Variables
        elif arg == '-d':
            s = next_arg("missing variable=value")
            try:
                name, value = s.split('=', 1)
            except ValueError:
                die("missing '=' in variable set")
            cmd_opts.set_variable(name, value)

        elif arg.startswith('-'):
            die('unknown option: ' + arg)

    return server_opts, cmd_opts


def main():
    server_opts, cmd_opts = parse_command_line()
    handler.default_opts = copy.deepcopy(cmd_opts)
    exit_code = 0
    try:
        server = HTTPServer(('', server_opts.port), handler.RequestHandler)
        print("Welcome to the python-ly HTTP server")
        print("Listening on port {port}".format(port=server_opts.port))
        server.serve_forever()
    except KeyboardInterrupt:
        print("\nKeyboard interrupt received. Shutting down server")
        server.socket.close()
        print("Successfully closed. Bye...")
    return exit_code
python_ly-0.9.9/ly/server/options.py0000644000000000000000000000454513615410400014505 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2014 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

"""
Options configuring the commands' behaviour
"""

from __future__ import unicode_literals

from ly.cli import setvar

class ServerOptions(object):
    """
    Options configuring the server itself, not the individual commands
    """
    
    def __init__(self):
        self.port = 5432
        self.timeout = 0
    

class Options(object):
    """Store all the startup options and their defaults."""
    def __init__(self):
        self.mode = None
        self.in_place = False
        self.encoding = 'UTF-8'
        self.output_encoding = None
        self.output = None
        self.replace_pattern = True
        self.backup_suffix = '~'
        self.with_filename = None
        self.default_language = "nederlands"
        
        self.indent_width = 2
        self.indent_tabs = False
        self.tab_width = 8
        
        self.full_html = True
        self.inline_style = False
        self.stylesheet = None
        self.number_lines = False
        self.wrapper_tag = 'pre'
        self.wrapper_attribute = 'class'
        self.document_id = 'lilypond'
        self.linenumbers_id = 'linenumbers'

    def set_variable(self, name, value):
        name = name.replace('-', '_')
        try:
            func = getattr(setvar, name)
        except AttributeError:
            raise AttributeError("unknown variable: {name}".format(name=name))
        try:
            value = func(value)
        except ValueError as e:
            raise ValueError(format(e))
        setattr(self, name, value)    
python_ly-0.9.9/ly/server/testjson.py0000644000000000000000000000117513615410400014657 0ustar00# test dataset for simpler handling of JSON request during testing phase

test_request = {
    'commands': [
        {
            'command': 'transpose',
            'args': 'c d'
        },
        { 'command': 'reformat' },
        {
            'command': 'highlight',
            'variables': { 'full-html': 'false' }
        },
        { 'command': 'musicxml' },
        { 'command': 'mode' },
        { 'command': 'version' }
    ],
    'options': {
        'encoding': 'UTF-16',
        'language': "deutsch"
    },
    'data': "%No JSON data supplied. This is a test request.\n" +
            "\\relative c' {\nc4 ( d e )\n}"
}
python_ly-0.9.9/ly/xml/__init__.py0000644000000000000000000000341113615410400014032 0ustar00# This file is part of python-ly, https://pypi.python.org/pypi/python-ly
#
# Copyright (c) 2008 - 2015 by Wilbert Berendsen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# See http://www.gnu.org/licenses/ for more information.

r"""
Routines that manipulate an XML mapping very similar to the Scheme music
structure used by LilyPond itself.

The mapping can also be generated from within LilyPond and then parsed
by other programs.

While designing the mapping, I decided to use xml elements for almost
everything, only values that are very simple in all cases, are attributes.

Code could be written to convert such an XML music tree to other formats.

Also code is added to build such trees from scratch and from tokenized
documents.

Code will be added to print LilyPond source. When all is finished, `ly.dom`
is deprecated and `ly.music` will probably use these xml tree for storage.

A single LilyPond file `xml-export.ily` is also included with this module;
it can be \included in a LilyPond document and exports the
``\displayLilyXML`` music function.

"""

from __future__ import unicode_literals
from __future__ import absolute_import
python_ly-0.9.9/ly/xml/xml-export-init.ly0000644000000000000000000000402013615410400015344 0ustar00%{

This script is intended to be used via the --init option. It automatically converts
every \book in the score to an XML document (LilyPond always creates at least one book).
In this case the XML is also written to standard output, but you can specify another file
with -dxml-export=.

So, to convert a LilyPond source file to an XML file containing the LilyPond music
structure in XML format, use the following command:

  lilypond --init /path/to/xml-export-init.ly -dxml-export=song.xml song.ly

The XML document has a  root element, containing a  element for every book
in the LilyPond file.

%}

%% find our companion script, but leave the old setting of relative-includes
#(define old-option-relative-includes (ly:get-option 'relative-includes))
#(ly:set-option 'relative-includes #t)
\include "xml-export.ily"
#(ly:set-option 'relative-includes old-option-relative-includes)

%% make a toplevel book handler
#(define (make-toplevel-book-handler->xml xml)
   "Return a book handler that dumps a book to specified XML instance"
   (lambda (parser book)
     (obj->lily-xml book xml)))

%% create the XML output instance (in the toplevel scope)
#(begin
  (define xml-outputter #f)
  (let* ((x (ly:get-option 'xml-export))
         (xml-file (if x (symbol->string x) "-"))
         (port (if (string=? xml-file "-")
                   (current-output-port)
                   (open-output-file xml-file)))
         (xml (XML port)))
    (ly:message
     (format "Writing XML to ~a..."
       (if (string=? xml-file "-")
           "standard output"
           xml-file)))
    (set! xml-outputter xml)))

%% create the output document and run the normal init procedure
#(xml-outputter 'declaration)
#(xml-outputter 'open-tag 'document)
%% HACK, overwrite print-book-with-defaults, because toplevel-book-handler
%% is overwritten by the declarations-init.ly script.
#(define print-book-with-defaults (make-toplevel-book-handler->xml xml-outputter))
\include "init.ly"
#(xml-outputter 'close-tag)
#(ly:message "Writing XML completed.")
python_ly-0.9.9/ly/xml/xml-export.dtd0000644000000000000000000000444113615410400014541 0ustar00






































































python_ly-0.9.9/ly/xml/xml-export.ily0000644000000000000000000003734213615410400014571 0ustar00\version "2.18.2"
%{


xml-export.ily

Written by Wilbert Berendsen, jan-feb 2015


This LilyPond module defines a function (xml-export) that converts LilyPond
datastructures to XML. For convenience, a \displayLilyXML music function is
added that converts a music expression to XML.

Usage e.g.:

  \include "/path/to/xml-export.ily"
  \displayLilyXML { c d e f }

The XML closely follows the LilyPond music structure.

All (make-music 'MusicName ...) objects translate to a 
tag. The music in the 'element and 'elements properties is put in the 
and  tags. (LilyPond uses 'element when there is a single music
argument, and 'elements for a list of music arguments, but for example \repeat
uses both: 'element for the repeated music and 'elements for the \alternatives.)

Thus , if there, always has one  child. , if there,
can have more than one  child.

Besides 'element and 'elements, the following properties of music objects are
handled specially:

- 'origin =>  element with filename, line and char attributes
- 'pitch =>  element with octave, notename and alteration attributes
- 'duration =>  element with log, dots, numer and denom attributes
- 'articulations =>  element containing  elements
- 'tweaks =>  element containing pairs (symbol . value)

All other properties a music object may have, are translated to a 
element with a name attribute. The value is the child element and can be any
object (string, list, pair, symbol, number etc.). (Note that the LilyPond
command \displayMusic does not display all properties.)

Markup objects are also converted to XML, where a toplevel  element
is used. The individual markup commands are converted to an  element, with
the name in the name attribute (e.g. ). Arguments to markup commands may be other commands, or other
objects (markup \score even has a score argument, which is also supported).


Example:

This LilyPond music:

  \relative {
    c d e
  }

maps to Scheme (using \displayMusic):

  (make-music
    'RelativeOctaveMusic
    'element
    (make-music
      'SequentialMusic
      'elements
      (list (make-music
              'NoteEvent
              'pitch
              (ly:make-pitch -1 0 0)
              'duration
              (ly:make-duration 2 0 1))
            (make-music
              'NoteEvent
              'pitch
              (ly:make-pitch -1 1 0)
              'duration
              (ly:make-duration 2 0 1))
            (make-music
              'NoteEvent
              'pitch
              (ly:make-pitch -1 2 0)
              'duration
              (ly:make-duration 2 0 1)))))

and maps to XML (using \displayLilyXML):

  
    
    
      
        
        
          
            
            
            
          
          
            
            
            
          
          
            
            
            
          
        
      
    
  

To automatically export a full LilyPond document to an XML representation,
use the xml-export-init.ly script with the --init LilyPond option. That script
automatically sets up LilyPond to output one XML document with a 
root element, containing a  element for every book in the LilyPond file.
(LilyPond always creates at least one book, collecting all the music or markup
at the toplevel.)

%}

% convert an assoc list to an xml attribute string (joined with a space in between)
#(define (attrs->string attrs)
   (string-join
    (map (lambda (e)
           (attr->string (car e) (cdr e))) attrs)
    " " 'prefix))

% convert a name value pair to an xml attribute
% name is a symbol, value can be a symbol, string, or number
#(define (attr->string name value)
   (string-append (symbol->string name)
     "=\""
     (cond
      ((string? value) (attribute-escape value))
      ((number? value) (number->string value))
      ((symbol? value) (attribute-escape (symbol->string value))))
     "\""))

% escape string for xml body
#(define (xml-escape s)
   (ly:string-substitute "<" "<"
     (ly:string-substitute ">" ">"
       (ly:string-substitute "\"" """
         (ly:string-substitute "&" "&"
           s)))))

% escape string for xml attribute
#(define (attribute-escape s)
   (ly:string-substitute "\n" "
"
     (ly:string-substitute "\"" """
       (ly:string-substitute "&" "&"
         s))))


% a nice class that outputs an XML document
% (define x (XML port)  ;; port is optional
% (x 'open-tag 'name attrs)
% (x 'open-close-tag 'name attrs)
% (x 'close-tag)
% when an open tag is closed and it has no child tags, it is automatically
% written to output as an open-close tag.
#(define XML
   (lambda args
     (define indent-width 2)
     (define pending #f)
     (define tags '())
     (define port (if (pair? args) (car args) (current-output-port)))

     (define (output-xml-tag indent tag-name attrs text how)
       "output an XML tag.
           indent: number of spaces before it
           tag-name: symbol
           attrs: assoc list
           text: text between open and close tag (how must be 'text-tag)
           how can be:
            'open-tag:       write an open-tag with attributes 
            'close-tag:      write a close-tag (attrs are ignored) 
            'open-close-tag: write a self-closing tag 
            'text-tag:       write a open and close tag with text text
       "
       (let ((s (string-append
                 (make-string (* indent indent-width) #\space)
                 "<"
                 (if (eq? how 'close-tag) "/" "")
                 (symbol->string tag-name)
                 (if (eq? how 'close-tag) "" (attrs->string attrs))
                 (if (eq? how 'open-close-tag) "/" "")
                 ">"
                 (if (eq? how 'text-tag)
                     (string-append (xml-escape text) "string tag-name) ">")
                     "")
                 "\n")))
         (display s port)))
     
     (define (output-last-tag how)
       "output the last tag on the tags stack."
       (let ((indent (1- (length tags)))
             (args (car tags)))
         (apply (lambda (tag-name attrs)
                  (output-xml-tag indent tag-name attrs "" how))
           args)))

     (define (declaration)
       "output an XML declaration."
       (display "\n" port))

     (define (open-tag tag-name attrs)
       "implementation of open-tag method."
       (if pending
           (output-last-tag 'open-tag))
       (set! tags (cons (list tag-name attrs) tags))
       (set! pending #t))

     (define (close-tag)
       "implementation of close-tag method."
       (if pending
           (output-last-tag 'open-close-tag)
           (output-last-tag 'close-tag))
       (set! pending #f)
       (set! tags (cdr tags)))

     (define (text-tag tag-name text attrs)
       "implementation of text-tag method."
       (if pending
           (output-last-tag 'open-tag))
       (output-xml-tag (length tags) tag-name attrs text 'text-tag)
       (set! pending #f))

     (lambda (method-name . args)
       "call a method. 
          'declaration
          'open-tag tag-name [attrs]
          'close-tag
          'open-close-tag tag-name [attrs]
          'text-tag tag-name text [attrs]
      "
       (let* ((l (length args))
              (tag-name (if (> l 0) (list-ref args 0)))
              (text (if (and (> l 1) (string? (list-ref args 1))) (list-ref args 1) ""))
              (attrs (if (and (> l 1) (list? (list-ref args (1- l)))) (list-ref args (1- l)) '())))
         (case method-name
           ((declaration) (declaration))
           ((open-tag) (open-tag tag-name attrs))
           ((close-tag) (close-tag))
           ((open-close-tag) (open-tag tag-name attrs) (close-tag))
           ((text-tag) (text-tag tag-name text attrs)))))))


% convert a markup object to XML
#(define (markup->lily-xml mkup xml)

   (define (cmd-name proc)
     "return the name of the markup procedure"
     (symbol->string (procedure-name proc)))

   (define (mkuparg->xml arg)
     "convert markup arguments to xml"
     (cond
      ((markup-list? arg) ;; markup list
        (for-each mkup->xml arg))
      ((markup? arg) ;; markup
        (mkup->xml arg))
      (else ;; can be another scheme object
        (obj->lily-xml arg xml))))

   (define (mkup->xml mkup)
     "convert a markup object to xml"
     (if (string? mkup)
         (xml 'text-tag 'string mkup)
         (begin
          (xml 'open-tag 'm `((name . ,(cmd-name (car mkup)))))
          (for-each mkuparg->xml (cdr mkup))
          (xml 'close-tag))))

   ;; wrap markup in a toplevel  tag
   (xml 'open-tag 'markup)
   (mkuparg->xml mkup)
   (xml 'close-tag))


% convert a header to XML
#(define (header->lily-xml header xml)
   (if (module? header)
       (let ((variables
              (filter (lambda (v)
                        (not (eq? (car v) '%module-public-interface))) (ly:module->alist header))))
         (if (pair? variables)
             (begin
              (xml 'open-tag 'header)
              (for-each (lambda (v)
                          (xml 'open-tag 'variable `((name . ,(car v))))
                          (obj->lily-xml (cdr v) xml)
                          (xml 'close-tag)) variables)
              (xml 'close-tag))))))


% convert any object to XML
% currently the xml is just (display)ed but later it will be written to a file or string.
% xml is an XML instance
#(define (obj->lily-xml o xml)
   (cond
    ((ly:music? o)
     (let ((name (ly:music-property o 'name))
           (e (ly:music-property o 'element))
           (es (ly:music-property o 'elements))
           (as (ly:music-property o 'articulations))
           (tw (ly:music-property o 'tweaks))
           (location (ly:music-property o 'origin))
           (pitch (ly:music-property o 'pitch))
           (duration (ly:music-property o 'duration))
           (properties
            (filter
             (lambda (prop)
               (not (memq (car prop)
                      '(name element elements articulations tweaks origin pitch duration))))
             (ly:music-mutable-properties o)))
           )
       (xml 'open-tag 'music `((name . ,name)))
       (if (ly:input-location? location)
           (obj->lily-xml location xml))
       (if (ly:pitch? pitch)
           (obj->lily-xml pitch xml))
       (if (ly:duration? duration)
           (obj->lily-xml duration xml))
       (if (ly:music? e)
           (begin
            (xml 'open-tag 'element)
            (obj->lily-xml e xml)
            (xml 'close-tag)))
       (if (and (list? es) (not (null? es)))
           (begin
            (xml 'open-tag 'elements)
            (for-each (lambda (e)
                        (obj->lily-xml e xml)) es)
            (xml 'close-tag 'elements)))
       (if (and (list? as) (not (null? as)))
           (begin
            (xml 'open-tag 'articulations)
            (for-each (lambda (e)
                        (obj->lily-xml e xml)) as)
            (xml 'close-tag 'articulations )))
       (if (and (list? tw) (not (null? tw)))
           (begin
            (xml 'open-tag 'tweaks)
            (for-each (lambda (e)
                        (obj->lily-xml e xml)) tw)
            (xml 'close-tag 'tweaks)))
       (for-each (lambda (prop)
                   (xml 'open-tag 'property `((name . ,(car prop))))
                   (obj->lily-xml (cdr prop) xml)
                   (xml 'close-tag)) properties)
       (xml 'close-tag)))

    ((ly:moment? o)
     (xml 'open-close-tag 'moment
       `((main-numer . ,(ly:moment-main-numerator o))
         (main-denom . ,(ly:moment-main-denominator o))
         (grace-numer . ,(ly:moment-grace-numerator o))
         (grace-denom . ,(ly:moment-grace-denominator o)))))
    ((ly:input-location? o)
     (let ((origin (ly:input-file-line-char-column o)))
       (xml 'open-close-tag 'origin
         `((filename . ,(car origin))
           (line     . ,(cadr origin))
           (char     . ,(caddr origin))))))
    ((ly:pitch? o)
     (xml 'open-close-tag 'pitch
       `((octave . ,(ly:pitch-octave o))
         (notename . ,(ly:pitch-notename o))
         (alteration . ,(ly:pitch-alteration o)))))
    ((ly:duration? o)
     (xml 'open-close-tag 'duration
       `((log . ,(ly:duration-log o))
         (dots . ,(ly:duration-dot-count o))
         (numer . ,(car (ly:duration-factor o)))
         (denom . ,(cdr (ly:duration-factor o))))))
    ((markup-list? o)
     (markup->lily-xml o xml))
    ((and (markup? o) (not (string? o)))
     (markup->lily-xml o xml))
    ((number? o)
     (xml 'text-tag 'number (number->string o)))
    ((string? o)
     (xml 'text-tag 'string o))
    ((char? o)
     (xml 'text-tag 'char (string o)))
    ((boolean? o)
     (xml 'text-tag 'boolean (if o "true" "false")))
    ((symbol? o)
     (xml 'text-tag 'symbol (symbol->string o)))
    ((null? o)
     (xml 'open-close-tag 'null)) ; or  ??
    ((list? o)
     (begin
      (xml 'open-tag 'list)
      (for-each (lambda (e)
                  (obj->lily-xml e xml)) o)
      (xml 'close-tag)))
    ((pair? o)
     (begin
      (xml 'open-tag 'pair)
      (obj->lily-xml (car o) xml)
      (obj->lily-xml (cdr o) xml)
      (xml 'close-tag)))
    ((procedure? o)
     (let* ((name (procedure-name o))
            (attrs (if name `((name . ,name)) '()))
            (source (procedure-source o)))
       (xml 'open-tag 'procedure attrs)
       (if source
           (begin
            (xml 'open-tag 'procedure-source)
            (obj->lily-xml source xml)
            (xml 'close-tag)))
       (xml 'close-tag)))
    ((ly:stencil? o)
     (begin
      (xml 'open-tag 'stencil
        `((x-min . ,(car (ly:stencil-extent o X)))
          (x-max . ,(cdr (ly:stencil-extent o X)))
          (y-min . ,(car (ly:stencil-extent o Y)))
          (y-max . ,(cdr (ly:stencil-extent o Y)))))
      (obj->lily-xml (ly:stencil-expr o) xml)
      (xml 'close-tag)))
    ((ly:score? o)
     (begin
      (xml 'open-tag 'score)
      (header->lily-xml (ly:score-header o) xml)
      (obj->lily-xml (ly:score-music o) xml)
      (xml 'close-tag)))
    ((ly:book? o)
     (begin
      (xml 'open-tag 'book)
      (header->lily-xml (ly:book-header o) xml)
      (for-each (lambda (book)
                  (obj->lily-xml book xml))
        (reverse (ly:book-book-parts o)))
      (for-each (lambda (score)
                  (obj->lily-xml score xml))
        (reverse (ly:book-scores o)))
      (xml 'close-tag)))

    ))


#(define-public (xml-export obj)
   "Dump an XML representation of the specified object to the current output port."
   (let ((xml (XML)))
     (xml 'declaration)
     (obj->lily-xml obj xml)))


displayLilyXML = #
(define-music-function (parser location music) (ly:music?)
  "Dump an XML representation of the music to the current output port."
  (xml-export music)
  music)


python_ly-0.9.9/tests/__init__.py0000644000000000000000000000000013615410400013737 0ustar00python_ly-0.9.9/tests/musicxml.xsd0000644000000000000000000110301413615410400014221 0ustar00

	
		MusicXMLβ„’ W3C XML schema (XSD)

Version 3.0

Copyright Β© 2004-2011 MakeMusic, Inc.
http://www.makemusic.com/

This MusicXMLβ„’ work is being provided by the copyright holder under the MusicXML Public License Version 3.0, available from:

	http://www.musicxml.org/dtds/license.html
	
This is the W3C XML Schema (XSD) version of the MusicXML 3.0 language. Validation is tightened by moving MusicXML definitions from comments into schema data types and definitions. Character entities and other entity usages that are not supported in W3C XML Schema have been removed. The features of W3C XML Schema make it easier to define variations of the MusicXML format, either via extension or restriction.

This file defines the MusicXML 3.0 XSD, including the score-partwise and score-timewise document elements.
	

	
		The MusicXML 3.0 DTD has no namespace, so for compatibility the MusicXML 3.0 XSD has no namespace either. Those who need to import the MusicXML XSD into another schema are advised to create a new version that uses "http://www.musicxml.org/xsd/MusicXML" as the namespace.
	
	
	

	

	
		
			The above-below type is used to indicate whether one element appears above or below another element.
		
		
			
			
		
	
	
	
		
			The MusicXML format supports six levels of beaming, up to 1024th notes. Unlike the number-level type, the beam-level type identifies concurrent beams in a beam group. It does not distinguish overlapping beams such as grace notes within regular notes, or beams used in different voices.
		
		
			
			
		
	
	
	
		
			The color type indicates the color of an element. Color may be represented as hexadecimal RGB triples, as in HTML, or as hexadecimal ARGB tuples, with the A indicating alpha of transparency. An alpha value of 00 is totally transparent; FF is totally opaque. If RGB is used, the A value is assumed to be FF. 

For instance, the RGB value "#800080" represents purple. An ARGB value of "#40800080" would be a transparent purple.

As in SVG 1.1, colors are defined in terms of the sRGB color space (IEC 61966).
		
		
			
		
	
	
	
		
			The comma-separated-text type is used to specify a comma-separated list of text elements, as is used by the font-family attribute.
		
		
			
		
	
	
	
		
			The css-font-size type includes the CSS font sizes used as an alternative to a numeric point size.
		
		
			
			
			
			
			
			
			
		
	

	
		
			The divisions type is used to express values in terms of the musical divisions defined by the divisions element. It is preferred that these be integer values both for MIDI interoperability and to avoid roundoff errors.
		
		
	
	
	
		
			The enclosure-shape type describes the shape and presence / absence of an enclosure around text or symbols. A bracket enclosure is similar to a rectangle with the bottom line missing, as is common in jazz notation.
		
		
			
			
			
			
			
			
			
			
		
	
	
	
		
			The fermata-shape type represents the shape of the fermata sign. The empty value is equivalent to the normal value.
		
		
			
			
			
			
		
	
	
	
		
			The font-size can be one of the CSS font sizes or a numeric point size.
		
		
	
	
	
		
			The font-style type represents a simplified version of the CSS font-style property.
		
		
			
			
		
	
	
	
		
			The font-weight type represents a simplified version of the CSS font-weight property.
		
		
			
			
		
	
	
	
		
			The left-center-right type is used to define horizontal alignment and text justification.
		
		
			
			
			
		
	
	
	
		
			The left-right type is used to indicate whether one element appears to the left or the right of another element.
		
		
			
			
		
	
	
	
		
			The line-shape type distinguishes between straight and curved lines.
		
		
			
			
		
	
	
	
		
			The line-type type distinguishes between solid, dashed, dotted, and wavy lines.
		
		
			
			
			
			
		
	
	
	
		
			The midi-16 type is used to express MIDI 1.0 values that range from 1 to 16.
		
		
			
			
		
	
	
	
		
			The midi-16 type is used to express MIDI 1.0 values that range from 1 to 128.
		
		
			
			
		
	
	
	
		
			The midi-16 type is used to express MIDI 1.0 values that range from 1 to 16,384.
		
		
			
			
		
	
	
	
		
			The mute type represents muting for different instruments, including brass, winds, and strings. The on and off values are used for undifferentiated mutes. The remaining values represent specific mutes.
		
		
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
		
			The non-negative-decimal type specifies a non-negative decimal value.
		
		
			
		
	
	
	
		
			Slurs, tuplets, and many other features can be concurrent and overlapping within a single musical part. The number-level type distinguishes up to six concurrent objects of the same type. A reading program should be prepared to handle cases where the number-levels stop in an arbitrary order. Different numbers are needed when the features overlap in MusicXML document order. When a number-level value is implied, the value is 1 by default.
		
		
			
			
		
	
	
	
		
			The number-of-lines type is used to specify the number of lines in text decoration attributes.
		
		
			
			
		
	
	
	
		
			The number-or-normal values can be either a decimal number or the string "normal". This is used by the line-height and letter-spacing attributes.
		
		
			
				
					
				
			
		
	
	
	
		
			The over-under type is used to indicate whether the tips of curved lines such as slurs and ties are overhand (tips down) or underhand (tips up).
		
		
			
			
		
	
	
	
		
			The percent type specifies a percentage from 0 to 100.
		
		
			
			
		
	
	
	
		
			The positive-decimal type specifies a positive decimal value.
		
		
			
		
	
	
	
		
			The positive-divisions type restricts divisions values to positive numbers.
		
		
			
		
	
	
	
		
			The positive-integer-or-empty values can be either a positive integer or an empty string.
		
		
			
				
					
				
			
		
	
	
	
		
			The rotation-degrees type specifies rotation, pan, and elevation values in degrees. Values range from -180 to 180.
		
		
			
			
		
	
	
	
		
			The semi-pitched type represents categories of indefinite pitch for percussion instruments.
		
		
			
			
			
			
			
			
		
	
	
	
		
			The start-note type describes the starting note of trills and mordents for playback, relative to the current note.
		
		
			
			
			
		
	
	
	
		
			The start-stop type is used for an attribute of musical elements that can either start or stop, such as tuplets.
									
The values of start and stop refer to how an element appears in musical score order, not in MusicXML document order. An element with a stop attribute may precede the corresponding element with a start attribute within a MusicXML document. This is particularly common in multi-staff music. For example, the stopping point for a tuplet may appear in staff 1 before the starting point for the tuplet appears in staff 2 later in the document.
		
		
			
			
		
	

	
		
			The start-stop-continue type is used for an attribute of musical elements that can either start or stop, but also need to refer to an intermediate point in the symbol, as for complex slurs or for formatting of symbols across system breaks.
						
The values of start, stop, and continue refer to how an element appears in musical score order, not in MusicXML document order. An element with a stop attribute may precede the corresponding element with a start attribute within a MusicXML document. This is particularly common in multi-staff music. For example, the stopping point for a slur may appear in staff 1 before the starting point for the slur appears in staff 2 later in the document.
		
		
			
			
			
		
	

	
		
			The start-stop-single type is used for an attribute of musical elements that can be used for either multi-note or single-note musical elements, as for tremolos.
		
		
			
			
			
		
	
	
	
		
			The string-number type indicates a string number. Strings are numbered from high to low, with 1 being the highest pitched string.
		
		
	

	
		
			The symbol-size type is used to indicate full vs. cue-sized vs. oversized symbols. The large value for oversized symbols was added in version 1.1.
		
		
			
			
			
		
	

	
		
			The tenths type is a number representing tenths of interline staff space (positive or negative). Both integer and decimal values are allowed, such as 5 for a half space and 2.5 for a quarter space. Interline space is measured from the middle of a staff line.

Distances in a MusicXML file are measured in tenths of staff space. Tenths are then scaled to millimeters within the scaling element, used in the defaults element at the start of a score. Individual staves can apply a scaling factor to adjust staff size. When a MusicXML element or attribute refers to tenths, it means the global tenths defined by the scaling element, not the local tenths as adjusted by the staff-size element.
		
		
	

	
		
			The text-direction type is used to adjust and override the Unicode bidirectional text algorithm, similar to the W3C Internationalization Tag Set recommendation. Values are ltr (left-to-right embed), rtl (right-to-left embed), lro (left-to-right bidi-override), and rlo (right-to-left bidi-override). The default value is ltr. This type is typically used by applications that store text in left-to-right visual order rather than logical order. Such applications can use the lro value to better communicate with other applications that more fully support bidirectional text.
		
		
			
			
			
			
		
	

	
		
			The time-only type is used to indicate that a particular playback-related element only applies particular times through a repeated section. The value is a comma-separated list of positive integers arranged in ascending order, indicating which times through the repeated section that the element applies.
		
		
			
		
	

	
		
			The top-bottom type is used to indicate the top or bottom part of a vertical shape like non-arpeggiate.
		
		
			
			
		
	
	
	
		
			The trill-beats type specifies the beats used in a trill-sound or bend-sound attribute group. It is a decimal value with a minimum value of 2.
		
		
			
		
	
	
	
		
			The trill-step type describes the alternating note of trills and mordents for playback, relative to the current note.
		
		
			
			
			
		
	
	
	
		
			The two-note-turn type describes the ending notes of trills and mordents for playback, relative to the current note.
		
		
			
			
			
		
	
	
	
		
			The up-down type is used for the direction of arrows and other pointed symbols like vertical accents, indicating which way the tip is pointing.
		
		
			
			
		
	

	
		
			The upright-inverted type describes the appearance of a fermata element. The value is upright if not specified.
		
		
			
			
		
	
	
	
		
			The valign type is used to indicate vertical alignment to the top, middle, bottom, or baseline of the text. Defaults are implementation-dependent.
		
		
			
			
			
			
		
	
	
	
		
			The valign-image type is used to indicate vertical alignment for images and graphics, so it does not include a baseline value. Defaults are implementation-dependent.
		
		
			
			
			
		
	
	
	
		
			The yes-no type is used for boolean-like attributes. We cannot use W3C XML Schema booleans due to their restrictions on expression of boolean values.
		
		
			
			
		
	

	
		
			The yes-no-number type is used for attributes that can be either boolean or numeric values.
		
		
	

	
		
			Calendar dates are represented yyyy-mm-dd format, following ISO 8601. This is a W3C XML Schema date type, but without the optional timezone data.
		
		
			
		
	
	
	
	
	
		
			The cancel-location type is used to indicate where a key signature cancellation appears relative to a new key signature: to the left, to the right, or before the barline and to the left. It is left by default. For mid-measure key elements, a cancel-location of before-barline should be treated like a cancel-location of left.
		
		
			
			
			
		
	
	
	
		
			The clef-sign element represents the different clef symbols. The jianpu sign indicates that the music that follows should be in jianpu numbered notation, just as the TAB sign indicates that the music that follows should be in tablature notation. Unlike TAB, a jianpu sign does not correspond to a visual clef notation.
		
		
			
			
			
			
			
			
			
		
	
	
	
		
			The fifths type represents the number of flats or sharps in a traditional key signature. Negative numbers are used for flats and positive numbers for sharps, reflecting the key's placement within the circle of fifths (hence the type name).
		
		
	
	
	
		
			The mode type is used to specify major/minor and other mode distinctions. Valid mode values include major, minor, dorian, phrygian, lydian, mixolydian, aeolian, ionian, locrian, and none.
		
		
	
	
	
		
			The show-frets type indicates whether to show tablature frets as numbers (0, 1, 2) or letters (a, b, c). The default choice is numbers.
		
		
			
			
		
	
	
	
		
			The staff-line type indicates the line on a given staff. Staff lines are numbered from bottom to top, with 1 being the bottom line on a staff. Staff line values can be used to specify positions outside the staff, such as a C clef positioned in the middle of a grand staff.
		
		
	
	
	
		
			The staff-number type indicates staff numbers within a multi-staff part. Staves are numbered from top to bottom, with 1 being the top staff on a part.
		
		
	
	
	
		
			The staff-type value can be ossia, cue, editorial, regular, or alternate. An alternate staff indicates one that shares the same musical data as the prior staff, but displayed differently (e.g., treble and bass clef, standard notation and tab).
		
		
			
			
			
			
			
		
	
	
	
		
			The time-relation type indicates the symbol used to represent the interchangeable aspect of dual time signatures.
		
		
			
			
			
			
			
			
		
	
	
	
		
			The time-separator type indicates how to display the arrangement between the beats and beat-type values in a time signature. The default value is none. The horizontal, diagonal, and vertical values represent horizontal, diagonal lower-left to upper-right, and vertical lines respectively. For these values, the beats and beat-type values are arranged on either side of the separator line. The none value represents no separator with the beats and beat-type arranged vertically. The adjacent value represents no separator with the beats and beat-type arranged horizontally.
		
		
			
			
			
			
			
		
	
	
	
		
			The time-symbol type indicates how to display a time signature. The normal value is the usual fractional display, and is the implied symbol type if none is specified. Other options are the common and cut time symbols, as well as a single number with an implied denominator. The note symbol indicates that the beat-type should be represented with the corresponding downstem note rather than a number. The dotted-note symbol indicates that the beat-type should be represented with a dotted downstem note that corresponds to three times the beat-type value, and a numerator that is one third the beats value.
		
		
			
			
			
			
			
			
		
	
	
	
	
	
		
			The backward-forward type is used to specify repeat directions. The start of the repeat has a forward direction while the end of the repeat has a backward direction.
		
		
			
			
		
	
	
	
		
			The bar-style type represents barline style information. Choices are regular, dotted, dashed, heavy, light-light, light-heavy, heavy-light, heavy-heavy, tick (a short stroke through the top line), short (a partial barline between the 2nd and 4th lines), and none.
		
		
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
		
			The ending-number type is used to specify either a comma-separated list of positive integers without leading zeros, or a string of zero or more spaces. It is used for the number attribute of the ending element. The zero or more spaces version is used when software knows that an ending is present, but cannot determine the type of the ending.
		
		
			
		
	
	
	
		
			The right-left-middle type is used to specify barline location.
		
		
			
			
			
		
	
	
	
		
			The start-stop-discontinue type is used to specify ending types. Typically, the start type is associated with the left barline of the first measure in an ending. The stop and discontinue types are associated with the right barline of the last measure in an ending. Stop is used when the ending mark concludes with a downward jog, as is typical for first endings. Discontinue is used when there is no downward jog, as is typical for second endings that do not conclude a piece.
		
		
			
			
			
		
	
	
	
		
			The winged attribute indicates whether the repeat has winged extensions that appear above and below the barline. The straight and curved values represent single wings, while the double-straight and double-curved values represent double wings. The none value indicates no wings and is the default.
		
		
			
			
			
			
			
		
	


	
	
		
			The accordion-middle type may have values of 1, 2, or 3, corresponding to having 1 to 3 dots in the middle section of the accordion registration symbol.
		
		
			
			
		
	
	
	
		
			The beater-value type represents pictograms for beaters, mallets, and sticks that do not have different materials represented in the pictogram. The finger and hammer values are in addition to Stone's list.
		
		
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
		
			The degree-symbol-value type indicates indicates that a symbol should be used in specifying the degree.
		
		
			
			
			
			
			
		
	
	
	
		
			The degree-type-value type indicates whether the current degree element is an addition, alteration, or subtraction to the kind of the current chord in the harmony element.
		
		
			
			
			
		
	
	
	
		
			The effect type represents pictograms for sound effect percussion instruments. The cannon value is in addition to Stone's list.
		
		
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
		
			The glass type represents pictograms for glass percussion instruments.
		
		
			
		
	
	
	
		
			The harmony-type type differentiates different types of harmonies when alternate harmonies are possible. Explicit harmonies have all note present in the music; implied have some notes missing but implied; alternate represents alternate analyses.
		
		
			
			
			
		
	
	
	
		
			A kind-value indicates the type of chord. Degree elements can then add, subtract, or alter from these starting points. Values include:
	
Triads:
	major (major third, perfect fifth)
	minor (minor third, perfect fifth)
	augmented (major third, augmented fifth)
	diminished (minor third, diminished fifth)
Sevenths:
	dominant (major triad, minor seventh)
	major-seventh (major triad, major seventh)
	minor-seventh (minor triad, minor seventh)
	diminished-seventh (diminished triad, diminished seventh)
	augmented-seventh (augmented triad, minor seventh)
	half-diminished (diminished triad, minor seventh)
	major-minor (minor triad, major seventh)
Sixths:
	major-sixth (major triad, added sixth)
	minor-sixth (minor triad, added sixth)
Ninths:
	dominant-ninth (dominant-seventh, major ninth)
	major-ninth (major-seventh, major ninth)
	minor-ninth (minor-seventh, major ninth)
11ths (usually as the basis for alteration):
	dominant-11th (dominant-ninth, perfect 11th)
	major-11th (major-ninth, perfect 11th)
	minor-11th (minor-ninth, perfect 11th)
13ths (usually as the basis for alteration):
	dominant-13th (dominant-11th, major 13th)
	major-13th (major-11th, major 13th)
	minor-13th (minor-11th, major 13th)
Suspended:
	suspended-second (major second, perfect fifth)
	suspended-fourth (perfect fourth, perfect fifth)
Functional sixths:
	Neapolitan
	Italian
	French
	German
Other:
	pedal (pedal-point bass)
	power (perfect fifth)
	Tristan
	
The "other" kind is used when the harmony is entirely composed of add elements. The "none" kind is used to explicitly encode absence of chords or functional harmony.
		
		
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
		
			The line-end type specifies if there is a jog up or down (or both), an arrow, or nothing at the start or end of a bracket.
		
		
			
			
			
			
			
		
	
	
	
		
			The measure-numbering-value type describes how measure numbers are displayed on this part: no numbers, numbers every measure, or numbers every system.
		
		
			
			
			
		
	
	
	
		
			The membrane type represents pictograms for membrane percussion instruments. The goblet drum value is in addition to Stone's list.
		
		
			
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
		
			The metal type represents pictograms for metal percussion instruments. The hi-hat value refers to a pictogram like Stone's high-hat cymbals but without the long vertical line at the bottom.
		
		
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
		
			The on-off type is used for notation elements such as string mutes.
		
		
			
			
		
	
	
	
		
			The pitched type represents pictograms for pitched percussion instruments. The chimes and tubular chimes values distinguish the single-line and double-line versions of the pictogram. The mallet value is in addition to Stone's list.
		
		
			
			
			
			
			
			
			
		
	
	
	
		
			The principal-voice-symbol type represents the type of symbol used to indicate the start of a principal or secondary voice. The "plain" value represents a plain square bracket. The value of "none" is used for analysis markup when the principal-voice element does not have a corresponding appearance in the score.
		
		
			
			
			
			
		
	
	
	
		
			The start-stop-change-continue type is used to distinguish types of pedal directions.
		
		
			
			
			
			
		
	
	
	
		
			The tip-direction type represents the direction in which the tip of a stick or beater points, using Unicode arrow terminology.
		
		
			
			
			
			
			
			
			
			
		
	
	
	
		
			The stick-location type represents pictograms for the location of sticks, beaters, or mallets on cymbals, gongs, drums, and other instruments.
		
		
			
			
			
			
		
	
	
	
		
			The stick-material type represents the material being displayed in a stick pictogram.
		
		
			
			
			
			
			
		
	
	
	
		
			The stick-type type represents the shape of pictograms where the material
	in the stick, mallet, or beater is represented in the pictogram.
		
		
			
			
			
			
			
		
	
	
	
		
			The up-down-stop-continue type is used for octave-shift elements, indicating the direction of the shift from their true pitched values because of printing difficulty.
		
		
			
			
			
			
		
	
	
	
		
			The wedge type is crescendo for the start of a wedge that is closed at the left side, diminuendo for the start of a wedge that is closed on the right side, and stop for the end of a wedge. The continue type is used for formatting wedges over a system break, or for other situations where a single wedge is divided into multiple segments.
		
		
			
			
			
			
		
	
	
	
		
			The wood type represents pictograms for wood percussion instruments. The maraca and maracas values distinguish the one- and two-maraca versions of the pictogram. The vibraslap and castanets values are in addition to Stone's list.
		
		
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
	
	
		
		The distance-type defines what type of distance is being defined in a distance element. Values include beam and hyphen. This is left as a string so that other application-specific types can be defined, but it is made a separate type so that it can be redefined more strictly.
		
		
	

	
		
		The line-width-type defines what type of line is being defined in a line-width element. Values include beam, bracket, dashes, enclosure, ending, extend, heavy barline, leger, light barline, octave shift, pedal, slur middle, slur tip, staff, stem, tie middle, tie tip, tuplet bracket, and wedge. This is left as a string so that other application-specific types can be defined, but it is made a separate type so that it can be redefined more strictly.
		
		
	

	
		
			The margin-type type specifies whether margins apply to even page, odd pages, or both.
		
		
			
			
			
		
	

	
		
			The millimeters type is a number representing millimeters. This is used in the scaling element to provide a default scaling from tenths to physical units.
		
		
	
	
	
		
			The note-size-type type indicates the type of note being defined by a note-size element. The grace type is used for notes of cue size that that include a grace element. The cue type is used for all other notes with cue size, whether defined explicitly or implicitly via a cue element. The large type is used for notes of large size.
		
		
			
			
			
		
	

	
	
	
		
			The accidental-value type represents notated accidentals supported by MusicXML. In the MusicXML 2.0 DTD this was a string with values that could be included. The XSD strengthens the data typing to an enumerated list. The quarter- and three-quarters- accidentals are Tartini-style quarter-tone accidentals. The -down and -up accidentals are quarter-tone accidentals that include arrows pointing down or up. The slash- accidentals are used in Turkish classical music. The numbered sharp and flat accidentals are superscripted versions of the accidental signs, used in Turkish folk music. The sori and koron accidentals are microtonal sharp and flat accidentals used in Iranian and Persian music.
		
		
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
		
			The arrow-direction type represents the direction in which an arrow points, using Unicode arrow terminology.
		
		
			
			
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
		
			The arrow-style type represents the style of an arrow, using Unicode arrow terminology. Filled and hollow arrows indicate polygonal single arrows. Paired arrows are duplicate single arrows in the same direction. Combined arrows apply to double direction arrows like left right, indicating that an arrow in one direction should be combined with an arrow in the other direction.
		
		
			
			
			
			
			
			
			
		
	
	
	
		
			The beam-value type represents the type of beam associated with each of 8 beam levels (up to 1024th notes) available for each note.
		
		
			
			
			
			
			
		
	
	
	
		
			The breath-mark-value type represents the symbol used for a breath mark.
		
		
			
			
			
		
	
	
	
		
			The circular-arrow type represents the direction in which a circular arrow points, using Unicode arrow terminology.
		
		
			
			
		
	
	
	
		
			The fan type represents the type of beam fanning present on a note, used to represent accelerandos and ritardandos.
		
		
			
			
			
		
	
	
	
		
			The handbell-value type represents the type of handbell technique being notated.
		
		
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
		
			The hole-closed-location type indicates which portion of the hole is filled in when the corresponding hole-closed-value is half.
		
		
			
			
			
			
		
	
	
	
		
			The hole-closed-value type represents whether the hole is closed, open, or half-open.
		
		
			
			
			
		
	
	
	
		
			The note-type type is used for the MusicXML type element and represents the graphic note type, from 1024th (shortest) to maxima (longest).
		
		
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
		
			
The notehead type indicates shapes other than the open and closed ovals associated with note durations. The values do, re, mi, fa, fa up, so, la, and ti correspond to Aikin's 7-shape system.  The fa up shape is typically used with upstems; the fa shape is typically used with downstems or no stems.

The arrow shapes differ from triangle and inverted triangle by being centered on the stem. Slashed and back slashed notes include both the normal notehead and a slash. The triangle shape has the tip of the triangle pointing up; the inverted triangle shape has the tip of the triangle pointing down. The left triangle shape is a right triangle with the hypotenuse facing up and to the left.
		
		
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		
	
	
	
		
			Octaves are represented by the numbers 0 to 9, where 4 indicates the octave started by middle C.
		
		
			
			
		
	
	
	
		
			The semitones type is a number representing semitones, used for chromatic alteration. A value of -1 corresponds to a flat and a value of 1 to a sharp. Decimal values like 0.5 (quarter tone sharp) are used for microtones.
		
		
	
	
	
		
			The show-tuplet type indicates whether to show a part of a tuplet relating to the tuplet-actual element, both the tuplet-actual and tuplet-normal elements, or neither.
		
		
			
			
			
		
	
	
	
		
			The stem type represents the notated stem direction.
		
		
			
			
			
			
		
	
	
	
		
			The step type represents a step of the diatonic scale, represented using the English letters A through G.
		
		
			
			
			
			
			
			
			
		
	
	
	
		
			Lyric hyphenation is indicated by the syllabic type. The single, begin, end, and middle values represent single-syllable words, word-beginning syllables, word-ending syllables, and mid-word syllables, respectively.
		
		
			
			
			
			
		
	
	
	
		
			The number of tremolo marks is represented by a number from 0 to 8: the same as beam-level with 0 added.
		
		
			
			
		
	
	
	
	
	
		
			The group-barline-value type indicates if the group should have common barlines.
		
		
			
			
			
		
	
	
	
		
			The group-symbol-value type indicates how the symbol for a group is indicated in the score. The default value is none.
		
		
			
			
			
			
			
		
	
	
	
	
	
		
			The bend-sound type is used for bend and slide elements, and is similar to the trill-sound attribute group. Here the beats element refers to the number of discrete elements (like MIDI pitch bends) used to represent a continuous bend or slide. The first-beat indicates the percentage of the direction for starting a bend; the last-beat the percentage for ending it. The default choices are:
	
	accelerate = "no"
	beats = "4"
	first-beat = "25"
	last-beat = "75"
		
		
		
		
		
	
	
	
		
			The bezier attribute group is used to indicate the curvature of slurs and ties, representing the control points for a cubic bezier curve. For ties, the bezier attribute group is used with the tied element.

Normal slurs, S-shaped slurs, and ties need only two bezier points: one associated with the start of the slur or tie, the other with the stop. Complex slurs and slurs divided over system breaks can specify additional bezier data at slur elements with a continue type.
	
The bezier-offset, bezier-x, and bezier-y attributes describe the outgoing bezier point for slurs and ties with a start type, and the incoming bezier point for slurs and ties with types of stop or continue. The attributes bezier-offset2, bezier-x2, and bezier-y2 are only valid with slurs of type continue, and describe the outgoing bezier point.
	
The bezier-offset and bezier-offset2 attributes are measured in terms of musical divisions, like the offset element. These are the recommended attributes for specifying horizontal position. The other attributes are specified in tenths, relative to any position settings associated with the slur or tied element.
		
		
		
		
		
		
		
	
	
	
		
			The color attribute group indicates the color of an element.
		
		
	

	
		
			The dashed-formatting entity represents the length of dashes and spaces in a dashed line. Both the dash-length and space-length attributes are represented in tenths. These attributes are ignored if the corresponding line-type attribute is not dashed.
			
		
		
	

	
		
			The directive attribute changes the default-x position of a direction. It indicates that the left-hand side of the direction is aligned with the left-hand side of the time signature. If no time signature is present, it is aligned with the left-hand side of the first music notational element in the measure. If a default-x, justify, or halign attribute is present, it overrides the directive attribute.
		
		
	
	
	
		
			The document-attributes attribute group is used to specify the attributes for an entire MusicXML document. Currently this is used for the version attribute.

The version attribute was added in Version 1.1 for the score-partwise and score-timewise documents. It provides an easier way to get version information than through the MusicXML public ID. The default value is 1.0 to make it possible for programs that handle later versions to distinguish earlier version files reliably. Programs that write MusicXML 1.1 or later files should set this attribute.
		
		
	
	
	
		
			The enclosure attribute group is used to specify the formatting of an enclosure around text or symbols.
		
		
	
	
	
		
			The font attribute group gathers together attributes for determining the font within a credit or direction. They are based on the text styles for Cascading Style Sheets. The font-family is a comma-separated list of font names. These can be specific font styles such as Maestro or Opus, or one of several generic font styles: music, engraved, handwritten, text, serif, sans-serif, handwritten, cursive, fantasy, and monospace. The music, engraved, and handwritten values refer to music fonts; the rest refer to text fonts. The fantasy style refers to decorative text such as found in older German-style printing. The font-style can be normal or italic. The font-size can be one of the CSS sizes (xx-small, x-small, small, medium, large, x-large, xx-large) or a numeric point size. The font-weight can be normal or bold. The default is application-dependent, but is a text font vs. a music font.
		
		
		
		
		
	
	
	
		
			In cases where text extends over more than one line, horizontal alignment and justify values can be different. The most typical case is for credits, such as:

	Words and music by
	  Pat Songwriter

Typically this type of credit is aligned to the right, so that the position information refers to the right-most part of the text. But in this example, the text is center-justified, not right-justified.

The halign attribute is used in these situations. If it is not present, its value is the same as for the justify attribute.
		
		
	
	
	
		
			The justify attribute is used to indicate left, center, or right justification. The default value varies for different elements. For elements where the justify attribute is present but the halign attribute is not, the justify attribute indicates horizontal alignment as well as justification.
		
		
	
	
	
		
			The letter-spacing attribute specifies text tracking. Values are either "normal" or a number representing the number of ems to add between each letter. The number may be negative in order to subtract space. The default is normal, which allows flexibility of letter-spacing for purposes of text justification.
		
		
	
	
	
		
			The level-display attribute group specifies three common ways to indicate editorial indications: putting parentheses or square brackets around a symbol, or making the symbol a different size. If not specified, they are left to application defaults. It is used by the level and accidental elements.
		
		
		
		
	
	
	
		
			The line-height attribute specifies text leading. Values are either "normal" or a number representing the percentage of the current font height to use for leading. The default is "normal". The exact normal value is implementation-dependent, but values between 100 and 120 are recommended.
		
		
	
	
	
		
			The line-shape attribute distinguishes between straight and curved lines.
		
		
	
	
	
		
			The line-type attribute distinguishes between solid, dashed, dotted, and wavy lines.
		
		
	
	
	
		
			The orientation attribute indicates whether slurs and ties are overhand (tips down) or underhand (tips up). This is distinct from the placement attribute used by any notation type.
		
		
	
	
	
		
			The placement attribute indicates whether something is above or below another element, such as a note or a notation.
		
		
	
	
	
		
			The position attributes are based on MuseData print suggestions. For most elements, any program will compute a default x and y position. The position attributes let this be changed two ways. 

The default-x and default-y attributes change the computation of the default position. For most elements, the origin is changed relative to the left-hand side of the note or the musical position within the bar (x) and the top line of the staff (y).

For the following elements, the default-x value changes the origin relative to the start of the current measure:

	- note
	- figured-bass
	- harmony
	- link
	- directive
	- measure-numbering
	- all descendants of the part-list element
	- all children of the direction-type element

This origin is from the start of the entire measure, at either the left barline or the start of the system.

When the default-x attribute is used within a child element of the part-name-display, part-abbreviation-display, group-name-display, or group-abbreviation-display elements, it changes the origin relative to the start of the first measure on the system. These values are used when the current measure or a succeeding measure starts a new system. The same change of origin is used for the group-symbol element.

For the note, figured-bass, and harmony elements, the default-x value is considered to have adjusted the musical position within the bar for its descendant elements.

Since the credit-words and credit-image elements are not related to a measure, in these cases the default-x and default-y attributes adjust the origin relative to the bottom left-hand corner of the specified page.

The relative-x and relative-y attributes change the position relative to the default position, either as computed by the individual program, or as overridden by the default-x and default-y attributes.
	
Positive x is right, negative x is left; positive y is up, negative y is down. All units are in tenths of interline space. For stems, positive relative-y lengthens a stem while negative relative-y shortens it.

The default-x and default-y position attributes provide higher-resolution positioning data than related features such as the placement attribute and the offset element. Applications reading a MusicXML file that can understand both features should generally rely on the default-x and default-y attributes for their greater accuracy. For the relative-x and relative-y attributes, the offset element, placement attribute, and directive attribute provide context for the relative position information, so the two features should be interpreted together.

As elsewhere in the MusicXML format, tenths are the global tenths defined by the scaling element, not the local tenths of a staff resized by the staff-size element.
		
		
		
		
		
	
	
	
		
			The print-object attribute specifies whether or not to print an object (e.g. a note or a rest). It is yes by default.
		
		
	
	
	
		
			The print-spacing attribute controls whether or not spacing is left for an invisible note or object. It is used only if no note, dot, or lyric is being printed. The value is yes (leave spacing) by default.
		
		
	
	
	
		
			The print-style attribute group collects the most popular combination of printing attributes: position, font, and color.
		
		
		
		
	
	
	
		
			The print-style-align attribute group adds the halign and valign attributes to the position, font, and color attributes.
		
		
		
		
	
	
	
		
			The printout attribute group collects the different controls over printing an object (e.g. a note or rest) and its parts, including augmentation dots and lyrics. This is especially useful for notes that overlap in different voices, or for chord sheets that contain lyrics and chords but no melody.

By default, all these attributes are set to yes. If print-object is set to no, the print-dot and print-lyric attributes are interpreted to also be set to no if they are not present.
		
		
		
		
		
	
	
	
		
			The text-decoration attribute group is based on the similar feature in XHTML and CSS. It allows for text to be underlined, overlined, or struck-through. It extends the CSS version by allow double or triple lines instead of just being on or off.
		
		
		
		
	
	
	
		
			The text-direction attribute is used to adjust and override the Unicode bidirectional text algorithm, similar to the W3C Internationalization Tag Set recommendation.
		
		
	
	
	
		
			The text-formatting attribute group collects the common formatting attributes for text elements. Default values may differ across the elements that use this group.
		
		
		
		
		
		
		
		
		
		
		
	
	
	
		
			The rotation attribute is used to rotate text around the alignment point specified by the halign and valign attributes. Positive values are clockwise rotations, while negative values are counter-clockwise rotations.
		
		
	
	
	
		
			The trill-sound attribute group includes attributes used to guide the sound of trills, mordents, turns, shakes, and wavy lines, based on MuseData sound suggestions. The default choices are:
	
	start-note = "upper"
	trill-step = "whole"
	two-note-turn = "none"
	accelerate = "no"
	beats = "4".
	
Second-beat and last-beat are percentages for landing on the indicated beat, with defaults of 25 and 75 respectively.
	
For mordent and inverted-mordent elements, the defaults are different:
	
	The default start-note is "main", not "upper".
	The default for beats is "3", not "4".
	The default for second-beat is "12", not "25".
	The default for last-beat is "24", not "75".
		
		
		
		
		
		
		
		
	
	
	
		
			The valign attribute is used to indicate vertical alignment to the top, middle, bottom, or baseline of the text. Defaults are implementation-dependent.
		
		
	
	
	
		
			The valign-image attribute is used to indicate vertical alignment for images and graphics, so it removes the baseline value. Defaults are implementation-dependent.
		
		
	
	
	
		
			The x-position attribute group is used for elements like notes where specifying x position is common, but specifying y position is rare.
		
		
		
		
		
	
	
	
		
			The y-position attribute group is used for elements like stems where specifying y position is common, but specifying x position is rare.
		
		
		
		
		
	
	
	
	
	
		
			The image-attributes group is used to include graphical images in a score. The required source attribute is the URL for the image file. The required type attribute is the MIME type for the image file format. Typical choices include application/postscript, image/gif, image/jpeg, image/png, and image/tiff.
		
		
		
		
		
		
	
	
	
		
			The print-attributes group is used by the print element. The new-system and new-page attributes indicate whether to force a system or page break, or to force the current music onto the same system or page as the preceding music. Normally this is the first music data within a measure. If used in multi-part music, they should be placed in the same positions within each part, or the results are undefined. The page-number attribute sets the number of a new page; it is ignored if new-page is not "yes". Version 2.0 adds a blank-page attribute. This is a positive integer value that specifies the number of blank pages to insert before the current measure. It is ignored if new-page is not "yes". These blank pages have no music, but may have text or images specified by the credit element. This is used to allow a combination of pages that are all text, or all text and images, together with pages of music.

The staff-spacing attribute specifies spacing between multiple staves in tenths of staff space. This is deprecated as of Version 1.1; the staff-layout element should be used instead. If both are present, the staff-layout values take priority.
		
		
		
		
		
		
	
	
	
	
	
		
			The element and position attributes are new as of Version 2.0. They allow for bookmarks and links to be positioned at higher resolution than the level of music-data elements. When no element and position attributes are present, the bookmark or link element refers to the next sibling element in the MusicXML file. The element attribute specifies an element type for a descendant of the next sibling element that is not a link or bookmark. The position attribute specifies the position of this descendant element, where the first position is 1. The position attribute is ignored if the element attribute is not present. For instance, an element value of "beam" and a position value of "2" defines the link or bookmark to refer to the second beam descendant of the next sibling element that is not a link or bookmark. This is equivalent to an XPath test of [.//beam[2]] done in the context of the sibling element.
		
		
		
	

	
		
			The link-attributes group includes all the simple XLink attributes supported in the MusicXML format.
		
		
		
		
		
		
		
		
	
	
	
	
	
		
			The group-name-text attribute group is used by the group-name and group-abbreviation elements. The print-style and justify attribute groups are deprecated in MusicXML 2.0 in favor of the new group-name-display and group-abbreviation-display elements.
		
		
		
	

	
		
			The measure-attributes group is used by the measure element. Measures have a required number attribute (going from partwise to timewise, measures are grouped via the number).
	
The implicit attribute is set to "yes" for measures where the measure number should never appear, such as pickup measures and the last half of mid-measure repeats. The value is "no" if not specified.
	
The non-controlling attribute is intended for use in multimetric music like the Don Giovanni minuet. If set to "yes", the left barline in this measure does not coincide with the left barline of measures in other parts. The value is "no" if not specified. 

In partwise files, the number attribute should be the same for measures in different parts that share the same left barline. While the number attribute is often numeric, it does not have to be. Non-numeric values are typically used together with the implicit or non-controlling attributes being set to "yes". For a pickup measure, the number attribute is typically set to "0" and the implicit attribute is typically set to "yes". Further details about measure numbering can be defined using the measure-numbering element.

Measure width is specified in tenths. These are the global tenths specified in the scaling element, not local tenths as modified by the staff-size element.	The width covers the entire measure from barline or system start to barline or system end.
		
		
		
		
		
	
	
	
		
			In either partwise or timewise format, the part element has an id attribute that is an IDREF back to a score-part in the part-list.
		
		
	
	
	
		
			The part-name-text attribute group is used by the part-name and part-abbreviation elements. The print-style and justify attribute groups are deprecated in MusicXML 2.0 in favor of the new part-name-display and part-abbreviation-display elements.
		
		
		
		
	
	
	

	
		
			The accidental-text type represents an element with an accidental value and text-formatting attributes.
		
		
			
				
			
		
	

	
		
			Dynamics can be associated either with a note or a general musical direction. To avoid inconsistencies between and amongst the letter abbreviations for dynamics (what is sf vs. sfz, standing alone or with a trailing dynamic that is not always piano), we use the actual letters as the names of these dynamic elements. The other-dynamics element allows other dynamic marks that are not covered here, but many of those should perhaps be included in a more general musical direction element. Dynamics elements may also be combined to create marks not covered by a single element, such as sfmp.
	
These letter dynamic symbols are separated from crescendo, decrescendo, and wedge indications. Dynamic representation is inconsistent in scores. Many things are assumed by the composer and left out, such as returns to original dynamics. Systematic representations are quite complex: for example, Humdrum has at least 3 representation formats related to dynamics. The MusicXML format captures what is in the score, but does not try to be optimal for analysis or synthesis of dynamics.
		
		
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
			
		
		
		
		
		
	
	
	
		
			The empty type represents an empty element with no attributes.
		
	
	
	
		
			The empty-placement type represents an empty element with print-style and placement attributes.
		
		
		
	
	
	
		
			The empty-print-style type represents an empty element with print-style attribute group.
		
		
	
	
	
		
			The empty-print-style-align type represents an empty element with print-style-align attribute group.
		
		
	
	
	
		
			The empty-print-style-align-object type represents an empty element with print-object and print-style-align attribute groups.
		
		
		
	
	
	
		
			The empty-trill-sound type represents an empty element with print-style, placement, and trill-sound attributes.
		
		
		
		
	
	
	
		
			The horizontal-turn type represents turn elements that are horizontal rather than vertical. These are empty elements with print-style, placement, trill-sound, and slash attributes. If the slash attribute is yes, then a vertical line is used to slash the turn; it is no by default.
		
		
		
		
		
	
	
	
		
			The fermata text content represents the shape of the fermata sign. An empty fermata element represents a normal fermata. The fermata type is upright if not specified.
		
		
			
				
				
			
		
	

	
		
			Fingering is typically indicated 1,2,3,4,5. Multiple fingerings may be given, typically to substitute fingerings in the middle of a note. The substitution and alternate values are "no" if the attribute is not present. For guitar and other fretted instruments, the fingering element represents the fretting finger; the pluck element represents the plucking finger.
		
		
			
				
				
				
				
			
		
	

	
		
			The formatted-text type represents a text element with text-formatting attributes.
		
		
			
				
			
		
	
	
	
		
			The fret element is used with tablature notation and chord diagrams. Fret numbers start with 0 for an open string and 1 for the first fret.
		
		
			
				
				
			
		
	

	
		
			The level type is used to specify editorial information for different MusicXML elements. If the reference attribute for the level element is yes, this indicates editorial information that is for display only and should not affect playback. For instance, a modern edition of older music may set reference="yes" on the attributes containing the music's original clef, key, and time signature. It is no by default.
		
		
			
				
				
			
		
	
	
	
		
			The midi-device type corresponds to the DeviceName meta event in Standard MIDI Files. The optional port attribute is a number from 1 to 16 that can be used with the unofficial MIDI port (or cable) meta event. Unlike the DeviceName meta event, there can be multiple midi-device elements per MusicXML part starting in MusicXML 3.0. The optional id attribute refers to the score-instrument assigned to this device. If missing, the device assignment affects all score-instrument elements in the score-part.
		
		
			
				
				
			
		
	

	
		
			The midi-instrument type defines MIDI 1.0 instrument playback. The midi-instrument element can be a part of either the score-instrument element at the start of a part, or the sound element within a part. The id attribute refers to the score-instrument affected by the change.
		
		
			
				
					The midi-channel element specifies a MIDI 1.0 channel numbers ranging from 1 to 16.
				
			
			
				
					The midi-name element corresponds to a ProgramName meta-event within a Standard MIDI File.
				
			
			
				
					The midi-bank element specified a MIDI 1.0 bank number ranging from 1 to 16,384.
				
			
			
				
					The midi-program element specifies a MIDI 1.0 program number ranging from 1 to 128.
				
			
			
				
					For unpitched instruments, the midi-unpitched element specifies a MIDI 1.0 note number ranging from 1 to 128. It is usually used with MIDI banks for percussion. Note that MIDI 1.0 note numbers are generally specified from 0 to 127 rather than the 1 to 128 numbering used in this element.
				
			
			
				
					The volume element value is a percentage of the maximum ranging from 0 to 100, with decimal values allowed. This corresponds to a scaling value for the MIDI 1.0 channel volume controller.
				
			
			
				
					The pan and elevation elements allow placing of sound in a 3-D space relative to the listener. Both are expressed in degrees ranging from -180 to 180. For pan, 0 is straight ahead, -90 is hard left, 90 is hard right, and -180 and 180 are directly behind the listener.
				
			
			
				
					The elevation and pan elements allow placing of sound in a 3-D space relative to the listener. Both are expressed in degrees ranging from -180 to 180. For elevation, 0 is level with the listener, 90 is directly above, and -90 is directly below.
				
			
		
		
	

	
		
			The name-display type is used for exact formatting of multi-font text in part and group names to the left of the system. The print-object attribute can be used to determine what, if anything, is printed at the start of each system. Enclosure for the display-text element is none by default. Language for the display-text element is Italian ("it") by default.
		
		
			
				
				
			
		
		
	
		
	
		
			The other-play element represents other types of playback. The required type attribute indicates the type of playback to which the element content applies.
		
		
			
				
			
		
	
	
	
		
			The play type, new in Version 3.0, specifies playback techniques to be used in conjunction with the instrument-sound element. When used as part of a sound element, it applies to all notes going forward in score order. In multi-instrument parts, the affected instrument should be specified using the id attribute. When used as part of a note element, it applies to the current note only.
		
		
			
				
					
						The ipa element represents International Phonetic Alphabet (IPA) sounds for vocal music. String content is limited to IPA 2005 symbols represented in Unicode 6.0.
					
				
				
				
				
			
		
		
	
	
	
		
			The string type is used with tablature notation, regular notation (where it is often circled), and chord diagrams. String numbers start with 1 for the highest string.
		
		
			
				
				
			
		
	
	
	
		
			The typed-text type represents a text element with a type attributes.
		
		
			
				
			
		
	
		
	
		
			Wavy lines are one way to indicate trills. When used with a measure element, they should always have type="continue" set.
		
		
		
		
		
		
		
	

	
	
	
		
			The attributes element contains musical information that typically changes on measure boundaries. This includes key and time signatures, clefs, transpositions, and staving. When attributes are changed mid-measure, it affects the music in score order, not in MusicXML document order.
		
		
			

			
				
					Musical notation duration is commonly represented as fractions. The divisions element indicates how many divisions per quarter note are used to indicate a note's duration. For example, if duration = 1 and divisions = 2, this is an eighth note duration. Duration and divisions are used directly for generating sound output, so they must be chosen to take tuplets into account. Using a divisions element lets us use just one number to represent a duration for each note in the score, while retaining the full power of a fractional representation. If maximum compatibility with Standard MIDI 1.0 files is important, do not have the divisions value exceed 16383.
				
			

			
				
					The key element represents a key signature. Both traditional and non-traditional key signatures are supported. The optional number attribute refers to staff numbers. If absent, the key signature applies to all staves in the part.
				
			
			
			
				
					Time signatures are represented by the beats element for the numerator and the beat-type element for the denominator.
				
			

			
				
					The staves element is used if there is more than one staff represented in the given part (e.g., 2 staves for typical piano parts). If absent, a value of 1 is assumed. Staves are ordered from top to bottom in a part in numerical order, with staff 1 above staff 2.
				
			

			
				
					The part-symbol element indicates how a symbol for a multi-staff part is indicated in the score.
				
			

			
				
					The instruments element is only used if more than one instrument is represented in the part (e.g., oboe I and II where they play together most of the time). If absent, a value of 1 is assumed.
				
			

			
				
					Clefs are represented by a combination of sign, line, and clef-octave-change elements.
				
			

			
				
					The staff-details element is used to indicate different types of staves.
				
			

			
				
					If the part is being encoded for a transposing instrument in written vs. concert pitch, the transposition must be encoded in the transpose element using the transpose type.
				
			

			
				
					Directives are like directions, but can be grouped together with attributes for convenience. This is typically used for tempo markings at the beginning of a piece of music. This element has been deprecated in Version 2.0 in favor of the directive attribute for direction elements. Language names come from ISO 639, with optional country subcodes from ISO 3166.
				
				
					
						
							
							
						
					
				
			

			
				
					A measure-style indicates a special way to print partial to multiple measures within a part. This includes multiple rests over several measures, repeats of beats, single, or multiple measures, and use of slash notation.
				
			

		
	

	
		
			The beat-repeat type is used to indicate that a single beat (but possibly many notes) is repeated. Both the start and stop of the beat being repeated should be specified. The slashes attribute specifies the number of slashes to use in the symbol. The use-dots attribute indicates whether or not to use dots as well (for instance, with mixed rhythm patterns). By default, the value for slashes is 1 and the value for use-dots is no.
	
The beat-repeat element specifies a notation style for repetitions. The actual music being repeated needs to be repeated within the MusicXML file. This element specifies the notation that indicates the repeat.
		
		
		
		
		
	

	
		
			A cancel element indicates that the old key signature should be cancelled before the new one appears. This will always happen when changing to C major or A minor and need not be specified then. The cancel value matches the fifths value of the cancelled key signature (e.g., a cancel of -2 will provide an explicit cancellation for changing from B flat major to F major). The optional location attribute indicates whether the cancellation appears relative to the new key signature.
		
		
			
				
			
		
	

	
		
			Clefs are represented by a combination of sign, line, and clef-octave-change elements. The optional number attribute refers to staff numbers within the part. A value of 1 is assumed if not present.

Sometimes clefs are added to the staff in non-standard line positions, either to indicate cue passages, or when there are multiple clefs present simultaneously on one staff. In this situation, the additional attribute is set to "yes" and the line value is ignored. The size attribute is used for clefs where the additional attribute is "yes". It is typically used to indicate cue clefs.

Sometimes clefs at the start of a measure need to appear after the barline rather than before, as for cues or for use after a repeated section. The after-barline attribute is set to "yes" in this situation. The attribute is ignored for mid-measure clefs.

Clefs appear at the start of each system unless the print-object attribute has been set to "no" or the additional attribute has been set to "yes".
		
		
			
				
					The sign element represents the clef symbol.
				
			
			
				
					Line numbers are counted from the bottom of the staff. Standard values are 2 for the G sign (treble clef), 4 for the F sign (bass clef), 3 for the C sign (alto clef) and 5 for TAB (on a 6-line staff).
				
			
			
				
					The clef-octave-change element is used for transposing clefs. A treble clef for tenors would have a value of -1.
				
			
		
		
		
		
		
		
		
	

	
		
			The interchangeable type is used to represent the second in a pair of interchangeable dual time signatures, such as the 6/8 in 3/4 (6/8). A separate symbol attribute value is available compared to the time element's symbol attribute, which applies to the first of the dual time signatures. The parentheses attribute value is yes by default.
		
		
			
			
		
		
		
	

	
		
			The key type represents a key signature. Both traditional and non-traditional key signatures are supported. The optional number attribute refers to staff numbers. If absent, the key signature applies to all staves in the part. Key signatures appear at the start of each system unless the print-object attribute has been set to "no".
		
		
			
				
				
			
			
				
					The optional list of key-octave elements is used to specify in which octave each element of the key signature appears.
				
			
		
		
		
		
	
	
	
		
			The key-octave element specifies in which octave an element of a key signature appears. The content specifies the octave value using the same values as the display-octave element. The number attribute is a positive integer that refers to the key signature element in left-to-right order. If the cancel attribute is set to yes, then this number refers to an element specified by the cancel element. It is no by default.
		
		
			
				
				
			
		
	

	
		
			The measure-repeat type is used for both single and multiple measure repeats. The text of the element indicates the number of measures to be repeated in a single pattern. The slashes attribute specifies the number of slashes to use in the repeat sign. It is 1 if not specified. Both the start and the stop of the measure-repeat must be specified. The text of the element is ignored when the type is stop.
	
The measure-repeat element specifies a notation style for repetitions. The actual music being repeated needs to be repeated within the MusicXML file. This element specifies the notation that indicates the repeat.
		
		
			
				
				
			
		
	

	
		
			A measure-style indicates a special way to print partial to multiple measures within a part. This includes multiple rests over several measures, repeats of beats, single, or multiple measures, and use of slash notation.

The multiple-rest and measure-repeat symbols indicate the number of measures covered in the element content. The beat-repeat and slash elements can cover partial measures. All but the multiple-rest element use a type attribute to indicate starting and stopping the use of the style. The optional number attribute specifies the staff number from top to bottom on the system, as with clef.
		
		
			
			
			
			
		
		
		
		
	

	
		
			The text of the multiple-rest type indicates the number of measures in the multiple rest. Multiple rests may use the 1-bar / 2-bar / 4-bar rest symbols, or a single shape. The use-symbols attribute indicates which to use; it is no if not specified. The element text is ignored when the type is stop.
		
		
			
				
			
		
	

	
		
			The part-symbol type indicates how a symbol for a multi-staff part is indicated in the score; brace is the default value. The top-staff and bottom-staff elements are used when the brace does not extend across the entire part. For example, in a 3-staff organ part, the top-staff will typically be 1 for the right hand, while the bottom-staff will typically be 2 for the left hand. Staff 3 for the pedals is usually outside the brace.
		
		
			
				
				
				
				
			
		
	

	
		
			The slash type is used to indicate that slash notation is to be used. If the slash is on every beat, use-stems is no (the default). To indicate rhythms but not pitches, use-stems is set to yes. The type attribute indicates whether this is the start or stop of a slash notation style. The use-dots attribute works as for the beat-repeat element, and only has effect if use-stems is no.
		
		
		
		
		
	

	
		
			The staff-details element is used to indicate different types of staves. The optional number attribute specifies the staff number from top to bottom on the system, as with clef. The print-object attribute is used to indicate when a staff is not printed in a part, usually in large scores where empty parts are omitted. It is yes by default. If print-spacing is yes while print-object is no, the score is printed in cutaway format where vertical space is left for the empty part.
		
		
			
			
				
					The staff-lines element specifies the number of lines for a non 5-line staff.
				
			
			
			
				
					The capo element indicates at which fret a capo should be placed on a fretted instrument. This changes the open tuning of the strings specified by staff-tuning by the specified number of half-steps.
				
			
			
				
					The staff-size element indicates how large a staff space is on this staff, expressed as a percentage of the work's default scaling. Values less than 100 make the staff space smaller while values over 100 make the staff space larger. A staff-type of cue, ossia, or editorial implies a staff-size of less than 100, but the exact value is implementation-dependent unless specified here. Staff size affects staff height only, not the relationship of the staff to the left and right margins.
				
			
		
		
		
		
		
	

	
		
			The staff-tuning type specifies the open, non-capo tuning of the lines on a tablature staff.
		
		
		
	

	
		
			Time signatures are represented by the beats element for the numerator and the beat-type element for the denominator. The symbol attribute is used indicate common and cut time symbols as well as a single number display. Multiple pairs of beat and beat-type elements are used for composite time signatures with multiple denominators, such as 2/4 + 3/8. A composite such as 3+2/8 requires only one beat/beat-type pair.

The print-object attribute allows a time signature to be specified but not printed, as is the case for excerpts from the middle of a score. The value is "yes" if not present. The optional number attribute refers to staff numbers within the part. If absent, the time signature applies to all staves in the part.
		
		
			
				
				
			
			
				
					A senza-misura element explicitly indicates that no time signature is present. The optional element content indicates the symbol to be used, if any, such as an X. The time element's symbol attribute is not used when a senza-misura element is present.
				
			
		
		
		
		
		
		
	

	
		
			The transpose type represents what must be added to a written pitch to get a correct sounding pitch. The optional number attribute refers to staff numbers, from top to bottom on the system. If absent, the transposition applies to all staves in the part. Per-staff transposition is most often used in parts that represent multiple instruments.
		
		
			
				
					The diatonic element specifies the number of pitch steps needed to go from written to sounding pitch. This allows for correct spelling of enharmonic transpositions.
				
			
			
				
					The chromatic element represents the number of semitones needed to get from written to sounding pitch. This value does not include octave-change values; the values for both elements need to be added to the written pitch to get the correct sounding pitch.
				
			
			
				
					The octave-change element indicates how many octaves to add to get from written pitch to sounding pitch.
				
			
			
				
					If the double element is present, it indicates that the music is doubled one octave down from what is currently written (as is the case for mixed cello / bass parts in orchestral literature).
				
			
		
		
	
	
	

	
		
			The bar-style-color type contains barline style and color information.
		
		
			
				
			
		
	

	
		
			If a barline is other than a normal single barline, it should be represented by a barline type that describes it. This includes information about repeats and multiple endings, as well as line style. Barline data is on the same level as the other musical data in a score - a child of a measure in a partwise score, or a part in a timewise score. This allows for barlines within measures, as in dotted barlines that subdivide measures in complex meters. The two fermata elements allow for fermatas on both sides of the barline (the lower one inverted).
	
Barlines have a location attribute to make it easier to process barlines independently of the other musical data in a score. It is often easier to set up measures separately from entering notes. The location attribute must match where the barline element occurs within the rest of the musical data in the score. If location is left, it should be the first element in the measure, aside from the print, bookmark, and link elements. If location is right, it should be the last element, again with the possible exception of the print, bookmark, and link elements. If no location is specified, the right barline is the default. The segno, coda, and divisions attributes work the same way as in the sound element. They are used for playback when barline elements contain segno or coda child elements.
		
		
			
			
			
			
			
			
			
			
		
		
		
		
		
	
	
	
		
			The ending type represents multiple (e.g. first and second) endings. Typically, the start type is associated with the left barline of the first measure in an ending. The stop and discontinue types are associated with the right barline of the last measure in an ending. Stop is used when the ending mark concludes with a downward jog, as is typical for first endings. Discontinue is used when there is no downward jog, as is typical for second endings that do not conclude a piece. The length of the jog can be specified using the end-length attribute. The text-x and text-y attributes are offsets that specify where the baseline of the start of the ending text appears, relative to the start of the ending line.
	
The number attribute reflects the numeric values of what is under the ending line. Single endings such as "1" or comma-separated multiple endings such as "1,2" may be used. The ending element text is used when the text displayed in the ending is different than what appears in the number attribute. The print-object element is used to indicate when an ending is present but not printed, as is often the case for many parts in a full score.
		
		
			
				
				
				
				
				
				
				
			
		
	

	
		
			The repeat type represents repeat marks. The start of the repeat has a forward direction while the end of the repeat has a backward direction. Backward repeats that are not part of an ending can use the times attribute to indicate the number of times the repeated section is played.
		
		
		
		
	

	
	
	
		
			The accord type represents the tuning of a single string in the scordatura element. It uses the same group of elements as the staff-tuning element. Strings are numbered from high to low.
		
		
		
	

	
		
			The accordion-registration type is use for accordion registration symbols. These are circular symbols divided horizontally into high, middle, and low sections that correspond to 4', 8', and 16' pipes. Each accordion-high, accordion-middle, and accordion-low element represents the presence of one or more dots in the registration diagram. An accordion-registration element needs to have at least one of the child elements present.
		
		
			
				
					The accordion-high element indicates the presence of a dot in the high (4') section of the registration symbol.
				
			
			
				
					The accordion-middle element indicates the presence of 1 to 3 dots in the middle (8') section of the registration symbol.
				
			
			
				
					The accordion-low element indicates the presence of a dot in the low (16') section of the registration symbol.
				
			
		
		
	

	
		
			The barre element indicates placing a finger over multiple strings on a single fret. The type is "start" for the lowest pitched string (e.g., the string with the highest MusicXML number) and is "stop" for the highest pitched string.
		
		
		
	
	
	
		
			The bass type is used to indicate a bass note in popular music chord symbols, e.g. G/C. It is generally not used in functional harmony, as inversion is generally not used in pop chord symbols. As with root, it is divided into step and alter elements, similar to pitches.
		
		
			
			
		
	

	
		
			The bass-alter type represents the chromatic alteration of the bass of the current chord within the harmony element. In some chord styles, the text for the bass-step element may include bass-alter information. In that case, the print-object attribute of the bass-alter element can be set to no. The location attribute indicates whether the alteration should appear to the left or the right of the bass-step; it is right by default.
		
		
			
				
				
				
			
		
	

	
		
			The bass-step type represents the pitch step of the bass of the current chord within the harmony element. The text attribute indicates how the bass should appear in a score if not using the element contents.
		
		
			
				
				
			
		
	

	
		
			The beater type represents pictograms for beaters, mallets, and sticks that do not have different materials represented in the pictogram.
		
		
			
				
			
		
	

	
		
			Brackets are combined with words in a variety of modern directions. The line-end attribute specifies if there is a jog up or down (or both), an arrow, or nothing at the start or end of the bracket. If the line-end is up or down, the length of the jog can be specified using the end-length attribute. The line-type is solid by default.
		
		
		
		
		
		
		
		
		
	

	
		
			The dashes type represents dashes, used for instance with cresc. and dim. marks.
		
		
		
		
		
		
	

	
		
			The degree type is used to add, alter, or subtract individual notes in the chord. The print-object attribute can be used to keep the degree from printing separately when it has already taken into account in the text attribute of the kind element. The degree-value and degree-type text attributes specify how the value and type of the degree should be displayed.
	
A harmony of kind "other" can be spelled explicitly by using a series of degree elements together with a root.
		
		
			
			
			
		
		
	

	
		
			The degree-alter type represents the chromatic alteration for the current degree. If the degree-type value is alter or subtract, the degree-alter value is relative to the degree already in the chord based on its kind element. If the degree-type value is add, the degree-alter is relative to a dominant chord (major and perfect intervals except for a minor seventh). The plus-minus attribute is used to indicate if plus and minus symbols should be used instead of sharp and flat symbols to display the degree alteration; it is no by default.
		
		
			
				
				
			
		
	

	
		
			The degree-type type indicates if this degree is an addition, alteration, or subtraction relative to the kind of the current chord. The value of the degree-type element affects the interpretation of the value of the degree-alter element. The text attribute specifies how the type of the degree should be displayed in a score.
		
		
			
				
				
			
		
	

	
		
			The content of the degree-value type is a number indicating the degree of the chord (1 for the root, 3 for third, etc). The text attribute specifies how the type of the degree should be displayed in a score. The degree-value symbol attribute indicates that a symbol should be used in specifying the degree. If the symbol attribute is present, the value of the text attribute follows the symbol.
		
		
			
				
				
				
			
		
	

	
		
			A direction is a musical indication that is not attached to a specific note. Two or more may be combined to indicate starts and stops of wedges, dashes, etc.
	
By default, a series of direction-type elements and a series of child elements of a direction-type within a single direction element follow one another in sequence visually. For a series of direction-type children, non-positional formatting attributes are carried over from the previous element by default.
		
		
			
			
			
			
			
		
		
		
	
	
	
		
			Textual direction types may have more than 1 component due to multiple fonts. The dynamics element may also be used in the notations element. Attribute groups related to print suggestions apply to the individual direction-type, not to the overall direction.
		
		
			
				
					The rehearsal type specifies a rehearsal mark. Language is Italian ("it") by default. Enclosure is square by default. Left justification is assumed if not specified.
				
			
			
				
					The segno element is the visual indicator of a segno sign. A sound element is needed to guide playback applications reliably.
				
			
			
				
					The words element specifies a standard text direction. Left justification is assumed if not specified. Language is Italian ("it") by default. Enclosure is none by default.
				
			
			
				
					The coda element is the visual indicator of a coda sign. A sound element is needed to guide playback applications reliably.
				
			
			
			
			
			
			
			
			
			
			
				
					The damp element specifies a harp damping mark.
				
			
			
				
					The damp-all element specifies a harp damping mark for all strings.
				
			
			
				
					The eyeglasses element specifies the eyeglasses symbol, common in commercial music.
				
			
			
			
			
			
			
			
			
		
	

	
		
			The feature type is a part of the grouping element used for musical analysis. The type attribute represents the type of the feature and the element content represents its value. This type is flexible to allow for different analyses.
		
		
			
				
			
		
	

	
		
			The first-fret type indicates which fret is shown in the top space of the frame; it is fret 1 if the element is not present. The optional text attribute indicates how this is represented in the fret diagram, while the location attribute indicates whether the text appears to the left or right of the frame.
		
		
			
				
				
			
		
	

	
		
			The frame type represents a frame or fretboard diagram used together with a chord symbol. The representation is based on the NIFF guitar grid with additional information. The frame type's unplayed attribute indicates what to display above a string that has no associated frame-note element. Typical values are x and the empty string. If the attribute is not present, the display of the unplayed string is application-defined.
		
		
			
				
					The frame-strings element gives the overall size of the frame in vertical lines (strings).
				
			
			
				
					The frame-frets element gives the overall size of the frame in horizontal spaces (frets).
				
			
			
			
		
		
		
		
		
		
		
		
	

	
		
			The frame-note type represents each note included in the frame. An open string will have a fret value of 0, while a muted string will not be associated with a frame-note element.
		
		
			
			
			
			
		
	

	
		
			The grouping type is used for musical analysis. When the type attribute is "start" or "single", it usually contains one or more feature elements. The number attribute is used for distinguishing between overlapping and hierarchical groupings. The member-of attribute allows for easy distinguishing of what grouping elements are in what hierarchy. Feature elements contained within a "stop" type of grouping may be ignored.
	
This element is flexible to allow for different types of analyses. Future versions of the MusicXML format may add elements that can represent more standardized categories of analysis data, allowing for easier data sharing.
		
		
			
		
		
		
		
	

	
		
			The harmony type is based on Humdrum's **harm encoding, extended to support chord symbols in popular music as well as functional harmony analysis in classical music.
	
If there are alternate harmonies possible, this can be specified using multiple harmony elements differentiated by type. Explicit harmonies have all note present in the music; implied have some notes missing but implied; alternate represents alternate analyses. 
	
The harmony object may be used for analysis or for chord symbols. The print-object attribute controls whether or not anything is printed due to the harmony element. The print-frame attribute controls printing of a frame or fretboard diagram. The print-style attribute group sets the default for the harmony, but individual elements can override this with their own print-style values.
		
		
			
			
			
			
			
		
		
		
		
		
		
	

	
		
			The harp-pedals type is used to create harp pedal diagrams. The pedal-step and pedal-alter elements use the same values as the step and alter elements. For easiest reading, the pedal-tuning elements should follow standard harp pedal order, with pedal-step values of D, C, B, E, F, G, and A.
		
		
			
		
		
	

	
		
			The image type is used to include graphical images in a score.
		
		
	

	
		
			The inversion type represents harmony inversions. The value is a number indicating which inversion is used: 0 for root position, 1 for first inversion, etc.
		
		
			
				
			
		
	

	
		
			Kind indicates the type of chord. Degree elements can then add, subtract, or alter from these starting points
	
The attributes are used to indicate the formatting of the symbol. Since the kind element is the constant in all the harmony-chord groups that can make up a polychord, many formatting attributes are here.
	
The use-symbols attribute is yes if the kind should be represented when possible with harmony symbols rather than letters and numbers. These symbols include:
	
	major: a triangle, like Unicode 25B3
	minor: -, like Unicode 002D
	augmented: +, like Unicode 002B
	diminished: Β°, like Unicode 00B0
	half-diminished: ΓΈ, like Unicode 00F8
	
For the major-minor kind, only the minor symbol is used when use-symbols is yes. The major symbol is set using the symbol attribute in the degree-value element. The corresponding degree-alter value will usually be 0 in this case.

The text attribute describes how the kind should be spelled in a score. If use-symbols is yes, the value of the text attribute follows the symbol. The stack-degrees attribute is yes if the degree elements should be stacked above each other. The parentheses-degrees attribute is yes if all the degrees should be in parentheses. The bracket-degrees attribute is yes if all the degrees should be in a bracket. If not specified, these values are implementation-specific. The alignment attributes are for the entire harmony-chord group of which this kind element is a part.
		
		
			
				
				
				
				
				
				
				
				
			
		
	

	
		
			The measure-numbering type describes how frequently measure numbers are displayed on this part. The number attribute from the measure element is used for printing. Measures with an implicit attribute set to "yes" never display a measure number, regardless of the measure-numbering setting.
		
		
			
				
			
		
	

	
		
			The metronome type represents metronome marks and other metric relationships. The beat-unit group and per-minute element specify regular metronome marks. The metronome-note and metronome-relation elements allow for the specification of more complicated metric relationships, such as swing tempo marks where two eighths are equated to a quarter note / eighth note triplet. The parentheses attribute indicates whether or not to put the metronome mark in parentheses; its value is no if not specified.
		
		
			
				
				
					
					
				
			
			
				
				
					
						
							The metronome-relation element describes the relationship symbol that goes between the two sets of metronome-note elements. The currently allowed value is equals, but this may expand in future versions. If the element is empty, the equals value is used.
						
					
					
				
			
		
		
		
		
	

	
		
			The metronome-beam type works like the beam type in defining metric relationships, but does not include all the attributes available in the beam type.
		
		
			
				
			
		
	

	
		
			The metronome-note type defines the appearance of a note within a metric relationship mark.
		
		
			
				
					The metronome-type element works like the type element in defining metric relationships.
				
			
			
				
					The metronome-dot element works like the dot element in defining metric relationships.
				
			
			
			
		
	

	
		
			The metronome-tuplet type uses the same element structure as the time-modification element along with some attributes from the tuplet element.
		
		
			
				
				
				
			
		
	

	
		
			The octave shift type indicates where notes are shifted up or down from their true pitched values because of printing difficulty. Thus a treble clef line noted with 8va will be indicated with an octave-shift down from the pitch data indicated in the notes. A size of 8 indicates one octave; a size of 15 indicates two octaves.
		
		
		
		
		
		
	

	
		
			An offset is represented in terms of divisions, and indicates where the direction will appear relative to the current musical location. This affects the visual appearance of the direction. If the sound attribute is "yes", then the offset affects playback too. If the sound attribute is "no", then any sound associated with the direction takes effect at the current location. The sound attribute is "no" by default for compatibility with earlier versions of the MusicXML format. If an element within a direction includes a default-x attribute, the offset value will be ignored when determining the appearance of that element.
		
		
			
				
			
		
	

	
		
			The other-direction type is used to define any direction symbols not yet in the current version of the MusicXML format. This allows extended representation, though without application interoperability.
		
		
			
				
				
			
		
	

	
		
			The pedal type represents piano pedal marks. The line attribute is yes if pedal lines are used. The sign attribute is yes if Ped and * signs are used. For MusicXML 2.0 compatibility, the sign attribute is yes by default if the line attribute is no, and is no by default if the line attribute is yes. The change and continue types are used when the line attribute is yes. The change type indicates a pedal lift and retake indicated with an inverted V marking. The continue type allows more precise formatting across system breaks and for more complex pedaling lines. The alignment attributes are ignored if the line attribute is yes.
		
		
		
		
		
	

	
		
			The pedal-tuning type specifies the tuning of a single harp pedal.
		
		
			
				
					The pedal-step element defines the pitch step for a single harp pedal.
				
			
			
				
					The pedal-alter element defines the chromatic alteration for a single harp pedal.
				
			
		
	

	
		
			The per-minute type can be a number, or a text description including numbers. If a font is specified, it overrides the font specified for the overall metronome element. This allows separate specification of a music font for the beat-unit and a text font for the numeric value, in cases where a single metronome font is not used.
		
		
			
				
			
		
	

	
		
			The percussion element is used to define percussion pictogram symbols. Definitions for these symbols can be found in Kurt Stone's "Music Notation in the Twentieth Century" on pages 206-212 and 223. Some values are added to these based on how usage has evolved in the 30 years since Stone's book was published.
		
		
			
			
			
			
			
			
			
			
			
			
			
		
		
		
	

	
		
			The principal-voice element represents principal and secondary voices in a score, either for analysis or for square bracket symbols that appear in a score. The symbol attribute indicates the type of symbol used at the start of the principal-voice. The content of the principal-voice element is used for analysis and may be any text value. When used for analysis separate from any printed score markings, the symbol attribute should be set to "none".
		
		
			
				
				
				
			
		
	

	
		
			The print type contains general printing parameters, including the layout elements defined in the layout.mod file. The part-name-display and part-abbreviation-display elements used in the score.mod file may also be used here to change how a part name or abbreviation is displayed over the course of a piece. They take effect when the current measure or a succeeding measure starts a new system.
	
Layout elements in a print statement only apply to the current page, system, staff, or measure. Music that follows continues to take the default values from the layout included in the defaults element.
		
		
			
			
			
			
			
		
		
	

	
		
			The root type indicates a pitch like C, D, E vs. a function indication like I, II, III. It is used with chord symbols in popular music. The root element has a root-step and optional root-alter element similar to the step and alter elements, but renamed to distinguish the different musical meanings.
		
		
			
			
		
	

	
		
			The root-alter type represents the chromatic alteration of the root of the current chord within the harmony element. In some chord styles, the text for the root-step element may include root-alter information. In that case, the print-object attribute of the root-alter element can be set to no. The location attribute indicates whether the alteration should appear to the left or the right of the root-step; it is right by default.
		
		
			
				
				
				
			
		
	

	
		
			The root-step type represents the pitch step of the root of the current chord within the harmony element. The text attribute indicates how the root should appear in a score if not using the element contents.
		
		
			
				
				
			
		
	

	
		
			Scordatura string tunings are represented by a series of accord elements, similar to the staff-tuning elements. Strings are numbered from high to low.
		
		
			
		
	

	
		
			The sound element contains general playback parameters. They can stand alone within a part/measure, or be a component element within a direction.
	
Tempo is expressed in quarter notes per minute. If 0, the sound-generating program should prompt the user at the time of compiling a sound (MIDI) file.
	
Dynamics (or MIDI velocity) are expressed as a percentage of the default forte value (90 for MIDI 1.0).
	
Dacapo indicates to go back to the beginning of the movement. When used it always has the value "yes".
	
Segno and dalsegno are used for backwards jumps to a segno sign; coda and tocoda are used for forward jumps to a coda sign. If there are multiple jumps, the value of these parameters can be used to name and distinguish them. If segno or coda is used, the divisions attribute can also be used to indicate the number of divisions per quarter note. Otherwise sound and MIDI generating programs may have to recompute this.
	
By default, a dalsegno or dacapo attribute indicates that the jump should occur the first time through, while a tocoda attribute indicates the jump should occur the second time through. The time that jumps occur can be changed by using the time-only attribute.
	
Forward-repeat is used when a forward repeat sign is implied, and usually follows a bar line. When used it always has the value of "yes".
	
The fine attribute follows the final note or rest in a movement with a da capo or dal segno direction. If numeric, the value represents the actual duration of the final note or rest, which can be ambiguous in written notation and different among parts and voices. The value may also be "yes" to indicate no change to the final duration.
	
If the sound element applies only particular times through a repeat, the time-only attribute indicates which times to apply the sound element.
	
Pizzicato in a sound element effects all following notes. Yes indicates pizzicato, no indicates arco.

The pan and elevation attributes are deprecated in Version 2.0. The pan and elevation elements in the midi-instrument element should be used instead. The meaning of the pan and elevation attributes is the same as for the pan and elevation elements. If both are present, the mid-instrument elements take priority.
	
The damper-pedal, soft-pedal, and sostenuto-pedal attributes effect playback of the three common piano pedals and their MIDI controller equivalents. The yes value indicates the pedal is depressed; no indicates the pedal is released. A numeric value from 0 to 100 may also be used for half pedaling. This value is the percentage that the pedal is depressed. A value of 0 is equivalent to no, and a value of 100 is equivalent to yes.
	
MIDI devices, MIDI instruments, and playback techniques are changed using the midi-device, midi-instrument, and play elements. When there are multiple instances of these elements, they should be grouped together by instrument using the id attribute values.

The offset element is used to indicate that the sound takes place offset from the current score position. If the sound element is a child of a direction element, the sound offset element overrides the direction offset element if both elements are present. Note that the offset reflects the intended musical position for the change in sound. It should not be used to compensate for latency issues in particular hardware configurations.
		
		
			
				
				
				
			
			
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	
	
	
		
			The stick type represents pictograms where the material of the stick, mallet, or beater is included.
		
		
			
			
		
		
	

	
		
			The string-mute type represents string mute on and mute off symbols.
		
		
		
	
	
	
		
			The wedge type represents crescendo and diminuendo wedge symbols. The type attribute is crescendo for the start of a wedge that is closed at the left side, and diminuendo for the start of a wedge that is closed on the right side. Spread values are measured in tenths; those at the start of a crescendo wedge or end of a diminuendo wedge are ignored. The niente attribute is yes if a circle appears at the point of the wedge, indicating a crescendo from nothing or diminuendo to nothing. It is no by default, and used only when the type is crescendo, or the type is stop for a wedge that began with a diminuendo type. The line-type is solid by default.
		
		
		
		
		
		
		
		
		
	

	

	
		
			The encoding element contains information about who did the digital encoding, when, with what software, and in what aspects. Standard type values for the encoder element are music, words, and arrangement, but other types may be used. The type attribute is only needed when there are multiple encoder elements.
		
		
			
			
			
			
			
		
	

	
		
			Identification contains basic metadata about the score. It includes the information in MuseData headers that may apply at a score-wide, movement-wide, or part-wide level. The creator, rights, source, and relation elements are based on Dublin Core.
		
		
			
				
					The creator element is borrowed from Dublin Core. It is used for the creators of the score. The type attribute is used to distinguish different creative contributions. Thus, there can be multiple creators within an identification. Standard type values are composer, lyricist, and arranger. Other type values may be used for different types of creative roles. The type attribute should usually be used even if there is just a single creator element. The MusicXML format does not use the creator / contributor distinction from Dublin Core.
				
			
			
				
					The rights element is borrowed from Dublin Core. It contains copyright and other intellectual property notices. Words, music, and derivatives can have different types, so multiple rights tags with different type attributes are supported. Standard type values are music, words, and arrangement, but other types may be used. The type attribute is only needed when there are multiple rights elements.
				
			
			
			
				
					The source for the music that is encoded. This is similar to the Dublin Core source element.
				
			
			
				
					A related resource for the music that is encoded. This is similar to the Dublin Core relation element. Standard type values are music, words, and arrangement, but other types may be used.
				
			
			
		
	

	
		
			If a program has other metadata not yet supported in the MusicXML format, it can go in the miscellaneous element. The miscellaneous type puts each separate part of metadata into its own miscellaneous-field type.
		
		
			
		
	

	
		
			If a program has other metadata not yet supported in the MusicXML format, each type of metadata can go in a miscellaneous-field element. The required name attribute indicates the type of metadata the element content represents.
		
		
			
				
			
		
	

	
		
			The supports type indicates if a MusicXML encoding supports a particular MusicXML element. This is recommended for elements like beam, stem, and accidental, where the absence of an element is ambiguous if you do not know if the encoding supports that element. For Version 2.0, the supports element is expanded to allow programs to indicate support for particular attributes or particular values. This lets applications communicate, for example, that all system and/or page breaks are contained in the MusicXML file.
		
		
		
		
		
	

	

	
		
			The appearance type controls general graphical settings for the music's final form appearance on a printed page of display. This includes support for line widths, definitions for note sizes, and standard distances between notation elements, plus an extension element for other aspects of appearance.
		
		
			
			
			
			
		
	

	
		
			The distance element represents standard distances between notation elements in tenths. The type attribute defines what type of distance is being defined. Valid values include hyphen (for hyphens in lyrics) and beam.
		
		
			
				
			
		
	

	
		
			The line-width type indicates the width of a line type in tenths. The type attribute defines what type of line is being defined. Values include beam, bracket, dashes, enclosure, ending, extend, heavy barline, leger, light barline, octave shift, pedal, slur middle, slur tip, staff, stem, tie middle, tie tip, tuplet bracket, and wedge. The text content is expressed in tenths.
		
		
			
				
			
		
	

	
		
			The measure-layout type includes the horizontal distance from the previous measure.
		
		
			
				
					The measure-distance element specifies the horizontal distance from the previous measure. This value is only used for systems where there is horizontal whitespace in the middle of a system, as in systems with codas. To specify the measure width, use the width attribute of the measure element.
				
			
		
	

	
		
			The note-size type indicates the percentage of the regular note size to use for notes with a cue and large size as defined in the type element. The grace type is used for notes of cue size that that include a grace element. The cue type is used for all other notes with cue size, whether defined explicitly or implicitly via a cue element. The large type is used for notes of large size. The text content represent the numeric percentage. A value of 100 would be identical to the size of a regular note as defined by the music font.
		
		
			
				
			
		
	

	
		
			The other-appearance type is used to define any graphical settings not yet in the current version of the MusicXML format. This allows extended representation, though without application interoperability.
		
		
			
				
			
		
	

	
		
			Page layout can be defined both in score-wide defaults and in the print element. Page margins are specified either for both even and odd pages, or via separate odd and even page number values. The type is not needed when used as part of a print element. If omitted when used in the defaults element, "both" is the default.
		
		
			
				
				
			
			
		
	

	
		
			Page margins are specified either for both even and odd pages, or via separate odd and even page number values. The type attribute is not needed when used as part of a print element. If omitted when the page-margins type is used in the defaults element, "both" is the default value.
		
		
		
	
	
	
		
			Margins, page sizes, and distances are all measured in tenths to keep MusicXML data in a consistent coordinate system as much as possible. The translation to absolute units is done with the scaling type, which specifies how many millimeters are equal to how many tenths. For a staff height of 7 mm, millimeters would be set to 7 while tenths is set to 40. The ability to set a formula rather than a single scaling factor helps avoid roundoff errors.
		
		
			
			
		
	

	
		
			Staff layout includes the vertical distance from the bottom line of the previous staff in this system to the top line of the staff specified by the number attribute. The optional number attribute refers to staff numbers within the part, from top to bottom on the system. A value of 1 is assumed if not present. When used in the defaults element, the values apply to all parts. This value is ignored for the first staff in a system.
		
		
			
		
		
	

	
		
			The system-dividers element indicates the presence or absence of system dividers (also known as system separation marks) between systems displayed on the same page. Dividers on the left and right side of the page are controlled by the left-divider and right-divider elements respectively. The default vertical position is half the system-distance value from the top of the system that is below the divider. The default horizontal position is the left and right system margin, respectively.

When used in the print element, the system-dividers element affects the dividers that would appear between the current system and the previous system.
		
		
			
			
		
	

	
		
			A system is a group of staves that are read and played simultaneously. System layout includes left and right margins and the vertical distance from the previous system. The system distance is measured from the bottom line of the previous system to the top line of the current system. It is ignored for the first system on a page. The top system distance is measured from the page's top margin to the top line of the first system. It is ignored for all but the first system on a page.
	
Sometimes the sum of measure widths in a system may not equal the system width specified by the layout elements due to roundoff or other errors. The behavior when reading MusicXML files in these cases is application-dependent. For instance, applications may find that the system layout data is more reliable than the sum of the measure widths, and adjust the measure widths accordingly.
		
		
			
			
			
			
		
	

	
		
			System margins are relative to the page margins. Positive values indent and negative values reduce the margin size.
		
		
	

	

	
		
			The bookmark type serves as a well-defined target for an incoming simple XLink.
		
		
		
		
	

	
		
			The link type serves as an outgoing simple XLink. It is also used to connect a MusicXML score with a MusicXML opus. If a relative link is used within a document that is part of a compressed MusicXML file, the link is relative to the  root folder of the zip file.
		
		
		
		
		
	

	
	
	
		
			The accidental type represents actual notated accidentals. Editorial and cautionary indications are indicated by attributes. Values for these attributes are "no" if not present. Specific graphic display such as parentheses, brackets, and size are controlled by the level-display attribute group.
		
		
			
				
				
				
				
			
		
	

	
		
			An accidental-mark can be used as a separate notation or as part of an ornament. When used in an ornament, position and placement are relative to the ornament, not relative to the note.
		
		
			
				
				
			
		
	

	
		
			The arpeggiate type indicates that this note is part of an arpeggiated chord. The number attribute can be used to distinguish between two simultaneous chords arpeggiated separately (different numbers) or together (same number). The up-down attribute is used if there is an arrow on the arpeggio sign. By default, arpeggios go from the lowest to highest note.
		
		
		
		
		
		
	

	
		
			Articulations and accents are grouped together here.
		
		
			
				
					The accent element indicates a regular horizontal accent mark.
				
			
			
				
					The strong-accent element indicates a vertical accent mark.
				
			
			
				
					The staccato element is used for a dot articulation, as opposed to a stroke or a wedge.
				
			
			
				
					The tenuto element indicates a tenuto line symbol.
				
			
			
				
					The detached-legato element indicates the combination of a tenuto line and staccato dot symbol.
				
			
			
				
					The staccatissimo element is used for a wedge articulation, as opposed to a dot or a stroke.
				
			
			
				
					The spiccato element is used for a stroke articulation, as opposed to a dot or a wedge.
				
			
			
				
					The scoop element is an indeterminate slide attached to a single note. The scoop element appears before the main note and comes from below the main pitch.
				
			
			
				
					The plop element is an indeterminate slide attached to a single note. The plop element appears before the main note and comes from above the main pitch.
				
			
			
				
					The doit element is an indeterminate slide attached to a single note. The doit element appears after the main note and goes above the main pitch.
				
			
			
				
					The falloff element is an indeterminate slide attached to a single note. The falloff element appears before the main note and goes below the main pitch.
				
			
			
			
				
					The caesura element indicates a slight pause. It is notated using a "railroad tracks" symbol.
				
			
			
				
					The stress element indicates a stressed note.
				
			
			
				
					The unstress element indicates an unstressed note. It is often notated using a u-shaped symbol.
				
			
			
				
					The other-articulation element is used to define any articulations not yet in the MusicXML format. This allows extended representation, though without application interoperability.
				
			
		
	

	
		
			The arrow element represents an arrow used for a musical technical indication..
		
		
			
				
				
			
			
		
		
		
	

	
		
			The backup and forward elements are required to coordinate multiple voices in one part, including music on multiple staves. The backup type is generally used to move between voices and staves. Thus the backup element does not include voice or staff elements. Duration values should always be positive, and should not cross measure boundaries or mid-measure changes in the divisions value.
		
		
			
			
		
	

	
		
			Beam values include begin, continue, end, forward hook, and backward hook. Up to eight concurrent beams are available to cover up to 1024th notes. Each beam in a note is represented with a separate beam element, starting with the eighth note beam using a number attribute of 1.

Note that the beam number does not distinguish sets of beams that overlap, as it does for slur and other elements. Beaming groups are distinguished by being in different voices and/or the presence or absence of grace and cue elements.

Beams that have a begin value can also have a fan attribute to indicate accelerandos and ritardandos using fanned beams. The fan attribute may also be used with a continue value if the fanning direction changes on that note. The value is "none" if not specified.
	
The repeater attribute has been deprecated in MusicXML 3.0. Formerly used for tremolos, it needs to be specified with a "yes" value for each beam using it.
		
		
			
				
				
				
				
			
		
	

	
		
			The bend type is used in guitar and tablature. The bend-alter element indicates the number of steps in the bend, similar to the alter element. As with the alter element, numbers like 0.5 can be used to indicate microtones. Negative numbers indicate pre-bends or releases; the pre-bend and release elements are used to distinguish what is intended. A with-bar element indicates that the bend is to be done at the bridge with a whammy or vibrato bar. The content of the element indicates how this should be notated.
		
		
			
				
					The bend-alter element indicates the number of steps in the bend, similar to the alter element. As with the alter element, numbers like 0.5 can be used to indicate microtones. Negative numbers indicate pre-bends or releases; the pre-bend and release elements are used to distinguish what is intended.
				
			
			
				
					
						The pre-bend element indicates that this is a pre-bend rather than a normal bend or a release.
					
				
				
					
						The release element indicates that this is a release rather than a normal bend or pre-bend.
					
				
			
			
				
					The with-bar element indicates that the bend is to be done at the bridge with a whammy or vibrato bar. The content of the element indicates how this should be notated.
				
			
		
		
		
	

	
		
			The breath-mark element indicates a place to take a breath.
		
		
			
				
				
			
		
	

	
		
			The empty-line type represents an empty element with line-shape, line-type, dashed-formatting, print-style and placement attributes.
		
		
		
		
		
		
	
	
	
		
			The extend type represents lyric word extension / melisma lines as well as figured bass extensions. The optional type and position attributes are added in Version 3.0 to provide better formatting control.
		
		
		
	

	
		
			The figure type represents a single figure within a figured-bass element.
		
		
			
				
					Values for the prefix element include the accidental values sharp, flat, natural, double-sharp, flat-flat, and sharp-sharp. The prefix element may contain additional values for symbols specific to particular figured bass styles.
				
			
			
				
					A figure-number is a number. Overstrikes of the figure number are represented in the suffix element.
				
			
			
				
					Values for the suffix element include the accidental values sharp, flat, natural, double-sharp, flat-flat, and sharp-sharp. Suffixes include both symbols that come after the figure number and those that overstrike the figure number. The suffix value slash is used for slashed numbers indicating chromatic alteration. The orientation and display of the slash usually depends on the figure number. The suffix element may contain additional values for symbols specific to particular figured bass styles.
				
			
			
		
	

	
		
			The figured-bass element represents figured bass notation. Figured bass elements take their position from the first regular note (not a grace note or chord note) that follows in score order. The optional duration element is used to indicate changes of figures under a note.
	
Figures are ordered from top to bottom. The value of parentheses is "no" if not present.
		
		
			
			
			
		
		
		
		
	

	
		
			The backup and forward elements are required to coordinate multiple voices in one part, including music on multiple staves. The forward element is generally used within voices and staves. Duration values should always be positive, and should not cross measure boundaries or mid-measure changes in the divisions value.
		
		
			
			
			
		
	

	
		
			Glissando and slide types both indicate rapidly moving from one pitch to the other so that individual notes are not discerned. The distinction is similar to that between NIFF's glissando and portamento elements. A glissando sounds the half notes in between the slide and defaults to a wavy line. The optional text is printed alongside the line.
		
		
			
				
				
				
				
				
			
		
	

	
		
			The grace type indicates the presence of a grace note. The slash attribute for a grace note is yes for slashed eighth notes. The other grace note attributes come from MuseData sound suggestions. The steal-time-previous attribute indicates the percentage of time to steal from the previous note for the grace note. The steal-time-following attribute indicates the percentage of time to steal from the following note for the grace note, as for appoggiaturas. The make-time attribute indicates to make time, not steal time; the units are in real-time divisions for the grace note.
		
		
		
		
		
	

	
		
			The hammer-on and pull-off elements are used in guitar and fretted instrument notation. Since a single slur can be marked over many notes, the hammer-on and pull-off elements are separate so the individual pair of notes can be specified. The element content can be used to specify how the hammer-on or pull-off should be notated. An empty element leaves this choice up to the application.
		
		
			
				
				
				
				
			
		
	

	
		
			The handbell element represents notation for various techniques used in handbell and handchime music.
		
		
			
				
				
			
		
	

	
		
			The harmonic type indicates natural and artificial harmonics. Allowing the type of pitch to be specified, combined with controls for appearance/playback differences, allows both the notation and the sound to be represented. Artificial harmonics can add a notated touching-pitch; artificial pinch harmonics will usually not notate a touching pitch. The attributes for the harmonic element refer to the use of the circular harmonic symbol, typically but not always used with natural harmonics.
		
		
			
				
					
						The natural element indicates that this is a natural harmonic. These are usually notated at base pitch rather than sounding pitch.
					
				
				
					
						The artificial element indicates that this is an artificial harmonic.
					
				
			
			
				
					
						The base pitch is the pitch at which the string is played before touching to create the harmonic.
					
				
				
					
						The touching-pitch is the pitch at which the string is touched lightly to produce the harmonic.
					
				
				
					
						The sounding-pitch is the pitch which is heard when playing the harmonic.
					
				
			
		
		
		
		
	

	
		
			The heel and toe elements are used with organ pedals. The substitution value is "no" if the attribute is not present.
		
		
			
				
			
		
	

	
		
			The hole type represents the symbols used for woodwind and brass fingerings as well as other notations.
		
		
			
				
					The content of the optional hole-type element indicates what the hole symbol represents in terms of instrument fingering or other techniques.
				
			
			
			
				
					The optional hole-shape element indicates the shape of the hole symbol; the default is a circle.
				
			
		
		
		
	
	
	
		
			The hole-closed type represents whether the hole is closed, open, or half-open. The optional location attribute indicates which portion of the hole is filled in when the element value is half.
		
		
			
				
			
		
	
	
	
		
			The instrument type distinguishes between score-instrument elements in a score-part. The id attribute is an IDREF back to the score-instrument ID. If multiple score-instruments are specified on a score-part, there should be an instrument element for each note in the part.
		
		
	

	
		
			The lyric type represents text underlays for lyrics, based on Humdrum with support for other formats. Two text elements that are not separated by an elision element are part of the same syllable, but may have different text formatting. The MusicXML 2.0 XSD is more strict than the 2.0 DTD in enforcing this by disallowing a second syllabic element unless preceded by an elision element. The lyric number indicates multiple lines, though a name can be used as well (as in Finale's verse / chorus / section specification). Justification is center by default; placement is below by default. The content of the elision type is used to specify the symbol used to display the elision. Common values are a no-break space (Unicode 00A0), an underscore (Unicode 005F), or an undertie (Unicode 203F).
		
		
			
				
					
					
					
						
							
							
						
						
					
					
				
				
				
					
						The laughing element is taken from Humdrum.
					
				
				
					
						The humming element is taken from Humdrum.
					
				
			
			
				
					The end-line element comes from RP-017 for Standard MIDI File Lyric meta-events. It facilitates lyric display for Karaoke and similar applications.
				
			
			
				
					The end-paragraph element comes from RP-017 for Standard MIDI File Lyric meta-events. It facilitates lyric display for Karaoke and similar applications.
				
			
			
		
		
		
		
		
		
		
		
	

	
		
			The mordent type is used for both represents the mordent sign with the vertical line and the inverted-mordent sign without the line. The long attribute is "no" by default. The approach and departure attributes are used for compound ornaments, indicating how the beginning and ending of the ornament look relative to the main part of the mordent.
		
		
			
				
				
				
			
		
	

	
		
			The non-arpeggiate type indicates that this note is at the top or bottom of a bracket indicating to not arpeggiate these notes. Since this does not involve playback, it is only used on the top or bottom notes, not on each note as for the arpeggiate type.
	
		
		
		
		
		
	

	
		
			Notations refer to musical notations, not XML notations. Multiple notations are allowed in order to represent multiple editorial levels. The print-object attribute, added in Version 3.0, allows notations to represent details of performance technique, such as fingerings, without having them appear in the score.
		
		
			
			
				
				
				
				
				
				
				
				
				
				
				
				
				
				
			
		
		
	

	
		
			Notes are the most common type of MusicXML data. The MusicXML format keeps the MuseData distinction between elements used for sound information and elements used for notation information (e.g., tie is used for sound, tied for notation). Thus grace notes do not have a duration element. Cue notes have a duration element, as do forward elements, but no tie elements. Having these two types of information available can make interchange considerably easier, as some programs handle one type of information much more readily than the other. 
	
The dynamics and end-dynamics attributes correspond to MIDI 1.0's Note On and Note Off velocities, respectively. They are expressed in terms of percentages of the default forte value (90 for MIDI 1.0). The attack and release attributes are used to alter the starting and stopping time of the note from when it would otherwise occur based on the flow of durations - information that is specific to a performance. They are expressed in terms of divisions, either positive or negative. A note that starts a tie should not have a release attribute, and a note that stops a tie should not have an attack attribute. If a note is played only particular times through a repeat, the time-only attribute shows which times to play the note. The pizzicato attribute is used when just this note is sounded pizzicato, vs. the pizzicato element which changes overall playback between pizzicato and arco.
		
		
			
				
					
					
					
				
				
					
						
							The cue element indicates the presence of a cue note.
						
					
					
					
				
				
					
					
					
				
			
			
			
			
			
				
					One dot element is used for each dot of prolongation. The placement element is used to specify whether the dot should appear above or below the staff line. It is ignored for notes that appear on a staff space.
				
			
			
			
			
			
			
			
			
			
			
			
		
		
		
		
		
		
		
		
		
		
		
	

	
		
			The note-type type indicates the graphic note type. Values range from 256th to long. The size attribute indicates full, cue, or large size, with full the default for regular notes and cue the default for cue and grace notes.
		
		
			
				
			
		
	

	
		
			The notehead element indicates shapes other than the open and closed ovals associated with note durations.
	
For the enclosed shapes, the default is to be hollow for half notes and longer, and filled otherwise. The filled attribute can be set to change this if needed.
	
If the parentheses attribute is set to yes, the notehead is parenthesized. It is no by default.
		
		
			
				
				
				
				
			
		
	

	
		
			The notehead-text type represents text that is displayed inside a notehead, as is done in some educational music. It is not needed for the numbers used in tablature or jianpu notation. The presence of a TAB or jianpu clefs is sufficient to indicate that numbers are used. The display-text and accidental-text elements allow display of fully formatted text and accidentals.
		
		
			
				
				
			
		
	
	
	
		
			Ornaments can be any of several types, followed optionally by accidentals. The accidental-mark element's content is represented the same as an accidental element, but with a different name to reflect the different musical meaning.
		
		
			
				
					
						The trill-mark element represents the trill-mark symbol.
					
				
				
					
						The turn element is the normal turn shape which goes up then down.
					
				
				
					
						The delayed-turn element indicates a normal turn that is delayed until the end of the current note.
					
				
				
					
						The inverted-turn element has the shape which goes down and then up.
					
				
				
					
						The delayed-inverted-turn element indicates an inverted turn that is delayed until the end of the current note.
					
				
				
					
						The vertical-turn element has the turn symbol shape arranged vertically going from upper left to lower right.
					
				
				
					
						The shake element has a similar appearance to an inverted-mordent element.
					
				
				
				
					
						The mordent element represents the sign with the vertical line. The long attribute is "no" by default.
					
				
				
					
						The inverted-mordent element represents the sign without the vertical line. The long attribute is "no" by default.
					
				
				
					
						The name for this ornament is based on the German, to avoid confusion with the more common slide element defined earlier.
					
				
				
				
					
						The other-ornament element is used to define any ornaments not yet in the MusicXML format. This allows extended representation, though without application interoperability.
					
				
			
			
		
	

	
		
			The other-notation type is used to define any notations not yet in the MusicXML format. This allows extended representation, though without application interoperability. It handles notations where more specific extension elements such as other-dynamics and other-technical are not appropriate.
		
		
			
				
				
				
				
				
			
		
	

	
		
			Pitch is represented as a combination of the step of the diatonic scale, the chromatic alteration, and the octave.
		
		
			
			
			
		
	

	
		
			The placement-text type represents a text element with print-style and placement attribute groups.
		
		
			
				
				
			
		
	
	
	
		
			The rest element indicates notated rests or silences. Rest elements are usually empty, but placement on the staff can be specified using display-step and display-octave elements. If the measure attribute is set to yes, this indicates this is a complete measure rest.
		
		
			
		
		
	
	
	
		
			Glissando and slide types both indicate rapidly moving from one pitch to the other so that individual notes are not discerned. The distinction is similar to that between NIFF's glissando and portamento elements. A slide is continuous between two notes and defaults to a solid line. The optional text for a is printed alongside the line.
		
		
			
				
				
				
				
				
				
			
		
	

	
		
			Slur types are empty. Most slurs are represented with two elements: one with a start type, and one with a stop type. Slurs can add more elements using a continue type. This is typically used to specify the formatting of cross-system slurs, or to specify the shape of very complex slurs.
		
		
		
		
		
		
		
		
		
		
	

	
		
			Stems can be down, up, none, or double. For down and up stems, the position attributes can be used to specify stem length. The relative values specify the end of the stem relative to the program default. Default values specify an absolute end stem position. Negative values of relative-y that would flip a stem instead of shortening it are ignored. A stem element associated with a rest refers to a stemlet.
		
		
			
				
				
			
		
	

	
		
			The strong-accent type indicates a vertical accent mark. The type attribute indicates if the point of the accent is down or up.
		
		
			
				
			
		
	

	
		
			The style-text type represents a text element with a print-style attribute group.
		
		
			
				
			
		
	
	
	
		
			Technical indications give performance information for individual instruments.
		
		
			
				
					The up-bow element represents the symbol that is used both for up-bowing on bowed instruments, and up-stroke on plucked instruments.
				
			
			
				
					The down-bow element represents the symbol that is used both for down-bowing on bowed instruments, and down-stroke on plucked instruments.
				
			
			
			
				
					The open-string element represents the zero-shaped open string symbol.
				
			
			
				
					The thumb-position element represents the thumb position symbol. This is a circle with a line, where the line does not come within the circle. It is distinct from the snap pizzicato symbol, where the line comes inside the circle.
				
			
			
			
				
					The pluck element is used to specify the plucking fingering on a fretted instrument, where the fingering element refers to the fretting fingering. Typical values are p, i, m, a for pulgar/thumb, indicio/index, medio/middle, and anular/ring fingers.
				
			
			
				
					The double-tongue element represents the double tongue symbol (two dots arranged horizontally).
				
			
			
				
					The triple-tongue element represents the triple tongue symbol (three dots arranged horizontally).
				
			
			
				
					The stopped element represents the stopped symbol, which looks like a plus sign.
				
			
			
				
						The snap-pizzicato element represents the snap pizzicato symbol. This is a circle with a line, where the line comes inside the circle. It is distinct from the thumb-position symbol, where the line does not come inside the circle.
				
			
			
			
			
			
			
			
				
					The tap element indicates a tap on the fretboard. The element content allows specification of the notation; + and T are common choices. If empty, the display is application-specific.
				
			
			
			
			
				
					The fingernails element is used in notation for harp and other plucked string instruments.
				
			
			
			
			
			
				
					The other-technical element is used to define any technical indications not yet in the MusicXML format. This allows extended representation, though without application interoperability.
				
			
		
	

	
		
			The text-element-data type represents a syllable or portion of a syllable for lyric text underlay. A hyphen in the string content should only be used for an actual hyphenated word. Language names for text elements come from ISO 639, with optional country subcodes from ISO 3166.
		
		
			
				
				
				
				
				
				
				
			
		
	

	
		
			The text-font-color type represents text with optional font and color information. It is used for the elision element.
		
		
			
				
				
				
				
				
				
				
			
		
	

	
		
			The tie element indicates that a tie begins or ends with this note. If the tie element applies only particular times through a repeat, the time-only attribute indicates which times to apply it. The tie element indicates sound; the tied element indicates notation.
		
		
		
	

	
		
			The tied type represents the notated tie. The tie element represents the tie sound.

The number attribute is rarely needed to disambiguate ties, since note pitches will usually suffice. The attribute is implied rather than defaulting to 1 as with most elements. It is available for use in more complex tied notation situations.
		
		
		
		
		
		
		
		
		
		
	

	
		
			Time modification indicates tuplets, double-note tremolos, and other durational changes. A time-modification element shows how the cumulative, sounding effect of tuplets and double-note tremolos compare to the written note type represented by the type and dot elements. Nested tuplets and other notations that use more detailed information need both the time-modification and tuplet elements to be represented accurately.
		
		
			
				
					The actual-notes element describes how many notes are played in the time usually occupied by the number in the normal-notes element.
				
			
			
				
					The normal-notes element describes how many notes are usually played in the time occupied by the number in the actual-notes element.
				
			
			
				
					
						If the type associated with the number in the normal-notes element is different than the current note type (e.g., a quarter note within an eighth note triplet), then the normal-notes type (e.g. eighth) is specified in the normal-type and normal-dot elements.
					
				
				
					
						The normal-dot element is used to specify dotted normal tuplet types.
					
				
			
		
	

	
		
				The tremolo ornament can be used to indicate either single-note or double-note tremolos. Single-note tremolos use the single type, while double-note tremolos use the start and stop types. The default is "single" for compatibility with Version 1.1. The text of the element indicates the number of tremolo marks and is an integer from 0 to 8. Note that the number of attached beams is not included in this value, but is represented separately using the beam element.

When using double-note tremolos, the duration of each note in the tremolo should correspond to half of the notated type value. A time-modification element should also be added with an actual-notes value of 2 and a normal-notes value of 1. If used within a tuplet, this 2/1 ratio should be multiplied by the existing tuplet ratio.

Using repeater beams for indicating tremolos is deprecated as of MusicXML 3.0.
		
		
			
				
				
				
			
		
	

	
		
			A tuplet element is present when a tuplet is to be displayed graphically, in addition to the sound data provided by the time-modification elements. The number attribute is used to distinguish nested tuplets. The bracket attribute is used to indicate the presence of a bracket. If unspecified, the results are implementation-dependent. The line-shape attribute is used to specify whether the bracket is straight or in the older curved or slurred style. It is straight by default.
	
Whereas a time-modification element shows how the cumulative, sounding effect of tuplets and double-note tremolos compare to the written note type, the tuplet element describes how this is displayed. The tuplet element also provides more detailed representation information than the time-modification element, and is needed to represent nested tuplets and other complex tuplets accurately. 
	
The show-number attribute is used to display either the number of actual notes, the number of both actual and normal notes, or neither. It is actual by default. The show-type attribute is used to display either the actual type, both the actual and normal types, or neither. It is none by default.
		
		
			
				
					The tuplet-actual element provide optional full control over how the actual part of the tuplet is displayed, including number and note type (with dots). If any of these elements are absent, their values are based on the time-modification element.
				
			
			
				
					The tuplet-normal element provide optional full control over how the normal part of the tuplet is displayed, including number and note type (with dots). If any of these elements are absent, their values are based on the time-modification element.
				
			
		
		
		
		
		
		
		
		
		
	

	
		
			The tuplet-dot type is used to specify dotted normal tuplet types.
		
		
		
	

	
		
			The tuplet-number type indicates the number of notes for this portion of the tuplet.
		
		
			
				
				
			
		
	

	
		
			The tuplet-portion type provides optional full control over tuplet specifications. It allows the number and note type (including dots) to be set for the actual and normal portions of a single tuplet. If any of these elements are absent, their values are based on the time-modification element.
		
		
			
			
			
		
	
	
	
		
			The tuplet-type type indicates the graphical note type of the notes for this portion of the tuplet.
		
		
			
				
				
			
		
	

	
		
			The unpitched type represents musical elements that are notated on the staff but lack definite pitch, such as unpitched percussion and speaking voice.
		
		
			
		
	
	
	

	
		
			The credit type represents the appearance of the title, composer, arranger, lyricist, copyright, dedication, and other text and graphics that commonly appears on the first page of a score. The credit-words and credit-image elements are similar to the words and image elements for directions. However, since the credit is not part of a measure, the default-x and default-y attributes adjust the origin relative to the bottom left-hand corner of the first page. The enclosure for credit-words is none by default.
	
By default, a series of credit-words elements within a single credit element follow one another in sequence visually. Non-positional formatting attributes are carried over from the previous element by default.
	
The page attribute for the credit element, new in Version 2.0, specifies the page number where the credit should appear. This is an integer value that starts with 1 for the first page. Its value is 1 by default. Since credits occur before the music, these page numbers do not refer to the page numbering specified by the print element's page-number attribute.

The credit-type element, new in Version 3.0, indicates the purpose behind a credit. Multiple types of data may be combined in a single credit, so multiple elements may be used. Standard values include page number, title, subtitle, composer, arranger, lyricist, and rights.

		
		
			
			
			
			
				
				
					
					
						
						
						
					
				
			
		
		
	

	
		
			The defaults type specifies score-wide defaults for scaling, layout, and appearance.
		
		
			
			
			
			
			
			
			
		
	

	
		
			The empty-font type represents an empty element with font attributes.
		
		
	

	
		
			The group-barline type indicates if the group should have common barlines.
		
		
			
				
			
		
	

	
		
			The group-name type describes the name or abbreviation of a part-group element. Formatting attributes in the group-name type are deprecated in Version 2.0 in favor of the new group-name-display and group-abbreviation-display elements.
		
		
			
				
			
		
	

	
		
			The group-symbol type indicates how the symbol for a group is indicated in the score.
		
		
			
				
				
			
		
	

	
		
			The lyric-font type specifies the default font for a particular name and number of lyric.
		
		
		
		
	

	
		
			The lyric-language type specifies the default language for a particular name and number of lyric.
		
		
		
		
	

	
		
			The opus type represents a link to a MusicXML opus document that composes multiple MusicXML scores into a collection.
		
		
	

	
		
			The part-group element indicates groupings of parts in the score, usually indicated by braces and brackets. Braces that are used for multi-staff parts should be defined in the attributes element for that part. The part-group start element appears before the first score-part in the group. The part-group stop element appears after the last score-part in the group.
	
The number attribute is used to distinguish overlapping and nested part-groups, not the sequence of groups. As with parts, groups can have a name and abbreviation. Values for the child elements are ignored at the stop of a group. 
	
A part-group element is not needed for a single multi-staff part. By default, multi-staff parts include a brace symbol and (if appropriate given the bar-style) common barlines. The symbol formatting for a multi-staff part can be more fully specified using the part-symbol element.
		
		
			
			
				
					Formatting specified in the group-name-display element overrides formatting specified in the group-name element.
				
			
			
			
				
					Formatting specified in the group-abbreviation-display element overrides formatting specified in the group-abbreviation element.
				
			
			
			
			
				
					The group-time element indicates that the displayed time signatures should stretch across all parts and staves in the group.
				
			
			
		
		
		
	

	
		
			The part-list identifies the different musical parts in this movement. Each part has an ID that is used later within the musical data. Since parts may be encoded separately and combined later, identification elements are present at both the score and score-part levels. There must be at least one score-part, combined as desired with part-group elements that indicate braces and brackets. Parts are ordered from top to bottom in a score based on the order in which they appear in the part-list.
		
		
			
			
			
				
				
			
		
	
	
	
		
			The part-name type describes the name or abbreviation of a score-part element. Formatting attributes for the part-name element are deprecated in Version 2.0 in favor of the new part-name-display and part-abbreviation-display elements.
		
		
			
				
			
		
	

	
		
			The score-instrument type represents a single instrument within a score-part. As with the score-part type, each score-instrument has a required ID attribute, a name, and an optional abbreviation.
	
A score-instrument type is also required if the score specifies MIDI 1.0 channels, banks, or programs. An initial midi-instrument assignment can also be made here. MusicXML software should be able to automatically assign reasonable channels and instruments without these elements in simple cases, such as where part names match General MIDI instrument names.
		
		
			
				
					The instrument-name element is typically used within a software application, rather than appearing on the printed page of a score.
				
			
			
				
					The optional instrument-abbreviation element is typically used within a software application, rather than appearing on the printed page of a score.
				
			
			
				
					The instrument-sound element describes the default timbre of the score-instrument. This description is independent of a particular virtual or MIDI instrument specification and allows playback to be shared more easily between applications and libraries.
				
			
			
				
					
						The solo element was added in Version 2.0. It is present if performance is intended by a solo instrument.
					
				
				
					
						The ensemble element was added in Version 2.0. It is present if performance is intended by an ensemble such as an orchestral section. The text of the ensemble element contains the size of the section, or is empty if the ensemble size is not specified.
					
				
			
			
		
		
	

	
		
			Each MusicXML part corresponds to a track in a Standard MIDI Format 1 file. The score-instrument elements are used when there are multiple instruments per track. The midi-device element is used to make a MIDI device or port assignment for the given track or specific MIDI instruments. Initial midi-instrument assignments may be made here as well.
		
		
			
			
			
			
			
			
				
					The group element allows the use of different versions of the part for different purposes. Typical values include score, parts, sound, and data. Ordering information that is directly encoded in MuseData can be derived from the ordering within a MusicXML score or opus.
				
			
			
			
				
				
			
		
		
	

	
		
			The virtual-instrument element defines a specific virtual instrument used for an instrument sound.
		
		
			
				
					The virtual-library element indicates the virtual instrument library name.
				
			
			
				
					The virtual-name element indicates the library-specific name for the virtual instrument.
				
			
		
	

	
		
			Works are optionally identified by number and title. The work type also may indicate a link to the opus document that composes multiple scores into a collection.
		
		
			
				
					The work-number element specifies the number of a work, such as its opus number.
				
			
			
				
					The work-title element specifies the title of a work, not including its opus or other work number.
				
			
			
		
	

	
	
	
		
			The editorial group specifies editorial information for a musical element.
		
		
			
			
		
	

	
		
			The editorial-voice group supports the common combination of editorial and voice information for a musical element.
		
		
			
			
			
		
	

	
		
			The editorial-voice-direction group supports the common combination of editorial and voice information for a direction element. It is separate from the editorial-voice element because extensions and restrictions might be different for directions than for the note and forward elements.
		
		
			
			
			
		
	

	
		
			The footnote element specifies editorial information that appears in footnotes in the printed score. It is defined within a group due to its multiple uses within the MusicXML schema.
		
		
			
		
	

	
		
			The level element specifies editorial information for different MusicXML elements. It is defined within a group due to its multiple uses within the MusicXML schema.
		
		
			
		
	

	
		
			The staff element is defined within a group due to its use by both notes and direction elements.
		
		
			
				
					Staff assignment is only needed for music notated on multiple staves. Used by both notes and directions. Staff values are numbers, with 1 referring to the top-most staff in a part.
				
			
		
	

	
		
			The tuning group contains the sequence of elements common to the staff-tuning and accord elements.
		
		
			
				
					The tuning-step element is represented like the step element, with a different name to reflect is different function.
				
			
			
				
					The tuning-alter element is represented like the alter element, with a different name to reflect is different function.
				
			
			
				
					The tuning-octave element is represented like the octave element, with a different name to reflect is different function.
				
			
		
	

	
		
			The voice is used to distinguish between multiple voices (what MuseData calls tracks) in individual parts. It is defined within a group due to its multiple uses within the MusicXML schema.
		
		
			
		
	

	

	
		
			The non-traditional-key group represents a single alteration within a non-traditional key signature. A sequence of these groups makes up a non-traditional key signature
		
		
			
				
					Non-traditional key signatures can be represented using the Humdrum/Scot concept of a list of altered tones. The key-step element indicates the pitch step to be altered, represented using the same names as in the step element.
				
			
			
				
					Non-traditional key signatures can be represented using the Humdrum/Scot concept of a list of altered tones. The key-alter element represents the alteration for a given pitch step, represented with semitones in the same manner as the alter element.
				
			
			
				
					Non-traditional key signatures can be represented using the Humdrum/Scot concept of a list of altered tones. The key-accidental element indicates the accidental to be displayed in the key signature, represented in the same manner as the accidental element. It is used for disambiguating microtonal accidentals.
				
			
		
	

	
		
			The slash group combines elements used for more complete specification of the slash and beat-repeat measure-style elements. They have the same values as the type and dot elements, and define what the beat is for the display of repetition marks. If not present, the beat is based on the current time signature.
		
		
			
				
					The slash-type element indicates the graphical note type to use for the display of repetition marks.
				
			
			
				
					The slash-dot element is used to specify any augmentation dots in the note type used to display repetition marks.
				
			
		
	

	
		
			Time signatures are represented by the beats element for the numerator and the beat-type element for the denominator.
		
		
			
				
					The beats element indicates the number of beats, as found in the numerator of a time signature.
				
			
			
				
					The beat-type element indicates the beat unit, as found in the denominator of a time signature.
				
			
		
	

	
		
			The traditional-key group represents a traditional key signature using the cycle of fifths.
		
		
			
			
			
		
	

	

	
		
			The beat-unit group combines elements used repeatedly in the metronome element to specify a note within a metronome mark.
		
		
			
				
					The beat-unit element indicates the graphical note type to use in a metronome mark.
				
			
			
				
					The beat-unit-dot element is used to specify any augmentation dots for a metronome mark note.
				
			
		
	

	
		
			A harmony element can contain many stacked chords (e.g. V of II). A sequence of harmony-chord groups is used for this type of secondary function, where V of II would be represented by a harmony-chord with a V function followed by a harmony-chord with a II function.
	
A root is a pitch name like C, D, E, where a function is an indication like I, II, III. It is an either/or choice to avoid data inconsistency.
		
		
			
				
				
					
						The function element is used to represent classical functional harmony with an indication like I, II, III rather than C, D, E. It is relative to the key that is specified in the MusicXML encoding.
					
				
			
			
			
			
			
		
	

	

	
		
			The all-margins group specifies both horizontal and vertical margins in tenths.
		
		
			
			
			
		
	

	
		
			The layout group specifies the sequence of page, system, and staff layout elements that is common to both the defaults and print elements.
		
		
			
			
			
		
	

	
		
			The left-right-margins group specifies horizontal margins in tenths.
		
		
			
			
		
	

	

	
		
			The duration element is defined within a group due to its uses within the note, figure-bass, backup, and forward elements.
		
		
			
				
					Duration is a positive number specified in division units. This is the intended duration vs. notated duration (for instance, swing eighths vs. even eighths, or differences in dotted notes in Baroque-era music). Differences in duration specific to an interpretation or performance should use the note element's attack and release attributes.
				
			
		
	

	
		
			The display-step-octave group contains the sequence of elements used by both the rest and unpitched elements. This group is used to place rests and unpitched elements on the staff without implying that these elements have pitch. Positioning follows the current clef. If percussion clef is used, the display-step and display-octave elements are interpreted as if in treble clef, with a G in octave 4 on line 2. If not present, the note is placed on the middle line of the staff, generally used for a one-line staff.
		
		
			
			
		
	

	
		
			The full-note group is a sequence of the common note elements between cue/grace notes and regular (full) notes: pitch, chord, and rest information, but not duration (cue and grace notes do not have duration encoded). Unpitched elements are used for unpitched percussion, speaking voice, and other musical elements lacking determinate pitch.
		
		
			
				
					The chord element indicates that this note is an additional chord tone with the preceding note. The duration of this note can be no longer than the preceding note. In MuseData, a missing duration indicates the same length as the previous note, but the MusicXML format requires a duration for chord notes too.
				
			
			
				
				
				
			
		
	

	

	
		
			The music-data group contains the basic musical data that is either associated with a part or a measure, depending on whether the partwise or timewise hierarchy is used.
		
		
			
				
				
				
				
				
								
				
				
				
				
				
				
				
			
		
	

	
		
			The part-group element is defined within a group due to its multiple uses within the part-list element.
		
		
			
			
		
	

	
		
			The score-header group contains basic score metadata about the work and movement, score-wide defaults for layout and fonts, credits that appear on the first or following pages, and the part list.
		
		
			
			
				
					The movement-number element specifies the number of a movement.
				
			
			
				
					The movement-title element specifies the title of a movement, not including its number.
				
			
			
			
			
			
		
	

	
		
			The score-part element is defined within a group due to its multiple uses within the part-list element.
		
		
			
				
					Each MusicXML part corresponds to a track in a Standard MIDI Format 1 file. The score-instrument elements are used when there are multiple instruments per track. The midi-device element is used to make a MIDI device or port assignment for the given track. Initial midi-instrument assignments may be made here as well.
				
			
		
	

	
		The score is the root element for the schema. It includes the score-header group, followed either by a series of parts with measures inside (score-partwise) or a series of measures with parts inside (score-timewise). Having distinct top-level elements for partwise and timewise scores makes it easy to ensure that an XSLT stylesheet does not try to transform a document already in the desired format.
	

	
		
			The score-partwise element is the root element for a partwise MusicXML score. It includes a score-header group followed by a series of parts with measures inside. The document-attributes attribute group includes the version attribute.
		
		
			
				
				
					
						
							
								
									
									
								
							
						
						
					
				
			
			
		
	

	
		
			The score-timewise element is the root element for a timewise MusicXML score. It includes a score-header group followed by a series of measures with parts inside. The document-attributes attribute group includes the version attribute.
		
		
			
				
				
					
						
							
								
									
									
								
							
						
						
					
				
			
			
		
	


python_ly-0.9.9/tests/test_xml.py0000644000000000000000000000724113615410400014055 0ustar00"""Tests for XML output."""
import datetime
import difflib
import glob
import ly.musicxml
from lxml import etree
import os
import os.path
import io
import pytest
import re
import sys


def test_glissando():
    compare_output('glissando')


def test_tie():
    compare_output('tie')


def test_merge_voice():
    compare_output('merge_voice')


def test_variable():
    compare_output('variable')


def test_dynamics():
    compare_output('dynamics')


def test_tuplet():
    compare_output('tuplet')

def test_merge_voice_slurs():
    compare_output('merge_voice_slurs')

def test_break():
    compare_output('break')


def test_mark():
    compare_output('mark')


@pytest.mark.xfail
def test_partial():
    compare_output('partial')


def test_full_bar():
    compare_output('full_bar_rest')


def test_stem_direction():
    compare_output('stem')


def test_church():
    compare_output('church_modes')


@pytest.mark.xfail
def test_markup():
    compare_output('markup')


def test_breathe():
    compare_output('breathe')


def test_no_barcheck():
    compare_output('no_barcheck')


def ly_to_xml(filename):
    """Read Lilypond file and return XML string."""
    writer = ly.musicxml.writer()
    with open(filename, 'r') as lyfile:
        writer.parse_text(lyfile.read())
    xml = writer.musicxml()
    sio = io.BytesIO()
    xml.write(sio, "utf-8")
    return sio.getvalue().decode("utf-8")

encoding_date_element_re = re.compile(r'(?<=)\d{4}-\d{2}-\d{2}(?=)')

def read_expected_xml(filename):
    """Return string with expected XML from file."""
    with open(filename, 'r') as xmlfile:
        output = xmlfile.read()
    # Replace date in XML file with today's date
    output = encoding_date_element_re.sub(str(datetime.date.today()), output)
    return output


def compare_output(filename):
    """Compare XML output with expected output."""
    filebase = os.path.join(os.path.dirname(__file__), 'test_xml_files',
                            filename)

    output = ly_to_xml(filebase + '.ly')
    expected_output = read_expected_xml(filebase + '.xml')

    assert_multi_line_equal(expected_output, output)
    validate_xml(output)


def validate_xml(xml):
    """Validate XML against XSD file."""
    xsdname = os.path.join(os.path.dirname(__file__), 'musicxml.xsd')
    xsdfile = open(xsdname, 'r')
    xmlschema_doc = etree.parse(xsdfile)
    xsdfile.close()
    xmlschema = etree.XMLSchema(xmlschema_doc)
    parser = etree.XMLParser(schema=xmlschema)
    xml_bytes = xml.encode('utf-8')
    # Raises Exception if not valid:
    etree.fromstring(xml_bytes, parser)


def assert_multi_line_equal(first, second, msg=None):
    """Assert that two multi-line strings are equal.

    If they aren't, show a nice diff.
    """
    assert isinstance(first, str), 'First argument is not a string'
    assert isinstance(second, str), 'Second argument is not a string'

    if first != second:
        message = ''.join(difflib.ndiff(first.splitlines(True),
                                        second.splitlines(True)))
        if msg:
            message += " : " + msg
        assert False, "Multi-line strings are unequal:\n" + message


def regenerate_xml():
    """Regenerate the XML files"""
    extension_re = re.compile(r'\.ly$')
    for ly_path in glob.glob(os.path.join(os.path.dirname(__file__), 'test_xml_files/*.ly')):
        xml_path = extension_re.sub('.xml', ly_path)
        xml = ly_to_xml(ly_path)
        with open(xml_path, 'w') as fw:
            fw.write(xml)


# Run
#   $ test_xml.py regenerate
# to generate the expected XML files anew with current python-ly
if __name__ == '__main__':
    if len(sys.argv) > 1 and sys.argv[1] == 'regenerate':
        regenerate_xml()
python_ly-0.9.9/tests/test_xml_files/break.ly0000644000000000000000000000006213615410400016311 0ustar00\relative c'' {
  c4 c c c | \break
  c4 c c c |
}python_ly-0.9.9/tests/test_xml_files/break.xml0000644000000000000000000000467213615410400016500 0ustar00


  
    
      python-ly 0.9.9
      2024-08-10
    
  
  
    
      
    
  
  
    
      
        1
        
        
          G
          2
        
      
      
        
          C
          5
        
        1
        1
        quarter
      
      
        
          C
          5
        
        1
        1
        quarter
      
      
        
          C
          5
        
        1
        1
        quarter
      
      
        
          C
          5
        
        1
        1
        quarter
      
    
    
      
      
        
          C
          5
        
        1
        1
        quarter
      
      
        
          C
          5
        
        1
        1
        quarter
      
      
        
          C
          5
        
        1
        1
        quarter
      
      
        
          C
          5
        
        1
        1
        quarter
      
    
  

python_ly-0.9.9/tests/test_xml_files/breathe.ly0000644000000000000000000000010013615410400016630 0ustar00\version "2.18.2"

\score {
  { f2. \breathe g4 }
  \layout {}
}python_ly-0.9.9/tests/test_xml_files/breathe.xml0000644000000000000000000000251613615410400017021 0ustar00


  
    
      python-ly 0.9.9
      2024-08-10
    
  
  
    
      
    
  
  
    
      
        1
        
        
          G
          2
        
      
      
        
          F
          3
        
        3
        1
        half
        
        
          
            
          
        
      
      
        
          G
          3
        
        1
        1
        quarter
      
    
  

python_ly-0.9.9/tests/test_xml_files/church_modes.ly0000644000000000000000000000016713615410400017676 0ustar00\version "2.18.2"

\score {
  \relative c' {
  \key d \major
  a b c d |

  \key d \dorian
  a b c d
  }
  \layout {}
}python_ly-0.9.9/tests/test_xml_files/church_modes.xml0000644000000000000000000000515713615410400020056 0ustar00


  
    
      python-ly 0.9.9
      2024-08-10
    
  
  
    
      
    
  
  
    
      
        1
        
          2
          major
        
        
        
          G
          2
        
      
      
        
          A
          3
        
        1
        1
        quarter
      
      
        
          B
          3
        
        1
        1
        quarter
      
      
        
          C
          4
        
        1
        1
        quarter
      
      
        
          D
          4
        
        1
        1
        quarter
      
    
    
      
        
          0
          dorian
        
      
      
        
          A
          3
        
        1
        1
        quarter
      
      
        
          B
          3
        
        1
        1
        quarter
      
      
        
          C
          4
        
        1
        1
        quarter
      
      
        
          D
          4
        
        1
        1
        quarter
      
    
  

python_ly-0.9.9/tests/test_xml_files/dynamics.ly0000644000000000000000000000012413615410400017033 0ustar00\version "2.18.2"

\score {
  { c4\cresc c4 c4\! d\dim d\! e\> e\! }
  \layout {}
}
python_ly-0.9.9/tests/test_xml_files/dynamics.xml0000644000000000000000000000652413615410400017221 0ustar00


  
    
      python-ly 0.9.9
      2024-08-10
    
  
  
    
      
    
  
  
    
      
        1
        
        
          G
          2
        
      
      
        
          cresc.
        
      
      
        
          C
          3
        
        1
        1
        quarter
      
      
        
          
        
      
      
        
          C
          3
        
        1
        1
        quarter
      
      
        
          
        
      
      
        
          C
          3
        
        1
        1
        quarter
      
      
        
          dim.
        
      
      
        
          D
          3
        
        1
        1
        quarter
      
      
        
          
        
      
    
    
      
        
          
        
      
      
        
          D
          3
        
        1
        1
        quarter
      
      
        
          
        
      
      
        
          E
          3
        
        1
        1
        quarter
      
      
        
          
        
      
      
        
          E
          3
        
        1
        1
        quarter
      
    
  

python_ly-0.9.9/tests/test_xml_files/full_bar_rest.ly0000644000000000000000000000015713615410400020055 0ustar00\version "2.18.2"

\score {
  {
  \compressFullBarRests
  R1*6 |
  R1*4 |
  b2^"Tutti" b4 a4
  }
  \layout {}
}python_ly-0.9.9/tests/test_xml_files/full_bar_rest.xml0000644000000000000000000000535313615410400020234 0ustar00


  
    
      python-ly 0.9.9
      2024-08-10
    
  
  
    
      
    
  
  
    
      
        1
        
        
          G
          2
        
      
      
        
        4
        1
      
    
    
    
      
        
        4
        1
      
    
    
      
        
        4
        1
      
    
    
      
        
        4
        1
      
    
    
      
        
        4
        1
      
    
    
      
        
        4
        1
      
      
        
        4
        1
      
    
    
    
      
        
        4
        1
      
    
    
      
        
        4
        1
      
    
    
      
        
        4
        1
      
      
        
          B
          3
        
        2
        1
        half
      
      
        
          B
          3
        
        1
        1
        quarter
      
      
        
          A
          3
        
        1
        1
        quarter
      
    
  

python_ly-0.9.9/tests/test_xml_files/glissando.ly0000644000000000000000000000010113615410400017202 0ustar00\version "2.18.2"

\score {
  { c4\glissando e4 }
  \layout {}
}
python_ly-0.9.9/tests/test_xml_files/glissando.xml0000644000000000000000000000263413615410400017373 0ustar00


  
    
      python-ly 0.9.9
      2024-08-10
    
  
  
    
      
    
  
  
    
      
        1
        
        
          G
          2
        
      
      
        
          C
          3
        
        1
        1
        quarter
        
          
        
      
      
        
          E
          3
        
        1
        1
        quarter
        
          
        
      
    
  

python_ly-0.9.9/tests/test_xml_files/mark.ly0000644000000000000000000000031213615410400016155 0ustar00\version "2.18.2"

\score {
  \relative c' {
    c1 \mark \default |
    d1 \mark #8 |
    c1 \mark \default |
    d1 \mark #25 |
    c1 \mark \default |
    d1 \mark #50 |
    c1 \mark \default |
  }
}python_ly-0.9.9/tests/test_xml_files/mark.xml0000644000000000000000000000704513615410400016343 0ustar00


  
    
      python-ly 0.9.9
      2024-08-10
    
  
  
    
      
    
  
  
    
      
        1
        
        
          G
          2
        
      
      
        
          C
          4
        
        4
        1
        whole
      
    
    
      
      
        
          A
        
      
      
        
          D
          4
        
        4
        1
        whole
      
    
    
      
      
        
          H
        
      
      
        
          C
          4
        
        4
        1
        whole
      
    
    
      
      
        
          J
        
      
      
        
          D
          4
        
        4
        1
        whole
      
    
    
      
      
        
          Z
        
      
      
        
          C
          4
        
        4
        1
        whole
      
    
    
      
      
        
          AA
        
      
      
        
          D
          4
        
        4
        1
        whole
      
    
    
      
      
        
          AZ
        
      
      
        
          C
          4
        
        4
        1
        whole
      
    
    
      
      
        
          BA
        
      
    
  

python_ly-0.9.9/tests/test_xml_files/markup.ly0000644000000000000000000000020613615410400016524 0ustar00\version "2.18.2"

\score {
  \relative {
    a'1-\markup intenso |
    a1-\markup intenso |
    a2^\markup { poco piΓΉ forte  }
  }
}python_ly-0.9.9/tests/test_xml_files/markup.xml0000644000000000000000000000360313615410400016704 0ustar00


  
    
      python-ly 0.9.9
      2017-06-30
    
  
  
    
      
    
  
  
    
      
        1
        
        
          G
          2
        
      
      
        
          intenso 
        
      
      
        
          A
          4
        
        4
        1
        whole
      
    
    
      
        
          intenso 
        
      
      
        
          A
          4
        
        4
        1
        whole
      
    
    
      
        
          poco piΓΉ forte 
        
      
      
        
          A
          4
        
        2
        1
        half
      
    
  

python_ly-0.9.9/tests/test_xml_files/merge_voice.ly0000644000000000000000000000057013615410400017515 0ustar00\version "2.12.3"

\header {
  title = "Somebody to love"
}

partone = \relative c'' {
  \key aes \major
  aes4 bes c c
}

parttwo = \relative c' {
  \key aes \major
  aes4 g aes aes
}

staffone = \new ChoirStaff {
  \new Staff {
    \partone
  }
}

stafftwo = \new ChoirStaff {
  \new Staff {
    \parttwo
  }
}

\score {
  <<
    \staffone
    \stafftwo
  >>
  \layout {}
}
python_ly-0.9.9/tests/test_xml_files/merge_voice.xml0000644000000000000000000000740113615410400017671 0ustar00


  Somebody to love
  
    
      python-ly 0.9.9
      2024-08-10
    
  
  
    
      bracket
    
    
      
    
    
      bracket
    
    
      
    
    
    
  
  
    
      
        1
        
          -4
          major
        
        
        
          G
          2
        
      
      
        
          A
          -1
          4
        
        1
        1
        quarter
        flat
      
      
        
          B
          -1
          4
        
        1
        1
        quarter
        flat
      
      
        
          C
          5
        
        1
        1
        quarter
      
      
        
          C
          5
        
        1
        1
        quarter
      
      
        4
      
    
  
  
    
      
        1
        
          -4
          major
        
        
        
          G
          2
        
      
      
        
          A
          -1
          3
        
        1
        1
        quarter
        flat
      
      
        
          G
          3
        
        1
        1
        quarter
      
      
        
          A
          -1
          3
        
        1
        1
        quarter
        flat
      
      
        
          A
          -1
          3
        
        1
        1
        quarter
        flat
      
      
        4
      
      
        4
      
    
  

python_ly-0.9.9/tests/test_xml_files/merge_voice_slurs.ly0000644000000000000000000000105313615410400020742 0ustar00\version "2.19.55"

\header {
  title = "merge voices with slurs"
}

sopranoOne = \relative c'' {
  % Music follows here.
  c1( | c) | 
  c( | c) |
  c( | c) |

  c2( d) |

  c4\( r2 d4( | e) r2 c4\) |
}

sopranoTwo = \relative c'' {
  % Music follows here.
  c1( | c) | 
  r2 c2( | c2) r2 |
  r2 c2( | r2 c2) |

  r4 e( f) r4 |

  r4 c4\( d( r4 | r4 d) c4\) r4 |
}

\score {
  \new ChoirStaff <<
    \new Staff <<
      \new Voice = "soprano1" { \voiceOne \sopranoOne }
      \new Voice = "soprano2" { \voiceTwo \sopranoTwo }
    >>
  >>
  \layout { }
}
python_ly-0.9.9/tests/test_xml_files/merge_voice_slurs.xml0000644000000000000000000002370613615410400021127 0ustar00


  merge voices with slurs
  
    
      python-ly 0.9.9
      2024-08-10
    
  
  
    
      bracket
    
    
      
    
    
  
  
    
      
        1
        
        
          G
          2
        
      
      
        
          C
          5
        
        4
        1
        whole
        
          
        
      
      
        4
      
      
        
          C
          5
        
        4
        2
        whole
        
          
        
      
    
    
      
        
          C
          5
        
        4
        1
        whole
        
          
        
      
      
        4
      
      
        
          C
          5
        
        4
        2
        whole
        
          
        
      
    
    
      
        
          C
          5
        
        4
        1
        whole
        
          
        
      
      
        4
      
      
        
        2
        2
        half
      
      
        
          C
          5
        
        2
        2
        half
        
          
        
      
    
    
      
        
          C
          5
        
        4
        1
        whole
        
          
        
      
      
        4
      
      
        
          C
          5
        
        2
        2
        half
        
          
        
      
      
        
        2
        2
        half
      
    
    
      
        
          C
          5
        
        4
        1
        whole
        
          
        
      
      
        4
      
      
        
        2
        2
        half
      
      
        
          C
          5
        
        2
        2
        half
        
          
        
      
    
    
      
        
          C
          5
        
        4
        1
        whole
        
          
        
      
      
        4
      
      
        
        2
        2
        half
      
      
        
          C
          5
        
        2
        2
        half
        
          
        
      
    
    
      
        
          C
          5
        
        2
        1
        half
        
          
        
      
      
        
          D
          5
        
        2
        1
        half
        
          
        
      
      
        4
      
      
        
        1
        2
        quarter
      
      
        
          E
          5
        
        1
        2
        quarter
        
          
        
      
      
        
          F
          5
        
        1
        2
        quarter
        
          
        
      
      
        
        1
        2
        quarter
      
    
    
      
        
          C
          5
        
        1
        1
        quarter
        
          
        
      
      
        
        2
        1
        half
      
      
        
          D
          5
        
        1
        1
        quarter
        
          
        
      
      
        4
      
      
        
        1
        2
        quarter
      
      
        
          C
          5
        
        1
        2
        quarter
        
          
        
      
      
        
          D
          5
        
        1
        2
        quarter
        
          
        
      
      
        
        1
        2
        quarter
      
    
    
      
        
          E
          5
        
        1
        1
        quarter
        
          
        
      
      
        
        2
        1
        half
      
      
        
          C
          5
        
        1
        1
        quarter
        
          
        
      
      
        4
      
      
        
        1
        2
        quarter
      
      
        
          D
          5
        
        1
        2
        quarter
        
          
        
      
      
        
          C
          5
        
        1
        2
        quarter
        
          
        
      
      
        
        1
        2
        quarter
      
    
  

python_ly-0.9.9/tests/test_xml_files/no_barcheck.ly0000644000000000000000000000020013615410400017455 0ustar00\version "2.18.2"

\score {
  \relative c'{
    c4 d2 r4
    d1
    f2. d4
    \time 2/4 c2
    \time 4/4 c1
  }
  \layout {}
}
python_ly-0.9.9/tests/test_xml_files/no_barcheck.xml0000644000000000000000000000534613615410400017651 0ustar00


  
    
      python-ly 0.9.9
      2024-08-10
    
  
  
    
      
    
  
  
    
      
        1
        
        
          G
          2
        
      
      
        
          C
          4
        
        1
        1
        quarter
      
      
        
          D
          4
        
        2
        1
        half
      
      
        
        1
        1
        quarter
      
    
    
      
        
          D
          4
        
        4
        1
        whole
      
    
    
      
        
          F
          4
        
        3
        1
        half
        
      
      
        
          D
          4
        
        1
        1
        quarter
      
    
    
      
        
      
      
        
          C
          4
        
        2
        1
        half
      
    
    
      
        
      
      
        
          C
          4
        
        4
        1
        whole
      
    
  

python_ly-0.9.9/tests/test_xml_files/partial.ly0000644000000000000000000000006413615410400016663 0ustar00score{
  \partial 8 f8 |
  c2 d2 |
  \partial 8 f8
}python_ly-0.9.9/tests/test_xml_files/partial.xml0000644000000000000000000000323513615410400017042 0ustar00


  
    
      python-ly 0.9.9
      2017-05-28
    
  
  
    
      
    
  
  
    
      
        2
        
        
          G
          2
        
      
      
        
          F
          3
        
        1
        1
        eighth
      
    
    
      
        
          C
          3
        
        4
        1
        half
      
      
        
          D
          3
        
        4
        1
        half
      
    
    
      
        
          F
          3
        
        1
        1
        eighth
      
    
  

python_ly-0.9.9/tests/test_xml_files/stem.ly0000644000000000000000000000017613615410400016203 0ustar00\version "2.18.2"

\score {
  { 
    \stemUp g4
    f4
    \stemDown g4
    f4 |
    \stemNeutral g4
    f4
  }
  \layout {}
}python_ly-0.9.9/tests/test_xml_files/stem.xml0000644000000000000000000000415713615410400016362 0ustar00


  
    
      python-ly 0.9.9
      2024-08-10
    
  
  
    
      
    
  
  
    
      
        1
        
        
          G
          2
        
      
      
        
          G
          3
        
        1
        1
        quarter
        up
      
      
        
          F
          3
        
        1
        1
        quarter
        up
      
      
        
          G
          3
        
        1
        1
        quarter
        down
      
      
        
          F
          3
        
        1
        1
        quarter
        down
      
    
    
      
        
          G
          3
        
        1
        1
        quarter
      
      
        
          F
          3
        
        1
        1
        quarter
      
    
  

python_ly-0.9.9/tests/test_xml_files/tie.ly0000644000000000000000000000007013615410400016005 0ustar00\version "2.18.2"

\score {
  { c4~ c4 }
  \layout {}
}
python_ly-0.9.9/tests/test_xml_files/tie.xml0000644000000000000000000000262113615410400016165 0ustar00


  
    
      python-ly 0.9.9
      2024-08-10
    
  
  
    
      
    
  
  
    
      
        1
        
        
          G
          2
        
      
      
        
          C
          3
        
        1
        
        1
        quarter
        
          
        
      
      
        
          C
          3
        
        1
        
        1
        quarter
        
          
        
      
    
  

python_ly-0.9.9/tests/test_xml_files/tuplet.ly0000644000000000000000000000011413615410400016540 0ustar00\version "2.18.2"

\score {
  { c4~ \times 2/3 { c4 c4 d } }
  \layout {}
}
python_ly-0.9.9/tests/test_xml_files/tuplet.xml0000644000000000000000000000450213615410400016721 0ustar00


  
    
      python-ly 0.9.9
      2024-08-10
    
  
  
    
      
    
  
  
    
      
        3
        
        
          G
          2
        
      
      
        
          C
          3
        
        3
        
        1
        quarter
        
          
        
      
      
        
          C
          3
        
        2
        
        1
        quarter
        
          3
          2
        
        
          
          
        
      
      
        
          C
          3
        
        2
        1
        quarter
        
          3
          2
        
      
      
        
          D
          3
        
        2
        1
        quarter
        
          3
          2
        
        
          
        
      
    
  

python_ly-0.9.9/tests/test_xml_files/variable.ly0000644000000000000000000000014513615410400017014 0ustar00\version "2.12.3"

date = "2016-03-27"

\header {
  title = \date
}

\score {
  { a4 }
  \layout {}
}python_ly-0.9.9/tests/test_xml_files/variable.xml0000644000000000000000000000200013615410400017160 0ustar00


  
    
      python-ly 0.9.9
      2024-08-10
    
  
  
    
      
    
  
  
    
      
        1
        
        
          G
          2
        
      
      
        
          A
          3
        
        1
        1
        quarter
      
    
  

python_ly-0.9.9/.gitignore0000644000000000000000000000002613615410400012464 0ustar00*.pyc
*~
build/
dist/
python_ly-0.9.9/README.rst0000644000000000000000000000500513615410400012165 0ustar00====================
README for python-ly
====================


This package provides a Python library `ly` containing various Python
modules to parse, manipulate or create documents in LilyPond format.
A command line program `ly` is also provided that can be used to do various
manipulations with LilyPond files.

The LilyPond format is a plain text input format that is used by the 
GNU music typesetter LilyPond (www.lilypond.org).

The python-ly package is Free Software, licensed under the GPL. This package 
is written by the Frescobaldi developers and is used extensively by the
Frescobaldi project. The main author is Wilbert Berendsen.

| Download from: https://pypi.org/project/python-ly
| Development homepage: https://github.com/frescobaldi/python-ly


The `ly` command line tool
--------------------------

With `ly` you can reformat, or re-indent LilyPond files, transpose music,
translate pitch names, convert LilyPond to syntax-colored HTML, etc.

There is also experimental support for converting LilyPond to MusicXML.

Use::

    ly -h

to get a full list of the features of the `ly` command.

Here is an example to re-indent and transpose a LilyPond file::

    ly "indent; transpose c d" -o output.ly file.ly

To test the `ly` module from the current directory without installing, use::

    python -m ly 

This will behave like running the `ly` command when the package is installed.


The `ly` Python module
----------------------

The `ly` module requires Python 3. This is a short description
of some modules:

* ``ly.slexer``: generic tools to build parsers using regular expressions
* ``ly.node``: a generic list-like node object to build tree structures with
* ``ly.document``: a tokenized text document (LilyPond file)
* ``ly.lex``: a parser for LilyPond, Scheme, and other formats, using `slexer`
* ``ly.music``: a tree structure of the contents of a document
* ``ly.pitch``: functions for translating, transposing etc
* ``ly.indent``: indent LilyPond text
* ``ly.reformat``: format LilyPond text
* ``ly.dom``: (deprecated) tree structure to build LilyPond text from
* ``ly.words``: words for highlighting and autocompletion
* ``ly.data``: layout objects, properties, interfaces, font glyphs etc extracted
  from LilyPond

Documentation
-------------

The documentation is built using Sphinx and located in the doc directory.
If you have Sphinx installed, you can build nicely formatted HTML documentation
by typing ``make html`` in the doc directory.

You can also read the docs online at http://python-ly.readthedocs.org/.

python_ly-0.9.9/pyproject.toml0000644000000000000000000000243613615410400013417 0ustar00[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "python-ly"
description = "Tool and library for manipulating LilyPond files"
readme = "README.rst"
license.text = "GPL"
maintainers = [{name = "Wilbert Berendsen", email = "info@frescobaldi.org"}]
requires-python = ">= 3.8"
classifiers = [
    'Development Status :: 4 - Beta',
    #'Development Status :: 5 - Production/Stable',
    'License :: OSI Approved :: GNU General Public License (GPL)',
    'Operating System :: MacOS :: MacOS X',
    'Operating System :: Microsoft :: Windows',
    'Operating System :: POSIX',
    'Programming Language :: Python :: 3.8',
    'Programming Language :: Python :: 3.9',
    'Programming Language :: Python :: 3.10',
    'Programming Language :: Python :: 3.11',
    'Topic :: Multimedia :: Sound/Audio',
    'Topic :: Text Editors',
]
dynamic = ["version"]

[project.urls]
Homepage = "https://github.com/frescobaldi/python-ly"
Documentation = "https://python-ly.readthedocs.io"
Repository = "https://github.com/frescobaldi/python-ly"
"Issue tracker" = "https://github.com/frescobaldi/python-ly/issues"

[project.scripts]
ly = "ly.cli.main:main"
ly-server = "ly.server.main:main"

[tool.hatch.version]
path = "ly/pkginfo.py"

[tool.hatch.build.targets.wheel]
packages = ["ly"]
python_ly-0.9.9/PKG-INFO0000644000000000000000000000703613615410400011601 0ustar00Metadata-Version: 2.4
Name: python-ly
Version: 0.9.9
Summary: Tool and library for manipulating LilyPond files
Project-URL: Homepage, https://github.com/frescobaldi/python-ly
Project-URL: Documentation, https://python-ly.readthedocs.io
Project-URL: Repository, https://github.com/frescobaldi/python-ly
Project-URL: Issue tracker, https://github.com/frescobaldi/python-ly/issues
Maintainer-email: Wilbert Berendsen 
License: GPL
Classifier: Development Status :: 4 - Beta
Classifier: License :: OSI Approved :: GNU General Public License (GPL)
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Multimedia :: Sound/Audio
Classifier: Topic :: Text Editors
Requires-Python: >=3.8
Description-Content-Type: text/x-rst

====================
README for python-ly
====================


This package provides a Python library `ly` containing various Python
modules to parse, manipulate or create documents in LilyPond format.
A command line program `ly` is also provided that can be used to do various
manipulations with LilyPond files.

The LilyPond format is a plain text input format that is used by the 
GNU music typesetter LilyPond (www.lilypond.org).

The python-ly package is Free Software, licensed under the GPL. This package 
is written by the Frescobaldi developers and is used extensively by the
Frescobaldi project. The main author is Wilbert Berendsen.

| Download from: https://pypi.org/project/python-ly
| Development homepage: https://github.com/frescobaldi/python-ly


The `ly` command line tool
--------------------------

With `ly` you can reformat, or re-indent LilyPond files, transpose music,
translate pitch names, convert LilyPond to syntax-colored HTML, etc.

There is also experimental support for converting LilyPond to MusicXML.

Use::

    ly -h

to get a full list of the features of the `ly` command.

Here is an example to re-indent and transpose a LilyPond file::

    ly "indent; transpose c d" -o output.ly file.ly

To test the `ly` module from the current directory without installing, use::

    python -m ly 

This will behave like running the `ly` command when the package is installed.


The `ly` Python module
----------------------

The `ly` module requires Python 3. This is a short description
of some modules:

* ``ly.slexer``: generic tools to build parsers using regular expressions
* ``ly.node``: a generic list-like node object to build tree structures with
* ``ly.document``: a tokenized text document (LilyPond file)
* ``ly.lex``: a parser for LilyPond, Scheme, and other formats, using `slexer`
* ``ly.music``: a tree structure of the contents of a document
* ``ly.pitch``: functions for translating, transposing etc
* ``ly.indent``: indent LilyPond text
* ``ly.reformat``: format LilyPond text
* ``ly.dom``: (deprecated) tree structure to build LilyPond text from
* ``ly.words``: words for highlighting and autocompletion
* ``ly.data``: layout objects, properties, interfaces, font glyphs etc extracted
  from LilyPond

Documentation
-------------

The documentation is built using Sphinx and located in the doc directory.
If you have Sphinx installed, you can build nicely formatted HTML documentation
by typing ``make html`` in the doc directory.

You can also read the docs online at http://python-ly.readthedocs.org/.