[Top][All Lists]

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

music functions: how to translate "user-durations" in ly:durations

From: Michael Meixner
Subject: music functions: how to translate "user-durations" in ly:durations
Date: Thu, 15 Jun 2006 20:52:51 +0200

Here is the music-function I built with some help by Scheme-meister Nicolas. I will try to write a short tutorial for the docs while memory of a struggling beginner is still fresh. Could some of the wise take a look, just to check I didn't
complicate things unnecessarily?

Moreover I would like to change the input to the function to be more LilyPond-like.
Right now the input is in the format:
        % dotted eigths:
                        \squashDurations #8 #1 {}

I would prefer:
        % dotted eigths:
                        \squashDurations "8." {}

My first guess was, that I would have to write some string-mangling Scheme to translate this to the proper (ly:make-duration (...something...)), but maybe there is
a function for this already, something named parser-etc. or so?
(I searched a lot, but didn't know exactly where to look...)

Thanks for any hints

% ****************************************************************
% Start cut-&-pastable-section
% ****************************************************************

\version "2.9.8"

% Make a music function which sets all notes (chords) to the same duration:

squashDurations =
#(define-music-function (parser location dur dots music)
                                                (number? number? ly:music?)
        "Sets all durations in music to dur / (number of) dots"

        ;; Define a function "setDuration" which sets
        ;; one note/chord (an "EventChord") to the specified duration:

        (define (setDuration event-chord)
                (for-each (lambda (event)
            (if (not (null? (ly:music-property event 'duration)))
                (set! (ly:music-property event 'duration)
                      (ly:make-duration (ly:intlog2 dur) dots 1 1))))
          (ly:music-property event-chord 'elements))

        ;; Map it on the music:

        (music-map setDuration music))
%% some music to play with:     
        someMusic =  { <c' d' e' g'>4 f'8. e'16 a2  }

% the example score:

\score {        
        \new Staff {
                \set Staff.instrument = "squashMyRhythm "

                        \someMusic  \break
                % set to eights (undotted):
                        \squashDurations #8 #0 \someMusic
                % set to quarters:
                        \squashDurations #4 #0 \someMusic r8
                % dotted eigths:
                        \squashDurations #8 #1 \someMusic r8
                % etc.
                        \repeat unfold 3 { \squashDurations #32 #0 \someMusic }
\paper { ragged-right=##t indent = 34\mm}

% ****************************************************************
% end ly snippet
% ****************************************************************

reply via email to

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