lilypond-user
[Top][All Lists]
Advanced

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

Re: \stopStaff \startStaff bug


From: Lukas-Fabian Moser
Subject: Re: \stopStaff \startStaff bug
Date: Fri, 6 Jan 2023 00:37:11 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2

Hi Tomasz,

Am 05.01.23 um 13:16 schrieb Tomasz Bauć:
I also checked version without the Scheme:

    \stopStaff
    \repeat unfold 9 {s8}
    \startStaff
    \stopStaff
    \repeat unfold 3 {s8}
    \startStaff
    \stopStaff
    \repeat unfold 11 {s8}
    \startStaff

(Please always give complete, compilable examples!)

The Staff_symbol_engraver is not really equipped to deal with multiple \startStaff / \stopStaff events at the same point of time. For a workaround, (there's probably an easier method, but) since I couldn't find a way of "killing" events in the time step cycle, I decided to wrap the startStaff/stopStaff commands into a custom event type that counts the simultaneous (start-/stop-)Staff commands and goes by the majority, so to speak:

\version "2.24"

#(define-event-class 'custom-staff-span-event 'span-event)

#(define my-types
   '((CustomStaffSpanEvent
      . ((description . "Custom wrapper to StaffSpanEvent.")
         (types . (event span-event custom-staff-span-event))))))

#(set!
  my-types
  (map (lambda (x)
         (set-object-property! (car x)
                               'music-description
                               (cdr (assq 'description (cdr x))))
         (let ((lst (cdr x)))
           (set! lst (assoc-set! lst 'name (car x)))
           (set! lst (assq-remove! lst 'description))
           (hashq-set! music-name-to-property-table (car x) lst)
           (cons (car x) lst)))
       my-types))

#(set! music-descriptions
       (append my-types music-descriptions))

#(set! music-descriptions
       (sort music-descriptions alist<?))

stopStaff = #(make-span-event 'CustomStaffSpanEvent STOP)
startStaff = #(make-span-event 'CustomStaffSpanEvent START)

Staff_stop_collecting_engraver = #
(lambda (context)
  (let
   ((stop-events 0)
    (start-events 0))
   (make-engraver
    (listeners
     ((custom-staff-span-event engraver event)
      (if (= (ly:event-property event 'span-direction) STOP)
          (set! stop-events (1+ stop-events))
          (set! start-events (1+ start-events)))))
    ((pre-process-music engraver)
     (when (not (= start-events stop-events))
       (ly:broadcast
        (ly:context-event-source context)
        (ly:make-stream-event
         (ly:make-event-class 'staff-span-event)
         `((span-direction . ,(sign (- stop-events start-events)))))))
     (set! stop-events 0)
     (set! start-events 0)))))

\layout {
  \context {
    \Staff
    \consists #Staff_stop_collecting_engraver
  }
}

<<
  \new Staff {
    c'1
    \stopStaff
    s1
    \startStaff
    \stopStaff
    s1
    \startStaff
    c'1
    \stopStaff
    \startStaff
    c'1
  }
  \new Staff { \repeat unfold 5 c'1 }

>>

Lukas




reply via email to

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