Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Generating sheet music - from one DSL to another

Generating sheet music - from one DSL to another

A workshop on how to typeset scores with Lilypond

Sheet music is perhaps the ultimate domain-specific language, but isn’t really accessible to programmers. It hardly has any curly brackets, and they don’t even match! This workshop for non-musicians demystifies musical notation by showing you how to generate it from a Scheme-based DSL, called Lilypond, which looks much more like a ‘normal’ programming language.

During this workshop you will learn the basic Lilypond syntax, starting with note pitches, durations and lyrics. You’ll use this to generate music as PDF that you can print, and MIDI files that you can listen to. This will be based on simple and familiar examples, starting with the world’s most recognisable tune. You’ll also learn how Lilypond separates content from presentation, and how its automatic layout creates professional print-quality results.

Peter Hilton

March 15, 2019
Tweet

More Decks by Peter Hilton

Other Decks in Technology

Transcript

  1. Workshop goals 1. Teach you enough Lilypond syntax for a

    nursery rhyme 2. Highlight Lilypond programming language capabilities 3. Creativity ⽄ 4. Fun ! 5. Reflect on the nature of domain-specific languages " !3 @PeterHilton •
  2. Missa Pro Defunctis G.P. da Palestrina Introitus qui mi Dó

    solo is, 8 ne, æ tutti Ré em tér é na nam dó at ce is. é et lux 8 tu lú a pé per tum vó in Je bi reddétur solo Te dé rúsalem. cet hymnus Dé 8 Sí on, et tí us, in te ad cá ra nis óm ó am; mé nem di ti o 8 áu vé tutti Ex ro niet. mi Dó em qui æ ne, Ré tér nam 8 é na is, dó lú a at ce pé lux et tu per is. 8 é Kyrie son, i le ri e Ky 8 solo e e Ky 4 e e ri e le le 8 ri e 3 e 6 i son son 5 Ky i e Ky ri i 7 son Ky ri Ky i son 8 le le le e e ri e son Ky ri 2 Ky e i 8 Copyright ©2019 Cappella Gabrieli Transcribed by Maarten Michielsen - Typeset by Peter Hilton - CPDL #33475 revision 11 Lilypond source https://github.com/hilton/sheet-music 2 e le Ky le e i ri son le e e 13 son son son. son. 15 14 i i i i le i son e 10 le Ky ri 8 8 9 e e Ky i i son son e le e 12 e ri e le ri e le 11 e Chri i le 8 son, ste solo 3 Chri ste Chri le le 10 8 Chri 8 2 ste Chri 6 ste le e ste 4 e 5 e 7 son son, i le 8 son Chri le Chri e i i le 9 le i ste son, e Chri Chri ison, ste, e e e 17 le le le i ste 16 Chri son e le son, e 19 son. i son. e son. son. 18 i i i i son. le 12 13 Chri son, i son, le le i 8 8 11 Chri e i e ste ste e e 15 le ste Chri i ste le e i Chri son, ste ste son, 14 son, i le ri e Ky 8 solo e
  3. son, i le ri e Ky 8 solo e e

    Ky 4 e e ri e le le 8 ri e 3 e 6 i son son 5 Ky i e Ky ri i 7 son Ky ri Ky i son 8 le le le e e ri e son Ky ri 2 Ky e i 8
  4. Missa Pro Defunctis G.P. da Palestrina Introitus qui mi Dó

    solo is, 8 ne, æ tutti Ré em tér é na nam dó at ce is. é et lux 8 tu lú a pé per tum vó in Je bi reddétur solo Te dé rúsalem. cet hymnus Dé 8 Sí on, et tí us, in te ad cá ra nis óm ó am; mé nem di ti o 8 áu vé tutti Ex ro niet. mi Dó em qui æ ne, Ré tér nam 8 é na is, dó lú a at ce pé lux et tu per is. 8 é Kyrie son, i le ri e Ky 8 solo e e Ky 4 e e ri e le le 8 ri e 3 e 6 i son son 5 Ky i e Ky ri i 7 son Ky ri Ky i son 8 le le le e e ri e son Ky ri 2 Ky e i 8 Copyright ©2019 Cappella Gabrieli Transcribed by Maarten Michielsen - Typeset by Peter Hilton - CPDL #33475 revision 11 Lilypond source https://github.com/hilton/sheet-music 2 e le Ky le e i ri son le e e 13 son son son. son. 15 14 i i i i le i son e 10 le Ky ri 8 8 9 e e Ky i i son son e le e 12 e ri e le ri e le 11 e Chri i le 8 son, ste solo 3 Chri ste Chri le le 10 8 Chri 8 2 ste Chri 6 ste le e ste 4 e 5 e 7 son son, i le 8 son Chri le Chri e i i le 9 le i ste son, e Chri Chri ison, ste, e e e 17 le le le i ste 16 Chri son e le son, e 19 son. i son. e son. son. 18 i i i i son. le 12 13 Chri son, i son, le le i 8 8 11 Chri e i e ste ste e e 15 le ste Chri i ste le e i Chri son, ste ste son, 14 son, i le ri e Ky 8 solo e 3 i son i e 5 ri son le e e Ky le e 4 i Ky e le 6 e Ky ri son 7 e ri e 3 8 8 e ri Ky e 2 Ky ri e e 12 le e e e 11 e son, Ky ri e Ky ri le le le 14 e 13 le i i son son, le le 8 8 8 son. son. son. son. son. 15 i i i i i Ky ri e 10 le e i ri e son i e 9 Ky Ky ri Graduale qui Dó na is, 8 é solo (1o ) em æ tutti Ré tér dó nam et per lux pé mi ne: 8 tu a lú 8 at ce é 8 is. Fine na a ri tér æ 8 mó me In solo stus, é rit 8 jú la ó ti di ne 8 au ab má bit. mé non tutti ti D.C. al Fine 8 4 Tractus dé um li Ab ni óm 8 fi um Dó tutti ve, sól ne, solo mi mas ni á rum ni ab óm cu lo 8 vín tó de func et solo rum tó a de tú 8 lic grá a ti rén cu suc te tur íl lis 8 re me án nis, ó vá de re ju 8 e ci um ul ti dí et solo lú næ æ cis tér di 8 ne a ti be tú fru i. 8 tutti pér Offertorium 9 ste, glo glo ste, Rex 8 ste, ste, Chri Rex Rex Do ne ne 3 ne Do mi mi mi Do æ, ri 2 Do mi su mi 8 5 Chri ne Chri Je ne mi su ne Je Je Je 4 Do su ste, Chri 7 su Je Chri su Chri Je Do 6 ste, su 8 15 um um om a be de fi a 16 de ra ni be fi fi um ni ni a ra 14 mas mas ni ni ni a li mas om om ni fi 18 de de mas de um de mas um li li li ni li a um um ni 17 ra om be Rex æ, Rex Rex ri glo glo glo Rex 8 8 10 ni fi func func om um li æ, æ, ri 12 æ, æ, æ, 13 ra ra li li be be li ri glo æ, 11 glo glo ri ri ri ri 5 fer in fer in 24 nis nis in nis 22 rum to rum rum rum rum nis 23 poe in poe poe de de poe de de fer in 26 nis fer ni fer de in 25 ni, ni, poe et pro pro de et de fi li pro et 8 8 fer 19 27 de de ni, um to to et ni, ni, et func 21 func to um de de de to li de 20 um func ra ra be ra be be cu: 31 li li li ra as, e be as li li li li e e e as as, 32 la la la le o o cu: cu: cu: 30 re o o 29 do do do do do fun fun pro la o o de nis, re re nis, de 8 8 28 fun fun fun de de le o pro le le 36 de de as e e o as o as 34 be be 33 ra ra e be ra de 35 o o re re le le 41 as as at e e e e tar as tar tar sor sor sor sor ab ab ab ab at at at 40 be be be be ta 43 rus, rus, ta ca ne 42 as rus, ne tar ta ta dant dant in in in scu ne scu scu 8 8 ne 37 44 ca rus, dant ca 38 nis, nis, nis, nis, nis, ne ne ne ne 39 le ob ob ob 45 o 6 ni ni ni ni 50 fer fer fer fer san san san rum: rum: rum: rum: sig 48 scu 49 sig sig sig sed sed sed fer fer 52 sed ni ni ni sig sed sed cha cha cha ctus ctus ctus Mi Mi Mi el el 51 sig sig el, ctus ctus 53 Mi Mi Mi re cha cha cha el el el re 8 8 fer 46 san san san ctus in ca in in 47 ob ob scu ob scu scu sed dant ob in rum rum rum: ca ne ne re re dant dant ne dant ca ca cem cem san 59 san ctam. ctam. Quam Quam Quam ctam. ctam. 58 in lu lu in in lu san lu cem san cem in o pro pro pro lim lim lim 60 o o o bra hæ bra 61 Quam hæ hæ A A A bra tet tet tet tet 55 e e e e sen sen sen sen 8 8 mi 54 præ præ præ præ lim cem cem san lu san lu ctam, ctam, ctam. ctam, 57 san san in in as 56 lu lu as as as in cem in cem se ni ni, mi et mi se et se et 66 se et mi mi ni e e e 68 e se ni e ni 67 mini mi hæ sti, 64 mi et se et sti, sti, sti, sti, mi pro mi pro si si si 65 si mi si hæ sti, sti, o pro 63 Quam sti, mi si bra A bra 8 pro 8 62 A si pro lim mi se 69 ius, mi ius. ius. ius. 70 ius. ius. si mini e 7 dis dis dis fe dis fe of of of dis, mi ne, 8 lau lau lau 9 dis, lau ne, as as Ho sti sti sti sti as as 3 Ho 2 ces ces ces ces 5 Ho 8 ti ti bi, bi, et et pre pre 4 et pre et pre Do ne, ne, 7 lau Do Ho ti mi lau bi, Do Do ti 6 8 bi, mi mi 15 ma a ma ma ma bus bus bus bus ni sci 14 pro pe pro sci su sci pe pe pe a a a ni pro ni ni pro rum rum rum 18 ho ho ho qua qua qua 16 il il il il 17 lis, lis, lis, lis, of fe ri ri mus; mus; ri 11 mus; ri mus; fe 8 8 10 e di rum di e qua di tu 13 sci su su tu tu su 12 tu as, fac as, fac e mi Do Do 25 e Do Do 24 e e fac as, as, fac ho e e me di ne, mi ne, 26 mi ne, mi mor de ne, de am am am am ri ri ri ri 21 fa fa 8 8 19 mo 20 me me me mo mo mo ci ci ci 23 mus: mus: mus: fa ci fa mus: 22 re vi vi re re ad re ad ad ad 34 trans te i te trans i i i 33 mor te trans te de de te tam. tam. tam. tam. 35 vi vi mor re re i 29 27 ad 30 ad ad re vi vi mor i 28 8 8 trans i i trans re, te trans mor mor te de te de de de 32 mor trans mor trans Attacca vi tam, tam, tam, 31 8 o o o o o lim, A A A A 2 lim lim lim lim si Quam o Quam Quam si mi si mi mi 3 mi bra bra bra Quam pro pro pro pro bra hæ hæ hæ hæ Quam Quam lim o o 5 Quam 8 o lim lim Quam Quam si si si sti, sti, sti, sti, 4 bra bra hæ hæ pro mi mi mi si sti, 7 si --mi pro pro Quam bra 8 A A A hæ pro 6 e 13 e 12 ni e ni se se mi et mi mi ni e e ni mi e 15 ius. ius. ius. ius. ius. se ius, mini 14 bra pro A bra pro mi mi 9 hæ hæ 8 8 8 lim o sti, A lim pro sti, sti, 11 et se et se sti, sti, sti, sti, et et mi mi et se se ni ni, si mi pro mi si si si 10 Sanctus ctus, 2 San San San ctus, 9 San San San San 5 ctus, San San 3 4 ctus, ctus, 6 San ctus, San 7 8 8 ctus, ctus, 8 ctus, San San 9 14 ctus, ctus, San San 13 ctus, ctus, ctus, San ctus, San minus ctus, ctus, San ctus, ctus, 15 Do ctus, 16 Do San San mi nus Do mi mi Do ctus, ctus, 8 8 10 De Do 17 San ctus, 12 San ctus, San 11 San oth, De 20 Do nus ba mi De nus ba us us 19 Sa Sa Sa oth, Sa oth, mi De us ba ba Do nus Do De Do 22 us us De 21 Sa Do Sa mi nus mi Sa ba ba Do oth, oth, oth, us us us De 23 De ba Sa ba ba Sa us Sa ba Sa 8 8 18 minus nus nus, mi De Pleni sunt nus De us nus mi oth. oth. oth. 24 oth. ba Ple Ple oth. Ple 25 et ter ter et ni cæ ra 29 ra li ter cæ sunt sunt 27 sunt li li et 28 li ple cæ sunt cæ ri a ri glo ter et 30 sunt ra 31 tu cæ ri ra a glo glo a, et tu glo a, a glo a 33 ter a, a, ri 8 8 26 32 li ri tu glo tu a tu ri a a glo tu ni li, ni Ple cæ ni ni a glo glo tu ri ra a, tu ri ri 34 10 tu a. a tu tu 37 tu glo ri ri a glo a a ri 36 in san ex 39 a, a. 38 Ho a. a. san san in na Ho Ho na cel sis, sis, in Ho san sis, ex Ho 41 8 8 35 cel ex 40 na ex in cel cel ex sis, Ho a, glo a, in san na Ho ex in san 42 na cel in na 44 ex sis, san in in ex in ex cel na san cel cel 45 Ho ex cel in san na ex cel 46 sis, san sis, Ho 47 sis, Ho ex in cel in na ex cel 49 cel ex 8 8 Ho 43 na san sis. in 48 cel san Ho na Ho na sis, sis, san na in ex cel sis. sis. sis. sis. 50 Benedictus ctus qui ne 4 ve Be di 3 ne 6 qui Be di 5 8 ctus Be di Be 7 Be ne ctus 8 nit, Be ve di ctus Be 2 ne ne ne ne qui di 8 nit, 11 no ne 13 nit nit in ne mi no Do Do nit in no in 11 nit mi in no 12 no Do ne mi 14 mi in Do 15 mi mi ne ni, ni, Do no ne 17 ni, no no in mi ne mi in Do ne no mi 9 8 8 mi mi ne mi ni, in 16 qui ve ctus ve 10 ve ve qui nit di ctus ve di mi Do ctus qui qui Ho cel san 25 Ho na sis, sis, san na in na cel ex na Ho ni, in san cel ex sis, in san 24 mi Do Do ni, Do mi 19 Ho ne na mi mi no Ho ni. ni. san ni. 20 na Ho in san ex 21 Ho na san in 18 8 8 mi mi mi ne mi ni. ni. Do cel sis, in Ho sis, san ex Ho 23 na ex in cel ex sis, 22 cel 31 cel ex cel cel cel Ho na san in 30 na ex in na san ex in ex 32 sis. sis. sis. sis. 33 27 ex cel san cel cel in sis, na 8 8 san in 26 in ex cel Ho in ex na ex sis. Ho 29 Ho san sis, sis, in san Ho na cel 28 ex sis, 12 Agnus Dei i, gnus i, A A De gnus De A i, 9 A 4 De A gnus 2 gnus De 3 A A De 6 8 gnus i, 5 De A gnus 8 gnus i, A 8 i, gnus 7 De qui tol tol tol lis 15 tol lis lis qui qui 14 i, i, qui mun mun mun mun qui di, ta ta ta ta di, di, di, 17 pec pec pec ca ca lis pec ca ca 16 gnus A gnus 11 A i, De 8 8 10 qui qui qui De 12 De i, i, i 13 A gnus De gnus De e 25 is e na pec do na na di, di, di, di, 24 mun mun do do do na lis lis lis lis ta ta ta ta 19 tol tol tol pec pec ca ca ca ca tol qui qui qui qui 21 di, di, di, di, tol tol tol pec tol 8 8 18 mun mun mun mun 20 mun mun ca 23 pec ta ta mun ca ta di, ta lis lis pec 22 pec ca ca pec lis lis pec ca ta 13 re e e re re 32 is is na do re do is is is na re 31 em, em, 33 em, em, em, qui qui qui qui qui qui qui 27 qui qui do em, em, 28 re em, em, 8 8 e e 26 is re re is re is na na do na e is, e na e is, e 30 do do na e 29 do A A gnus 2 A pec pec ta pec A ca lis lis De i, A 4 gnus gnus gnus De De De 3 A A 8 De gnus gnus i, gnus gnus i, i, 5 A qui qui qui lis tol lis tol 8 8 tol tol qui De De De 6 i, i, i, i, 7 ta ca 12 do 14 mun di, lis mun di, di, di, pec ta ca mun ca mun 13 pec ta re re e na na na 15 do do is is na is 16 e do e e em, em, em, qui em, qui qui pec ta ta ca ca mun 8 8 is 9 qui 17 re re qui lis qui tol 11 tol di, di, di, ca tol lis ta pec pec qui mun di, 10 mun ta mun ca 14 re is re re re 25 is e e 24 na is is re is na na do do do 19 na qui em, em, em, em, em, 26 qui qui qui qui do is is re re re re qui 21 8 8 18 is is e 20 e e e na do do na do na na e e e na 23 quiem, qui em, em, do em, do 22 qui gnus gnus 2 i, gnus A 9 De gnus A A gnus A gnus A De De 3 A A i, 4 A gnus De i, A 6 gnus gnus i, De A De gnus 5 De gnus i, i, 8 8 De A gnus A i, A 7 De 8 i, ta 15 ta pec pec ta ta mun mun ca ca mun mun ca pec tol qui tol 13 pec lis ca 14 lis tol lis pec ca lis lis 17 qui lis tol tol lis di, di, di, di, qui qui tol qui tol 16 De ca ta gnus De i, De A 8 8 10 ta pec pec mun ca De i, i, i, 12 lis qui qui i, tol qui De i, 11 gnus 15 e na 25 re e do na e do 24 re qui na em, mun qui is em, do na do ca ca pec ta, di, 19 qui pec pec mun na 20 di, do ta mun di, e 18 8 8 di, ta ta mun ca do do na e qui 22 is 23 e is em, re di, is 21 do na re ter ter 31 nam, sem ter pi sem sem nam, pi pi sem 30 nam, nam. 32 nam. nam. nam. 33 pi ter nam. is sem re is qui 27 em, em, em, qui re qui 8 8 26 e e re re em, na is is pi ter ter ter 29 ter pi nam, qui pi em, sem sem 28 ter sem sem pi pi Communio na Lux tér num, tér é tutti lú ce at æ ne, cum is, Dó solo mi tú is in 8 æ tis sánc na dó nam Dó is, é qui tér æ em pé ne; mi per lux et at ce lú is; é 8 a tu pí us Ré solo es. qui a pá in cant ce. Re és qui sánc Am tú en. æ tér num, 8 in is tis a pí es. tutti us cum qui
  5. Workshop instructions https://github.com/hilton/lilypond-workshop 1. Clone the repo 2. Install Lilypond

    and Frescobaldi 3. (Optionally) install SimpleSynth or another MIDI device !10 @PeterHilton •
  6. Basic syntax 1. Pitch - note names 2. Pitch -

    octaves and clefs 3. Pitch - relative mode 4. MIDI output 5. Common errors 6. Bar checks 7. MIDI instruments !12 @PeterHilton •
  7. Ro, ro, ro din båt = 100 din båt, ta

    8 6 Ro, år e fatt. ro din ro, de, vug gen de vug gen Kat ov er 5 te gatt de, vug gen de, Vug gen
  8. Et gammeldags dansk navn for både Skagerrak og Kattegat var

    Norgeshav, medens nordmændene omvendt i de gamle sagaer bruger betegnelsen Jótlandshaf (‘Jyllandshav’). An old-fashioned Danish name for both the Skagerrak and the Kattegat was Norwegian Sea, while the Norwegians, conversely in the old sagas, use the term Jótlandshaf (Jutland Sea). https://da.wikipedia.org/wiki/Ro,_ro,_ro_din_båd
 Google Translate
  9. Row, row, row your boat, Gently down the stream. If

    you see an alligator, Don’t forget to scream. Row, row, row your boat, Gently down the stream. Throw your teacher overboard And listen to her scream. The Culture of Adolescent Risk-Taking Culture and Human Development via Wikipedia
  10. % Basic Lilypond syntax \version "2.18.2" \header { title =

    "Title" } \score { \relative c' { \time 6/8 \tempo 4 = 140 \set Staff.midiInstrument = "marimba" c4. c r4. d4 e8 f8 g c r4. } \addlyrics { ly -- rics au -- to -- ma -- tic too! } \layout {} \midi {} }
  11. Twinkle, Twinkle, Little Star what I won = 140 der

    you are. kle lit kle, twin How tle Twin star, mond in a dia the sky. a bove the 5 Up so high, Like world what won I der Twin kle, you are. lit kle 9 twin How tle star,
  12. \version "2.18.2" \header { title = "Twinkle, Twinkle, Little Star"

    } partA = \relative c'' { c4 c g' g | a a g2 | f4 f e e | d d c2 | } partB = \relative c'' { g'4 g f f | e e d2 | } partC = \relative c' { c4 c' e c | f c e c | d b c a | f g c,2 | } partD = { e'4 g, d' g, | c g b g | } \score { \new PianoStaff << \set Score.midiInstrument = "vibraphone" \new Staff << \relative c'' { \tempo 4 = 140 \partA \partB \partB \transpose c cis { \partA } \bar "|." } \addlyrics { Twin -- kle, twin -- kle lit -- tle star, How I won -- der what you are. Up a -- bove the world so high, Like a dia -- mond in the sky. Twin -- kle, twin -- kle lit -- tle star, How I won -- der what you are. } >> \new Staff << \relative c' { \partC \partD \partD \transpose c cis { \partC } } >> >> \layout {} \midi {} }
  13. \version "2.18.2" \header { title = "Three blind mice vs

    Frère Jacques" } mice = { \repeat unfold 2 { e4. d c r } \repeat unfold 2 { g' f4 f8 e4. r } \repeat unfold 2 { c'4 c8 b a b c4 g8 g4 r8 } \repeat unfold 2 { e4. d c r } } brother = { \repeat unfold 2 { c4. d e c } \repeat unfold 2 { e4. f g2. } \repeat unfold 2 { g4 a8 g4 f8 e4. c } \repeat unfold 2 { c4. g c2. } } \score { << \new Staff << \time 12/8 \tempo 4. = 140 \set Staff.midiInstrument = "vibraphone" \relative c' { \mice R1. R R R R R } >> \new Staff << \set Staff.midiInstrument = "recorder" \relative c'' { R1. R \brother R1. R R R } >> \new Staff << \set Staff.midiInstrument = "vibraphone" \relative c' { R1. R R R \mice R1. R } >> \new Staff << \set Staff.midiInstrument = "recorder" \relative c'' { R1. R R R R R \brother } >> >> \layout {} \midi {} }
  14. \version "2.18.2" boat = { \relative c' { c4. c

    c4 d8 e4. e4 d8 e4 f8 g4. r c8 c c g g g e e e c c c g'4 f8 e4 d8 c4. r } } \score { << \set Score.midiInstrument = "marimba" \new Staff { \time 6/8 \tempo 4. = 100 \repeat unfold 2 \boat R1. R R } \new Staff { R1. \repeat unfold 2 \boat R1. R } \new Staff { R1. R \repeat unfold 2 \boat R1. } \new Staff { R1. R R \repeat unfold 2 \boat } >> \layout {} \midi {} }