diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/control.c | 2 | ||||
-rw-r--r-- | src/jack.c | 12 | ||||
-rw-r--r-- | src/jalv.c | 26 | ||||
-rw-r--r-- | src/jalv_config.h | 169 | ||||
-rw-r--r-- | src/jalv_console.c | 22 | ||||
-rw-r--r-- | src/jalv_internal.h | 4 | ||||
-rw-r--r-- | src/log.c | 8 | ||||
-rw-r--r-- | src/portaudio.c | 1 | ||||
-rw-r--r-- | src/zix/ring.c | 2 |
9 files changed, 209 insertions, 37 deletions
diff --git a/src/control.c b/src/control.c index 23bdf05..7150032 100644 --- a/src/control.c +++ b/src/control.c @@ -1,8 +1,6 @@ // Copyright 2007-2022 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC -#define _POSIX_C_SOURCE 200809L - #include "control.h" #include "log.h" @@ -27,7 +27,7 @@ #include <jack/transport.h> #include <jack/types.h> -#ifdef HAVE_JACK_METADATA +#if USE_JACK_METADATA # include <jack/metadata.h> #endif @@ -64,7 +64,7 @@ jack_buffer_size_cb(jack_nframes_t nframes, void* data) Jalv* const jalv = (Jalv*)data; jalv->block_length = nframes; jalv->buf_size_set = true; -#ifdef HAVE_JACK_PORT_TYPE_GET_BUFFER_SIZE +#if USE_JACK_PORT_TYPE_GET_BUFFER_SIZE jalv->midi_buf_size = jack_port_type_get_buffer_size(jalv->backend->client, JACK_DEFAULT_MIDI_TYPE); #endif @@ -174,7 +174,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) // Connect plugin port directly to Jack port buffer lilv_instance_connect_port( jalv->instance, p, jack_port_get_buffer(port->sys_port, nframes)); -#ifdef HAVE_JACK_METADATA +#if USE_JACK_METADATA } else if (port->type == TYPE_CV && port->sys_port) { // Connect plugin port directly to Jack port buffer lilv_instance_connect_port( @@ -376,7 +376,7 @@ jalv_backend_init(Jalv* jalv) jalv->sample_rate = (float)jack_get_sample_rate(client); jalv->block_length = jack_get_buffer_size(client); jalv->midi_buf_size = 4096; -#ifdef HAVE_JACK_PORT_TYPE_GET_BUFFER_SIZE +#if USE_JACK_PORT_TYPE_GET_BUFFER_SIZE jalv->midi_buf_size = jack_port_type_get_buffer_size(client, JACK_DEFAULT_MIDI_TYPE); #endif @@ -455,7 +455,7 @@ jalv_backend_activate_port(Jalv* jalv, uint32_t port_index) port->sys_port = jack_port_register( client, lilv_node_as_string(sym), JACK_DEFAULT_AUDIO_TYPE, jack_flags, 0); break; -#ifdef HAVE_JACK_METADATA +#if USE_JACK_METADATA case TYPE_CV: port->sys_port = jack_port_register( client, lilv_node_as_string(sym), JACK_DEFAULT_AUDIO_TYPE, jack_flags, 0); @@ -482,7 +482,7 @@ jalv_backend_activate_port(Jalv* jalv, uint32_t port_index) break; } -#ifdef HAVE_JACK_METADATA +#if USE_JACK_METADATA if (port->sys_port) { // Set port order to index char index_str[16]; @@ -1,10 +1,6 @@ // Copyright 2007-2022 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC -#define _POSIX_C_SOURCE 200809L // for mkdtemp -#define _XOPEN_SOURCE 600 // for S_IFMT and S_IFDIF -#define _DARWIN_C_SOURCE // for mkdtemp on Darwin - #include "backend.h" #include "control.h" #include "frontend.h" @@ -48,7 +44,7 @@ #include "zix/ring.h" #include "zix/sem.h" -#ifdef HAVE_SUIL +#if USE_SUIL # include "suil/suil.h" #endif @@ -210,7 +206,7 @@ create_port(Jalv* jalv, uint32_t port_index, float default_value) } else if (lilv_port_is_a( jalv->plugin, port->lilv_port, jalv->nodes.lv2_AudioPort)) { port->type = TYPE_AUDIO; -#ifdef HAVE_JACK_METADATA +#if USE_JACK_METADATA } else if (lilv_port_is_a( jalv->plugin, port->lilv_port, jalv->nodes.lv2_CVPort)) { port->type = TYPE_CV; @@ -415,7 +411,7 @@ jalv_set_control(Jalv* jalv, void jalv_ui_instantiate(Jalv* jalv, const char* native_ui_type, void* parent) { -#ifdef HAVE_SUIL +#if USE_SUIL jalv->ui_host = suil_host_new(jalv_ui_write, jalv_ui_port_index, NULL, NULL); const LV2_Feature parent_feature = {LV2_UI__parent, parent}; @@ -752,7 +748,7 @@ setup_signals(Jalv* const jalv) { exit_sem = &jalv->done; -#ifdef HAVE_SIGACTION +#if !defined(_WIN32) && USE_SIGACTION struct sigaction action; sigemptyset(&action.sa_mask); action.sa_flags = 0; @@ -780,7 +776,7 @@ jalv_select_custom_ui(const Jalv* const jalv) return ui; } -#ifdef HAVE_SUIL +#if USE_SUIL if (native_ui_type_uri) { // Try to find an embeddable UI LilvNode* native_type = lilv_new_uri(jalv->world, native_ui_type_uri); @@ -834,7 +830,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) jalv->bpm = 120.0f; jalv->control_in = (uint32_t)-1; -#ifdef HAVE_SUIL +#if USE_SUIL suil_init(argc, argv, SUIL_ARG_NONE); #endif @@ -1082,6 +1078,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) jalv->uis = lilv_plugin_get_uis(jalv->plugin); if (!jalv->opts.generic_ui) { if ((jalv->ui = jalv_select_custom_ui(jalv))) { +#if USE_SUIL const char* host_type_uri = jalv_frontend_ui_type(); if (host_type_uri) { LilvNode* host_type = lilv_new_uri(jalv->world, host_type_uri); @@ -1093,6 +1090,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) lilv_node_free(host_type); } +#endif } } @@ -1127,7 +1125,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) jalv->opts.buffer_size = jalv->midi_buf_size * N_BUFFER_CYCLES; } - if (jalv->opts.update_rate == 0.0) { + if (!jalv->opts.update_rate) { // Calculate a reasonable UI update frequency jalv->ui_update_hz = jalv_frontend_refresh_rate(jalv); } else { @@ -1136,7 +1134,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) jalv->ui_update_hz = MAX(1.0f, jalv->ui_update_hz); } - if (jalv->opts.scale_factor == 0.0) { + if (!jalv->opts.scale_factor) { // Calculate the monitor's scale factor jalv->ui_scale_factor = jalv_frontend_scale_factor(jalv); } else { @@ -1335,7 +1333,7 @@ jalv_close(Jalv* const jalv) jalv_worker_destroy(&jalv->worker); // Deactivate plugin -#ifdef HAVE_SUIL +#if USE_SUIL suil_instance_free(jalv->ui_instance); #endif if (jalv->instance) { @@ -1352,7 +1350,7 @@ jalv_close(Jalv* const jalv) } symap_free(jalv->symap); zix_sem_destroy(&jalv->symap_lock); -#ifdef HAVE_SUIL +#if USE_SUIL suil_host_free(jalv->ui_host); #endif diff --git a/src/jalv_config.h b/src/jalv_config.h new file mode 100644 index 0000000..1587d17 --- /dev/null +++ b/src/jalv_config.h @@ -0,0 +1,169 @@ +// Copyright 2021-2022 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: ISC + +/* + Configuration header that defines reasonable defaults at compile time. + + This allows compile-time configuration from the command line, while still + allowing the source to be built "as-is" without any configuration. The idea + is to support an advanced build system with configuration checks, while still + allowing the code to be simply "thrown at a compiler" with features + determined from the compiler or system headers. Everything can be + overridden, so it should never be necessary to edit this file to build + successfully. + + To ensure that all configure checks are performed, the build system can + define JALV_NO_DEFAULT_CONFIG to disable defaults. In this case, it must + define all HAVE_FEATURE symbols below to 1 or 0 to enable or disable + features. Any missing definitions will generate a compiler warning. + + To ensure that this header is always included properly, all code that uses + configuration variables includes this header and checks their value with #if + (not #ifdef). Variables like USE_FEATURE are internal and should never be + defined on the command line. +*/ + +#ifndef JALV_CONFIG_H +#define JALV_CONFIG_H + +// Define version unconditionally so a warning will catch a mismatch +#define JALV_VERSION "1.6.7" + +#if !defined(JALV_NO_DEFAULT_CONFIG) + +// We need unistd.h to check _POSIX_VERSION +# ifndef JALV_NO_POSIX +# ifdef __has_include +# if __has_include(<unistd.h>) +# include <unistd.h> +# endif +# elif defined(__unix__) +# include <unistd.h> +# endif +# endif + +// POSIX.1-2001: fileno() +# ifndef HAVE_FILENO +# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L +# define HAVE_FILENO +# endif +# endif + +// POSIX.1-2001: isatty() +# ifndef HAVE_ISATTY +# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L +# define HAVE_ISATTY +# endif +# endif + +// POSIX.1-2001: mlock() +# ifndef HAVE_MLOCK +# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L +# define HAVE_MLOCK 1 +# else +# define HAVE_MLOCK 0 +# endif +# endif + +// POSIX.1-2001: posix_memalign() +# ifndef HAVE_POSIX_MEMALIGN +# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L +# define HAVE_POSIX_MEMALIGN 1 +# else +# define HAVE_POSIX_MEMALIGN 0 +# endif +# endif + +// POSIX.1-2001: sigaction() +# ifndef HAVE_SIGACTION +# if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L +# define HAVE_SIGACTION +# endif +# endif + +// Suil +# ifndef HAVE_SUIL +# ifdef __has_include +# if __has_include("suil/suil.h") +# define HAVE_SUIL +# endif +# endif +# endif + +// JACK metadata API +# ifndef HAVE_JACK_METADATA +# ifdef __has_include +# if __has_include("jack/metadata.h") +# define HAVE_JACK_METADATA +# endif +# endif +# endif + +// JACK jack_port_type_get_buffer_size() function +# ifndef HAVE_JACK_PORT_TYPE_GET_BUFFER_SIZE +# ifdef __has_include +# if __has_include("jack/midiport.h") +# define HAVE_JACK_PORT_TYPE_GET_BUFFER_SIZE +# endif +# endif +# endif + +#endif // !defined(JALV_NO_DEFAULT_CONFIG) + +/* + Make corresponding USE_FEATURE defines based on the HAVE_FEATURE defines from + above or the command line. The code checks for these using #if (not #ifdef), + so there will be an undefined warning if it checks for an unknown feature, + and this header is always required by any code that checks for features, even + if the build system defines them all. +*/ + +#if HAVE_FILENO +# define USE_FILENO 1 +#else +# define USE_FILENO 0 +#endif + +#if HAVE_ISATTY +# define USE_ISATTY 1 +#else +# define USE_ISATTY 0 +#endif + +#if HAVE_MLOCK +# define USE_MLOCK 1 +#else +# define USE_MLOCK 0 +#endif + +#if HAVE_POSIX_MEMALIGN +# define USE_POSIX_MEMALIGN 1 +#else +# define USE_POSIX_MEMALIGN 0 +#endif + +#if HAVE_SIGACTION +# define USE_SIGACTION 1 +#else +# define USE_SIGACTION 0 +#endif + +#if HAVE_SUIL +# define USE_SUIL 1 +#else +# define USE_SUIL 0 +#endif + +#if HAVE_JACK_METADATA +# define USE_JACK_METADATA 1 +#else +# define USE_JACK_METADATA 0 +#endif + +#if HAVE_JACK_PORT_TYPE_GET_BUFFER_SIZE +# define USE_JACK_PORT_TYPE_GET_BUFFER_SIZE 1 +#else +# define USE_JACK_PORT_TYPE_GET_BUFFER_SIZE 0 +#endif + +#endif // JALV_CONFIG_H diff --git a/src/jalv_console.c b/src/jalv_console.c index ebb9164..5c129ff 100644 --- a/src/jalv_console.c +++ b/src/jalv_console.c @@ -1,11 +1,6 @@ // Copyright 2007-2022 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC -#define _POSIX_C_SOURCE 200809L -#define _XOPEN_SOURCE 600 -#define _BSD_SOURCE 1 -#define _DEFAULT_SOURCE 1 - #include "control.h" #include "frontend.h" #include "jalv_config.h" @@ -18,10 +13,13 @@ #include "lilv/lilv.h" #include "lv2/ui/ui.h" -#include "suil/suil.h" #include "zix/common.h" #include "zix/sem.h" +#if USE_SUIL +# include "suil/suil.h" +#endif + #ifdef _WIN32 # include <synchapi.h> #else @@ -74,10 +72,18 @@ jalv_ui_port_event(Jalv* jalv, uint32_t protocol, const void* buffer) { +#if USE_SUIL if (jalv->ui_instance) { suil_instance_port_event( jalv->ui_instance, port_index, buffer_size, protocol, buffer); } +#else + (void)jalv; + (void)port_index; + (void)buffer_size; + (void)protocol; + (void)buffer; +#endif } int @@ -247,7 +253,7 @@ jalv_frontend_discover(Jalv* jalv) static bool jalv_run_custom_ui(Jalv* jalv) { -#ifdef HAVE_SUIL +#if USE_SUIL const LV2UI_Idle_Interface* idle_iface = NULL; const LV2UI_Show_Interface* show_iface = NULL; if (jalv->ui && jalv->opts.show_ui) { @@ -278,6 +284,8 @@ jalv_run_custom_ui(Jalv* jalv) show_iface->hide(suil_instance_get_handle(jalv->ui_instance)); return true; } +#else + (void)jalv; #endif return false; diff --git a/src/jalv_internal.h b/src/jalv_internal.h index 5a33bf5..87c61d9 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -20,7 +20,7 @@ #include "lilv/lilv.h" #include "serd/serd.h" #include "sratom/sratom.h" -#ifdef HAVE_SUIL +#if USE_SUIL # include "suil/suil.h" #endif @@ -93,7 +93,7 @@ struct JalvImpl { const LilvUI* ui; ///< Plugin UI (RDF data) const LilvNode* ui_type; ///< Plugin UI type (unwrapped) LilvInstance* instance; ///< Plugin instance (shared library) -#ifdef HAVE_SUIL +#if USE_SUIL SuilHost* ui_host; ///< Plugin UI host support SuilInstance* ui_instance; ///< Plugin UI instance (shared library) #endif @@ -1,8 +1,6 @@ // Copyright 2007-2022 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC -#define _POSIX_C_SOURCE 200809L - #include "log.h" #include "jalv_config.h" @@ -14,7 +12,7 @@ #include "lv2/log/log.h" #include "lv2/urid/urid.h" -#ifdef HAVE_ISATTY +#if USE_ISATTY # include <unistd.h> #endif @@ -129,7 +127,7 @@ jalv_printf(LV2_Log_Handle handle, LV2_URID type, const char* fmt, ...) bool jalv_ansi_start(FILE* stream, int color) { -#if defined(HAVE_ISATTY) && defined(HAVE_FILENO) +#if USE_ISATTY && USE_FILENO if (isatty(fileno(stream))) { return fprintf(stream, "\033[0;%dm", color); } @@ -140,7 +138,7 @@ jalv_ansi_start(FILE* stream, int color) void jalv_ansi_reset(FILE* stream) { -#ifdef HAVE_ISATTY +#if USE_ISATTY if (isatty(fileno(stream))) { fprintf(stream, "\033[0m"); fflush(stream); diff --git a/src/portaudio.c b/src/portaudio.c index bc687b1..2d2ccfc 100644 --- a/src/portaudio.c +++ b/src/portaudio.c @@ -4,6 +4,7 @@ #include "backend.h" #include "jalv_internal.h" +#include "port.h" #include "worker.h" #include <math.h> diff --git a/src/zix/ring.c b/src/zix/ring.c index 78cc7b4..a48153a 100644 --- a/src/zix/ring.c +++ b/src/zix/ring.c @@ -6,7 +6,7 @@ #include <stdlib.h> #include <string.h> -#ifdef HAVE_MLOCK +#if HAVE_MLOCK # include <sys/mman.h> # define ZIX_MLOCK(ptr, size) mlock((ptr), (size)) #elif defined(_WIN32) |