Overlapping notes

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

Hi there,

a recent bug report on my pg8x lead me to a weird problem, which also other developers might face. So, I wonder what others are doing about it.

The problem is that I had "prematurely killed notes", which was not due to voice stealing. What happened is that these issues seem to arise if the plugin receives overlapping notes for the same key, i.e. two note On events for a given note followed by two note Off events for that note.

Obviously, such situation _should_ never happen, at least not when playing on a real keyboard. But there are situations where it does happen (e.g. playing over a recorded MIDI track), or some arpeggiators can do that (e.g. Kirnu Cream, when setting the gate time to more than 100%).

Of course, without further information (such as MIDI channel) there is no way to figure out which of the Note Off's correspond to a given Note On.

Imagine the sequence ( (1) On, (2) On, (3) Off, (4) Off) for a given note. Possibilities for the plugin to react to this sequence are:

In round robin assigner schemes:


A):
(1) trigger one voice
(2) trigger second voice
(3) release second voice
(4) release first voice

B):
(1) trigger first voice
(2) trigger second voice
(3) release first voice
(4) release second voice

and in retrigger schemes:

C):
(1) trigger voice
(2) ignore event
(3) release voice
(4) ignore event

D):
(1) trigger voice
(2) retrigger voice
(3) release voice
(4) ignore event


E):
(1) trigger voice
(2) retrigger voice
(3) ignore event
(4) release voice


Each of these behaviours will sound right for some scenarios and wrong for others.

For instance, to get Kirnu sounding right, one should use either (B) or (E), but they require some additional book keeping code.

Currently, pg8x implements (A) and (D).

I am just wondering how other plugins behave. What seems to be the most sensible solution?

Thanks,
Martin

Post

My voice-assignment logic only allows one instance of a particular note at a time to actually be "on". So if the note is triggered multiple times it will be shut off and either for "voice recycling" the same voice retriggered, or a new voice assigned.

MIDI isn't designed to allow more than one instance of a note. If you read up on MIDI from the official documents you'll find they explicitly state this. (There are 16 "channels" provided to allow 16 instances of the same note to exist keyed by channel index and key index.)

I'm not sure about interfaces as used in VST3 however, there it should be possible to distinguish between notes as they aren't referred to by pitch (?) but rather keyed uniquely, such as with a GUID or hash.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.

Post

aciddose wrote:My voice-assignment logic only allows one instance of a particular note at a time to actually be "on". So if the note is triggered multiple times it will be shut off and either for "voice recycling" the same voice retriggered, or a new voice assigned.

MIDI isn't designed to allow more than one instance of a note. If you read up on MIDI from the official documents you'll find they explicitly state this. (There are 16 "channels" provided to allow 16 instances of the same note to exist keyed by channel index and key index.)

I'm not sure about interfaces as used in VST3 however, there it should be possible to distinguish between notes as they aren't referred to by pitch (?) but rather keyed uniquely, such as with a GUID or hash.

Thanks. I am aware of the MIDI standard. That's why I so far did not really think about what to do with the situation that something in the MIDI chain before my plugin is doing something non-standard.

It seems, though, that these 'forbidden' MIDI streams exist (see Kirnu, it is also discussed in their forum). I am just wondering whether I should simply say "if you give me non standard input, I give you garbage output", or whether I should try to somehow do the best I can in to handle it.

I should mention, that my plugin is VST 2.4 only.

Post

I think I am using E (implemented using a reference counter) in Combo Model F. But because this is non-standard I now think that C or D would be better.

Note that overlapping notes can also easily occur if your plug-in supports input from any rather than one specific MIDI channel (which I guess is also non-standard), although then you could use the MIDI channel to pair Note On/Off messages.

Post

Are you counding the deltaFrames value in the note on and off events in the vstMidiEvent struct, Martin? It's possible you could be mixing up order, if not. (Though for the example that was provided, it sounded played by hand, so you wouldn't expect any events that close to each other in time.)

