Hi,

2011/3/13 Graham Percival wrote:
> I'm always astounded at how much we _could_ be doing
> with "helper" scheme functions [...].
(http://lists.gnu.org/archive/html/lilypond-devel/2011-03/msg00339.html)

Inspired by Graham i've just written another helper scheme function!

We all need to use custom dynamics in our scores from time to time
(like "p espressivo").  Notation Reference 1.3.1 describes how you can
create them, but the process is a bit inconvenient - there's just too
much to write:
{
  c'-#(make-dynamic-script
       (markup #:dynamic "p"
         #:normal-text #:italic "espressivo"))
}

So, i defined a \dynamic function that will do all the magic for you,
so that you can define and use custom dynamics on-the-fly.  With it,
you just write
{
  c'-\dynamic "p espressivo"
}
and that's it.  Nice, isn't it?
You can find the snippet in the attachment, or in the
openlilylib/snippets repository:
https://github.com/openlilylib/snippets/tree/master/input-shorthands/easy-custom-dynamics

The function is dedicated to Marc and Tine Hohl :-)

I'd like to improve it further, in particular add a shorthand syntax
for upright letters (currently the function automatically uses
italics, unless you use \markup but that's a lot of typing), better
support parenthesizing and bracketifying of dynamic letters, and see
how i could use a function that Curt wrote
(https://github.com/tunesmith/TheForgivingSea/blob/master/1M2/lib/special-dynamics.ily)
to improve the alignment.

Would anyone want to sponsor it?  I don't know when i'll have time to
work on this, but sponsoring will make it "sometime before Christmas"
instead of "sometime in 2014" :-)

best,
Janek
\version "2.16.2"

\header {
  snippet-title = "Easy custom dynamics"
  snippet-author = "Janek Warchoł"
  snippet-source = ""
  snippet-description = \markup {
    Simple, user-friendly way to define custom dynamics
    with minimal fuss.  Accepts markups and plain text definitions.
  }
  snippet-dedication = "dedicated to Marc and Tine Hohl :-)"
  % add comma-separated tags to make searching more effective:
  tags = "dynamics"
  % is this snippet ready?  See meta/status-values.md
  status = ""
}


%%%%%%%%%%%%%%%%%%%%%%%%%%
% here goes the snippet: %
%%%%%%%%%%%%%%%%%%%%%%%%%%

#(use-modules (ice-9 regex))

dynamic =
#(define-music-function (parser location text) (markup?)
   (if (string? text)
       (let* ((underscores-replaced
               (string-map
                (lambda (x) (if (eq? x #\_) #\space x))
                text))
              (split-text (string-split underscores-replaced #\space))
              (formatted (map
                          (lambda (word)
                            (if (string-match "^[mrzfps]*$" word)
                                (markup #:dynamic word)
                                (markup #:normal-text #:italic word)))
                          split-text))
              )
         #{
           #(make-dynamic-script (make-line-markup formatted))
         #})

       ;; user provided a full-blown markup, so we don't mess with it:
       #{
         #(make-dynamic-script (markup #:normal-text text))
       #}))

%%%%%%%%%%%%%%%%%%%
% usage examples: %
%%%%%%%%%%%%%%%%%%%

{
  c'1 -\dynamic sfffzppppp
}
{
  c' -\dynamic "molto f ekspressivvo"
}
{
  c' -\dynamic fff_I_can_use_underscores
}
{
  c' -\dynamic \markup { lolish \huge \dynamic pp \italic ekspress, \caps "markups ftw!" }
}

<<attachment: example.png>>

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

Reply via email to