Re: QSlider Update Problem
Quote:
Originally Posted by December
even though the MIDI messages are not coming in at any crazy rate
Are you sure? What is the maximum number of messages per second?
How does that data-collecting thread works? Maybe it starves the GUI thread?
Re: QSlider Update Problem
Well, even if I push the fader up real slow.. say 6 seconds from bottom to top, the same problem occurs.
That would mean around 16 messages per second.The code in the MIDI thread is actually still a bit of a mystery to me.. as its taken from some other o/s projects
Code:
void midiThread::run()
{
snd_seq_t *seq_handle;
int npfd;
struct pollfd *pfd;
seq_handle = open_seq();
npfd = snd_seq_poll_descriptors_count(seq_handle, POLLIN);
pfd = (struct pollfd *)alloca(npfd * sizeof(struct pollfd));
snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN);
while (1) {
if (poll(pfd, npfd, 100000) > 0) {
midi_action(seq_handle);
}
}
}
This is the run part of the QThread. The other relevant bit is:
Code:
void midiThread::midi_action(snd_seq_t *seq_handle) {
snd_seq_event_t *ev;
MyDataEvent dataEvent(0,0);
do {
snd_seq_event_input(seq_handle, &ev);
switch (ev->type) {
case SND_SEQ_EVENT_CONTROLLER:
dataEvent.setParam(ev->data.control.param);
dataEvent.setValue(ev->data.control.value);
break;
}
snd_seq_free_event(ev);
} while (snd_seq_event_input_pending(seq_handle, 0) > 0);
}
If this is a horrible way to do things.. I would much appreciate any ideas on how to handle MIDI better.
On windows I used Borland C++ Builder.. and found a great component that pretty much did it all for me, passing the messages to my callback function. I guess I have to learn more C++ to program on Linux ;-)
Re: QSlider Update Problem
Quote:
Originally Posted by December
That would mean around 16 messages per second.
Then it shouldn't be a problem, unless you do a busy-wait somewhere. You check with top if your program doesn't eat whole CPU power.
poll() is a good way to go, but in midi_action() you have a problem --- you use sendEvent(), but only postEvent() is thread-safe.
Try:
Code:
void midiThread::midi_action(snd_seq_t *seq_handle) {
...
do {
snd_seq_event_input(seq_handle, &ev);
switch (ev->type) {
case SND_SEQ_EVENT_CONTROLLER:
MyDataEvent *dataEvent = new MyDataEvent(0,0);
dataEvent.setParam(ev->data.control.param);
dataEvent.setValue(ev->data.control.value);
QApplication::postEvent( parent, dataEvent
);
// QApplication takes ownership of the event break;
}
...
Re: QSlider Update Problem
Wow, that was the problem.
Changing from using sendEvent to postEvent solved it. I feel stupid now, I even remember reading that sendEvent is not thread safe a while back :o
Thanks for the help.. I think QT is going to be a lot of fun with such knowledgeable people around :)