As for how I handle multiple of the same note, I do just like the JXes did. First note on is first note off (so scheme #B). I used to plug the MIDI OUT of my JX-3P into the MIDI IN to get a free doubled sound!

Post

There are two more variants for the round-robin case:

F
(1) Trigger voice 1
(2) Trigger voice 2
(3) Release both voices
(4) ignore

and

G
(1) Trigger voice 1
(2) Release voice 1, Trigger voice 2
(3) Release voice 2
(4) ignore

Personally I'd go with G, I think.

Post

aciddose wrote:My voice-assignment logic only allows one instance of a particular note at a time to actually be "on". So if the note is triggered multiple times it will be shut off and either for "voice recycling" the same voice retriggered, or a new voice assigned.

MIDI isn't designed to allow more than one instance of a note. If you read up on MIDI from the official documents you'll find they explicitly state this. (There are 16 "channels" provided to allow 16 instances of the same note to exist keyed by channel index and key index.)
Unfortunately this is not true.

This is specified in the MIDI specification.

The MIDI spec is allows more than one note simultaneously playing on the same pitch. A single note on event must turn off only a single note on. If two note on events are sent, then two note offs must be sent. This is standard MIDI protocol. If a synthesizer turns off both notes when it receives just one note off event, that is a bug.

The MIDI spec does not comment on *which* note on should be turned off by a note off event of the same pitch, but common practice has been to turn off the oldest note.

This is discussed in the Appendix, section A-4 "Assignment of Note On/Off commands."

You can easily do this in DP by cutting one long note and create two new ones. It is used to simulate legato AFAIK

MIDI spec is not freely available unfortunately.

If you google "Assignment of Note On/Off commands", you find results though

HTH
Olivier Tristan
Developer - UVI Team
http://www.uvi.net

Post

otristan wrote:
aciddose wrote:My voice-assignment logic only allows one instance of a particular note at a time to actually be "on". So if the note is triggered multiple times it will be shut off and either for "voice recycling" the same voice retriggered, or a new voice assigned.

MIDI isn't designed to allow more than one instance of a note. If you read up on MIDI from the official documents you'll find they explicitly state this. (There are 16 "channels" provided to allow 16 instances of the same note to exist keyed by channel index and key index.)
Unfortunately this is not true.

This is specified in the MIDI specification.

The MIDI spec is allows more than one note simultaneously playing on the same pitch. A single note on event must turn off only a single note on. If two note on events are sent, then two note offs must be sent. This is standard MIDI protocol. If a synthesizer turns off both notes when it receives just one note off event, that is a bug.

The MIDI spec does not comment on *which* note on should be turned off by a note off event of the same pitch, but common practice has been to turn off the oldest note.

This is discussed in the Appendix, section A-4 "Assignment of Note On/Off commands."

You can easily do this in DP by cutting one long note and create two new ones. It is used to simulate legato AFAIK

MIDI spec is not freely available unfortunately.

If you google "Assignment of Note On/Off commands", you find results though

HTH
Agreed. I was going to ask for a quote of where in the MIDI spec exactly it makes that claim, but I didn't want to start yet another fight with aciddose. I've never heard of it, and know of MANY classic synths that certainly DID let you activate more than one voice on the same channel playing the same note, the original MIDI synth, the JX-3P being a (literally) prime example.

Post

What do you mean?
MIDI isn't designed to allow more than one instance of a note. If you read up on MIDI from the official documents you'll find they explicitly state this. (There are 16 "channels" provided to allow 16 instances of the same note to exist keyed by channel index and key index.)
All I've said here is MIDI isn't designed to allow more than one instance of a note. What I meant was there is no way provided to distinguish between which note is associated with a particular on/off message.

Sure, you can allow it and yes as otristan mentioned the devices that do usually turn off the oldest note first.

I don't believe this is a particularly useful feature, some devices do it, some don't.

My suggestion is to do as I do, replace any existing note with the same note.

Where I might be wrong is if you mean to say the MIDI spec requires that multiple note-on messages produce multiple sustained notes and require multiple note-off messages to deactivate. That is something I'd be unaware of and vehemently disagree with, I'd never willingly implement such a thing.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.

Post

And THAT'S why you're wrong.

Who's got a copy of the actual MIDI spec we can quote from so we can settle this?

Post

What's why I'm wrong?
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.

Post

Given an instrument like a pipe organ for example, there will only be one pipe, reed, string or so on available per note. Even if two note-on messages were received it would be impossible to produce two of the same sustained note.

My understanding of the MIDI spec is that if multiple note-on messages are received it is not a requirement to create two distinct sustained notes but acceptable to simply re-trigger or ignore the additional note-on messages.

This may not be the case of course, although the language in the spec itself states something like "a note-off message must not deactivate more than a single sustained note". This should leave room for having ignored the second note-on message and only turned off a single sustained note when receiving the first note-on message.

Alternatively, it may be possible to maintain a counter and only deactivate a sustained note once the counter reaches zero, although I'm not aware of this being described in the spec.

In any case if the spec were to require multiple instances of the same sustained note, it would make it impossible to create a fully polyphonic MIDI piano or MIDI organ to-spec without having an infinite number of redundant voices available for every note.

Not exactly sounding very practical in my opinion.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.

Post

To disagree with anything other than one MIDI note-off event ALWAYS means ONE voice off. (Of course a voice playing that note number has to already be on.)

Don't talk to me about pipe organs. And your understanding of the MIDI spec is WRONG. So suck it up, and STFU, for once. Advising everyone else in the world to do the wrong thing is just going to get me and a bunch of others in here tearing your head off.

Post

AdmiralQuality wrote:And THAT'S why you're wrong.

Who's got a copy of the actual MIDI spec we can quote from so we can settle this?
Aciddose is not wrong. This isn't required per se. Although this what we do in the UVI engine FWIW.
MIDI specifications wrote:Assignment of Note On/Off Commands
If an instrument receives two or more Note On messages with the same key number and MIDI channel, it must make a determination of how to handle the additional Note Ons. It is up to the receiver as to whether the same voice or another voice will be sounded, or if the messages will be ignored. The transmitter, however, must send a corresponding Note Off message for every Note On sent. If the transmitter were to send only one Note Off message, and if the receiver in fact assigned the two Note On messages to different voices, then one note would linger. Since there is no harm or negative side effect in sending redundant Note Off messages this is the recommended practice.
Last edited by otristan on Fri Feb 06, 2015 3:11 pm, edited 2 times in total.
Olivier Tristan
Developer - UVI Team
http://www.uvi.net

Post

AdmiralQuality wrote:... is just going to get me and a bunch of others in here tearing your head off.
AQ, there are situations in which the logic should immediately lead you to understand, intuitively (at least for me) that given such a specification, creating an instrument to-spec would be impossible.

Such an impossible specification would be useless, therefore it is extremely unlikely MIDI would require such a thing.
Free plug-ins for Windows, MacOS and Linux. Xhip Synthesizer v8.0 and Xhip Effects Bundle v6.7.
The coder's credo: We believe our work is neither clever nor difficult; it is done because we thought it would be easy.
Work less; get more done.

Post Reply

Return to “DSP and Plugin Development”