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: Sat, 21 Jan 2006 18:57:52 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (darwin)

Han-Wen Nienhuys <address@hidden> writes:

> Why not do
>
>   \parMusic #'(A B C)  { c | e | g  | d | f | a}
>
> which expands to  { }, and defines the following vars in the parser
>
>    A = { c d }
>    B = { e f }
>    C = { g a }
>
> then, the user can decide for himself how to structure A B and C.

Another attempt. I had to make ly:music-message public first (in
scm/music-functions.scm). BTW, I may be missing something obvious for
getting music expression origin locations (see music-origin
below). Also, i have problem expressing syntheticaly a documentation
string for that function. Finally, what should be the function's name?

nicolas

\version "2.7.27"
#(use-modules (srfi srfi-1))

parallelMusic = 
#(def-music-function (parser location voice-ids music) (list? ly:music?)
  " doc string: TODO "
  (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 searches 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 dispatch the sequences to the different 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 sequences
    (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))

\parallelMusic #'(voiceA voiceB voiceC)
 {
  \time 4/4 
  g' g' g' g' |
  e' e' e' e' |
  c' c' c' c' |
%% a quater note is missing in the third voice
%% \time 3/4 is added because such music expression does not have a
%% origin property. An accurate location should be pointed out
%% to the user nevertheless
  \time 3/4 a' a' a' | fis' fis' fis' | \time 3/4  d' d' | 
%%
  \time 2/4 
  b'   b'   c'' c'' |
  gis' gis' a'  a' |
  e'   e'   f'  f' |
}

\new StaffGroup <<
  \new Staff \voiceA
  \new Staff \voiceB
  \new Staff \voiceC
>>




reply via email to

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