Sharing my LilyPond workflow
Posted: 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:
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
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.
Code: Select all
#!/usr/bin/env bash
shopt -s expand_aliases
SERVICE1="org.mpris.MediaPlayer2.vlc"
SERVICE2="/org/mpris/MediaPlayer2"
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."
else
echo "Opening $1.midi and -.pdf"
xdg-open "$1.midi"
xdg-open "$1.pdf"
fi
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 "================"
echo
fi
done
This post isn't going anywhere in particular but I'd love to hear of other setups and tips :3