]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/music-functions.scm
* Documentation/topdocs/NEWS.texi (Top): add quarter tones.
[lilypond.git] / scm / music-functions.scm
index 50a0dd8160dde4dad85680e6faf019a4d59f698b..4ee3dfe0b5b36b7a2ad62c0bcdcbda5a5553162c 100644 (file)
@@ -1,4 +1,3 @@
-
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 (define-public (music-map function music)
        (function music)
        ))
 
+(define-public (music-filter pred? music)
+  "Filter out music expressions that do not satisfy PRED."
+  
+  (define (inner-music-filter pred? music)
+    "Recursive function."
+    (let* ((es (ly:get-mus-property music 'elements))
+          (e (ly:get-mus-property music 'element))
+          (as (ly:get-mus-property music 'articulations))
+          (filtered-as (filter ly:music? (map (lambda (y) (inner-music-filter pred? y)) as)))
+          (filtered-e (if (ly:music? e)
+                          (inner-music-filter pred? e)
+                          e))
+          (filtered-es (filter ly:music? (map (lambda (y) (inner-music-filter pred? y)) es)))
+          )
+
+      (ly:set-mus-property! music 'element filtered-e)
+      (ly:set-mus-property! music 'elements filtered-es)
+      (ly:set-mus-property! music 'articulations filtered-as)
+
+      ;; if filtering emptied the expression, we remove it completely.
+      (if (or (pred? music)
+             (and (eq? filtered-es '()) (not (ly:music? e))
+                  (or (not (eq? es '()))
+                      (ly:music? e))))
+         (set! music '()))
+      
+      music))
+
+  (set! music (inner-music-filter pred? music))
+  (if (ly:music? music)
+      music
+      (make-music-by-name 'Music)      ;must return music.
+      ))
+
+(define-public (remove-tag tag)
+  (lambda (mus)
+    (music-filter
+     (lambda (m)
+       (let* ((tags (ly:get-mus-property m 'tags))
+             (res (memq tag tags)))
+       res)) mus)))
+
 (define-public (display-music music)
   "Display music, not done with music-map for clarity of presentation."
   (display music)
@@ -204,9 +245,7 @@ i.e.  this is not an override"
 
 (define-public (make-apply-context func)
   (let*
-      (
-       (m (make-music-by-name 'ApplyContext))
-       )
+      ((m (make-music-by-name 'ApplyContext)))
 
     (ly:set-mus-property! m 'procedure func)
     m
@@ -320,9 +359,7 @@ a property set for MultiMeasureRestNumber."
 
 (define-public (make-ottava-set octavation)
   (let*
-      (
-       (m (make-music-by-name 'ApplyContext))
-       )
+      ((m (make-music-by-name 'ApplyContext)))
     
   
   (define (ottava-modify context)
@@ -336,7 +373,7 @@ and set OTTAVATION to `8va', or whatever appropriate."
                ((where (ly:context-property-where-defined context 'centralCPosition))
                 (oc0 (ly:get-context-property context 'originalCentralCPosition)))
 
-             (ly:set-context-property context 'centralCPosition oc0)
+             (ly:set-context-property! context 'centralCPosition oc0)
              (ly:unset-context-property where 'originalCentralCPosition)
              (ly:unset-context-property where 'ottavation))
 
@@ -351,14 +388,14 @@ and set OTTAVATION to `8va', or whatever appropriate."
                                              (-1 . "8va bassa")
                                              (-2 . "15ma bassa"))))))
 
-             (ly:set-context-property context 'centralCPosition new-c0)
-             (ly:set-context-property context 'originalCentralCPosition c0)
-             (ly:set-context-property context 'ottavation string)
+             (ly:set-context-property! context 'centralCPosition new-c0)
+             (ly:set-context-property! context 'originalCentralCPosition c0)
+             (ly:set-context-property! context 'ottavation string)
              
              ))))
 
   (ly:set-mus-property! m 'procedure  ottava-modify)
-  (context-spec-music m "Staff")
+  (context-spec-music m 'Staff)
   ))
 
 (define-public (set-octavation ottavation)
@@ -383,7 +420,7 @@ Rest can contain a list of beat groupings
        (basic  (list set1 set2 set3 set4)))
 
     (context-spec-music
-     (make-sequential-music basic) "Timing")))
+     (make-sequential-music basic) 'Timing)))
 
 (define-public (set-time-signature num den . rest)
   (ly:export (apply make-time-signature-set `(,num ,den . ,rest))))
@@ -450,7 +487,7 @@ Rest can contain a list of beat groupings
                (make-voice-props-set number)
                (make-simultaneous-music (car lst))))
 
-             "Voice"  (number->string number))
+             'Voice  (number->string number))
              (voicify-list (cdr lst) (+ number 1))
        ))
    )
@@ -458,8 +495,7 @@ Rest can contain a list of beat groupings
 (define (voicify-chord ch)
   "Split the parts of a chord into different Voices using separator"
    (let* ((es (ly:get-mus-property ch 'elements)))
-
-
+     
      (ly:set-mus-property!  ch 'elements
        (voicify-list (split-list es music-separator?) 0))
      ch
@@ -501,6 +537,9 @@ Rest can contain a list of beat groupings
     ;;(eq? #t (ly:get-grob-property elt symbol))
     (not (eq? #f (memq symbol (ly:get-grob-property elt 'interfaces))))))
 
+(define-public ((outputproperty-compatibility func sym val) grob g-context ao-context)
+  (if (func grob)
+      (ly:set-grob-property! grob sym val)))
 
 ;;
 (define-public (smart-bar-check n)
@@ -569,15 +608,91 @@ Rest can contain a list of beat groupings
      music
      )
 
+
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; switch it on here, so parsing and init isn't checked (too slow!)
+;;
+;; setting stuff for grace context.
+;;
 
+(define (vector-extend v x)
+  "Make a new vector consisting of V, with X added to the end."
+  (let*
+      ((n (vector-length v))
+       (nv (make-vector (+ n 1) '())))
+
+    
+    (vector-move-left! v 0 n nv 0)
+    (vector-set! nv n x)
+    nv))
+
+
+(define (vector-map f v)
+  "Map  F over V. This function returns nothing."
+  (do
+      ((n (vector-length v))
+       (i 0 (+ i 1)))
+      ((>= i n))
+  
+    (f (vector-ref v i))))
+
+(define (vector-reverse-map f v)
+  "Map  F over V, N to 0 order. This function returns nothing."
+  (do
+      ((i (- (vector-length v) 1) (- i 1)))
+      ((< i 0))
+  
+    (f (vector-ref v i))))
+
+;; TODO:  make a remove-grace-property too.
+(define-public (add-grace-property context-name grob sym val)
+  "Set SYM=VAL for GROB in CONTEXT-NAME. "
+  (define (set-prop context)
+    (let*
+       ((where (ly:context-property-where-defined context 'graceSettings))
+        (current (ly:get-context-property where 'graceSettings))
+        (new-settings (vector-extend current (list context-name grob sym val)))
+        )
+      (ly:set-context-property! where 'graceSettings new-settings)))
+    
+    (ly:export (context-spec-music (make-apply-context set-prop) 'Voice)))
+
+
+(define-public (set-start-grace-properties context)
+  (define (execute-1 x)
+    (let*
+       ((tr (ly:translator-find context (car x))))
+
+      (if (ly:context? tr)
+         (ly:context-pushpop-property tr (cadr x) (caddr x) (cadddr x))
+         )))
+  
+  (let*
+      ((props (ly:get-context-property context 'graceSettings)))
+    (if (vector? props)
+       (vector-map execute-1 props))))
+
+(define-public (set-stop-grace-properties context)
+  (define (execute-1 x)
+    (let*
+       ((tr (ly:translator-find context (car x))))
+      (if (ly:context? tr)
+         (ly:context-pushpop-property tr (cadr x) (caddr x))
+         )))
+  
+  (let*
+      ((props (ly:get-context-property context 'graceSettings)))
+    (if (vector? props)
+       (vector-reverse-map execute-1 props))))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; switch it on here, so parsing and init isn't checked (too slow!)
+;;
 ;; automatic music transformations.
 
 (define (switch-on-debugging m)
   (set-debug-cell-accesses! 15000)
-  m
-  )
+  m)
 
 (define-public toplevel-music-functions
   (list check-start-chords