2013/4/1 luis jure <l...@internet.com.uy>

>
>
> hello list, i have yet another question regarding the definition of a
> custom drumstaff, and it is how to add a custom articulation.
>
> it's actually two questions, the first one is how to make custom
> articulations available inside #define mydrums().
>
> i managed to do that adding a custom articulation in script.scm, but
> somehow i fail to see how to put the definition in a separate file that i
> could include (script.scm will be rewritten every time i install lilypond)
>
> the second question later, if i manage to solve this...
>
>
>
> best,
>
>
> lj


Hi Luis,

below my approach.
Several comments in code, file and png attached.
Hope there are no problems, I tested it with 2.16.2 up to 2.17.16 from
latest master.

\version "2.16.2" %% and higher

%% Although, it is public I didn't manage to get full acces to
%% `default-script-alist´ from/scm/script.scm.
%% It is possible to modify the values, though, I couldn't create a new
entry.
%%
%% Anyway, working on a copy of `default-script-alist´ guarantees no
bleed-over.
#(define my-script-alist default-script-alist)

%% Some crazy stencils :)
#(define my-crazy-stil
 ;; A longish ellipse
  (ly:stencil-in-color
    (make-partial-ellipse-stencil 4 0.5 10 10 0.13 #t #t)
    1 0 0))

#(define my-crazy-stil-2
 ;; A small hexagon
  (let* ((th 0.1)
         ;; Value @code{6} returns a hexagon, try others.
         (alpha-step (/ (* 2 PI) 6))
         (alpha-start (/ alpha-step 2))
         (radius 0.7)
         (polypoints
           (let loop ((alpha alpha-start))
             (if (> alpha (* 2 PI))
                 '()
                 (cons (* (abs radius) (sin alpha))
                       (cons (- 0 (* (abs radius) (cos alpha)))
                             (loop (+ alpha alpha-step))))))))
  (ly:make-stencil `(polygon ',polypoints  ,th #f))))

%% Two alists with the name of the new articulation and its settings.
#(define my-wish-list-1
         `("ellipse"
           . (
              (avoid-slur . around)
          (padding . 0.20)
          (stencil . ,my-crazy-stil)
          ;(direction . ,DOWN)
          (side-relative-direction . ,DOWN))))

#(define my-wish-list-2
         `("hexagon"
           . (
              (avoid-slur . around)
          (padding . 0.40)
          (stencil . ,my-crazy-stil-2)
          ;(direction . ,DOWN)
          (side-relative-direction . ,DOWN))))

%% A macro setting the lists from above in the copy of
`default-script-alist´
%% I didn't manage to program some looping, mapping ... How to do?
%% For now, every new script has to be inserted in a single run.
#(define-macro (set-my-script-alist! ls-1 ls-2)
"Creates a new key-value-pair, taken from ls-2, in ls-1"
 `(set! ,ls-1
    (if (and (pair? ,ls-2) (pair? (cadr ,ls-2)))
        (assoc-set! ,ls-1 (car ,ls-2) (cdr ,ls-2))
        (begin
          (ly:warning (_"Unsuitable list\n\t~a \n\tdetected, ignoring. ")
,ls-2)
          ,ls-1))))

#(set-my-script-alist! my-script-alist my-wish-list-1)
#(set-my-script-alist! my-script-alist my-wish-list-2)

%% from
http://lists.gnu.org/archive/html/lilypond-user/2013-04/msg00009.html
alwaysPrintWholeLaThinBassDrum =
\override NoteHead #'duration-log =
  #(lambda (grob)
     (let* ((style (ly:grob-property grob 'style))
            (grob-probs (ly:grob-properties grob))
            (cause (assoc-get 'cause grob-probs))
            (drum-type (ly:prob-property cause 'drum-type)))

     ;; If laThin-NoteHead for bassdrum is detected,
     ;; change duration-log, else default.
     (if (and (eq? style 'laThin) (eq? drum-type 'bassdrum))
         0
         (note-head::calc-duration-log grob))))

%% A new drum-table
#(define mydrums
  '(
    (bassdrum    laThin    "ellipse"    -1)
    (hihat     laThin  "hexagon"      3)
   ))

%% To use the new scripts call them in \layout
\layout {
    \context {
        \Score
        scriptDefinitions = #my-script-alist
    }
}

\new DrumStaff
  \with {
    \override StaffSymbol #'line-count = #2
    drumStyleTable = #(alist->hash-table mydrums)
    \alwaysPrintWholeLaThinBassDrum
  }

\drummode {
    bd8 bd  bd2. hh1 hh2 hh4 hh8 hh
}

%% To use in \notemode you may want to use:
ellipse = #(make-articulation "ellipse")
hexagon = #(make-articulation "hexagon")

%% Shortcuts.
%% TODO: How to create more shortcuts? I didn't test so far.
%% Below are redefined ones.
dashDash = "ellipse"
dashHat = "hexagon"

\relative c' {
    c1\ellipse d^\ellipse
    e\hexagon f^\hexagon
    c'1-- d_-
    e-^ f_^
}

\header {
    title = "New Scripts"
    subtitle = "for"
    subsubtitle = \markup \column {
                 "\\drummode and \\notemode"
                 \vspace #2
    }
}

HTH,
  Harm

Attachment: new-scripts.ly
Description: Binary data

<<attachment: new-scripts.png>>

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to