variables for specific kinds of markup?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

variables for specific kinds of markup?

marc
Hi all,

I'm trying to create a variable to handle a certain type of markup text.
For instance, I'd like percussion strikings to be in small caps above
the staff, and what I really want is to define some sort of macro that
replaces all instances of "\striking { theText }" with
"^\markup\smallCaps { theText }".

The following clearly doesn't work (much as I would like it to):

striking = ^\markup\smallCaps

 From searching around, it seems like I need to define a function using
scheme. I tried this:

striking = #(define-music-function (parser location text)
          (string?)
          #{
            ^\markup\smallCaps { #text }
          #})

... and while the single line "\striking mallet" seems to render the
word mallet as a smallCaps markup above a dummy staff, when I try to
incorporate it into a series of notes, e.g.:

{c'4 \striking mallet d'4 e'4 f'4 }

I get an "error: unexpected post-event". What exactly does that mean?

I did notice something close to what I want here:

http://lilypond.org/doc/v2.19/Documentation/extending/new-markup-command-definition.en.html

But it still would require me to put something like \markup\striking, as
opposed to \striking.

I'm pretty new to lilypond, so apologies if I've said something that
betrays a lack of understanding. I guess I'd just mostly like to know
what that "unexpected post-event" error means.

Thanks in advance!

Marc


--
Marc Evans
PhD Candidate in Music Composition at UCSB
Stanford BA '10, Music; MA '11, Music, Science and Technology
www.marcevansmusic.com

---

"I'm a random guy. I shake a hand and make a friend. I don't do egotistical things."
– Vanilla Ice


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: variables for specific kinds of markup?

David Kastrup
"Marc Evanstein (formerly Evans)" <[hidden email]> writes:

> Hi all,
>
> I'm trying to create a variable to handle a certain type of markup
> text. For instance, I'd like percussion strikings to be in small caps
> above the staff, and what I really want is to define some sort of
> macro that replaces all instances of "\striking { theText }" with
> "^\markup\smallCaps { theText }".
>
> The following clearly doesn't work (much as I would like it to):
>
> striking = ^\markup\smallCaps

Current master will allow

striking = ^\markup \smallCaps \etc

> From searching around, it seems like I need to define a function using
> scheme. I tried this:
>
> striking = #(define-music-function (parser location text)
>          (string?)
>          #{
>            ^\markup\smallCaps { #text }
>          #})
>
> ... and while the single line "\striking mallet" seems to render the
> word mallet as a smallCaps markup above a dummy staff, when I try to
> incorporate it into a series of notes, e.g.:
>
> {c'4 \striking mallet d'4 e'4 f'4 }
>
> I get an "error: unexpected post-event". What exactly does that mean?

Current master would have worked as expected for this use...

At any rate, you are pretty close (whether we are talking about 2.18 or
2.19).  Just use define-event-function instead of define-music-function
.

And rejoice that LilyPond will have fewer stumbling blocks in the near
future.  Or at least will be better at hiding the stumbling blocks so
you'll just get hit by them when digging deeper.

--
David Kastrup

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: variables for specific kinds of markup?

marc
Thanks so much – changing it to define-event-function worked perfectly. Is a markup considered an "event" rather than "music"? Was define-music-function somehow returning that event attached to empty music or something?

At any rate, glad to hear that this is getting simpler in the near future, and many thanks for all the help!

September 17, 2018 8:01 AM, "David Kastrup" <[hidden email]> wrote:

> "Marc Evanstein (formerly Evans)" <[hidden email]> writes:
>
>> Hi all,
>>
>> I'm trying to create a variable to handle a certain type of markup
>> text. For instance, I'd like percussion strikings to be in small caps
>> above the staff, and what I really want is to define some sort of
>> macro that replaces all instances of "\striking { theText }" with
>> "^\markup\smallCaps { theText }".
>>
>> The following clearly doesn't work (much as I would like it to):
>>
>> striking = ^\markup\smallCaps
>
> Current master will allow
>
> striking = ^\markup \smallCaps \etc
>
>> From searching around, it seems like I need to define a function using
>> scheme. I tried this:
>>
>> striking = #(define-music-function (parser location text)
>> (string?)
>> #{
>> ^\markup\smallCaps { #text }
>> #})
>>
>> ... and while the single line "\striking mallet" seems to render the
>> word mallet as a smallCaps markup above a dummy staff, when I try to
>> incorporate it into a series of notes, e.g.:
>>
>> {c'4 \striking mallet d'4 e'4 f'4 }
>>
>> I get an "error: unexpected post-event". What exactly does that mean?
>
> Current master would have worked as expected for this use...
>
> At any rate, you are pretty close (whether we are talking about 2.18 or
> 2.19). Just use define-event-function instead of define-music-function
> .
>
> And rejoice that LilyPond will have fewer stumbling blocks in the near
> future. Or at least will be better at hiding the stumbling blocks so
> you'll just get hit by them when digging deeper.
>
> --
> David Kastrup


"I'm a random guy. I shake a hand and make a friend. I don't do egotistical things."
– Vanilla Ice

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: variables for specific kinds of markup?

David Kastrup
"Marc Evanstein" <[hidden email]> writes:

> Thanks so much – changing it to define-event-function worked
> perfectly. Is a markup considered an "event" rather than "music"?

No.  But ^\markup ... is.

> Was define-music-function somehow returning that event attached to
> empty music or something?

The decision whether to attach is made when the function is _called_,
not when it returns.

If you write something like

\displayLilyMusic c \displayLilyMusic d

then LilyPond cannot tentatively call the second \displayLilyMusic
before the first in order to decide whether it might return some
articulation to attach to the c before it calls the first
\displayLilyMusic .

LilyPond 2.20 has an additional sweepup stage that will let

\displayLilyMusic c \displayLilyMusic ^"Hi"

attach the ^"Hi" from the second \displayLilyMusic call to the finished
c from the first \displayLilyMusic call so that while the order of
evaluation gets messed up you would not get to see the same error
message as you do with your version.

This will likely reduce the number of complaints, but evaluation order
will not likely be always what one would expect.

--
David Kastrup

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user