music21 translates to Lilypond format and if Lilypond is installed on the local computer, can automatically generate .pdf, .png, and .svg versions of musical files using Lilypond
this replaces (April 2012) the old LilyString() conversion methods.
The Grammar for Lilypond comes from http://lilypond.org/doc/v2.14/Documentation/notation/lilypond-grammar
LyAlternativeMusic bases
LyAlternativeMusic read-only properties
Read-only properties inherited from LyObject:
LyAlternativeMusic methods
Methods inherited from LyObject:
one of three forms of assignment:
assignment_id ‘=’ identifier_init assignment_id property_path ‘=’ identifier_init embedded_scm
if self.embeddedScm is not None, uses type 3 if self.propertyPath is not None, uses type 2 else uses type 1 or raises an exception.
>>> lyii = lily.lilyObjects.LyIdentifierInit(string = "hi")
>>> lya = lily.lilyObjects.LyAssignment(assignmentId = "title", identifierInit = lyii)
>>> print(lya)
title = "hi"
Note that you could also pass assignmentId a LyAssignmentId object, but that’s overkill for a lot of things.
LyAssignment bases
LyAssignment read-only properties
Read-only properties inherited from LyObject:
LyAssignment methods
Methods inherited from LyObject:
LyAssignmentId bases
LyAssignmentId read-only properties
Read-only properties inherited from LyObject:
LyAssignmentId methods
Methods inherited from LyObject:
LyBookBlock bases
LyBookBlock read-only properties
Read-only properties inherited from LyObject:
LyBookBlock methods
Methods inherited from LyObject:
Contains None, bookIdentifier (string?) or one or more of the following:
paperBlock bookPartBlock scoreBlock compositeMusic fullMarkup fullMarkupList lilypondHeader error
LyBookBody bases
LyBookBody read-only properties
Read-only properties inherited from LyObject:
LyBookBody methods
Methods inherited from LyObject:
LyBookpartBlock bases
LyBookpartBlock read-only properties
Read-only properties inherited from LyObject:
LyBookpartBlock methods
Methods inherited from LyObject:
Contains None, bookIdentifier (string?) or one or more of the following:
paperBlock scoreBlock compositeMusic fullMarkup fullMarkupList lilypondHeader error
LyBookpartBody bases
LyBookpartBody read-only properties
Read-only properties inherited from LyObject:
LyBookpartBody methods
Methods inherited from LyObject:
LyChordBody bases
LyChordBody read-only properties
Read-only properties inherited from LyObject:
LyChordBody methods
Methods inherited from LyObject:
Contains a note or a drum pitch or a music function:
chord_body_element: pitch
exclamations (a string of zero or more ! marks)
questions (a string of zero or more ? marks)
octave_check
post_events
| DRUM_PITCH post_events
| music_function_chord_body
TODO: only the first form is currently supported in creation
LyChordBodyElement bases
LyChordBodyElement read-only properties
Read-only properties inherited from LyObject:
LyChordBodyElement methods
Methods inherited from LyObject:
LyCommandElement bases
LyCommandElement read-only properties
Read-only properties inherited from LyObject:
LyCommandElement methods
Methods inherited from LyObject:
LyCommandEvent bases
LyCommandEvent read-only properties
Read-only properties inherited from LyObject:
LyCommandEvent methods
Methods inherited from LyObject:
one of LyPrefixCompositeMusic or LyGroupedMusicList stored in self.contents
LyCompositeMusic bases
LyCompositeMusic read-only properties
Read-only properties inherited from LyObject:
LyCompositeMusic methods
Methods inherited from LyObject:
LyContextChange bases
LyContextChange read-only properties
Read-only properties inherited from LyObject:
LyContextChange methods
Methods inherited from LyObject:
one of consists, remove, accepts, defaultchild, denies, alias, type, description, name
LyContextDefMod bases
LyContextDefMod read-only properties
Read-only properties inherited from LyObject:
LyContextDefMod methods
Methods inherited from LyObject:
LyContextDefSpecBlock bases
LyContextDefSpecBlock read-only properties
Read-only properties inherited from LyObject:
LyContextDefSpecBlock methods
Methods inherited from LyObject:
None or one of four forms:
CONTEXT_DEF_IDENTIFIER context_def_spec_body “grobdescriptions” embedded_scm context_def_spec_body context_mod context_def_spec_body context_modification
LyContextDefSpecBody bases
LyContextDefSpecBody read-only properties
Read-only properties inherited from LyObject:
LyContextDefSpecBody methods
Methods inherited from LyObject:
LyContextMod bases
LyContextMod read-only properties
Read-only properties inherited from LyObject:
LyContextMod methods
Methods inherited from LyObject:
contains zero or more LyContextMod objects and an optional contextModIdentifier
LyContextModList bases
LyContextModList read-only properties
Read-only properties inherited from LyObject:
LyContextModList methods
Methods inherited from LyObject:
represents both context_modification and optional_context_mod
but not context_mod!!!!!
LyContextModification bases
LyContextModification read-only properties
Read-only properties inherited from LyObject:
LyContextModification methods
Methods inherited from LyObject:
represents [‘[‘,’]’,’~’,’(‘,’)’,’!’,’(‘,’)’,’>’,’<’] or an EVENT_IDENTIFIER or a tremolo_type
LyDirectionLessEvent bases
LyDirectionLessEvent read-only properties
Read-only properties inherited from LyObject:
LyDirectionLessEvent methods
Methods inherited from LyObject:
LyDirectionReqdEvent bases
LyDirectionReqdEvent read-only properties
Read-only properties inherited from LyObject:
LyDirectionReqdEvent methods
Methods inherited from LyObject:
represents Scheme embedded in Lilypond code.
Can be either a SCM_TOKEN (Scheme Token) or SCM_IDENTIFIER String stored in self.content
Note that if any LyEmbeddedScm is found in an output then the output SHOULD be marked as unsafe. But a lot of standard lilypond functions are actually embedded scheme. For instance, clef, which as http://lilypond.org/doc/v2.12/input/lsr/lilypond-snippets/Pitches#Tweaking-clef-properties shows is a macro to run a lot of set commands.
>>> lyscheme = lily.lilyObjects.LyEmbeddedScm('##t')
>>> str(lyscheme)
'##t'
LyEmbeddedScm bases
LyEmbeddedScm read-only properties
Read-only properties inherited from LyObject:
LyEmbeddedScm methods
Methods inherited from LyObject:
takes all the parts as a list of up to three elements
- event_chord: simple_chord_elements post_events
CHORD_REPETITION optional_notemode_duration post_eventsMULTI_MEASURE_REST optional_notemode_duration post_eventscommand_elementnote_chord_element
simple_chord_elements can be a LySimpleElement object. Or it can be a LyNewChord or LyFigureSpec + Duration once that is done. But there is no LySimpleChordElements object yet.
LyEventChord bases
LyEventChord read-only properties
Read-only properties inherited from LyObject:
LyEventChord methods
Methods inherited from LyObject:
LyFullMarkup bases
LyFullMarkup read-only properties
Read-only properties inherited from LyObject:
LyFullMarkup methods
Methods inherited from LyObject:
LyFullMarkupList bases
LyFullMarkupList read-only properties
Read-only properties inherited from LyObject:
LyFullMarkupList methods
Methods inherited from LyObject:
holds either full_markup, string, or DIGIT
LyGenTextDef bases
LyGenTextDef read-only properties
Read-only properties inherited from LyObject:
LyGenTextDef methods
Methods inherited from LyObject:
one of LySimultaneousMusic or LySequentialMusic
LyGroupedMusicList bases
LyGroupedMusicList read-only properties
Read-only properties inherited from LyObject:
LyGroupedMusicList methods
Methods inherited from LyObject:
>>> lyii = lily.lilyObjects.LyIdentifierInit(string = "hello")
>>> print(lyii)
"hello"
LyIdentifierInit bases
LyIdentifierInit read-only properties
Read-only properties inherited from LyObject:
LyIdentifierInit methods
Methods inherited from LyObject:
LyLayout bases
LyLayout read-only properties
Read-only properties inherited from LyObject:
LyLayout methods
Methods inherited from LyObject:
A header object with a headerbody
>>> lyh = lily.lilyObjects.LyLilypondHeader()
>>> str(lyh)
'\\header { } '
LyLilypondHeader bases
LyLilypondHeader read-only properties
Read-only properties inherited from LyObject:
LyLilypondHeader methods
Methods inherited from LyObject:
LyLilypondHeaderBody bases
LyLilypondHeaderBody read-only properties
Read-only properties inherited from LyObject:
LyLilypondHeaderBody methods
Methods inherited from LyObject:
corresponds to the highest level lilypond object in Appendix C:
`lilypond: /* empty */
| lilypond toplevel_expression
| lilypond assignment
| lilypond error
| lilypond "\invalid"`
error and invalid are not defined by music21
LyLilypondTop bases
LyLilypondTop read-only properties
Read-only properties inherited from LyObject:
LyLilypondTop methods
Methods inherited from LyObject:
Object represents a single Lyric in lilypond.
>>> lle = lily.lilyObjects.LyLyricElement("hel_")
>>> lle
<music21.lily.lilyObjects.LyLyricElement object 'hel_'>
>>> print(lle)
hel_
LyLyricElement bases
LyLyricElement read-only properties
Read-only properties inherited from LyObject:
LyLyricElement methods
Methods inherited from LyObject:
LyLyricMarkup bases
LyLyricMarkup read-only properties
Read-only properties inherited from LyObject:
LyLyricMarkup methods
Methods inherited from LyObject:
LyMarkup bases
LyMarkup read-only properties
Read-only properties inherited from LyObject:
LyMarkup methods
Methods inherited from LyObject:
LyMarkupBracedList bases
LyMarkupBracedList read-only properties
Read-only properties inherited from LyObject:
LyMarkupBracedList methods
Methods inherited from LyObject:
LyMarkupBracedListBody bases
LyMarkupBracedListBody read-only properties
Read-only properties inherited from LyObject:
LyMarkupBracedListBody methods
Methods inherited from LyObject:
LyMarkupComposedList bases
LyMarkupComposedList read-only properties
Read-only properties inherited from LyObject:
LyMarkupComposedList methods
Methods inherited from LyObject:
LyMarkupList bases
LyMarkupList read-only properties
Read-only properties inherited from LyObject:
LyMarkupList methods
Methods inherited from LyObject:
LyMarkupTop bases
LyMarkupTop read-only properties
Read-only properties inherited from LyObject:
LyMarkupTop methods
Methods inherited from LyObject:
A test object for trying various music21 to Lily conversions
LyMock bases
LyMock read-only properties
Read-only properties inherited from LyObject:
LyMock methods
Methods inherited from LyObject:
represents both mode_changing_head and mode_changing_head_with_context
.hasContext = False .mode = [‘note’, ‘drum’, ‘figure’, ‘chord’, ‘lyric’]
>>> l = lily.lilyObjects.LyModeChangingHead(hasContext = True, mode = 'drum')
>>> print(l.stringOutput())
\drummode
>>> l2 = lily.lilyObjects.LyModeChangingHead(hasContext = False, mode = 'chord')
>>> print(l2.stringOutput())
\chords
LyModeChangingHead bases
LyModeChangingHead read-only properties
Read-only properties inherited from LyObject:
LyModeChangingHead methods
Methods inherited from LyObject:
represents either a simple LyStenoDuration or a list of things that the steno duration should be multiplied by.
if stenoDur is None then output is None – thus also represents optional_notemode_duration
LyMultipliedDuration bases
LyMultipliedDuration read-only properties
Read-only properties inherited from LyObject:
LyMultipliedDuration methods
Methods inherited from LyObject:
LyMusic bases
LyMusic read-only properties
Read-only properties inherited from LyObject:
LyMusic methods
Methods inherited from LyObject:
can take any number of LyMusic, LyEmbeddedScm, or LyError objects
LyMusicList bases
LyMusicList read-only properties
Read-only properties inherited from LyObject:
LyMusicList methods
Methods inherited from LyObject:
LyMusicPropertyDef bases
LyMusicPropertyDef read-only properties
Read-only properties inherited from LyObject:
LyMusicPropertyDef methods
Methods inherited from LyObject:
contains a list of LyGroupedMusicList objects or identifiers
LyNewLyrics bases
LyNewLyrics read-only properties
Read-only properties inherited from LyObject:
LyNewLyrics methods
Methods inherited from LyObject:
LyNoteChordElement bases
LyNoteChordElement read-only properties
Read-only properties inherited from LyObject:
LyNoteChordElement methods
Methods inherited from LyObject:
any list of numbers or LyNumberTerms separated by ‘+’ or ‘-‘ objects.
LyNumberExpression bases
LyNumberExpression read-only properties
Read-only properties inherited from LyObject:
LyNumberExpression methods
Methods inherited from LyObject:
any list of numbers separated by ‘*’ or ‘/’ strings.
LyNumberTerm bases
LyNumberTerm read-only properties
Read-only properties inherited from LyObject:
LyNumberTerm methods
Methods inherited from LyObject:
LyObject read-only properties
LyObject methods
returns a list of all unwrapped parent objects for the current object
returns a comment that is %{ stringIn.strip() %}
Don’t put %} etc. in comments. That’s just rude...
returns a string that is quoted with internal quotation marks backslash’d out and an extra space at the end.
>>> m = lily.lilyObjects.LyObject()
>>> print(m.quoteString(r'Hello "there"!'))
"Hello \"there\"!"
Returns a dictionary and sets self.lilyAttributes to that dictionary, for a m21Object of class classLookup using the mapping of self.m21toLy[classLookup]
>>> class Mock(base.Music21Object): pass
>>> m = Mock()
>>> m.mockAttribute = 32
>>> m.mockAttribute2 = None
>>> lm = lily.lilyObjects.LyMock()
LyMock (our test class) defines mappings for two classes: to LyMock.lilyAttributes:
>>> print(lm.supportedClasses)
[...'Mock', ...'Mocker']
Thus we can get attributes from the Mock class (see setAttributesFromClassObject):
>>> lilyAttributes = lm.setAttributes(m)
>>> for x in sorted(lilyAttributes.keys()):
... print("%s: %s" % (x, lilyAttributes[x]))
mock-attribute: 32
mock-attribute-2: None
>>> lilyAttributes is lm.lilyAttributes
True
Returns a dictionary and sets self.lilyAttributes to that dictionary, for a m21Object of class classLookup using the mapping of self.m21toLy[classLookup]
>>> class Mock(base.Music21Object): pass
>>> m = Mock()
>>> lm = lily.lilyObjects.LyMock()
LyMock (our test class) defines certain mappings from the m21 Mock class to LyMock.lilyAttributes:
>>> for x in sorted(lm.m21toLy['Mock'].keys()):
... print("%s: %s" % (x, lm.m21toLy['Mock'][x]))
mockAttribute: mock-attribute
mockAttribute2: mock-attribute-2
Some of these attributes have defaults:
>>> for x in sorted(lm.defaultAttributes.keys()):
... print("%s: %s" % (x, lm.defaultAttributes[x]))
mockAttribute2: 7
>>> m.mockAttribute = "hello"
>>> lilyAttributes = lm.setAttributesFromClassObject('Mock', m)
>>> for x in sorted(lilyAttributes.keys()):
... print("%s: %s" % (x, lilyAttributes[x]))
mock-attribute: hello
mock-attribute-2: 7
>>> lilyAttributes is lm.lilyAttributes
True
LyOctaveCheck bases
LyOctaveCheck read-only properties
Read-only properties inherited from LyObject:
LyOctaveCheck methods
Methods inherited from LyObject:
an optional id setting
LyOptionalId bases
LyOptionalId read-only properties
Read-only properties inherited from LyObject:
LyOptionalId methods
Methods inherited from LyObject:
LyOptionalRest bases
LyOptionalRest read-only properties
Read-only properties inherited from LyObject:
LyOptionalRest methods
Methods inherited from LyObject:
represents ossia music.
Can be tagged with startStaff and stopStaff if startstop is True
LyOssiaMusic bases
LyOssiaMusic read-only properties
Read-only properties inherited from LyObject:
LyOssiaMusic methods
Methods inherited from LyObject:
ugly grammar since it doesnt close curly bracket...
LyOutputDef bases
LyOutputDef read-only properties
Read-only properties inherited from LyObject:
LyOutputDef methods
Methods inherited from LyObject:
LyOutputDefBody bases
LyOutputDefBody read-only properties
Read-only properties inherited from LyObject:
LyOutputDefBody methods
Methods inherited from LyObject:
defType can be paper, midi, or layout.
>>> lyODH = lily.lilyObjects.LyOutputDefHead()
>>> lyODH.defType = 'midi'
>>> print(lyODH.stringOutput())
\midi
According to Appendix C, is the same as LyOutputDefHeadWithModeSwitch
LyOutputDefHead bases
LyOutputDefHead read-only properties
Read-only properties inherited from LyObject:
LyOutputDefHead methods
Methods inherited from LyObject:
LyPaperBlock bases
LyPaperBlock read-only properties
Read-only properties inherited from LyObject:
LyPaperBlock methods
Methods inherited from LyObject:
represents a pitch name and zero or more sup or sub quotes also used for steno_pitch and steno_tonic_pitch
LyPitch bases
LyPitch read-only properties
Read-only properties inherited from LyObject:
LyPitch methods
Methods inherited from LyObject:
LyPostEvent bases
LyPostEvent read-only properties
Read-only properties inherited from LyObject:
LyPostEvent methods
Methods inherited from LyObject:
LyPostEvents bases
LyPostEvents read-only properties
Read-only properties inherited from LyObject:
LyPostEvents methods
Methods inherited from LyObject:
type must be specified. Should be one of:
scheme, context, new, times, repeated, transpose, modeChanging, modeChangingWith, relative, rhythmed
LyPrefixCompositeMusic bases
LyPrefixCompositeMusic read-only properties
Read-only properties inherited from LyObject:
LyPrefixCompositeMusic methods
Methods inherited from LyObject:
Represents:
- property_operation: STRING ‘=’ scalar
“\unset” simple_string“override” simple_string property_path ‘=’ scalar“revert” simple_string embedded_scm
manditory mode in [‘set’, ‘unset’, ‘override’, ‘revert’]
also represents simple_music_property_def which has the same forms
LyPropertyOperation bases
LyPropertyOperation read-only properties
Read-only properties inherited from LyObject:
LyPropertyOperation methods
Methods inherited from LyObject:
represents both property_path and property_path_revved
has one or more of LyEmbeddedScm objects
LyPropertyPath bases
LyPropertyPath read-only properties
Read-only properties inherited from LyObject:
LyPropertyPath methods
Methods inherited from LyObject:
LyReRhythmedMusic bases
LyReRhythmedMusic read-only properties
Read-only properties inherited from LyObject:
LyReRhythmedMusic methods
Methods inherited from LyObject:
relative music
LyRelativeMusic bases
LyRelativeMusic read-only properties
Read-only properties inherited from LyObject:
LyRelativeMusic methods
Methods inherited from LyObject:
LyRepeatedMusic bases
LyRepeatedMusic read-only properties
Read-only properties inherited from LyObject:
LyRepeatedMusic methods
Methods inherited from LyObject:
Unsupported for now, represents all of:
function_scm_argument: embedded_scm
116 | simple_string
117 function_arglist_music_last: EXPECT_MUSIC function_arglist music
118 function_arglist_nonmusic_last: EXPECT_MARKUP
function_arglist
full_markup
119 | EXPECT_MARKUP
function_arglist
simple_string
120 | EXPECT_SCM
function_arglist
function_scm_argument
121 function_arglist_nonmusic: EXPECT_NO_MORE_ARGS
122 | EXPECT_MARKUP
function_arglist_nonmusic
full_markup
123 | EXPECT_MARKUP
function_arglist_nonmusic
simple_string
124 | EXPECT_SCM
function_arglist_nonmusic
function_scm_argument
125 function_arglist: EXPECT_NO_MORE_ARGS
126 | function_arglist_music_last
127 | function_arglist_nonmusic_last
128 generic_prefix_music_scm: MUSIC_FUNCTION function_arglist
We have ususally been using LyEmbeddedScm for this
LySchemeFunction bases
LySchemeFunction read-only properties
Read-only properties inherited from LyObject:
LySchemeFunction methods
Methods inherited from LyObject:
represents the container for a score ( score { ... } )
with all the real stuff being in self.scoreBody
>>> lysb = lily.lilyObjects.LyScoreBlock(scoreBody = "hello")
>>> print(lysb)
\score { hello }
LyScoreBlock bases
LyScoreBlock read-only properties
Read-only properties inherited from LyObject:
LyScoreBlock methods
Methods inherited from LyObject:
represents the contents of a score { ...contents... } block
can take one of the following attributes: music, scoreIdentifier, scoreBody, lilypondHeader, outputDef, error
LyScoreBody bases
LyScoreBody read-only properties
Read-only properties inherited from LyObject:
LyScoreBody methods
Methods inherited from LyObject:
Holds a script abbreviation (for articulations etc.), one of:
^ + - | > . _
LyScriptAbbreviation bases
LyScriptAbbreviation read-only properties
Read-only properties inherited from LyObject:
LyScriptAbbreviation methods
Methods inherited from LyObject:
Holds a script direction abbreviation (above below etc), one of:
_ ^ -
LyScriptDir bases
LyScriptDir read-only properties
Read-only properties inherited from LyObject:
LyScriptDir methods
Methods inherited from LyObject:
represents sequential music.
Can be explicitly tagged with “sequential” if displayTag is True
LySequentialMusic bases
LySequentialMusic read-only properties
Read-only properties inherited from LyObject:
LySequentialMusic methods
Methods inherited from LyObject:
A single note, lyric element, drum pitch or hidden rest:
simple_element: pitch
exclamations (a string of zero or more ! marks)
questions (a string of zero or more ? marks)
octave_check
optional_notemode_duration
optional_rest
| DRUM_PITCH optional_notemode_duration
| RESTNAME optional_notemode_duration
| lyric_element optional_notemode_duration
LySimpleElement bases
LySimpleElement read-only properties
Read-only properties inherited from LyObject:
LySimpleElement methods
Methods inherited from LyObject:
simpleType can be ‘string’ (or markup identifier or lyric markup identifier, etc.) or ‘score-body’ or ‘markup-function’
takes 1 required arg, 2nd for markup_function
LySimpleMarkup bases
LySimpleMarkup read-only properties
Read-only properties inherited from LyObject:
LySimpleMarkup methods
Methods inherited from LyObject:
LySimpleMusic bases
LySimpleMusic read-only properties
Read-only properties inherited from LyObject:
LySimpleMusic methods
Methods inherited from LyObject:
represents simultaneous music.
Can be explicitly tagged with “simultaneous” if displayTag is True otherwise encloses in double angle brackets
LySimultaneousMusic bases
LySimultaneousMusic read-only properties
Read-only properties inherited from LyObject:
LySimultaneousMusic methods
Methods inherited from LyObject:
the main thing that we think of as non-tuplet duration.
a duration number followed by one or more dots
>>> lsd = lily.lilyObjects.LyStenoDuration('2', 2)
>>> print(lsd)
2..
LyStenoDuration bases
LyStenoDuration read-only properties
Read-only properties inherited from LyObject:
LyStenoDuration methods
Methods inherited from LyObject:
LyTempoEvent bases
LyTempoEvent read-only properties
Read-only properties inherited from LyObject:
LyTempoEvent methods
Methods inherited from LyObject:
defines either a single tempo or a range
LyTempoRange bases
LyTempoRange read-only properties
Read-only properties inherited from LyObject:
LyTempoRange methods
Methods inherited from LyObject:
can contain one of:
lilypondHeader bookBlock bookPartBlock scoreBlock compositeMusic fullMarkup fullMarkupList outputDef
>>> bookBlock = lily.lilyObjects.LyBookBlock()
>>> lytle = lily.lilyObjects.LyTopLevelExpression(bookBlock=bookBlock)
>>> str(lytle)
'\\book { } '
LyTopLevelExpression bases
LyTopLevelExpression read-only properties
Read-only properties inherited from LyObject:
LyTopLevelExpression methods
Methods inherited from LyObject:
LyTremoloType bases
LyTremoloType read-only properties
Read-only properties inherited from LyObject:
LyTremoloType methods
Methods inherited from LyObject: