groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Macro to add sheetmusic either inline or as a figure with lilypond


From: hbezemer
Subject: Macro to add sheetmusic either inline or as a figure with lilypond
Date: Wed, 16 Nov 2022 19:25:20 +0100
User-agent: s-nail v14.9.24

Dear all,

I've created a macroset (see below) which enables me to use lilypond source 
files and build
pdf images from them.
When using '.LILY <lilypondfile.ly>' lilypond gets called and builds a pdf. The
linelenght is used to adjust the amount of bars per line.
The pointsize is used to adjust the pointsize used in the sheetmusic
Calling '.LILYIN <lilypond.ly>' creates a pdf which is scaled to the current
pointsize and will be put inline.

Since compiling with lilypond is time consuming, the macro checks if the pdf is
present or has an older date then the corresponding .ly file. If not present or
older then the .ly file, the pdf will be (re)build. 

I've attached a sample document.

Kind regards,

Hans

cat > lilypond.tmac << EOF
.de LILYBUILD
.nr centi 1c
.nr milli \\n[centi]/10
.nr linemm \\n[.ll]/\\n[milli]
.open tmp tmp.ly
.write tmp \include "lilypond-book-preamble.ly"
.write tmp \paper {
.write tmp      indent = 0\mm
.write tmp line-width = \\n[linemm]\mm
.write tmp % offset the left padding, also add 1mm as lilypond creates cropped
.write tmp   % images with a little space on the right
.write tmp      line-width = #(- line-width (* mm  3.000000) (* mm 1))
.write tmp myStaffSize = #10
.write tmp }
.write tmp \layout {
.write tmp #(layout-set-staff-size \\n[.s])
.write tmp \context {
.write tmp    \Score
.write tmp    \override StaffGrouper.staff-staff-spacing.padding = #0
.write tmp    \override StaffGrouper.staff-staff-spacing.basic-distance = #0
.write tmp  }
.write tmp }
.close tmp
.sy cat \\$1 >> tmp.ly
.sy lilypond --output=$(pwd)/build/\\$1 tmp.ly
.sy rm $(pwd)/build/\\$1-* tmp.ly
..
.de LILYCHECK
.sy touch rblil.txt 
.sy [ ! -f $(pwd)/build/\\$1.pdf ] && echo ".nr lily 1" > rblil.txt
.sy [ -f $(pwd)/build/\\$1.pdf ] && [ \\$1 -nt $(pwd)/build/\\$1.pdf ] && echo 
".nr lily 1" > rblil.txt
.so rblil.txt
.if r lily .LILYBUILD \\$1
..
.
.de LILY
.LILYCHECK \\$1
.PDFPIC \\$2 build/\\$1.pdf \\$3 \\$4 \\$5
.sy rm rblil.txt
.rm lily
..
.
.de LILYIN
.LILYCHECK \\$1
.ec @
.sy pdfinfo build/@$1.pdf | \
grep -a "Page *size" | \
sed -e 's/Page *size: *\\([[:digit:].]*\\) *x *\\([[:digit:].]*\\).*$/\
.nr in-wid (p;\\1)\\n\
.nr in-ht  (p;\\2)/' \
> /tmp/pdfpicA
.so /tmp/pdfpicA
.sy rm /tmp/pdfpicA
.ec
.sy echo ".ds Breed $(echo 'scale=2; \\n[in-wid]/\\n[in-ht]*\\n[.ps]/1000' | bc 
-l)"p > /tmp/pdffac
.so /tmp/pdffac
.sy rm /tmp/pdffac
\v'-\\n[.ps]u'
\X'pdf: pdfpic build/\\$1.pdf 0p \\*[Breed]'
\h'\\*[Breed]' 
..
EOF

Attachment: Lilypond.pdf
Description: Adobe PDF document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]