Sharing my LilyPond workflow

Do you typeset your scores on Linux? Share your thoughts, tips, and tricks here.

Moderators: khz, MattKingUSA

Established Member
Posts: 7
Joined: Fri Apr 12, 2019 5:44 pm

Sharing my LilyPond workflow

Postby Jorin » Mon Aug 12, 2019 9:00 pm

Hey! I figured I ought share my workflow here because absolutely no one anywhere else would show any interest in my extremely wonky but fully functional workflow.

So, my work uses four tools:

  • neovim, my editor of choice. There isn't a whole lot to unpack here -- just my personal preferences. The official plugin isn't very useful aside from the highlighting. Last time I tried using it I believe it was hardcoded to use some rather old, obscure PDF viewer for example. One really neat trick vim enables is using split views to edit in two places at once. So I'll usually keep one pane for the bass and one for the drums, for example.
  • Okular, the PDF viewer shipped with KDE. It's quite potent, and it has a reload on file change feature, which is exactly what I needed. Another feature, one that I haven't quite bothered working out, is making the links to the source code work nicely with vim. Out of the box, I have Kate as my default text editor. Making nvim play nicely with them will probably require a bit more effort since it's going to require some special commands in order to not just spawn a new shell with a new nvim instance, but rather go to the line in the existing session (if it exists).
  • VLC. Just for MIDI playback. Unfortunately doesn't support reload on file change, but we can work past that. A caveat is that Manjaro doesn't ship VLC with the MIDI plugin, so I have to compile that manually.
  • A watcher script, presented further down. It requires inotify-tools. I run it from my lilypond source directory, and it compiles on file change, and reloads the MIDI in VLC. Okular does that on its own so luckily that's not a problem. It has some rough edges, e.g. reloading MIDI even when the source doesn't compile, but I'm sure you could work that out easily.

The watcher script

Code: Select all

#!/usr/bin/env bash
shopt -s expand_aliases


alias qdbus_rem="qdbus $SERVICE1 $SERVICE2 org.mpris.MediaPlayer2.TrackList.RemoveTrack"
alias qdbus_uri="qdbus $SERVICE1 $SERVICE2 org.mpris.MediaPlayer2.Player.OpenUri"
alias qdbus_pau="qdbus $SERVICE1 $SERVICE2 org.mpris.MediaPlayer2.Player.Pause"

if [ "$1" == "" ]; then
  echo "Not opening anything."
  echo "Opening $1.midi and -.pdf"
  xdg-open "$1.midi"
  xdg-open "$1.pdf"

inotifywait -e close_write -mr . |
while read -r directory events filename; do
  if [ "`sed 's/^[a-zA-Z1-9_-]\+.//' <<< "$filename"`" == "ly" ]; then
    echo "================"
    fname_base=`basename $filename .ly`
    lilypond -o "$directory$fname_base" "$directory$filename" || notify-send "Failed to compile $filename."

    to_remove="$(qdbus --literal org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.TrackList.Tracks | sed 's/\(.*{.*: \)\(.*\)\(]}]*\)/\2/')"
    uri="file://$(realpath $directory$fname_base).midi"
    # Remove previous track (doesn't actually pay attention to what it was...)
    qdbus_rem "$to_remove" || echo "Failed to remove previous track."
    qdbus_uri "$uri" || notify-send "Could not reload track via URI $uri"
    # sleep 1 && qdbus_pau || echo "Failed to pause VLC."
    echo "================"

All in all, it's a duct-taped hack, rough around the edges, but I feel like each and every individual component works a lot better than something like Frescobaldi does, and so I'd rather take this. Writing in vim is a joy to me because of how efficient it is and my only wish is that it would be more adapted to it. There's a lot that could be done there as the editor is rather naive to how lilypond works. The biggest lack is a linter, which unfortunately isn't something provided by lilypond as far as I have been able to tell. It might be possible to work something out but it'd be a lot of work. It would also be really cool if you could do stuff like using <C-a> and <C-x> to change note values and rhythms properly.

This post isn't going anywhere in particular but I'd love to hear of other setups and tips :3
metal bassist

Established Member
Posts: 7
Joined: Mon Nov 26, 2018 12:49 pm
Location: Seoul, South Korea

Re: Sharing my LilyPond workflow

Postby rizzin » Tue Aug 13, 2019 7:21 am

That's neat!

I also use vim to write Lilypond files. Evince is another pdf viewer that hot reloading of files.
My workflow is pretty basic, really: come up with a line on the instrument -> type that stuff in vim -> save (:w) -> run the command before the last one (:, up, up) which happens to be export to pdf -> immediately see the result in Evince.
Guess having a watcher like yours would be even more comfortable.

I share the sentiment that a vim plugin dedicated to working with lilypond files would be a great addition!

Established Member
Posts: 6
Joined: Sun Oct 19, 2014 6:16 pm

Re: Sharing my LilyPond workflow

Postby thumbknuckle » Thu Aug 22, 2019 12:26 am

Not to be that guy, but there is a very usable EMACS mode for Lilypond. I've been been writing all my Lilypond code with it since 2003 or so. Started with Lilypond 1.8 I think. For larger projects where multiple scores are being combined in to books I use a Ghostscript and GNU Make. Essays and composition notes and such are done with LaTex and lilypond-book. Revision history of everything is handled with subversion.

The makefiles, shell scripts, LaTex documents, and lilypond source are all edited in EMACS. I like Ghostview for previewing.

I have some scores where fragments of lilypond generated postscript is embedded in documents I make with Xfig. I've attached an example.



You do not have the required permissions to view the files attached to this post.

Return to “Notation Editors”

Who is online

Users browsing this forum: No registered users and 2 guests