Counterpoint assumes distinct voices that may not be present in the input material; for example the voices may be presented as simultaneous events in MIDI, and if the number of events vary vertically, into what voice do the various events belong, if any? Here one may guess based on the range of previously identified voices and give priority to the typically more important bass and soprano lines, but that still leaves problems. And now for a very contrived example.
C5 A4 G4 G4 F4 F4 E4 E4 D4 D4 C4
There are two to four voices here, and for the outer voices, assuming no voice crossing takes place, one might reasonably trace a "C5 rest A4 G4" descending line, and a "C4 D4 D4 E4" ascending line, but what middle voice drops out (or doubles?) to the F4, and then does the middle voice (or voices?) drop out or double on the final "E4 G4" pair? Assuming the work is following counterpoint (it may not be) one could reasonably exclude "C4 G4" moving to "D4 A4" as that's illegal parallel fifths, and less bad if it's "C4 C5" moving to "D4 A4" by contrary motion. Other motions may be less clear, especially if there's a voice crossing that causes those crossed notes to be assigned to the wrong voice where they then run afoul counterpoint rules, which is probably why the voices crossed one another in the first place, to avoid some persnickety rules violation.
An easier solution might be only to accept a simplified input format, and leave it up to the caller to massage (or mangle) their material into a suitable form: each voice must be in a distinct track with only one note event per dtime within the track. This may require simplification or quantization according to some opinion, which may corrupt or distort the input. Bach for example sometimes hides key harmonic tones in grace notes, so it may not be so simple a matter as to strip out the ornaments and pick what you assume to be the most notable events. Depending on the opinions of the manglers, you may get different analyses of the same work, and some composers are not above being deliberately vague. Maybe to wedge everything into a four-voice system could be an option?
Yet another solution would be to ignore the rules of counterpoint and perform some other analysis aimed at categorizing the voice leading, maybe the interval changes between all the notes involved between each vertical step, which one might then compare to proper counterpoint with properly separated voices is doing. So C4 gets a +2 and a +5, E4 gets a -2 and a +1, and so on for all the other notes involved, possibly complicated by also computing the intervals to non-adjacent yet still significant events such as the next strong beat, or the beginning of the next measure. What if you do not know what the rhythmic pulse is, or it changes all the time without being noted? Err, well, this sort of analysis can get into the weeds, fast, and may not actually help you compose anything.
P.S. "simultaneous events in MIDI" is a lie. The events arrive shortly after one another, but generally sound close enough to be lumped together as a chord by the listener. Or, how fast does the arpeggio have to be before it's heard as a vertical, or how slow can it be to still be considered a vertical for analysis?
text/gemini
This content has been proxied by September (ba2dc).