Jack MIDI client seems to send MIDI messages repeatedly

时光怂恿深爱的人放手 提交于 2020-06-28 08:07:57

问题


my problem is:

I am implementing a jack MID proxy client - I want to control yoshimi's mute function with my MIDI keyboard.

So: MIDI controller is "connected" to my proxy, and proxy is "connected" to yoshimi's MIDI input.

Code works allright; mute button message is intercepted, data channel changed and yoshimi is accepting command being muted... However I have discovered, that even when controller's (note) button press/release event is received (and forwarded) just once per event, it looks it's being repeated. For example: if I press a note key on controller, yoshimi sounds like key is being pressed (and released?) like 10 times per second... But when controller is connected to yoshimi directly, all sounds as it should.

MIDI messages are being processed in process_callback function. I tried with processing within main loop, but result is the same.

What is wrong here?

This is processing function:

int res = 0;
int i,j;

//get events
void* in_port_buf = jack_port_get_buffer(input_port, nframes);

jack_nframes_t n = jack_midi_get_event_count(in_port_buf);

if(n==0)
    return 0;

jack_midi_event_t jev;

printf("%i: Data arrived!\n", cnt);
for(i = 0;i<n;i++){

    res = jack_midi_event_get(&jev,in_port_buf,i);
    if(res == 0){
        printf("Got event, %i bytes!\n",jev.size);
        for(j=0;j<jev.size;j++)
            printf("%i: %i\n",j,jev.buffer[j]);

    } else{
        printf("ERROR getting event!\n");
        return 0;
    }

    //first button: mute yoshimi volume, port 120, all sound off
    if(jev.buffer[0]==176 && jev.buffer[1] == 97){
        jev.buffer[1] = 120;
    }

    //transmit data
    cnt++;


    void* port_buf = jack_port_get_buffer(output_port, nframes);


    jack_midi_clear_buffer(port_buf);

    res = jack_midi_event_write(port_buf, jev.time, jev.buffer, jev.size);

    if(res == 0)
        printf("Data sent!\n");
    else
        printf("Error: %i\n",res);
}

return 0;

回答1:


Got it!

After studying jack examples I've discovered, that I had to move output port's clear and assignment rutines out of the loop.

Also, midi_event_write is not neccessary.

Works as it should now.



来源:https://stackoverflow.com/questions/28122968/jack-midi-client-seems-to-send-midi-messages-repeatedly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!