Good afternoon, Jean and Valentin,
Thank you very much for the up to the point explanation, working function, as well as alternatives syntax for object properties using Scheme metaprogramming! Lilypond is quite flexible, but with its own quirks as the handling of default parameters to a music function.
I wonder if there is a way to define a music function with default parameters and be able to selectively specify some parameters using the parameters names leaving all other parameters with their default values? Probably it is asking too much :)
My use case is for the shaped slur function currently defined using the Nunjucks _javascript_ templating engine. The meaning of parameters is: dir = direction, bs = baseline height, sh = horizontal shift, wd = slur width, ht = slur height, dt = delta between left and right ends
{% macro shapedSlur(dir, bs = 2.0, sh = 0.5, wd = 1.0, ht = 1.0, dt = 0.0) %}
{% set ax = 0.0 * wd + sh %}
{% set bx = 1.0 * wd + sh %}
{% set cx = 2.0 * wd + sh %}
{% set dx = 3.0 * wd + sh %}
{% set ay, dy = bs %}
{% set by, cy = (bs + ht) %}
{% if dir == "fu" %} <# forward up slur #>
{% set dy = dy + dt %}
{% elif dir == "fd" %} <# forward down slur #>
{% set dy = dy + dt %}
{% set ay = -ay %}
{% set by = -by %}
{% set cy = -cy %}
{% set dy = -dy %}
{% elif dir == "bu" %} <# backward up slur #>
{% set ax = ax - 3.0 * wd %}
{% set bx = bx - 3.0 * wd %}
{% set cx = cx - 3.0 * wd %}
{% set dx = dx - 3.0 * wd %}
{%set ay = ay + dt %}
{% elif dir == "bd" %} <# backward down slur #>
{% set ax = ax - 3.0 * wd %}
{% set bx = bx - 3.0 * wd %}
{% set cx = cx - 3.0 * wd %}
{% set dx = dx - 3.0 * wd %}
{%set ay = ay + dt %}
{% set ay = -ay %}
{% set by = -by %}
{% set cy = -cy %}
{% set dy = -dy %}
{% endif %}
\tweak control-points
#'(({{ ax }} . {{ ay }}) ({{ bx }} . {{ by }})
({{ cx }} . {{ cy }}) ({{ dx }} . {{ dy }}))
{% endmacro %}
I can easily specify only arguments that differ from default values like below
{{ shapedSlur("fd", bs = 3) }} ( <>)
{{ shapedSlur("fu", bs = 0, wd = 2.2, ht = 2.8) }} ( <>)
The current solution depends on the Nunjucks external template engine. It would be nice to define this logic using a music function with the syntax similar to the below (not yet working code) and ideally not having to specify the \default placeholder for every not modified argument. The last parameter is mandatory and indicates the direction of a slur
\shapedSlur bs = 3 "fd" ( <>)
\shapedSlur bs = 0 wd = 2.2 ht = 2.8 "fu" ( <>)
Probably the above is too challenging or maybe there is an alternative equally concise idiomatic solution in LilyPond.
Thank you very much!
Vlad