-
Notifications
You must be signed in to change notification settings - Fork 433
metronome marks aren't written to lilypond files #1852
Description
music21 version
9.9.1
Operating System(s) checked
Linux
Problem summary
MetronomeMark is not included when converting Stream object to Lilypond score.
Steps to reproduce
import music21 as mm
keysig = mm.key.Key("a-")
tempo = mm.tempo.MetronomeMark(number=87, referent=mm.note.Note(type="quarter"))
timesig = mm.meter.TimeSignature("3/4")
melody = [
mm.note.Note(pitch=pitch, duration=mm.duration.Duration(type="quarter"))
for pitch in keysig.getPitches()
]
stream = mm.stream.Stream([keysig, tempo, timesig, *melody])
stream.write("lily", "path/to/output/file.ly")Expected vs. actual behavior
actual output (note the lack of any \tempo quarter = 87 or similar):
\version "2.24"
\include "lilypond-book-preamble.ly"
color = #(define-music-function (parser location color) (string?) #{
\once \override NoteHead.color = #(x11-color color)
\once \override Stem.color = #(x11-color color)
\once \override Rest.color = #(x11-color color)
\once \override Beam.color = #(x11-color color)
#})
\header { }
\score {
\new Voice { \new Voice { \key aes \minor
\time 3/4
aes' 4
bes' 4
ces'' 4
des'' 4
ees'' 4
fes'' 4
ges'' 4
aes'' 4
}
}
}
\paper { }
\layout {
\context {
\RemoveEmptyStaves
\override VerticalAxisGroup.remove-first = ##t
}
}More information
My particular use case was a bit more complicated (instantiating a converter, extracting just the LyScoreBlock from its context, and writing a whole series of those one-line scores to a single page, with a custom header for the .ly file). FWIW, what I hacked together as a workaround is:
def insert_metronome_mark_into_score(score, tempo):
tempo_range = mm.lily.lilyObjects.LyTempoRange(tempo)
steno = mm.lily.lilyObjects.LyStenoDuration("4") # "quarter" doesn't work
tempo_mark = mm.lily.lilyObjects.LyTempoEvent(
tempoRange=tempo_range, stenoDuration=steno
)
score[
0
].scoreBody.music.compositeMusic.contents.music.compositeMusic.contents.sequentialMusic.musicList.contents[
0
].music.compositeMusic.contents.sequentialMusic.musicList.contents.insert(
2, tempo_mark
)I mention it because inserting the more simple mm.lilyObjects.LyTempoEvent(scalar="87") fails (lilypond seems to choke on \tempo 87 with no steno and equals sign). Also fails if the steno is "quarter" instead of "4" --- the docstring example code uses "quarter" so may want to change that.