darktable icon indicating copy to clipboard operation
darktable copied to clipboard

Reduce MIDI latency (over BLE)

Open dterrahe opened this issue 3 weeks ago • 0 comments

When connecting a midi device over bluetooth BLE (like https://discuss.pixls.us/t/using-a-midi-device-with-darktable/54391/1) latency is much higher than when using USB. This manifests itself with button lights updating only 10secs after the onscreen button it is linked to is toggled and rotors in absolute mode getting jumpy when using shift to take large steps.

Possible solutions to investigate:

  1. monitor the queue in portmidi if possible. The polling updates for rotors and buttons should be postponed when the queue is still processing the last update. It may be that the actual size of congestion is hidden in a driver level, in which case hopefully we can still monitor throughput and then scale back the volume of updates so that it should be low enough for the driver to catch up.
  2. When sending updates remember the previous confirmed level (i.e. received from the device) and then when receiving new data from the device, if it is in between both values, make a best guess whether it was based off the previous or "latest" level. Don't do this when outside of the range of the two values, because physical sliders (that ignore the updated value) actually work better if we believe that they made a large move from the corrected value we sent them, rather than a small change from the previous value it was really at. This allows it to catch up and reach the end of the on-screen slider range by the time the physical slider reaches its limit. Taking this one step further we could look in the receive queue before sending an update and correct any values that were already in there before the update was even sent and therefore clearly were based off the previous (or even older) value.

dterrahe avatar Dec 13 '25 14:12 dterrahe