Writing a function

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

Writing a function

Rok Kršmanc
Hi!

I would like to write a function for the next music expression:
\once \override TextScript.extra-offset = #'(0 . 1)
c^"o"

Here is my try:
f =
#(define-music-function (parser location offset music)
   (number? ly:music?)
   #{
     \once \override TextScript.extra-offset = #'(0 . $offset)
     $music ^"o"
   #})

When I call this function:
\f #1 c

I get syntax error:
unexpected '^'

What am I doing wrong?

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

Re: Writing a function

David Kastrup
Rok Kršmanc <[hidden email]> writes:

> Hi!
>
> I would like to write a function for the next music expression:
> \once \override TextScript.extra-offset = #'(0 . 1)
> c^"o"
>
> Here is my try:
> f =
> #(define-music-function (parser location offset music)
>   (number? ly:music?)
>   #{
>     \once \override TextScript.extra-offset = #'(0 . $offset)
>     $music ^"o"
>   #})
>
> When I call this function:
> \f #1 c
>
> I get syntax error:
> unexpected '^'
>
> What am I doing wrong?

First it seems like a bad idea to redefine \f ("forte").  But the main
problem is that an expression like $music cannot take articulations
(this has been ameliorated to some degree in current development, likely
appearing as 2.21 eventually).

You can achieve about the same effect with << $music <>-"o" >> namely
putting the articulation instead on a simultaneously executing empty
chord.

--
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: Writing a function

Aaron Hill
On 2019-05-12 3:40 am, David Kastrup wrote:

> Rok Kršmanc <[hidden email]> writes:
>
>> Hi!
>>
>> I would like to write a function for the next music expression:
>> \once \override TextScript.extra-offset = #'(0 . 1)
>> c^"o"
>>
>> Here is my try:
>> f =
>> #(define-music-function (parser location offset music)
>>   (number? ly:music?)
>>   #{
>>     \once \override TextScript.extra-offset = #'(0 . $offset)
>>     $music ^"o"
>>   #})
>>
>> When I call this function:
>> \f #1 c
>>
>> I get syntax error:
>> unexpected '^'
>>
>> What am I doing wrong?
>
> First it seems like a bad idea to redefine \f ("forte").  But the main
> problem is that an expression like $music cannot take articulations
> (this has been ameliorated to some degree in current development,
> likely
> appearing as 2.21 eventually).
>
> You can achieve about the same effect with << $music <>-"o" >> namely
> putting the articulation instead on a simultaneously executing empty
> chord.

Would an event function possibly make more sense?  Consider:

%%%%
\version "2.19.82"

foo = #(define-event-function (offset) (number?)
   #{ \tweak extra-offset #(cons 0 offset)
      ^"foo" #})

{ b'4 \foo #0.5 b' b' \foo #-1 }
%%%%


-- Aaron Hill

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