Re: How to define a macro that expands to a percussion "pitch"?
Jean Abou Samra writes: >> Le 28 janv. 2023 à 08:01, Darren Ng a écrit : >> >> [subject] How to define a macro that expands to a percussion "pitch"? > > > It may be worth noting that LilyPond does not have macros, only > variables and regular functions. Call me pedantic, but I think it is > helpful not to conflate the two. It's a hybrid, actually. In Lispy terms, the difference between a function and a macro is that a function evaluates its arguments while a macro evaluates the result of executing the macro body on the unevaluated arguments. LilyPond evaluates a music/event/scheme/void function's body after reading its arguments but the reading/interpretation of the arguments is directed by the predicates. So a music/event/scheme/void function does evaluate some of its parts (the predicates) in order to direct the syntactic interpretation of its arguments. > There is no way in LilyPond to make a variable "just be replaced by > this code". Sometimes users get confused by this (I remember a > question about defining a chord modifier, which was similar to this > one). Instead, there are functions, as well as some other mechanisms > like drumPitchNames. In general, things are not purely functional but the categories and interpretation change around more by ad-hoc conditions than a cohesive macro mechanism. -- David Kastrup
Re: How to define a macro that expands to a percussion "pitch"?
> Le 28 janv. 2023 à 08:01, Darren Ng a écrit : > > [subject] How to define a macro that expands to a percussion "pitch"? It may be worth noting that LilyPond does not have macros, only variables and regular functions. Call me pedantic, but I think it is helpful not to conflate the two. There is no way in LilyPond to make a variable "just be replaced by this code". Sometimes users get confused by this (I remember a question about defining a chord modifier, which was similar to this one). Instead, there are functions, as well as some other mechanisms like drumPitchNames. Lukas already gave the solution, so I don’t have anything more to add. Jean
Re: How to define a macro that expands to a percussion "pitch"?
Hi Pierre-Luc, Am 28.01.23 um 14:02 schrieb Pierre-Luc Gauthier: m = \drummode { hh } Unfortunately not: This turns m into "music" including a duration. Hence, \m 8 will be interpreted as "first \m" (with its own pitch), then another one of duration 8. Compare: \version "2.24.0" m = \drummode { hh } \drummode { \m 8 \m r4 \m } \drummode { hh8 hh8 r4 hh4 } But what you can do is: \version "2.24.0" drumPitchNames.m = #'hihat \drummode { m8 m r4 m } (which might be even better than the OP hoped for). Lukas
Re: How to define a macro that expands to a percussion "pitch"?
m = \drummode { hh } Le sam. 28 janv. 2023, à 02 h 01, Darren Ng a écrit : > > [subject] How to define a macro that expands to a percussion "pitch"? > > input is > > m = hh > \drummode { \m 8 \m r4 \m } > > expected output should be equivalent to > > \drummode { hh8 hh8 r4 hh4 } > > actual output (console) > > percussion.ly:*:*: warning: Ignoring non-music expression > > \m 8 \m r4 \m > percussion.ly:*:*: warning: Ignoring non-music expression > \m 8 > \m r4 \m > percussion.ly:*:*: warning: Ignoring non-music expression > \m 8 \m r4 >\m > > actual output (midi) > > (I hear no percussion at all) > -- Pierre-Luc Gauthier
How to define a macro that expands to a percussion "pitch"?
[subject] How to define a macro that expands to a percussion "pitch"? input is m = hh \drummode { \m 8 \m r4 \m } expected output should be equivalent to \drummode { hh8 hh8 r4 hh4 } actual output (console) percussion.ly:*:*: warning: Ignoring non-music expression \m 8 \m r4 \m percussion.ly:*:*: warning: Ignoring non-music expression \m 8 \m r4 \m percussion.ly:*:*: warning: Ignoring non-music expression \m 8 \m r4 \m actual output (midi) (I hear no percussion at all)