diff options
author | David Robillard <d@drobilla.net> | 2018-09-29 11:29:27 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-11-10 11:45:15 +0100 |
commit | 84d5676be6648c29a972f58b0b920a772191c71e (patch) | |
tree | 1b1d5aa3450511719b8d16a1fb98b8c7113acae3 | |
parent | 677b06dfc2d8a8b361572d1dbee9c763823f8e9b (diff) | |
download | jalv-84d5676be6648c29a972f58b0b920a772191c71e.tar.gz jalv-84d5676be6648c29a972f58b0b920a772191c71e.tar.bz2 jalv-84d5676be6648c29a972f58b0b920a772191c71e.zip |
Separate the bulk of main code into jalv_open() and jalv_close()
-rw-r--r-- | src/jalv.c | 37 | ||||
-rw-r--r-- | src/jalv_internal.h | 6 |
2 files changed, 32 insertions, 11 deletions
@@ -728,10 +728,9 @@ signal_handler(ZIX_UNUSED int sig) zix_sem_post(&exit_sem); } -static int -jalv_main(Jalv* jalv, int argc, char** argv) +int +jalv_open(Jalv* const jalv, int argc, char** argv) { - memset(jalv, '\0', sizeof(Jalv)); jalv->prog_name = argv[0]; jalv->block_length = 4096; /* Should be set by backend */ jalv->midi_buf_size = 1024; /* Should be set by backend */ @@ -742,6 +741,7 @@ jalv_main(Jalv* jalv, int argc, char** argv) #ifdef HAVE_SUIL suil_init(&argc, &argv, SUIL_ARG_NONE); #endif + if (jalv_init(&argc, &argv, &jalv->opts)) { return -1; } @@ -1127,11 +1127,12 @@ jalv_main(Jalv* jalv, int argc, char** argv) jalv_backend_activate(jalv); jalv->play_state = JALV_RUNNING; - /* Run UI (or prompt at console) */ - jalv_open_ui(jalv); + return 0; +} - /* Wait for finish signal from UI or signal handler */ - zix_sem_wait(&exit_sem); +int +jalv_close(Jalv* const jalv) +{ jalv->exit = true; fprintf(stderr, "Exiting...\n"); @@ -1155,8 +1156,10 @@ jalv_main(Jalv* jalv, int argc, char** argv) #ifdef HAVE_SUIL suil_instance_free(jalv->ui_instance); #endif - lilv_instance_deactivate(jalv->instance); - lilv_instance_free(jalv->instance); + if (jalv->instance) { + lilv_instance_deactivate(jalv->instance); + lilv_instance_free(jalv->instance); + } /* Clean up */ free(jalv->ports); @@ -1173,7 +1176,7 @@ jalv_main(Jalv* jalv, int argc, char** argv) sratom_free(jalv->sratom); sratom_free(jalv->ui_sratom); lilv_uis_free(jalv->uis); - lilv_world_free(world); + lilv_world_free(jalv->world); zix_sem_destroy(&exit_sem); @@ -1188,5 +1191,17 @@ int main(int argc, char** argv) { Jalv jalv; - return jalv_main(&jalv, argc, argv); + memset(&jalv, '\0', sizeof(Jalv)); + + if (jalv_open(&jalv, argc, argv)) { + return EXIT_FAILURE; + } + + /* Run UI (or prompt at console) */ + jalv_open_ui(&jalv); + + /* Wait for finish signal from UI or signal handler */ + zix_sem_wait(jalv.done); + + return jalv_close(&jalv); } diff --git a/src/jalv_internal.h b/src/jalv_internal.h index 13773e1..6335f9e 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -321,8 +321,14 @@ struct Jalv { }; int +jalv_open(Jalv* jalv, int argc, char** argv); + +int jalv_init(int* argc, char*** argv, JalvOptions* opts); +int +jalv_close(Jalv* jalv); + JalvBackend* jalv_backend_init(Jalv* jalv); |