Lilypond
Code for translating jird music into lilypond code.
Lilypond can produce pdf sheet music from the lilypond code.
Primary functions
- lilypond_music(music, f0)[source]
Lilypond representation of music containing multiple simultaneous parts.
- Parameters:
music (Piece) – Music to represent
f0 (float) – Base frequency in Hertz.
- Returns:
Complete lilypond representation of music.
- Return type:
str
Examples
The output contains lilypond headers and Scheme functions for annotations with cent deviations and ratios.
>>> from jird.core import parse >>> part = parse("1:4") >>> print(lilypond_music(part, f0=440)) \version "2.22.2" \language "english" #(define (cents . args) #{ ^\markup{ \teeny \override #'(baseline-skip . 1.4) \with-color "gray" \center-column { $(reverse args) } } #}) #(define (ratios . args) #{ _\markup{ \teeny \override #'(baseline-skip . 1.4) \center-column { \with-color "blueviolet" $(reverse (cdr args)) \with-color "orangered" $(car args) } } #}) \score { << \new Staff{ a'1 $(cents "+0") $(ratios "1" "1") } >> \layout{} }
Helper functions
- lilypond_pitch(note, f0, base_edo=12)[source]
Calculate lilypond representation of pitch of note.
- Parameters:
note (Note) – Note to represent.
f0 (float) – Frequency of 1/1 in Hz.
base_edo (int) – EDO to use when calculating cent deviations. Defaults to 12, in which case deviations are with respect to the nearest note in twelve tone equal temperament.
- Returns:
Note name, formatted cent deviation, and note frequency. Frequency is either a ratio or a power if note is tempered.
- Return type:
tuple of (str, str, RatioProduct or Fraction or Power)
- lilypond_duration(note)[source]
Get lilypond representation of duration of note.
- Parameters:
note (Note) – Note to find duration of.
- Returns:
Template of lilypond representation of note duration, ready to be populated with a lilypond note pitch or chord.
- Return type:
str
- lilypond_note(note, f0)[source]
Find complete lilypond representation of note.
- Parameters:
note (Note) – Note to represent.
f0 (float) – Base frequency in Hz.
- Returns:
Lilypond representation of note including note name, duration, and annotations with cent deviation and ratios.
- Return type:
str
Examples
Lilypond representation of the just major third above middle C
>>> from jird.core import parse >>> note = parse("5/4:1")[0][0] >>> print(lilypond_note(note, f0=261.63)) e'4 $(cents "-14") $(ratios "1" "5/4")
The $(cents “-14”) is lilypond syntax to call a Scheme function called cents on “-14”. This Scheme function is defined at the top of the generated lilypond file to allow easy modification of the cent deviation formatting. Likewise for ratios.
- lilypond_chord(chord, f0)[source]
Find lilypond representation of chord.
- Parameters:
chord (Chord) – Chord to represent.
f0 (float) – Base frequency in Hz.
- Returns:
Lilypond representation of chord with note names, duration, and annotations with cent deviations and ratios.
- Return type:
str
Examples
Lilypond representation of just major triad
>>> from jird.core import parse >>> chord = parse("<1 5/4 3/2>:4")[0][0] >>> print(lilypond_chord(chord, f0=440)) <a' cs'' e''>1 $(cents "+0" "-14" "+2") $(ratios "1" "1" "5/4" "3/2")
- lilypond_part(music, f0, *, indent_level)[source]
Lilypond representation of one part.
- Parameters:
music (Part) – Part to be represented.
f0 (float) – Base frequency in Hz.
indent_level (int) – Number of levels to indent part in generated lilypond.
- Returns:
Lilypond representation of part in music.
- Return type:
str
Examples
Lilypond representation of two notes and a chord
>>> from jird.core import parse >>> part = parse("1:1 5/4:1 <1 5/4 3/2>:2")[0] >>> print(lilypond_part(part, f0=440, indent_level=0)) \new Staff{ a'4 $(cents "+0") $(ratios "1" "1") cs''4 $(cents "-14") $(ratios "1" "5/4") <a' cs'' e''>2 $(cents "+0" "-14" "+2") $(ratios "1" "1" "5/4" "3/2") }
Bass clef is used for parts containing low notes
>>> part = parse("1/4:4")[0] >>> print(lilypond_part(part, f0=440, indent_level=0)) \new Staff{ \clef bass a,1 $(cents "+0") $(ratios "1" "1/4") }