Send to / read from Pisound MIDI Out / In directly with C code

Hello,

I’m trying to write C functions which talk directly to Pisound’s MIDI ports. I know that it’s possible to use the command line utility amidi to do this (e.g. amidi -p hw:1,0 -S 91 3c 7f to send a noteon message that plays middle C at max velocity on channel 2) but (correct me if I’m wrong) to do that in a function would need a system call (system(“amidi -p hw:1,0 -S 91 3c 7f”)), and it doesn’t seem to be possible to pass values as arguments this way. I’m very inexperienced writing C code, so apologies if this is a naive question. What I’m looking for is something along the lines of this, which achieves what I’m after but in Arduino:

void noteSend(byte cmd, byte data1, byte data2) {
cmd = cmd | midiChannel;
Serial.write(cmd);
Serial.write(data1);
Serial.write(data2);
}

Please can anyone advise how I would do this with Pisound?

Many thanks

Stat

You have to use ALSA Sequencer API, see our aseqsend utility for an example how it’s done:

In your application you would simply keep your g_seq and port handles open as long as you need them and send events using snd_seq_event_output.

See the ALSA Sequencer API documentation here: ALSA project - the C library reference: Sequencer interface

Thank you. Had a look at aseqsend.c and it made me realise that I’ve probably bitten off more than I can chew - a bit advanced for me so will come back to this once I’ve got some more coding experience under my belt. But thank you again.

Using ALSA sequencer API is the most direct way :slight_smile: You could look into using some C/C++ libraries such as PortMidi (couldn’t find a succinct example, but the API is mostly here) or rtmidi (example)

ALSA RAW MIDI might work as well, but it works in a sort of exclusive way, you could choose to use it only for MIDI output, ALSA Seq API is more preferred by Linux audio software, as it can be freely routed around between audio applications and hardware.