VstMidiEvent noteLength ignored and play endless

Topics: Host Processing, Midi, Newbie, VST.NET Framework
Dec 12, 2014 at 9:11 PM

I have downloaded VST.NET and trying to build a small vst host application with a simple sequence with midi data I want to play. And I am playing with a VST plugin.

And I have done something like this:
public override void ProcessEvents(ref MidiMessage data)
            VstEvent[] vstevents = new VstEvent[1];

            byte[] midiData = new byte[4];
            midiData[0] = data.MidiData.Status;  // ignoring channel
            midiData[1] = data.MidiData.Parameter1;     // Midi note
            midiData[2] = data.MidiData.Parameter2;     // Note strike velocity
            midiData[3] = 0;                            // Reserved, unused
            int deltaFrame = (int)data.DeltaTime;
            int noteLength = (int)data.LengthTime;
            int noteOffset = 0;
            short detune = data.Detune;
            byte noteOffVelocity = 8;

            vstevents[0] = new VstMidiEvent(deltaFrame, noteLength, noteOffset, midiData, detune, noteOffVelocity, false);

I have input a note with a specific note key, note delta and note length. But the problems is that the note length doesnt work. When I play a note in the VST plugin it will play endless.

Am I doing something wrong?

Dec 12, 2014 at 9:31 PM
Edited Dec 12, 2014 at 9:36 PM
Nothing really wrong but the way VST plugins are made doesn't follow strict standards. VST development is a hodge-podge of overlapping features in MIDI spec and VST spec. Plugin developpers tend to implement only the most convenient and better documented one. If you want to send a CC (Control Change) to a plugin, you need to send it through Vst Parameter instead of a midi CC message. If you want to control the note length you need to send a midi note off message instead of a note length vst property. You'd be hard pressed to find a plugin which actually do something with noteLength, note strike velocity and noteOffVelocity.
Dec 12, 2014 at 10:22 PM
Aaah okey I see! Thansk for that! So I can just skip noteLength, noteOffset and noteOfVelocity forever?

So if I send a note off, how to handle if for example 3 notes on the same key hold on at the same time? If I then release a note, how do the VST synth know which note key was released.
  1. =========================
  2. ==============
  3. ==============================
You see here, 3 notes at the same time and same key. How do VST plugin know which notes will be released?
Dec 12, 2014 at 10:59 PM
Edited Dec 12, 2014 at 11:03 PM
Yeah my advice is to skip those properties altogether unless you work only with a specific synth that handles these since they are virtually not used in practice.

As for your second question this is usually a fixed or configurable parameter of the synthesizer. The plugin doesn't know which note is released and doesn't care because note off message are dispatched according to the plugin internal note-priority algorithm.
Dec 13, 2014 at 7:33 AM
Some hosts use the noteLength etc. fields for midi events that are played back from a recorded track. Then it is relatively easy to calculate them. As for live midi events, these fields are usually empty.

One other thing: the midi deltaTime is NOT the same as the deltaFrames!
The amount of time deltaTime represents is based on the pulses-per-quarter-note (ppqn: how may ticks per second) and the amount of time one deltaFrame represents is based on the sample-rate (how many samples per second).

Dec 13, 2014 at 6:02 PM
That's interesting, my understanding was that generally only midi synthesizer (hardware and software) tend to make use of note length. I may be wrong on this as my host is live oriented and haven't played a lot with this property. Would you also send a note off so that vst plugins actually do stop playing the note?

From previous threads I thought that a standard midi loop for recorded playback would go like this:
Send midi note on with adjusted delta frame if the note is to be started during the current buffer and do the same with note off.
Dec 13, 2014 at 6:15 PM
The note on and note off messages would still be sent by the host to the midi plugin. Just for the note-on message the host can in advance know how long it is going to be. The NoteLength property is not MIDI it is part of VST so no MIDI hardware will ever make use of that...

Dec 13, 2014 at 8:47 PM
Thank you all for Everything. Now it seems to work now after some changes :)