Search code examples
lilypond

How to integrate midi export into existing lilypond score


I'm trying to do a MIDI export of existing Lilypond scores, but am unable to do so if there's more than one staff. I'm new to Lilypond but have been through the documentation and forums with no luck.

Wrapping the code below in \score doesn't work. If I take the first \relative c' section and delete everything after it, things appear to work fine, but I need the score in its entirety, including the paper and markup instructions.

Also tried \new Staff, as seen in some of the documentation, but ended up exactly where I started.

\score {

\header{
    title = "Exercise: C, D, E Notes"
}

\paper {
  #(set-paper-size "arch a" 'landscape)
  system-system-spacing #'basic-distance = #20
  markup-system-spacing #'basic-distance = #15
  indent = 0\cm
}

    \markup { \bold "Treble Clef - Right Hand" }
    \markup { \small Fingering }
\relative c' {
    \time 4/4
    \override Staff.TimeSignature #'style = #'() 
    \clef "treble"
    c4 c c c | d d d d | e e e e | e2 e | \break
    e4 e e e | d d d d | c c c c | c2 c  | \bar "|." \break
}


    \markup { \bold "Bass Clef - Left Hand" }
    \markup { \small Fingering }

\relative c, {
    \time 4/4
    \override Staff.TimeSignature #'style = #'() 
    \clef "bass"
    e4 e e e | d d d d | c c c c | c2 c  | \break
    e4 e e e | d d d d | c c c c | c2 c  | \bar "|."
}

  \layout { }
  \midi { }
}

\version "2.18.2"  % necessary for upgrading to future LilyPond versions.

Solution

  • I would assign each of the little sections of music to individual variables and then create separate score blocks for each as well as a unique score block for midi output only:

    \version "2.18.2"  % necessary for upgrading to future LilyPond versions.
    
    \header{
        title = "Exercise: C, D, E Notes"
    }
    
    \paper{
        #(set-paper-size "arch a" 'landscape)
        system-system-spacing.basic-distance = #20
        markup-system-spacing.basic-distance = #15
        indent = 0\cm
    }
    
    mark_A = ^\markup { \bold "Treble Clef - Right Hand" }^\markup { \small Fingering }
    mark_B = ^\markup { \bold "Bass Clef - Left Hand" }^\markup { \small Fingering }
    
    music_A = \relative c' {
        \time 4/4
        \override Staff.TimeSignature #'style = #'() 
        \clef "treble"
        c4-\mark_A c c c | d d d d | e e e e | e2 e | \break
        e4 e e e | d d d d | c c c c | c2 c  | \bar "|." \break
    }
    
    music_B = \relative c, {
        \time 4/4
        \override Staff.TimeSignature #'style = #'() 
        \clef "bass"
        e4-\mark_B e e e | d d d d | c c c c | c2 c  | \break
        e4 e e e | d d d d | c c c c | c2 c  | \bar "|."
    }
    
    
    \score{
        \new Staff \music_A
        \layout{}
    }
    
    
    \score{
        \new Staff \music_B
        \layout{}
    }
    
    \score{
        \new Staff {\music_A \music_B}
        \midi{}
    }
    

    More info here: http://lilypond.org/doc/v2.19/Documentation/learning/multiple-staves