Handling frequency, attack/release and octave shift for several instances of a synth
I'm relatively new to Max, and while working on a project I stumbled with a problem I cannot sort out. I'll try to be as simple as I can as uploading the patch with its subpatches would be unpractical, while giving the most precision I can.
In my patch I have 12 instances of a synthesizer (which is 2 voices [poly~] for reasons I'll explain in a moment) and to all of them I send the same adsr values through [send], using [line~] as method to process the attacks and releases. From a root frequency I generate, with several [expr], one pitch for each of these instances, which is at a specific interval in just intonation from the fundamental (instance 1 has the fundamental pitch, instance 2 has its 5th, instance 3 its 3rd, etc). With a toggle I send the attack and release of each instance. All fine until here, but the issues come when I modify the pitch on the fly.
I have two ways of doing this. One is by affecting the octave of the pitch of each instance with [incdec] and an [expr]. The other one is by modifying the fundamental pitch through transposition by an specific interval, which provoques changing all pitches. Therefore I'm sending three messages to each instance: frequency [float], octave shift [int] and attack/release (1/0). I'm using a 2 voices [poly~] as I try to achieve a crossfade when an active instance receives a new pitch. That's when I have troubles, so here's what I want to achieve:
- When the instance receives an attack (1), it triggers the frequency and then sends the attack to the first voice of [poly~].
- If the frequency changes while one voice is sounding (i.e. while the instance is active), it turns out that voice, triggers the new frequency and then sends an attack to the new voice. This repeats alternating between both voices as long as the instance is active and the frequency changes.
- When the instance receives a release (0), it sends an off message to the active voice.
- If a frequency changes while the instance is inactive, it doesn't trigger any attacks.
- The 2 voices of each instance exist only to achieve crossfade between different pitches, they are never on sustain at the same time.
Hope this is somewhat clear. I've tried several options getting more or less success, but at some point something fails (triggering a release for an inactive voice, or not matching the voice with the correct frequency after transposing back and forth), and I think mostly my problem has to do with the order in which data flows. Hope somebody can help me with this!
Thanks,
Tomás.