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: Wed, 08 Sep 2004 14:05:04 +0200
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Erik Sandberg <address@hidden> writes:

> On Friday 03 September 2004 23.41, Nicolas Sceaux wrote:
>> what I've started to look at is something like that:
>>
>> \tupletify { c8 c8*2/3 c c c8 c8*4/5 c16*4/5 c  c4*2/6}
>> ==>
>> { c8 \tuplet 2/3 { c8 c c } c8 \tuplet 4/5 { c8 c16 c }  \tuplet 2/6 { c4 }
>> }
>>
>> is this ok?
>
> This is just about perfect! (except \tuplet should be \times :) )
>
> Some small questions though:
> 1. What will it do about strange multipliers, like:
> { c8*2/3 c8*1*2/3 c8*4/3*1/2 c8*2 }
> In my opinion, it would be sensible to just ignore strange multipliers and 
> turn it into something like
> { \times 2/3 {c8} c8*1*2/3 c8*4/3*1/2 c8*2 }
>
> One could reason that c8*2 should be turned into \times 2 {c8}. But IMHO this 
> notation is so rare anyways; and in most of the cases integer multiplication 
> occur (such as in R1*20) you don't want tuplet notation. so I suggest that 
> c8*2 is left untouched by the tupletifier.
>
> 2. What about grace notes? Will this work?
> \tupletify { c8*2/3 \grace c16*2/3 c8*2/3 c }
> =>
> \times 2/3 { c8 \grace c16 c8 c}
>
> 3. Does anyone have a better word than tupletify?
>
> Erik

hm.
Here is a first trial. 
After the music has been parsed, there is no distinction between *2/3
and *4/6, so

    3                       6
 ------- is ok whereas =========== is not.
 |  |  |               | | | | | |

Thus, I'm not sure that such a limited function is really useful.

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

#(define-public (mus: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 (mus: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))
          (begin
            (set! result-notes (cons (make-music 'TimeScaledMusic
                                                 'denominator 
current-tuple-denominator
                                                 'numerator 
current-tuple-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 (mus:duration music)))
                 (if (and duration
                          (not (= 1 (car (ly:duration-factor 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' {
            %\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
                c4
                c2
            }
        }
        \new Staff \relative c' {
            %\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 }
            c4
            c2
        }
    >>
}


nicolas

reply via email to

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