Music-function "arguments" - help

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

Music-function "arguments" - help

Mansour Aoun
Hello,

I'm still quite a beginner in Lilypond and as much as I'm liking how much
customisable is its notation capabilities, understanding it is driving me
crazy because sometimes I can pass more than 4 or 5 hours reading manuals
and blogposts without reaching a simple answer to a simple question.

My current problem is that I'm learning how to write a music function yet
there's this mysterious element in it "nth argument" that I can't quite
understand. I understood all the other elements: the function syntax and how
parser and location should be copied literally, the predicate type and the
body. In this blogpost for example
https://lilypondblog.org/2015/04/defining-a-music-function/
<https://lilypondblog.org/2015/04/defining-a-music-function/>   Urs Liska
demonstrates how to create a simple function. In his/her example, the nth
argument is "my-color". In other examples the argument is
"paddingHorizontal", or "paddingVertical", or just "padding". I searched for
hours for a list of those arguments to see which one I should use for my
need and yet I can't find it anywhere.

I just want to create a simple function with an x-offset for dynamic texts
but i don't know what is the correct argument for this.
Any help would be much appreciated.
Thanks!



--
Sent from: http://lilypond.1069038.n5.nabble.com/User-f3.html

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

Mansour Aoun
Reply | Threaded
Open this post in threaded view
|

Re: Music-function "arguments" - help

David Kastrup
mansouraoun <[hidden email]> writes:

> Hello,
>
> I'm still quite a beginner in Lilypond and as much as I'm liking how much
> customisable is its notation capabilities, understanding it is driving me
> crazy because sometimes I can pass more than 4 or 5 hours reading manuals
> and blogposts without reaching a simple answer to a simple question.
>
> My current problem is that I'm learning how to write a music function yet
> there's this mysterious element in it "nth argument" that I can't quite
> understand.

That's just a shorthand for "the argument at position n", a
generalization of "1st, 2nd, 3rd, 4th, 5th, 6th"...

> I understood all the other elements: the function syntax and how
> parser and location should be copied literally, the predicate type and
> the body. In this blogpost for example
> https://lilypondblog.org/2015/04/defining-a-music-function/
> <https://lilypondblog.org/2015/04/defining-a-music-function/> Urs
> Liska demonstrates how to create a simple function. In his/her
> example, the nth argument is "my-color". In other examples the
> argument is "paddingHorizontal", or "paddingVertical", or just
> "padding". I searched for hours for a list of those arguments to see
> which one I should use for my need and yet I can't find it anywhere.

It's not a matter of _using_ an argument but of _naming_ an argument.
Basically it is arbitrary as long as it has the form of a Scheme
identifier.  For LilyPond, only the position is interesting, namely
whether it is 1st, 2nd, 3rd... in the list of the actual arguments when
calling a music function.

Of course it makes sense to name the argument something that conveys
meaning to you as the one having to _understand_ the code at a later
point of time rather than just _execute_ it, but arg1, arg2, arg3,
arg4... would be totally valid here.

> I just want to create a simple function with an x-offset for dynamic
> texts but i don't know what is the correct argument for this.

There is no "correct" argument name but x-offset would be fine.

--
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: Music-function "arguments" - help

Mansour Aoun
Ah ok I see ! The problem is that I thought that the "nth" argument should
come from a list of built-in, pre-defined arguments that should be
appropriate for the task I'm trying to do.

I just realised that I made a fool of myself when I just named it "blabla"
and it worked.

Thanks a lot David!
Cheers



--
Sent from: http://lilypond.1069038.n5.nabble.com/User-f3.html

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

Mansour Aoun
Reply | Threaded
Open this post in threaded view
|

Re: Music-function "arguments" - help

David Kastrup
mansouraoun <[hidden email]> writes:

> Ah ok I see ! The problem is that I thought that the "nth" argument
> should come from a list of built-in, pre-defined arguments that should
> be appropriate for the task I'm trying to do.
>
> I just realised that I made a fool of myself when I just named it
> "blabla" and it worked.

It's more like you made a fool of the ones writing the manual.  It's
actually hard to explain things in a manner not requiring previous
exposure to some of the terminology and concepts when you've been used
to them for too long.

--
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: Music-function "arguments" - help

Andrew Bernard
In reply to this post by Mansour Aoun
Hi Mansour,

The Notation Reference manual can be difficult to follow at first. We all suffer that.

Now that it's cleared up, just by way of example I use this:

dynamicsX-offset =
#(define-music-function (offset)
   (number?)
   #{
     \once \override DynamicText.X-offset = $offset
     \once \override DynamicLineSpanner.Y-offset = #0
   #})

If you are using 2.18 you need to use the parser and location arguments - no longer needed in recent versions.

I can't remember why you need to set the line spanner offset as well. But at the time I wrote this it seemed necessary. Could be redundant.

Andrew



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

Re: Music-function "arguments" - help

Urs Liska-3
In reply to this post by David Kastrup


Am 7. Dezember 2018 01:46:00 MEZ schrieb David Kastrup <[hidden email]>:

>mansouraoun <[hidden email]> writes:
>
>> Hello,
>>
>> I'm still quite a beginner in Lilypond and as much as I'm liking how
>much
>> customisable is its notation capabilities, understanding it is
>driving me
>> crazy because sometimes I can pass more than 4 or 5 hours reading
>manuals
>> and blogposts without reaching a simple answer to a simple question.
>>
>> My current problem is that I'm learning how to write a music function
>yet
>> there's this mysterious element in it "nth argument" that I can't
>quite
>> understand.
>
>That's just a shorthand for "the argument at position n", a
>generalization of "1st, 2nd, 3rd, 4th, 5th, 6th"...
>
>> I understood all the other elements: the function syntax and how
>> parser and location should be copied literally, the predicate type
>and
>> the body. In this blogpost for example
>> https://lilypondblog.org/2015/04/defining-a-music-function/
>> <https://lilypondblog.org/2015/04/defining-a-music-function/> Urs
>> Liska demonstrates how to create a simple function. In his/her
>> example,

his.

 the nth argument is "my-color". In other examples the
>> argument is "paddingHorizontal", or "paddingVertical", or just
>> "padding". I searched for hours for a list of those arguments to see
>> which one I should use for my need and yet I can't find it anywhere.

Maybe https://scheme-book.ursliska.de can give you further insight. It's far from complete and I can't guarantee everything's correct. But I've explicitly tried to address  the sort of slow-paced explanations the LilyPond manuals can't afford.

Urs


>
>It's not a matter of _using_ an argument but of _naming_ an argument.
>Basically it is arbitrary as long as it has the form of a Scheme
>identifier.  For LilyPond, only the position is interesting, namely
>whether it is 1st, 2nd, 3rd... in the list of the actual arguments when
>calling a music function.
>
>Of course it makes sense to name the argument something that conveys
>meaning to you as the one having to _understand_ the code at a later
>point of time rather than just _execute_ it, but arg1, arg2, arg3,
>arg4... would be totally valid here.
>
>> I just want to create a simple function with an x-offset for dynamic
>> texts but i don't know what is the correct argument for this.
>
>There is no "correct" argument name but x-offset would be fine.

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

Re: Music-function "arguments" - help

Mansour Aoun
David exactly. Just the small information of "arguments' names are
user-defined", (which might be a self-evidence for people with programming
background/experience) would have saved me 3 hours yesterday. But it's fine,
the important is that I understand now.

Andrew thanks for replying. I ended up with this simple code working
correctly:



And Urs thanks for the feedback. The book will be of a great help for me at
this stage.

Mansour



--
Sent from: http://lilypond.1069038.n5.nabble.com/User-f3.html

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

Mansour Aoun
Reply | Threaded
Open this post in threaded view
|

Re: Music-function "arguments" - help

Mansour Aoun
i wrote the code in raw and it's somehow not displayed in my message
Here it is

dynx =
#(define-music-function
     (parser location X-offset)
     (number?)
   #{
     \once\override DynamicText.X-offset = #X-offset
   #})

Mansour



--
Sent from: http://lilypond.1069038.n5.nabble.com/User-f3.html

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

Mansour Aoun
Reply | Threaded
Open this post in threaded view
|

Re: Music-function "arguments" - help

Urs Liska-3

Am 07.12.18 um 10:55 schrieb mansouraoun:

> i wrote the code in raw and it's somehow not displayed in my message
> Here it is
>
> dynx =
> #(define-music-function
>       (parser location X-offset)
>       (number?)
>     #{
>       \once\override DynamicText.X-offset = #X-offset
>     #})
>
> Mansour
>
As David said: if you use the development version (currently 2.19.82)
you can simplify this by skipping "parser location":

   ...
   #(define-music-function (X-offset)(number?)
   ...

Urs


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

Re: Music-function "arguments" - help

Urs Liska-3

Am 07.12.18 um 11:07 schrieb Urs Liska:

>
> Am 07.12.18 um 10:55 schrieb mansouraoun:
>> i wrote the code in raw and it's somehow not displayed in my message
>> Here it is
>>
>> dynx =
>> #(define-music-function
>>       (parser location X-offset)
>>       (number?)
>>     #{
>>       \once\override DynamicText.X-offset = #X-offset
>>     #})
>>
>> Mansour
>>
> As David said: if you use the development version (currently 2.19.82)
> you can simplify this by skipping "parser location":
>
>   ...
>   #(define-music-function (X-offset)(number?)
>   ...


And while we're at it:

As David also pointed out, the *naming* of such variables is arbitrary,
it's just their order/position. "parser" and "location" are arguments
that the LilyPond parser (in 2.18) *implicitly* passes to a music
function because *sometimes* a music function has the need to access
either the current LilyPond parser or the "location" (the place in the
input file from where the function was called). But since the vast
majority of functions does *not* need them it is needlessly verbose
having to write them for each and every music function. So two
procedures, *parser* and *location* were at some point added to LilyPond
that can be called from within a music function, if it should actually
need one of these values (to *invoke* a procedure it has to be enclosed
in parentheses like

   (display (*location*))

For the function you are currently interested in this is of absolutely
no interest, but I thought to point it out since you were irritated by
the function arguments in the first place, so it may be interesting to know.

Best
Urs

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

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

Re: Music-function "arguments" - help

Mansour Aoun
In reply to this post by Urs Liska-3
Just switched to 2.19.82 and it works like a charm.

Thanks

Mansour



--
Sent from: http://lilypond.1069038.n5.nabble.com/User-f3.html

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

Mansour Aoun
Reply | Threaded
Open this post in threaded view
|

Re: Music-function "arguments" - help

David Kastrup
In reply to this post by Urs Liska-3
Urs Liska <[hidden email]> writes:

> Am 07.12.18 um 10:55 schrieb mansouraoun:
>> i wrote the code in raw and it's somehow not displayed in my message
>> Here it is
>>
>> dynx =
>> #(define-music-function
>>       (parser location X-offset)
>>       (number?)
>>     #{
>>       \once\override DynamicText.X-offset = #X-offset
>>     #})
>>
>> Mansour
>>
> As David said: if you use the development version (currently 2.19.82)
> you can simplify this by skipping "parser location":
>
>   ...
>   #(define-music-function (X-offset)(number?)
>   ...

Actually, if you switch to the development version, you can simplify
this by writing

dynx = \once\override DynamicText.X-offset = \etc

but the \etc construct works only for a limited number of uses and does
nothing different than generating a music function of that kind.  Also
when writing the music function manually, you can use a more specific
predicate and have the arguments checked directly for the right type and
possibly coerced: for example, -3 without further qualification is a
number, but when you use a ly:event? predicate for a music function, it
will be a fingering.

--
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: Music-function "arguments" - help

Mansour Aoun
Well I was earlier trying the \etc method only to realise that it wasn't
available for 2.18. Yes indeed it is simpler but the function method gives
me more control over what I want to achieve, and even if the \etc had worked
on 2.18 I would still want to know how to write a correct music function.

Mansour



--
Sent from: http://lilypond.1069038.n5.nabble.com/User-f3.html

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

Mansour Aoun