[LAD] sequencer and sysex again

rdxesy at yahoo.de rdxesy at yahoo.de
Fri Jun 6 18:47:27 UTC 2008


On Fri, Jun 06, 2008 at 20:22:44 +0200
Fons Adriaensen <fons at kokkinizita.net> wrote:
> On Fri, Jun 06, 2008 at 07:30:49PM +0200, rdxesy at yahoo.de wrote:
> 
> > now there are two things i dont understand:
> > first: why is the midi_callback() thread being called once 
> > ...
> > 1. call the midi_callback() thread more often
> > ...
> 
> I try to understand what's happening, but your terminology
> is somewhat confusing...
> 
> Threads are run, or can be running or waiting, but they
> are never 'called'. Functions are called. 
> 
> So what is this 'midi callback' thing exactly ?
> 
> Is it a thread doing a blocking read() on a midi port,
> and waking up when there is data for it ? If so what
> does this trhead do with the data it receives ?
> Or is it a function you call periodically ?
> Or something else ?
> 
> Ciao,
> 

Ciao,

sorry for being unprecise.
let me show you :)

...
pthread_create (&midi_listener, NULL, midi_listen, NULL);
...


static void
*midi_listen(void *ptr)
{
    int seq_nfds, i;
    struct pollfd *pfds;

    seq_nfds = snd_seq_poll_descriptors_count(seq, POLLIN);
    pfds = (struct pollfd *)alloca(sizeof(struct pollfd) * (seq_nfds));
    snd_seq_poll_descriptors(seq, pfds, seq_nfds, POLLIN);

    while (1)
    {
        if (poll (pfds, seq_nfds, 1000) > 0)
        {
            pmesg(100, "poll\n");
            for (i = 0; i < seq_nfds; i++)
                if (pfds[i].revents > 0)
                    midi_callback ();
        }
    }

}

static void
midi_callback(void)
{
    pmesg(100, "midi midi_callback() ENTERING\n");

    snd_seq_event_t *ev;
    unsigned char *data = NULL;
    int param, value, err;

    do
    {
        err = snd_seq_event_input(seq, &ev);
        if (err < 0)
            return;

        if (ev->type == SND_SEQ_EVENT_SYSEX)
        {
            data = ev->data.ext.ptr;

            ... set sliders and stuff eg:

            if (param == VOLUME || param == PAN)
            {
                gdk_threads_enter ();
                set_slider(param, value);
                gdk_threads_leave ();
            }
            ...

    }
    while (snd_seq_event_input_pending(seq, 0) > 0);
}


I guess this makes things clearer :)

While this thread is running i am requesting the parameters 
as shown earlier.

Cheers,
Jan



More information about the Linux-audio-dev mailing list