diff options
-rw-r--r-- | src/jack.c | 5 | ||||
-rw-r--r-- | src/jalv.c | 50 | ||||
-rw-r--r-- | src/jalv_internal.h | 8 |
3 files changed, 47 insertions, 16 deletions
@@ -404,7 +404,7 @@ jalv_backend_activate(Jalv* jalv) void jalv_backend_deactivate(Jalv* jalv) { - if (jalv->backend && !jalv->backend->is_internal_client) { + if (!jalv->backend->is_internal_client) { jack_deactivate(jalv->backend->client); } } @@ -551,6 +551,8 @@ jack_initialize(jack_client_t* const client, const char* const load_init) if (err || (err = jalv_open(jalv, &argc, &argv))) { jalv_close(jalv); free(jalv); + } else { + jalv_activate(jalv); } free(argv); @@ -566,6 +568,7 @@ jack_finish(void* const arg) { Jalv* const jalv = (Jalv*)arg; if (jalv) { + jalv_deactivate(jalv); if (jalv_close(jalv)) { jalv_log(JALV_LOG_ERR, "Failed to close Jalv\n"); } @@ -1118,30 +1118,47 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) } } - jalv_worker_launch(jalv->worker); - - // Activate plugin - lilv_instance_activate(jalv->instance); - // Discover UI jalv->has_ui = jalv_frontend_discover(jalv); + return 0; +} - // Activate audio backend +int +jalv_activate(Jalv* const jalv) +{ jalv->run_state = JALV_RUNNING; - jalv_backend_activate(jalv); + + if (jalv->backend) { + if (jalv->worker) { + jalv_worker_launch(jalv->worker); + } + lilv_instance_activate(jalv->instance); + jalv_backend_activate(jalv); + } return 0; } int -jalv_close(Jalv* const jalv) +jalv_deactivate(Jalv* const jalv) { - // Terminate the worker - jalv_worker_exit(jalv->worker); - - // Deactivate audio if (jalv->backend) { jalv_backend_deactivate(jalv); + lilv_instance_deactivate(jalv->instance); + if (jalv->worker) { + jalv_worker_exit(jalv->worker); + } + } + + jalv->run_state = JALV_PAUSED; + return 0; +} + +int +jalv_close(Jalv* const jalv) +{ + jalv_deactivate(jalv); + if (jalv->backend) { jalv_backend_close(jalv); } @@ -1156,12 +1173,11 @@ jalv_close(Jalv* const jalv) jalv_worker_free(jalv->worker); jalv_worker_free(jalv->state_worker); - // Deactivate plugin + // Free UI and plugin instances #if USE_SUIL suil_instance_free(jalv->ui_instance); #endif if (jalv->instance) { - lilv_instance_deactivate(jalv->instance); lilv_instance_free(jalv->instance); } @@ -1217,13 +1233,15 @@ main(int argc, char** argv) Jalv jalv; memset(&jalv, '\0', sizeof(Jalv)); + // Initialize application if (jalv_open(&jalv, &argc, &argv)) { jalv_close(&jalv); return EXIT_FAILURE; } - // Set up signal handlers + // Set up signal handlers and activate audio processing setup_signals(&jalv); + jalv_activate(&jalv); // Run UI (or prompt at console) jalv_frontend_open(&jalv); @@ -1231,5 +1249,7 @@ main(int argc, char** argv) // Wait for finish signal from UI or signal handler zix_sem_wait(&jalv.done); + // Deactivate audio processing and tear down application + jalv_deactivate(&jalv); return jalv_close(&jalv); } diff --git a/src/jalv_internal.h b/src/jalv_internal.h index cad085b..17d2b33 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -126,6 +126,14 @@ jalv_open(Jalv* jalv, int* argc, char*** argv); int jalv_close(Jalv* jalv); +/// Activate audio processing +int +jalv_activate(Jalv* jalv); + +/// Deactivate audio processing +int +jalv_deactivate(Jalv* jalv); + /// Allocate appropriately-sized port buffers and connect the plugin to them void jalv_allocate_port_buffers(Jalv* jalv); |