]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/translation-functions.scm
Merge remote branch 'origin' into HEAD
[lilypond.git] / scm / translation-functions.scm
index 6a23c4124f0ed7cd4f8d2443e72468b894b4e6aa..2dd8d2d92c8ac06aa1beee75fa124b32351eff4f 100644 (file)
@@ -1,6 +1,6 @@
 ;;;; This file is part of LilyPond, the GNU music typesetter.
 ;;;;
-;;;; (c) 1998--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
+;;;; (c) 1998--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
 ;;;;                Jan Nieuwenhuizen <janneke@gnu.org>
 ;;;;
 ;;;; LilyPond is free software: you can redistribute it and/or modify
@@ -276,6 +276,10 @@ dot placement entries."
 along with @var{minimum-fret}, @var{maximum-stretch}, and
 @var{tuning}.  Returns a list of @code{(string fret finger) lists."
 
+
+    (define restrain-open-strings (ly:context-property context
+                                                      'restrainOpenStrings
+                                                      #f))
     (define specified-frets '())
     (define free-strings (iota (length tuning) 1))
 
@@ -296,7 +300,7 @@ if no fingering is present."
        (map (lambda (art)
               (let* ((num (ly:event-property art 'digit)))
 
-                (if (and (eq? 'fingering-event (ly:event-property art 'class))
+                (if (and (ly:in-event-class? art 'fingering-event)
                          (number? num)
                          (> num 0))
                   (set! finger-found num))))
@@ -326,6 +330,8 @@ if no string-number is present."
          #t
          (map (lambda (specced-fret)
                 (or (eq? 0 specced-fret)
+                    (and (not restrain-open-strings)
+                    (eq? 0 fret))
                     (>= maximum-stretch (abs (- fret specced-fret)))))
               specified-frets))))
 
@@ -333,7 +339,9 @@ if no string-number is present."
       "Can @var{pitch} be played on @var{string}, given already placed
 notes?"
       (let* ((fret (calc-fret pitch string tuning)))
-       (and (>= fret minimum-fret)
+       (and (or (and (not restrain-open-strings)
+                     (eq? fret 0))
+                (>= fret minimum-fret))
             (close-enough fret))))
 
     (define (open-string string pitch)
@@ -657,3 +665,39 @@ only ~a fret labels provided")
   (= 0 (modulo count n)))
 
 (define-public (all-repeat-counts-visible count context) #t)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; make-engraver helper macro
+
+(defmacro-public make-engraver forms
+  "Helper macro for creating Scheme engravers.
+
+The usual form for an engraver is an association list (or alist)
+mapping symbols to either anonymous functions or to another such
+alist.
+
+@code{make-engraver} accepts forms where the first element is either
+an argument list starting with the respective symbol, followed by the
+function body (comparable to the way @code{define} is used for
+defining functions), or a single symbol followed by subordinate forms
+in the same manner.  You can also just make an alist pair
+literally (the @samp{car} is quoted automatically) as long as the
+unevaluated @samp{cdr} is not a pair.  This is useful if you already
+have defined your engraver functions separately.
+
+Symbols mapping to a function would be @code{initialize},
+@code{start-translation-timestep}, @code{process-music},
+@code{process-acknowledged}, @code{stop-translation-timestep}, and
+@code{finalize}.  Symbols mapping to another alist specified in the
+same manner are @code{listeners} with the subordinate symbols being
+event classes, and @code{acknowledgers} and @code{end-acknowledgers}
+with the subordinate symbols being interfaces."
+  (let loop ((forms forms))
+    (if (cheap-list? forms)
+       `(list
+         ,@(map (lambda (form)
+                  (if (pair? (car form))
+                      `(cons ',(caar form) (lambda ,(cdar form) ,@(cdr form)))
+                      `(cons ',(car form) ,(loop (cdr form)))))
+                forms))
+       forms)))