Best strategy to handle incoming midi signal from MIDIReadProc in cocoa
Asked Answered
B

2

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.

Bray answered 17/10, 2012 at 8:22 Comment(0)
B
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).

Brinn answered 29/10, 2012 at 12:50 Comment(6)
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.Bray
@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.Brinn
Thank you, i will adopt your suggestions. I will tell you the results about.Bray
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:Bray
@tritono: I am not familiar with Objective-C, I am more a c++ guy. Maybe you should ask look at ObjC or Cocoa-dev mailing list.Brinn
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.Bray
B
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.

Bray answered 4/12, 2012 at 9:28 Comment(1)
get attention... at this link you can find a good document wich explain midi lag. linkBray

© 2022 - 2024 — McMap. All rights reserved.