Re: Attempt at divisi automating engraver

2019-01-01 Thread Saul Tobin
Still working on this...

The new version attached sets make-dead-when so that staves with fewer
parts have priority over those that they can be merged into. (Disregard
what I wrote previously about remove-layers — I got a bit confused.) The
engraver now does mainly what it is supposed to, namely provide an
intuitive UI for condensing n-parts into shared staves.

Two issues currently, which I am not yet sure how to solve:

1) The engraver is not able to push a change to keepAliveInterfaces to a
context that does not already have an event at the current moment.

2) If the status of alive/hidden staves changes on the first moment of a
system, the status from the last moment of the previous system will still
apply.

Hopefully this is of interest to at least a few others.

>


divisi_engraver.ly
Description: Binary data
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Attempt at divisi automating engraver

2018-12-30 Thread Saul Tobin
Updating this with cleaned up code and a clearer example in four parts.
Realized a few things:

1) The context property changes are working as I expected and staves are
correctly hiding or showing. There is no need to use remove-layers here.

2) When keepAliveInterfaces is set to '() in the first moment of a system,
the new value only applies starting after the line break, so if the staff
was alive on the previous system it will be kept alive on this system. The
workaround is to apply changes to keepAliveInterfaces at a moment just
before they are meant to take effect. This makes for awkward user input,
but doing it automatically would require the engraver looking a moment into
the future. Is looking ahead a feasible thing for an engraver to do? Should
this be written as an iterator instead?

\version "2.19.82"

