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 <u...@openlilylib.org> 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
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to