[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to get all Voice-Contexts?
From: |
Thomas Morley |
Subject: |
Re: How to get all Voice-Contexts? |
Date: |
Sat, 28 Nov 2015 00:24:51 +0100 |
2015-11-27 23:45 GMT+01:00 David Kastrup <address@hidden>:
> Thomas Morley <address@hidden> writes:
>
>> Hi,
>>
>> for some engraver I need to look at all Voices, comparing them in some
>> regard.
>>
>> If I put the engraver in every Voice, then every Voice is processed,
>> yes, but I can't find a method to compare them.
>> So I thought the way might be to put the engraver in Score, get the
>> Voices and do nasty things ...
>>
>> Though, I can't find a method to select all Voices.
>>
>> Consider this tiny and boiled down example:
>>
>> %%%%%%%%%%%%%%%
>> \version "2.19.32"
>>
>> get-Voices =
>> \context Score \applyContext #(lambda (ctx) (display ctx))
>>
>> \score {
>> \new Staff
>> <<
>> \new Voice = "1" { \get-Voices c''1 }
>> \new Voice = "2" { e'1 }
>> >>
>> }
>> %%%%%%%%%%%%%%%%
>>
>> How to get all Voices looking down from Score?
>
> You could have an engraver listen for AnnounceNewContext and
> RemoveContext events and keep tally of the Voice contexts among them in
> a hash table or something like that.
>
> --
> David Kastrup
As a first step, this leads to:
\version "2.19.32"
#(define (my-engraver ctx)
(let ((voices '()))
`(
(listeners
;; TODO: don't forget `RemoveContext'
(AnnounceNewContext
.
,(lambda (engraver event)
(let ((context (ly:event-property event 'context)))
(if (eq? (ly:context-name context) 'Voice)
(set! voices (cons context voices)))
(write-me "voices " voices)
)))))))
\score {
\new Staff
<<
\new Voice = "1" { c''1 }
\new Voice = "2" { e'1 }
>>
\layout {
\context {
\Score
\consists #my-engraver
}
}
}
Promising. Thanks a lot!
Btw, AnnounceNewContext and RemoveContex are not listed in the IR, I
had to git grep them. Intended or over-sight?
Thanks,
Harm