% From define-context-properties.scm
#(define (translator-property-description symbol type? description)
   (if (not (and
 (symbol? symbol)
 (procedure? type?)
 (string? description)))
   (throw 'init-format-error))


   (if (not (equal? #f (object-property symbol 'translation-doc)))
   (ly:error (_ "symbol ~S redefined") symbol))

   (set-object-property! symbol 'translation-type? type?)
   (set-object-property! symbol 'translation-doc description)
   (set! all-translation-properties (cons symbol
all-translation-properties))
   symbol)


#(translator-property-description 'sharingParts list? "List of consecutive
ints, indices of parts sharing this staff.")
#(translator-property-description 'combineWithNext boolean? "Is it okay for
this music to share a staff with the music in the next staff?")

#(define (segment pred lst)
   "Segments a list into sublists, such that all elements satisfy pred
except the last element of each sublist."
   (fold-right
(lambda (x y)
  (if (pred x)
  (cons (cons x (car y)) (cdr y))
  (cons (list x) y)))
'(() . ())
lst))

% #(display (segment cdr '((1 . #f) (2 . #t) (3 . #t

Staff_sharing_engraver = #(lambda (ctx)
(let* ((all-staves '())
   (solo-staves '()))
  (make-engraver
   (acknowledgers
((hara-kiri-group-spanner-interface
  engraver grob source-engraver)
 ; We need an alist of child contexts, but
getting them this way
 ; means the engraver can't operate on the
first measure.
 ; Not sure what the proper way to get them
is?
 (let* (
 (child-ctx (ly:translator-context
source-engraver))
 (child-id (ly:context-id
child-ctx))
 (child-parts (ly:context-property
child-ctx 'sharingParts))
 )
   (set! all-staves (assoc-set! all-staves
child-parts child-ctx))

   ; Build alist of just the staves for a
single part.
   (if (and (eq? 1 (length child-parts))
(not (assoc child-parts
solo-staves)))
   (set! solo-staves
 (merge solo-staves
   (acons child-parts child-ctx
'())
   (lambda (x y) (< (caar x)
(caar y)))
 ))


   ((start-translation-timestep translator)
(let* (
; Build alist of index:
combineWithNext value for solo staves
(combine-which-parts (fold-right
  (lambda (kv
result)
(acons (car
kv)

(ly:context-property (cdr kv) 'combineWithNext)
  result))
  '()
  solo-staves))

; Split the list by which parts can
be combined
; Then just keep the part indices
(groups (map
 (lambda (sublst)
   (map caar sublst))
 (segment cdr
combine-which-parts)))
; Use the index lists to select
staves
(live-ctxs (if (pair? (car groups))
 

Attempt at divisi automating engraver

2018-12-29 Thread Saul Tobin
Hi all,

Attached is my latest attempt to make progress toward an automatic
mechanism for n-parts that may share a staff or not.

The idea is that if the context property combineNext = ##t, then that part
can share a staff with the next part down. The engraver is supposed to set
keepAliveInterfaces = '() for all the staves except the ones corresponding
to the current part grouping. Then depending on line-breaking, staves will
be hidden according to remove-layers.

I have two issues currently:
1) How to initialize the engraver with a list of child staff contexts?
Grabbing them by acknowledging hara-kiri-group-spanner grobs means this
engraver can't affect which staves display on the first system, which isn't
ideal. Is there a better way?

2) ly:context-set-property! seems to work in the sense that the changed
value gets read back correctly, but it doesn't seem like it's affecting the
music output as I'd expect. Should I be having the engraver broadcast a
property change event or something? How would one even do that? Or is this
something to do with the timing of property changes happening over line
breaks?

Apologies for the less than elegant Scheme code. I would love some
feedback/assistance on how to improve this or approach it better.

Happy new year!
\version "2.19.82"

#(debug-enable 'debug)

unfrench = #'(
   bass-figure-interface
   chord-name-interface
   cluster-beacon-interface
   fret-diagram-interface
   lyric-syllable-interface
   note-head-interface
   tab-note-head-interface
   lyric-interface
   percent-repeat-item-interface
   percent-repeat-interface
   ;; need this, as stanza numbers are items, and appear only once.
   stanza-number-interface

   multi-measure-rest-interface
   )

% From define-context-properties.scm
#(define (translator-property-description symbol type? description)
   (if (not (and
 (symbol? symbol)
 (procedure? type?)
 (string? description)))
   (throw 'init-format-error))


   (if (not (equal? #f (object-property symbol 'translation-doc)))
   (ly:error (_ "symbol ~S redefined") symbol))

   (set-object-property! symbol 'translation-type? type?)
   (set-object-property! symbol 'translation-doc description)
   (set! all-translation-properties (cons symbol all-translation-properties))
   symbol)


#(translator-property-description 'sharingParts list? "List of consecutive ints, indices of parts sharing this staff.")
#(translator-property-description 'combineNext boolean? "Is it okay for this music to share a staff with the music in the next staff?")

%% modified from lily-library.scm
#(define (split-at-predicate pred lst)
   "Split LST into two lists at the first element that returns #t for
  (PRED element).  Return the two parts as a pair.
  Example: (split-at-predicate odd? '(0 2 3 2 0)) ==> ((0 2 3) . (2 0))"
   (let ((i (and (pair? lst)
 (list-index pred
   lst
 (if i
 (call-with-values
  (lambda () (split-at lst (1+ i)))
  cons)
 (list lst

#(define (rsplit pred lst)
   (let ((splitted (split-at-predicate pred lst)))
 (if (pair? (cdr splitted))
 (cons (car splitted) (rsplit pred (cdr splitted)))
 splitted)))

% #(display (rsplit (lambda (x) (not (cdr x))) '((1 . #f) (2 . #t) (3 . #t

Staff_sharing_engraver = #(lambda (ctx)
(let* ((all-staves '())
   (solo-staves '()))
  (make-engraver
   (acknowledgers
((hara-kiri-group-spanner-interface
  engraver grob source-engraver)
 ; We need an alist of child contexts, but getting them this way
 ; means the engraver can't operate on the first measure.
 ; Not sure what the proper way to get them is?
 (let* (
 (child-ctx (ly:translator-context source-engraver))
 (child-id (ly:context-id child-ctx))
 (child-parts (ly:context-property child-ctx 'sharingParts))
 )
   (set! all-staves (assoc-set! all-staves child-parts child-ctx))

   ; Build alist of just the staves for a single part.
   (if (and (eq? 1 (length child-parts))
(not (assoc child-parts solo-staves)))
   (set! solo-staves
 (merge solo-staves