From 5a16e2d8cb8e9db9b48a7baa79a8cbfbb1fd7697 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 18 Nov 2024 09:18:50 -0500 Subject: Move main() and related code to a separate file --- src/jalv.c | 59 ------------------------------------------------ src/main.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 59 deletions(-) create mode 100644 src/main.c (limited to 'src') diff --git a/src/jalv.c b/src/jalv.c index d7d236b..3400f89 100644 --- a/src/jalv.c +++ b/src/jalv.c @@ -37,7 +37,6 @@ #include "lv2/urid/urid.h" #include "lv2/worker/worker.h" #include "zix/allocator.h" -#include "zix/attributes.h" #include "zix/filesystem.h" #include "zix/ring.h" #include "zix/sem.h" @@ -47,7 +46,6 @@ # include "suil/suil.h" #endif -#include #include #include #include @@ -64,8 +62,6 @@ */ #define N_BUFFER_CYCLES 16 -static ZixSem* exit_sem = NULL; ///< Exit semaphore used by signal handler - /// These features have no data static const LV2_Feature static_features[] = { {LV2_STATE__loadDefaultState, NULL}, @@ -577,12 +573,6 @@ jalv_apply_control_arg(Jalv* jalv, const char* s) return true; } -static void -signal_handler(int ZIX_UNUSED(sig)) -{ - zix_sem_post(exit_sem); -} - static void init_feature(LV2_Feature* const dest, const char* const URI, void* data) { @@ -590,25 +580,6 @@ init_feature(LV2_Feature* const dest, const char* const URI, void* data) dest->data = data; } -static void -setup_signals(Jalv* const jalv) -{ - exit_sem = &jalv->done; - -#if !defined(_WIN32) && USE_SIGACTION - struct sigaction action; - sigemptyset(&action.sa_mask); - action.sa_flags = 0; - action.sa_handler = signal_handler; - sigaction(SIGINT, &action, NULL); - sigaction(SIGTERM, &action, NULL); -#else - // May not work in combination with fgets in the console interface - signal(SIGINT, signal_handler); - signal(SIGTERM, signal_handler); -#endif -} - static const LilvUI* jalv_select_custom_ui(const Jalv* const jalv) { @@ -1177,33 +1148,3 @@ jalv_close(Jalv* const jalv) return 0; } - -int -main(int argc, char** argv) -{ - Jalv jalv; - memset(&jalv, '\0', sizeof(Jalv)); - jalv.backend = jalv_backend_allocate(); - - // Initialize application - if (jalv_open(&jalv, &argc, &argv)) { - jalv_close(&jalv); - return EXIT_FAILURE; - } - - // Set up signal handlers and activate audio processing - setup_signals(&jalv); - jalv_activate(&jalv); - - // Run UI (or prompt at console) - jalv_frontend_open(&jalv); - - // Wait for finish signal from UI or signal handler - zix_sem_wait(&jalv.done); - - // Deactivate audio processing and tear down application - jalv_deactivate(&jalv); - const int ret = jalv_close(&jalv); - jalv_backend_free(jalv.backend); - return ret; -} diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..51a5d3d --- /dev/null +++ b/src/main.c @@ -0,0 +1,76 @@ +// Copyright 2007-2024 David Robillard +// SPDX-License-Identifier: ISC + +#include "backend.h" +#include "frontend.h" +#include "jalv_config.h" +#include "jalv_internal.h" +#include "types.h" + +#include "zix/attributes.h" +#include "zix/sem.h" + +#if USE_SUIL +#endif + +#include +#include +#include +#include + +static ZixSem* exit_sem = NULL; ///< Exit semaphore used by signal handler + +static void +signal_handler(int ZIX_UNUSED(sig)) +{ + zix_sem_post(exit_sem); +} + +static void +setup_signals(Jalv* const jalv) +{ + exit_sem = &jalv->done; + +#if !defined(_WIN32) && USE_SIGACTION + struct sigaction action; + sigemptyset(&action.sa_mask); + action.sa_flags = 0; + action.sa_handler = signal_handler; + sigaction(SIGINT, &action, NULL); + sigaction(SIGTERM, &action, NULL); +#else + // May not work in combination with fgets in the console interface + signal(SIGINT, signal_handler); + signal(SIGTERM, signal_handler); +#endif +} + +int +main(int argc, char** argv) +{ + Jalv jalv; + memset(&jalv, '\0', sizeof(Jalv)); + jalv.backend = jalv_backend_allocate(); + + // Initialize application + if (jalv_open(&jalv, &argc, &argv)) { + jalv_close(&jalv); + return EXIT_FAILURE; + } + + // Set up signal handlers and activate audio processing + setup_signals(&jalv); + jalv_activate(&jalv); + + // Run UI (or prompt at console) + jalv_frontend_open(&jalv); + + // Wait for finish signal from UI or signal handler + zix_sem_wait(&jalv.done); + + // Deactivate audio processing and tear down application + jalv_deactivate(&jalv); + const int ret = jalv_close(&jalv); + jalv_backend_free(jalv.backend); + return ret; +} -- cgit v1.2.1