Best strategy to handle incoming midi signal from MIDIReadProc in cocoa

限于喜欢 提交于 2019-12-11 02:45:07

问题


I have to move some NSSlider by hardware midi controller, I have programmed a midi learn procedure to assign hardware cursor to NSSlider(sub class of), and up there it's all right. Inside MIDIReadProc, I handle moving NSSlider wich depends from incoming control and value, but now when I move hardware cursor, Sliders can be move one for time, it is like moving cursor stop the others.

My question is, what is best strategy to handle cursor moving concurrently ? 1 . Should I have to handle with a separated thread ? 2 . Should I have one FIFO data structure of MIDIPacket and processing that out of MIDIReadProc(with some concurrency separated process) ?

I'm sorry for my english. Thanks for attention.

a.


回答1:


You should not do any UI synchronisation inside MIDIReadProc callback.

This callback is called from a high priority realtime thread so you must avoid doing anything that could be "too long" in it.

As you said you can use a FIFO and treat that in another thread (for instance the main thread).




回答2:


I found a solution, to update 'NSSlider', moving sliders updating code in kvo path and using a background process separated thread to update a slider ui and value. After, I have separated ui control with assignment from that without and using a 'NSMutableDictionary' with key value equal at midi control to identify the 'NSSlider' faster in MIDIReadProc.

Thanks for the attention.



来源:https://stackoverflow.com/questions/12930024/best-strategy-to-handle-incoming-midi-signal-from-midireadproc-in-cocoa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!