From 3170fd65067a96ea861c173c81fce5f0e127762e Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sun, 23 Oct 2011 15:29:45 +0200 Subject: [PATCH] Get rid of most of the insane string-tunings API --- .../display-predefined-string-tunings.ly | 36 ++-- Documentation/notation/fretted-strings.itely | 70 +++----- input/regression/tablature-letter.ly | 9 +- input/regression/tablature-string-tunings.ly | 7 +- ly/string-tunings-init.ly | 165 +++++++----------- python/convertrules.py | 12 ++ 6 files changed, 116 insertions(+), 183 deletions(-) diff --git a/Documentation/included/display-predefined-string-tunings.ly b/Documentation/included/display-predefined-string-tunings.ly index 6216fbe123..d917dd3d64 100644 --- a/Documentation/included/display-predefined-string-tunings.ly +++ b/Documentation/included/display-predefined-string-tunings.ly @@ -7,30 +7,18 @@ tuning-alist)) #(define (chord-display tuning-alist-entry) - (let* ((ch-mus (cdr tuning-alist-entry)) - (tuning-symbol (car tuning-alist-entry)) - (ev-chord (car (extract-named-music - ch-mus - 'EventChord))) - (elts (ly:music-property ev-chord 'elements))) - (music-map (lambda (m) - (begin - (if (not (null? (ly:music-property m 'duration))) - (ly:music-set-property! - m - 'duration - (ly:make-duration 0 0 1 1))) - m)) - ev-chord) - (let ((elts (ly:music-property ev-chord 'elements)) - (script (make-music 'TextScriptEvent - 'direction 1 - 'text (symbol->string tuning-symbol)))) - (ly:music-set-property! - ev-chord - 'elements - (cons script elts))) - ev-chord)) + (let* ((tuning-symbol (car tuning-alist-entry)) + (pitches (cdr tuning-alist-entry))) + (make-music 'EventChord + 'elements + (cons (make-music 'TextScriptEvent + 'direction 1 + 'text (symbol->string tuning-symbol)) + (map (lambda (pitch) + (make-music 'NoteEvent + 'duration (ly:make-duration 0 0 1 1) + 'pitch pitch)) + pitches))))) displayInstrumentDefaultTunings = #(define-music-function (parser location instrument) (string?) diff --git a/Documentation/notation/fretted-strings.itely b/Documentation/notation/fretted-strings.itely index d3407249ab..3cb4dadb68 100644 --- a/Documentation/notation/fretted-strings.itely +++ b/Documentation/notation/fretted-strings.itely @@ -503,7 +503,7 @@ Guitar special effects are limited to harmonics and slides. @cindex tablature, bass @cindex tablature, double bass -@funindex StringTunings +@funindex stringTunings LilyPond tablature automatically calculates the fret for a note based on the string to which the note is assigned. @@ -541,19 +541,18 @@ is the standard EADGBE tuning. Some other predefined tunings are @code{banjo-open-g-tuning}. The predefined string tunings are found in @file{ly/string-tuning-init.ly}. -@funindex contextStringTunings -@funindex \contextStringTunings +@funindex stringTuning +@funindex \stringTuning @cindex tablature, custom string tunings @cindex custom string tunings Any desired string tuning can be created. The -@code{\contextStringTuning} function can be -used to define a string tuning and set it as the -@code{stringTunings} for the current context. -@code{\contextStringTuning} takes two arguments: the -symbol in which the string tuning will be stored, -and a chord construct -that defines the pitches of each string in the tuning. +@code{\stringTuning} function can be +used to define a string tuning which can be used +to set @code{stringTunings} for the current context. + +Its argument is a chord construct +defining the pitches of each string in the tuning. The chord construct must be in absolute octave mode, see @ref{Absolute octave entry}. The string with the highest number (generally the lowest string) must @@ -574,7 +573,7 @@ mynotes = { \mynotes } \new TabStaff { - \contextStringTuning #'custom-tuning + \set stringTunings = \stringTuning \mynotes } >> @@ -583,17 +582,10 @@ mynotes = { The @code{stringTunings} property is also used by @code{FretBoards} to calculate automatic fret diagrams. -@funindex makeStringTuning -@funindex \makeStringTuning - String tunings are used as part of the hash key for predefined fret diagrams -(see @ref{Predefined fret diagrams}). The @code{\makeStringTuning} -function is used to create a string tuning without setting the -@code{stringTunings} property in the current context. The -arguments to @code{\makeStringTuning} are the symbol to be -used for the new string tuning and a chord construct used -to define the tuning. +(see @ref{Predefined fret diagrams}). + The previous example could also be written as follows: @lilypond[quote,verbatim] @@ -627,36 +619,26 @@ A string pitch in a string tuning list is a LilyPond pitch object. Pitch objects are created with the Scheme function @code{ly:make-pitch} (see @ref{Scheme functions}). -If desired, a string tuning can be created as a Scheme -literal. The example below recreates the examples above, -but the string tuning is not saved as a separate object: - -@lilypond[quote,verbatim] -mynotes = { - c'4 e' g' c'' | - e''4 g'' b'' c''' -} - -<< - \new Staff { - \clef treble - \mynotes - } - \new TabStaff { - \set TabStaff.stringTunings = #`(,(ly:make-pitch 1 5 0) - ,(ly:make-pitch 1 1 0) - ,(ly:make-pitch 0 4 0) - ,(ly:make-pitch 0 0 0)) - \mynotes - } ->> -@end lilypond +@code{\stringTuning} creates such an object from chord input. LilyPond automatically calculates the number of lines in the @code{TabStaff} and the number of strings in an automatically calculated @code{FretBoard} as the number of elements in @code{stringTunings}. +To let all TabStaff contexts use the same custom tuning by default, +you can use + +@example +\layout @{ + \context @{ + \TabStaff + stringTunings = \stringTuning \notemode @{ @} + @} +@} +@end example + + @cindex moderntab clef @cindex clef, moderntab @cindex clef, tab diff --git a/input/regression/tablature-letter.ly b/input/regression/tablature-letter.ly index 3fc098e8d8..e2d8c94a8a 100644 --- a/input/regression/tablature-letter.ly +++ b/input/regression/tablature-letter.ly @@ -1,4 +1,4 @@ -\version "2.14.0" +\version "2.15.16" \header { texidoc = " @@ -29,12 +29,7 @@ notes = \relative c' { \score { \new TabStaff \with { - stringTunings = #`(,(ly:make-pitch 1 3 0) - ,(ly:make-pitch 1 1 0) - ,(ly:make-pitch 0 5 0) - ,(ly:make-pitch 0 3 0) - ,(ly:make-pitch 0 1 0) - ,(ly:make-pitch -1 5 0)) + stringTunings = \stringTuning \notemode { } tablatureFormat = #fret-letter-tablature-format } \new TabVoice { diff --git a/input/regression/tablature-string-tunings.ly b/input/regression/tablature-string-tunings.ly index 0808e8d565..9727294b54 100644 --- a/input/regression/tablature-string-tunings.ly +++ b/input/regression/tablature-string-tunings.ly @@ -1,4 +1,4 @@ -\version "2.14.0" +\version "2.15.16" \header { @@ -10,10 +10,7 @@ \new TabStaff { - \set TabStaff.stringTunings = #`(,(ly:make-pitch 0 3 0) - ,(ly:make-pitch 0 5 SHARP) - ,(ly:make-pitch 1 1 SHARP) - ,(ly:make-pitch 1 4 SHARP)) + \set TabStaff.stringTunings = \stringTuning \relative c'' { c4 d e f } } diff --git a/ly/string-tunings-init.ly b/ly/string-tunings-init.ly index fade5dad32..d3e4f54d57 100644 --- a/ly/string-tunings-init.ly +++ b/ly/string-tunings-init.ly @@ -15,118 +15,77 @@ %%%% You should have received a copy of the GNU General Public License %%%% along with LilyPond. If not, see . -\version "2.14.0" +\version "2.15.16" %% 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 scheme function for converting a chord to a string tuning -#(define (chord->tuning parser tuning-symbol chord) - (let* ((ev-chord (car (extract-named-music chord 'EventChord))) - (pitches (event-chord-pitches ev-chord))) - (ly:parser-define! parser tuning-symbol (reverse pitches)))) - %% 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 -makeStringTuning = -#(define-music-function (parser location tuning chord) - (symbol? ly:music?) - (_ "Convert @{chord} to a string tuning stored in @code{tuning}. -@{chord} must be in absolute pitches and should have the highest -string number (generally the lowest pitch) first. @code{tuning} -should be a string that will be converted to a symbol.") - (begin - (chord->tuning parser tuning chord) - (make-music 'SequentialMusic 'void #t))) - - -%% A music function for converting a chord to a string tuning -%% and setting the current context stringTunings property to -%% the newly-defined-string tuning. - -contextStringTuning = -#(define-music-function (parser location tuning chord) - (symbol? ly:music?) - (_ "Convert @{chord} to a string tuning stored in @code{tuning}, -and set @code{stringTunings} of the current context to the -newly-defined tuning. -@{chord} must be in absolute pitches and should have the highest -string number (generally the lowest pitch) first. @code{tuning} -should be a string that will be converted to a symbol.") - (chord->tuning parser tuning chord) - #{ \set stringTunings = #(ly:parser-lookup $parser $tuning) - #}) - -%% A music function for converting an alist to string-tunings -makeDefaultStringTunings = -#(define-music-function (parser location default-tuning-alist) - (cheap-list?) - (_ "Define default string tunings for each element of -@code{default-tuning-alist}.") - (begin - (for-each (lambda (alist-entry) - (chord->tuning parser (car alist-entry) (cdr alist-entry))) - default-tuning-alist) - (make-music 'SequentialMusic 'void #t))) - -% tuning definitions require default pitchnames -\languageSaveAndChange #default-language - -%% Define alist of default string tunings -defaultStringTunings = -#`( - ;; guitar tunings - (guitar-tuning . ,#{#}) - (guitar-seven-string-tuning . ,#{#}) - (guitar-drop-d-tuning . ,#{#}) - (guitar-open-g-tuning . ,#{#}) - (guitar-open-d-tuning . ,#{#}) - (guitar-dadgad-tuning . ,#{#}) - (guitar-lute-tuning . ,#{#}) - (guitar-asus4-tuning . ,#{#}) - - ;; bass tunings - (bass-tuning . ,#{#}) - (bass-four-string-tuning . ,#{#}) - (bass-drop-d-tuning . ,#{#}) - (bass-five-string-tuning . ,#{#}) - (bass-six-string-tuning . ,#{#}) - - ;; mandolin tunings - (mandolin-tuning . ,#{#}) - - ;; tunings for 5-string banjo - (banjo-open-g-tuning . ,#{#}) - (banjo-c-tuning . ,#{#}) - (banjo-modal-tuning . ,#{#}) - (banjo-open-d-tuning . ,#{#}) - (banjo-open-dm-tuning . ,#{#}) - - ;; ukulele tunings - (ukulele-tuning . ,#{#}) - (ukulele-d-tuning . ,#{#}) - (tenor-ukulele-tuning . ,#{#}) - (baritone-ukulele-tuning . ,#{#}) - - ;; orchestral strings - (violin-tuning . ,#{#}) - (viola-tuning . ,#{#}) - (cello-tuning . ,#{#}) - (double-bass-tuning . ,#{#}) - ) +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 +\makeDefaultStringTuning #'guitar-seven-string-tuning \stringTuning +\makeDefaultStringTuning #'guitar-drop-d-tuning \stringTuning +\makeDefaultStringTuning #'guitar-open-g-tuning \stringTuning +\makeDefaultStringTuning #'guitar-open-d-tuning \stringTuning +\makeDefaultStringTuning #'guitar-dadgad-tuning \stringTuning +\makeDefaultStringTuning #'guitar-lute-tuning \stringTuning +\makeDefaultStringTuning #'guitar-asus4-tuning \stringTuning + +%% bass tunings +\makeDefaultStringTuning #'bass-tuning \stringTuning +\makeDefaultStringTuning #'bass-four-string-tuning \stringTuning +\makeDefaultStringTuning #'bass-drop-d-tuning \stringTuning +\makeDefaultStringTuning #'bass-five-string-tuning \stringTuning +\makeDefaultStringTuning #'bass-six-string-tuning \stringTuning + +%% mandolin tunings +\makeDefaultStringTuning #'mandolin-tuning \stringTuning + +%% tunings for 5-string banjo +\makeDefaultStringTuning #'banjo-open-g-tuning \stringTuning +\makeDefaultStringTuning #'banjo-c-tuning \stringTuning +\makeDefaultStringTuning #'banjo-modal-tuning \stringTuning +\makeDefaultStringTuning #'banjo-open-d-tuning \stringTuning +\makeDefaultStringTuning #'banjo-open-dm-tuning \stringTuning + +%% ukulele tunings +\makeDefaultStringTuning #'ukulele-tuning \stringTuning +\makeDefaultStringTuning #'ukulele-d-tuning \stringTuning +\makeDefaultStringTuning #'tenor-ukulele-tuning \stringTuning +\makeDefaultStringTuning #'baritone-ukulele-tuning \stringTuning + +%% orchestral strings +\makeDefaultStringTuning #'violin-tuning \stringTuning +\makeDefaultStringTuning #'viola-tuning \stringTuning +\makeDefaultStringTuning #'cello-tuning \stringTuning +\makeDefaultStringTuning #'double-bass-tuning \stringTuning + +defaultStringTunings = #(reverse! defaultStringTunings) %% convert 5-string banjo tuning to 4-string by removing the 5th string -#(define-public (four-string-banjo tuning) - (reverse (cdr (reverse tuning)))) - -%% make all of the default string tunings - -\makeDefaultStringTunings #defaultStringTunings - -% restore the language -\languageRestore - +"four-string-banjo" = #(lambda (tuning) + (take tuning 4)) diff --git a/python/convertrules.py b/python/convertrules.py index 749e8624b6..f1fab5c0a2 100644 --- a/python/convertrules.py +++ b/python/convertrules.py @@ -3244,6 +3244,18 @@ def conv (str): str = re.sub (r"(\s+(?:\\once\s*)?)\\revert\s*Stem\s+#'stencil", r"\g<1>\\revert Stem #'stencil\g<1>\\revert Flag #'stencil", str) return str +@rule ((2, 15, 16), r"\makeStringTuning, \contextStringTuning -> \stringTuning") +def conv (str): + str = re.sub (r"(\s+)\\contextStringTuning(\s+)#'([-a-zA-Z]+)(\s+<[^<>]+>)", + r"""\g<1>#(define \g<3> #{ \\stringTuning\g<4> #})\g<1>\\set stringTunings = #\g<3>""", + str) + str = re.sub (r""" +\\makeStringTuning(\s+)#'([-a-zA-Z]+)""", + r""" +"\g<2>" = \\stringTuning""", str) + str = re.sub (r"\\makeStringTuning(\s+)#'([-a-zA-Z]+)(\s+<[^<>]+>)", + r"#(define \g<2> #{ \\stringTuning\g<3> #})", str) + return str # Guidelines to write rules (please keep this at the end of this file) # -- 2.39.2