+; Tablature functions, by Jiba (jiba@tuxfamily.org)
+
+; The TabNoteHead stem attachment function.
+(define (tablature-stem-attachment-function style duration)
+ (cons 0.0 0.5))
+
+
+; The TabNoteHead tablatureFormat callback.
+; Compute the text grob-property
+(define-public (fret-number-tablature-format string tuning pitch)
+ (number->string
+ (- (ly:pitch-semitones pitch)
+ (list-ref tuning
+ (- string 1) ; remove 1 because list index starts at 0 and guitar string at 1.
+ )
+ )))
+
+(define-public (hammer-print-function grob)
+ (let* ((note-collums (ly:grob-property grob 'note-columns))
+ (note-column1 (cadr note-collums))
+ (note-column2 (car note-collums))
+ (note1 (car (ly:grob-property note-column1 'note-heads)))
+ (note2 (car (ly:grob-property note-column2 'note-heads)))
+ (text1 (ly:grob-property note1 'text))
+ (text2 (ly:grob-property note2 'text))
+ (fret1 (if (string? text1) (string->number text1) 0))
+ (fret2 (if (string? text2) (string->number text2) 0))
+ (letter (cond
+ ((< fret1 fret2) "H")
+ ((> fret1 fret2) "P")
+ (else "")))
+
+ )
+ (let* ((slur (Slur::print grob))
+ (paper (ly:grob-paper grob))
+ (text (interpret-markup
+ paper
+ (ly:grob-alist-chain grob (ly:output-def-lookup paper 'text-font-defaults))
+ letter)))
+
+ (let ((x (/ (- (cdr (ly:stencil-extent slur 0))
+ (/ (cdr (ly:stencil-extent text 0)) 2.0)
+ )
+ -2.0)))
+
+ (ly:stencil-set-extent! text 0 (cons x x))
+ (ly:stencil-align-to! text 0 1)
+ )
+
+ (ly:stencil-combine-at-edge slur 1 1 text -0.6)
+ ) ) )
+
+
+
+(define-public guitar-tunings '(4 -1 -5 -10 -15 -20))
+
+; end of tablature functions
+
+
+(define-public (make-stencil-boxer line-thick x-padding y-padding callback)
+ "Makes a routine that adds a box around the grob parsed as argument"
+ (define (stencil-boxer grob)
+ (let*
+ (
+ (mol (callback grob))
+ (x-ext (interval-widen (ly:stencil-extent mol 0) x-padding))
+ (y-ext (interval-widen (ly:stencil-extent mol 1) y-padding))
+ (x-rule (make-filled-box-stencil (interval-widen x-ext line-thick)
+ (cons 0 line-thick)))
+ (y-rule (make-filled-box-stencil (cons 0 line-thick) y-ext))
+ )
+
+ (set! mol (ly:stencil-combine-at-edge mol 0 1 y-rule x-padding))
+ (set! mol (ly:stencil-combine-at-edge mol 0 -1 y-rule x-padding))
+ (set! mol (ly:stencil-combine-at-edge mol 1 1 x-rule 0))
+ (set! mol (ly:stencil-combine-at-edge mol 1 -1 x-rule 0))
+
+ mol))
+ stencil-boxer)
+
+(define-public (arg->string arg)
+ (cond ((number? arg) (ly:inexact->string arg 10))