]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/translation-functions.scm
Add default padding between staves.
[lilypond.git] / scm / translation-functions.scm
index 79a924812ab224c6804b1ae938a18607e05c41db..fb8ccac3c5b1dde2bfd8d812659144391005a9c2 100644 (file)
@@ -2,44 +2,45 @@
 ;;;;
 ;;;;  source file of the GNU LilyPond music typesetter
 ;;;; 
-;;;; (c) 1998--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
+;;;; (c) 1998--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
 ;;;;                Jan Nieuwenhuizen <janneke@gnu.org>
 
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; metronome marks
+
 (define-public (format-metronome-markup text dur count context)
-  (let* ((hide_note (eq? #t (ly:context-property context 'tempoHideNote)))
-        (note-mark (if (and (not hide_note) (ly:duration? dur))
+  (let* ((hide-note (eq? #t (ly:context-property context 'tempoHideNote))))
+    (metronome-markup text dur count hide-note)))
+
+(define-public (metronome-markup text dur count hide-note)
+  (let* ((note-mark (if (and (not hide-note) (ly:duration? dur))
                       (make-smaller-markup
                       (make-note-by-number-markup (ly:duration-log dur)
                                                   (ly:duration-dot-count dur)
                                                   1))
                      #f))
-         (note-markup (if (and note-mark (number? count) (> count 0) )
+         (note-markup (if (and (not hide-note) (number? count) (> count 0) )
                         (make-concat-markup (list
                           (make-general-align-markup Y DOWN note-mark)
                           (make-simple-markup " ")
-                          (make-simple-markup  "=")
+                          (make-simple-markup "=")
                           (make-simple-markup " ")
                           (make-simple-markup (number->string count))))
-                        #f))
+                      #f))
          (text-markup (if (not (null? text))
                         (make-bold-markup text)
                         #f)))
     (if text-markup
-      (if note-markup
+      (if (and note-markup (not hide-note))
         (make-line-markup (list text-markup
           (make-concat-markup (list (make-simple-markup "(")
                                     note-markup
                                     (make-simple-markup ")")))))
-        (make-line-markup (list text-markup))
-      )
+        (make-line-markup (list text-markup)))
       (if note-markup
         (make-line-markup (list note-markup))
-        #f
-      )
-    )
-  )
-)
+        (make-null-markup)))))
 
 (define-public (format-mark-alphabet mark context)
   (make-bold-markup (make-markalphabet-markup (1- mark))))
@@ -82,7 +83,6 @@
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Bass figures.
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (define-public (format-bass-figure figure event context)
   (let* ((fig (ly:event-property event 'figure))
     ;;    (if (markup? fig-markup)
     ;; (set!
     ;;  fig-markup (markup #:translate (cons 1.0 0)
-    ;;                     #:hcenter fig-markup)))
+    ;;                     #:center-align fig-markup)))
 
     (if alt-markup
        (set! fig-markup
 
     ))
 
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; fret diagrams
 
                      ))
                  string-frets)
        (vector->list desc)))
+    
+  (define (get-predefined-fretboard predefined-fret-table tuning pitches)
+;   (_i "Search through @var{predefined-fret-table} looking for a predefined
+;fretboard with a key of @var{(tuning . pitches)}.  The search will check
+;both up and down an octave in order to accomodate transposition of the
+;chords.")
+   (define (get-fretboard key)
+    (let ((hash-handle
+           (hash-get-handle predefined-fret-table key)))
+     (if hash-handle
+         (cdr hash-handle)  ; return table entry
+         '())))
+
+   (let ((test-fretboard (get-fretboard (cons tuning pitches))))
+    (if (not (null? test-fretboard))
+        test-fretboard
+        (let ((test-fretboard 
+               (get-fretboard
+                (cons tuning (map (lambda (x) (shift-octave x 1)) pitches)))))
+         (if (not (null? test-fretboard))
+             test-fretboard
+             (get-fretboard 
+              (cons tuning (map (lambda (x) (shift-octave x -1)) pitches))))))))
 
 ;; body.
   (let*
               (acons 'string-count (length tunings) details)))
     (set! (ly:grob-property grob 'dot-placement-list)
         (if predefined-frets
-            (let ((hash-handle 
-                    (hash-get-handle
+            (let ((predefined-fretboard 
+                    (get-predefined-fretboard
                       predefined-frets
-                      (cons tunings pitches))))
-              (if hash-handle 
-                  (cdr hash-handle)  ;found default diagram
+                      tunings
+                      pitches)))
+              (if (null? predefined-fretboard)
                   (string-frets->dot-placement 
-                        string-frets my-string-count)))
+                        string-frets my-string-count)  ;no predefined diagram
+                  predefined-fretboard)) ;found default diagram
             (string-frets->dot-placement string-frets my-string-count)))))
 
 (define-public (determine-frets-mf notes string-numbers
   (define (note-pitch a)
     (ly:event-property a 'pitch))
 
-  (define (note-pitch<? a b)
-    (ly:pitch<? (note-pitch a)
-               (note-pitch b)))
+  (define (note-pitch>? a b)
+    (ly:pitch<? (note-pitch b)
+               (note-pitch a)))
 
   (define (note-finger ev)
     (let* ((articulations (ly:event-property ev 'articulations))
                           specified-frets))
                           
               )))
-   (sort notes note-pitch<?))
+   (sort notes note-pitch>?))
 
   string-fret-fingering-tuples)
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; tablature
+
+;; The TabNoteHead tablatureFormat callback.
+;; Compute the text grob-property
+(define-public (fret-number-tablature-format string context event)
+  (let* ((tuning (ly:context-property context 'stringTunings))
+        (pitch (ly:event-property event 'pitch))
+        (is-harmonic (apply
+                      functional-or
+                      (map
+                       (lambda (ev)
+                         (eq? 'harmonic-event (ly:event-property ev 'class)))
+                       (ly:event-property event 'articulations)))))
+
+    (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))))))))
+
+;; 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 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))))))))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; 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)