Lilypond

Lilypond is a music typesetting program, usually available in the ports or package system. It can produce sheet music, or adequate MIDI files.

Template

I like to split the MIDI from the Score, though both use the same music sections. This allows the score and MIDI to vary; perhaps the score uses a volta repeat while the MIDI unfolds the same. Or, I can disable sections in the MIDI block to only playback particular bits. Or, the score can have a RhythmicStaff for reference that is not part of the MIDI.

For example:

    % LilyPond engraving system - https://www.lilypond.org/
    \version "2.22.2"
    \include "articulate.ly"
    \header {
      title = "TODO FIXME"
      tagline = #f
    }

    tempoandetc = {
      \tempo 4=120
      \time 4/4
      \key c \minor
    }

    sopa = \relative c'' {
      c4 c c c
    }

    sopb = \relative c'' {
      d4-. d( d) d-!
    }

    msop = {
      \tempoandetc 
      \set Staff.midiInstrument = #"french horn"
      \articulate {
        % here is where to twiddle what parts to listen to
        %\sopa
        \sopb
      }
    }
    themidi = {
      <<
        \set Score.midiChannelMapping = #'staff
        \new Staff = "soprano" \msop
      >>
    }
    \score {
      \themidi
      \midi { }
    }

    ssop = {
      \tempoandetc
      \set Staff.instrumentName = #"French Horn"
      % TODO
      %\transpose c g {
        \sopa
        \sopb
      %}
      r8 r r r r r
      % TODO
      %\bar "|."
    }
    thescore = {
      <<
        \new Staff << \clef sop \ssop >>
        \new RhythmicStaff {
          c8 c c c c c c c c c c c c c c c
          c8 c c c c c c c c c c c c c c c
        }
      >>
    }
    \score {
      \thescore
      \layout { }
    }

Build

I dislike stray clicks in a PDF doing wacky things, and the rest of the commands are to produce a somewhat normalized MP3 file with (modern music tends to be too much compressed, whereby there isn't much range between the loudest and not so loud notes—maybe there is too much external noise pollution from cars and whatnot, or folks think louder sounds better?).

    $ lilypond -dno-point-and-click --silent foo.ly
    $ fluidsynth -F foo.wav foo.midi
    $ sox -G --norm=-1 foo.wav -b 16 -t wav norm.wav rate 44100 dither -s
    $ ffmpeg -f wav -i norm.wav foo.mp3
    $ rm *.wav

Mostly I use "midiplay" (a custom fluidsynth CLI tool) to listen to the MIDI output, or sometimes will import the MIDI into LMMS. There is a "music" directory in the following repository where some of the scripts are.

https://thrig.me/src/scripts.git