+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; tablature
+
+;; 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-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
+;; are referred to relative to the other frets:
+;; 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-number context event)
+ (let* ((tuning (ly:context-property context 'stringTunings))
+ (pitch (ly:event-property event 'pitch)))
+ (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)))))))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; bar numbers
+
+(define-public ((every-nth-bar-number-visible n) barnum)
+ (= 0 (modulo barnum n)))
+
+(define-public ((modulo-bar-number-visible n m) barnum)
+ (and (> barnum 1) (= m (modulo barnum n))))
+
+(define-public ((set-bar-number-visibility n) tr)
+ (let ((bn (ly:context-property tr 'currentBarNumber)))
+ (ly:context-set-property! tr 'barNumberVisibility
+ (modulo-bar-number-visible n (modulo bn n)))))
+
+(define-public (first-bar-number-invisible barnum) (> barnum 1))
+
+(define-public (all-bar-numbers-visible barnum) #t)
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; percent repeat counters
+
+(define-public ((every-nth-repeat-count-visible n) count context)
+ (= 0 (modulo count n)))
+
+(define-public (all-repeat-counts-visible count context) #t)