Autor Thema: grow-direction in beide Richtungen...  (Gelesen 12370 mal)

kilgore

  • Member
grow-direction in beide Richtungen...
« am: Donnerstag, 29. September 2011, 17:31 »
Liebe Lilys!


grow-direction kann man leicht einstellen für links oder rechts, aber was ist, wenn eine Gruppe von Tönen erst allmählich schneller, und dann allmählich langsamer gespielt werden sollen?

Anbei sind ein paar Beispiele, und meine Versuche das irgendwie abzubilden.  Kennt jemand da eine gute Lösung?

Danke!
Gruß
kil


\version "2.14.2"



\relative c' {
  \once \override Beam #'grow-direction = #RIGHT
  c32[ c c c]
  \once \override Beam #'grow-direction = #LEFT
  c[ c c c]
 
  \once \override Beam #'grow-direction = #RIGHT
  c32[ c c c
  \once \override Beam #'grow-direction = #LEFT
  c c c c]
}


\relative c' {
  \once \override Beam #'grow-direction = #RIGHT
  d32[ d d d d]
  \once \override Beam #'grow-direction = #LEFT
  \override NoteHead #'extra-offset = #'( -2.5 . 0 )
  \override Stem #'extra-offset = #'( -2.5 . 0 )
  \override Beam #'extra-offset = #'( -2.5 . 0 )
  \once \override NoteHead #'transparent = ##t
  \once \override Stem #'transparent = ##t
  d[ d d d]
}

\relative c' {
 
  \once \override Beam #'grow-direction = #RIGHT
  c32[ c c
  \set stemRightBeamCount = #3
  c]
  \once \override Beam #'grow-direction = #LEFT
  \set stemLeftBeamCount = #3
  c[ c c c]
 
}


harm6

  • Member
Re: grow-direction in beide Richtungen...
« Antwort #1 am: Donnerstag, 29. September 2011, 23:41 »
Hallo kil,

grow-direction scheint ja nur in eine Richtung zu funktionieren.
Es geht vielleicht, indem man den stencil neu definiert. Aber bevor ich mich dran gebe es auch nur zu versuchen (keine Garantie für Erfolg), bestätige doch bitte, daß das angehängte Bild ungefähr Deinem Wunsch entspricht.

Gruß,
  Harm

P.S. Der Code mit dem ich es erzeugt habe ist es nicht wert gepostet zu werden: viel zu mühsam und bei der geringsten layout-Änderung funktioniert er schon nicht mehr.

kilgore

  • Member
Re: grow-direction in beide Richtungen...
« Antwort #2 am: Freitag, 30. September 2011, 09:55 »
Liebe Harm,

Gute Versuch!  Es entspricht fast das was ich möchte.  Da sollten alle Beams, also in diesem Fall alle drei, zusammen kommen in der Mitte (oder auch nicht in der Mitte).  Bei deinem Beispiel würde es zB zu einer Sptize kommen zwischen den vierten und fünften 16tel. Die Spitze kann auch über einen Ton sein, statt zwischen zwei.  Macht das Sinn?

Gruß
kil

harm6

  • Member
Re: grow-direction in beide Richtungen...
« Antwort #3 am: Freitag, 30. September 2011, 11:25 »
Hallo kil,

ich werde mal meinen Notenschrank durchforsten, ob ich ein Beispiel finde.
Als ich schrieb es müßte über den stencil machbar sein, war das erstmal eine rein theoretische Aussage, denn eigentlich ist via stencil immer alles möglich. Ob man es dann auch hinbekommt ist natürlich eine andere Frage.
Hilfreich wäre, wenn ich wüßte wie grow-direction für beams definiert ist. Ich habs aber auf die Schnelle nicht gefunden.

Weiß jemand wo man nachschauen kann?

Gruß,
  Harm

kilgore

  • Member
Re: grow-direction in beide Richtungen...
« Antwort #4 am: Freitag, 30. September 2011, 15:31 »
Lieber Harm

Danke füe deine Mühe!  Ich habe auch meine Lilypond Ordern durchsucht und fand auch nichts....  Hoffentlich weiss es jemand!

Gruß
kil

harm6

  • Member
Re: grow-direction in beide Richtungen...
« Antwort #5 am: Sonntag, 2. Oktober 2011, 19:55 »
Hallo kil,

mein erster Versuch das Procedere mit nur wenigen Variablen quasi automatisiert zu definieren ist leider gescheitert.
Es gibt für Stem und Beam eine Unzahl von Ausgleichsvariablen, die schlecht oder gar nicht kommentiert sind. (siehe IR Stem bzw. Beam und dort: details ) Sie haben natürlich alle einen Sinn, denn nicht umsonst liefert lily schon so einen hervorragenden default-output.
Diese Variablen aber alle in einer eigenen Definition zu berücksichtigen, würde wahrscheinlich dazu führen, daß ich nächstes Jahr noch damit beschäftigt wäre.

So kriegst Du jetzt eine Fassung mit einer Unmenge von Variablen ;). Sie sind alle ausgleichender bzw anpassender Natur. Es muß also kein Wert gänzlich neu erraten werden, sondern die errechneten Werte können angepaßt werden. (Das ist Arbeit genug). Der Code ist recht ausführlich kommentiert und es gibt eine "Step-by-Step-Demonstration" in einem zweiten Score, so daß eigentlich klar werden sollte, wie vorzugehen ist. Wenn nicht, dann frag. :)

Die von mir im ersten Score benutzten Werte kann man wahrscheinlich noch besser einstellen, aber das fein-tunen nur für ein Snippet war mir dann zu aufwendig.;)

Ich hoffe es kommt dem zumindest nahe, was Dir vorschwebt.

\version "2.14.2"

