aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-11-18 09:18:50 -0500
committerDavid Robillard <d@drobilla.net>2024-11-24 19:08:02 -0500
commit5a16e2d8cb8e9db9b48a7baa79a8cbfbb1fd7697 (patch)
treeb480610ea2f9264dd03c215a183fd061bc85b95a
parent64f74f51f864ef8cf40f026013a2e466e7fc9066 (diff)
downloadjalv-5a16e2d8cb8e9db9b48a7baa79a8cbfbb1fd7697.tar.gz
jalv-5a16e2d8cb8e9db9b48a7baa79a8cbfbb1fd7697.tar.bz2
jalv-5a16e2d8cb8e9db9b48a7baa79a8cbfbb1fd7697.zip
Move main() and related code to a separate file
-rw-r--r--meson.build1
-rw-r--r--src/jalv.c59
-rw-r--r--src/main.c76
3 files changed, 77 insertions, 59 deletions
diff --git a/meson.build b/meson.build
index f2f18b1..ec347c2 100644
--- a/meson.build
+++ b/meson.build
@@ -420,6 +420,7 @@ common_sources = files(
'src/jalv.c',
'src/log.c',
'src/lv2_evbuf.c',
+ 'src/main.c',
'src/mapper.c',
'src/nodes.c',
'src/process.c',
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 <signal.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
@@ -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},
@@ -578,37 +574,12 @@ jalv_apply_control_arg(Jalv* jalv, const char* s)
}
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)
{
dest->URI = URI;
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 <d@drobilla.net>
+// 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 <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+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;
+}