From c75617c60b8585fc27615de77b3add995adc9fee Mon Sep 17 00:00:00 2001 From: Valentin Villenave Date: Thu, 9 Oct 2014 13:27:11 +0200 Subject: [PATCH] Add functionality to string numbers This commit adds a number-type property that allows for different numbering styles, as well as user-exposed predefined commands to easily switch between default guitar-like string numbers and roman numerals more suitable for unfretted strings. Additionally, the number formatting function previously used only in fret-diagrams is now available for possibly wider use. --- Documentation/changes.tely | 11 ++++++++++ Documentation/notation/fretted-strings.itely | 20 +++++++++++++++++++ .../notation/unfretted-strings.itely | 19 ++++++++++++++---- ly/property-init.ly | 16 +++++++++++++++ scm/define-grob-interfaces.scm | 5 +++++ scm/define-grob-properties.scm | 2 ++ scm/define-grobs.scm | 2 ++ scm/fret-diagrams.scm | 16 +++------------ scm/lily-library.scm | 20 +++++++++++++++++++ scm/output-lib.scm | 4 +++- 10 files changed, 97 insertions(+), 18 deletions(-) diff --git a/Documentation/changes.tely b/Documentation/changes.tely index 9e53285a1c..b714fe5d94 100644 --- a/Documentation/changes.tely +++ b/Documentation/changes.tely @@ -164,6 +164,17 @@ group, but @emph{not} with @var{violinI}, will be removed. The @code{\addlyrics} function now works with arbitrary contexts incuding @code{Staff}. +@item +String numbers can now also be used to print roman numerals +(e.g. for unfretted string instruments). +@lilypond[verbatim,quote,relative=2] +c2\2 +\romanStringNumbers +c\2 +\arabicStringNumbers +c1\3 +@end lilypond + @item The @code{thin-kern} property of the @code{BarLine} grob has been renamed to @code{segno-kern}. diff --git a/Documentation/notation/fretted-strings.itely b/Documentation/notation/fretted-strings.itely index 76d8f5d375..c1257539ec 100644 --- a/Documentation/notation/fretted-strings.itely +++ b/Documentation/notation/fretted-strings.itely @@ -119,6 +119,21 @@ g-0\3 @end lilypond +String numbers may also, as is customary with unfretted strings, +be printed in Roman numerals and placed below the staff rather +than above. + +@lilypond[verbatim,quote,relative=2] +c2\2 +a\3 +\romanStringNumbers +c\2 +\set stringNumberOrientations = #'(down) +a\3 +\arabicStringNumbers +g1\4 +@end lilypond + @snippets @lilypondfile[verbatim,quote,texidoc,doctitle] @@ -127,6 +142,11 @@ g-0\3 @lilypondfile[verbatim,quote,texidoc,doctitle] {allowing-fingerings-to-be-printed-inside-the-staff.ly} +@predefined +@code{\arabicStringNumbers}, +@code{\romanStringNumbers}. +@endpredefined + @seealso Notation Reference: @ref{Fingering instructions}. diff --git a/Documentation/notation/unfretted-strings.itely b/Documentation/notation/unfretted-strings.itely index fcaff9d4dc..4a48d5c97a 100644 --- a/Documentation/notation/unfretted-strings.itely +++ b/Documentation/notation/unfretted-strings.itely @@ -85,12 +85,14 @@ Snippets: @funindex \upbow @funindex \downbow @funindex \open +@funindex \romanStringNumbers @cindex bowing indications @cindex up bow indication @cindex down bow indication @cindex open string indication @cindex string, indicating open +@cindex string numbers Bowing indications are created as articulations, which are described in @ref{Articulations and ornamentations}. @@ -103,12 +105,19 @@ c4(\downbow d) e(\upbow f) @end lilypond @noindent -and the following example shows three ways in which an open A -string on a violin might be indicated: + +Roman numerals can be added as strings numbers (rather +than the default circled Arabic numbers), as explained in +@ref{String number indications}. + +Alternatively, string indications may be printed using +markup commands; articulation scripts may also indicate +open strings. @lilypond[verbatim,quote,relative=2] a4 \open -a^\markup { \teeny "II" } +\romanStringNumbers +a\2 a2^\markup { \small "sul A" } @end lilypond @@ -116,12 +125,14 @@ a2^\markup { \small "sul A" } @predefined @code{\downbow}, @code{\upbow}, -@code{\open}. +@code{\open}, +@code{\romanStringNumbers}. @endpredefined @seealso Notation Reference: @ref{Articulations and ornamentations}, +@ref{String number indications}, @ref{Slurs}. diff --git a/ly/property-init.ly b/ly/property-init.ly index f27311f9a4..8d6d892d17 100644 --- a/ly/property-init.ly +++ b/ly/property-init.ly @@ -509,6 +509,22 @@ stemDown = \override Stem.direction = #DOWN stemNeutral = \revert Stem.direction +%% string numbers + +romanStringNumbers = { + \override StringNumber.number-type = #'roman-upper + \override StringNumber.stencil = #ly:text-interface::print + \override StringNumber.font-encoding = #'latin1 + \override StringNumber.font-shape = #'italic +} +arabicStringNumbers = { + \revert StringNumber.number-type + \revert StringNumber.stencil + \revert StringNumber.font-encoding + \revert StringNumber.font-shape +} + + %% tablature % switch to full notation diff --git a/scm/define-grob-interfaces.scm b/scm/define-grob-interfaces.scm index e07006e350..2321e1c903 100644 --- a/scm/define-grob-interfaces.scm +++ b/scm/define-grob-interfaces.scm @@ -216,6 +216,11 @@ accidentals)." "Note names." '()) +(ly:add-interface + 'number-interface + "Numbers." + '(number-type)) + (ly:add-interface 'only-prebreak-interface "Kill this grob after the line breaking process." diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index a81eed5009..d6deaec30f 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -698,6 +698,8 @@ over the total spanner, where the width of the spanner is normalized between 0 and 1.") (note-names ,vector? "Vector of strings containing names for easy-notation note heads.") + (number-type ,symbol? "Numbering style. Choices include +@code{roman-lower}, @code{roman-upper} and @code{arabic}.") ;;; diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 7baaf000cb..65063d7af5 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -2168,6 +2168,7 @@ (cross-staff . ,script-or-side-position-cross-staff) (font-encoding . fetaText) (font-size . -5) ; don't overlap when next to heads. + (number-type . arabic) (padding . 0.5) (parent-alignment-X . ,CENTER) (script-priority . 100) @@ -2182,6 +2183,7 @@ self-alignment-interface outside-staff-interface side-position-interface + number-interface string-number-interface text-interface text-script-interface)))))) diff --git a/scm/fret-diagrams.scm b/scm/fret-diagrams.scm index e60c0dca35..a1daae3321 100644 --- a/scm/fret-diagrams.scm +++ b/scm/fret-diagrams.scm @@ -801,19 +801,9 @@ at @var{fret}." (number-type (assoc-get 'number-type details 'roman-lower)) (label-text - (cond - ((equal? number-type 'roman-lower) - (fancy-format #f "~(~@r~)" base-fret)) - ((equal? number-type 'roman-upper) - (fancy-format #f "~@r" base-fret)) - ((equal? 'arabic number-type) - (fancy-format #f "~d" base-fret)) - ((equal? 'custom number-type) - (fancy-format #f - (assoc-get 'fret-label-custom-format - details "~a") - base-fret)) - (else (fancy-format #f "~(~@r~)" base-fret)))) + (number-format number-type base-fret + (assoc-get 'fret-label-custom-format + details "~a"))) (label-stencil (centered-stencil (sans-serif-stencil diff --git a/scm/lily-library.scm b/scm/lily-library.scm index 472a82da24..9008831c72 100644 --- a/scm/lily-library.scm +++ b/scm/lily-library.scm @@ -889,6 +889,26 @@ Handy for debugging, possibly turned off." (reverse matches)) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; numbering styles + +(define-public (number-format number-type num . custom-format) + "Print NUM accordingly to the requested NUMBER-TYPE. +Choices include @code{roman-lower} (by default), +@code{roman-upper}, @code{arabic} and @code{custom}. +In the latter case, CUSTOM-FORMAT must be supplied +and will be applied to NUM." + (cond + ((equal? number-type 'roman-lower) + (fancy-format #f "~(~@r~)" num)) + ((equal? number-type 'roman-upper) + (fancy-format #f "~@r" num)) + ((equal? number-type 'arabic) + (fancy-format #f "~d" num)) + ((equal? number-type 'custom) + (fancy-format #f (car custom-format) num)) + (else (fancy-format #f "~(~@r~)" num)))) + ;;;;;;;;;;;;;;;; ;; other diff --git a/scm/output-lib.scm b/scm/output-lib.scm index 59f93e2e7e..6a385fd72a 100644 --- a/scm/output-lib.scm +++ b/scm/output-lib.scm @@ -995,7 +995,9 @@ and duration-log @var{log}." (define-public (string-number::calc-text grob) (let ((event (event-cause grob))) (or (ly:event-property event 'text #f) - (number->string (ly:event-property event 'string-number) 10)))) + (number-format + (ly:grob-property grob 'number-type) + (ly:event-property event 'string-number))))) (define-public (stroke-finger::calc-text grob) (let ((event (event-cause grob))) -- 2.39.2