2

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.

tritono
  • 21
  • 3

2 Answers2

2

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).

Kevin MOLCARD
  • 2,168
  • 3
  • 22
  • 35
  • I'm realy happy for your answer, for now I call one method inside 'MIDIReadProc' callback, and inside the method wich has the packetlist reference, I create a new thread wich dispatch the packetlist to UI based on cc assigned, but I have always the same problem, it's better than previous code but it isn't what I want. Using a FIFO is a good choose but where can I dispacth the FIFO? In another thread in background wich continually escapes the FIFO? Thanks for attention. – tritono Oct 29 '12 at 13:49
  • @tritono: Creating a thread inside the callback is typically what I call "anything that could be "too long"". Having a background is a good idea indeed. – Kevin MOLCARD Oct 29 '12 at 14:08
  • Thank you, i will adopt your suggestions. I will tell you the results about. – tritono Oct 29 '12 at 14:17
  • At this moment in `MIDIReadProc` insert `MIDIPacket` inside a FIFO crates with `NSMutableArray`. When I initialize the class wich handle midi, I create a new thread(init it) and set his priority and start it. I need a NSRunLoop which dispatch a FIFO while `[FIFO count]>0`. But something is wrong because I don't know how to set-up and handle the RunLoop. I need a good guide to work with `NSRunLoop`. Here pseudo-code: – tritono Nov 06 '12 at 14:51
  • @tritono: I am not familiar with Objective-C, I am more a c++ guy. Maybe you should ask look at [ObjC](https://lists.apple.com/mailman/listinfo/objc-language) or [Cocoa-dev](https://lists.apple.com/mailman/listinfo/cocoa-dev) mailing list. – Kevin MOLCARD Nov 07 '12 at 07:50
  • thanks, yesterday I have tryed a solution for a thread with timer which executes a procedure to dispatch `FIFO` every x ms. It seems work now I need to test performance. I hope to answer my question as soon as. – tritono Nov 07 '12 at 09:00
0

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.

tritono
  • 21
  • 3
  • get attention... at this link you can find a good document wich explain midi lag. [link](https://www.haiku-os.org/documents/dev/introduction_to_midi_part_2) – tritono Jan 17 '13 at 12:05