lilypond-user
[Top][All Lists]
Advanced

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

Re: rhythm template function


From: Jay Anderson
Subject: Re: rhythm template function
Date: Sat, 24 May 2008 21:22:41 -0700

Whoops, you're right. I should have tested that. I'm betting that
there is an easier way to do this (Something more like the staccato
snippet http://lsr.dsi.unimi.it/LSR/Snippet?id=82). I'll hopefully get
a chance to mess with it a bit more this weekend (Memorial day on
Monday here in the US). Thanks.

-----Jay

On Thu, May 22, 2008 at 5:28 AM, Alard de Boer <address@hidden> wrote:
> On Thu, May 22, 2008 at 5:09 AM, Jay Anderson <address@hidden> wrote:
>> "Easy Rhythm Template Creation" added to the lsr. Thanks.
>>
>> -----Jay
>
> Hi Jay,
>
> I had some trouble getting tuplets to work with your snippet. Here's a 
> modified
> version that checks whether a tuplet (TimeScaledMusic) is used in the 
> template,
> and handles that case separately; see function make-chord-or-tuplet. I'm not
> very good with Scheme, perhaps there is an easier way to do this?
>
> Thanks again,
> Alard.
>
> ---
> \version "2.11.46"
>
> %Rhythm template stuff
> #(define (create-note pitch duration)
>  (make-music 'NoteEvent
>    'duration duration
>    'pitch pitch))
>
> #(define (make-chord chord-pitches chordevent)
>  (let* ((skip (car (ly:music-property chordevent 'elements)))
>        (rest (cdr (ly:music-property chordevent 'elements)))
>        (duration (ly:music-property skip 'duration)))
>   (if (eq? (ly:music-property skip 'name) 'SkipEvent)
>     (make-music 'EventChord
>       'elements (append
>                   (map (lambda (x) (create-note x duration)) chord-pitches)
>                   rest))
>     chordevent)))
>
> #(define (make-chord-or-tuplet pitches event)
>  (if (eq? (ly:music-property event 'name) 'TimeScaledMusic)
>   (make-music
>    'TimeScaledMusic
>    'denominator (ly:music-property event 'denominator)
>    'numerator (ly:music-property event 'numerator)
>    'element (make-music
>              'SequentialMusic
>              'elements (make-rhythm
>                         pitches
>                         (ly:music-property
>                          (ly:music-property event 'element) 'elements))))
>   (make-chord pitches event)))
>
> #(define (make-rhythm pitches template)
>  (cond ((null? template) '())
>       ((ly:pitch? (car pitches))
>         (cons
>           (make-chord-or-tuplet pitches (car template))
>           (make-rhythm pitches (cdr template))))
>       (else
>         (cons
>           (make-chord-or-tuplet (car pitches) (car template))
>           (make-rhythm (cadr pitches) (cdr template))))))
>
> % Returns two pitches from the input:
> %  ( <The original pitch(es)>
> %    <The pitch(es) in octave '-1'> )
> % This makes the function work in \relative sections
> % To make it work outside of \relative only return p.
> #(define (get-pitches mus)
>  (let* ((p (map
>             (lambda (x) (ly:music-property x 'pitch))
>             (ly:music-property mus 'elements)))
>        (first-p (car p))
>        (pitch (ly:pitch-notename first-p))
>        (alteration (ly:pitch-alteration first-p))
>        (octave -1)
>        (px (ly:make-pitch octave pitch alteration)))
>   (list p (cons px (cdr p)))))
>
> #(define (rhythm-template template)
>  (define-music-function (parser location mus) (ly:music?)
>   (make-music
>     'SequentialMusic
>     'elements (make-rhythm
>                 (get-pitches mus)
>                 (ly:music-property template 'elements)))))
>
> %Example usage:
> %These methods should only be used within a \relative section.
> rhya = #(rhythm-template #{s8.-> s16 s8#} )
> rhyb = #(rhythm-template #{s8[ r16 s16 s8]#} )
> rhyc = #(rhythm-template #{s16 s~ s4#} )
>
> rhyd = #(rhythm-template #{ \times 2/3 { s8 s8 s8 } s4 s4 s8 s8 s4 #} )
> rhye = #(rhythm-template #{
>    \times 2/3 { s8---\pp s8-- s8-- } s4-- s4-- s8-- s8-- s4-- #} )
>
> \score
> {
>  \new Staff \relative c'
>  {
>   \time 6/8
>   \rhya c \rhyb c |
>   \rhya <c e> \rhyb <c f> |
>   \rhyc <c e> \rhyc <c d> |
>   \time 5/4
>   \rhyd c
>   \rhyd e
>   \rhye <c e g>
>  }
> }
>
>
> --
> Groeten,
> Alard.
>
> Ceterum censeo MS Word esse delendam.
>




reply via email to

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