From 6f3440b10855ea6792beed412a4f4d642ea53537 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 26 Apr 2016 00:08:32 +0200 Subject: [PATCH 1/6] 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" From c1e8ac80ed3eda5e823eee70a4a4768798011916 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 26 Apr 2016 06:30:03 +0200 Subject: [PATCH 2/6] Do not split definition of chord notation between python module and template --- patacrep/build.py | 14 +++++++++----- patacrep/data/templates/songbook/default.tex | 6 ------ patacrep/data/templates/songbook_model.yml | 4 ++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/patacrep/build.py b/patacrep/build.py index ce2ee802..f349c02c 100644 --- a/patacrep/build.py +++ b/patacrep/build.py @@ -111,7 +111,7 @@ class Songbook: # Processing special options self._config['_bookoptions'] = iter_bookoptions(self._config) - self._config['chords']['_notenames'] = self._process_chord_notation( + self._config['chords']['_notenames'] = self._get_chord_names( self._config['chords']['notation'] ) @@ -123,13 +123,17 @@ 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 + def _get_chord_names(self, notation): + """Return a list of chord names, given the user option.""" + if notation == "alphascale": + return ["A", "B", "C", "D", "E", "F", "G"] + if notation == "solfedge": + return ["La", "Si", "Do", r"R\'e", "Mi", "Fa", "Sol"] + 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 " diff --git a/patacrep/data/templates/songbook/default.tex b/patacrep/data/templates/songbook/default.tex index 0e62f0a5..1b02b2d3 100644 --- a/patacrep/data/templates/songbook/default.tex +++ b/patacrep/data/templates/songbook/default.tex @@ -85,13 +85,7 @@ description: \authsepword{((word))} (* endfor *) -(* if chords._notenames == "alphascale" -*) - \notenamesout{A}{B}{C}{D}{E}{F}{G} -(* 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 *) (* block title *) diff --git a/patacrep/data/templates/songbook_model.yml b/patacrep/data/templates/songbook_model.yml index af8320f8..045c0876 100644 --- a/patacrep/data/templates/songbook_model.yml +++ b/patacrep/data/templates/songbook_model.yml @@ -152,7 +152,7 @@ description: lilypond: "Display lilypond scores" tablatures: "Display tablatures" instrument: "Instrument for the diagrams" - notation: "Chord notation. Can be `solfedge`, `alphascale`, or a space separated list of note names." + notation: "Space separated list of chord names, with special values `solfedge` being an alias for `La Si Do Ré Mi Fa Sol`, and `alphascale` for `A B C D E F G`." authors: separators: "Separator words between artists" @@ -178,7 +178,7 @@ description: lilypond: "Inclure les partitions lilypond" tablatures: "Inclure les tablatures" instrument: "Instrument pour les diagrammes d'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." + notation: "Liste des noms de notes, séparés par des espaces, en commençant par LA, sachant que `solfedge` est un alias pour `La Si Do Ré Mi Fa Sol`, et `alphascale` pour `A B C D E F G`." authors: separators: "Mots de séparation entre les artistes" From 51fe10d8c9290cb70aeae3431b4dc8ed06a50293 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 26 Apr 2016 06:50:41 +0200 Subject: [PATCH 3/6] Fix indentation --- patacrep/data/templates/songbook/default.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/patacrep/data/templates/songbook/default.tex b/patacrep/data/templates/songbook/default.tex index 1b02b2d3..b16d0cba 100644 --- a/patacrep/data/templates/songbook/default.tex +++ b/patacrep/data/templates/songbook/default.tex @@ -85,7 +85,7 @@ description: \authsepword{((word))} (* endfor *) - \notenamesout{(( chords._notenames[0] ))}{(( chords._notenames[1] ))}{(( chords._notenames[2] ))}{(( chords._notenames[3] ))}{(( chords._notenames[4] ))}{(( chords._notenames[5] ))}{(( chords._notenames[6] ))} +\notenamesout{(( chords._notenames[0] ))}{(( chords._notenames[1] ))}{(( chords._notenames[2] ))}{(( chords._notenames[3] ))}{(( chords._notenames[4] ))}{(( chords._notenames[5] ))}{(( chords._notenames[6] ))} (* endblock *) (* block title *) From f8e99316701f9f042876869dabaaa8a99f4d39dc Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 26 Apr 2016 07:56:38 +0200 Subject: [PATCH 4/6] Chord names must be given as an array (instead of a space separated list) --- patacrep/build.py | 27 +--------------------- patacrep/data/templates/songbook_model.yml | 16 ++++++++++--- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/patacrep/build.py b/patacrep/build.py index f349c02c..cd11a1ee 100644 --- a/patacrep/build.py +++ b/patacrep/build.py @@ -29,16 +29,6 @@ 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: """Represent a songbook (.yaml) file. @@ -129,22 +119,7 @@ class Songbook: return ["A", "B", "C", "D", "E", "F", "G"] if notation == "solfedge": return ["La", "Si", "Do", r"R\'e", "Mi", "Fa", "Sol"] - - 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] + return notation def has_errors(self): """Return `True` iff errors have been encountered in the book. diff --git a/patacrep/data/templates/songbook_model.yml b/patacrep/data/templates/songbook_model.yml index 045c0876..2fa193d7 100644 --- a/patacrep/data/templates/songbook_model.yml +++ b/patacrep/data/templates/songbook_model.yml @@ -56,7 +56,17 @@ schema: - type: //str value: "ukulele" notation: - type: //str + type: //any + of: + - type: //str + value: "alphascale" + - type: //str + value: "solfedge" + - type: //arr + contents: //str + length: + min: 7 + max: 7 authors: type: //rec required: @@ -152,7 +162,7 @@ description: lilypond: "Display lilypond scores" tablatures: "Display tablatures" instrument: "Instrument for the diagrams" - notation: "Space separated list of chord names, with special values `solfedge` being an alias for `La Si Do Ré Mi Fa Sol`, and `alphascale` for `A B C D E F G`." + notation: "List of chord names, with special values `solfedge` being an alias for `La Si Do Ré Mi Fa Sol`, and `alphascale` for `A B C D E F G`." authors: separators: "Separator words between artists" @@ -178,7 +188,7 @@ description: lilypond: "Inclure les partitions lilypond" tablatures: "Inclure les tablatures" instrument: "Instrument pour les diagrammes d'accords" - notation: "Liste des noms de notes, séparés par des espaces, en commençant par LA, sachant que `solfedge` est un alias pour `La Si Do Ré Mi Fa Sol`, et `alphascale` pour `A B C D E F G`." + notation: "Liste des noms de notes, en commençant par LA, sachant que `solfedge` est un alias pour `La Si Do Ré Mi Fa Sol`, et `alphascale` pour `A B C D E F G`." authors: separators: "Mots de séparation entre les artistes" From 665f9fa4b925d65754bcb43d4e7febadec7a2a2f Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 26 Apr 2016 08:45:17 +0200 Subject: [PATCH 5/6] Turn method into static method --- patacrep/build.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/patacrep/build.py b/patacrep/build.py index cd11a1ee..3998244d 100644 --- a/patacrep/build.py +++ b/patacrep/build.py @@ -113,7 +113,8 @@ class Songbook: if self.has_errors(): raise errors.SongbookError("Some songs contain errors. Stopping as requested.") - def _get_chord_names(self, notation): + @staticmethod + def _get_chord_names(notation): """Return a list of chord names, given the user option.""" if notation == "alphascale": return ["A", "B", "C", "D", "E", "F", "G"] From dec5d9e973a498b8ccbac6a64b0984bab263a84b Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 26 Apr 2016 08:45:26 +0200 Subject: [PATCH 6/6] Make help more clear --- patacrep/data/templates/songbook_model.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/patacrep/data/templates/songbook_model.yml b/patacrep/data/templates/songbook_model.yml index 2fa193d7..e1418e97 100644 --- a/patacrep/data/templates/songbook_model.yml +++ b/patacrep/data/templates/songbook_model.yml @@ -162,7 +162,7 @@ description: lilypond: "Display lilypond scores" tablatures: "Display tablatures" instrument: "Instrument for the diagrams" - notation: "List of chord names, with special values `solfedge` being an alias for `La Si Do Ré Mi Fa Sol`, and `alphascale` for `A B C D E F G`." + notation: "List of chord names, with special values `solfedge` being an alias for `['La', 'Si', 'Do', 'Ré', 'Mi', 'Fa', 'Sol']`, and `alphascale` for `['A', 'B', 'C', 'D', 'E', 'F', 'G']`." authors: separators: "Separator words between artists" @@ -188,7 +188,7 @@ description: lilypond: "Inclure les partitions lilypond" tablatures: "Inclure les tablatures" instrument: "Instrument pour les diagrammes d'accords" - notation: "Liste des noms de notes, en commençant par LA, sachant que `solfedge` est un alias pour `La Si Do Ré Mi Fa Sol`, et `alphascale` pour `A B C D E F G`." + notation: "Liste des noms de notes, en commençant par LA, sachant que `solfedge` est un alias pour `['La', 'Si', 'Do', 'Ré', 'Mi', 'Fa', 'Sol']`, et `alphascale` pour `['A', 'B', 'C', 'D', 'E', 'F', 'G']`." authors: separators: "Mots de séparation entre les artistes"