[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: music functions: how to translate "user-durations" in ly:durations
From: |
Michael Meixner |
Subject: |
Re: music functions: how to translate "user-durations" in ly:durations |
Date: |
Fri, 16 Jun 2006 21:12:01 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Nicolas Sceaux <nicolas.sceaux <at> free.fr> writes:
>
> Michael Meixner <meixner <at> mdw.ac.at> writes:
>
> > Right now the input is in the format:
> > % dotted eigths:
> > \squashDurations #8 #1 {...music...}
> >
> > I would prefer:
> > % dotted eigths:
> > \squashDurations "8." {...music...}
>
> Why not something like:
>
> \squashDurations s8. {...music...}
>
> then you have the duration parsing for free: just get the duration
> property from the skip event.
Ah, great!
Here's the last incarnation of my function.
One more question for my education (certainly not the last...):
In this part:
==
(for-each (lambda (event) ...)
==
I tried "map" instead of "for-each" which yielded the same result.
In "teach yourself Scheme" they say:
"The 'for-each' procedure also applies a procedure to each element
in a list, but returns void. The procedure application is done
purely for any sied-effects it may cause."
I don't get this, even the example provided doesn't enlighten me.
What is the advantage of "for-each" in our case?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\version "2.9.8"
% A music function which sets all notes (chords)
% to the same duration, which is given as a skip:
setDurations =
#(define-music-function (parser location dur music)
(ly:music? ly:music?)
"Sets all durations in 'music' to 'dur' "
;; Extract the duration from the given SkipEvent:
(define newDuration
(ly:music-property (first (ly:music-property dur
'elements )) 'duration ))
;; 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) newDuration )))
(ly:music-property event-chord 'elements))
event-chord)
;; Map it on the music:
(music-map setDuration music)
;; don't forget the closing bracket for your music function!
)
% some music to play with:
someMusic = { <c' d' e' fis'>4 f'8. e'16 a2 }
% the example score:
\score {
\new Staff {
\someMusic \break
% set to eights:
\setDurations s8 \someMusic
% etc:
\setDurations s4 \someMusic
\setDurations s32 \someMusic
\setDurations s16. \someMusic
}}
\paper { ragged-right=##t indent = 0\mm}
%%%%%%%%%%%%%%%%%%%%%%%