okay thanks a lot, this 4-terminal method really helped!
so in the 4 terminal check everything works perfectly.
amidi -p -S messages only go out when the midi device is opened (whatever that means) so either when the program is running or when amidi -d -p is active in a terminal.
After digging deeper i found that the device is never opened. the function readFrom in Midi.cpp has the following code. I hope this is the right backup - i overwrote the original and on github there seems to be a different version of Midi.cpp. could it be that the bela gem shipped with different version of Midi.cpp than what is on github/was it maybe shipped with an old version? I copied the github version of Midi.cpp to bela but it is not compatible due to xenomai_wrapper.
int Midi::readFrom(const char* port){
if(port == NULL){
port = defaultPort;
}
inPort = port;
if(!exists(inPort)
return 1;
i changed the return value to -1 and then i get an error, so the inPort is not in ListAllPorts() and therefore alsaIn was null and this is why no messages were received.
anyway Midi::listAllPorts() was buggy and after fixing that everything worked.
The old version was:
std::vector<Midi::Port> Midi::listAllPorts(){
std::vector<Port> ports;
int card = -1;
int status;
while((status = snd_card_next(&card)) == 0){
if(card < 0){
break;
}
snd_ctl_t *ctl;
char name[32];
int device = -1;
int status;
sprintf(name, "hw:%d", card);
if ((status = snd_ctl_open(&ctl, name, 0)) < 0) {
error("cannot open control for card %d: %s\n", card, snd_strerror(status));
return ports;
}
do {
status = snd_ctl_rawmidi_next_device(ctl, &device);
if (status < 0) {
error("cannot determine device number: %s", snd_strerror(status));
break;
}
if (device >= 0) {
snd_rawmidi_info_t *info;
snd_rawmidi_info_alloca(&info);
snd_rawmidi_info_set_device(info, device);
// count subdevices:
snd_rawmidi_info_set_stream(info, SND_RAWMIDI_STREAM_INPUT);
snd_ctl_rawmidi_info(ctl, info);
unsigned int subs_in = snd_rawmidi_info_get_subdevices_count(info);
snd_rawmidi_info_set_stream(info, SND_RAWMIDI_STREAM_OUTPUT);
snd_ctl_rawmidi_info(ctl, info);
unsigned int subs_out = snd_rawmidi_info_get_subdevices_count(info);
//number of subdevices is max (inputs, outputs);
unsigned int subs = subs_in > subs_out ? subs_in : subs_out;
for(unsigned int sub = 0; sub < subs; ++sub){
bool in = false;
bool out = false;
if ((status = is_output(ctl, card, device, sub)) < 0) {
error("cannot get rawmidi information %d:%d: %s",
card, device, snd_strerror(status));
return ports;
} else if (status){
out = true;
// writeTo
}
if (status == 0) {
if ((status = is_input(ctl, card, device, sub)) < 0) {
error("cannot get rawmidi information %d:%d: %s",
card, device, snd_strerror(status));
return ports;
}
} else if (status) {
in = true;
// readfrom
}
if(in || out){
Port port = getPort(info);
port.hasInput = in;
port.hasOutput = out;
ports.push_back(port);
}
}
}
} while (device >= 0);
snd_ctl_close(ctl);
}
return ports;
}
and the new version is
std::vector<Midi::Port> Midi::listAllPorts(){
std::vector<Port> ports;
int card = -1;
int status;
while((status = snd_card_next(&card)) == 0){
if(card < 0){
break;
}
snd_ctl_t *ctl;
char name[32];
int device = -1;
int status;
sprintf(name, "hw:%d", card);
if ((status = snd_ctl_open(&ctl, name, 0)) < 0) {
error("cannot open control for card %d: %s\n", card, snd_strerror(status));
return ports;
}
do {
status = snd_ctl_rawmidi_next_device(ctl, &device);
if (status < 0) {
error("cannot determine device number: %s", snd_strerror(status));
break;
}
if (device >= 0) {
snd_rawmidi_info_t *info;
snd_rawmidi_info_alloca(&info);
snd_rawmidi_info_set_device(info, device);
// count subdevices:
snd_rawmidi_info_set_stream(info, SND_RAWMIDI_STREAM_INPUT);
snd_ctl_rawmidi_info(ctl, info);
unsigned int subs_in = snd_rawmidi_info_get_subdevices_count(info);
snd_rawmidi_info_set_stream(info, SND_RAWMIDI_STREAM_OUTPUT);
snd_ctl_rawmidi_info(ctl, info);
unsigned int subs_out = snd_rawmidi_info_get_subdevices_count(info);
//number of subdevices is max (inputs, outputs);
unsigned int subs = subs_in > subs_out ? subs_in : subs_out;
for(unsigned int sub = 0; sub < subs; ++sub){
bool in = false;
bool out = false;
int statusOut = is_output(ctl, card, device, sub);
if (statusOut < 0) {
error("cannot get rawmidi output information %d:%d:%d: %s",
card, device, sub, snd_strerror(statusOut));
return ports;
}
else if (statusOut){
out = true;
// writeTo
}
int statusIn = is_input(ctl, card, device, sub);
if (statusIn < 0) {
error("cannot get rawmidi input information %d:%d:%d: %s",
card, device, sub, snd_strerror(statusIn));
return ports;
}
else if (statusIn) {
in = true;
// readfrom
}
if(in || out){
// Refresh ALSA info for this exact subdevice before creating the name.
snd_rawmidi_info_set_device(info, device);
snd_rawmidi_info_set_subdevice(info, sub);
snd_rawmidi_info_set_stream(info, in ? SND_RAWMIDI_STREAM_INPUT : SND_RAWMIDI_STREAM_OUTPUT);
if ((status = snd_ctl_rawmidi_info(ctl, info)) < 0) {
error("cannot get rawmidi information %d:%d:%d: %s",
card, device, sub, snd_strerror(status));
return ports;
}
Port port = getPort(info);
port.hasInput = in;
port.hasOutput = out;
ports.push_back(port);
}
}
}
} while (device >= 0);
snd_ctl_close(ctl);
}
return ports;
}
So the problem was that in setting the ports for the subdevices, the info was not updated.
thanks a lot for the help in looking for the problem!! and maybe this can be included in the next update!