Hi David,
thank you very much, actually it *did* help me a lot.
First to understand why my previous approaches just *could* not work.
Then (hopefully) to understand how it can work.
I had a hard time to incorporate it into my real function because I
didn't realize that LilyPond can't distinguish between a symbol and a
string/markup for the first arguments: I had a markup? argument as
second argument, and Lily took this for the first argument. However,
moving the markup? argument behind the context-mod argument solved that too.
I'll eventually post the final file, although I'm afraid it's slightly
too project specific to even be included in openlilylib (at least
without some fundamental changes.
Best
Urs
Am 03.11.2014 22:07, schrieb David Nalesnik:
Hi Urs,
I'll try to address your first problem--which is pretty tricky!
On Mon, Nov 3, 2014 at 11:06 AM, Urs Liska <[email protected]
<mailto:[email protected]>> wrote:
Hi Scheme wizards, can you help me?
I have two unrelated questions regarding the attached file.
It is a very much stripped down version of a function actually in use.
It takes an annotation from the input file, produces a clickable
message on the console and colors the affected object. (In reality
it does and will do more, but that's what's necessary for the
example/question).
###
The first question should be quite simple, but I don't seem to
find a solution on my own: How can I make the function be able to
affect only selected items, e.g. only one note of the chord in the
example (or only a specific tie etc.)
This is hard to explain, and I'm afraid I'm not going to do a good job
of it.
The issue here is that your function needs to be able to distinguish
between tweaks and overrides. Ideally, it should also be able to
handle basic and directed tweaks.
The predicate for the last argument, ly:symbol-list-or-music?, is
there to distinguish between tweak and override, and it is used in
several functions for this purpose (\shape, \offset, and \alterBroken
are those I know about). If what follows is music, we get a tweak, if
there is a symbol-list we get an override.
Since that variable needs to be fed either NoteHead in your example or
a music expression, and you need NoteHead to specify the grob you want
in a directed tweak, I added an optional variable, for use with the
directed tweak form. For a regular tweak, you just leave out that
initial NoteHead.
This makes for a bit of awkwardness when you want to specify the
object of your tweak and not let LilyPond determine it for you, but I
don't see any other way.
Hope this helps,
David
%%%%%%%%%%%%%%%%%
\version "2.18.2"
annotate =
#(define-music-function (parser location name properties item)
((symbol?) ly:context-mod? symbol-list-or-music?)
;; annotates a musical object for use with lilypond-doc
(let
(
;; create dummy alist (is that necessary?)
(props '( )))
;; Add or replace props entries taken from the properties argument
(map (lambda (mod) (set! props
(assoc-set! props
(symbol->string (cadr mod)) (caddr mod))))
(ly:get-context-mods properties))
;; produce a clickable message
(ly:input-message location "Annotation")
;; Print a message with all properties to the console
(map (lambda (prop)
(ly:message (format " ~a: ~a" (car prop) (cdr prop))))
props)
(ly:message "\n"))
;; Color the affected grob
(cond
((and (ly:music? item) (symbol? name))
#{
\tweak #`(,name color) #darkgreen #item
#})
((ly:music? item)
#{
\tweak color #darkgreen #item
#})
(else
#{
\once \override #item #'color = #darkgreen
#})))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Usage examples
% OVERRIDE SYNTAX
{
\annotate \with {
author = "Urs Liska"
message = "Important information"
} NoteHead
<c' e' g'>-> d' e'
}
% BASIC TWEAK
{
<c'
\annotate \with {
author = "Urs Liska"
message = "Important information"
}
e' g'>-> d' e'
}
% DIRECTED TWEAK
{
<c'
\annotate NoteHead \with {
author = "Urs Liska"
message = "Important information"
}
e' g'>-> d' e'
}
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user