On Wed, 31 May 2023, Gilles Thibault wrote: > Not hardly tested but this should work :
Thanks for looking at it further. I hate to impose on you because I've already decided to solve this problem in external postprocessing of the MIDI files, so I hope you won't put a lot of effort into trying to satisfy my use case with modifications to your script. I don't think doing it in Lilypond is really the right solution for me because to really solve it I need to automatically handle *all* cases of simultaneous notes. I need, at each point in time, to have at most one note per track, exactly one track per note, and silence in any leftover tracks, regardless of the voice/chord structure of the music. The code you provide works for the specific example I gave, where the desired silence comes from a note written as a single note instead of a chord, but there are many other cases (illustrating the problem with minimal examples). In particular: * change b2 to <b>2 and the b2 comes out in two tracks. Maybe it would never occur to me to write a one-note chord, but a similar issue can happen between two- and three-note chords, or anywhere the number of notes per chord in a voice is not always the same. * a one-voice passage added outside the << >> construct comes out in two tracks * if each of two voices sometimes contains two simultaneous notes, but only at most three notes are simultaneous overall, then I need to either use four output tracks, or carefully split and then merge to bring it down to three, and handling this kind of thing becomes steadily more complicated as the number of voices and simultaneous notes grows. Resolving these points and any other similar ones that may come up, seems like a lot of work. If an in-Lilypond solution means I need to do things like maintain the same number of Voice contexts throughout the entire piece of music, or think hard about which note/voice index needs to merge with which other one to minimize the overall number of tracks without ever having more than one note simultaneous in a track, then we quickly approach a point where it would be less work for me to just write out the intended output by hand and not have Lilypond calculate it at all. In external MIDI processing it's relatively easy: at every "Note on" message in chronological order, I can route the note to an unused track or else know unambiguously that I need more tracks. At every "Note off," the track in question becomes available again. The external code basically does the same thing that a polyphonic synthesizer would do, just with output to new MIDI tracks instead of directly to hardware voices. No need for separate handling of Lilypond's "single note," "chord," and "voice" concepts. -- Matthew Skala msk...@ansuz.sooke.bc.ca People before tribes. https://ansuz.sooke.bc.ca/