1

I am trying to use ALSA for MIDI purposes in C.

My problem is, snd_rawmidi_open() sort of "crashes" (waits forever like a while loop) when using valuable arguments :

#include <stdio.h>
#include <stdlib.h>
#include <alsa/asoundlib.h>

int main(int argc,char** argv)
{
    snd_rawmidi_t *handle_in = 0;
    int err;
    fprintf(stderr, "TEST 1\n");
    err = snd_rawmidi_open(&handle_in,NULL,"hw:1,0,0",0);
    fprintf(stderr,"TEST 2\n");
    if (err) {
        fprintf(stderr,"snd_rawmidi_open failed: %d\n",err);
    }
    fprintf(stderr, "TEST 3\n");
    exit(0);    
}

"hw:1,0,0" is a MIDI keyboard. When I use an invalid value like "foo", it gives an error. With a valid one, the program displays "TEST 1" and pauses.

Any idea?

Many thanks!

1

By default, snd_rawmidi_open waits until the requested port is available.

If you do not want this, add the SND_RAWMIDI_NONBLOCK flag (and reset it afterwards with snd_rawmidi_nonblock() if you want the read/write calls to be blocking).

1
  • You're right, in my case Jack was already using this port : one can check the input port using amidi -d -p{port} - this said me "hw:1,0,0 : device or resource busy".
    – theredled
    Sep 12 '14 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.