[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Stem.stem-begin-position not giving desired output on beamed stems (
From: |
Carl Williams |
Subject: |
Re: Stem.stem-begin-position not giving desired output on beamed stems (tablature) |
Date: |
Mon, 19 Dec 2016 08:44:49 +1300 |
User-agent: |
Mailbird/2.3.36.0 |
Thanks Harm,
Then remove it there.
Yes, for some reason that flew over my head. Probably because it wasn't styled
correctly ;)
One question on styling, which is correct?
I think the first, considering rule 3: closing parenthesis close the line.
(/ (+ start-in (- (abs length-in)
thickness))
2)
or
(/ (+ start-in (- (abs length-in)
thickness)) 2)
or
(/ (+ start-in (- (abs length-in) thickness)) 2)
(let*
;; TODO returns 'direction always correctly?
((dir (ly:grob-property grob 'direction))
(position
(/ (+ (abs start-in)
(- (abs length-in)
(ly:grob-property grob 'beam-thickness)))
(* dir 2))))
This bit gave funny results when start-position was below, but direction was
up, so I just used what I have. Sure using if is another step, but it ain't
broke ;)
Here it is now:
beam-stem-height =
#(define-music-function (parser location start-in length-in)(number? number?)
"Takes a list containing values for:
- the stem-start in Y-direction
- the stem-length
Values can be positive or negative, depending on direction
but may produce a warning if only one value is negative:
'warning: weird stem size, check for narrow beams'
"
#{
\override Stem.direction = #(if (positive? length-in) UP DOWN)
\override Stem.stem-begin-position = #start-in
\override Stem.length = #(abs length-in)
\override Beam.after-line-breaking =
#(lambda (grob)
(let ((stems (ly:grob-array->list (ly:grob-object grob 'stems))))
(for-each
(lambda (stem)
(ly:stem::calc-stem-begin-position stem)
(ly:grob-set-property! stem 'length (abs length-in))
(ly:grob-set-property! stem 'stem-begin-position start-in))
stems)))
\override Beam.before-line-breaking =
#(lambda (grob)
(let* ((thickness (ly:grob-property grob 'beam-thickness))
(position (if (positive? length-in)
(/ (+ start-in (- (abs length-in)
thickness))
2)
(/ (- start-in (- (abs length-in)
thickness))
2))))
(ly:grob-set-property! grob 'positions (cons position position))))
#})
Thanks,
Carl
On 19/12/2016 00:43:52, Thomas Morley <address@hidden> wrote:
Hi Carl,
2016-12-18 8:26 GMT+01:00 Carl Williams :
> One more little adjustment, for anyone who will benefit from it.
> The previous version only overrode Beam.positions on the first line. After a
> line break they go back to how they were if by default.
> I don't quite understand why, but the solution was to move that section
> under a before-line-breaking section rather than after-line-breaking.
Then remove it there.
I missed to take 'beam-thickness into account. Good catch.
Your code can be shortened to the below, probably even more (depending
on your final goal)
beam-stem-height =
#(define-music-function (parser location start-in length-in)(number? number?)
"Takes a list containing values for:
- the stem-start in Y-direction
- the stem-length
Values can be positive or negative, depending on direction
but may produce a warning if only one value is negative:
'warning: weird stem size, check for narrow beams'
"
#{
\override Stem.direction = #(if (positive? length-in) UP DOWN)
\override Stem.stem-begin-position = #start-in
\override Stem.length = #(abs length-in)
\override Beam.after-line-breaking =
#(lambda (grob)
(let ((stems (ly:grob-array->list (ly:grob-object grob 'stems))))
(for-each
(lambda (stem)
(ly:stem::calc-stem-begin-position stem)
(ly:grob-set-property! stem 'length (abs length-in))
(ly:grob-set-property! stem 'stem-begin-position start-in))
stems)))
\override Beam.before-line-breaking =
#(lambda (grob)
(let*
;; TODO returns 'direction always correctly?
((dir (ly:grob-property grob 'direction))
(position
(/ (+ (abs start-in)
(- (abs length-in)
(ly:grob-property grob 'beam-thickness)))
(* dir 2))))
(ly:grob-set-property! grob 'positions (cons position position))))
#})
Cheers,
Harm
P.S.
Your code doesn't follow the recommended style, makes it harder to follow.
Please read
http://community.schemewiki.org/?scheme-style