Re: Using circles in \tabFullNotation

2021-02-04 Thread Jean Abou Samra



Le 05/02/2021 à 06:15, Kuredant a écrit :

On 1/31/2021 10:41 PM, Jean Abou Samra wrote:

Sorry, this line:

    \override Stem.Y-extent = #grob::always-Y-extent-from-stencil

should have been commented out.

Also, I now believe that the behavior of X-offset here is a bug:

https://lists.gnu.org/archive/html/bug-lilypond/2021-01/msg00014.html

Jean


That's awesome. It's even possible to easily tweak the shape of the 
circle.


I'll try to do some more research regarding Scheme since I don't 
understand everything that's going on.



Here are some useful resources:

https://scheme-book.ursliska.de/introduction/index.html

https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-4.html

Feel free to ask questions!



Thanks again for all your help.


You are welcome.

Jean




Re: Using circles in \tabFullNotation

2021-02-04 Thread Kuredant

On 1/31/2021 10:41 PM, Jean Abou Samra wrote:

Sorry, this line:

    \override Stem.Y-extent = #grob::always-Y-extent-from-stencil

should have been commented out.

Also, I now believe that the behavior of X-offset here is a bug:

https://lists.gnu.org/archive/html/bug-lilypond/2021-01/msg00014.html

Jean


That's awesome. It's even possible to easily tweak the shape of the circle.

I'll try to do some more research regarding Scheme since I don't 
understand everything that's going on.


Thanks again for all your help.




Re: Using circles in \tabFullNotation

2021-01-31 Thread Jean Abou Samra

Sorry, this line:

    \override Stem.Y-extent = #grob::always-Y-extent-from-stencil

should have been commented out.

Also, I now believe that the behavior of X-offset here is a bug:

https://lists.gnu.org/archive/html/bug-lilypond/2021-01/msg00014.html

Jean




Re: Using circles in \tabFullNotation

2021-01-30 Thread Jean Abou Samra

Hi,

(Also forwarding to the list, please keep it in CC.)


Le 30/01/2021 à 16:57, Kuredant a écrit :

Thanks a lot! I wouldn't have been able to come up with that myself.

The code works very well, especially for chords.

I have two minor issues:

– The stem is right below the lowest fret number, but I'd like it in 
the middle of the circle.


– The overrides apply to all notes regardless of their lengths (e.g. 
quarter notes also have a circle around them). For this issue I think 
I can check the source code for \tabFullNotation.


This shouldn't be too complex so I'll try to figure it out for myself.

> 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).

I didn't know how to change the horizontal position of a single 
TabNoteHead, thanks. My images come from a Japanese tab I scanned. I 
just wanted to mimic its style.



Here is a new version.

Beware that I am coding to my maximum capacity. In particular, I don't 
at all understand why LilyPond behaves the way it does in some parts of 
the code (see the comments).


As you say, the two issues were not all too complex (when you know the 
functions at hand). However, after quite some time messing up with pure 
and unpure calls, I have not found a proper solution to handle the 
extents. Thus, you will have to do a very bit of manual spacing when 
dots are present.


Maybe someone on this list can explain what is happening with X-offset 
(or maybe it will become obvious to me tomorrow).


Best,
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?)
#(set-object-property! 'is-special 'backend-type? boolean?)


#(define (calc-stem-is-special stem)
   "Only stems for half and whole notes are made special."
   (let* ((cause (event-cause stem))
  (duration (ly:event-property cause 'duration)))
 (>= 1 (ly:duration-log duration


% 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 (coords-for-axis stem 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))

#(define (custom-stem-stencil stem)
   "Draw a stem and an oval around all note heads found."
   (if
 (not (ly:grob-property stem 'is-special))
 (ly:stem::print stem)
 (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))
    ; The note heads have their X-offset property set
    ; by the \tweaks. Why the hell is it always zero
    ; here?
    ;(nothing
    ;   (for-each (lambda (note-head)
    ; (ly:message "~s" (ly:grob-property note-head 
'X-offset)))

    ; note-heads))
    (relative-x-coords (coords-for-axis stem note-head-array 
note-heads X))
    (relative-y-coords (coords-for-axis stem note-head-array 
note-heads Y))

    (stencils (map tab-note-head::print note-heads))
    (coord-pairs (map cons relative-x-coords relative-y-coords))
    (translated-stencils (map ly:stencil-translate stencils 
coord-pa

Using circles in \tabFullNotation

2021-01-29 Thread Jean Abou Samra

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
  2.
}

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