-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Maybe not as clever as some scripts, but it may give more clever
people some ideas.

Dependencies:

    * timidity
    * lame
    * inkscape
    * mid3v2
    * vlc

(The PAGE_BREAKING environment variable used below was from ananswer
provided on this list. My templates now all contain a conditionalthat
gives me an infinitely long (or short) page if I'm generating an
SVGrather than a PDF. I use the SVG for embedding in web pages and
MP3files, and PDF for stuff I want to print.)

############################################################

#!/bin/bash
#
# Engrave (nee Celticize)
# ______________________________________________________________________________
#
# Generate MP3 file w/ an embedded score image ("cover art") and
# embedded ID3v2 tags from Celtic tune LilyPond source file.
#
# Written by Kevin Cole <[email protected]> 2026.09.03 (kjc)
#
# For tags, see: https://docs.mp3tag.de/mapping/
#

if (( $# != 2 )); then
    >&2 printf "ERROR: Missing argument(s)\n\n"
    >&2 printf "Usage: engrave.sh filename.ly \"Tune Title\"\n\n"
    exit 2
fi

rootname="${1%.*}"     # filename  without extension
extension="${1##*.}"   # extension without filename

if [[ "$extension" != "ly" ]]; then
    >&2 printf "ERROR: First argument not a LilyPond file\n\n"
    >&2 printf "Usage: engrave.sh filename.ly \"Tune Title\"\n\n"
    exit 2
fi

source ~/.bash_functions   # Import mid2mp3() function

printf "Generating MP3 with image and tags for \"$2\"...\n\n"

# Purge VLC's cache
#
rm -rf ~/.cache/vlc/art

# Generate PDF, SVG and MP3 from LilyPond source
#
PAGE_BREAKING=pdf lilypond --pdf $rootname.ly &> /dev/null
PAGE_BREAKING=svg lilypond --svg $rootname.ly &> /dev/null
mid2mp3 $rootname &> /dev/null

# Convert SVG to a 900x??? px PNG w/ "parchment" background color
#
inkscape $rootname.svg               \
    --export-type=png                \
    --export-filename=$rootname.png  \
    --export-width=900               \
    --export-background=#ffffea      \
    --export-background-opacity=1 &> /dev/null

mid3v2 -D $rootname.mp3    # Delete all ID3v1 and ID3v2 tags

# Add Title, Artist, Year, Genre, BPM and "cover art" sheet music PNG.
#
# Genres: 13=Pop, 88=Celtic, 80=Folk, 17=Rock
# See all genres with "mid3v2 -L | most"
#
mid3v2  -t        "$2" $rootname.mp3   # Title
mid3v2  -a  "LilyPond" $rootname.mp3   # Artist
mid3v2  -y      "2026" $rootname.mp3   # Date
mid3v2  -g          88 $rootname.mp3   # Genre (Celtic)
mid3v2 --TBPM    "100" $rootname.mp3   # BPM
mid3v2 --picture "$rootname.png:'$2' sheet music:3:image/png" $rootname.mp3

# Cleanup
#
#cp output.mp3 $rootname.mp3
rm -f $rootname.svg $rootname.png $rootname.midi

# Show results
#
mid3v2 -l $rootname.mp3

# Test
printf "\nTest playback? [y/N]: "
read checkmp3

if [[ "$checkmp3" != "y" ]]; then
    exit
fi

XDG_CACHE_HOME=/tmp/vlc-test-cache vlc $rootname.mp3
rm -rf /tmp/vlc-test-cache

# ----------------------------------------------------------------------------
# Better comments
#
#mid3v2 -c     "Location:7DrumCity, Washington, DC:eng"  $rootname.mp3
#mid3v2 -c     "Recorded:2026-08-16:eng"                 $rootname.mp3
#mid3v2 -c     "Performer:Kevin Cole (Flute):eng"        $rootname.mp3
#mid3v2 --WXXX "Funkwhale:https://open.audio/@tadonic";   $rootname.mp3

############################################################

~/.bash_functions contains (among lots of other functions):

############################################################

mid2mp3() {
    timidity "$1.midi" -Ow -o - | \
    lame - -b 64 "$1.mp3"
}
############################################################
- --
 ======================================================================
  Tadonic the Flautulent • Breaker of Wind • Disenfranchised City (DC)
  Music (audio): https://open.audio/channels/tadonic_music_channel
  Music (video): https://rankett.net/c/rx_remix/videos
  PGP / GPG Key: 0x3E696927
 ======================================================================
              Neurologist: "He's a wee bit flautistic..."

-----BEGIN PGP SIGNATURE-----
Version: Mailvelope v6.3.0
Comment: https://mailvelope.com

wsFzBAEBCgAnBYJqttvwCZBsyzOXPmlpJxYhBCKYEZpbjZTpErfJh2zLM5c+
aWknAACSMA//amOxCM4jVVVOjw8ZyeP9Y90q/dCT3Wu9cGFyczF4B76eywYE
u8RvbqLgvPRKH8mfiT0iOKvDbamdysbEC5RKlFR8wCkzr+JxXSo4gy18fHCB
Xe2T6pfVv9Nkjl1yftsWvEt7EpRzgPM85DynEgVKZzlSU+GW3Cv6xbhgC9DZ
v9nLC4f/7UrbIjtXtRD/EvzG8uZrfPe+8h3J4bSI1C30CipPfMDLo1PP9LsG
tLGgeLKkx4cRupa/0UEF4avJFrPjNBz3yDmLG+bQiiq1FzelpL1zgTmbza6X
EKuoMzdNP+zb+RR+7SCszgdD998OBNSy9h0w3mSD2p3sgYG61oReZehVSTcA
n+Nrpz+MVITPRyHIdeIDsgIqkCW2Lylq5W8J8gdDRfaTrGjQQN5MZCKouuBy
XYjThQo88X37V9okLUf0gkrR0pbHtEigthEJ36hHveyeZJzL2DjVgW7H+JBv
ZN2Raaucf77je3V67byBR9wlUcTrCbWea9vh4mpQavc9IYnKVuWLrjtK+EF8
21w+YN38Tv5625maoQG/svq1hm+K/mX/bayF6zeCrQDKL++j/GJFmGptgsAY
PXc6j8eAtdS/nKdiYt8c39lxbCcbt+fMSmpPyDagacIEBFQp1qO7IU4LCdFv
2XBR4i20UmLsOBR5ZQ6jkIg0WLTK1NXhThw=
=EtBq
-----END PGP SIGNATURE-----

Reply via email to