lilypond-user
[Top][All Lists]
Advanced

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

Re: Please help


From: Thomas Morley
Subject: Re: Please help
Date: Sat, 30 Nov 2013 02:07:20 +0100

2013/11/30 David Kastrup <address@hidden>:
> Thomas Morley <address@hidden> writes:
>
>> 2013/11/29 Mateusz Goździewski <address@hidden>
>>
>>> How I need to enter the code to get this effect:
>>> [image: Obraz w treści 1]or this
>>> [image: Obraz w treści 2]
>>
>> how about:
>>
>> \version "2.17.95"
>>
>> alternativeKey =
>> #(define-music-function (parser location p-1 p-2)(ly:pitch? ly:pitch?)
>
>>                        { \key $p-2 \major s4 }
>
> [...]
>
> Any reason you don't put the \major as last function argument (see
> definition of \key in scm/music-functions-init.ly for an example how
> this works)?  Looks less ad-hoc.

An oversight. :)
Was already working on it, as I noticed your reply.

> Possibly also as second function
> argument.  That's likely redundant for most use cases, but makes the
> function call look less cryptic.
>
>> Thanks David Kastrup for his improved \score-markup-command.
>
> That remark makes it likely that for versions before 2.17.14 you'll not
> be able to get consistent vertical positions with this approach.
> I think there were some pointers to the LSR in this thread as well:
> maybe there is some different approach working for older versions among
> it.

I made a short test with 2.16.2. Looks weird.
Not sure wether there's any way with older versions, have to test.

>
> All the best
>
> --
> David Kastrup

Below the newest code, also making it more robust in case no
KeySignature is ptinted (a\minor, c\major). The other scales (ionian,
etc) are not yet implemented, should work for most use cases though.

\version "2.17.95"

alternativeKey =
#(define-music-function (parser location p-1 p-2 scale-def)
     (ly:pitch? ly:pitch? list?)
#{
  \override Staff.KeySignature #'stencil =
   #(lambda (grob)
      (let* ((staff-space (ly:staff-symbol-staff-space grob))
             (line-thickness (ly:staff-symbol-line-thickness grob))
             (th line-thickness)
             (default-stil (ly:key-signature-interface::print grob))
             ;; To avoid programming error @code{(markup #:null)} is returned if
             ;; the scale would not result in printed KeySignature.
             ;; TODO: add the other scales: ionian, locrian etc
             (stil-to-add
               (grob-interpret-markup grob
                 (if (or (and (= (ly:pitch-notename p-2) 5)
                              (eq? scale-def minor))
                         (and (= (ly:pitch-notename p-2) 0)
                              (eq? scale-def major)))
                 (markup #:null)
                 #{
                   \markup
                     \score {
                       { \key $p-2 $scale-def }
                       \layout {
                         \override Staff.TimeSignature #'stencil = ##f
                         \override Staff.Clef #'stencil = ##f
                         \override Staff.StaffSymbol #'line-count = #0
                         indent = 0
                       }
                   }
                 #})
                 ))
             (stil-to-add-x-ext (ly:stencil-extent stil-to-add X))
             (stil-to-add-y-ext (ly:stencil-extent stil-to-add Y))
             )
    (if (< 0 (interval-length stil-to-add-x-ext))
        (if (or (and (= (ly:pitch-notename p-1) 5)
                     (eq? scale-def minor))
                (and (= (ly:pitch-notename p-1) 0)
                     (eq? scale-def major)))
            (bracketify-stencil
                      (ly:make-stencil
                        (ly:stencil-expr stil-to-add)
                        ;; left bracket is to far away
                        ;; trimmed a little
                        (cons
                           (+ (car stil-to-add-x-ext) (* 0.7 staff-space) )
                           (cdr stil-to-add-x-ext))
                        ;; adjusting the top and bottom ending of the bracket
                        (cons
                           (+ (car stil-to-add-y-ext) (* 0.2 staff-space))
                           (- (cdr stil-to-add-y-ext) (* 0.5 staff-space))))
                      Y th (* 2.5 th) th)
            (ly:stencil-combine-at-edge
              default-stil
              X
              RIGHT
              (bracketify-stencil
                (ly:make-stencil
                  (ly:stencil-expr stil-to-add)
                  ;; left bracket is to far away
                  ;; trimmed a little
                  (cons
                     (+ (car stil-to-add-x-ext) (* 0.7 staff-space) )
                     (cdr stil-to-add-x-ext))
                  ;; adjusting the top and bottom ending of the bracket
                  (cons
                     (+ (car stil-to-add-y-ext) (* 0.2 staff-space))
                     (- (cdr stil-to-add-y-ext) (* 0.5 staff-space))))
                Y th (* 2.5 th) th)
                1))
      default-stil)))

  \key $p-1 $scale-def
#})

%%%%%%%%%%%%%%
% EXAMPLES
%%%%%%%%%%%%%%

\relative c' {
    \alternativeKey c f \major
    c1
    \alternativeKey b c \major
    c
    \alternativeKey e ees \major
    c
    \alternativeKey a aes \major
    c
    \alternativeKey d des \major
    c
    \alternativeKey g ges \major
    c
    \alternativeKey c ces \major
    c
    \alternativeKey ges g \major
    c1
    \alternativeKey des d \major
    c
    \alternativeKey aes a \major
    c
    \alternativeKey ees e \major
    c
    \alternativeKey bes b \major
    c
    \alternativeKey f fis \major
    c
    \alternativeKey ces cis \major
    c
}


Cheers,
  Harm



reply via email to

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