lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: parallel versus series scoring


From: Nicolas Sceaux
Subject: Re: parallel versus series scoring
Date: Sun, 22 Jan 2006 18:02:19 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin)

Han-Wen Nienhuys <address@hidden> writes:

> As final finish, something should be  added to the
> process-toplevel-music hook so that you can make it ignore the result
> of \parallelMusic. Maybe set a #'void property in the returned value,
> and
> ignore a music expression  with #'void in
>
>    collect-music-for-book

Here is a patch, doing what you described above:

Index: ly/music-functions-init.ly
===================================================================
RCS file: /cvsroot/lilypond/lilypond/ly/music-functions-init.ly,v
retrieving revision 1.44
diff -u -r1.44 music-functions-init.ly
--- ly/music-functions-init.ly  18 Jan 2006 13:46:55 -0000      1.44
+++ ly/music-functions-init.ly  22 Jan 2006 16:56:18 -0000
@@ -310,6 +310,90 @@
       (list chain-grob-member-functions `(,cons 0 0))
       (check-slope-callbacks comp))))))
     
+parallelMusic =
+#(def-music-function (parser location voice-ids music) (list? ly:music?)
+  "Define parallel music sequences, separated by '|' (bar check signs),
+and assign them to the identifiers provided in @var{voice-ids}.
 
address@hidden: a list of music identifiers (symbols containing only letters)
 
address@hidden: a music sequence, containing BarChecks as limiting expressions.
 
+Example:
+  \\parallelMusic #'(A B C) {
+    c c | d d | e e |
+    d d | e e | f f |
+  }
+<==>
+  A = { c c | d d | }
+  B = { d d | e e | }
+  C = { e e | f f | }
+"
+  (let* ((voices (apply circular-list (make-list (length voice-ids) (list))))
+         (current-voices voices)
+         (current-sequence (list)))
+    ;;
+    ;; utilities
+    (define (push-music m)
+      "Push the music expression into the current sequence"
+      (set! current-sequence (cons m current-sequence)))
+    (define (change-voice)
+      "Stores the previously built sequence into the current voice and
+       change to the following voice."
+      (list-set! current-voices 0 (cons (make-music 'SequentialMusic 
+                                         'elements (reverse! current-sequence))
+                                        (car current-voices)))
+      (set! current-sequence (list))
+      (set! current-voices (cdr current-voices)))
+    (define (bar-check? m)
+      "Checks whether m is a bar check."
+      (eq? (ly:music-property m 'name) 'BarCheck))
+    (define (music-origin music)
+      "Recursively search an origin location stored in music."
+      (cond ((null? music) #f)
+            ((not (null? (ly:music-property music 'origin)))
+             (ly:music-property music 'origin))
+            (else (or (music-origin (ly:music-property music 'element))
+                      (let ((origins (remove not (map music-origin 
+                                                      (ly:music-property music 
'elements)))))
+                        (and (not (null? origins)) (car origins)))))))
+    ;;
+    ;; first, split the music and fill in voices
+    (map-in-order (lambda (m)
+                    (push-music m)
+                    (if (bar-check? m) (change-voice)))
+                  (ly:music-property music 'elements))
+    (if (not (null? current-sequence)) (change-voice))
+    ;; un-circularize `voices' and reorder the voices
+    (set! voices (map-in-order (lambda (dummy seqs)
+                                 (reverse! seqs))
+                               voice-ids voices))
+    ;;
+    ;; set origin location of each sequence in each voice
+    ;; for better type error tracking
+    (for-each (lambda (voice)
+                (for-each (lambda (seq)
+                            (set! (ly:music-property seq 'origin)
+                                  (or (music-origin seq) location)))
+                          voice))
+              voices)
+    ;;
+    ;; check sequence length
+    (apply for-each (lambda (. seqs)
+                      (let ((moment-reference (ly:music-length (car seqs))))
+                        (for-each (lambda (seq moment)
+                                    (if (not (equal? moment moment-reference))
+                                        (ly:music-message seq 
+                                         "Bars in parallel music don't have 
the same length")))
+                          seqs (map-in-order ly:music-length seqs))))
+           voices)
+   ;;
+   ;; bind voice identifiers to the voices
+   (map (lambda (voice-id voice)
+          (ly:parser-define! parser voice-id 
+                             (make-music 'SequentialMusic 
+                               'origin location
+                               'elements voice)))
+        voice-ids voices))
+ ;; Return an empty sequence. this function is actually a "void" function.
+ (make-music 'SequentialMusic 'void #t))
\ No newline at end of file
Index: scm/define-music-properties.scm
===================================================================
RCS file: /cvsroot/lilypond/lilypond/scm/define-music-properties.scm,v
retrieving revision 1.47
diff -u -r1.47 define-music-properties.scm
--- scm/define-music-properties.scm     6 Jan 2006 09:13:23 -0000       1.47
+++ scm/define-music-properties.scm     22 Jan 2006 16:56:19 -0000
@@ -108,6 +108,8 @@
 engraver this music expression is processed.")
      (value ,scheme? "Assignment value for a
 translation property")
+     (void ,boolean? "If this property is #t, then the music expression is to 
be
+discarded by the toplevel music handler.")
      (what ,symbol? "What to change for auto-change. FIXME, naming")
      (part-combine-status ,symbol?
                          "Change to what kind of state? Options are
Index: scm/lily-library.scm
===================================================================
RCS file: /cvsroot/lilypond/lilypond/scm/lily-library.scm,v
retrieving revision 1.53
diff -u -r1.53 lily-library.scm
--- scm/lily-library.scm        6 Jan 2006 09:13:23 -0000       1.53
+++ scm/lily-library.scm        22 Jan 2006 16:56:19 -0000
@@ -75,7 +75,10 @@
   (ly:make-score music))
 
 (define-public (collect-music-for-book parser music)
-  (collect-scores-for-book parser (scorify-music music parser)))
+  ;; discard music if its 'void property is true.
+  (let ((void-music (ly:music-property music 'void)))
+    (if (or (null? void-music) (not void-music))
+        (collect-scores-for-book parser (scorify-music music parser)))))
 
 
 (define-public (print-book-with-defaults parser book)
Index: scm/music-functions.scm
===================================================================
RCS file: /cvsroot/lilypond/lilypond/scm/music-functions.scm,v
retrieving revision 1.159
diff -u -r1.159 music-functions.scm
--- scm/music-functions.scm     12 Jan 2006 00:52:29 -0000      1.159
+++ scm/music-functions.scm     22 Jan 2006 16:56:19 -0000
@@ -603,7 +603,7 @@
                 (equal? (ly:music-property x 'name) 'RequestChord))
               elts)))
 
-(define (ly:music-message music msg)
+(define-public (ly:music-message music msg)
   (let ((ip (ly:music-property music 'origin)))
     (if (ly:input-location? ip)
        (ly:input-message ip msg)
nicolas

reply via email to

[Prev in Thread] Current Thread [Next in Thread]