Lilypond is free, open-source music notation software that can be used to create sheet music in alternative notation systems. One of LilyPond’s strengths is its flexibility. It is designed so that its output can be modified using the Scheme programming language. This opens the door to a world of customization without having to alter LilyPond’s source code. This page documents how to use LilyPond with alternative music notation systems with a chromatic staff.
The following files can be used to produce music in a number of alternative music notation systems. These files demonstrate the use of the specific “lower-level” techniques documented below.
- MNP-scripts.ly — A LilyPond file containing LilyPond and Scheme code that supports alternative music notation systems.
— A LilyPond music file demonstrating the use of the
— LilyPond’s PDF output from the
There are basically just a few steps to use an existing traditional LilyPond music file to create a PDF of music in an alternative notation system:
MNP-scripts.lyfile above and put it in the same directory as your music file.
MNP-scripts.lyfile at the top of the music file. (See Including LilyPond Files.) The
MNP-scripts.lyfile and the music file must be in the same directory for the
\includecommand to work.
Change “Staff” in the music file to the name of any
alternative staff that is defined at the bottom of the
MNP-scripts.lyfile. (Examples are “StaffFiveLineOne” or “StaffKlavarMirckTwo”. See the
MNP-music-demo.lyfile for more.)
If the alternative staff is larger than two octaves and is not a
compressed staff (i.e. Twinline, TwinNote), then you may need to
make the following adjustment for any bass clefs that appear in
the music. Enter “
\set Staff.middleCPosition = #18” just after any instances of “
\clef bass” in the music file. Otherwise the notes may not appear in the expected places on the staff.
- Run LilyPond on your music file. Voilà! You now have a PDF of music in an alternative notation system.
Older Demo Files
These are some older demo files that are inferior to those shown above.
- Chromatic staves demo, showing various line patterns and note layouts — PDF file — LilyPond file (.ly)
- Custom note head styles (shapes) demo — PDF file — LilyPond file (.ly)
- Twinline music notation demo — PDF file — LilyPond file (.ly)
- TwinNote music notation demo — PDF file — LilyPond file (.ly)
Customizing Note Positions
staffLineLayoutFunction is used to customize the default
vertical positions of notes on the staff. For a standard pitch-proportional
chromatic staff with a semitone between each adjacent note position (line
or space), set it to use the
staffLineLayoutFunction = #ly:pitch-semitones
- Changing the interval of lines on the stave (staffLineLayoutFunction)
- Example use of staffLineLayoutFunction
- Email exchange about this example
Scheme Functions (
ly:pitch-semitonesis a Scheme function )
Other Spacing Patterns
For notation systems like Equiton or TwinNote that have a staff based on a whole tone scale with a whole tone between each adjacent note position (line or space), use the following function. (Thanks to Graham Breed for this function.)
staffLineLayoutFunction = #(lambda (p) (floor (/ (+
(ly:pitch-semitones p) 0) 2)))
For staves based on other intervals simply change the number 2 in the function above to the number of semitones in the interval you want. Change the number 0 in the formula to 1 (or 2, etc.) to adjust which notes share a line or space (and which are on different lines or spaces). See: Snippet: Staves based on a whole tone scale (or other interval)
For Twinline and similar chromatic staves with one note on a line and three in a space, use the following version of the function which uses “banker’s rounding” to get the desired 1-3-1-3-1-3… pattern.
staffLineLayoutFunction = #(lambda (p) (+ 1 (round (+ -1 (/
(ly:pitch-semitones p) 2)))))
(Note: Graham Breed has also shown how to use the
ly:set-default-scale scheme function to reposition notes: Dodecaphonic staff snippet)
Customizing Staff Lines
In LilyPond the vertical position of notes and the vertical position of staff lines are independent of each other. Notes are not placed on a line or space per se, but at a vertical position that may or may not coincide with the vertical position of a line or space.
A staff’s line pattern can be customized using
Staff.StaffSymbol and the
line-positions property. See Changing the staff line pattern (Staff Symbol Properties). The numbers ( 4 2 0 -2 -4 ) in the line of code below represent
the five standard line positions. A different list of numbers will
produce a custom line pattern.
\override Staff.StaffSymbol #'line-positions = #'( 4 2 0 -2 -4 )
It is possible to simulate bold lines by adding extra lines close
together with the
line-positions property. Go to Modifying a single staff and scroll down to “Making some staff lines thicker than the
others” for more about this trick.
Dashed or dotted lines can be achieved using the Scheme function
found in this post to the LilyPond user list. This function is also included in the
MNP-scripts.ly file linked at the top of this page.
Customizing Ledger Lines
In LilyPond version 2.15.13 or higher, ledger line positions can be
customized, including ledger lines that appear above or below the
staff and those that are internal to it. Similar to customizing
staff lines, you use
Staff.StaffSymbol with the
\override Staff.StaffSymbol #'ledger-positions = #'(-12 -10 -8 -6
-4 -2 (0 2) 4 6 8 10 12)
The numbers define positions for a series of ledger lines, this series is repeated in a cycle extending both up and down the pitch axis. The last number in the series is also the first ledger line in the next repetition of the cycle (i.e. the last number refers to the same ledger line as the first number, just in the next iteration of the series).
Internal ledger lines appear by default when custom staff line positions are set with a gap between them of 4 steps or more.
You can group multiple ledger lines together by placing them in parentheses, as shown above: (0 2). When one of the ledger lines in a group appears all of the others will appear as well. This can be used to achieve thicker, bold ledger lines by using the same trick described above for bold staff lines.
Thanks goes to Piers Titus for his work adding this feature to LilyPond. (This supersedes Kevin Dalley’s code for internal ledger lines that was never added to LilyPond.) More details…
An Older Deprecated Method
Before the method above was available, internal ledger lines could be achieved by creating a custom notehead stencil (glyph) that has the ledger line included in it, and then assigning that notehead stencil to the pitches that require a ledger line. This is how it is done in the TwinNote Demo file (linked above). With systems that do not already use custom note heads this would be more difficult since you would have to access to the default oval note head stencil and combine it with a ledger line stencil. You would also need to create different stencils for quarter notes, half notes, and whole notes, and then have a script to determine when to use which based on a note’s duration.
Noteheads can be colored: Coloring notes depending on their pitch
Notehead styles (shapes) can be customized using a modified version
of the code for coloring note heads. See our
Custom-notehead-styles-demo.ly for the modified code. This offers more fine-grained control than
property that is used for Shape Note notation. That property
only allows you to set custom shapes for each step of the scale (as set
by the key signature or the tonic property). It does not let you customize
each chromatic scale degree. For example, whatever shape you designate
for G will also be the shape for G# and Gb.)
Documentation for notehead styles (shapes):
Custom notehead shapes can be created with
ly:make-stencil, see this snippet on Using PostScript to generate special note head shapes. This PostScript stencil method was used to create the triangle
note shapes in these TwinNote demo files:
This TwinNote demo also has a different, more streamlined script for customizing noteheads based on pitch.
This override prevents LilyPond from extending stems to the middle of the staff. This is particularly helpful with multiple-octave chromatic staves, otherwise you can get stems that extend an octave or more. It is shown in this snippet: Preventing Stem Extension
\override Stem #'no-stem-extend = ##t
The following TwinNote demo LilyPond file (.ly) includes a script for adjusting the stems so that they “attach” to the note head correctly in TwinNote (not too short or too long). It also includes a script that gives half notes a double stem to differentiate them from quarter notes.
Removing Unneeded Symbols
Accidental signs, key signatures, and clefs can be removed as follows. Other unneeded symbols can be hidden: Making symbols invisible
Desired Features List
Most desired features can now be achieved as described above. Any additional desired features can be listed here, should they come to light.