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.
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)
Creates the XML nodes according to the Music XML standard.
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
Create all nodes needed for a normal note.
The information of the parsed source is organised into an object structure with help of the classes in ly.musicxml.xml_objs.
Help class that acts as mediator between the ly source parser and the XML creating modules.
Adds snippet to previous barlist. A snippet can be shorter than a full bar, so this can also mean continuing a previous bar.
Change the current note into a tuplet note.
Perform checks common for all new notes and rests.
Check the finished lyrics section and merge it into the referenced voice.
Check score
If no part were created, place first variable (fallback) as part.
More checks?
Checks active sections. The two latest created are merged. Also checks for empty sections.
Used for snippets. Merges all active snippets created after the stored voice number.
An articulation, fingering, string number, or other symbol.
Grouped as articulations, ornaments, technical and others.
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).
default and initial values
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.
Calculate tremolo duration from number of repeats and initial duration.
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.
Extra class that gives information about the end of Container elements in the node list.
creates the XML-file from the source code according to the Music XML standard
Variables should already have been substituted so this need only cover other types of assignments.
A drummode or drums expression.
If the shorthand form drums is found, DrumStaff is implicit.
Check context and do appropriate action (e.g. create new part).
Find substitute for scorenode. Takes first music node that isn’t an assignment.
Returns the nodes previous node or false if the node is first in its branch.
Iter over score.
Similarly to items.Document.iter_music user commands are substituted.
Furthermore repeat unfold expressions are unfolded.
Looks ahead in a container node and returns True if the search is successful.
Looks behind on the parent node(s) and returns True if the search is successful.
Parse the LilyPond source as a ly.document document.
The document is converted to absolute mode to facilitate the export. Use parse_text instead if you want the document to be unaffected.
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)
Representing the bar/measure. Contains also information about how complete it is.
object that keep track of bar attributes, e.g. time sign, clef, key etc
Bases: ly.musicxml.xml_objs.BarMus
object to keep track of note parameters
Bases: ly.musicxml.xml_objs.BarMus
object to keep track of different rests and skips
Stores information about dynamics.
A ly.musicxml.xml_objs.Score object is iterated and the Music XML node tree is constructed.
Bases: ly.musicxml.xml_objs.ScoreSection
Holds the lyrics information. Will eventually be merged to the corresponding note in the section set by the voice id.
Object that keep track of a whole score.
Object to keep track of part group.
Bases: ly.musicxml.xml_objs.ScoreSection
Short section intended to be merged. Holds reference to the barlist to be merged into.
Object that stores tempo direction information
Bases: ly.musicxml.xml_objs.BarNote
Object to keep track of unpitched notes.