Mark Polesky wrote:

> Okay, this is not ready yet. I found a confusing problem. When setting
> connectArpeggios to #f after it has been #t, there's some issue with
> the unreverted PianoStaff stencil somehow overriding the new Voice
> stencil. Or something. I'm not really sure -- it's confusing.

Oh man, that was rough. But I think I solved it. The problem was that
the macro was looking for a context where 'connectArpeggios was set to
#t to set and revert the properties. This worked fine when it was set
to #t, but once it was set to #f, the macro couldn't find the old
properties to revert. So the old PianoStaff properties, defined in one
staff, were overriding the old Voice properties defined in the other
staff. Confusing, but I got it.

I've rewritten it so that now it should all work. If you're curious, the
procedure called "move-arpeggio-to-this-context" is what does the trick.
This is called just before setting 'connectArpeggios to #f.

Also, to ease the burden on the user, I went ahead and made two new
commands, \connectArpeggiosOn and \connectArpeggiosOff. Without these,
the user would have to manually call "move-arpeggio-to-this-context"
just before setting 'connectArpeggios to #f. The new \connectArpeggiosOff
command automates this.

So now, I *think*, all the built-in arpeggio commands such work
intuitively, regardless of the connectArpeggios value.

Hopefully there are no more snafus, but I need you guys to test this.
Let me know if you find any problems. I'd like to apply this if the
developers approve.

(see the attached file)

Thanks.
- Mark



      
\version "2.13.3"

%%%%%% begin property-init.ly revision %%%%%%

#(define (arpeggio-generic context pushpops)
  (let* ((parent (ly:context-property-where-defined context
                                                    'connectArpeggios))
         (target (if (and (not (null? parent))
                          (eq? #t (ly:context-property parent
                                                       'connectArpeggios)))
                     parent
                     context)))
    (for-each
      (lambda (pushpop)
        (if (pair? pushpop)
            (ly:context-pushpop-property target
                                         'Arpeggio
                                         (car pushpop)
                                         (cdr pushpop))
            (ly:context-pushpop-property target
                                         'Arpeggio
                                         pushpop)))
      pushpops)))

#(define move-arpeggio-to-this-context
  ;; if the active arpeggio properties are set in GrandStaff, PianoStaff,
  ;; or StaffGroup, move them into this context (usually Voice).
  (lambda (context)
    (let ((parent (ly:context-property-where-defined context
                                                     'connectArpeggios)))
      (if (and (not (null? parent))
               (eq? #t (ly:context-property parent 'connectArpeggios)))
          (let* ((Arpeggio (ly:context-grob-definition context 'Arpeggio))
                 (X-extent           (assoc 'X-extent           Arpeggio))
                 (stencil            (assoc 'stencil            Arpeggio))
                 (arpeggio-direction (assoc 'arpeggio-direction Arpeggio))
                 (direction          (assoc 'direction          Arpeggio))
                 (dash-definition    (assoc 'dash-definition    Arpeggio))
                 (props `((X-extent           . ,X-extent)
                          (stencil            . ,stencil)
                          (arpeggio-direction . ,arpeggio-direction)
                          (direction          . ,direction)
                          (dash-definition    . ,dash-definition))))
            (for-each
              (lambda (prop)
                ;; copy <parent>.Arpeggio props to <context>.Arpeggio
                (if (cdr prop)
                    (ly:context-pushpop-property context
                                                 'Arpeggio
                                                 (cadr prop)
                                                 (cddr prop))
                    (ly:context-pushpop-property context
                                                 'Arpeggio
                                                 (car prop)))
                ;; revert <parent>.Arpeggio props
                (ly:context-pushpop-property parent 'Arpeggio (car prop)))
              props))))))

#(define (connect-arpeggios-switch value)
  (lambda (context)
    (define target-list '(GrandStaff PianoStaff StaffGroup))
    (define (find-target context)
      (if (member (ly:context-name context) target-list)
          context
          (let ((parent (ly:context-parent context)))
            (if parent
                (let ((parent-name (ly:context-name parent)))
                  (if (member parent-name target-list)
                      parent
                      (find-target parent)))
                #f))))
    (let ((target (find-target context)))
      (if target
          (ly:context-set-property! target 'connectArpeggios value)
          (ly:warning "No viable context found for connectArpeggios")))))

connectArpeggiosOn =
  \applyContext #(connect-arpeggios-switch #t)

connectArpeggiosOff = {
  \applyContext #move-arpeggio-to-this-context
  \applyContext #(connect-arpeggios-switch #f)
}

arpeggioArrowUp =
\applyContext
  #(lambda (context)
    (arpeggio-generic context
      `(stencil X-extent (arpeggio-direction . ,UP))))

arpeggioArrowDown =
\applyContext
  #(lambda (context)
    (arpeggio-generic context
      `(stencil X-extent (arpeggio-direction . ,DOWN))))

arpeggioNormal =
\applyContext
  #(lambda (context)
     (arpeggio-generic context
       '(stencil X-extent arpeggio-direction dash-definition)))

arpeggioBracket =
\applyContext
  #(lambda (context)
    (arpeggio-generic context
      `(X-extent (stencil . ,ly:arpeggio::brew-chord-bracket))))


%%%%%% end property-init.ly revision %%%%%%


%%%%%% demonstration %%%%%%


\new PianoStaff \relative <<
  \new Staff {
    \arpeggioArrowUp
    <c e g>4\arpeggio

    \connectArpeggiosOn
    \arpeggioBracket
    <c e g>4\arpeggio

    \connectArpeggiosOff
    <c e g>\arpeggio
  }
  \new Staff {
    \clef bass
    \arpeggioArrowDown
    <c, e g>4\arpeggio

    <c e g>\arpeggio

    <c e g>\arpeggio
  }
>>
_______________________________________________
lilypond-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/lilypond-devel

Reply via email to