[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: aligning variables with upbeats
From: |
Pedro Pessoa |
Subject: |
Re: aligning variables with upbeats |
Date: |
Tue, 12 Feb 2019 13:04:15 -0700 (MST) |
Hello John,
I took this task as a way of learning a bit more about moments and durations
(and also, I wanted to achieve this a while ago). It is certainly not a very
robust or elegant solution, but seems to work for this particular case.
%% \makeRestOfLenght \mus "rest/skip" upbeat %%
\version "2.19.82"
partA = { c'2 b | R1*3 }
partB = { \partial 4 g4 | \bar "||" c'1 }
#(define (make-dynamic-rest len event)
"The rest/skip body."
(make-music
event ; To choose if it is gonna be Skip or Rest
'duration
; intlog transforms the rational values used in Moments (the
denominator) into log values used in Durations.
; 1 (whole)->0
; 2 (half)->1
; 4 (quarter)->2 ... etc
(ly:make-duration (ly:intlog2 len))))
#(define (makeRestofLog num den opts)
"Logging function"
(display (format "~%>> \\makeRestOfLenght:~%~A ~As of value ~A will be
created:~%" num opts den)))
makeRestOfLenght=
#(define-scheme-function (mus opts upbeat)(ly:music? string? ly:music?)
"Creates a series of rests/skips of the same length as the given music
minus an upbeat value. Opts are 'rest', 'skip'. Anything else calls 'rest'."
(let* ((musLen (ly:music-length mus));
(upBeatLen (ly:music-length upbeat))
(musMinusUp (ly:moment-sub musLen upBeatLen))
(den (ly:moment-main-denominator musMinusUp))
(num (ly:moment-main-numerator musMinusUp))
(event (cond
((string>= opts "skip")
'SkipEvent)
((string>= opts "rest")
'RestEvent)
(else
(set! opts "rest")
'RestEvent)
))
(rests '()))
(makeRestofLog num den opts) ; Didatic logging.
; Iterate over the number of rest needed (given by the numerator).
; The value of the rest is given by the denominator.
(let loop ((i 0))
(if (< i num)
(begin
(set! rests (append rests (list (make-dynamic-rest den event))))
(loop (+ i 1)))))
(newline)
(make-music
'SequentialMusic
'elements
rests)
))
\score {
\new Staff <<
\new Voice \partA
\new Voice {
% \makeRestOfLenght \partA "rest" 4 % To visualize rests.
\makeRestOfLenght \partA "skip" 4
\partB
}
>>
}
--
Sent from: http://lilypond.1069038.n5.nabble.com/User-f3.html
- Re: aligning variables with upbeats, (continued)
Re: aligning variables with upbeats, Gianmaria Lari, 2019/02/07
Re: aligning variables with upbeats, Mats Bengtsson, 2019/02/07
Re: aligning variables with upbeats, Kieren MacMillan, 2019/02/07
Re: aligning variables with upbeats,
Pedro Pessoa <=