lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scheme syntax help ( I think)


From: Jean Abou Samra
Subject: Re: Scheme syntax help ( I think)
Date: Sun, 16 Oct 2022 22:33:27 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1

Le 16/10/2022 à 16:43, Colin Baguley a écrit :
Hi there,
By reading this mailing list I've recently discovered how to add some text in a box to my music which doesn't
affect any other elements of the score. This is an example of what I mean.

\mark \markup {\with-dimensions-from \null
           \translate #'(1.0 . -4.0)
           \override #'(font-name . "Calibra Bold ")
           \fontsize #3
           \with-color #(x11-color "Red")
           \box   \whiteout  "Some text here" }

So, my next challenge was to  make this into a function so that I could alter the font, size, colour, position etc on the fly so to speak but I'm struggling with Scheme syntax here. I've managed to  work out position and fontsize, but struggling with the rest. Here is how far I've got. Could someone  improve on this please [ and also comment on why the 'whiteout' isn't perfect ]



Like this?

\version "2.22.2"

specialbox =
#(define-music-function (coord marktext fsize fname color) (pair? markup? number? string? color?)
   #{
     \once \override Score.RehearsalMark.layer = 5
     \mark \markup {\with-dimensions-from \null
           \translate #coord
           \override #`(font-name . ,fname)
           \fontsize #fsize
           \with-color #color
           \box   \whiteout  $marktext }
   #})
%---------------------------------------------------
melody = \relative c' {
\repeat unfold 4 {  c8 d e f g f e d } \break

\specialbox #'(0.0 . -4.0 ) #"Testing 123" #3 "Linux Libertine" #(x11-color "red")

\repeat unfold 4 { c8 d e f g f e d  } \break
}
%----------------------------------------------------
\score {
    \new Staff { \melody }
    \layout { }
}
%----------------------------------------------------





For the color, there is nothing special, just replace #(x11-color "red"),
a Scheme expression that always evaluates to the same color, with #color,
a Scheme expression that evaluates to the 'color' parameter of the
function. The predicate for colors that you need to put in the signature
is color? . For font-name, you need to use Scheme quasiquoting syntax,
with a backtick ` instead of a quote ' . This allows you to use a comma
to evaluate an expression inside the quoted expression. Quoting and
quasiquoting can be confusing for Scheme beginners. Perhaps this will
help a bit, although the part about quasiquoting is admittedly short:

https://tutoriel-scheme.readthedocs.io/en/latest/quoting.html#quasiquotes

You can also search the net for 'Scheme quasiquoting' and find plenty
of explanations of this concept.

If you don't like (quasi)quoting, you can always use the more verbose

#(cons 'font-name fname)

instead of

#`(font-name . ,fname)

By the way, I don't understand why you use $marktext. The difference
between # and $ is subtle but in most cases you don't need to know
about it and you can just use #.

Now, you know how to do this, but actually it is not necessary, and you
will likely start to find writing all parameters every time inconvenient.
All the markup transformations you are doing except \box are also available
in the form of properties, so you can just as well do

\version "2.22.2"

melody = \relative c' {
  \override Score.RehearsalMark.whiteout = ##t
  \override Score.RehearsalMark.X-extent = ##f
  \override Score.RehearsalMark.Y-extent = ##f
  \override Score.RehearsalMark.vertical-skylines = ##f
  \override Score.RehearsalMark.horizontal-skylines = ##f
  \override Score.RehearsalMark.outside-staff-priority = ##f
  \override Score.RehearsalMark.font-size = 3
  %% Change to a font available on your computer
  \override Score.RehearsalMark.font-name = "Linux Libertine"
  \override Score.RehearsalMark.color = #(x11-color "red")
  %% These two lines work around spurious failures that have been fixed
  %% in LilyPond 2.23.x. They occur in LilyPond 2.22 if X-offset and
  %% Y-offset are not overridden/tweaked.
  \override Score.RehearsalMark.X-offset = 0
  \override Score.RehearsalMark.Y-offset = 0

  \repeat unfold 4 {  c8 d e f g f e d } \break

  \tweak X-offset 2 \tweak Y-offset -8 \mark \markup \box "Testing 123"

\repeat unfold 4 { c8 d e f g f e d  } \break
}
%----------------------------------------------------
\score {
    \new Staff { \melody }
    \layout { }
}
%----------------------------------------------------



As you can see, you can use overrides and/or tweaks to change the properties,
so when you don't want any change from the default values, you don't have
to write out the defaults every time.

About the whiteout issue: LilyPond draws each object on a certain layer.
Most objects are on layer 1. The order in which objects from the same
layer are drawn is not specified. So you need to move the RehearsalMark
a few layers up so that it is drawn on top of other objects, by adding

\override Score.RehearsalMark.layer = 5


A final note: are you aware of this LSR snippet?

https://lsr.di.unimi.it/LSR/Item?id=1000

Best,
Jean




reply via email to

[Prev in Thread] Current Thread [Next in Thread]