From 18843938965b101d4cb49d3bbe23760b14000254 Mon Sep 17 00:00:00 2001 From: rekado Date: Sat, 1 Oct 2016 18:33:49 +0200 Subject: Validate scales. --- scales/scales.scm | 15 +++++++++++++++ scales/ui.scm | 16 ++++++++++++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/scales/scales.scm b/scales/scales.scm index 4d80bbf..38c7579 100644 --- a/scales/scales.scm +++ b/scales/scales.scm @@ -19,6 +19,7 @@ #:use-module (srfi srfi-1) #:use-module (scales utils) #:export (steps->scale + valid-scales lydian ionian @@ -76,3 +77,17 @@ root note and returns a list of scale notes." (steps->scale '(2 2 2 2 2 2))) (define chromatic (steps->scale '(1 1 1 1 1 1 1 1 1 1 1))) + +(define valid-scales + '(lydian + ionian + mixolydian + lydian-b7 + altered + symmetrical-diminished + dorian + aeolian + phrygian + locrian + whole-tone + chromatic)) diff --git a/scales/ui.scm b/scales/ui.scm index b95d5d9..8ddfda6 100644 --- a/scales/ui.scm +++ b/scales/ui.scm @@ -17,6 +17,7 @@ (define-module (scales ui) #:use-module (ice-9 getopt-long) + #:use-module (scales utils) #:use-module (scales fretboard) #:use-module (scales scales) #:export (main)) @@ -29,10 +30,17 @@ (lambda _ tuning))) (define (lookup-scale scale) - (catch #t - (lambda _ - (module-ref (resolve-interface '(scales scales)) scale)) - (lambda _ (steps->scale scale)))) + (if (member scale valid-scales) + (module-ref (resolve-interface '(scales scales)) scale) + (if (not (pair? scale)) + (leave " +Invalid scale \"~s\". +The scale must be either the name of a pre-defined scale or a list of steps. + +Valid scale names are: + +~{ ~s \n~}\n" scale valid-scales) + (steps->scale scale)))) (define (main args) (let* ((option-spec '((version (single-char #\v) (value #f)) -- cgit v1.2.3