\markup \column { \bold \fill-line { "EXAMPLE" } \vspace #2 }

#(define ((grow-dir-var top y-offset corr-y slope-1 slope-2 slope-3) grob)
 (cond ((= top 1) (and (display "\n ______________No Top wanted?________________________") #f))
       ((< top 1) (and (display "\n ______________No reachable Top!_____________________") #f))
       ((> top 1)
  (if (ly:stencil? (ly:beam::print grob))
     (let* ((beam (ly:beam::print grob))
            (dir (ly:beam::calc-direction grob))
            (beam-extent-X (ly:stencil-extent beam X))
            (beam-length-x (interval-length beam-extent-X))
            (beam-extent-Y (ly:stencil-extent beam Y))
            (beam-length-y (interval-length beam-extent-Y))
            (line-thickness (ly:output-def-lookup (ly:grob-layout grob) 'line-thickness))
            (beam-thickness (* 0.48 (ly:output-def-lookup (ly:grob-layout grob) 'staff-space)))
            (half-stem-thickness (/ (* 1.3 line-thickness) 2))
            (space-helper (/ beam-length-y (/ beam-length-x 1.5)))
           
;; markup-a is the longest beam
           
            (markup-a (markup #:beam (- beam-length-x (* half-stem-thickness 1.26)) ;; length
                 (if (or (> 0 (cdr beam-extent-Y)) (equal? dir 1)) ;; slope
                        (+ (car slope-1) 0)
                        (+ (car slope-1) (cdr beam-extent-Y)))
                        beam-thickness)) ;; thickness 
            (long-beam (grob-interpret-markup grob markup-a))
            (long-beam-ext-y (ly:stencil-extent long-beam Y))
            (long-beam-ext-x (ly:stencil-extent long-beam X))
           
;; markup-b is begin of the first additional beam

            (part-beam-1 (markup #:beam (- (/ beam-length-x top) (* half-stem-thickness 1.4)) ;; length
                 (if (> 0 (cdr beam-extent-Y)) ;; slope
                  (+ (car slope-2) (* dir (/ space-helper  -1 )))
                  (+ (car slope-2) (* dir (/ space-helper -0.8))))
                  beam-thickness)) ;; thickness 
            (markup-b (markup part-beam-1))
            (first-part-beam-1 (grob-interpret-markup grob markup-b))
            (first-part-beam-1-ext-y (ly:stencil-extent first-part-beam-1 Y))
            (length-first-part-beam-1-y (interval-length first-part-beam-1-ext-y))
            (first-part-beam-1-ext-x (ly:stencil-extent first-part-beam-1 X))

;; markup-bb is the end of the first additional beam
            (part-beam-11 (markup #:beam (- (- beam-length-x (/ beam-length-x top)) (* half-stem-thickness 1.4)) ;; length
                  (if (> 0 dir) ;; slope
                    (+ (cdr slope-2) (* dir (/
                    (- (cdr first-part-beam-1-ext-y) (cdr long-beam-ext-y))
                    (- (cdr long-beam-ext-x) (cdr first-part-beam-1-ext-x))
                    )))
                    (+ (cdr slope-2) (* dir (/
                    (- (cdr long-beam-ext-y)(cdr first-part-beam-1-ext-y))
                    (- (cdr long-beam-ext-x) (cdr first-part-beam-1-ext-x))
                    ))))
                    beam-thickness)) ;; thickness
            (markup-bb (markup part-beam-11))
           
;; markup-c is the begin of the second additional beam
            (part-beam-2
              (if (not (equal? (car slope-3) #f))
            (markup #:beam (- (/ beam-length-x top) (* half-stem-thickness 1.4)) ;; length
                  (if (> 0 (cdr beam-extent-Y)) ;; slope
                    (+ (car slope-3) (* dir (/ space-helper -2)))
                    (+ (car slope-3) (* dir (/ space-helper -1.2))))
                    beam-thickness) ;; thickness
            (markup #:null)))
            (markup-c (markup part-beam-2))
           
            (first-part-beam-2 (grob-interpret-markup grob markup-c))
            (first-part-beam-2-ext-y (ly:stencil-extent first-part-beam-2 Y))
            (length-first-part-beam-2-y (interval-length first-part-beam-2-ext-y))
            (first-part-beam-2-ext-x (ly:stencil-extent first-part-beam-2 X))
           
;; markup-cc is the end of the second additional beam
            (part-beam-22
              (if (not (equal? (cdr slope-3) #f))
              (markup #:beam (- (- beam-length-x (/ beam-length-x top)) (* half-stem-thickness 1.4)) ;;length
                  (if (> 0 dir) ;;slope
                  (+ (cdr slope-3)
                  (* dir (/
                  (- (cdr first-part-beam-2-ext-y) (cdr long-beam-ext-y))
                  (- (cdr long-beam-ext-x) (cdr first-part-beam-2-ext-x))
                  )))
                  (+ (cdr slope-3)
                  (* dir (/
                  (- (cdr long-beam-ext-y) (cdr first-part-beam-2-ext-y))
                  (- (cdr long-beam-ext-x) (cdr first-part-beam-2-ext-x))
                  ))))
                  beam-thickness) ;; thickness
              (markup #:null)))
            (markup-cc (markup part-beam-22))
            )   ;; end of defs in let*
           
 (ly:stencil-translate-axis
   (ly:stencil-add
   ;; first (long beam)
     (ly:stencil-translate-axis
       (grob-interpret-markup grob markup-a)
         (/ half-stem-thickness -2.7)
          X)
   ;; parts of second beam
     (ly:stencil-combine-at-edge
       (grob-interpret-markup grob markup-b)
       X RIGHT
       (ly:stencil-translate-axis
         (grob-interpret-markup grob markup-bb)
      (+ (car corr-y)
        (if (> 0 dir)
            (- (cdr first-part-beam-1-ext-y) (* 0.5 beam-thickness))
            (* -1 (- length-first-part-beam-1-y (* 1 beam-thickness)))))
            Y)
      0)
   ;; parts of third beam
     (ly:stencil-combine-at-edge
      (grob-interpret-markup grob markup-c)
      X RIGHT
      (ly:stencil-translate-axis
        (grob-interpret-markup grob markup-cc)
        (+ (cdr corr-y)
          (if (equal? dir -1)
            (- (cdr first-part-beam-2-ext-y) (* 0.5 beam-thickness))
            (* -1 (- length-first-part-beam-2-y beam-thickness))))
            Y)
      0)
      ) ;; end of stencil-add
    (if (equal? dir 1)
      (+ y-offset 0)
        (if (> 0 (cdr beam-extent-Y))
          (+ y-offset -3.3)
          (+ y-offset -1.8)))
   Y)
       ) ;; end of let*
       #f))))
       
%--------------------- Test ----------------------------------------------------
       
       \layout {
        \context {
          \Score
             \override NonMusicalPaperColumn #'line-break-permission = ##f
        }
       }
       
\relative c' {
         \once \override Beam #'stencil = #(grow-dir-var 3 ; where to print the turn (2 is half-beam)
                   -0.2 ; Y-offset of the whole construct
                   '(0 . 0) ; additional Y-offset
                    ;    '(<second part of the first added beam>
                    ;      .
                    ;      <second part of the second added beam>)
                   '(0 . 0) ; slope of the long beam (without) top
                   '(-0.01 . 0) ; slope '(<first part of the first added beam>
                    ;         .
                    ;         <second part of the first added beam>)
                   '(0.1 . 0)) % slope '(<first part of the second added beam>
                    %         .
                    %         <second part of the second added beam>)
                    % to delete the second additional
                    %     beam use '(#f . #f)
  c'32 [d' e, f g a b, c d'' e f g, a b c d
  ]

  \once \override Beam #'stencil = #(grow-dir-var 3 -1.1 '(0 . 0) '(-0.02 . 0) '(-0.028 . 0) '(0.09 . 0))
  c,,32 [d e f g a b c d e f g a b c d
  ]
\break 
  \once \override Beam #'stencil = #(grow-dir-var 3 0 '(0 . 0) '(-0.1 . 0) '(-0.17 . -0.07) '(-0.009 . -0.07))
  c32 [b a g f e d c b a g f e d c b
  ]

  \once\override Beam #'stencil = #(grow-dir-var 3.5 1 '(0 . 0) '(0 . 0) '(0.0285 . 0.034) '(-0.1 . 0.07))
  c,,32 [c c c c c c c c c c c c c c c
  ]
  \once\override Beam #'stencil = #(grow-dir-var 1.3 5.5 '(0.255 . 0) '(0.06 . 0.0) '(0.26 . 0) '(0.13 . 0.12))
  c32 [c' c' c,, c d e f g c e b' c'
  ]
}

%\pageBreak

\markup \column { \vspace #2 \bold \fill-line { "Step-By-Step-Demonstration" } \vspace #2 }

\relative c' {
       
% Die Spitze kommt z.B. in die Mitte (top -> 2)
  \once\override Beam #'stencil = #(grow-dir-var 2 0 '(0 . 0) '(0 . 0) '(0 . 0) '(0 . 0))
  c32 [c' c' c, c d e f g c e b' c'
  ]
 
% Die linke Ecke des ganzen Balkens wird ausgerichtet (y-offset -> -3)
  \once\override Beam #'stencil = #(grow-dir-var 2 -3 '(0 . 0) '(0 . 0) '(0 . 0) '(0 . 0))
  c,,,,32 [c' c' c, c d e f g c e b' c'
  ]
 
\bar "" \break
 
% Die rechte Ecke des ganzen Balkens wird ausgerichtet (slope-1 -> '(0.04 . 0))
  \once\override Beam #'stencil = #(grow-dir-var 2 -3 '(0 . 0) '(0.04 . 0) '(0 . 0) '(0 . 0))
  c,,,,32 [c' c' c, c d e f g c e b' c'
  ]
 
% Die Steigung des ersten zusätzlichen Balkens wird ausgerichtet (slope-2 -> '(-0.05 . 0))
% Damit der zweite Balken nicht stört wird er mittels '(#f . #f) ausgeschlossen.
  \once\override Beam #'stencil = #(grow-dir-var 2 -3 '(0 . 0) '(0.04 . 0) '(-0.05 . 0) '(#f . #f))
  c,,,,32 [c' c' c, c d e f g c e b' c'
  ]
 
\bar "" \break

% Die Steigung des zweiten zusätzlichen Balkens wird ausgerichtet (slope-3 -> '(0.05 . 0))
  \once\override Beam #'stencil = #(grow-dir-var 2 -3 '(0 . 0) '(0.04 . 0) '(-0.05 . 0) '(0.05 . 0))
  c,,,,32 [c' c' c, c d e f g c e b' c'
  ]

% Andere Veränderungen waren hier nicht nötig!
  \once\override Beam #'stencil = #(grow-dir-var 2 -3 '(0 . 0) '(0.04 . 0) '(-0.05 . 0) '(0.05 . 0))
  c,,,,32 [c' c' c, c d e f g c e b' c'
  ]
 
\bar "" \break

% Leider führt jede Veränderung (wie der gerade erfolgte \break) zu anderen Werten)
  \once\override Beam #'stencil = #(grow-dir-var 2 -3 '(0 . 0) '(0.02 . 0) '(-0.025 . 0) '(0.025 . 0))
  c,,,,32 [c' c' c, c d e f g c e b' c'
  ]
}

% An diesem Beispiel mit LilyPond default-Befehlen zeigt sich allerdings,
% daß auch bessere Leute Schwierigkeiten haben. :)
% Hohe Vergrößerung auf die rechte obere Ecke des Balkens zeigt ein Überstehen eines Balkens!

\relative c' {
  \once \override Beam #'grow-direction = #LEFT
  c,32[ d e f]
}


Desweiteren ist mir bislang keine Partitur in die Hände gefallen in der sowas wie oben vorkommt. (Mag natürlich auch allein an meiner Beschränktheit liegen). Ich habe allerdings häufig etwas gesehen wie im Anhang: beam-bild.png.

Gruß,
  Harm

P.S.:Im übrigen ist mir aufgefallen, daß es bei \once \override Beam #'grow-direction = #LEFT (also einem default-Befehl) bei hoher Vergrößerung (sichtbar ab ca 800%) eine unsaubere Graphik gibt. (Es scheint, nicht nur ich habe da Schwierigkeiten. :) ) siehe Anhang: beamsTwo-from-1.1.16-to-1.1.8-clip.pdf.


kilgore

  • Member
Re: grow-direction in beide Richtungen...
« Antwort #6 am: Montag, 3. Oktober 2011, 08:50 »
Oh Harm wie großartig!!!  Deine Scheme Fähigkeiten sind echt erstaunlich!  Ich muss mich später heute mit den Details auseinandersetzen, aber erstmal bin ich schwer beeindruckt.  Ich werde versuchen ein paar Beispiele aus der Praxis zu finden...ich weiss ich bin so was schon ein paar mal begegnet....

 ;D  ;D   ;D

U Rock!!

Gruß
kil

harm6

  • Member
Re: grow-direction in beide Richtungen...
« Antwort #7 am: Montag, 3. Oktober 2011, 16:13 »
Hallo kil,

ich hoffe Du bist immer noch begeistert, wenn Du es erst mal ausprobiert hast. ;)

Gruß,
  Harm

kilgore

  • Member
Re: grow-direction in beide Richtungen...
« Antwort #8 am: Montag, 3. Oktober 2011, 21:14 »
Naja, erstmal bin ich so weit!  Schon gewöhnungsbedürftig, aber es sieht erstmal richtig cool aus!

Die ungenauigkeit am rechten ende des default beams habe ich auch bemerkt, obwohl ich nicht wusste wo der fehler lag! 


\version "2.14.2"

\markup \column { \bold \fill-line { "EXAMPLE" } \vspace #2 }

#(define ((grow-dir-var top y-offset corr-y slope-1 slope-2 slope-3) grob)
 (cond ((= top 1) (and (display "\n ______________No Top wanted?________________________") #f))
       ((< top 1) (and (display "\n ______________No reachable Top!_____________________") #f))
       ((> top 1)
  (if (ly:stencil? (ly:beam::print grob))
     (let* ((beam (ly:beam::print grob))
            (dir (ly:beam::calc-direction grob))
            (beam-extent-X (ly:stencil-extent beam X))
            (beam-length-x (interval-length beam-extent-X))
            (beam-extent-Y (ly:stencil-extent beam Y))
            (beam-length-y (interval-length beam-extent-Y))
            (line-thickness (ly:output-def-lookup (ly:grob-layout grob) 'line-thickness))
            (beam-thickness (* 0.48 (ly:output-def-lookup (ly:grob-layout grob) 'staff-space)))
            (half-stem-thickness (/ (* 1.3 line-thickness) 2))
            (space-helper (/ beam-length-y (/ beam-length-x 1.5)))
           
;; markup-a is the longest beam
           
            (markup-a (markup #:beam (- beam-length-x (* half-stem-thickness 1.26)) ;; length
                 (if (or (> 0 (cdr beam-extent-Y)) (equal? dir 1)) ;; slope
                        (+ (car slope-1) 0)
                        (+ (car slope-1) (cdr beam-extent-Y)))
                        beam-thickness)) ;; thickness 
            (long-beam (grob-interpret-markup grob markup-a))
            (long-beam-ext-y (ly:stencil-extent long-beam Y))
            (long-beam-ext-x (ly:stencil-extent long-beam X))
           
;; markup-b is begin of the first additional beam

            (part-beam-1 (markup #:beam (- (/ beam-length-x top) (* half-stem-thickness 1.4)) ;; length
                 (if (> 0 (cdr beam-extent-Y)) ;; slope
                  (+ (car slope-2) (* dir (/ space-helper  -1 )))
                  (+ (car slope-2) (* dir (/ space-helper -0.8))))
                  beam-thickness)) ;; thickness 
            (markup-b (markup part-beam-1))
            (first-part-beam-1 (grob-interpret-markup grob markup-b))
            (first-part-beam-1-ext-y (ly:stencil-extent first-part-beam-1 Y))
            (length-first-part-beam-1-y (interval-length first-part-beam-1-ext-y))
            (first-part-beam-1-ext-x (ly:stencil-extent first-part-beam-1 X))

;; markup-bb is the end of the first additional beam
            (part-beam-11 (markup #:beam (- (- beam-length-x (/ beam-length-x top)) (* half-stem-thickness 1.4)) ;; length
                  (if (> 0 dir) ;; slope
                    (+ (cdr slope-2) (* dir (/
                    (- (cdr first-part-beam-1-ext-y) (cdr long-beam-ext-y))
                    (- (cdr long-beam-ext-x) (cdr first-part-beam-1-ext-x))
                    )))
                    (+ (cdr slope-2) (* dir (/
                    (- (cdr long-beam-ext-y)(cdr first-part-beam-1-ext-y))
                    (- (cdr long-beam-ext-x) (cdr first-part-beam-1-ext-x))
                    ))))
                    beam-thickness)) ;; thickness
            (markup-bb (markup part-beam-11))
           
;; markup-c is the begin of the second additional beam
            (part-beam-2
              (if (not (equal? (car slope-3) #f))
            (markup #:beam (- (/ beam-length-x top) (* half-stem-thickness 1.4)) ;; length
                  (if (> 0 (cdr beam-extent-Y)) ;; slope
                    (+ (car slope-3) (* dir (/ space-helper -2)))
                    (+ (car slope-3) (* dir (/ space-helper -1.2))))
                    beam-thickness) ;; thickness
            (markup #:null)))
            (markup-c (markup part-beam-2))
           
            (first-part-beam-2 (grob-interpret-markup grob markup-c))
            (first-part-beam-2-ext-y (ly:stencil-extent first-part-beam-2 Y))
            (length-first-part-beam-2-y (interval-length first-part-beam-2-ext-y))
            (first-part-beam-2-ext-x (ly:stencil-extent first-part-beam-2 X))
           
;; markup-cc is the end of the second additional beam
            (part-beam-22
              (if (not (equal? (cdr slope-3) #f))
              (markup #:beam (- (- beam-length-x (/ beam-length-x top)) (* half-stem-thickness 1.4)) ;;length
                  (if (> 0 dir) ;;slope
                  (+ (cdr slope-3)
                  (* dir (/
                  (- (cdr first-part-beam-2-ext-y) (cdr long-beam-ext-y))
                  (- (cdr long-beam-ext-x) (cdr first-part-beam-2-ext-x))
                  )))
                  (+ (cdr slope-3)
                  (* dir (/
                  (- (cdr long-beam-ext-y) (cdr first-part-beam-2-ext-y))
                  (- (cdr long-beam-ext-x) (cdr first-part-beam-2-ext-x))
                  ))))
                  beam-thickness) ;; thickness
              (markup #:null)))
            (markup-cc (markup part-beam-22))
            )   ;; end of defs in let*
           
 (ly:stencil-translate-axis
   (ly:stencil-add
   ;; first (long beam)
     (ly:stencil-translate-axis
       (grob-interpret-markup grob markup-a)
         (/ half-stem-thickness -2.7)
          X)
   ;; parts of second beam
     (ly:stencil-combine-at-edge
       (grob-interpret-markup grob markup-b)
       X RIGHT
       (ly:stencil-translate-axis
         (grob-interpret-markup grob markup-bb)
      (+ (car corr-y)
        (if (> 0 dir)
            (- (cdr first-part-beam-1-ext-y) (* 0.5 beam-thickness))
            (* -1 (- length-first-part-beam-1-y (* 1 beam-thickness)))))
            Y)
      0)
   ;; parts of third beam
     (ly:stencil-combine-at-edge
      (grob-interpret-markup grob markup-c)
      X RIGHT
      (ly:stencil-translate-axis
        (grob-interpret-markup grob markup-cc)
        (+ (cdr corr-y)
          (if (equal? dir -1)
            (- (cdr first-part-beam-2-ext-y) (* 0.5 beam-thickness))
            (* -1 (- length-first-part-beam-2-y beam-thickness))))
            Y)
      0)
      ) ;; end of stencil-add
    (if (equal? dir 1)
      (+ y-offset 0)
        (if (> 0 (cdr beam-extent-Y))
          (+ y-offset -3.3)
          (+ y-offset -1.8)))
   Y)
       ) ;; end of let*
       #f))))
       
%--------------------- Test ----------------------------------------------------


\relative c' {
  \once \override Beam #'stencil = #(grow-dir-var 2 ; where to print the turn (2 is half-beam)
                   0.6 ; Y-offset of the whole construct
                   '(0 . 0) ; additional Y-offset
                    ;    '(<second part of the first added beam>
                    ;      .
                    ;      <second part of the second added beam>)
                   '(0 . 0) ; slope of the long beam (without) top
                   '(0 . .2) ; slope '(<first part of the first added beam>
                    ;         .
                    ;         <second part of the first added beam>)
                   '(.04 . .1)) % slope '(<first part of the second added beam>
                    %         .
                    %         <second part of the second added beam>)
                    % to delete the second additional
                    %     beam use '(#f . #f)
  c32[ c c c c c c c]
}


Ich werde erst mal weiterhin damit basteln.....

harm6

  • Member
Re: grow-direction in beide Richtungen...
« Antwort #9 am: Montag, 3. Oktober 2011, 22:18 »
Hallo kil,

Zitat
Schon gewöhnungsbedürftig

das ist richtig. Und die Schwierigkeiten nehmen zu, wenn der Balken geneigt ist. ;)

Aber als ich mir angesehen habe was Du genau gemacht hast, konnte ich meine Definition noch ein kleines bißchen besser einstellen (das führt natürlich auch zu ein klein wenig veränderten Werten):

\version "2.14.2"

\markup \column { \bold \fill-line { "EXAMPLE" } \vspace #2 }

#(define ((grow-dir-var top y-offset corr-y slope-1 slope-2 slope-3) grob)
 (cond ((= top 1) (and (display "\n ______________No Top wanted?________________________") #f))
       ((< top 1) (and (display "\n ______________No reachable Top!_____________________") #f))
       ((> top 1)
  (if (ly:stencil? (ly:beam::print grob))
     (let* ((beam (ly:beam::print grob))
            (dir (ly:beam::calc-direction grob))
            (beam-extent-X (ly:stencil-extent beam X))
            (beam-length-x (interval-length beam-extent-X))
            (beam-extent-Y (ly:stencil-extent beam Y))
            (beam-length-y (interval-length beam-extent-Y))
            (line-thickness (ly:output-def-lookup (ly:grob-layout grob) 'line-thickness))
            (beam-thickness (* 0.48 (ly:output-def-lookup (ly:grob-layout grob) 'staff-space)))
            (half-stem-thickness (/ (* 1.3 line-thickness) 2))
            (space-helper (/ beam-length-y (/ beam-length-x 1.5)))
           
;; markup-a is the longest beam
           
            (markup-a (markup #:beam (- beam-length-x (* half-stem-thickness 1.25)) ;; length
                 (if (or (> 0 (cdr beam-extent-Y)) (equal? dir 1)) ;; slope
                        (+ (car slope-1) 0)
                        (+ (car slope-1) (cdr beam-extent-Y)))
                        beam-thickness)) ;; thickness 
            (long-beam (grob-interpret-markup grob markup-a))
            (long-beam-ext-y (ly:stencil-extent long-beam Y))
            (long-beam-ext-x (ly:stencil-extent long-beam X))
           
;; markup-b is begin of the first additional beam

            (part-beam-1 (markup #:beam (- (/ beam-length-x top) (* half-stem-thickness 0.8)) ;; length
                 (if (> 0 (cdr beam-extent-Y)) ;; slope
                  (+ (car slope-2) (* dir (/ space-helper  -1 )))
                  (+ (car slope-2) (* dir (/ space-helper -0.8))))
                  beam-thickness)) ;; thickness 
            (markup-b (markup part-beam-1))
            (first-part-beam-1 (grob-interpret-markup grob markup-b))
            (first-part-beam-1-ext-y (ly:stencil-extent first-part-beam-1 Y))
            (length-first-part-beam-1-y (interval-length first-part-beam-1-ext-y))
            (first-part-beam-1-ext-x (ly:stencil-extent first-part-beam-1 X))

;; markup-bb is the end of the first additional beam
            (part-beam-11 (markup #:beam (- (- beam-length-x (/ beam-length-x top)) (* half-stem-thickness 0.8)) ;; length
                  (if (> 0 dir) ;; slope
                    (+ (cdr slope-2) (* dir (/
                    (- (cdr first-part-beam-1-ext-y) (cdr long-beam-ext-y))
                    (- (cdr long-beam-ext-x) (cdr first-part-beam-1-ext-x))
                    )))
                    (+ (cdr slope-2) (* dir (/
                    (- (cdr long-beam-ext-y)(cdr first-part-beam-1-ext-y))
                    (- (cdr long-beam-ext-x) (cdr first-part-beam-1-ext-x))
                    ))))
                    beam-thickness)) ;; thickness
            (markup-bb (markup part-beam-11))
           
;; markup-c is the begin of the second additional beam
            (part-beam-2
              (if (not (equal? (car slope-3) #f))
            (markup #:beam (- (/ beam-length-x top) (* half-stem-thickness 0.8)) ;; length
                  (if (> 0 (cdr beam-extent-Y)) ;; slope
                    (+ (car slope-3) (* dir (/ space-helper -2)))
                    (+ (car slope-3) (* dir (/ space-helper -1.2))))
                    beam-thickness) ;; thickness
            (markup #:null)))
            (markup-c (markup part-beam-2))
           
            (first-part-beam-2 (grob-interpret-markup grob markup-c))
            (first-part-beam-2-ext-y (ly:stencil-extent first-part-beam-2 Y))
            (length-first-part-beam-2-y (interval-length first-part-beam-2-ext-y))
            (first-part-beam-2-ext-x (ly:stencil-extent first-part-beam-2 X))
           
;; markup-cc is the end of the second additional beam
            (part-beam-22
              (if (not (equal? (cdr slope-3) #f))
              (markup #:beam (- (- beam-length-x (/ beam-length-x top)) (* half-stem-thickness 0.8)) ;;length
                  (if (> 0 dir) ;;slope
                  (+ (cdr slope-3)
                  (* dir (/
                  (- (cdr first-part-beam-2-ext-y) (cdr long-beam-ext-y))
                  (- (cdr long-beam-ext-x) (cdr first-part-beam-2-ext-x))
                  )))
                  (+ (cdr slope-3)
                  (* dir (/
                  (- (cdr long-beam-ext-y) (cdr first-part-beam-2-ext-y))
                  (- (cdr long-beam-ext-x) (cdr first-part-beam-2-ext-x))
                  ))))
                  beam-thickness) ;; thickness
              (markup #:null)))
            (markup-cc (markup part-beam-22))
            )   ;; end of defs in let*
           
 (ly:stencil-translate-axis
   (ly:stencil-add
   ;; first (long beam)
     (ly:stencil-translate-axis
       (grob-interpret-markup grob markup-a)
         (/ half-stem-thickness -2.7)
          X)
   ;; parts of second beam
     (ly:stencil-combine-at-edge
       (grob-interpret-markup grob markup-b)
       X RIGHT
       (ly:stencil-translate-axis
         (grob-interpret-markup grob markup-bb)
      (+ (car corr-y)
        (if (> 0 dir)
            (- (cdr first-part-beam-1-ext-y) (* 0.5 beam-thickness))
            (* -1 (- length-first-part-beam-1-y (* 1 beam-thickness)))))
            Y)
      0)
   ;; parts of third beam
     (ly:stencil-combine-at-edge
      (grob-interpret-markup grob markup-c)
      X RIGHT
      (ly:stencil-translate-axis
        (grob-interpret-markup grob markup-cc)
        (+ (cdr corr-y)
          (if (equal? dir -1)
            (- (cdr first-part-beam-2-ext-y) (* 0.5 beam-thickness))
            (* -1 (- length-first-part-beam-2-y beam-thickness))))
            Y)
      0)
      ) ;; end of stencil-add
    (if (equal? dir 1)
      (+ y-offset 0)
        (if (> 0 (cdr beam-extent-Y))
          (+ y-offset -3.3)
          (+ y-offset -1.8)))
   Y)
       ) ;; end of let*
       #f))))
       
%--------------------- Test ----------------------------------------------------
% '(#f . #f)) %

\relative c' {
  \once \override Beam #'stencil = #(grow-dir-var 2 ; where to print the turn (2 is half-beam)
                   0.7 ; Y-offset of the whole construct
                   '(0 . 0) ; additional Y-offset
                    ;    '(<second part of the first added beam>
                    ;      .
                    ;      <second part of the second added beam>)
                   '(0 . 0) ; slope of the long beam (without) top
                   '(0 . .221) ; slope '(<first part of the first added beam>
                    ;         .
                    ;         <second part of the first added beam>)
                   '(.04 . .108)) % slope '(<first part of the second added beam>
                    %         .
                    %         <second part of the second added beam>)
                    % to delete the second additional
                    %     beam use '(#f . #f)
  c32[ c c c c c c c]
}

Ich wäre Dir also dankbar, wenn Du weitere Testversuche ebenfalls posten könntest, damit ich dann wieder schauen kann, wie ich meine Funktion noch verbessern kann.

Gruß,
  Harm

kilgore

  • Member
Re: grow-direction in beide Richtungen...
« Antwort #10 am: Mittwoch, 5. Oktober 2011, 15:17 »
Lieber Harm,

Das Unterschied mit deiner Änderungen sehe ich nicht, aber es liegt wohl in den Details!

Hier ein paar weitere Versuche, obwohl ich schon längst nicht fertig bin mit probieren :)

Ein Problem ist schon aufgetaucht, und zwar in der dritten Zeile.  Es geht um diesen Wert:

'(0.3 . .02)) % slope '(<first part of the second added beam>

das 0.3 verursacht (anscheinend) diese Ungenauigkeit wo die beiden Beams sich in der Mitte treffen.  Ich habe es lösen können mit einem Wert von 0.29, wollte diesen Beam aber doch ein bisschen höher haben.    Warum das so vorkommt kann ich noch nicht erklären, aber vielleicht verstehst du es?

Gruß
kil



harm6

  • Member
Re: grow-direction in beide Richtungen...
« Antwort #11 am: Mittwoch, 5. Oktober 2011, 22:39 »
Hallo kil,

Zitat
Das Unterschied mit deiner Änderungen sehe ich nicht, aber es liegt wohl in den Details!

Ich hatte das Ganze noch mal mit 6400% Vergrößerung betrachtet und ein paar winzige Ungenauigkeiten bemerkt und dann korrigiert. Die Unterschiede sind mikroskopisch klein. ;)

Zitat
das 0.3 verursacht (anscheinend) diese Ungenauigkeit wo die beiden Beams sich in der Mitte treffen.  Ich habe es lösen können mit einem Wert von 0.29, wollte diesen Beam aber doch ein bisschen höher haben.    Warum das so vorkommt kann ich noch nicht erklären, aber vielleicht verstehst du es?

Zunächst mal will es mir vorkommen, als ob Du Beam zwei und drei vertauscht hast. Letztendlich macht das keinen Unterschied, aber die Korrekturwerte vergrößern sich. Insoweit rate ich Dir den dritten Beam erstmal auszuschließen, dann den zweiten einzustellen und erst am Schluß den dritten wieder zuzulassen und einzustellen. Soviel erst mal grundsätzlich.
Warum die Beams manchmal vertikal auseinanderdriften kann ich nicht erklären. Aber um dieses Phänomen ausgleichen zu können hatte ich corr-y als Variable in die Definition eingefügt (im Test-Kommentar als additional Y-offset benannt). Du hast diesen Wert immer auf '(0 . 0) belassen. Schön wenn es so funktioniert, wenn nicht muß man da was ändern.

Hier die veränderten Werte für den ersten Abschnitt der dritten Zeile. Alles andere habe ich nicht verändert:

  \once \override Beam #'stencil = #(grow-dir-var 2       ; where to print the turn (2 is half-beam)
                           2       ; Y-offset of the whole construct
                           '(0.0915 . 0)    ; additional Y-offset   '(<second part of the first added beam> . <second part of the second added beam>)
                           '(0.1 . 0)    ; slope of the long beam (without) top
                           '(0.44 . 0)    ; slope '(<first part of the first added beam>  .  <second part of the first added beam>)
                           '(0.2 . 0.0905))    % slope '(<first part of the second added beam> . <second part of the second added beam>)
                                 % to delete the second additional  beam use '(#f . #f)
  c32[ d e f g a b c]

Ansonsten werde ich am Wochenende versuchen das ganze noch zu verbessern (falls ich Zeit dafür finde  ;) )

Gruß,
  Harm

harm6

  • Member
Re: grow-direction in beide Richtungen...
« Antwort #12 am: Montag, 10. Oktober 2011, 01:02 »
Hallo kil,

hier die neueste Fassung:

\version "2.14.2"

#(set-global-staff-size 20)

\layout {
        \context {
        \Staff
        \override Beam #'layer = #-4
        %\override Beam #'color = #red
        }
}

\markup \column { \bold \fill-line { "EXAMPLE" } \vspace #2 }

#(define ((grow-dir-var top y-offset corr-y slope-1 slope-2 slope-3) grob)
 (cond ((= top 1) (and (display "\n ______________No Top wanted?________________________") #f))
       ((< top 1) (and (display "\n ______________No reachable Top!_____________________") #f))
       ((> top 1)
  (if (ly:stencil? (ly:beam::print grob))
     (let* ((beam (ly:beam::print grob))
            (dir (ly:beam::calc-direction grob))
            (beam-extent-X (ly:stencil-extent beam X))
            (beam-length-x (interval-length beam-extent-X))
            (beam-extent-Y (ly:stencil-extent beam Y))
            (beam-length-y (interval-length beam-extent-Y))
            (line-thickness (ly:output-def-lookup (ly:grob-layout grob) 'line-thickness))
            (half-stem-thickness (/ (* 1.3 line-thickness) 2))
            (beam-thickness (ly:grob-property grob 'beam-thickness))
            (orig-slope (/ (- beam-length-y (+ (* 3 beam-thickness) 0.6)) beam-length-x))
            (alpha (atan orig-slope))
            (h-max (/ (+ (* 3 beam-thickness) 0.35) (cos alpha)))
           
;; markup-a is the longest beam
           
            (markup-a (markup #:beam (- beam-length-x (* half-stem-thickness 1.25)) ;; length
                 (* (car slope-1) orig-slope) ;; slope
                 beam-thickness)) ;; thickness
           
;; markup-b is begin of the first additional beam

            (y1 (- (/ (- beam-length-y (+ (* 3 beam-thickness) 0.6)) top) (/ h-max 2)))
            (x1 (/ (- beam-length-x (* half-stem-thickness 1.25)) top))

            (part-beam-1
              (if (not (equal? (car slope-2) #f))
                (markup #:beam (- (/ beam-length-x top) (* half-stem-thickness 0.8)) ;; length
                    (* (car slope-2) dir (/ y1 x1)) ;; slope
                    beam-thickness) ;; thickness
            (markup #:null)))
            (markup-b (markup part-beam-1))
            (first-part-beam-1 (grob-interpret-markup grob markup-b))
            (first-part-beam-1-ext-y (ly:stencil-extent first-part-beam-1 Y))
            (length-first-part-beam-1-y (interval-length first-part-beam-1-ext-y))

;; markup-bb is the end of the first additional beam
            (y11 (- (- beam-length-y (+ (* 3 beam-thickness) 0.6)) y1 ))
            (x11 (- beam-length-x x1))
            (part-beam-11
              (if (not (equal? (cdr slope-2) #f))
                (markup #:beam (- (- beam-length-x (/ beam-length-x top)) (* half-stem-thickness 0.8)) ;; length
                     (* (cdr slope-2) dir (/ y11 x11)) ;; slope
                     beam-thickness) ;; thickness
            (markup #:null)))
            (markup-bb (markup part-beam-11))
           
;; markup-c is the begin of the second additional beam
            (y2 (- (/ (- beam-length-y (+ (* 3 beam-thickness) 0.6)) top) h-max))
            (x2 x1)
            (part-beam-2
              (if (not (equal? (car slope-3) #f))
            (markup #:beam (- (/ beam-length-x top) (* half-stem-thickness 0.8)) ;; length
            (* (car slope-3) dir (/ y2 x2)) ;; slope
                    beam-thickness) ;; thickness
            (markup #:null)))
            (markup-c (markup part-beam-2))
           
            (first-part-beam-2 (grob-interpret-markup grob markup-c))
            (first-part-beam-2-ext-y (ly:stencil-extent first-part-beam-2 Y))
            (length-first-part-beam-2-y (interval-length first-part-beam-2-ext-y))
           
;; markup-cc is the end of the second additional beam
            (y22 (- (- beam-length-y (+ (* 3 beam-thickness) 0.6)) y2 ))
            (x22 x11)
            (part-beam-22
              (if (not (equal? (cdr slope-3) #f))
              (markup #:beam (- (- beam-length-x (/ beam-length-x top)) (* half-stem-thickness 0.8)) ;;length
                             (* (cdr slope-3) dir (/ y22 x22)) ;;slope
                             beam-thickness) ;; thickness
              (markup #:null)))
            (markup-cc (markup part-beam-22))
            )   ;; end of defs in let*
       
 (ly:stencil-translate-axis
   (ly:stencil-add
   ;; first (long beam)
     (ly:stencil-translate-axis
       (grob-interpret-markup grob markup-a)
         (/ half-stem-thickness -2.7)
          X)
   ;; parts of second beam
   (ly:stencil-in-color
     (ly:stencil-combine-at-edge
       (grob-interpret-markup grob markup-b)
       X RIGHT
       (ly:stencil-translate-axis
         (grob-interpret-markup grob markup-bb)
           (* dir (car corr-y) (- length-first-part-beam-1-y beam-thickness))
           Y)
      0)
      0 0 0) ;; <-- coloring
   ;; parts of third beam
   (ly:stencil-in-color
     (ly:stencil-combine-at-edge
      (grob-interpret-markup grob markup-c)
      X RIGHT
      (ly:stencil-translate-axis
        (grob-interpret-markup grob markup-cc)
          (* dir (cdr corr-y) (* -1 (- length-first-part-beam-2-y beam-thickness)))
          Y)
      0)
      0 0 0) ;; <-- coloring
      ) ;; end of stencil-add
   (* dir y-offset (- beam-length-y (+ (* 3 beam-thickness) 1)))
   Y)
       ) ;; end of let*
       #f))))
       
%--------------------- Test ----------------------------------------------------

\relative c' {
       
\mark\markup { \with-color #red "A" }

  \once \override Beam #'stencil = #(grow-dir-var        2 ; where to print the turn (2 is half-beam)
                   1 ; Y-offset of the whole construct
                   '(1 . 1) ; additional Y-offset
                    ;    '(<second part of the first added beam>
                    ;      .
                    ;      <second part of the second added beam>)
                   '(1 . 1) ; slope of the long beam (without) top
                   '(1 . 1) ; slope '(<first part of the first added beam>
                    ;         .
                    ;         <second part of the first added beam>)
                   '(1 . 1)) % slope '(<first part of the second added beam>
                    %         .
                    %         <second part of the second added beam>)
                    % to delete the first or second additional
                    %     beam use '(#f . #f)

  c32[ d e f g a b c]
 
\mark\markup {  \with-color #red  "B" }

  \once \override Beam #'stencil = #(grow-dir-var        1.4 ; where to print the turn (2 is half-beam)
                   1 ; Y-offset of the whole construct
                   '(1 . 1) ; additional Y-offset
                    ;    '(<second part of the first added beam>
                    ;      .
                    ;      <second part of the second added beam>)
                   '(1 . 1) ; slope of the long beam (without) top
                   '(1 . 1) ; slope '(<first part of the first added beam>
                    ;         .
                    ;         <second part of the first added beam>)
                   '(1 . 1)) % slope '(<first part of the second added beam>
                    %         .
                    %         <second part of the second added beam>)
                    % to delete the first or second additional
                    %     beam use '(#f . #f)
  c,32[ d e f g a b c]
 
\mark\markup { \with-color #red "C" }

\once \override Beam #'stencil = #(grow-dir-var 2 2.9 '(-1 . 1) '(-1 . 1) '(8 . 0.17) '(2.5 . 0.55))
a32[ g f e d c b a]

\bar "" \break

\mark\markup { \with-color #red "D" }   
       
         \once \override Beam #'stencil = #(grow-dir-var 3 ; where to print the turn (2 is half-beam)
                   -11 ; Y-offset of the whole construct
                   '(-1 . 1) ; additional Y-offset
                    ;    '(<second part of the first added beam>
                    ;      .
                    ;      <second part of the second added beam>)
                   '(1 . 1) ; slope of the long beam (without) top
                   '(1 . 0.85) ; slope '(<first part of the first added beam>
                    ;         .
                    ;         <second part of the first added beam>)
                   '(1 . 0.9)) % slope '(<first part of the second added beam>
                    %         .
                    %         <second part of the second added beam>)
                    % to delete the first or second additional
                    %     beam use '(#f . #f)
  c'32 [d' e, f g a b, c d'' e f g, a b c d
  ]

\mark\markup {  \with-color #red  "E" }
 
  \once \override Beam #'stencil = #(grow-dir-var 3 4.3 '(-1 . 1) '(1 . 1) '(2.5 . 0.1) '(1.6 . 0.45))
  c,,32 [d e f g a b c d e f g a b c d
  ]
\bar ""\break 

\mark\markup {  \with-color #red  "F" }

  \once \override Beam #'stencil = #(grow-dir-var 3 1.5 '(-1 . 1) '(-1 . 1) '(1.2 . 1.03) '(1 . 1))
  c32 [b a g f e d c b a g f e d c b
  ]
 
\mark\markup {  \with-color #red  "G" }

  \once\override Beam #'stencil = #(grow-dir-var 3.5 -2 '(-1 . 1) '(1 . 1) '(1 . 1) '(1 . 1))
  c,,32 [c c c c c c c c c c c c c c c
  ]
 
\mark\markup {  \with-color #red  "H" }
 
  \once\override Beam #'stencil = #(grow-dir-var 1.3 4 '(1 . 1) '(1 . 1) '(1 . 1) '(1 . 1))
  c32 [c' c' c,, c d e f g c e b' c'
  ]
}

Ich bin über Winkelfunktionen gegangen, hab' die Korrekturmöglichkeiten über Multiplikation geregelt und den Code teilweise vereinfacht. Das führt dazu, daß es etwas benutzerfreundlicher wird.
Auch wirken sich layout-Änderungen nicht mehr so stark aus (manchmal sind sie so gering, daß eine Nachbesserung entfallen kann).
Wenn ein Zahlenpaar '(1 . 1) beträgt, so bedeutet das, daß keine Korrektur erfolgt. Zahlen kleiner null ändern die Richtung. Es gibt jetzt auch die Möglichkeit den ersten zusätzlichen Balken durch Setzung von '(#f . #f) auszuschließen.
Ein vertikales auseinanderdriften der Teil-Beams habe ich nur noch dann gesehen, wenn die Richtung nicht stimmt. Die Korrektur erfolgte dann durch Setzung von '(-1 . 1) als "additional offset".

Den \layout-Block und die Möglichkeiten zur Einfärbung (im Code angezeigt durch: ;; <-- coloring) habe ich zur Konstruktionserleichterung benutzt und drin gelassen (ich finde sie recht hilfreich).

Ich habe noch eine (bislang unbeantwortete) Frage zu einem Teilaspekt des Problems auf der englischen Liste eingestellt. Sollte da etwas substantielles, rauskommen könnte ich das Ganze noch vereinfachen. Ansonsten glaube ich, daß es das Beste ist, was ich momentan erreichen kann.

Ansonsten habe ich ->hier noch eine ganz andere Herangehensweise gefunden:

\version "2.12.1"

% http://lists.gnu.org/archive/html/lilypond-user/2009-03/msg00620.html

\new Staff {
        << { \oneVoice \override Beam #'positions = #'(1 . 3.5)
        c'8*1/2[ d' e' f' g' a' b' c'' d''] }
        \new Voice { \oneVoice \override Beam #'positions = #'(1 . 1.2)
        c'8*1/2[ d' e' f' g'] }
        \new Voice { s4 \override Beam #'positions = #'(1.2 . 3.5) \stemUp
        g'8*1/2[ a' b' c'' d''] }
        >> }


Wenn man diesen Ansatz jedoch auf 32-tel erweitert muß man ebenfalls mit insgesamt zehn Variablen jonglieren (genau wie bei mir) und wird zusätzlich noch von Warnmeldungen im log überschwemmt. Außerdem finde ich den eigentlichen Code für die Musik noch unübersichtlicher. Aber entscheide selbst!

Gruß,
  Harm
« Letzte Änderung: Montag, 10. Oktober 2011, 01:08 von harm6 »

kilgore

  • Member
Re: grow-direction in beide Richtungen...
« Antwort #13 am: Donnerstag, 13. Oktober 2011, 09:27 »
Lieber Harm,


Wo schon eine große Verbesserung!  Mir gefällt es bei den "simplen" Beispielen, dass fast keine Änderungen nötig sind.  Jetzt bin ich aber auf ein Problem gestoßen mit Beispiel E.  Ich habe es geschafft, die Balken richtig zu ordnen, nur stimmt die Richtung nicht.  Ich habe es auch nicht schaffen können es korrekt zu richten.  Was mach ich da falsch?

\version "2.14.2"

#(set-global-staff-size 20)

\layout {
        \context {
        \Staff
        \override Beam #'layer = #-4
        %\override Beam #'color = #red
        }
}

\markup \column { \bold \fill-line { "EXAMPLE" } \vspace #2 }

#(define ((grow-dir-var top y-offset corr-y slope-1 slope-2 slope-3) grob)
 (cond ((= top 1) (and (display "\n ______________No Top wanted?________________________") #f))
       ((< top 1) (and (display "\n ______________No reachable Top!_____________________") #f))
       ((> top 1)
  (if (ly:stencil? (ly:beam::print grob))
     (let* ((beam (ly:beam::print grob))
            (dir (ly:beam::calc-direction grob))
            (beam-extent-X (ly:stencil-extent beam X))
            (beam-length-x (interval-length beam-extent-X))
            (beam-extent-Y (ly:stencil-extent beam Y))
            (beam-length-y (interval-length beam-extent-Y))
            (line-thickness (ly:output-def-lookup (ly:grob-layout grob) 'line-thickness))
            (half-stem-thickness (/ (* 1.3 line-thickness) 2))
            (beam-thickness (ly:grob-property grob 'beam-thickness))
            (orig-slope (/ (- beam-length-y (+ (* 3 beam-thickness) 0.6)) beam-length-x))
            (alpha (atan orig-slope))
            (h-max (/ (+ (* 3 beam-thickness) 0.35) (cos alpha)))
           
;; markup-a is the longest beam
           
            (markup-a (markup #:beam (- beam-length-x (* half-stem-thickness 1.25)) ;; length
                 (* (car slope-1) orig-slope) ;; slope
                 beam-thickness)) ;; thickness
           
;; markup-b is begin of the first additional beam

            (y1 (- (/ (- beam-length-y (+ (* 3 beam-thickness) 0.6)) top) (/ h-max 2)))
            (x1 (/ (- beam-length-x (* half-stem-thickness 1.25)) top))

            (part-beam-1
              (if (not (equal? (car slope-2) #f))
                (markup #:beam (- (/ beam-length-x top) (* half-stem-thickness 0.8)) ;; length
                    (* (car slope-2) dir (/ y1 x1)) ;; slope
                    beam-thickness) ;; thickness
            (markup #:null)))
            (markup-b (markup part-beam-1))
            (first-part-beam-1 (grob-interpret-markup grob markup-b))
            (first-part-beam-1-ext-y (ly:stencil-extent first-part-beam-1 Y))
            (length-first-part-beam-1-y (interval-length first-part-beam-1-ext-y))

;; markup-bb is the end of the first additional beam
            (y11 (- (- beam-length-y (+ (* 3 beam-thickness) 0.6)) y1 ))
            (x11 (- beam-length-x x1))
            (part-beam-11
              (if (not (equal? (cdr slope-2) #f))
                (markup #:beam (- (- beam-length-x (/ beam-length-x top)) (* half-stem-thickness 0.8)) ;; length
                     (* (cdr slope-2) dir (/ y11 x11)) ;; slope
                     beam-thickness) ;; thickness
            (markup #:null)))
            (markup-bb (markup part-beam-11))
           
;; markup-c is the begin of the second additional beam
            (y2 (- (/ (- beam-length-y (+ (* 3 beam-thickness) 0.6)) top) h-max))
            (x2 x1)
            (part-beam-2
              (if (not (equal? (car slope-3) #f))
            (markup #:beam (- (/ beam-length-x top) (* half-stem-thickness 0.8)) ;; length
            (* (car slope-3) dir (/ y2 x2)) ;; slope
                    beam-thickness) ;; thickness
            (markup #:null)))
            (markup-c (markup part-beam-2))
           
            (first-part-beam-2 (grob-interpret-markup grob markup-c))
            (first-part-beam-2-ext-y (ly:stencil-extent first-part-beam-2 Y))
            (length-first-part-beam-2-y (interval-length first-part-beam-2-ext-y))
           
;; markup-cc is the end of the second additional beam
            (y22 (- (- beam-length-y (+ (* 3 beam-thickness) 0.6)) y2 ))
            (x22 x11)
            (part-beam-22
              (if (not (equal? (cdr slope-3) #f))
              (markup #:beam (- (- beam-length-x (/ beam-length-x top)) (* half-stem-thickness 0.8)) ;;length
                             (* (cdr slope-3) dir (/ y22 x22)) ;;slope
                             beam-thickness) ;; thickness
              (markup #:null)))
            (markup-cc (markup part-beam-22))
            )   ;; end of defs in let*
       
 (ly:stencil-translate-axis
   (ly:stencil-add
   ;; first (long beam)
     (ly:stencil-translate-axis
       (grob-interpret-markup grob markup-a)
         (/ half-stem-thickness -2.7)
          X)
   ;; parts of second beam
   (ly:stencil-in-color
     (ly:stencil-combine-at-edge
       (grob-interpret-markup grob markup-b)
       X RIGHT
       (ly:stencil-translate-axis
         (grob-interpret-markup grob markup-bb)
           (* dir (car corr-y) (- length-first-part-beam-1-y beam-thickness))
           Y)
      0)
      0 0 0) ;; <-- coloring
   ;; parts of third beam
   (ly:stencil-in-color
     (ly:stencil-combine-at-edge
      (grob-interpret-markup grob markup-c)
      X RIGHT
      (ly:stencil-translate-axis
        (grob-interpret-markup grob markup-cc)
          (* dir (cdr corr-y) (* -1 (- length-first-part-beam-2-y beam-thickness)))
          Y)
      0)
      0 0 0) ;; <-- coloring
      ) ;; end of stencil-add
   (* dir y-offset (- beam-length-y (+ (* 3 beam-thickness) 1)))
   Y)
       ) ;; end of let*
       #f))))


%--------------------- Test ----------------------------------------------------

\relative c' {
       
\mark\markup { \with-color #red "A" }

  \once \override Beam #'stencil = #(grow-dir-var        2 ; where to print the turn (2 is half-beam)
                   -1.5 ; Y-offset of the whole construct
                   '(-1 . 1) ; additional Y-offset
                    ;    '(<second part of the first added beam>
                    ;      .
                    ;      <second part of the second added beam>)
                   '(1 . 1) ; slope of the long beam (without) top
                   '(1 . 1) ; slope '(<first part of the first added beam>
                    ;         .
                    ;         <second part of the first added beam>)
                   '(1 . 1)) % slope '(<first part of the second added beam>
                    %         .
                    %         <second part of the second added beam>)
                    % to delete the first or second additional
                    %     beam use '(#f . #f)

  c32[ c c c c c c c]
 
  \mark\markup { \with-color #red "B" }

  \once \override Beam #'stencil = #(grow-dir-var        5 ; where to print the turn (2 is half-beam)
                   -1.5 ; Y-offset of the whole construct
                   '(-1 . 1) ; additional Y-offset
                    ;    '(<second part of the first added beam>
                    ;      .
                    ;      <second part of the second added beam>)
                   '(1 . 1) ; slope of the long beam (without) top
                   '(1 . 1) ; slope '(<first part of the first added beam>
                    ;         .
                    ;         <second part of the first added beam>)
                   '(1 . 1)) % slope '(<first part of the second added beam>
                    %         .
                    %         <second part of the second added beam>)
                    % to delete the first or second additional
                    %     beam use '(#f . #f)

  c32[ c c c c c c c]
 
  \mark\markup { \with-color #red "C" }

  \once \override Beam #'stencil = #(grow-dir-var        1.3 ; where to print the turn (2 is half-beam)
                   -1.5 ; Y-offset of the whole construct
                   '(-1 . 1) ; additional Y-offset
                    ;    '(<second part of the first added beam>
                    ;      .
                    ;      <second part of the second added beam>)
                   '(1 . 1) ; slope of the long beam (without) top
                   '(1 . 1) ; slope '(<first part of the first added beam>
                    ;         .
                    ;         <second part of the first added beam>)
                   '(1 . 1)) % slope '(<first part of the second added beam>
                    %         .
                    %         <second part of the second added beam>)
                    % to delete the first or second additional
                    %     beam use '(#f . #f)

  c32[ c c c c c c c]
 
}


\relative c' {
       
\mark\markup { \with-color #red "D" }

  \once \override Beam #'stencil = #(grow-dir-var        2 ; where to print the turn (2 is half-beam)
                   -1.7 ; Y-offset of the whole construct
                   '(-1 . 1) ; additional Y-offset
                    ;    '(<second part of the first added beam>
                    ;      .
                    ;      <second part of the second added beam>)
                   '(1 . 1) ; slope of the long beam (without) top
                   '(1 . 1) ; slope '(<first part of the first added beam>
                    ;         .
                    ;         <second part of the first added beam>)
                   '(1 . 1)) % slope '(<first part of the second added beam>
                    %         .
                    %         <second part of the second added beam>)
                    % to delete the first or second additional
                    %     beam use '(#f . #f)

  g''32[ g g g g g g g]
 
  \mark\markup { \with-color #red "E" }

  \once \override Beam #'stencil = #(grow-dir-var        2 ; where to print the turn (2 is half-beam)
                   2 ; Y-offset of the whole construct
                   '(-1 . -1) ; additional Y-offset
                    ;    '(<second part of the first added beam>
                    ;      .
                    ;      <second part of the second added beam>)
                   '(1 . -1) ; slope of the long beam (without) top
                   '(-1 . -1) ; slope '(<first part of the first added beam>
                    ;         .
                    ;         <second part of the first added beam>)
                   '(-1 . -1)) % slope '(<first part of the second added beam>
                    %         .
                    %         <second part of the second added beam>)
                    % to delete the first or second additional
                    %     beam use '(#f . #f)

  c,,32[ e g b d f a c]
 
}
 



Was ich auch nicht verstehe:

Beam #'layer - Wenn ich das auskommentiere ändert sich (scheinbar nichts).  Was hat es zu bedeuten?

Auch - das Y-Offset vom ganzen Konstrukt - Positive zahlen bewegen alles nach unten, negative nach oben.  Klappt, aber warum nicht umgekehrt?

Grüße
kil

harm6

  • Member
Re: grow-direction in beide Richtungen...
« Antwort #14 am: Donnerstag, 13. Oktober 2011, 12:27 »
Hallo kil,

heute vormittag habe ich kaum Zeit, deshalb nur in aller Kürze: Meine Anfrage auf der englischen Liste führte tatsächlich zu einer wertvollen Erkenntnis.
In der Folge habe ich die notwendigen Variablen reduzieren können, y-offset konnte ich eliminieren (corr-y und slope-1 auch), deshalb gehe ich nicht weiter darauf ein.
Ich hatte noch keine Gelegenheit mich darum zu kümmern, ob es möglich ist die Definition für die zusätzlichen Balken auch noch zu verbessern. Genau dort liegt nämlich das Problem welches Du schilderst.
Nichtsdestotrotz kann man mit der Definition auf ihrem derzeitigen Stand zu einem befriedigenden Ergebnis kommen. (Die dazu nötigen Werte legen aber ebenfalls die Vermutung nahe, daß irgenwas noch nicht ganz in Ordnung ist.) Dein Beispiel ist bei Buchstabe "J".

Ein Wort zu 'layer. Das layer-property bestimmt in welcher Reihenfolge "gedruckt" wird. Wenn ich \override Beam #'layer = #-4 einstelle, dann wird der Balken (normalerweise) zuerst gedruckt. Sichtbar ist ein Effekt nur dann, wenn man den Balken einfärbt. Ich benutze es, um zu kontrollieren wie tief die Stems in den Beam hineinragen. Im Code unten habe ich per layout die Balkenfarbe (für den langen Balken) gelb eingestellt, sodaß Du den Effekt sehen können müßtest. Das kannst Du natürlich problemlos wieder rückgämgig machen. Die zusätzlichen Balken kann man auch einzeln einfärben (wenn auch an anderer Stelle im Code). Wie schon gesagt das Ganze dient der Kontrolle, nicht der Konstruktion.

\version "2.14.2"

#(set-global-staff-size 20)

\layout {
        \context {
        \Staff
        \override Beam #'layer = #-4
        \override Beam #'color = #yellow
        }
}

\markup \column { \bold \fill-line { "EXAMPLE" } \vspace #2 }

#(define ((grow-dir-var top slope-2 slope-3) grob)
 (cond ((= top 1) (and (display "\n ______________No Top wanted?________________________") #f))
       ((< top 1) (and (display "\n ______________No reachable Top!_____________________") #f))
       ((> top 1)
  (if (ly:stencil? (ly:beam::print grob))
     (let* ((beam (ly:beam::print grob))
            (dir (ly:beam::calc-direction grob))
            (beam-extent-X (ly:stencil-extent beam X))
            (beam-length-x (interval-length beam-extent-X))
            (beam-extent-Y (ly:stencil-extent beam Y))
            (beam-length-y (interval-length beam-extent-Y))
            (line-thickness (ly:output-def-lookup (ly:grob-layout grob) 'line-thickness))
            (half-stem-thickness (/ (* 1.3 line-thickness) 2))
            (beam-thickness (ly:grob-property grob 'beam-thickness))
            (beam-positions (ly:grob-property grob 'positions))
            (beam-slant (if (>= (car beam-positions) (cdr beam-positions)) -1 1))
            (orig-slope (* beam-slant (/ (- beam-length-y (+ (* 3 beam-thickness) 0.6)) beam-length-x)))
            (alpha (atan orig-slope))
            (h-max (/ (+ (* 3 beam-thickness) 0.35) (cos alpha)))
           
;; markup-a is the longest beam
           
            (markup-a (markup #:beam (- beam-length-x (* half-stem-thickness 1.25)) ;; length
                 orig-slope ;; slope
                 beam-thickness)) ;; thickness
           
;; markup-b is begin of the first additional beam

            (y1 (- (/ (- beam-length-y (+ (* 3 beam-thickness) 0.6)) top) (/ h-max 2)))
            (x1 (/ (- beam-length-x (* half-stem-thickness 1.25)) top))

            (part-beam-1
              (if (not (equal? (car slope-2) #f))
                (markup #:beam (- (/ beam-length-x top) (* half-stem-thickness 0.8)) ;; length
                ;(if (and (> dir 0) (> beam-slant 0))
                        ;(/ y1 x1)
                    (* (car slope-2) dir (/ y1 x1))
                    ;) ;; slope
                    beam-thickness) ;; thickness
            (markup #:null)))
            (markup-b (markup part-beam-1))
            (first-part-beam-1 (grob-interpret-markup grob markup-b))
            (first-part-beam-1-ext-y (ly:stencil-extent first-part-beam-1 Y))
            (length-first-part-beam-1-y (interval-length first-part-beam-1-ext-y))

;; markup-bb is the end of the first additional beam
            (y11 (- (- beam-length-y (+ (* 3 beam-thickness) 0.6)) y1 ))
            (x11 (- beam-length-x x1))
            (part-beam-11
              (if (not (equal? (cdr slope-2) #f))
                (markup #:beam (- (- beam-length-x (/ beam-length-x top)) (* half-stem-thickness 0.8)) ;; length
                     (* (cdr slope-2) dir (/ y11 x11)) ;; slope
                     beam-thickness) ;; thickness
            (markup #:null)))
            (markup-bb (markup part-beam-11))
           
;; markup-c is the begin of the second additional beam
            (y2 (- (/ (- beam-length-y (+ (* 3 beam-thickness) 0.6)) top) h-max))
            (x2 x1)
            (part-beam-2
              (if (not (equal? (car slope-3) #f))
            (markup #:beam (- (/ beam-length-x top) (* half-stem-thickness 0.8)) ;; length
            (* (car slope-3) dir (/ y2 x2)) ;; slope
                    beam-thickness) ;; thickness
            (markup #:null)))
            (markup-c (markup part-beam-2))
           
            (first-part-beam-2 (grob-interpret-markup grob markup-c))
            (first-part-beam-2-ext-y (ly:stencil-extent first-part-beam-2 Y))
            (length-first-part-beam-2-y (interval-length first-part-beam-2-ext-y))
           
;; markup-cc is the end of the second additional beam
            (y22 (- (- beam-length-y (+ (* 3 beam-thickness) 0.6)) y2 ))
            (x22 x11)
            (part-beam-22
              (if (not (equal? (cdr slope-3) #f))
              (markup #:beam (- (- beam-length-x (/ beam-length-x top)) (* half-stem-thickness 0.8)) ;;length
                             (* (cdr slope-3) dir (/ y22 x22)) ;;slope
                             beam-thickness) ;; thickness
              (markup #:null)))
            (markup-cc (markup part-beam-22))
            )   ;; end of defs in let*
       
 (ly:stencil-translate-axis
   (ly:stencil-add
   ;; first (long beam)
     (ly:stencil-translate-axis
       (grob-interpret-markup grob markup-a)
         (/ half-stem-thickness -2.5)
          X)
   ;; parts of second beam
   (ly:stencil-in-color
     (ly:stencil-combine-at-edge
       (ly:stencil-translate-axis
         (grob-interpret-markup grob markup-b)
         (/ half-stem-thickness -2.5) X)
       X RIGHT
       (ly:stencil-translate-axis
         (grob-interpret-markup grob markup-bb)
           (cond ((> dir 0)
                    (* beam-slant (- length-first-part-beam-1-y beam-thickness)))
                 ((and (< dir 0) (> beam-slant 0))
                    (* beam-slant (- length-first-part-beam-1-y beam-thickness)))
                 ((and (< dir 0) (< beam-slant 0))
                    (- length-first-part-beam-1-y beam-thickness)))
           Y)
      0)
      0 0 0) ;; <-- coloring
   ;; parts of third beam
   (ly:stencil-in-color
     (ly:stencil-combine-at-edge
      (grob-interpret-markup grob markup-c)
      X RIGHT
      (ly:stencil-translate-axis
        (grob-interpret-markup grob markup-cc)
          (cond ((> dir 0)
            (* -1 (- length-first-part-beam-2-y beam-thickness)))
                 ((and (< dir 0) (> beam-slant 0))
                    (* beam-slant (* beam-slant (- length-first-part-beam-2-y beam-thickness))))
                 ((and (< dir 0) (< beam-slant 0))
                    (* beam-slant (* beam-slant (- length-first-part-beam-2-y beam-thickness)))))
          Y)
      0)                                     
      0 0 0) ;; <-- coloring
      ) ;; end of stencil-add
   (car beam-positions)
   Y)
       ) ;; end of let*
       #f))))
       
%--------------------- Test ----------------------------------------------------

\relative c' {
       
\mark\markup { \with-color #red "A" }

  \once \override Beam #'stencil = #(grow-dir-var        2 ; where to print the turn (2 is half-beam)
                   '(1 . 1) ; slope '(<first part of the first added beam>
                    ;         .
                    ;         <second part of the first added beam>)
                   '(1 . 1)) % slope '(<first part of the second added beam>
                    %         .
                    %         <second part of the second added beam>)
                    % to delete the first or second additional
                    %     beam use '(#f . #f)

  c32[ d e f g a b c]
 
\mark\markup {  \with-color #red  "B" }

  \once \override Beam #'stencil = #(grow-dir-var        1.4 ; where to print the turn (2 is half-beam)
                   '(1 . 1) ; slope '(<first part of the first added beam>
                    ;         .
                    ;         <second part of the first added beam>)
                   '(1 . 1)) % slope '(<first part of the second added beam>
                    %         .
                    %         <second part of the second added beam>)
                    % to delete the first or second additional
                    %     beam use '(#f . #f)
  c,32[ d e f g a b c]
 
\mark\markup { \with-color #red "C" }

\once \override Beam #'stencil = #(grow-dir-var 2  '(8 . 0.17) '(2.5 . 0.55))
a32[ g f e d c b a]

\mark\markup {  \with-color #red  "D" }
 
  \once\override Beam #'stencil = #(grow-dir-var 3.5  '(1 . 1) '(1 . 1))
  c,32 [c c c c c c c c c c c c c c c
  ]

\bar "" \break

\mark\markup { \with-color #red "E" }   
       
         \once \override Beam #'stencil = #(grow-dir-var 3 ; where to print the turn (2 is half-beam)
                   '(1 . 0.85) ; slope '(<first part of the first added beam>
                    ;         .
                    ;         <second part of the first added beam>)
                   '(1 . 0.9)) % slope '(<first part of the second added beam>
                    %         .
                    %         <second part of the second added beam>)
                    % to delete the first or second additional
                    %     beam use '(#f . #f)
  c''32 [d' e, f g a b, c d'' e f g, a b c d
  ]
 
\mark\markup {  \with-color #red  "F" }
 
  \once \override Beam #'stencil = #(grow-dir-var 3  '(2.5 . 0.1) '(1.6 . 0.45))
  c,,32 [d e f g a b c d e f g a b c d
  ]
\bar ""\break 

\mark\markup {  \with-color #red  "G" }

  \once \override Beam #'stencil = #(grow-dir-var 3   '(1.2 . 1.03) '(1 . 1))
  c32 [b a g f e d c b a g f e d c b
  ]

\mark\markup {  \with-color #red  "H" }
 
  \once\override Beam #'stencil = #(grow-dir-var 1.3  '(1 . 1) '(1 . 1))
  c,32 [c' c' c,, c d e f g c e b' c'
  ]
}

\relative c' {
  \mark\markup { \with-color #red "J" }

  \once \override Beam #'stencil = #(grow-dir-var        2
                   '(-3.2 . -0.33) ; slope '(<first part of the first added beam>
                    ;         .
                    ;         <second part of the first added beam>)
                   '(42 . 0.05)) % slope '(<first part of the second added beam>
                    %         .
                    %         <second part of the second added beam>)
                    % to delete the first or second additional
                    %     beam use '(#f . #f)

  c32[ e g b d f a c]
}


Gruß,
  Harm