]> git.donarmstrong.com Git - lilypond.git/commitdiff
Add option to indicate frets in tablature by letter
authorTrevor Daniels <t.daniels@treda.co.uk>
Mon, 14 Dec 2009 11:36:50 +0000 (11:36 +0000)
committerTrevor Daniels <t.daniels@treda.co.uk>
Wed, 23 Dec 2009 16:48:32 +0000 (16:48 +0000)
 - 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
input/regression/tablature-letter.ly [new file with mode: 0644]
lily/tab-note-heads-engraver.cc
scm/define-context-properties.scm
scm/translation-functions.scm

index ca961e24f83579c17d783a262225ecb03df14059..ba222abccd7570796d5d6526998006786f124574 100644 (file)
@@ -70,6 +70,38 @@ single-line markup due to enhanced integration with Pango.
 @item
 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"))
+  <f d>4. <bes>8 <g e>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:
 
diff --git a/input/regression/tablature-letter.ly b/input/regression/tablature-letter.ly
new file mode 100644 (file)
index 0000000..6e9291c
--- /dev/null
@@ -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
+  <f d>4. <bes>8 <g e>4
+  \set fretLabels = #`("a" "b" ,(markup #:italic #:smaller "c"))
+  <f d>4. <bes>8 <g e>4
+  \set fretLabels = #`(,(markup #:with-color red "a")
+                       "b"
+                       ,(markup #:italic #:smaller "c"))
+  <f d>4. <bes>8 <g e>4
+  \set fretLabels = #'("α" "β" "γ")
+  <f d>4. <bes>8 <g e>4
+}
+
+\score {
+  \new TabStaff
+  \with {
+    stringTunings = #'(17 14 9 5 2 -3)
+    tablatureFormat = #fret-letter-tablature-format
+  }
+  \new TabVoice {
+    \notes
+  }
+}
+
+
+
index 79947b7045bff4d6e675172d4800837c225f94bb..3c5b2e91d195e92cfe38bc12d2f6a210600b3f02 100644 (file)
@@ -169,12 +169,13 @@ ADD_TRANSLATOR (Tab_note_heads_engraver,
                "TabNoteHead ",
 
                /* read */
+               "fretLabels "
+               "highStringOne "
                "middleCPosition "
-               "stringTunings "
                "minimumFret "
-               "tablatureFormat "
-               "highStringOne "
-               "stringOneTopmost ",
+               "stringOneTopmost "
+               "stringTunings "
+               "tablatureFormat ",
 
                /* write */ ""
                );
index a46e8b5d0819b97f857ab53888ab3cefb38be3fe..dac42fd3e234146071413217a163f6de93c41c04 100644 (file)
@@ -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
index 02de02db4d59d14da4b3c87cdd30a41adfb44b30..6c68f34cb073a88c2b3cfa38dfc089cce0bf9a20 100644 (file)
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; 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
 ;;   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)))))))
 
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;