Hello Kieren, that seems to be correct.

One could also try something like this.

Cheers,
Valentin

Am Samstag, 22. Jänner 2022, 03:22:42 CET schrieb Kenneth Wolcott:
> Hi;
> 
>   I have a piece of music from which I am engraving that confuses me.
> 
>   At bar #13 there is the Segno sign.
> 
>   At the end of bar #20 there is a "Fine".
> 
>   At the end of the piece (bar #37) there is a "D.S. al Fine".
> 
>   I'd like to have Lilypond generate midi output that would match this
> intent.
> 
>   Does this mean:
>   Play all the way through; then start at the Segno and continue until the
> Fine?
> 
> I think that's what it means.
> 
> So I need to have bar #1 to bar #12 in one macro;
> bar #13 through bar #20 in a second macro;
> and the third macro would contain bars 21-33.
> 
> Then I need "M_one", "M_two", "M_three", followed by "M_two" to
> implement this in the midi score section.
> 
> Is that correct?
> 
> Thanks,
> Ken Wolcott
unfoldJumpMarks =
#(define-music-function (music) (ly:music?)
   (let ((jump-points '()) (jump-marks '()) (chained-jumps '()) (current-fine #f) (result-music '()))
   (define (search-music music)
     (let ((this-jump-points (ly:music-property music 'jump-points))
           (jump-details (ly:music-property music 'jump-details)))
       (for-each (lambda (x)
                   (set! jump-points
                         `((,x . ,music) . ,jump-points)))
                 this-jump-points)
       (if (not (null? jump-details))
           (set! jump-marks `((,music . ,jump-details))))))
   (define (listify-music music-list)
     (if (null? music-list) '()
         (begin
          (ly:music-set-property! (car music-list) 'LIST-next (listify-music (cdr music-list)))
          (car music-list))))
   (define (walk-search-music music)
     (let ((elts (ly:music-property music 'elements)))
       (listify-music elts)
       (map search-music elts)
       (if (not (assoc-get 'BEGIN-OF-PIECE jump-points #f))
           (set! jump-points
                 `((BEGIN-OF-PIECE . ,(car elts)) . ,jump-points)))))
   (define (build-music)
     (let ((current-pos (assoc-get 'BEGIN-OF-PIECE jump-points)))
       (while #t
              (set! result-music (cons current-pos result-music))
              (let* ((mem-pos current-pos)
                     (next-el (ly:music-property current-pos 'LIST-next))
                     (this-j-point (any (lambda (x)
                                          (if
                                            (or (eq? current-pos (assoc-get (car x) jump-points))
                                                (and ;; treat end of music as begin-jump-mark END-OF-PIECE
                                                 (equal? (car x) 'END-OF-PIECE)
                                                 (null? next-el)))
                                            x
                                            #f))
                                        chained-jumps))
                     (this-jump-instruction (assq-ref jump-marks current-pos))
                     (this-jump-instruction (if this-jump-instruction this-jump-instruction '())))
                (if this-j-point ;; reached a triggered jump
                    (begin
                      (set! current-pos (assoc-get (cdr this-j-point) jump-points))
                      (set! chained-jumps (delete this-j-point chained-jumps)))
                    (if (or (null? this-jump-instruction) (not (car this-jump-instruction))) ;; no active jump-mark was found
                        (if (or (null? next-el) (eq? current-pos (assoc-get current-fine jump-points)))  ;; no jump and no more music or at fine
                            (break)
                            (set! current-pos next-el)) ;; set to next element
                        (let* ((now-jump (car this-jump-instruction)) ;; found am active jump mark, perform jump
                               (first-jump (first now-jump))
                               (following-jumps (second now-jump))
                               (this-fine (if (> (length now-jump) 2)
                                              (third now-jump)
                                              #f)))
                          (set! current-pos (assoc-get first-jump jump-points))
                          (set! chained-jumps (append following-jumps chained-jumps))
                          (if this-fine
                              (set! current-fine this-fine)))))
                (if (not (null? this-jump-instruction))
                    (set! jump-marks (assq-set! jump-marks mem-pos (cdr this-jump-instruction))))))))
   (walk-search-music music)
   (build-music)
   (ly:music-set-property! music 'elements (reverse result-music))
   music))

jumpPoint =
#(define-music-function (mark music) (symbol? ly:music?)
   (ly:music-set-property! music 'jump-points
                           (cons mark
                                 (ly:music-property music 'jump-points)))
   music)

jumpMark =
#(define-music-function (dets music) (list? ly:music?)
   (ly:music-set-property! music 'jump-details dets)
   music)


%\unfoldJumpMarks { c' d' e' f' g' a' b' c'' }
%\unfoldJumpMarks { c' d' e' f' \jumpPoint BEGIN-OF-PIECE g' a' b' c'' }


{ \tweak color #red c'^"begin" d' e' \jumpPoint fine \tweak color #green f'^"fine"
                   \jumpPoint segno \tweak color #blue g'^"segno" a' b'
                   \jumpMark #'((BEGIN-OF-PIECE ((fine . BEGIN-OF-PIECE)))
                                (segno ((END-OF-PIECE . BEGIN-OF-PIECE)) fine))
                                \tweak color #yellow c''^\markup\column{ "(1) D.C.→fine & D.C.→'()" "(2) D.S.→END & D.C.→fine" }
  d'' e'' f'' g''
}

{\omit TextScript
 \unfoldJumpMarks
 { \tweak color #red c'^"begin" d' e' \jumpPoint fine \tweak color #green f'^"fine"
                   \jumpPoint segno \tweak color #blue g'^"segno" a' b'
                   \jumpMark #'((BEGIN-OF-PIECE ((fine . BEGIN-OF-PIECE)))
                                (segno ((END-OF-PIECE . BEGIN-OF-PIECE)) fine))
                                \tweak color #yellow c''^\markup\column{ "(1) D.C.→fine & D.C.→'()" "(2) D.S.→END & D.C.→fine" }
   d'' e'' f'' g''
 }
}

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to