Skip to content

Instantly share code, notes, and snippets.

@dominicus
Created January 3, 2013 05:50
Show Gist options
  • Save dominicus/4441122 to your computer and use it in GitHub Desktop.
Save dominicus/4441122 to your computer and use it in GitHub Desktop.
Author: Felix Janda
#!/bin/sh
tempfile=idontexist
composerfile="$MUTOPIA_BASE/datafiles/composers.dat"
stylesfile="$MUTOPIA_BASE/datafiles/styles.dat"
set -e
test -e "$1"
cp "$1" "$tempfile"
cat >>"$tempfile"<<"EOF"
% helper function to retrieve header fields
% replace markups by underlying strings
% returns #f if header field not set
#(define (get_header field)
(let ((me_packed (assoc field (car (map ly:module->alist
(list $defaultheader))))))
(if (eq? me_packed #f) #f (let ((me (cdr me_packed)))
(if (string? me) me (string-concatenate
(map markup->string me)))))))
#(cond ((string? (get_header 'mutopiatitle))
(format #t "title: ~s~%" (get_header 'mutopiatitle)))
((string? (get_header 'title))
(format #t "title: ~s~%" (get_header 'title)))
(else (format #t "No title found!~%")))
#(define composers (list
EOF
cat "$composerfile" | sed -n '{x;N;g;s/^/"/;s/$/"/;p}' >>"$tempfile"
cat >>"$tempfile"<<"EOF"
))
#(define (print_composer) (if (eq? (get_header 'composer) #f)
(format #t "No composer found!~%" (get_header 'composer))
(format #t "composer: ~s~%" (get_header 'composer))))
#(cond ((eq? (get_header 'mutopiacomposer) #f)
(begin (format #t "No mutopiacomposer found!~%")) (print_composer))
((eq? (member (get_header 'mutopiacomposer) composers) #f)
(begin (format #t "invalid mutopiacomposer! (was ~s)~%"
(get_header 'mutopiacomposer)) (print_composer)))
(else (format #t "composer: ~s~%" (get_header 'mutopiacomposer))))
#(cond ((string? (get_header 'mutopiapoet))
(format #t "poet: ~s~%" (get_header 'mutopiapoet)))
((string? (get_header 'poet))
(format #t "poet: ~s~%" (get_header 'poet)))
(else '()))
#(cond ((string? (get_header 'mutopiaopus))
(format #t "opus: ~s~%" (get_header 'mutopiaopus)))
((string? (get_header 'opus))
(format #t "opus: ~s~%" (get_header 'opus)))
(else '()))
#(cond ((string? (get_header 'mutopiainstrument))
(format #t "instrument: ~s~%" (get_header 'mutopiainstrument)))
((string? (get_header 'instrument))
(format #t "instrument: ~s~%" (get_header 'instrument)))
(else (format #t "No instrument found!~%")))
#(if (eq? (get_header 'date) #f) '()
(format #t "date: ~s~%" (get_header 'date)))
#(define styles (list
EOF
cat "$stylesfile" | sed -n '{x;N;g;s/^/"/;s/$/"/;p}' >>"$tempfile"
cat >>"$tempfile"<<"EOF"
))
#(cond ((eq? (get_header 'style) #f) (format #t "No style found!~%"))
((eq? (member (get_header 'style) styles) #f)
(format #t "invalid style! (was ~s)~%" (get_header 'style)))
(else (format #t "style: ~s~%" (get_header 'style))))
#(define licenses (list "Creative Commons Attribution-ShareAlike 3.0"
"Creative Commons Attribution 3.0" "Public Domain"))
#(cond ((eq? (get_header 'copyright) #f) (format #t "No license found!~%"))
((eq? (member (get_header 'copyright) licenses) #f)
(format #t "invalid license! (was ~s)~%" (get_header 'copyright)))
(else (format #t "license: ~s~%" (get_header 'copyright))))
#(if (eq? (get_header 'maintainer) #f)
(format #t "No maintainer found!~%")
(format #t "maintainer: ~s~%" (get_header 'maintainer)))
#(if (eq? (get_header 'mainainerEmail) #f) '()
(format #t "maintainerEmail: ~s~%" (get_header 'maintainerEmail)))
#(if (eq? (get_header 'mainainerWeb) #f) '()
(format #t "maintainerWeb: ~s~%" (get_header 'maintainerWeb)))
#(if (eq? (get_header 'moreInfo) #f) '()
(format #t "moreInfo: ~s~%" (get_header 'moreInfo)))
#(exit)
EOF
lilypond -dprotected-scheme-parsing=#f "$tempfile" 2>/dev/null
rm "$tempfile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment