Discussion:
Music-function "arguments" - help
mansouraoun
2018-12-07 00:18:53 UTC
Permalink
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
David Kastrup
2018-12-07 00:46:00 UTC
Permalink
Post by mansouraoun
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"...
Post by mansouraoun
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.
Post by mansouraoun
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
mansouraoun
2018-12-07 00:53:56 UTC
Permalink
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
David Kastrup
2018-12-07 01:05:33 UTC
Permalink
Post by mansouraoun
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
Urs Liska
2018-12-07 01:31:11 UTC
Permalink
Post by mansouraoun
Post by mansouraoun
Hello,
I'm still quite a beginner in Lilypond and as much as I'm liking how
much
Post by mansouraoun
customisable is its notation capabilities, understanding it is
driving me
Post by mansouraoun
crazy because sometimes I can pass more than 4 or 5 hours reading
manuals
Post by mansouraoun
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
Post by mansouraoun
there's this mysterious element in it "nth argument" that I can't
quite
Post by mansouraoun
understand.
That's just a shorthand for "the argument at position n", a
generalization of "1st, 2nd, 3rd, 4th, 5th, 6th"...
Post by mansouraoun
I understood all the other elements: the function syntax and how
parser and location should be copied literally, the predicate type
and
Post by mansouraoun
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
Post by mansouraoun
Post by mansouraoun
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
Post by mansouraoun
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.
Post by mansouraoun
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.
mansouraoun
2018-12-07 09:52:23 UTC
Permalink
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
mansouraoun
2018-12-07 09:55:27 UTC
Permalink
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
Urs Liska
2018-12-07 10:07:34 UTC
Permalink
Post by 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
Urs Liska
2018-12-07 10:23:13 UTC
Permalink
Post by Urs Liska
Post by 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)
  ...
  #(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
Post by Urs Liska
Urs
_______________________________________________
lilypond-user mailing list
https://lists.gnu.org/mailman/listinfo/lilypond-user
mansouraoun
2018-12-07 10:35:15 UTC
Permalink
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
David Kastrup
2018-12-07 12:01:56 UTC
Permalink
Post by Urs Liska
Post by 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)
  ...
  #(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
mansouraoun
2018-12-07 13:22:07 UTC
Permalink
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

Andrew Bernard
2018-12-07 01:29:36 UTC
Permalink
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
Loading...