From ea1a0047d45bb880f7a8a3efd4c45c5c4e3f4af2 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 10 Aug 2022 15:00:52 -0400 Subject: Define JALV_BEGIN_DECLS and define JALV_END_DECLS One lines good, three lines bad. --- src/attributes.h | 15 +++++++++++++++ src/backend.h | 9 +++------ src/control.h | 9 +++------ src/frontend.h | 9 +++------ src/jalv_internal.h | 9 +++------ src/log.h | 9 +++------ src/nodes.h | 10 ++++------ src/options.h | 10 ++++------ src/port.h | 9 +++------ src/state.h | 9 +++------ src/types.h | 10 ++++------ src/urids.h | 10 ++++------ src/worker.h | 10 ++++------ 13 files changed, 56 insertions(+), 72 deletions(-) create mode 100644 src/attributes.h diff --git a/src/attributes.h b/src/attributes.h new file mode 100644 index 0000000..88a3e41 --- /dev/null +++ b/src/attributes.h @@ -0,0 +1,15 @@ +// Copyright 2022 David Robillard +// SPDX-License-Identifier: ISC + +#ifndef JALV_ATTRIBUTES_H +#define JALV_ATTRIBUTES_H + +#ifdef __cplusplus +# define JALV_BEGIN_DECLS extern "C" { +# define JALV_END_DECLS } +#else +# define JALV_BEGIN_DECLS +# define JALV_END_DECLS +#endif + +#endif // JALV_ATTRIBUTES_H diff --git a/src/backend.h b/src/backend.h index 53f5db2..a3bf1e9 100644 --- a/src/backend.h +++ b/src/backend.h @@ -4,13 +4,12 @@ #ifndef JALV_BACKEND_H #define JALV_BACKEND_H +#include "attributes.h" #include "types.h" #include -#ifdef __cplusplus -extern "C" { -#endif +JALV_BEGIN_DECLS // Audio/MIDI I/O backend interface @@ -30,8 +29,6 @@ jalv_backend_close(Jalv* jalv); void jalv_backend_activate_port(Jalv* jalv, uint32_t port_index); -#ifdef __cplusplus -} // extern "C" -#endif +JALV_END_DECLS #endif // JALV_BACKEND_H diff --git a/src/control.h b/src/control.h index e638d10..46ca360 100644 --- a/src/control.h +++ b/src/control.h @@ -4,6 +4,7 @@ #ifndef JALV_CONTROL_H #define JALV_CONTROL_H +#include "attributes.h" #include "nodes.h" #include "lilv/lilv.h" @@ -14,9 +15,7 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif +JALV_BEGIN_DECLS // Plugin control utilities @@ -99,8 +98,6 @@ add_control(Controls* controls, ControlID* control); ControlID* get_property_control(const Controls* controls, LV2_URID property); -#ifdef __cplusplus -} // extern "C" -#endif +JALV_END_DECLS #endif // JALV_CONTROL_H diff --git a/src/frontend.h b/src/frontend.h index 68e6863..774796d 100644 --- a/src/frontend.h +++ b/src/frontend.h @@ -4,6 +4,7 @@ #ifndef JALV_UI_H #define JALV_UI_H +#include "attributes.h" #include "options.h" #include "types.h" @@ -11,9 +12,7 @@ #include -#ifdef __cplusplus -extern "C" { -#endif +JALV_BEGIN_DECLS // Interface that must be implemented by UIs @@ -49,8 +48,6 @@ jalv_frontend_open(Jalv* jalv); int jalv_frontend_close(Jalv* jalv); -#ifdef __cplusplus -} // extern "C" -#endif +JALV_END_DECLS #endif // JALV_UI_H diff --git a/src/jalv_internal.h b/src/jalv_internal.h index 8028bcc..f7b820e 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -4,6 +4,7 @@ #ifndef JALV_INTERNAL_H #define JALV_INTERNAL_H +#include "attributes.h" #include "control.h" #include "jalv_config.h" #include "log.h" @@ -38,9 +39,7 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif +JALV_BEGIN_DECLS typedef struct { LV2_Feature map_feature; @@ -227,8 +226,6 @@ jalv_run(Jalv* jalv, uint32_t nframes); int jalv_update(Jalv* jalv); -#ifdef __cplusplus -} // extern "C" -#endif +JALV_END_DECLS #endif // JALV_INTERNAL_H diff --git a/src/log.h b/src/log.h index a2b7629..471d206 100644 --- a/src/log.h +++ b/src/log.h @@ -4,6 +4,7 @@ #ifndef JALV_LOG_H #define JALV_LOG_H +#include "attributes.h" #include "types.h" #include "urids.h" @@ -19,9 +20,7 @@ # define JALV_LOG_FUNC(fmt, arg1) #endif -#ifdef __cplusplus -extern "C" { -#endif +JALV_BEGIN_DECLS struct Port; @@ -69,8 +68,6 @@ jalv_ansi_start(FILE* stream, int color); void jalv_ansi_reset(FILE* stream); -#ifdef __cplusplus -} // extern "C" -#endif +JALV_END_DECLS #endif // JALV_LOG_H diff --git a/src/nodes.h b/src/nodes.h index d1adcd7..ff9d4da 100644 --- a/src/nodes.h +++ b/src/nodes.h @@ -4,11 +4,11 @@ #ifndef JALV_NODES_H #define JALV_NODES_H +#include "attributes.h" + #include "lilv/lilv.h" -#ifdef __cplusplus -extern "C" { -#endif +JALV_BEGIN_DECLS typedef struct { LilvNode* atom_AtomPort; @@ -51,8 +51,6 @@ typedef struct { LilvNode* end; ///< NULL terminator for easy freeing of entire structure } JalvNodes; -#ifdef __cplusplus -} // extern "C" -#endif +JALV_END_DECLS #endif // JALV_NODES_H diff --git a/src/options.h b/src/options.h index a9ffdc6..ae0d172 100644 --- a/src/options.h +++ b/src/options.h @@ -4,11 +4,11 @@ #ifndef JALV_OPTIONS_H #define JALV_OPTIONS_H +#include "attributes.h" + #include -#ifdef __cplusplus -extern "C" { -#endif +JALV_BEGIN_DECLS typedef struct { char* name; ///< Client name @@ -30,8 +30,6 @@ typedef struct { char* ui_uri; ///< URI of UI to load } JalvOptions; -#ifdef __cplusplus -} // extern "C" -#endif +JALV_END_DECLS #endif // JALV_OPTIONS_H diff --git a/src/port.h b/src/port.h index 7c6d644..5b3e0c9 100644 --- a/src/port.h +++ b/src/port.h @@ -4,6 +4,7 @@ #ifndef JALV_PORT_H #define JALV_PORT_H +#include "attributes.h" #include "lv2_evbuf.h" #include "lilv/lilv.h" @@ -11,9 +12,7 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif +JALV_BEGIN_DECLS enum PortFlow { FLOW_UNKNOWN, FLOW_INPUT, FLOW_OUTPUT }; @@ -31,8 +30,6 @@ struct Port { float control; ///< For control ports, otherwise 0.0f }; -#ifdef __cplusplus -} // extern "C" -#endif +JALV_END_DECLS #endif // JALV_PORT_H diff --git a/src/state.h b/src/state.h index 6d68967..86defd7 100644 --- a/src/state.h +++ b/src/state.h @@ -4,6 +4,7 @@ #ifndef JALV_STATE_H #define JALV_STATE_H +#include "attributes.h" #include "types.h" #include "lilv/lilv.h" @@ -12,9 +13,7 @@ #include "lv2/urid/urid.h" #include "serd/serd.h" -#ifdef __cplusplus -extern "C" { -#endif +JALV_BEGIN_DECLS // State and preset utilities @@ -60,8 +59,6 @@ atom_to_turtle(LV2_URID_Unmap* unmap, const SerdNode* predicate, const LV2_Atom* atom); -#ifdef __cplusplus -} // extern "C" -#endif +JALV_END_DECLS #endif // JALV_STATE_H diff --git a/src/types.h b/src/types.h index 6a1cfd7..ed577f6 100644 --- a/src/types.h +++ b/src/types.h @@ -4,9 +4,9 @@ #ifndef JALV_TYPES_H #define JALV_TYPES_H -#ifdef __cplusplus -extern "C" { -#endif +#include "attributes.h" + +JALV_BEGIN_DECLS /// Backend playing state typedef enum { JALV_RUNNING, JALV_PAUSE_REQUESTED, JALV_PAUSED } JalvPlayState; @@ -17,8 +17,6 @@ typedef struct JalvImpl Jalv; /// Audio/MIDI backend typedef struct JalvBackendImpl JalvBackend; -#ifdef __cplusplus -} // extern "C" -#endif +JALV_END_DECLS #endif // JALV_TYPES_H diff --git a/src/urids.h b/src/urids.h index 9363419..4dcbe20 100644 --- a/src/urids.h +++ b/src/urids.h @@ -4,11 +4,11 @@ #ifndef JALV_URIDS_H #define JALV_URIDS_H +#include "attributes.h" + #include "lv2/urid/urid.h" -#ifdef __cplusplus -extern "C" { -#endif +JALV_BEGIN_DECLS typedef struct { LV2_URID atom_Float; @@ -43,8 +43,6 @@ typedef struct { LV2_URID ui_updateRate; } JalvURIDs; -#ifdef __cplusplus -} // extern "C" -#endif +JALV_END_DECLS #endif // JALV_URIDS_H diff --git a/src/worker.h b/src/worker.h index b64fb46..5956e23 100644 --- a/src/worker.h +++ b/src/worker.h @@ -4,6 +4,8 @@ #ifndef JALV_WORKER_H #define JALV_WORKER_H +#include "attributes.h" + #include "zix/ring.h" #include "zix/sem.h" #include "zix/thread.h" @@ -14,9 +16,7 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif +JALV_BEGIN_DECLS // Worker for running non-realtime tasks for plugins @@ -52,8 +52,6 @@ jalv_worker_schedule(LV2_Worker_Schedule_Handle handle, void jalv_worker_emit_responses(JalvWorker* worker, LV2_Handle lv2_handle); -#ifdef __cplusplus -} // extern "C" -#endif +JALV_END_DECLS #endif // JALV_WORKER_H -- cgit v1.2.1