]> git.donarmstrong.com Git - lilypond.git/blobdiff - scm/ly-syntax-constructors.scm
Doc: rename section in LM (3280)
[lilypond.git] / scm / ly-syntax-constructors.scm
index 0fe9aa0f7839db0d37f05debac77f4bf63f4a63d..7817ec25c5ddee138681eed94ca77b5ec8f3490c 100644 (file)
@@ -1,6 +1,6 @@
 ;;;; This file is part of LilyPond, the GNU music typesetter.
 ;;;;
-;;;; Copyright (C) 2006--2011 Erik Sandberg <mandolaerik@gmail.com>
+;;;; Copyright (C) 2006--2012 Erik Sandberg <mandolaerik@gmail.com>
 ;;;;
 ;;;; LilyPond is free software: you can redistribute it and/or modify
 ;;;; it under the terms of the GNU General Public License as published by
@@ -18,7 +18,7 @@
 ;; TODO: use separate module for syntax
 ;; constructors. Also create wrapper around the constructor?
 (defmacro define-ly-syntax (args . body)
-  `(define-public ,args ,(cons 'begin body)))
+  `(define-public ,args ,@body))
 
 ;; A ly-syntax constructor takes two extra parameters, parser and
 ;; location. These are mainly used for reporting errors and
 ;; we don't call the function but rather return the general
 ;; fallback.
 (define-ly-syntax (music-function parser loc fun args . rest)
-  (let* ((sig (object-property fun 'music-function-signature))
+  (let* ((sig (ly:music-function-signature fun))
         (pred (if (pair? (car sig)) (caar sig) (car sig)))
         (good (proper-list? args))
-        (m (and good (apply fun parser loc (reverse! args rest)))))
+        (m (and good (apply (ly:music-function-extract fun)
+                            parser loc (reverse! args rest)))))
     (if (and good (pred m))
        (begin
          (if (ly:music? m)
 into a @code{MultiMeasureTextEvent}."
 
   (if (memq 'script-event (ly:music-property music 'types))
-      (let* ((location (ly:music-property music 'origin))
-            (dir (ly:music-property music 'direction))
-            (tags (ly:music-property music 'tags))
-            (p (make-music 'MultiMeasureTextEvent
-                           'origin location
-                           'tags tags
-                           'text (ly:music-property music 'text))))
-       (if (ly:dir? dir)
-           (set! (ly:music-property p 'direction) dir))
-       p)
+      (apply make-music 'MultiMeasureTextEvent
+            (flatten-alist (ly:music-mutable-properties music)))
       music))
 
 (define-ly-syntax (multi-measure-rest parser location duration articulations)
@@ -158,10 +151,10 @@ into a @code{MultiMeasureTextEvent}."
              'duration duration
              'origin location))
 
-(define-ly-syntax (repetition-chord parser location previous-chord repetition-function duration articulations)
-  (make-music 'RepeatedChord
-             'original-chord previous-chord
-             'element (repetition-function previous-chord location duration articulations)
+(define-ly-syntax (repetition-chord parser location duration articulations)
+  (make-music 'EventChord
+             'duration duration
+             'elements articulations
              'origin location))
 
 (define-ly-syntax-simple (context-specification type id ops create-new mus)
@@ -171,6 +164,33 @@ into a @code{MultiMeasureTextEvent}."
     (if create-new (set! (ly:music-property csm 'create-new) #t))
     csm))
 
+(define-ly-syntax (composed-markup-list parser location commands markups)
+;; `markups' being a list of markups, eg (markup1 markup2 markup3),
+;; and `commands' a list of commands with their scheme arguments, in reverse order,
+;; eg: ((italic) (raise 4) (bold)), maps the commands on each markup argument, eg:
+;;  ((bold (raise 4 (italic markup1)))
+;;   (bold (raise 4 (italic markup2)))
+;;   (bold (raise 4 (italic markup3))))
+
+  (define (compose arg)
+    (fold
+     (lambda (cmd prev) (append cmd (list prev)))
+     arg
+     commands))
+  (let loop ((markups markups) (completed '()))
+    (cond ((null? markups) (reverse! completed))
+          ((markup? (car markups))
+           (loop (cdr markups)
+                 (cons (compose (car markups)) completed)))
+          (else
+           (call-with-values
+               (lambda () (break! markup? markups))
+             (lambda (complex rest)
+               (loop rest
+                     (reverse!
+                      (make-map-markup-commands-markup-list
+                       compose complex) completed))))))))
+
 (define-ly-syntax (property-operation parser location ctx music-type symbol . args)
   (let* ((props (case music-type
                  ((PropertySet) (list 'value (car args)))