lilypond-devel
[Top][All Lists]
Advanced

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

Re: entering music without \time


From: Nicolas Sceaux
Subject: Re: entering music without \time
Date: Sat, 11 Sep 2004 11:48:24 +0200
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Erik Sandberg <address@hidden> writes:

> Given that {c16*2/3 c c c c c} can be interpreted both as \times 2/3 and as 
> \times 4/6, the only other thing I can see is to look at beaming. I.e., a 
> beamed group of 6 identically *2/3 notes will probably want a 6 over it 
> rather than a 3.

We cannot look at beaming too, it is not known at the time the music
expressions are processed. I used an other rule which finaly made it
possible to have =====6=====. 

> I understand that c1*4/3 is not a possibility. I mean that there just should 
> be some way to make the the tuplification ignore a note. Just in case someone 
> wants it. The typical use of tuplification is to apply it to a score; so if 
> there is one fraction somewhere that shouldn't be tuplified you will need 
> _something_. E.g. it would be enough with something like 
> \tuplify { ...
> \excludeFromTuplify {...}
> ...
> }

I don't know how to do that easily.
In the meantime, one can do: \tuplify { ... } R1*3/4 \tuplify { ... }

Besides that, do you think most real cases are covered?

A more general note/question:

I have been thinking about writing examples showing how to use more complex
music functions. This could be such an example. I also wrote a
\prelude function that can generate Bach's first prelude from Das
Wohltemperierte Clavier, like that:

\prelude { 
  c'   e'  g' c'' e'' 
  c'   d'  a' d'' f'' 
  b    d'  g' d'' f''
  ...
}

Do you (a general you) think that such articles could be useful?

nicolas

\version "2.3.13"
%% $Id: tuplefy.ly,v 1.2 2004/09/11 09:27:37 nicolas Exp $      

#(use-modules (srfi srfi-1))

#(define-public (music-duration music)
  "If `music' has a duration (for instance, a chord), return it;
otherwise, return #f"
  (cond ((member 'rhythmic-event (ly:music-property music 'types))
         (ly:music-property music 'duration))
        ((member 'event-chord (ly:music-property music 'types))
         (let ((dur-event (find (lambda (elt)
                                  (member 'rhythmic-event (ly:music-property 
elt 'types)))
                                (ly:music-property music 'elements))))
           (and dur-event (ly:music-property dur-event 'duration))))
        (else #f)))

#(define-public (tuplefy-sequence seq-music)
  (let ((current-tuple-numerator 1)
        (current-tuple-denominator 1)
        (current-tuple (list))
        (result-notes (list)))
    ;; push a non tuplet chord into the result
    (define (push-not-tuple elt)
      (push-current-tuple-group)
      (set! result-notes (cons elt result-notes)))
    ;; push a tuplet chord
    (define (push-tuple chord)
      (let* ((duration (music-duration chord))
             (length (ly:duration-log duration))
             (dot-count (ly:duration-dot-count duration))
             (dur-factor (ly:duration-factor duration))
             (num (car dur-factor))
             (den (cdr dur-factor)))
        (if (and (not (null? current-tuple))
                 (= num current-tuple-numerator)
                 (= den current-tuple-denominator))
            ;; a chord with same fraction than the previous chord
            ;; just push it in the tuplet accumulator
            (set! current-tuple (cons chord current-tuple))
            ;; otherwise, push the existing accumulator (if not empty) in the 
result
            ;; and start a new accumulator, storing the new fraction.
            (begin
              (push-current-tuple-group)
              (set! current-tuple-numerator num)
              (set! current-tuple-denominator den)
              (set! current-tuple (list chord))))))
    ;; push a tuplet group into the result
    (define (push-current-tuple-group)
      (if (not (null? current-tuple))
          (let* ((min-log (apply min (map ly:duration-log (remove null? (map 
(lambda (chord) (music-duration chord)) current-tuple)))))
                 (multiplier (max 1 (- (1+ min-log) current-tuple-denominator)))
                 (numerator   (* multiplier current-tuple-numerator))
                 (denominator (* multiplier current-tuple-denominator)))
            (set! result-notes (cons (make-music 'TimeScaledMusic
                                                 'denominator denominator
                                                 'numerator numerator
                                                 'element (make-music 
'SequentialMusic 'elements (reverse! current-tuple)))
                                     result-notes))
            (set! current-tuple (list)))))
    ;; body
    (map (lambda (music)
           (if (member 'sequential-music (ly:music-property music 'types))
               (begin
                 ;; a inner sequential music
                 (push-current-tuple-group)
                 (set! result-notes (cons (tuplefy-sequence music) 
result-notes)))
               (let ((duration (music-duration music)))
                 (if (and duration
                          (not (= 1 (cdr (ly:duration-factor duration)))))
                     ;; a tuple
                     (push-tuple music)
                     ;; not a tuple
                     (push-not-tuple music)))))
         (ly:music-property seq-music 'elements))
    (push-current-tuple-group)
    (make-music 'SequentialMusic 'elements (reverse! result-notes))))


tuplefy = #(def-music-function (location music) (ly:music?)
            (tuplefy-sequence music))

\score {
    \context StaffGroup <<
        \new Staff \relative c' {
            #(override-auto-beam-setting '(end * * * *) 1 4 'Staff)
            \set tupletSpannerDuration = #(ly:make-moment 1 4) 
            \tuplefy { 
                c4 
                c8*2/3 d16*2/3 e d8*2/3
                d8*4/6 e16*4/6 f e8*4/6
                { f8*2/3 g16*2/3 a g8*2/3 }
                { c16*4/6 d e f e d c d e f e d }
                c2
            }
        }
        \new Staff \relative c' {
            #(override-auto-beam-setting '(end * * * *) 1 4 'Staff)
            \set tupletSpannerDuration = #(ly:make-moment 1 4)
            c4
            \times 2/3 { c8 d16 e d8 }
            \times 4/6 { d8 e16 f e8 }
            \times 2/3 { f8 g16 a g8 }
            \times 4/6 { c16 d e f e d c d e f e d }
            c2
        }
    >>
}



reply via email to

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