lilypond-user
[Top][All Lists]
Advanced

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

Re: Triplets


From: Richard Shann
Subject: Re: Triplets
Date: Sat, 14 Jan 2017 21:29:52 +0000

On Sat, 2017-01-14 at 20:51 +0000, J Martin Rushton wrote:
> 
> On 14/01/17 19:57, Richard Shann wrote:
> > On Sat, 2017-01-14 at 18:14 +0000, J Martin Rushton wrote:
> >> Hi,
> >> I'm trying to set a melody from a 19thC source as closely as possible to
> >> the original.  Triplets are indicated with a curved bracket rather than
> >> the square one Lily uses by default.  I've come up with a mechanism:
> >>
> >> \relative c'' {
> >>   \tupletUp
> >>   \override TupletBracket.bracket-visibility = ##f
> >>   \tuplet 3/2 { c8( c c ) }
> >> }
> >>
> >> but using a slur in this way seems wrong.  Is there a better way? 
> > 
> > yes!
> > 
> >>  I'm
> >> using Lily 2.14 in this instance.
> > That might be a problem. The solution lies in some code posted a month
> > or two back on this list:
> > 
> > tupletBracketToSlur = {
> >   % Use slur-stencil
> >   \\override TupletBracket.stencil = #ly:slur::print
> >   %% Use 'thickness from Slur
> >   \\override TupletBracket.thickness = #1.2
> >   %% 'control-points need to be set
> >   \\override TupletBracket.control-points =
> >     #(lambda (grob)
> >       (let* ((x-pos (ly:grob-property grob 'X-positions))
> >              (pos (ly:grob-property grob 'positions))
> >              (x-ln (interval-length x-pos))
> >              (dir (ly:grob-property grob 'direction))
> >              ;; read out the height of the TupletBracket, maybe
> > negative!
> >              (height (- (cdr pos) (car pos)))
> >              ;; height-corr is introduced because sometimes the shape of
> > the
> >              ;; slur needs to be adjusted.
> >              ;; It is used in the 2nd/3rd control-point.
> >              ;; The value of 0.3 is found by trial and error
> >              (height-corr (* 0.3 dir height))
> >              (edge-height (ly:grob-property grob 'edge-height '(0.7 .
> > 0.7)))
> >              (pad 1.0))
> >         (list
> >           ;; first cp
> >           (cons
> >             (+ (car x-pos) 0.5)
> >             (- (+ (* dir pad) (+ (car pos) (* -1 dir (car
> > edge-height))))
> >               (if (= dir -1)
> >                   (if (> height 3)
> >                     (/ dir 2.0)
> >                     0.0)
> >                   (if (< height -3)
> >                     (/ dir 2.0)
> >                     0.0))))
> >           ;; second cp
> >           (cons
> >             (+ (car x-pos) (* x-ln 1/4))
> >             (+ (* dir pad) (+ (car pos) (* dir (+ 0.5 height-corr)))))
> >           ;; third cp
> >           (cons
> >             (+ (car x-pos) (* x-ln 3/4))
> >             (+ (* dir pad) (+ (cdr pos) (* dir (- 0.5 height-corr)))))
> >           ;; fourth cp
> >           (cons
> >             (- (cdr x-pos) 0.5)
> >             (+ (* dir pad) (+ (cdr pos) (* -1 dir (cdr edge-height)))))
> >         )))
> >   \\override TupletBracket.staff-padding = #'()
> >   #(define (invert-direction x) (if (eq? UP
> > (ly:tuplet-bracket::calc-direction x)) DOWN UP))
> > \\override TupletBracket.direction = #invert-direction
> > }
> > 
> > 
> > then you put \tupletBracketToSlur in a \layout{ } block.
> > 
> > I've just cut-and-pasted this codefrom the command in Denemo that
> > inserts this stuff for you.
> > 
> > Richard
> 
> I've just cut and pasted that into the file and the first line starts
> throwing syntax errors:
> --------------%<------------
> Processing `.../file.ly'
> Parsing...
> .../file.ly:13:1: error: unrecognized string, not in text script or
> \lyricmode
> 
> tupletBracketToSlur = {
> .../file.ly:13:21: error: syntax error, unexpected '='
> tupletBracketToSlur
>                     = {
> .../file.ly:105:25: error: syntax error, unexpected '}'
> 
>                         }
> fatal error: failed files: ".../file.ly"
> 
> exited with status: 1
> -------------%<------------
> 
> I'm guessing things aren't that simple, can I mix scheme and LP in the
> same input file?  I don't have access to the code, this is embedded
> within a larger application.  At present all I have is a \relative { ...
> } block, all the meody lies within that.

Here's a complete working example:
8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><

%% LilyPond file generated by Denemo version 2.0.17

%%http://www.gnu.org/software/denemo/

\version "2.18.0"



tupletBracketToSlur = {
  % Use slur-stencil
  \override TupletBracket.stencil = #ly:slur::print
  %% Use 'thickness from Slur
  \override TupletBracket.thickness = #1.2
  %% 'control-points need to be set
  \override TupletBracket.control-points =
    #(lambda (grob)
      (let* ((x-pos (ly:grob-property grob 'X-positions))
             (pos (ly:grob-property grob 'positions))
             (x-ln (interval-length x-pos))
             (dir (ly:grob-property grob 'direction))
             ;; read out the height of the TupletBracket, maybe negative!
             (height (- (cdr pos) (car pos)))
             ;; height-corr is introduced because sometimes the shape of the
             ;; slur needs to be adjusted.
             ;; It is used in the 2nd/3rd control-point.
             ;; The value of 0.3 is found by trial and error
             (height-corr (* 0.3 dir height))
             (edge-height (ly:grob-property grob 'edge-height '(0.7 . 0.7)))
             (pad 1.0))
        (list
          ;; first cp
          (cons
            (+ (car x-pos) 0.5)
            (- (+ (* dir pad) (+ (car pos) (* -1 dir (car edge-height))))
              (if (= dir -1)
                  (if (> height 3)
                    (/ dir 2.0)
                    0.0)
                  (if (< height -3)
                    (/ dir 2.0)
                    0.0))))
          ;; second cp
          (cons
            (+ (car x-pos) (* x-ln 1/4))
            (+ (* dir pad) (+ (car pos) (* dir (+ 0.5 height-corr)))))
          ;; third cp
          (cons
            (+ (car x-pos) (* x-ln 3/4))
            (+ (* dir pad) (+ (cdr pos) (* dir (- 0.5 height-corr)))))
          ;; fourth cp
          (cons
            (- (cdr x-pos) 0.5)
            (+ (* dir pad) (+ (cdr pos) (* -1 dir (cdr edge-height)))))
        )))
  \override TupletBracket.staff-padding = #'()
  #(define (invert-direction x) (if (eq? UP (ly:tuplet-bracket::calc-direction 
x)) DOWN UP))
\override TupletBracket.direction = #invert-direction
}


\score { %Start of Movement
          <<

          %Start of Staff
          \new Staff   << 
 
                          \tuplet 3/2 { c''4 d'' e'' }
                    

                        >> %End of Staff

          >>
        
        \layout {
        \tupletBracketToSlur
        }

       } %End of Movement

8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><

HTH Richard





reply via email to

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