lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Add scheme engraver for StaffTab notation


From: Werner LEMBERG
Subject: Re: [PATCH] Add scheme engraver for StaffTab notation
Date: Wed, 25 Feb 2015 14:54:05 +0100 (CET)

>> It's not clear to me how an alist of tuning names and the
>> associated string tunings is `utterly incomprehensible'...  Oh
>> well.
> 
> So what is the purpose of having _strings_ here?

For me this is the most natural form to present input that gets
massaged later on.

> What does the . mean?  What do the parens mean?

Uh, oh, ... alist ...  Please don't pretend to be a noob.

> To hide from the editor and reader what one is doing?  So that you
> don't get syntax highlighting and become unable to convert notenames
> or absolute/relative?  Not everything that is possible to do is a
> good idea.

Huh?  Are we still talking about string tunings?  What you do here is
trick number 3 in Schopenhauer's `Eristic Dialectic': Generalize your
opponent's specific statements.  Please don't do that.

> One error already introduced by yourself is that
> guitar-drop-c-tuning will be undefined since instead you are
> defining guitar-drop-c-tuning-tuning.

Yep, copy-and-paste error.

> Which stresses my point about it being a bad idea to use different
> words in definition and use.

Well, lilypond happily accepts a line like

  \makeDefaultStringTuning #'guitar-asus4-tunink \stringTuning <e, a, d e a e'>

without any error message.  Your argument is thus weak.

> The next thing to note is that the error messages are entirely
> incomprehensible

Again, I wouldn't call an error message `entirely incomprehensible' if
the offending line and position in the line is displayed.

> Of course, this also means that the input will be read, parsed, and
> tokenized, several times in a row, making this also quite less
> efficient.

This, however, is indeed true and a valid argument.  Just as a side
note for others who are reading this thread: the same is true for
`#{ ... #}', which is just syntactical sugar around
`ly:parser-parse-string', a variant of `ly:parser-include-string'.

> It is a good practice to have the syntactical context of input be
> its location in the file, without juggling it around between
> interpreters and input stacks manually.
> 
> Otherwise, error messages cannot properly track the source
> locations, and the editor cannot help with formatting and
> highlighting the source code appropriately.  And you avoid
> recombining tokens and several tokenizers working in sequence on the
> same input, requiring escaping of quote characters and other stuff.

I agree.  *However*, there are IMHO situations where some sweeps with
a magic wand makes everything looks more nicely.

