lilypond-user
[Top][All Lists]
Advanced

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

Re: How to generate \scaleDurations values procedurally


From: Jean Abou Samra
Subject: Re: How to generate \scaleDurations values procedurally
Date: Mon, 12 Jun 2023 10:57:59 +0200
User-agent: Evolution 3.48.3 (3.48.3-1.fc38)

Le lundi 12 juin 2023 à 10:23 +0200, Lib Lists a écrit :

> In your example, I changed the line: #{ \new Staff { \scaleDurations #(cons 
> 60 i) \mus } #})
> to this: #{ \new Staff { \scaleDurations #(cons 60 i)  #(ly:music-transpose 
> {\mus} i)  } #})
> but clearly there's something wrong,

Well, there are a couple problems.

{\mus} is LilyPond syntax, but within the #(ly:music-transpose ...), you
are in Scheme syntax due to the # . Curly brackets have a totally different
meaning in Scheme (namely usually no meaning, so in this case it literally
looks up a variable called “{\mus}” which doesn't exist, but you can also
activate syntax extensions that make use of curly brackets). If you want
to switch to LilyPond syntax inside the Scheme code, you should use #{ #} again.
Or, in this case, you can just use the variable “mus”, which is defined since
LilyPond variables are also Scheme variables (except that Scheme doesn't need
a \ to reuse a variable). But in that case, you will get into trouble
because ly:music-transpose is destructive, so the calls will mutate it
and their effects will accumulate. So you would actually need 
(ly:music-deep-copy mus).
If you stay in LilyPond syntax with \transpose c' #(...) \mus, there is no such
problem (the \ in LilyPond makes a copy). See also
https://extending-lilypond.gitlab.io/en/extending/music.html#copying-music

Also, it is not meaningful in general to “transpose music X by i semitones”,
because that does not tell whether C transposed by 2 semitones down should be
B♭ or A♯. That is why the second argument to ly:music-transpose is not a number
but a pitch. See

https://extending-lilypond.gitlab.io/en/extending/music.html#pitches
For this type of case, LilyPond has a make-semitone->pitch function that helps
you to pick one or the other.

Lastly, i takes values from 60 to 51 so you should use (- 60 i) for the index
of the staff.

By the way, \remove'ing Timing_translator sounds a bit... scary, it's a kind of
fundamental translator, I don't know if we really support removing it entirely.
Also, your method of removing bar lines will still make LilyPond insert them.
I think it's better to just use \cadenzaOn.

\version "2.25.5"

mus = \repeat unfold 3 \relative { c'' c c c }

#(define my-semitone->pitch
   (make-semitone->pitch
    (music-pitches #{ { c cis d ees e f fis g gis a bes b } #})))

\score {
  \new StaffGroup  <<
    #@(map (lambda (i)
             #{
                \new Staff {
                  \scaleDurations #(cons 60 i) {
                    \transpose c' #(my-semitone->pitch (- (- 60 i))) {
                      \mus
                    }
                  }
                }
              #})
           (iota 10 60 -1))
  >>

   \layout {
    \context {
      \Score
      \override SpacingSpanner.base-shortest-duration = #(ly:make-moment 1/4)
      proportionalNotationDuration = #(ly:make-moment 1/10)
      \override SpacingSpanner.uniform-stretching = ##t
      \override SpacingSpanner.strict-note-spacing = ##t
      forbidBreakBetweenBarLines = ##f
      \cadenzaOn
    }
    \context {
      \Staff
      \remove Time_signature_engraver
    }
    \context {
      \Voice
      \remove Forbid_line_break_engraver
    }
  }
}





Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

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