[Gambas-user] Gambas & API of ALSA

Doriano Blengino doriano.blengino at ...1909...
Tue May 25 09:36:46 CEST 2010


Ru Vuott ha scritto:
> Thank you very much.
>
> Now the problem is how I can use those information with Gambas !!! :-(
>   
I would interested too in writing a midi librarian for my keyboard, but 
leaved this idea behind because I am too busy these days. I wrote a 
working one under windows, but now I would need a linux version. So, if 
you succeed in doing something, let me know.

If I well understand, you want to send data to a midi device. It seems 
that you can do it in two ways - using the filesystem, or using the alsa 
library.

In the documentation from:

>> I guess you can find some answers here, thanks google!
>>
>> https://ccrma.stanford.edu/~craig/articles/linuxmidi/
>>     
there are several C sources, which can be translated more or less to 
gambas. The simplest of them is:

    int main(void) {
       char* device =  "/dev/midi" ;
       unsigned char data[3] = {0x90, 60, 127};

       // step 1: open the OSS device for writing
       int fd = open(device, O_WRONLY, 0);
       if (fd < 0) {
          printf("Error: cannot open %s\n", device);
          exit(1);
       }

       // step 2: write the MIDI information to the OSS device
       write(fd, data, sizeof(data));

       // step 3: (optional) close the OSS device
       close(fd);

       return 0;
    }

This code (output/method1.c) does something very simple - it write three 
bytes to the file /dev/midi. You can try from console using something like:
    cat myfile >/dev/midi
where "myfile" has a suitable content, like 0x90, 60, 127, which in 
gambas translate to &h90, 60, 127.

If you only want to send out some midi data, this approach seems to be 
effective and easy: just open a file for output, and write some bytes to 
it (you must know what to write - this is a different problem). If you 
want to make your device play, you will have to output several "0x90 
0xXX 0xXX" (note on event) followed by "0x80 0xXX 0xXX"; accurate timing 
will be an issue.

The device /dev/sequencer does similar things, but is more intelligent 
and can do good timing.

Alternatively, you can use a library like alsa. You must use "External 
function declaration" in gambas, and you will have access to the power 
of alsa. This is not easy, but possible; in this case, you must know a 
little the C language.

To summarize, think at what you want to do and choose one of the three 
methods: /dev/midi is poor and simple; /dev/sequencer is more 
complicated but still easy in gambas; using alsa (OSS is older) is the 
way to go if you want to do a complicated but powerful program.

Let me know if you have more doubts. I have no time to write a program 
myself, but I can find some time to give you some hint. Please specify 
more precisely what you want to do.

Regards,
Doriano




More information about the User mailing list