Just for fun: Attached are the original and my massaged version of
`string-tunings-init.ly'.  Is my version really *that*
incomprehensible?


    Werner
%%%% This file is part of LilyPond, the GNU music typesetter.
%%%%
%%%% Copyright (C) 2010--2015 Carl D. Sorensen <address@hidden>
%%%%
%%%% LilyPond 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.
%%%%
%%%% LilyPond 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 LilyPond.  If not, see <http://www.gnu.org/licenses/>.

\version "2.16.0"

%%  A stringTuning is a list of pitches ordered by string number
%%  from 1 to N.
%%  Here we define a number of default string tunings.

%% A music function for converting a chord to a string tuning.
%% The music argument for \makeStringTuning must be a chord in
%% absolute mode ordered from the highest string number to the
%% lowest string number

stringTuning =
#(define-scheme-function (parser location chord)
   (ly:music?)
   (_i "Convert @var{chord} to a string tuning.
@var{chord} must be in absolute pitches and should have the highest
string number (generally the lowest pitch) first.")
   (let* ((ev-chord (car (extract-named-music chord 'EventChord))))
     (reverse! (event-chord-pitches ev-chord))))

defaultStringTunings = #'()

makeDefaultStringTuning =
#(define-void-function (parser location symbol pitches) (symbol? list?)
   (_i "This defines a string tuning @var{symbol} via a list of @var{pitches}.
The @var{symbol} also gets registered in @code{defaultStringTunings}
for documentation purposes.")
   (ly:parser-define! parser symbol pitches)
   (set! defaultStringTunings (acons symbol pitches defaultStringTunings)))

%% guitar tunings
\makeDefaultStringTuning #'guitar-tuning \stringTuning <e, a, d g b e'>
\makeDefaultStringTuning #'guitar-seven-string-tuning \stringTuning <b,, e, a, 
d g b e'>
\makeDefaultStringTuning #'guitar-drop-d-tuning \stringTuning <d, a, d g b e'>
\makeDefaultStringTuning #'guitar-drop-c-tuning \stringTuning <c, g, c f a d'>
\makeDefaultStringTuning #'guitar-open-g-tuning \stringTuning <d, g, d g b d'>
\makeDefaultStringTuning #'guitar-open-d-tuning \stringTuning <d, a, d fis a d'>
\makeDefaultStringTuning #'guitar-dadgad-tuning \stringTuning <d, a, d g a d'>
\makeDefaultStringTuning #'guitar-lute-tuning \stringTuning <e, a, d fis b e'>
\makeDefaultStringTuning #'guitar-asus4-tuning \stringTuning <e, a, d e a e'>

%% bass tunings
\makeDefaultStringTuning #'bass-tuning \stringTuning <e,, a,, d, g,>
\makeDefaultStringTuning #'bass-four-string-tuning \stringTuning <e,, a,, d, g,>
\makeDefaultStringTuning #'bass-drop-d-tuning \stringTuning <d,, a,, d, g,>
\makeDefaultStringTuning #'bass-five-string-tuning \stringTuning <b,,, e,, a,, 
d, g,>
\makeDefaultStringTuning #'bass-six-string-tuning \stringTuning <b,,, e,, a,, 
d, g, c>

%% mandolin tunings
\makeDefaultStringTuning #'mandolin-tuning \stringTuning <g d' a' e''>

%% tunings for 5-string banjo
\makeDefaultStringTuning #'banjo-open-g-tuning \stringTuning <g' d g b d'>
\makeDefaultStringTuning #'banjo-c-tuning \stringTuning <g' c g b d'>
\makeDefaultStringTuning #'banjo-modal-tuning \stringTuning <g' d g c' d'>
\makeDefaultStringTuning #'banjo-open-d-tuning \stringTuning <a' d fis a d'>
\makeDefaultStringTuning #'banjo-open-dm-tuning \stringTuning <a' d fis a d'>

%% ukulele tunings
\makeDefaultStringTuning #'ukulele-tuning \stringTuning <g' c' e' a'>
\makeDefaultStringTuning #'ukulele-d-tuning \stringTuning <a' d' fis' b'>
\makeDefaultStringTuning #'tenor-ukulele-tuning \stringTuning <g c' e' a'>
\makeDefaultStringTuning #'baritone-ukulele-tuning \stringTuning <d g b e'>

%% orchestral strings
\makeDefaultStringTuning #'violin-tuning \stringTuning <g d' a' e''>
\makeDefaultStringTuning #'viola-tuning \stringTuning <c g d' a'>
\makeDefaultStringTuning #'cello-tuning \stringTuning <c, g, d a>
\makeDefaultStringTuning #'double-bass-tuning \stringTuning <e,, a,, d, g,>

defaultStringTunings = #(reverse! defaultStringTunings)

%% convert 5-string banjo tuning to 4-string by removing the 5th string
four-string-banjo = #(lambda (tuning)
                         (take tuning 4))
%%%% This file is part of LilyPond, the GNU music typesetter.
%%%%
%%%% Copyright (C) 2010--2015 Carl D. Sorensen <address@hidden>
%%%%
%%%% LilyPond 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.
%%%%
%%%% LilyPond 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 LilyPond.  If not, see <http://www.gnu.org/licenses/>.

\version "2.16.0"

%%  A stringTuning is a list of pitches ordered by string number
%%  from 1 to N.
%%  Here we define a number of default string tunings.

%% A music function for converting a chord to a string tuning.
%% The music argument for \makeStringTuning must be a chord in
%% absolute mode ordered from the highest string number to the
%% lowest string number

stringTuning =
#(define-scheme-function (parser location chord)
   (ly:music?)
   (_i "Convert @var{chord} to a string tuning.
@var{chord} must be in absolute pitches and should have the highest
string number (generally the lowest pitch) first.")
   (let* ((ev-chord (car (extract-named-music chord 'EventChord))))
     (reverse! (event-chord-pitches ev-chord))))

defaultStringTunings = #'()

makeDefaultStringTuning =
#(define-void-function (parser location symbol pitches) (symbol? list?)
   (_i "This defines a string tuning @var{symbol} via a list of @var{pitches}.
The @var{symbol} also gets registered in @code{defaultStringTunings}
for documentation purposes.")
   (ly:parser-define! parser symbol pitches)
   (set! defaultStringTunings (acons symbol pitches defaultStringTunings)))


% We now iterate over an alist of tuning names and the associated tunings,
% constructing calls to \makeDefaultStringTuning.  For simplicity, the alist
% omits the final `-tuning' part in the tuning name; it also omits `<' and
% `>' around the pitches (the omitted parts are added by the alist
% iterator).

#(for-each
  (lambda (elem)
    (let* ((sym (car elem))
           (tuning (cdr elem)))
      (ly:parser-include-string
       parser
       (string-append "\\makeDefaultStringTuning #'" sym "-tuning"
                      " \\stringTuning <" tuning ">"))))

  '(
    ;; guitar tunings
    ("guitar" . "e, a, d g b e'")
    ("guitar-seven-string" . "b,, e, a, d g b e'")
    ("guitar-drop-d" . "d, a, d g b e'")
    ("guitar-drop-c" . "c, g, c f a d'")
    ("guitar-open-g" . "d, g, d g b d'")
    ("guitar-open-d" . "d, a, d fis a d'")
    ("guitar-dadgad" . "d, a, d g a d'")
    ("guitar-lute" . "e, a, d fis b e'")
    ("guitar-asus4" . "e, a, d e a e'")

    ;; bass tunings
    ("bass" . "e,, a,, d, g,")
    ("bass-four-string" . "e,, a,, d, g,")
    ("bass-drop-d" . "d,, a,, d, g,")
    ("bass-five-string" . "b,,, e,, a,, d, g,")
    ("bass-six-string" . "b,,, e,, a,, d, g, c")

    ;; mandolin tunings
    ("mandolin" . "g d' a' e''")

    ;; tunings for 5-string banjo
    ("banjo-open-g" . "g' d g b d'")
    ("banjo-c" . "g' c g b d'")
    ("banjo-modal" . "g' d g c' d'")
    ("banjo-open-d" . "a' d fis a d'")
    ("banjo-open-dm" . "a' d fis a d'")

    ;; ukulele tunings
    ("ukulele" . "g' c' e' a'")
    ("ukulele-d" . "a' d' fis' b'")
    ("tenor-ukulele" . "g c' e' a'")
    ("baritone-ukulele" . "d g b e'")

    ;; orchestral strings
    ("violin" . "g d' a' e''")
    ("viola" . "c g d' a'")
    ("cello" . "c, g, d a")
    ("double-bass" . "e,, a,, d, g,")
    ))


defaultStringTunings = #(reverse! defaultStringTunings)

%% convert 5-string banjo tuning to 4-string by removing the 5th string
four-string-banjo = #(lambda (tuning)
                         (take tuning 4))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]