From ffe0102369a39f5289e9e64a521537a2c9043ea5 Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Mon, 12 Aug 2013 20:14:29 +0200 Subject: [PATCH] The lytex file now gets assembled with the help of a python script. because I can! --- COPYING.txt => COPYING | 0 Makefile | 5 +- assemble.py | 72 +++++++++++ music_booklet.lytex | 154 ----------------------- {notes => scores}/AllForMeGrog.ly | 0 {notes => scores}/AuldLangSyne.ly | 0 {notes => scores}/BlackVelvetBand.ly | 0 {notes => scores}/Buergerlied.ly | 0 {notes => scores}/DrunkenSailor.ly | 0 {notes => scores}/FinnegansWake.ly | 0 {notes => scores}/FoggyDew.ly | 0 {notes => scores}/ImARoverSeldomSober.ly | 0 {notes => scores}/IrishRover.ly | 0 {notes => scores}/JohnnyIHardlyKnewYe.ly | 0 {notes => scores}/KerryRecruit.ly | 0 {notes => scores}/MacPhersonsFarewell.ly | 0 {notes => scores}/MollyMalone.ly | 0 {notes => scores}/MuirsheenDurkin.ly | 0 {notes => scores}/NationOnceAgain.ly | 0 {notes => scores}/PartingGlass.ly | 0 {notes => scores}/RisingOfTheMoon.ly | 0 {notes => scores}/SpancilHill.ly | 0 {notes => scores}/StarOfTheCountyDown.ly | 0 {notes => scores}/WhiskeyInTheJar.ly | 0 {notes => scores}/WildRover.ly | 0 singalongs.tex | 51 ++++++++ 26 files changed, 126 insertions(+), 156 deletions(-) rename COPYING.txt => COPYING (100%) create mode 100644 assemble.py delete mode 100644 music_booklet.lytex rename {notes => scores}/AllForMeGrog.ly (100%) rename {notes => scores}/AuldLangSyne.ly (100%) rename {notes => scores}/BlackVelvetBand.ly (100%) rename {notes => scores}/Buergerlied.ly (100%) rename {notes => scores}/DrunkenSailor.ly (100%) rename {notes => scores}/FinnegansWake.ly (100%) rename {notes => scores}/FoggyDew.ly (100%) rename {notes => scores}/ImARoverSeldomSober.ly (100%) rename {notes => scores}/IrishRover.ly (100%) rename {notes => scores}/JohnnyIHardlyKnewYe.ly (100%) rename {notes => scores}/KerryRecruit.ly (100%) rename {notes => scores}/MacPhersonsFarewell.ly (100%) rename {notes => scores}/MollyMalone.ly (100%) rename {notes => scores}/MuirsheenDurkin.ly (100%) rename {notes => scores}/NationOnceAgain.ly (100%) rename {notes => scores}/PartingGlass.ly (100%) rename {notes => scores}/RisingOfTheMoon.ly (100%) rename {notes => scores}/SpancilHill.ly (100%) rename {notes => scores}/StarOfTheCountyDown.ly (100%) rename {notes => scores}/WhiskeyInTheJar.ly (100%) rename {notes => scores}/WildRover.ly (100%) create mode 100644 singalongs.tex diff --git a/COPYING.txt b/COPYING similarity index 100% rename from COPYING.txt rename to COPYING diff --git a/Makefile b/Makefile index ffd545e..00e11df 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ OUTDIR=out PDFDIR=pdf -FILE = music_booklet +FILE = singalongs GITINFO=revision.tex LILY_PDF = lilypond-book --process="lilypond -dinclude-settings=lilysettings.ly" --pdf -o $(OUTDIR) PDF=cd $(OUTDIR) && pdflatex --enable-pipes --shell-escape $(FILE).tex @@ -17,13 +17,14 @@ VPATH = \ all: book booklet book: $(OUTDIR) $(PDFDIR) $(GITINFO) + python assemble.py > $(OUTDIR)/$(FILE).lytex cp lilysettings.ly $(OUTDIR)/ cp headfoot.tex $(OUTDIR)/ cp settings.tex $(OUTDIR)/ cp -r license/ $(OUTDIR)/ cp -r images/ $(OUTDIR)/ cp $(GITINFO) $(OUTDIR)/ - $(LILY_PDF) $(FILE).lytex + $(LILY_PDF) $(OUTDIR)/$(FILE).lytex $(PDF) $(INDEX) $(PDF) diff --git a/assemble.py b/assemble.py new file mode 100644 index 0000000..f149a4d --- /dev/null +++ b/assemble.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import re + +lily_template = """ +\chapter {[[title]]} + \lilypondfile{[[scorefile]]} + ~\\ ~\\ + \input{[[lyricfile]]} +""" + +def find_ly_files(path='./scores'): + lilyfiles = [] + for found_file in os.listdir(path): + if found_file.endswith(".ly"): + filepath = os.path.join(path, found_file) + lilyfiles.append(filepath) + + return lilyfiles + +def build_songmap(lilyfiles, lyric_folder='./lyrics'): + songmap = [] + for scorefile in lilyfiles: + filename_with_ext = os.path.basename(scorefile) + filename = os.path.splitext(filename_with_ext)[0] + lyricfile = os.path.join(lyric_folder, "{0}.tex".format(filename)) + + title = find_title(scorefile) + + songmap.append({'scorefile': scorefile, 'lyricfile': lyricfile, 'title': title }) + + return songmap + +def find_title(scorefile): + with open(scorefile) as opened_file: + score = opened_file.read() + title = re.findall('title = "(.*)"', score) + + return title[0] + +def build_lytex(base_template, songmap): + lilychapters = [] + for song in sorted(songmap, key=lambda k: k['scorefile']): + lilychapter = lily_template.replace('[[title]]', song['title']) + lilychapter = lilychapter.replace('[[scorefile]]', song['scorefile']) + lilychapter = lilychapter.replace('[[lyricfile]]', song['lyricfile']) + + lilychapters.append(lilychapter) + + lilychapters_string = create_lilychapter_string(lilychapters) + + with open(base_template) as opened_file: + template = opened_file.read() + template = template.replace('\\musicbooklet', lilychapters_string) + + return template + +def create_lilychapter_string(lilychapters): + lilychapter_string = '' + for lilychapter in lilychapters: + lilychapter_string += '{0}\n'.format(lilychapter) + + return lilychapter_string + +lilyfiles = find_ly_files() +songmap = build_songmap(lilyfiles) +lytex_source = build_lytex('singalongs.tex', songmap) + +print(lytex_source) + diff --git a/music_booklet.lytex b/music_booklet.lytex deleted file mode 100644 index 9a7f4d1..0000000 --- a/music_booklet.lytex +++ /dev/null @@ -1,154 +0,0 @@ -% This document is free software: you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation, either version 3 of the License, or -% (at your option) any later version. -% -% This document is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details. -% -% You should have received a copy of the GNU General Public License -% along with this document. If not, see . - -\documentclass[12pt, a4paper, openany]{scrbook} -\usepackage[utf8]{inputenc} -\usepackage[T1]{fontenc} -\usepackage{graphicx} -\usepackage{fancyhdr} -\usepackage{geometry} -\usepackage{xmpincl} -\usepackage{hyperref} - -\input{revision.tex} -\input{settings.tex} -\input{headfoot.tex} - -\renewcommand*\rmdefault{iwona}\normalfont\upshape - -\begin{document} - \widowpenalties 1 10000 - \raggedbottom - \pagenumbering{roman} - - \input{title.tex} - - \chapter*{Contributors} - \begin{itemize} - \item Matias Hugentobler - \item Sebastian Hugentobler - \end{itemize} - - \tableofcontents - - \clearpage - - \pagenumbering{arabic} - - \chapter{All for Me Grog} - \lilypondfile{notes/AllForMeGrog.ly} - ~\\ ~\\ - \input{lyrics/AllForMeGrog.tex} - - \chapter{Auld Lang Syne} - \lilypondfile{notes/AuldLangSyne.ly} - ~\\ ~\\ - \input{lyrics/AuldLangSyne.tex} - - \chapter{The Black Velvet Band} - \lilypondfile{notes/BlackVelvetBand.ly} - ~\\ ~\\ - \input{lyrics/BlackVelvetBand.tex} - - \chapter{Bürgerlied} - \lilypondfile{notes/Buergerlied.ly} - ~\\ ~\\ - \input{lyrics/Buergerlied.tex} - - \chapter {Drunken Sailor} - \lilypondfile{notes/DrunkenSailor.ly} - ~\\ ~\\ - \input{lyrics/DrunkenSailor.tex} - - \chapter{Finnegan's Wake} - \lilypondfile{notes/FinnegansWake.ly} - ~\\ ~\\ - \input{lyrics/FinnegansWake.tex} - - \chapter{The Foggy Dew} - \lilypondfile{notes/FoggyDew.ly} - ~\\ ~\\ - \input{lyrics/FoggyDew.tex} - - \chapter{I'm a Rover Seldom Sober} - \lilypondfile{notes/ImARoverSeldomSober.ly} - ~\\ ~\\ - \input{lyrics/ImARoverSeldomSober.tex} - - \chapter{The Irish Rover} - \lilypondfile{notes/IrishRover.ly} - ~\\ ~\\ - \input{lyrics/IrishRover.tex} - - \chapter{Johnny I Hardly Knew Ye} - \lilypondfile{notes/JohnnyIHardlyKnewYe.ly} - ~\\ ~\\ - \input{lyrics/JohnnyIHardlyKnewYe.tex} - - \chapter{The Kerry Recruit} - \lilypondfile{notes/KerryRecruit.ly} - ~\\ ~\\ - \input{lyrics/KerryRecruit.tex} - - \chapter{MacPherson's Farewell} - \lilypondfile{notes/MacPhersonsFarewell.ly} - ~\\ ~\\ - \input{lyrics/MacPhersonsFarewell.tex} - - \chapter{Molly Malone} - \lilypondfile{notes/MollyMalone.ly} - ~\\ ~\\ - \input{lyrics/MollyMalone.tex} - - \chapter{Muirsheen Durkin} - \lilypondfile{notes/MuirsheenDurkin.ly} - ~\\ ~\\ - \input{lyrics/MuirsheenDurkin.tex} - - \chapter {A Nation Once Again} - \lilypondfile{notes/NationOnceAgain.ly} - ~\\ ~\\ - \input{lyrics/NationOnceAgain.tex} - - \chapter{The Parting Glass} - \lilypondfile{notes/PartingGlass.ly} - ~\\ ~\\ - \input{lyrics/PartingGlass.tex} - - \chapter {The Rising of the Moon} - \lilypondfile{notes/RisingOfTheMoon.ly} - ~\\ ~\\ - \input{lyrics/RisingOfTheMoon.tex} - - \chapter{Spancil Hill} - \lilypondfile{notes/SpancilHill.ly} - ~\\ ~\\ - \input{lyrics/SpancilHill.tex} - - \chapter{The Star of the County Down} - \lilypondfile{notes/StarOfTheCountyDown.ly} - ~\\ ~\\ - \input{lyrics/StarOfTheCountyDown.tex} - - \chapter{Whiskey in the Jar} - \lilypondfile{notes/WhiskeyInTheJar.ly} - ~\\ ~\\ - \input{lyrics/WhiskeyInTheJar.tex} - - \chapter{The Wild Rover} - \lilypondfile{notes/WildRover.ly} - ~\\ ~\\ - \input{lyrics/WildRover.tex} - -\end{document} - diff --git a/notes/AllForMeGrog.ly b/scores/AllForMeGrog.ly similarity index 100% rename from notes/AllForMeGrog.ly rename to scores/AllForMeGrog.ly diff --git a/notes/AuldLangSyne.ly b/scores/AuldLangSyne.ly similarity index 100% rename from notes/AuldLangSyne.ly rename to scores/AuldLangSyne.ly diff --git a/notes/BlackVelvetBand.ly b/scores/BlackVelvetBand.ly similarity index 100% rename from notes/BlackVelvetBand.ly rename to scores/BlackVelvetBand.ly diff --git a/notes/Buergerlied.ly b/scores/Buergerlied.ly similarity index 100% rename from notes/Buergerlied.ly rename to scores/Buergerlied.ly diff --git a/notes/DrunkenSailor.ly b/scores/DrunkenSailor.ly similarity index 100% rename from notes/DrunkenSailor.ly rename to scores/DrunkenSailor.ly diff --git a/notes/FinnegansWake.ly b/scores/FinnegansWake.ly similarity index 100% rename from notes/FinnegansWake.ly rename to scores/FinnegansWake.ly diff --git a/notes/FoggyDew.ly b/scores/FoggyDew.ly similarity index 100% rename from notes/FoggyDew.ly rename to scores/FoggyDew.ly diff --git a/notes/ImARoverSeldomSober.ly b/scores/ImARoverSeldomSober.ly similarity index 100% rename from notes/ImARoverSeldomSober.ly rename to scores/ImARoverSeldomSober.ly diff --git a/notes/IrishRover.ly b/scores/IrishRover.ly similarity index 100% rename from notes/IrishRover.ly rename to scores/IrishRover.ly diff --git a/notes/JohnnyIHardlyKnewYe.ly b/scores/JohnnyIHardlyKnewYe.ly similarity index 100% rename from notes/JohnnyIHardlyKnewYe.ly rename to scores/JohnnyIHardlyKnewYe.ly diff --git a/notes/KerryRecruit.ly b/scores/KerryRecruit.ly similarity index 100% rename from notes/KerryRecruit.ly rename to scores/KerryRecruit.ly diff --git a/notes/MacPhersonsFarewell.ly b/scores/MacPhersonsFarewell.ly similarity index 100% rename from notes/MacPhersonsFarewell.ly rename to scores/MacPhersonsFarewell.ly diff --git a/notes/MollyMalone.ly b/scores/MollyMalone.ly similarity index 100% rename from notes/MollyMalone.ly rename to scores/MollyMalone.ly diff --git a/notes/MuirsheenDurkin.ly b/scores/MuirsheenDurkin.ly similarity index 100% rename from notes/MuirsheenDurkin.ly rename to scores/MuirsheenDurkin.ly diff --git a/notes/NationOnceAgain.ly b/scores/NationOnceAgain.ly similarity index 100% rename from notes/NationOnceAgain.ly rename to scores/NationOnceAgain.ly diff --git a/notes/PartingGlass.ly b/scores/PartingGlass.ly similarity index 100% rename from notes/PartingGlass.ly rename to scores/PartingGlass.ly diff --git a/notes/RisingOfTheMoon.ly b/scores/RisingOfTheMoon.ly similarity index 100% rename from notes/RisingOfTheMoon.ly rename to scores/RisingOfTheMoon.ly diff --git a/notes/SpancilHill.ly b/scores/SpancilHill.ly similarity index 100% rename from notes/SpancilHill.ly rename to scores/SpancilHill.ly diff --git a/notes/StarOfTheCountyDown.ly b/scores/StarOfTheCountyDown.ly similarity index 100% rename from notes/StarOfTheCountyDown.ly rename to scores/StarOfTheCountyDown.ly diff --git a/notes/WhiskeyInTheJar.ly b/scores/WhiskeyInTheJar.ly similarity index 100% rename from notes/WhiskeyInTheJar.ly rename to scores/WhiskeyInTheJar.ly diff --git a/notes/WildRover.ly b/scores/WildRover.ly similarity index 100% rename from notes/WildRover.ly rename to scores/WildRover.ly diff --git a/singalongs.tex b/singalongs.tex new file mode 100644 index 0000000..28a57ba --- /dev/null +++ b/singalongs.tex @@ -0,0 +1,51 @@ +% This document is free software: you can redistribute it and/or modify +% it under the terms of the GNU General Public License as published by +% the Free Software Foundation, either version 3 of the License, or +% (at your option) any later version. +% +% This document is distributed in the hope that it will be useful, +% but WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +% GNU General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with this document. If not, see . + +\documentclass[12pt, a4paper, openany]{scrbook} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{graphicx} +\usepackage{fancyhdr} +\usepackage{geometry} +\usepackage{xmpincl} +\usepackage{hyperref} + +\input{revision.tex} +\input{settings.tex} +\input{headfoot.tex} + +\renewcommand*\rmdefault{iwona}\normalfont\upshape + +\begin{document} + \widowpenalties 1 10000 + \raggedbottom + \pagenumbering{roman} + + \input{title.tex} + + \chapter*{Contributors} + \begin{itemize} + \item Matias Hugentobler + \item Sebastian Hugentobler + \end{itemize} + + \tableofcontents + + \clearpage + + \pagenumbering{arabic} + + \musicbooklet + +\end{document} +