Use jack_on_shutdown callback to terminate gracefully when Jack is shutting down.

master
Albert Graef 2018-08-15 21:36:42 +02:00
parent c1b7398513
commit b4e85ef288
3 changed files with 19 additions and 0 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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;