Page 1 of 1

Sharing my LilyPond workflow

Posted: Mon Aug 12, 2019 9:00 pm
by Jorin
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

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
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

Re: Sharing my LilyPond workflow

Posted: Tue Aug 13, 2019 7:21 am
by rizzin
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!

Re: Sharing my LilyPond workflow

Posted: Thu Aug 22, 2019 12:26 am
by thumbknuckle
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.
maze11.bass.pdf
(22.39 KiB) Downloaded 254 times
cheers

-r

Re: Sharing my LilyPond workflow

Posted: Mon Sep 23, 2019 7:36 am
by Jorin
thumbknuckle wrote: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.
maze11.bass.pdf
cheers

-r
There's always an Emacs mode! I've wanted to look into Emacs but I've never really had a reason as I was comfortable with vim in software development, maybe this is it though!

Re: Sharing my LilyPond workflow

Posted: Sun Nov 22, 2020 5:54 pm
by Philotomy
Another neovim user, here.

I typically use:
  • neovim as my editor
  • lilypond
  • evince (Gnome document viewer) for viewing pdfs
  • audacious for listening to MIDI

Re: Sharing my LilyPond workflow

Posted: Thu Dec 30, 2021 3:47 pm
by vonbiber
My workflow is as follow.
I start with abc file, which I edit with vi (elvis) on my slackware system.
The abc file is either something that I downloaded (e.g., thesession.com) or
wrote while reading a standard sheet music.
Some shell scripts (that I wrote) convert the abc file into ly files.
I have 4 lilypond files (not counting the ones that are included and are placed
in a fixed location): dim.ly, lmain.ly, notes.ly, score.ly
and a Makefile
$ make
produces tab.pdf

(a tablature for either one of these instruments:
guitar, tenor guitar, mandolin, Irish banjo, ukulele.