lilypond-user
[Top][All Lists]
Advanced

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

Re: flam snippet not working


From: Thomas Morley
Subject: Re: flam snippet not working
Date: Sat, 17 Aug 2013 01:40:39 +0200

2013/8/16 David Kastrup <address@hidden>:
> David Kastrup <address@hidden> writes:
>
>> Roel Spruit <address@hidden> writes:
>>> flam =
>>> #(define-music-function (parser location note) (ly:music?)
>>>    "Return { \\grace { note8 } note }."
>>>    (let ((mypitch (ly:music-property (first (ly:music-property note 
>>> 'elements))
>>>                                      'drum-type)))
>>>      (make-sequential-music
>>>       (list (make-grace-music
>>>              (make-sequential-music
>>>               (list
>>>                (context-spec-music
>>>                 (make-grob-property-set 'Stem
>>>                                         'stroke-style "grace")
>>>                 'Bottom)
>>>                (make-event-chord
>>>                 (list (make-music 'NoteEvent
>>>                                   'duration (ly:make-duration 3 0 1 1)
>>>                                   'drum-type mypitch))))))
>>>             note))))
>>
>> Try something like
>> flam =
>> #(define-music-function (parser location note) (ly:music?)
>>   "Return { \\slashedGrace { note8 } note }."
>>   #{ \slashedGrace {
>>      $(let ((m (ly:music-deep-copy note)))
>>         (set! (ly:music-property m 'duration)
>>               (ly:make-duration 3 0 1 1))
>>         m) } $m #})
>
> Somewhat more robust in the presence of chords etc:
>
> flam =
> #(define-music-function (parser location note) (ly:music?)
>   "Return { \\slashedGrace { note8 } note }."
>   #{ \slashedGrace {
>        $(map-some-music
>           (lambda (m)
>             (and (ly:duration? (ly:music-property m 'duration))
>                  (begin
>                    (set! (ly:music-property m 'duration)
>                          (ly:make-duration 3 0 1 1))
>                    m)))
>           (ly:music-deep-copy note)) }
>        $m #})
>
> --
> David Kastrup
>
>
> _______________________________________________
> lilypond-user mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/lilypond-user

Hi Roel,

I took David's proposal (many thanks) and rewrote the whole snippet.
It now works with \drummode and \notemode for 2.16.2 and 2.17.24.
I added a more generic function
\grace-repeat
which offers the possibility to specify any number of repetitins and
to switch between repeating the first (written) note of the chord and
the whole one.
I feel not very convinced about the way I inserted the beaming,
though, at least it works.


\version "2.16.2"
% Also, working with:
% \version "2.17.24"

#(define (grace-from-main-note chord? lngth music)
  (let* ((mus (if (music-is-of-type? music 'event-chord)
                  (first (ly:music-property music 'elements))
                  music))
         (note (map-some-music
                  (lambda (m)
                    (and (ly:duration? (ly:music-property m 'duration))
                         (begin
                           (set! (ly:music-property m 'duration)
                                 (ly:make-duration (if (> lngth 1) 4 3) 0 1 1))
                           m)))
                  (ly:music-deep-copy (if chord? music mus))))
         (next-note (ly:music-deep-copy note))
         (last-note (ly:music-deep-copy note))
         (m-list
           (flatten-list
             (list note
                   (make-list (max 0 (- lngth 2)) next-note)
                   last-note))))

  (cond ((= lngth 1 )
           note)
        ((> lngth 1)
           (list-set!  m-list 0
             (begin
                (ly:music-set-property!
                    note
                    'articulations
                    (list (make-music
                           'BeamEvent
                           'span-direction -1)))
                 note))
           (list-set!  m-list (- lngth 1)
             (begin
                (ly:music-set-property!
                    last-note
                    'articulations
                    (list (make-music
                           'BeamEvent
                           'span-direction 1)))
                last-note))
            (make-music 'SequentialMusic 'elements m-list)))))


flam =
#(define-music-function (parser location note) (ly:music?)
  "Return { \\slashedGrace { note8 } note }.
  If @var{note} is a chord the first written note of it is used.
  "
  #{
    \slashedGrace {  $(grace-from-main-note #f 1 note) }
    $note
  #})

drag =
#(define-music-function (parser location note) (ly:music?)
  "Return { \\slashedGrace { note16[  note16] } note }.
  If @var{note} is a chord the first written note of it is used."
  #{
    \slashedGrace {  $(grace-from-main-note #f 2 note) }
    $note
  #})

ruff =
#(define-music-function (parser location note) (ly:music?)
  "Return { \\slashedGrace { note16[ note16 note16] } note }.
  If @var{note} is a chord the first written note of it is used."
  #{
    \slashedGrace {  $(grace-from-main-note #f 3 note) }
    $note
  #})

grace-repeat =
#(define-music-function (parser location chord-repeat? how-much note)
  ((boolean? #f) integer? ly:music?)
  "Return @var{note} preceded by repeated and beamed grace-notes. The number of
  grace-notes is specified by @var{how-much}.
  If @var{note} is a chord the first written note of it is used.
  If @var{chord-repeat?} is specified the whole chord is repeated during
  @code{GraceMusic}"
  #{
    \slashedGrace {  $(grace-from-main-note chord-repeat? how-much note) }
    $note
  #})


\new DrumStaff {
  \new DrumVoice \drummode {
    r4 \flam sn4 \drag cymr4 \ruff bd4
    \flam <sn bd>2 \flam <bd sn>2
    \grace-repeat ##t #4 <bd sn>1
  }
}

\new Staff
\relative c' {
    \flam c \drag d \ruff e \grace-repeat #4 f
    \flam <c f>
    \drag <f c>
    \ruff <c f>
    \grace-repeat  #4 <f c>
    \grace-repeat  #5 <c f>
    \grace-repeat ##t #6 <f c>
}


HTH,
  Harm



reply via email to

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