ly.musicxml package¶
Module contents¶
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.
Submodules¶
ly.musicxml.create_musicxml module¶
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)
- class ly.musicxml.create_musicxml.CreateMusicXML[source]¶
Bases:
object
Creates the XML nodes according to the Music XML standard.
- add_tuplet_type(nr, ttype, actnr=0, acttype='', normnr=0, normtype='')[source]¶
Create tuplet with type attribute
- create_new_node(parentnode, nodename, txt)[source]¶
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_bar_attr(clef=0, mustime=0, key=None, mode=0, divs=0, multirest=0)[source]¶
Create all bar attributes set.
- new_note(step, octave, durtype, divdur, alter=0, acc_token=0, voice=1, dot=0, chord=0, grace=(0, 0), stem_dir=0)[source]¶
Create all nodes needed for a normal note.
ly.musicxml.ly2xml_mediator module¶
The information of the parsed source is organised into an object structure with help of the classes in ly.musicxml.xml_objs.
- class ly.musicxml.ly2xml_mediator.Mediator[source]¶
Bases:
object
Help class that acts as mediator between the ly source parser and the XML creating modules.
- add_snippet(snippet_name)[source]¶
Adds snippet to previous barlist. A snippet can be shorter than a full bar, so this can also mean continuing a previous bar.
- calc_tupl_den(tfraction, length)[source]¶
Calculate the tuplet denominator from fraction and duration of tuplet.
- change_to_tuplet(tfraction, ttype, nr, length=None)[source]¶
Change the current note into a tuplet note.
- check_current_note(rel=False, rest=False, is_unpitched=False)[source]¶
Perform checks common for all new notes and rests.
- check_lyrics(voice_id)[source]¶
Check the finished lyrics section and merge it into the referenced voice.
- check_score()[source]¶
Check score
If no part were created, place first variable (fallback) as part.
Apply the latest global section.
- check_voices()[source]¶
Checks active sections. The two latest created are merged. Also checks for empty sections.
- check_voices_by_nr()[source]¶
Used for snippets. Merges all active snippets created after the stored voice number.
- new_articulation(art_token)[source]¶
An articulation, fingering, string number, or other symbol.
Grouped as articulations, ornaments, technical and others.
- new_iso_dura(note, rel=False, is_unpitched=False)[source]¶
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).
- sections¶
default and initial values
- set_slur(nr, slur_type, phrasing=False)[source]¶
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.
- ly.musicxml.ly2xml_mediator.artic_token2xml_name(art_token)[source]¶
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.
- ly.musicxml.ly2xml_mediator.calc_trem_dur(repeats, base_scaling, duration)[source]¶
Calculate tremolo duration from number of repeats and initial duration.
- ly.musicxml.ly2xml_mediator.clefname2clef(clefname)[source]¶
To add a clef look up the clef name in LilyPond and the corresponding definition in musicXML. Add it to the python dictionary below.
ly.musicxml.lymus2musxml module¶
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.
- class ly.musicxml.lymus2musxml.End(node)[source]¶
Bases:
object
Extra class that gives information about the end of Container elements in the node list.
- class ly.musicxml.lymus2musxml.ParseSource[source]¶
Bases:
object
creates the XML-file from the source code according to the Music XML standard
- Assignment(a)[source]¶
Variables should already have been substituted so this need only cover other types of assignments.
- DrumMode(drummode)[source]¶
A drummode or drums expression.
If the shorthand form drums is found, DrumStaff is implicit.
- check_context(context, context_id=None, token='')[source]¶
Check context and do appropriate action (e.g. create new part).
- find_score_sub(doc)[source]¶
Find substitute for scorenode. Takes first music node that isn’t an assignment.
- get_previous_node(node)[source]¶
Returns the nodes previous node or false if the node is first in its branch.
- iter_score(scorenode, doc)[source]¶
Iter over score.
Similarly to items.Document.iter_music user commands are substituted.
Furthermore repeat unfold expressions are unfolded.
- look_ahead(node, find_node)[source]¶
Looks ahead in a container node and returns True if the search is successful.
- look_behind(node, find_node)[source]¶
Looks behind on the parent node(s) and returns True if the search is successful.
- parse_document(ly_doc, relative_first_pitch_absolute=False)[source]¶
Parse the LilyPond source specified as a ly.document document.
If relative_first_pitch_absolute is set to True, the first pitch in a
- elative expression without startpitch is considered to be absolute
(LilyPond 2.18+ behaviour).
- parse_nodes(nodes)[source]¶
Work through all nodes by calling the function with the same name as the nodes class.
ly.musicxml.xml_objs module¶
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)
- class ly.musicxml.xml_objs.Bar[source]¶
Bases:
object
Representing the bar/measure. Contains also information about how complete it is.
- class ly.musicxml.xml_objs.BarAttr[source]¶
Bases:
object
object that keep track of bar attributes, e.g. time sign, clef, key etc
- class ly.musicxml.xml_objs.BarBackup(duration)[source]¶
Bases:
object
Object that stores duration for backup
- class ly.musicxml.xml_objs.BarMus(duration, voice=1)[source]¶
Bases:
object
Common class for notes and rests.
- class ly.musicxml.xml_objs.BarNote(pitch_note, alter, accidental, duration, voice=1)[source]¶
Bases:
ly.musicxml.xml_objs.BarMus
object to keep track of note parameters
- class ly.musicxml.xml_objs.BarRest(duration, voice=1, show_type=True, skip=False, pos=0)[source]¶
Bases:
ly.musicxml.xml_objs.BarMus
object to keep track of different rests and skips
- class ly.musicxml.xml_objs.Dynamics(sign, before=True)[source]¶
Bases:
object
Stores information about dynamics.
- class ly.musicxml.xml_objs.DynamicsDashes(sign, before=True)[source]¶
Bases:
ly.musicxml.xml_objs.Dynamics
Dynamics dashes.
- class ly.musicxml.xml_objs.DynamicsMark(sign, before=True)[source]¶
Bases:
ly.musicxml.xml_objs.Dynamics
A dynamics mark.
- class ly.musicxml.xml_objs.DynamicsText(sign, before=True)[source]¶
Bases:
ly.musicxml.xml_objs.Dynamics
A dynamics text.
- class ly.musicxml.xml_objs.DynamicsWedge(sign, before=True)[source]¶
Bases:
ly.musicxml.xml_objs.Dynamics
A dynamics wedge/hairpin.
- class ly.musicxml.xml_objs.IterateXmlObjs(score, musxml, div)[source]¶
Bases:
object
A ly.musicxml.xml_objs.Score object is iterated and the Music XML node tree is constructed.
- class ly.musicxml.xml_objs.LyricsSection(name, voice_id)[source]¶
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.
- class ly.musicxml.xml_objs.OctaveShift(plac, octdir, size)[source]¶
Bases:
object
Class for octave shifts.
- class ly.musicxml.xml_objs.Score[source]¶
Bases:
object
Object that keep track of a whole score.
- class ly.musicxml.xml_objs.ScorePart(staves=0, part_id=None, to_part=None, name='')[source]¶
Bases:
ly.musicxml.xml_objs.ScoreSection
object to keep track of part
- class ly.musicxml.xml_objs.ScorePartGroup(num, bracket)[source]¶
Bases:
object
Object to keep track of part group.
- class ly.musicxml.xml_objs.ScoreSection(name, glob=False)[source]¶
Bases:
object
object to keep track of music section
- class ly.musicxml.xml_objs.Slur(nr, slurtype, phrasing=False, start_node=None)[source]¶
Bases:
object
Stores information about slur. start_node is only interesting if slurtype is ‘stop’. start_node must be None or a Slur instance.
- class ly.musicxml.xml_objs.SlurCount[source]¶
Bases:
object
Utility class meant for keeping count of started slurs in a section
- class ly.musicxml.xml_objs.Snippet(name, merge_into)[source]¶
Bases:
ly.musicxml.xml_objs.ScoreSection
Short section intended to be merged. Holds reference to the barlist to be merged into.
- class ly.musicxml.xml_objs.TempoDir(unit, unittype, beats, dots, text)[source]¶
Bases:
object
Object that stores tempo direction information
- class ly.musicxml.xml_objs.Tuplet(fraction, ttype, nr, acttype, normtype)[source]¶
Bases:
object
Stores information about tuplet.
- class ly.musicxml.xml_objs.Unpitched(duration, step=None, voice=1)[source]¶
Bases:
ly.musicxml.xml_objs.BarNote
Object to keep track of unpitched notes.