Voice retrigger allocation

pechnatunk's icon

I have a feeling this is quite simple but I'm struggling to implement it.
It sounds weird but I need to manage voices for a mono synth...
I'm "hacking" something to play melodies that is not designed to, it doesn't respond to note offs, but I would like it to behave like a monosynth - as long as a key is held a sound will play - at the moment if two or more notes are played others are released there is no sound even if one key remains pressed - so I need to detect when there is only one note remaining and retrigger it when the second last note's velocity is at zero.
I've had a look at poly, but still can't get to the bottom of it. - I tried using poly 1, + overflow outlet for new notes, but then voice outlet does not go above 1 for me to detect when there is only one voice remaining. Or if I use a higher voice number, I can detect when the voice gets back to 2 or 1, but then I'm struggling to have the notes saved somewhere so I know which one to retrigger.
I am most likely over-complicating this, and suspect there is quite a simple way to do this.

Source Audio's icon

mono synth = one voice.
only possible diference is to retrigger (adsr) or just change frequency
when keys overlap or multiple ones are held.
More keys held = last pressed one plays.
----------
borax will report number of held notes.
If You use == 1 at 3rd outlet to open gate to let note off through,
that could work

pechnatunk's icon

Ah, sorry I should have specified the thing I'm "hacking" is hardware and I have no control over the actual sound - that would make this easier.

I'm only managing the midi note on/offs and CC values to create the notes.
I'll look into Borax - it already seems more promising as there are more options to play with.

Ernest's icon

I had a lot or arguments at Reaktor about this issue, and I uphold you are right about this. Depending how you want it to work, a monophonic synth could still need a polyphonic allocator. For example, the following sequence:

C3 on
D3 on
D3 off

would cause the C3 note to play legato in many mono hardware synths. Typical monophonic allocators do not maintain a record of prior notes played and so don't have the data for C3 to start playing again when D3 is released, in this example.

pechnatunk's icon

Thanks - that’s exactly what I’m talking about - it’s different to stealing in a poly, where you typically want the oldest note to end. Here you want the last remaining one to retrigger.
However - I think I’ve just solved this in my head. I think instead of using poly/borax I can build a list of incoming notes and just use a zl object that searches for duplicates, (each duplicate should be the note off) and another zl that counts the length of the list - when the list length reaches 1 - that should be the note to retrigger... I don’t know if this is right, or efficient, but may work. I’ll try tomorrow.

Ernest's icon

There's two typical approaches.

When multiple notes are on and the playing note is released, pne is to trigger the lowest or highest note For that one keeps the state of all notes and search the list for the lowest or highest note number that is on. The other is to keep a record of the order of notes played, which is more complicated. Thats because a middle note can be released for example

C on
D on
E on
F on
D off
F off
E off

in this latter case,, of playing least recently used the next note would be C no t D/

pechnatunk's icon

God damn ddg!
Well thanks for nothin forum :)
Ive spent the best half of a week trying to sort this out with poly, zl, bag, etc.
Only to find out there’s a dedicated object in max for what I want:
ddg.mono
At least I’ve learnt a lot, mainly - that it’s sometimes better to search through other max patches than to continue struggling with a single concept :)

Michael Gary Dean's icon

Thanks PECHNATUNK for following up on this. That tip really helped me out!