lilypond-user
[Top][All Lists]
Advanced

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

Re: Basic functions


From: Jean Abou Samra
Subject: Re: Basic functions
Date: Sat, 15 May 2021 22:44:45 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1


Le 15/05/2021 à 19:49, Jenifer Tribe a écrit :
I want to include a change of midi tempo at various points in a score, using something like
  \setSpeed #2 #120

where 
setSpeed =
  #(define-music-function
      (parser location scale speed)
      (number? number? )
    #{
       \set Score.tempoHideNote = ##t
       \tempo scale = speed
    #}
  )

I'm still using 2.18 I'm afraid, which still used the parser and location parameters..
I'm assuming this should be a music function rather than markup, but perhaps my arguments aren't numbers.
In this case the function is hardly worth it, but I want to base more complicated routines on it, and have failed at the first hurdle!

There are two mistakes here:

- In the function, scale and speed are interpreted as strings.
  You want $scale and $speed (the reason for using $ instead
  of # is explained in [1]).

- The scale argument is a duration, not a number (you can do
  \tempo 4. = 120 for instance).

Corrected version:

\version "2.23.3"

setSpeed =
#(define-music-function
    (parser location scale speed)
    (ly:duration? number?)
  #{
     \set Score.tempoHideNote = ##t
     \tempo $scale = $speed
  #})


\score {
  {
    \setSpeed 4. 4
    c
  }
  \layout { }
  \midi { }
}

There is also the possibility of doing

\layout {
  \context {
    \Score
    tempoHideNote = ##t
  }
}

to set tempoHideNote globally (read [2]), and then you
can just use the normal \tempo command in the music.


Best,
Jean

[1] https://extending-lilypond.readthedocs.io/en/latest/lily-and-scheme.html#hash-vs-dollar
[2]
http://lilypond.org/doc/v2.22/Documentation/notation/changing-context-default-settings


reply via email to

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