Using the LilyPond format
as input

Lilypond is free music notation software. It can be found at the lilypond website.

In an effort to create a more interactive music theory learning environment, we're combining the power of two different software systems: Tone.js and Lilypond. Lilypond is free notation software from the GNU project. It can produce beautiful music scores and it has a texted based input format. I've adopted the lilypond language as an input format for Tone.js enabled web pages. This page is a short introduction to the lilypond file format (of which we're only using a small portion). For this class I suggest you create a text file that you can keep all of your lilypond note code for assignments. Here is a template. You might call it Music10Lilypond.txt (or whatever). For writing code, it's best to use a basic text editor instead of full featured word processor (like Word) because word processors sometime insert invisible characters that cause problems in the code yet it doesn't appear anything is wrong (the problem is an invisible character!) Yeah, that can cause frustration trying to debug invisible stuff. Common free text editors include sublime text (free to try), textedit (free). notepad (free).

Note entry

In Tone.js the pitch can take on different forms, i.e. frequency (440), pitch/octave (A4). In lilypond the pitch is given names using lowercase only. For instance the comparison between Tone.js and lilypond for the note 'middle C'

The lilypond program doesn't use '#' (sharp) or 'b' (flat) or even those words. Instead the Dutch 'is' (sharp) and 'es' (flat) are attached to the letter name, i.e. fis (F#) or ges (Gb). (lilypond's author/programmer is Dutch). You'll get used to it easily.

The octave is indicated by the appostrophe (') character or the comma (,) character. c' is middle C, c'' is one octave higher. Here is a list of the octave markings:

Using octave marks on every note is known as "absolute octave entry' entry method. As it turns out, we won't need to use these octave marks on every note. We'll use an entry method known as "relative octave entry" which allows us to set the octave of the beginning note and then lilypond will choose the octave of the next note by choosing that letter name that is closest to previous note. If you want a different octave than what that rule results in, you can add an octave mark, using (') for one octave higher than the default, or (,) one octave lower (don't add the parentheses marks, just the appostrophe or comma symbols). The relative octave method will save alot of time in manual entry.

Durations

The duration is attached to the note in the form of a number. For example c4 means a quarter note C. If the next note is the same duration as the previous, you don't have to attach a number to the note. Only change the duration number when a new duration is needed. Here is a list of the common duration syntax:

Here is an example of a C major scale using both absolute and relative methods. In this short example there are less key strokes in the 'absolute' method but for longer passages of music, the 'relative' method is the better method for doing it by hand. The absolute method is very good for computer generated lilypond files.

The relative mode version is already in the lilypond note entry field ready for you to click play. Change the '4' to an '8'. Experiment, go ahead, mess around!

Enter your lilypond note code here:

| tempo: | | volume:

Ties

Two notes can be ties together using the tilde symbol (~). i.e. e8~e2 = and eighth note E is tied to a half note E. Currently only two notes can be tied together. The functionality of longer chains of tied notes is not yet implemented.

Rests

Rests are indicated by using 'r' instead of a letter name. Attached to the 'r' is the number indicating the duration of the rest. i.e. r8 = eighth note rest, r2. dotted half rest. Rests are not used with ties, just add another without a tie. i.e. { c4 r2 r8 c8 } (quarter note C followed by a half note rest and eight note rest followed by an eighth note C.)

Optional barlines

You can insert the vertical bar '|' as a barline if you want. It can help you keep track of where you are when entering a long passage. You can also use the '|' symbol as a marker for larger sections. As long as the '|' symbol has space around it, it will be ignored, it is strictly for helping you keep track of your location in a phrase.

Triplets

Lilypond has a powerful tuplet feature that allows you to divide the beat in to any subdivision. For our purposes we can use only the triplet subdivision ( \\tuplet 3/2 {...} ). It is used with the following syntax:

\\relative c' { c4 b \\tuplet 3/2 { c4 d e } f1 }

The tuplet section ( \\tuplet 3/2 { c4 d e } ) will create a quarter note triplet of the notes C D E. A longer triplet section is created by just continuing within the tuplet braces (assuming it's the same triplet type, you can't mix eighth note triplets and quarter note triplets within the same tuplet braces).

i.e. \\tuplet 3/2 { g8 gis a ais b c cis c b bes a aes g gis a ais b c cis c b bes a aes }

Using the Lilypond code

We'll use this small portion of the lilypond language as an input language for the Tone.js enabled web pages so the assignments can been heard and more importantly, experimentation can take place. And the files that you create can also be used with lilypond to create a notated version of your work. Unfortunately it won't be automatic. You'll need to keep your lilypond code in your own file. You'll paste the note code into the web page to hear it. For using the note code with lilypond your note code will need to be added to a template (that is done for you by the assignment page). The assignment pages will deliver a lilypond-ready version for you. You'll need to copy it from the output area (don't forget to paste it into your class lilypond file and save the updated file). Open lilypond and paste the output file into lilypond manually. See instructions here. The process is kind of clunky. But when you do it, you'll see your assignments printed out beautifully on the screen (in pdf format).

Below is a list of the Tone.js enabled assignments.

  1. write out a C major scale (using \relative c' with c4 as first note)
  2. write out all of the sharp Major Scales ( 'is' = sharp, 'es' = flat i.e. fis = F#, ges = Gb)
  3. write out all of the flat Major Scales ( 'is' = sharp, 'es' = flat i.e. fis = F#, ges = Gb)
  4. write out rhythm figures on a single note
  5. write out rhythm figures on a single note Using rests.
  6. write out rhythm figures on a melody note Using triplets and ties.
  7. write in key signature (also time signature and tempo)
  8. write out A natural minor, A harmonic minor and A melodic minor Scales
  9. write out Minor scales for sharp keys
  10. write out Minor scales for flat keys
  11. write out intervals broken thirds, fourths, fifths, sixths, sevenths, octaves In the key of C
  12. write out intervals broken thirds, fourths, fifths, sixths, sevenths, octaves In the key of your choice
  13. write out specified intervals (quiz)
  14. write out Major, Minor, Diminished and Augmented triads with a root of C.
  15. write out diatonic triads in C major.
  16. write out diatonic triads in A minor.
  17. write out specified triads (quiz).
  18. write out the modes of C major.
  19. write out the modes all starting on D.
  20. write out specified modes (quiz).
  21. write out harmonic cadences in C major.
  22. write out harmonic cadences in C minor
  23. write out harmonic cadences in A major
  24. write out harmonic cadences in A minor
  25. write out specified harmonic cadences (quiz)

The Chorales of J.S.Bach have been used as a model for 4-part writing. I've been entering several of the Chorales into a ToneJS/Lilypond environment so that a student can hear the chorale, listen to individual phrases (from one fermata to the next) and using the exported lilypond file to create the score of that chorale.

Using the Lilypond application to open your lilypond score

Lilypond is free music notation software. It isn't a web based utility, you'll need to download it and run it on your personal computer. It can be downloaded at the lilypond website. Follow the instructions at the website for installation. Once installed, you can use it to create pdf copies of your assignment lilypond scores. It's magical. Part of the magic is having Adobe Acrobat Reader. (most of us have that already but if not, get Acrobat Reader, its free also). But before we talk about the process of using Lilypond to create our musical scores, let's first examine a typical lilypond score and identify some characteristics of lilypond files that haven't been discussed yet. Below is shown the lilypond score output generated for you from the web page for assignment 1


%{ 
 Assignment on Thu Feb 01 2018 
%} 
\version "2.18.2"
\header { 
  title = "Assignment on Thu Feb 01 2018"
  composer = ""
  opus = ""
}

myMelody =  { c'4 d' e' f' g' a' b' c'' b' a' g' f' e' d' c'2 \bar "|." }

\new Staff {
\clef "treble"
\key c \major
\time 4/4
\tempo  "moderato" 4 = 90
\myMelody
}

This is a basic template for a simple lilypond score. Notice near the bottom it declares this is treble clef in the key of C major with a time signature of 4/4 and a tempo of 'moderato' 4 = 90. All of that was automatically provided for you. At the top of the file contains a 'comment'. Programming languages have the concept of 'comments', which are sections of the code file that are inside of special boundary markers. These 'comment' sections are not used in the actual code. The boundary markers for lilypond code are '%{' for beginning a multi-line comment. and a closing comment boundary marker of '%}'. Everything in-between those markers is ignored by the code compiler. Comments are for the programmers to read (for whatever purpose). In this case the comment is "Assignment on Thu Feb 01 2018" which is a time stamped message automatically added to all assignment lilypond scores. One more thing about comment boundary markers, the "%' symbol by itself is a single line comment boundary, everything to right of the '%' symbol becomes a comment and won't be evaluated as lilypond code. NOTE: The assignment page's input field cannot process comments yet so don't put any comment in your lily note entries. The comment show up in the lilypond score that is an output. This score has an auto-generated value for the title (same as the comment), and blank values for composer and opus.

The notes that were provided as input are now labeled as "myMelody". But this is weird, it was entered using the \\relative octave entry and now its been translated into absolute octave entry. Yes the assignment page's software made the change. As mentioned earlier, the absolute octave entry mode works well with computers. The processing is actually easier and the computer doesn't mind putting in all of the octave marks. The 'myMelody' name shows up again at the bottom of the score. The first time was to define what 'myMelody' actually meant (what notes, durations, etc). The second time was to add it to the score. If you read some of the documentation at the lilypond website you will gain a better understanding of the lilypond format. But the assignment pages will take care of that part for you so that you need only enter the notes (and occasionally some other things as time goes on). Since you now have a lilypond score you could, if you wanted to, make changes. You could add your name as the composer or change the displayed title or tempo. You could add more comments using the proper boundary markers. I don't advise you to change the clef unless you want to see several ledger lines, but you could. Or you could leave everything as is.

So assuming you've downloaded and installed lilypond (and Acrobat Reader) here are instructions for how to use your lilypond score code to create the pdf score.

  1. Open Lilypond.
  2. It will open a default window. We can use that window but we don't need its contents, we have our own score to use. If the window isn't already blank, Select All ('command-a' shortcut on mac) so you can delete all the contents (press delete). It isn't actually necessary to delete it before you paste your score in the next step, but I want to make the point that we don't need their default file contents.
  3. Copy your lilypond SCORE code (not your shorter lilypond note code) from your course lilypond file (the copy you saved while doing the assignment). Now paste it into the lilypond window. .
  4. From the lilypond 'File' menu select Save (or Save As)
  5. Before saving, type in a filename of 'assignment1.ly' (must have the '.ly' extension), (Optional) at the save dialog box, created a new folder for your .ly files inside the Lilypond folder. Name it something like 'myLilypondScores'. (end Optional).
  6. click Save. You just saved your lilypond score code as a lilypond file. (with extension '.ly'). But we're not done yet.
  7. From the lilypond 'Compile' menu select 'Typeset file' ('command-r' shortcut on mac).
  8. You'll see another window open which prints the realtime status of the compilation operation. If the file compiles correctly, the magic happens.
  9. Magically, Adode Acrobat automatically opens and displays your score in music notation.
  10. You say "Wow, cool".
  11. A pdf version of your score has been saved in the same folder as your '.ly' file.
  12. NOTE: If you find there is a mistake and you need to fix the '.ly' score to re-compile, you'll need to close the existing pdf file before you re-compile or a new pdf won't be generated.

That's the way it is supposed to work. Give it a try with assignment 1, write out a C major scale.


Back to the Tone.js Setup page.