lilypond-user
[Top][All Lists]
Advanced

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

Re: Separating pitch and rhythm


From: Janek Warchoł
Subject: Re: Separating pitch and rhythm
Date: Sun, 25 Mar 2012 22:43:44 +0200

David,

On Wed, Mar 21, 2012 at 7:54 PM, David Kastrup <address@hidden> wrote:
>
> Possibly this mail got lost, so I rewrite it (code is somewhat different).
>
> Siska Ádám <address@hidden> writes:
>
>> Dear List,
>>
>>
>> is there an effective way to separate the pitches and the rhythms in a
>> voice? I'm thinking about something like defining a variable
>> consisting only of rhythms:
>>
>> Rhythm = {
>>       \time 4/4
>>       4 4 4. 8
>>       8 8 4 4 8 8
>>       2 4 8 8 ...
>> }
>>
>> and then apply this to different sequences of pitches:
>>
>> Seq1 = {
>>       \clef treble
>>       c d e f
>>       g a g f e d
>>       c e g c ...
>> }
>>
>> Seq2 = {
>>       \clef bass
>>       c b a g
>>       f e f g a b
>>       c g e c ...
>> }
>
> #(define-public (for-some-music stop? music)
>  "Walk through @var{music}, process all elements calling @var{stop?}
> and only recurse if this returns @code{#f}."
>  (let loop ((music music))
>    (if (not (stop? music))
>       (let ((elt (ly:music-property music 'element)))
>         (if (ly:music? elt)
>             (loop elt))
>         (for-each loop (ly:music-property music 'elements))
>         (for-each loop (ly:music-property music 'articulations))))))
>
> #(define (extract-all-durations music)
>   (map! (lambda (m) (ly:music-property m 'duration))
>         (extract-music music
>                        (lambda (m) (ly:duration?
>                                      (ly:music-property m 'duration))))))
>
> applyRhythm =
> #(define-music-function (parser location p r)
>  (ly:music? ly:music?)
>    (let ((l (extract-all-durations r)))
>      (for-some-music
>        (lambda (m)
>          (or (null? l)
>              (and (ly:duration? (ly:music-property m 'duration))
>                   (begin
>                     (set! (ly:music-property m 'duration) (car l))
>                     (set! l (cdr l))
>                     #t))))
>        p))
>  p)
>
> Rhythm = {
>        s4 s4 s4. s8
>        s8 s8 s4 s4 s8 s8
>        s2 s4 s8 s8
> }
>
> SeqI = {
>        \clef treble
>        c d e f
>        g a g f e d
>        c e g c
> }
>
> SeqII = {
>        \clef bass
>        c b a g
>        f e f g a b
>        c g e c
> }
>
> \new PianoStaff
> << \new Staff \applyRhythm \SeqI \Rhythm
>   \new Staff \applyRhythm \SeqII \Rhythm
>>>

Thanks for this!  I'll keep it bookmarked.

Janek



reply via email to

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