lilypond-user
[Top][All Lists]
Advanced

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

Using circles in \tabFullNotation


From: Jean Abou Samra
Subject: Using circles in \tabFullNotation
Date: Fri, 29 Jan 2021 18:35:52 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0

Hello,

I'm trying to have an output similar to the attached images when using \tabFullNotation: half-notes and chords circled with a single stem and whole notes and chords circled with no stem. Reading the source code for \tabFullNotation, I think I need to \override TabStaff.Stem.stencil with a custom Scheme function, but I'm note sure how to do that. Can someone point me in the right direction?

Hi,

Your hunch is correct. Try this somewhat experimental
code (note that I am not sure how you are positioning the
TabNoteHead grobs horizontally, I used an X-offset).

Regards,
Jean


\version "2.23.0"

% Define new grob properties used for Stem

#(set-object-property! 'oval-thickness 'backend-type? number?)
#(set-object-property! 'oval-x-padding 'backend-type? number?)
#(set-object-property! 'oval-y-padding 'backend-type? number?)

% Amended from scm/stencil.scm, to use #t for filling

#(define (filled-oval-stencil stencil thickness x-padding y-padding)
  (let* ((x-ext (ly:stencil-extent stencil X))
         (y-ext (ly:stencil-extent stencil Y))
         (x-length (+ (interval-length x-ext) x-padding thickness))
         (y-length (+ (interval-length y-ext) y-padding thickness))
         (x-radius (* 0.707 x-length) )
         (y-radius (* 0.707 y-length) )
         (oval (make-oval-stencil x-radius y-radius thickness #! #f !# #t)))
    (ly:stencil-add
     stencil
     (ly:stencil-translate oval
                           (cons
                            (interval-center x-ext)
                            (interval-center y-ext))))))

#(define (custom-stem-stencil stem)
   "Draw a stem and an oval around all note heads found."
   (define (coords-for-axis note-head-array note-heads axis)
     "Compute relative coordinates of note heads
      relative to the stem along given axis."
     (let* ((refpoint(ly:grob-common-refpoint-of-array stem note-head-array axis))
            (note-head-coords (map (lambda (note-head)
                                 (ly:grob-relative-coordinate
                                   note-head
                                   refpoint
                                   axis))
                         note-heads))
            (stem-coord (ly:grob-relative-coordinate
                          stem
                          refpoint
                          axis))
            (scaled-coords (map (lambda (coord)
                                  (- coord stem-coord))
                                note-head-coords)))
       scaled-coords))
           
   (let* ((stem-stencil (ly:stem::print stem))
          (oval-thickness (ly:grob-property stem 'oval-thickness))
          (oval-x-padding (ly:grob-property stem 'oval-x-padding))
          (oval-y-padding (ly:grob-property stem 'oval-y-padding))
          (note-head-array (ly:grob-object stem 'note-heads))
          (note-heads (ly:grob-array->list note-head-array))
          (scaled-x-coords (coords-for-axis note-head-array note-heads X))
          (scaled-y-coords (coords-for-axis note-head-array note-heads Y))
          (stencils (map (lambda (note-head)
                           (tab-note-head::print note-head))
                         note-heads))
          (translated-stencils (map (lambda (stencil x y)
                                      (ly:stencil-translate
                                        stencil
                                        (cons x y)))
                                    stencils
                                    scaled-x-coords
                                    scaled-y-coords))
          (combo-stencil (apply ly:stencil-add translated-stencils)))
     (ly:stencil-add
       stem-stencil
       (stencil-with-color
         (filled-oval-stencil combo-stencil oval-thickness oval-x-padding oval-y-padding)
         white)
       (oval-stencil combo-stencil oval-thickness oval-x-padding oval-y-padding))))

\layout {
  \context {
    \TabVoice
    \override Stem.stencil = #custom-stem-stencil
   
    % You can set these.
    \override Stem.oval-thickness = 0.1
    \override Stem.oval-x-padding = 0.75
    \override Stem.oval-y-padding = 0.75
   
    % The oval is drawn over the stem. Lower the layer to prevent
    % it from going over the staff symbol too.
    \override Stem.layer = -1
   
    % Override default extent calculations, because those do not
    % actually use the stencil.
    \override Stem.X-extent = #'(0 . 0)
    \override Stem.Y-extent = #(ly:make-unpure-pure-container grob::always-Y-extent-from-stencil)
   
    % Add a bit of padding on the right of TabNoteHead to
    % account for the right side of the oval. This is required
    % for proper alignment of dots.
    \override TabNoteHead.X-extent = #'(-1 . 2)
  }
}


symbols = {
  \time 3/4
  <a \tweak X-offset 0.7 e'>2.
}

\score {
  \new TabStaff {
    \tabFullNotation
    \symbols
  }
}


reply via email to

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