diff --git a/jackdriver.c b/jackdriver.c index b176df5..6e726ff 100644 --- a/jackdriver.c +++ b/jackdriver.c @@ -369,6 +369,15 @@ int pop_midi(void* seqq, uint8_t msg[], uint8_t *port_no) return 0; } +int jack_shutdown; + +void +shutdown_callback() +{ + // we can't do anything fancy here, just ping the main thread + jack_shutdown = 1; +} + //////////////////////////////// //this is run in the main thread //////////////////////////////// @@ -388,6 +397,9 @@ init_jack(JACK_SEQ* seq, uint8_t verbose) return 0; } + if(verbose)printf("assigning shutdown callback...\n"); + jack_on_shutdown(seq->jack_client, shutdown_callback, (void*)seq); + if(verbose)printf("assigning process callback...\n"); err = jack_set_process_callback(seq->jack_client, process_callback, (void*)seq); if (err) diff --git a/jackdriver.h b/jackdriver.h index 2c86a91..4092ca4 100644 --- a/jackdriver.h +++ b/jackdriver.h @@ -15,6 +15,8 @@ typedef struct _jseq uint8_t n_out; } JACK_SEQ; +extern int jack_shutdown; + int init_jack(JACK_SEQ* seq, uint8_t verbose); void close_jack(JACK_SEQ* seq); void queue_midi(void* seqq, uint8_t msg[], uint8_t port_no); diff --git a/midizap.c b/midizap.c index 03de0ac..8dace48 100644 --- a/midizap.c +++ b/midizap.c @@ -900,6 +900,11 @@ main(int argc, char **argv) signal(SIGINT, quitter); while (!quit) { uint8_t portno; + if (jack_shutdown) { + fprintf(stderr, "%s: jack shutting down, exiting\n", argv[0]); + close_jack(&seq); + exit(0); + } while (pop_midi(&seq, msg, &portno)) { handle_event(msg, portno); count = 0;