Wow, cool!

Can you give a quick hint why this isn't possible to implement as an \override?

Attached you'll find a function that AFAIR you provided too, which displays the control points of curves. This new function would be a great companion for that, but it would of course be nice if they could be used consistently.

BTW we're preparing the release of a LilyPond toolbox library (where \displayControlPoints will be included of course), and I'd love to include this new one there too.

Best
Urs

Am 26.03.2013 00:34, schrieb Thomas Morley:
2013/3/25 Thomas Morley <thomasmorle...@googlemail.com>:
2013/3/24 Janek Warcho? <janek.lilyp...@gmail.com>:

On Sun, Mar 24, 2013 at 3:02 AM, Thomas Morley
<thomasmorle...@googlemail.com> wrote:
this is great!!
[...]
Could i ask you to write a function that would print a red dot on top
of a grob's refpoint?  (the image i've attached was made with GIMP,
and it would be better to have it in lily code.  I'm sure this would
be simple for you.)
Sometimes simple things are the most difficult. :)

Will try the upcoming days.
Hi Janek,

functions below as desired. :)

Usage:
\printRefpoint <boolean> <arg>
<arg> may be a single grob-name-symbol or a list of grob-names or 'all-grobs
Setting <boolean> #t will result in an additional text, printing the
grob-name. Enabling it will result in possible
overlappings.
Due to issue 3255 the output will be strange, while using a newer devel-version.

I didn't manage to apply \printRefpoint only once. Hints?
Therefore I provide a second method.

More comments in code.


\version "2.16.2"

#(set-global-staff-size 20)

#(define (add-dot text?)
   (lambda (grob)
       (let* ((layout (ly:grob-layout grob))
              (props (layout-extract-page-properties layout))
              (font
                (ly:paper-get-font layout
                  (cons '((font-encoding . fetaMusic)) props)))
              ;; Get the stencil-procedure from ly:grob-basic-properties.
              ;; If any, use it to create the stencil.
              (function (assoc-get 'stencil (ly:grob-basic-properties grob)))
              (stencil (if function (function grob) point-stencil))
              ;; Get the grob-name and create a text-stencil.
              ;; Read out the y-length for later translate.
              (grob-name-proc
                 (lambda (x) (assq-ref (ly:grob-property x 'meta) 'name)))
              (grob-name (grob-name-proc grob))
              (grob-string (if (symbol? grob-name)
                               (symbol->string grob-name)
                               "no name"))
              (ref-text-stil (grob-interpret-markup grob
                                   (markup
                                      #:with-color red
                                      #:normal-text
                                      #:abs-fontsize 6
                                      (string-append "   " grob-string))))
              (ref-text-stil-length
                 (interval-length (ly:stencil-extent ref-text-stil Y)))
              (grob-string-stil (if text? (grob-interpret-markup grob
                                   (markup
                                      #:with-dimensions '(0 . 0) '(0 . 0)
                                      #:stencil
                                      ref-text-stil))
                                      point-stencil
                                      ))
              ;; Create a red-dot-stencil
              (dot (ly:font-get-glyph font "dots.dot"))
              (red-dot (ly:stencil-in-color dot 1 0 0))
              (red-dot-length
                 (interval-length (ly:stencil-extent red-dot X)))
              (red-dot-stil
                 (ly:stencil-translate-axis red-dot (/ red-dot-length -2) X)))

       ;; If there's a grob with stencil-procedure and a valid stencil is
       ;; created, add the red-dot-stil and an optional text-stencil.
       (if (and function (ly:stencil? stencil) (grob::is-live? grob))
           (ly:grob-set-property! grob 'stencil
             (ly:stencil-add
               stencil
               red-dot-stil
               (if text?
                 (ly:stencil-translate-axis
                   (ly:stencil-rotate
                     grob-string-stil
                     90 0 0)
                     (/ ref-text-stil-length 2)
                     X)
                 point-stencil)))))))

% needs to be here for 2.16.2
#(define-public (symbol-list-or-symbol? x)
   (if (list? x)
       (every symbol? x)
       (symbol? x)))

#(define (add-red-dot-to-grobs text? l)
  ;; possible values for l:
  ;;   'all-grobs (adds red-dots to all grobs, where possible)
  ;;          this will naturally cause collisions,
  ;;   a single grob-name, must be a symbol,
  ;;   a list of grob-names,
  ;;   anything else (returns the unchanged original stencil)
  ;;  TODO: How to apply it once?
   (let ((grobs-to-consider
           (cond ((eq? l 'all-grobs)
                   all-grob-descriptions)
                 ((symbol? l)
                   (list (assoc l all-grob-descriptions)))
                 ((list? l)
                   (map
                     (lambda (grob)
                       (assoc grob all-grob-descriptions))
                       l))
                 (else '()))))
   (lambda (context)
    (let loop ((x grobs-to-consider))
     (if (not (null? x))
      (let ((grob-name (caar x)))
       (ly:context-pushpop-property
          context
          grob-name
          'after-line-breaking
          (add-dot text?))
       (loop (cdr x))))))))

printRefpoint =
#(define-music-function (parser location text? s-or-l)(boolean?
symbol-list-or-symbol?)
"
  Will add a red dot (and an optional text) to the stencil's ref-point of the
  specified grob(s).
  Valid input for s-or-l:
       @code{'all-grobs}, (adds red-dots to all grobs, where possible), this 
will
           naturally cause collisions
       a single grob-name, must be a symbol,
       a list of grob-names.
  The additional text may be activated by @code{##t}.
  To avoid bleeding-overs any context has to be initiated explicitly.
"
#{
         \applyContext #(add-red-dot-to-grobs text? s-or-l)
#})

%% For single use:

#(define addDot
   (lambda (grob)
       (let* ((function (assoc-get 'stencil (ly:grob-basic-properties grob)))
              (stencil (if function (function grob) point-stencil))
              (layout (ly:grob-layout grob))
              (props (layout-extract-page-properties layout))
              (font
                (ly:paper-get-font layout
                  (cons '((font-encoding . fetaMusic)) props)))
              (dot (ly:font-get-glyph font "dots.dot"))
              (red-dot (ly:stencil-in-color dot 1 0 0))
              (red-dot-length (interval-length (ly:stencil-extent red-dot X)))
              (red-dot-stil
                 (ly:stencil-translate-axis red-dot (/ red-dot-length -2) X)))

       (if (and function (ly:stencil? stencil) (grob::is-live? grob))
           (ly:grob-set-property! grob 'stencil
             (ly:stencil-add
               stencil
               red-dot-stil))))))

%% Overriding grobs must be defined separately.
%% Don't forget to specify the context if necessary.
onceRedScript = \once \override Script #'after-line-breaking = #addDot

%%%%%%%%%%%%
%%% EXAMPLES
%%%%%%%%%%%%

mus =
{
         \override NoteHead #'style = #'altdefault
         g'2->
         % Testing if \printRefpoint works with a custom-override.
         \once \override Script #'stencil =
           #(lambda (grob)
              (ly:font-get-glyph (ly:grob-default-font grob) "scripts.coda"))

         c''\fermata |
         as'1^"Yogi" |
         b'\breve _"Larry" |
         \mark "Twinkle" e''8 s4.
         \bar "|."
}


\markup "Red dots are added for TimeSignature, Script, BarLine"
\new Staff \with { \printRefpoint ##f #'(TimeSignature Script BarLine) } \mus

\markup "Red dots are added for TextScript plus additional text"
\new Staff \with { \printRefpoint ##t #'TextScript } \mus

\markup "Red dots are added for all grobs"
\new Staff \with { \printRefpoint ##f #'all-grobs } \mus

\markup "Red dots are added for all grobs plus additional text"
\new Staff \with { \printRefpoint ##t #'all-grobs } \mus

\markup "Red dot is added once to Script using \\onceRedScript"
{
         \override NoteHead #'style = #'altdefault
         g'2->
         \onceRedScript
         % Testing if \printRefpoint works with a custom-override.
         \once \override Script #'stencil =
           #(lambda (grob)
              (ly:font-get-glyph (ly:grob-default-font grob) "scripts.coda"))
         c''\fermata |
         as'1^"Yogi" |
         b'\breve _"Larry" |
         \mark "Twinkle" e''8-| s4.
         \bar "|."
}


Code and png are attached, too.

Regards,
   Harm


_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

\version "2.17.3"
% ulLibrary/curvesToolbox/debugCurves.ily


#(define (make-cross-stencil coords)
 (ly:stencil-add
   (make-line-stencil 0.1 (- (car coords) 0.2) (- (cdr coords) 0.2)
  (+ (car coords) 0.2) (+ (cdr coords) 0.2))
   (make-line-stencil 0.1 (- (car coords) 0.2) (+ (cdr coords) 0.2)
  (+ (car coords) 0.2) (- (cdr coords) 0.2))))

#(define (display-control-points)
 (lambda (grob)
   (let* ((grob-name (lambda (x) (assq-ref (ly:grob-property x 'meta) 'name)))
          (name (grob-name grob))
          (stil (cond ((or (eq? name 'Slur)(eq? name 
'PhrasingSlur))(ly:slur::print grob))
                      ((eq? name 'Tie)(ly:tie::print grob))))
          (cps (ly:grob-property grob 'control-points)))

          (ly:stencil-add stil
            (ly:stencil-in-color
              (ly:stencil-add
                (make-cross-stencil (second cps))
                (make-cross-stencil (third cps))
                )
            1 0 0) ; color is hard-coded here (R G B).
                   ; modify to change the color of the crosses
 
          (ly:stencil-in-color
            (ly:stencil-add
            (make-line-stencil 0.05 
                (car (first cps)) (cdr (first cps))
                (car (second cps))  (cdr (second cps)))
            ;(make-line-stencil 0.05 (car (second cps)) (cdr (second cps)) (car 
(third cps))  (cdr (third cps)))
            (make-line-stencil 0.05 
                (car (third cps)) (cdr (third cps))
                (car (fourth cps))  (cdr (fourth cps)))
            )
            1 0 0) ; color is hard-coded here (R G B).
                   ; modify to change the color of the lines
          empty-stencil)
     )
     ))

% The following functions work in the current context
% So you can place it in the music input and modify the
% following music.

% Switch on the display of control-points for the current Voice
displayControlPoints = {
  \override Slur #'stencil = #(display-control-points)
  \override PhrasingSlur #'stencil = #(display-control-points)
  \override Tie #'stencil = #(display-control-points) 
}

%FIXME: This doesn't seem to work
% How can I set it back to normal behaviour?
% 
% Switch the display of control-points off again
hideControlPoints = {
  \revert Slur #'stencil 
  \revert PhrasingSlur #'stencil
}

% display the control-points of the following curve
% (Slur, PhrasingSlur or Tie).
% This is probably the most common function,
% place immediately before the start of the curve
displayControlPointsOnce = {
  \once \override Slur #'stencil = #(display-control-points)
  \once \override PhrasingSlur #'stencil = #(display-control-points)
  \once \override Tie #'stencil = #(display-control-points) % commenting this 
out gives an error
}

% Switch on the display of the control-points globally
% Place in a \layout block
debugCurvesOn = \layout {
  \context {
    \Score
    \override Slur #'stencil = #(display-control-points)
    \override PhrasingSlur #'stencil = #(display-control-points)
    \override Tie #'stencil = #(display-control-points) 
  }
}

testDebugCurves = {
  \override Slur #'stencil = #(display-control-points)
  \override PhrasingSlur #'stencil = #(display-control-points)
  \override Tie #'stencil = #(display-control-points) 
}
        
\version "2.17.3"
%{PROJECT:
        This file belongs to the project
                "Oskar Fried. Complete Lieder"
                edited from the original prints by Urs Liska and Alexander 
Gurdon (m...@ursliska.de, alexander.gur...@tu-dortmund.de)
%}

%{TYPE:
        This file is part of the global configuration
%}

%{FILE:
        This file globally switches on the display of control-points
        To achieve this, just include this file as a top level include
        Alternatively (and usually preferrable) use 
        \display[Once]ControlPoints[WithLines] to show selected control-points
        
%}

% TODO: clean up comments
% Add "Part of curvesToolbox"


% DEPRECATED
% This shouldn't be used anymore and is only present
% for compatibility with existing scores.
% Please use
% \layout { \debugCurvesOn }
% somewhere in the (master) file
% 

\layout {
  \context {
    \Score
    \override Slur #'stencil = #(display-control-points)
    \override PhrasingSlur #'stencil = #(display-control-points)
    \override Tie #'stencil = #(display-control-points) 
  }
}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to