New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Designing ly.xml #8
Comments
Great! One question, do you mean that |
I think that the conversion from 1 to 2 should be implemented in a ly.xml module. The When LilyPond is available, exporting from LilyPond-generated output is the best way. But when it isn't or for simpler scores, we could create an XML tree ourselves. |
Agreed, we could get quite far without needing to use LilyPond and I guess that method would be quicker. (Could it even be up to the user to choose method when exporting?) |
I'm also wondering about the conversion in the other direction (from 2 to 1). Normally when a document is created from scratch we would like to go from 1 to a LilyPond source text, right (that format is closest to a document)? But if we want to import music (e. g. from MEI) would we then convert MEI -> 2 -> 1 -> LilyPond document? Or did you mean that it would be better to write LilyPond code from 2? |
I think it should be designed so that creating LilyPond source from 2. would be perfectly possible. It'd just be that all music would be absolute and wrapped in one large expression inside a |
I was playing with the idea of using templates for imports (and perhaps also for creating documents from scratch). That way the user could have some control over what the imported document would look like. I guess it's part of the idea that the template would be partly parsed into format 1 and then used to create the actual document. Another additional use of such templates could be when creating a document via the score wizard. |
Here's an example of the distance between the in-Lily-generated XML and what we would need: \version "2.18.2"
\include "/home/wilbert/dev/python-ly/ly/xml/xml-export.ily"
\displayLilyXML {
\clef treble
} generates this scheme expression (when using (make-music
'SequentialMusic
'elements
(list (make-music
'ContextSpeccedMusic
'context-type
'Staff
'element
(make-music
'SequentialMusic
'elements
(list (make-music
'PropertySet
'value
"clefs.G"
'symbol
'clefGlyph)
(make-music
'PropertySet
'value
-6
'symbol
'middleCClefPosition)
(make-music
'PropertySet
'value
-2
'symbol
'clefPosition)
(make-music
'PropertySet
'value
0
'symbol
'clefTransposition)
(make-music
'ApplyContext
'procedure
ly:set-middle-C!)))))) and generates this XML: <?xml version="1.0" encoding="utf-8"?>
<music name="SequentialMusic">
<origin filename="/home/wilbert/ly/lilyxml-test1.ly" line="5" char="16"/>
<elements>
<music name="ContextSpeccedMusic">
<origin filename="/home/wilbert/ly/lilyxml-test1.ly" line="6" char="2"/>
<element>
<music name="SequentialMusic">
<elements>
<music name="PropertySet">
<property name="value">
<string value="clefs.G"/>
</property>
<property name="symbol">
<symbol value="clefGlyph"/>
</property>
</music>
<music name="PropertySet">
<property name="value">
<number value="-6"/>
</property>
<property name="symbol">
<symbol value="middleCClefPosition"/>
</property>
</music>
<music name="PropertySet">
<property name="value">
<number value="-2"/>
</property>
<property name="symbol">
<symbol value="clefPosition"/>
</property>
</music>
<music name="PropertySet">
<property name="value">
<number value="0"/>
</property>
<property name="symbol">
<symbol value="clefTransposition"/>
</property>
</music>
<music name="ApplyContext">
<property name="procedure">
<procedure name="ly:set-middle-C!"/>
</property>
</music>
</elements>
</music>
</element>
<property name="context-type">
<symbol value="Staff"/>
</property>
</music>
</elements>
</music> When converting such XML we can easily recognize and understand the clef command that is used. But when we create an XML tree from source, we would like to have a simpler construction that also maps the clef change, e.g.: <music name="_user_">
<command name="\clef">
<string value="treble"/>
</command>
</music> This is just a musing... The same holds true for other commands that are already executed or parsed in some way by LilyPond when building the music expression, like The idea is that we have a clear way to map things closely to LilyPond source. As The I converted my Mouvement piece to XML, and the speed of loading it in |
I decided that for the base scheme types boolean, string, char, number and symbol I use the text value of the XML element as the value, not a So \markup {
\override #'(baseline-skip . 3) { Yo! }
} now evaluates to: <?xml version="1.0" encoding="utf-8"?>
<markup>
<m name="line-markup">
<m name="override-markup">
<pair>
<symbol>baseline-skip</symbol>
<number>3</number>
</pair>
<string>Yo!</string>
</m>
</m>
</markup> |
Well, I played with the LilyPond xml-export of the music structure and I propose the following approach:
When exporting from a source ly file using python-ly, we will build a format 1 xml tree and (in most cases) convert that to a format 2 tree, which very much behaves like the When it is desired, we can have LilyPond generate the XML tree, so music generated by LilyPond's scheme functions is available, using the When importing music, it in most cases boils down to manually building the XML tree and then producing LilyPond source from it. When the XML structure is done, we are able to understand music in a meaningful way and can implement a wealth of interesting functions like transpose, translate, change durations etc. etc. When implementing such functions (that currently operate on the tokenized source), they should operate on the XML (format 1) tree and modify the tree via a layer that performs, but also stores the modifications. That layer then is able to perform the desired changes on the source document, without generating full parts again. When all is done, |
I can't fully see through that but it looks very promising.
(Unfortunately I had been away when all this discussion started, but i
hope to be able to join efforts again slowly)
|
I agree, it looks very good! But it means a massive rewrite of python-ly. I have one question at this point: how is it decided when LilyPond and the |
Actually I have one more question: I'm a little confused by the description quoted above - isn't it |
I guess that means that we'll need to create a new branch where the current implementation stays while the restructure is in progress (like the |
The
xml-export.ily
script is now fairly complete, although we could change it in details or to improve usability. But now it can be tested and the XML it generates carefully examined. http://python-ly.readthedocs.org/en/latest/ly.xml.html#the-xml-export-ily-file.Let's use this issue to discuss the XML output and see if we would need to change some aspects.
Then we design our own XML (built from the tokenized source, mimicking the source document) which will be clearly different:
\transpose
and\relative
are not executed already, so we need a way to specify LilyPond commands in their normal syntax.It could be thinkable that we design two styles of XML tree:
ly.music
but as XML, and akin to the XMLxml-export.ily
generates)\relative
and\transpose
executed. This tree then is the same as the one thexml-export.ily
script would generate and can be used to perform conversion to other formats and XML encodings.The conversion from 1. to 2. should be very easy to implement. 1. is then used to understand a document as good as possible, but taylored to writing LilyPond sourcecode from scratch or altering the source document; and providing information (like how many notes are entered). 2. is used to export music to other formats. Also writing code from scratch from 2. could be implemented, but it would not much look like human-written LilyPond code.
The text was updated successfully, but these errors were encountered: