Skip to content

Commit

Permalink
feat: first version of lyscaffold
Browse files Browse the repository at this point in the history
Signed-off-by: Davide Madrisan <[email protected]>
  • Loading branch information
madrisan committed Feb 17, 2024
1 parent ed314b5 commit 558afa4
Show file tree
Hide file tree
Showing 18 changed files with 504 additions and 260 deletions.
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

AM_MAKEFLAGS = --no-print-directory

SUBDIRS = src \
template
SUBDIRS = lyinit \
src

check-local: all
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ test -n "$critic_missing" && AC_MSG_ERROR([

AC_CONFIG_FILES([\
Makefile \
lyinit/Makefile \
src/Makefile \
src/alfredo-casella/Makefile \
src/alfredo-casella/deux-contrastes-op.31/Makefile \
Expand Down Expand Up @@ -141,7 +142,6 @@ AC_CONFIG_FILES([\
src/robert-schumann/Makefile \
src/rued-langgaard/Makefile \
src/rued-langgaard/insektarium-BVN134/Makefile \
template/Makefile
])

AC_OUTPUT
18 changes: 13 additions & 5 deletions template/Makefile.am → lyinit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@

AM_MAKEFLAGS = --no-print-directory

EXTRA_DIST = covercolor.ly.in \
global.ly \
logo.ly \
template.ly \
translate.sh
EXTRA_DIST = lyscaffold.sh \
addons/translate.sh \
data/jsbach \
templates/covercolor.ly \
templates/covercolor.ly.in \
templates/global.ly \
templates/header.ily \
templates/logo.ly \
templates/makefile-clean \
templates/makefile-clean-parts \
templates/makefile-head \
templates/mainfile.ly \
templates/part-four-voices.ly

check-local: all
File renamed without changes.
7 changes: 7 additions & 0 deletions lyinit/data/jsbach
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
composer_firstname='Johann Sebastian'
composer_lastname="Bach"
instruments="For Piano or Harpsichord"
header_composer="Johann Sebastian Bach (1685-1750)"
header_style="Baroque"
mutopiacomposer="BachJS"
mutopiainstrument="Harpsichord, Piano"
214 changes: 214 additions & 0 deletions lyinit/lyscaffold.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
#!/usr/bin/env bash
# A simple scaffolding script for Lilypond partitions.
# Copyright (c) 2024 Davide Madrisan <[email protected]>

PROGNAME="${0##*/}"
PROGPATH="${0%/*}"
REVISION=1

die () { echo -e "$PROGNAME: error: $1" 1>&2; exit 1; }

usage () {
cat <<__EOF
Usage: $PROGNAME -t <targetdir> [-p]
$PROGNAME --help
$PROGNAME --version
Where:
-c|--composer : the data file for the composer
-d|--targetdir : the directory where to create the partition
-n|--pdfname : the name of the file containing the partition
-o|--opus : opus of the composition
-p|--parts : the partition is splitted into several files
-s|--source : the source of the partition
-t|--title : title of the composition
-y|--year : the date of the composition
|--part4 : 4-voice part to be added to ./parts folder
Example:
$0 -c $PROGPATH/data/jsbach \\
--targetdir src/johann-sebastian-bach/partitas/BWV825 \\
--opus 'BWV 825' \\
--parts \\
--title 'Partita I' \\
--pdfname JS-Bach-BWV830-Partita-1.pdf \\
--source 'Muzgiz, Moscow' \\
--year "between 1725 and 1726" \\
--part4 bach-partita-1-1-praeludium.ly \\
--part4 bach-partita-1-2-allemande.ly \\
--part4 bach-partita-1-3-corrente.ly \\
--part4 bach-partita-1-4-sarabande.ly \\
--part4 bach-partita-1-5-menuet-1.ly \\
--part4 bach-partita-1-5-menuet-2.ly \\
--part4 bach-partita-1-6-giga.ly
__EOF
}

help () {
cat <<__EOF
$PROGNAME v$REVISION - a simple scaffolding script for Lilypond partitions
Copyright (C) 2024 Davide Madrisan <[email protected]>
__EOF

usage
}

lilypond_version () {
( set -- $(lilypond --version 2>/dev/null | head -n 1); echo "$3"; )
}

ly_opus="Unset --opus"
ly_title="Unset --title"

ly_parts="false"

ly_sed () {
[ -n "$1" -a ! -r "$1" ] && die "ly_sed: cannot read input file: $1"
(
. "$ly_data"
# footer = "Mutopia-2023/04/15"
header_footer="$(date +'%Y/%m/%d')"
# lastupdated = "2023 April 15"
header_lastupdate="$(date +'%Y %B %d')"

sed "s^@composer_firstname@^${composer_firstname}^g;
s^@composer_lastname@^${composer_lastname}^g;
s^@COMPOSER_LASTNAME@^${composer_lastname^^}^g;
s^@header_composer@^${header_composer}^;
s^@header_date@^${header_date}^;
s^@header_footer@^${header_footer}^;
s^@header_lastupdate@^${header_lastupdate}^;
s^@header_style@^${header_style}^;
s^@instruments@^${instruments}^;
s^@mutopiacomposer@^${mutopiacomposer}^;
s^@mutopiainstrument@^${mutopiainstrument}^;
s^@opus@^${ly_opus}^g;
s^@source@^${ly_source}^g;
s^@title@^${ly_title}^g;
" < "${1:-/dev/stdin}"
)
}

ly_parts4_files=()

while test -n "$1"; do
case "$1" in
--help|-h) help; exit 0 ;;
--version|-V)
echo "$PROGNAME v$REVISION"
exit 0 ;;
--composer|-c)
ly_data="$2"; shift ;;
--opus|-o)
ly_opus="$2"; shift ;;
--parts|-p)
ly_parts="true" ;;
--part4)
ly_parts4_files+=("$2"); shift ;;
--pdfname|-n)
ly_pdfname="$2"; shift ;;
--source|-s)
ly_source="$2"; shift ;;
--targetdir|-d)
ly_targetdir="$2"; shift ;;
--title|-t)
ly_title="$2"; shift ;;
--year|-y)
ly_date="$2"; shift ;;
--*|-*) die "unknown argument: $1" ;;
*) die "unknown option: $1" ;;
esac
shift
done

[ "$ly_data" ] || die "you must set a --composer"
[ "$ly_date" ] || die "you must set a --year"
[ "$ly_pdfname" ] || die "you must set a --pdfname"
[ "$ly_source" ] || die "you must set a --source"
[ "$ly_targetdir" ] || die "you must set a --targetdir"

[ -r "$ly_data" ] || die "file not found: $ly_data"

# remove the .pdf suffix if any
ly_mainfile="${ly_pdfname%\.pdf}"

LY_STATIC_FILES="\
covercolor.ly
covercolor.ly.in
global.ly
logo.ly"

ly_version="$(lilypond_version)"
[ "$ly_version" ] || die "cannot get the Lilyond version"
echo "found Lilypond version $ly_version"

echo "creating the target folder '$ly_targetdir' ..."
mkdir -p "$ly_targetdir"
[ "$ly_parts" = "true" ] && mkdir -p "$ly_targetdir/parts"

echo "copying common files ..."
for f in $LY_STATIC_FILES; do
cp -v $PROGPATH/templates/$f "$ly_targetdir"
done

echo "creating '$ly_targetdir/header.ily' ..."
(
ly_sed < $PROGPATH/templates/header.ily
) > "$ly_targetdir/header.ily"

echo "creating '$ly_targetdir/${ly_mainfile}.ly'"
(
echo "\\version \"$ly_version\""
echo
ly_sed < $PROGPATH/templates/mainfile.ly
) > "$ly_targetdir/${ly_mainfile}.ly"

echo "creating the makefile '$ly_targetdir/Makefile.am' ..."
(
cat $PROGPATH/templates/makefile-head
echo
echo "EXTRA_DIST = ${ly_mainfile}.ly \\"

set -- $LY_COMMON_FILES
while test -n "$1"; do
[ "$f" = "covercolor.ly" ] && { shift; continue; }
echo -en "\t $1"
[ "$2" ] && echo " \\" || echo ""
shift
done

echo
echo "all: \$(BUILT_SOURCES) $ly_mainfile"

echo
if [ "$ly_parts" = "true" ]; then
cat $PROGPATH/templates/makefile-clean-parts
else
cat $PROGPATH/templates/makefile-clean
fi
) > "$ly_targetdir/Makefile.am"

for p in ${ly_parts4_files[@]}; do
if [ -s "$ly_targetdir/parts/$p" ]; then
echo "WARNING: skip non empty file: $ly_targetdir/parts/$p"
else
echo "creating $ly_targetdir/parts/$p ..."
( ly_sed < $PROGPATH/templates/part-four-voices.ly ) \
> "$ly_targetdir/parts/$p"
fi
echo "updating $ly_targetdir/${ly_mainfile}.ly"
echo "\\include \"./parts/$p\"" >> $ly_targetdir/${ly_mainfile}.ly
done

echo "
+ new project structure"
tree "$ly_targetdir"

echo "
WARNING: make sure to update
* configure.ac
* the files Makefile.am in $ly_targetdir
* 'date' and 'source' in $ly_targetdir/header.ily
"
File renamed without changes.
File renamed without changes.
File renamed without changes.
65 changes: 65 additions & 0 deletions lyinit/templates/header.ily
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
\header {
composer = "@header_composer@"
date = "@header_date@"

footer = "Mutopia-@header_footer@"

lastupdated = "@header_lastupdate@"
license = "Creative Commons Attribution-ShareAlike 4.0"
maintainerEmail = "[email protected]"
maintainerWeb = "https://github.com/madrisan/open-scores"

% Extra Mutopia Information
mutopiacomposer = "@mutopiacomposer@"
mutopiacopyright = "Creative Commons Attribution-ShareAlike 4.0"
mutopiainstrument = "@mutopiainstrument@"
mutopiamaintainer = "Davide Madrisan"
mutopiaopus = "@opus@"
mutopiatitle = "@title@"

opus = "@opus@"
title = "@title@"
source = "@source@"
style = "@header_style@"

copyright = \markup {
\override #'(font-name . "DejaVu Sans, Bold")
\override #'(baseline-skip . 0)
\right-column {
\with-url #"http://www.MutopiaProject.org" {
\abs-fontsize #9 "Mutopia "
\concat {
\abs-fontsize #12
\with-color \coverColor "ǀ"
\abs-fontsize #9 "Project "
}
}
}
\override #'(font-name . "DejaVu Sans, Bold")
\override #'(baseline-skip . 0 )
\center-column {
\abs-fontsize #11.9
\with-color #grey
\bold { "ǀ" "ǀ" }
}
\override #'(font-name . "DejaVu Sans,sans-serif")
\override #'(baseline-skip . 0)
\column {
\abs-fontsize #8
\concat {
"Typeset using " \with-url #"http://www.lilypond.org" "LilyPond " ©" 2022-2024 ""by " \maintainer "" \footer
}
\concat {
\concat {
\abs-fontsize #8 {
\with-url #"http://creativecommons.org/licenses/by-sa/40/"
"Creative Commons Attribution ShareAlike 4.0 International License"
" — free to distribute, modify, and perform"
}
}
\abs-fontsize #13 \with-color \coverColor "ǀ"
}
}
}
tagline = ##f
}
File renamed without changes.
Loading

0 comments on commit 558afa4

Please sign in to comment.