tebjan/Sanford.Multimedia.Midi

Big delay

Closed this issue · 4 comments

I am experiencing a big delay when changing values from my midicontroller traktor kontrol f1 (mostly with faders and potentiometers). Is this normal or should the changes be instantly?

Do I need to handle my code in another thread? Or is the callback already in another thread? Maybe I am doing to much work in the callback? What do you think may cause this issue?

hello, this sounds like the midi values firing faster than you process them. the midi input has a synchronization context on which the events are fired. but for simplicity i would just us a simple value field to store the latest values that you receive and read the values on your UI thread.

so in the midi event handler only do:
myValueField = midiValue;

and when you do your program logic:
DoSomethingWithTheLatestValue(myValueField);

that is a simple way to not block the event handler and it works because single values are thread safe...

And
DoSomethingWithTheLatestValue(myValueField);
Need to be called from a new thread or do I need to make a new thread in that method? Or is there something I'm still missing?

Because the UI needs to be updated immediately when the sliders and potentiometers are changed. I still need to do this in the callback?

myValueField = midiValue;
DoSomethingWithTheLatestValue(myValueField);

Or is the DoSomethingWithTheLatestValue(myValueField);
Called at a later time?

DoSomethingWithTheLatestValue(myValueField);

In a new thread did the trick :) thank you, stupid mistake