From 6f3440b10855ea6792beed412a4f4d642ea53537 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 26 Apr 2016 00:08:32 +0200 Subject: [PATCH] New feature: Can now explicitely define note names Closes #117 --- patacrep/build.py | 31 ++++++++++++++++++++ patacrep/data/templates/songbook/default.tex | 6 ++-- patacrep/data/templates/songbook_model.yml | 11 ++----- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/patacrep/build.py b/patacrep/build.py index de7bb3ce..ce2ee802 100644 --- a/patacrep/build.py +++ b/patacrep/build.py @@ -29,7 +29,15 @@ GENERATED_EXTENSIONS = [ "_title.sxd", ] +class BookError(errors.SharedError): + """Global book error.""" + def __init__(self, message): + super().__init__() + self.message = message + + def __str__(self): + return self.message # pylint: disable=too-few-public-methods class Songbook: @@ -101,7 +109,11 @@ class Songbook: ) self._config['filename'] = output.name[:-4] + # Processing special options self._config['_bookoptions'] = iter_bookoptions(self._config) + self._config['chords']['_notenames'] = self._process_chord_notation( + self._config['chords']['notation'] + ) renderer.render_tex(output, self._config) @@ -111,6 +123,25 @@ class Songbook: if self.has_errors(): raise errors.SongbookError("Some songs contain errors. Stopping as requested.") + def _process_chord_notation(self, notation): + notation = notation.strip() + if notation in ['solfedge', 'alphascale']: + return notation + names = notation.split(" ") + if len(names) == 7: + return names + error = BookError( + "Option `notation` of section `chords` must be `solfedge`, " + "`alphascale` or a space separated list of exactly seven note " + "names." + ) + self._errors.append(error) + LOGGER.warning(str(error)) + if len(names) < 7: + return names + ["?"] * (7-len(names)) + else: + return names[:7] + def has_errors(self): """Return `True` iff errors have been encountered in the book. diff --git a/patacrep/data/templates/songbook/default.tex b/patacrep/data/templates/songbook/default.tex index d3b6fd34..0e62f0a5 100644 --- a/patacrep/data/templates/songbook/default.tex +++ b/patacrep/data/templates/songbook/default.tex @@ -85,10 +85,12 @@ description: \authsepword{((word))} (* endfor *) -(* if chords.notation=="alphascale" -*) +(* if chords._notenames == "alphascale" -*) \notenamesout{A}{B}{C}{D}{E}{F}{G} -(* else -*) +(* elif chords._notenames == "solfedge" -*) \notenamesout{La}{Si}{Do}{R\'e}{Mi}{Fa}{Sol} +(* else -*) + \notenamesout{(( chords._notenames[0] ))}{(( chords._notenames[1] ))}{(( chords._notenames[2] ))}{(( chords._notenames[3] ))}{(( chords._notenames[4] ))}{(( chords._notenames[5] ))}{(( chords._notenames[6] ))} (* endif *) (* endblock *) diff --git a/patacrep/data/templates/songbook_model.yml b/patacrep/data/templates/songbook_model.yml index a3d3ce1b..af8320f8 100644 --- a/patacrep/data/templates/songbook_model.yml +++ b/patacrep/data/templates/songbook_model.yml @@ -56,12 +56,7 @@ schema: - type: //str value: "ukulele" notation: - type: //any - of: - - type: //str - value: "alphascale" - - type: //str - value: "solfedge" + type: //str authors: type: //rec required: @@ -157,7 +152,7 @@ description: lilypond: "Display lilypond scores" tablatures: "Display tablatures" instrument: "Instrument for the diagrams" - notation: "Chord notation" + notation: "Chord notation. Can be `solfedge`, `alphascale`, or a space separated list of note names." authors: separators: "Separator words between artists" @@ -183,7 +178,7 @@ description: lilypond: "Inclure les partitions lilypond" tablatures: "Inclure les tablatures" instrument: "Instrument pour les diagrammes d'accords" - notation: "Notation des accords" + notation: "Notation des accords. Peut être `solfedge` (DO RE MI...), `alphascale` (A B C...), ou une liste des noms de notes séparés par des espaces, en commençant par LA." authors: separators: "Mots de séparation entre les artistes"