From 4e78c9fec86816a7a1afca9463b71094a2dcf62c Mon Sep 17 00:00:00 2001 From: Trevor Daniels Date: Mon, 14 Dec 2009 11:36:50 +0000 Subject: [PATCH] Add option to indicate frets in tablature by letter - Add Scheme function to provide fret number as a letter, invoked by setting the context property tablatureFormat to fret-letter-tablature-format - Add context property fretLabels to specify the fret labels, overriding the default letters of the alphabet --- Documentation/changes.tely | 32 +++++++++++++++++++ input/regression/tablature-letter.ly | 39 +++++++++++++++++++++++ lily/tab-note-heads-engraver.cc | 9 +++--- scm/define-context-properties.scm | 3 ++ scm/translation-functions.scm | 62 +++++++++++++++++++++++------------- 5 files changed, 119 insertions(+), 26 deletions(-) create mode 100644 input/regression/tablature-letter.ly diff --git a/Documentation/changes.tely b/Documentation/changes.tely index ca961e24f8..ba222abccd 100644 --- a/Documentation/changes.tely +++ b/Documentation/changes.tely @@ -71,6 +71,38 @@ single-line markup due to enhanced integration with Pango. LilyPond is now licensed under the GNU GPL v3+. @item +In tablature, frets can be indicated with labels other than numbers: + +@lilypond[verbatim,quote,relative=1] +\new TabStaff +\with { + stringTunings = #'(17 14 9 5 2 -3) + tablatureFormat = #fret-letter-tablature-format +} +\new TabVoice { + \set fretLabels = #`(,(markup #:with-color red "a") + "b" + ,(markup #:italic #:smaller "c")) + 4. 8 4 +} +@end lilypond + +@item +Layout objects can be printed over a white background, which whites-out objects +in lower layers which lie beneath: + +@lilypond[verbatim,quote,relative=1] +\time 3/4 +\override Staff.StaffSymbol #'layer = #4 +\once \override Tie #'layer = #2 +b'2.~ +\once \override Staff.TimeSignature #'whiteout = ##t +\once \override Staff.TimeSignature #'layer = #3 +\time 5/4 +b4 +@end lilypond + +@item Chords can be repeated using the @code{q} shortcut: @lilypond[verbatim,quote,relative=2] diff --git a/input/regression/tablature-letter.ly b/input/regression/tablature-letter.ly new file mode 100644 index 0000000000..6e9291ceb3 --- /dev/null +++ b/input/regression/tablature-letter.ly @@ -0,0 +1,39 @@ +\version "2.13.9" + +\header { texidoc = "A sample tablature with lettered tab, +using fretLabels to modify the fret letters. + +By default, letters are drawn sequentially from the alphabet, +but if the context property fretLabels is defined, these are +substituted. If specified, the length of fretLabels must be +sufficient to label all the frets used. A warning is issued +if the length is too short. +" +} + +notes = \relative c' { + \time 3/4 + 4. 8 4 + \set fretLabels = #`("a" "b" ,(markup #:italic #:smaller "c")) + 4. 8 4 + \set fretLabels = #`(,(markup #:with-color red "a") + "b" + ,(markup #:italic #:smaller "c")) + 4. 8 4 + \set fretLabels = #'("α" "β" "γ") + 4. 8 4 +} + +\score { + \new TabStaff + \with { + stringTunings = #'(17 14 9 5 2 -3) + tablatureFormat = #fret-letter-tablature-format + } + \new TabVoice { + \notes + } +} + + + diff --git a/lily/tab-note-heads-engraver.cc b/lily/tab-note-heads-engraver.cc index 79947b7045..3c5b2e91d1 100644 --- a/lily/tab-note-heads-engraver.cc +++ b/lily/tab-note-heads-engraver.cc @@ -169,12 +169,13 @@ ADD_TRANSLATOR (Tab_note_heads_engraver, "TabNoteHead ", /* read */ + "fretLabels " + "highStringOne " "middleCPosition " - "stringTunings " "minimumFret " - "tablatureFormat " - "highStringOne " - "stringOneTopmost ", + "stringOneTopmost " + "stringTunings " + "tablatureFormat ", /* write */ "" ); diff --git a/scm/define-context-properties.scm b/scm/define-context-properties.scm index a46e8b5d08..dac42fd3e2 100644 --- a/scm/define-context-properties.scm +++ b/scm/define-context-properties.scm @@ -241,6 +241,9 @@ at this point.") (forceClef ,boolean? "Show clef symbol, even if it has not changed. Only active for the first clef after the property is set, not for the full staff.") + (fretLabels ,list? "A list of strings or Scheme-formatted markups +containing, in the correct order, the labels to be used for lettered +frets in tablature.") (gridInterval ,ly:moment? "Interval for which to generate diff --git a/scm/translation-functions.scm b/scm/translation-functions.scm index 02de02db4d..6c68f34cb0 100644 --- a/scm/translation-functions.scm +++ b/scm/translation-functions.scm @@ -385,21 +385,40 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; tablature -;; The TabNoteHead tablatureFormat callback. -;; Compute the text grob-property -(define-public (fret-number-tablature-format string context event) +;; The TabNoteHead tablatureFormat callbacks. + +;; Calculate the fret from pitch and string number as letter +;; The fret letter is taken from 'fretLabels if present +(define-public (fret-letter-tablature-format string-number context event) + (let* ((tuning (ly:context-property context 'stringTunings)) + (pitch (ly:event-property event 'pitch)) + (labels (ly:context-property context 'fretLabels)) + (fret (- (ly:pitch-semitones pitch) + (list-ref tuning (- string-number 1))))) + (make-vcenter-markup + (cond + ((= 0 (length labels)) + (string (integer->char (+ fret (char->integer #\a))))) + ((and (<= 0 fret) (< fret (length labels))) + (list-ref labels fret)) + (else + (ly:warning "No label for fret ~a (~a on string ~a); +only ~a fret labels provided" + fret pitch string-number (length labels)) + "."))))) + +;; Calculate the fret from pitch and string number as number +(define-public (fret-number-tablature-format string-number context event) (let* ((tuning (ly:context-property context 'stringTunings)) (pitch (ly:event-property event 'pitch))) - - (make-whiteout-markup - (make-vcenter-markup - (format - "~a" - (- (ly:pitch-semitones pitch) - (list-ref tuning - ;; remove 1 because list index starts at 0 - ;;and guitar string at 1. - (1- string)))))))) + (make-vcenter-markup + (format + "~a" + (- (ly:pitch-semitones pitch) + (list-ref tuning + ;; remove 1 because list index starts at 0 + ;;and guitar string at 1. + (1- string-number))))))) ;; The 5-string banjo has got a extra string, the fifth (duh), which ;; starts at the fifth fret on the neck. Frets on the fifth string @@ -407,17 +426,16 @@ ;; the "first fret" on the fifth string is really the sixth fret ;; on the banjo neck. ;; We solve this by defining a new fret-number-tablature function: -(define-public (fret-number-tablature-format-banjo string context event) +(define-public (fret-number-tablature-format-banjo string-number context event) (let* ((tuning (ly:context-property context 'stringTunings)) (pitch (ly:event-property event 'pitch))) - - (make-whiteout-markup - (make-vcenter-markup - (let ((fret (- (ly:pitch-semitones pitch) (list-ref tuning (1- string))))) - (number->string (cond - ((and (> fret 0) (= string 5)) - (+ fret 5)) - (else fret)))))))) + (make-vcenter-markup + (let ((fret (- (ly:pitch-semitones pitch) + (list-ref tuning (1- string-number))))) + (number->string (cond + ((and (> fret 0) (= string-number 5)) + (+ fret 5)) + (else fret))))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -- 2.11.4.GIT