src/XJack.cpp
// jack process callback for the midi input
jack process callback for the midi input
jack process callback for the midi input
inline void XJack::process_midi_in(void* buf, void* out_buf) {
    if (record && fresh_take) {
        start = jack_last_frame_time(client);
        absoluteStart = jack_last_frame_time(client);
        absoluteRecordStart = jack_last_frame_time(client);
        rcStart = jack_last_frame_time(client);
        fresh_take = false;
        NotOn = 0;
        int b = 0xB0 | mmessage->channel;
        int p = 0xC0 | mmessage->channel;
        const mamba::MidiEvent evb = {{(unsigned char)b, 32, (unsigned char)bank}, 3, 0, 0};
        st->push_back(evb);
        const mamba::MidiEvent evp = {{(unsigned char)p, (unsigned char)program, 0}, 2, 0, 0};
        st->push_back(evp);
        if (!freewheel && play && (get_max_time_loop() > -1)) {
            start = startPlay[mmessage->channel];
            absoluteStart = startPlay[mmessage->channel];
        }
    } else if (record_finished && !freewheel && (get_max_time_loop() > -1)) {
        record_finished = 0;
        if (rec.is_sorted.load(std::memory_order_acquire)) {
            posPlay[mmessage->channel] = find_pos_for_playtime();
            rec.is_sorted.store(false, std::memory_order_release);
        } else {
            posPlay[mmessage->channel] = posPlay[get_max_time_loop()];
        }
        stStart = jack_last_frame_time(client);
    }
    jack_midi_event_t in_event;
    event_count = jack_midi_get_event_count(buf);
    unsigned int i;
    for (i = 0; i < event_count; i++) {
        jack_midi_event_get(&in_event, buf, i);
        unsigned char* midi_send = jack_midi_event_reserve(out_buf, i, in_event.size);
        midi_send[0] = in_event.buffer[0];
        midi_send[1] = in_event.buffer[1];
        if (in_event.size>2) 
            midi_send[2] = in_event.buffer[2];
        if (record)
            record_midi(midi_send, i, in_event.size);
        send_to_alsa(midi_send, in_event.size);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
        if ((in_event.buffer[0] & 0xf0) == 0x90) {   
            std::async(std::launch::async, trigger_get_midi_in, (int(in_event.buffer[0]&0x0f)), in_event.buffer[1], true);
        } else if ((in_event.buffer[0] & 0xf0) == 0x80) {   
            std::async(std::launch::async, trigger_get_midi_in, (int(in_event.buffer[0]&0x0f)), in_event.buffer[1], false);
        } else if ((in_event.buffer[0] ) == 0xf8) {   
            clock_gettime(CLOCK_MONOTONIC, &ts1);
            double time0 = (ts1.tv_sec*1000000000.0)+(ts1.tv_nsec)+
                    (1000000000.0/(double)(SampleRate/(double)in_event.time));
            if (mp.time_to_bpm(time0, &bpm)) {
                bpm_changed.store(true, std::memory_order_release);
                bpm_set.store((int)bpm, std::memory_order_release);
            }
        }
#pragma GCC diagnostic pop
    }
}
inline void XJack :: process_midi_in ( void * buf , void * out_buf ) { if ( record && fresh_take ) { start = jack_last_frame_time ( client ) ; absoluteStart = jack_last_frame_time ( client ) ; absoluteRecordStart = jack_last_frame_time ( client ) ; rcStart = jack_last_frame_time ( client ) ; fresh_take = false ; NotOn = 0 ; int b = 0xB0 | mmessage -> channel ; int p = 0xC0 | mmessage -> channel ; const mamba :: MidiEvent evb = { { ( unsigned char ) b , 32 , ( unsigned char ) bank } , 3 , 0 , 0 } ; st -> push_back ( evb ) ; const mamba :: MidiEvent evp = { { ( unsigned char ) p , ( unsigned char ) program , 0 } , 2 , 0 , 0 } ; st -> push_back ( evp ) ; if ( ! freewheel && play && ( get_max_time_loop ( ) > -1 ) ) { start = startPlay [ mmessage -> channel ] ; absoluteStart = startPlay [ mmessage -> channel ] ; } } else if ( record_finished && ! freewheel && ( get_max_time_loop ( ) > -1 ) ) { record_finished = 0 ; if ( rec . is_sorted . load ( std :: memory_order_acquire ) ) { posPlay [ mmessage -> channel ] = find_pos_for_playtime ( ) ; rec . is_sorted . store ( false , std :: memory_order_release ) ; } else { posPlay [ mmessage -> channel ] = posPlay [ get_max_time_loop ( ) ] ; } stStart = jack_last_frame_time ( client ) ; } jack_midi_event_t in_event ; event_count = jack_midi_get_event_count ( buf ) ; unsigned int i ; for ( i = 0 ; i < event_count ; i ++ ) { jack_midi_event_get ( & in_event , buf , i ) ; unsigned char * midi_send = jack_midi_event_reserve ( out_buf , i , in_event . size ) ; midi_send [ 0 ] = in_event . buffer [ 0 ] ; midi_send [ 1 ] = in_event . buffer [ 1 ] ; if ( in_event . size > 2 ) midi_send [ 2 ] = in_event . buffer [ 2 ] ; if ( record ) record_midi ( midi_send , i , in_event . size ) ; send_to_alsa ( midi_send , in_event . size ) ; #pragma  GCC diagnostic push #pragma  GCC diagnostic ignored "-Wunused-result" if ( ( in_event . buffer [ 0 ] & 0xf0 ) == 0x90 ) { std :: async ( std :: launch :: async , trigger_get_midi_in , ( int ( in_event . buffer [ 0 ] & 0x0f ) ) , in_event . buffer [ 1 ] , true ) ; } else if ( ( in_event . buffer [ 0 ] & 0xf0 ) == 0x80 ) { std :: async ( std :: launch :: async , trigger_get_midi_in , ( int ( in_event . buffer [ 0 ] & 0x0f ) ) , in_event . buffer [ 1 ] , false ) ; } else if ( ( in_event . buffer [ 0 ] ) == 0xf8 ) { clock_gettime ( CLOCK_MONOTONIC , & ts1 ) ; double time0 = ( ts1 . tv_sec * 1000000000.0 ) + ( ts1 . tv_nsec ) + ( 1000000000.0 / ( double ) ( SampleRate / ( double ) in_event . time ) ) ; if ( mp . time_to_bpm ( time0 , & bpm ) ) { bpm_changed . store ( true , std :: memory_order_release ) ; bpm_set . store ( ( int ) bpm , std :: memory_order_release ) ; } } #pragma  GCC diagnostic pop } }
jack process callback for the midi input
jack process callback for the midi input
// Note On // Note Off // midi beat clock