commit 4edb06e60ee5c81af38b0b060f225dfd05d5a41e
parent 72423e1edd1ab52e397313dbc9a155a4c6510c84
Author: falkTX <falktx@falktx.com>
Date: Sat, 25 Sep 2021 14:59:14 +0100
VST3: Rework headers coding style, add C++ util, cleanup
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat:
10 files changed, 246 insertions(+), 424 deletions(-)
diff --git a/distrho/src/DistrhoPluginVST3.cpp b/distrho/src/DistrhoPluginVST3.cpp
@@ -25,18 +25,25 @@
#include <atomic>
#include <vector>
-// TESTING awful idea dont reuse
-#include "../extra/Thread.hpp"
+/* TODO items:
+ * - base component refcount handling
+ * - program support
+ * - state support
+ * - midi cc parameter mapping
+ * - full MIDI1 encode and decode
+ * - call component handler restart with params-changed flag when setting program
+ * - call component handler restart with latency-changed flag when latency changes
+ */
START_NAMESPACE_DISTRHO
// --------------------------------------------------------------------------------------------------------------------
#if ! DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
-static const writeMidiFunc writeMidiCallback = nullptr;
+static constexpr const writeMidiFunc writeMidiCallback = nullptr;
#endif
#if ! DISTRHO_PLUGIN_WANT_PARAMETER_VALUE_CHANGE_REQUEST
-static const requestParameterValueChangeFunc requestParameterValueChangeCallback = nullptr;
+static constexpr const requestParameterValueChangeFunc requestParameterValueChangeCallback = nullptr;
#endif
// --------------------------------------------------------------------------------------------------------------------
@@ -67,7 +74,7 @@ static dpf_tuid dpf_tuid_view = { dpf_id_entry, dpf_id_view, 0, 0 };
// --------------------------------------------------------------------------------------------------------------------
// Utility functions
-static const char* tuid2str(const v3_tuid iid)
+const char* tuid2str(const v3_tuid iid)
{
if (v3_tuid_match(iid, v3_funknown_iid))
return "{v3_funknown}";
@@ -220,7 +227,6 @@ public:
PluginVst3()
: fPlugin(this, writeMidiCallback, requestParameterValueChangeCallback),
fComponentHandler(nullptr),
- fComponentHandlerArg(nullptr),
fParameterValues(nullptr)
#if DISTRHO_PLUGIN_WANT_MIDI_OUTPUT
, fHostEventOutputHandle(nullptr)
@@ -1136,10 +1142,9 @@ public:
return V3_OK;
}
- v3_result setComponentHandler(v3_component_handler* const handler, void* const arg) noexcept
+ v3_result setComponentHandler(v3_component_handler** const handler) noexcept
{
fComponentHandler = handler;
- fComponentHandlerArg = arg;
return V3_OK;
}
@@ -1150,8 +1155,7 @@ private:
PluginExporter fPlugin;
// VST3 stuff
- v3_component_handler* fComponentHandler;
- void* fComponentHandlerArg;
+ v3_component_handler** fComponentHandler;
// Temporary data
float* fParameterValues;
@@ -1209,15 +1213,14 @@ private:
bool requestParameterValueChange(const uint32_t index, const float value)
{
DISTRHO_SAFE_ASSERT_RETURN(fComponentHandler != nullptr, false);
- DISTRHO_SAFE_ASSERT_RETURN(fComponentHandlerArg != nullptr, false);
- if (fComponentHandler->begin_edit(fComponentHandlerArg, index) != V3_OK)
+ if (v3_cpp_obj(fComponentHandler)->begin_edit(fComponentHandler, index) != V3_OK)
return false;
const double normalized = fPlugin.getParameterRanges(index).getNormalizedValue(value);
- const bool ret = fComponentHandler->perform_edit(fComponentHandlerArg, index, normalized) == V3_OK;
+ const bool ret = v3_cpp_obj(fComponentHandler)->perform_edit(fComponentHandler, index, normalized) == V3_OK;
- fComponentHandler->end_edit(fComponentHandlerArg, index);
+ v3_cpp_obj(fComponentHandler)->end_edit(fComponentHandler, index);
return ret;
}
@@ -1308,10 +1311,13 @@ struct v3_edit_controller_cpp : v3_funknown {
struct dpf_edit_controller : v3_edit_controller_cpp {
ScopedPointer<PluginVst3>& vst3;
bool initialized;
+ // cached values
+ v3_component_handler** handler;
dpf_edit_controller(ScopedPointer<PluginVst3>& v)
: vst3(v),
- initialized(false)
+ initialized(false),
+ handler(nullptr)
{
static const uint8_t* kSupportedInterfaces[] = {
v3_funknown_iid,
@@ -1547,27 +1553,12 @@ struct dpf_edit_controller : v3_edit_controller_cpp {
dpf_edit_controller* const controller = *(dpf_edit_controller**)self;
DISTRHO_SAFE_ASSERT_RETURN(controller != nullptr, V3_NOT_INITIALISED);
- PluginVst3* const vst3 = controller->vst3;
- DISTRHO_SAFE_ASSERT_RETURN(vst3 != nullptr, V3_NOT_INITIALISED);
+ controller->handler = handler;
-// v3_component_handler_cpp** const cpphandler = (v3_component_handler_cpp**)handler;
-//
-// controller->handler = cpphandler;
-//
-// if (controller->view != nullptr)
-// {
-// controller->view->handler = cpphandler;
-//
-// if (UIVst3* const uivst3 = controller->view->uivst3)
-// uivst3->setHandler(cpphandler);
-// }
-
- // offset struct by sizeof(v3_funknown), because of differences between C and C++
- v3_component_handler* const handlerptr
- = handler != nullptr ? (v3_component_handler*)((uint8_t*)*(handler)+sizeof(v3_funknown))
- : nullptr;
+ if (PluginVst3* const vst3 = controller->vst3)
+ return vst3->setComponentHandler(handler);
- return vst3->setComponentHandler(handlerptr, handler);
+ return V3_NOT_INITIALISED;
};
controller.create_view = []V3_API(void* self, const char* name) -> v3_plugin_view**
diff --git a/distrho/src/DistrhoUIVST3.cpp b/distrho/src/DistrhoUIVST3.cpp
@@ -21,16 +21,16 @@
// TESTING awful idea dont reuse
#include "../extra/Thread.hpp"
-// #if DISTRHO_PLUGIN_HAS_UI && ! DISTRHO_PLUGIN_HAS_EMBED_UI
-// # undef DISTRHO_PLUGIN_HAS_UI
-// # define DISTRHO_PLUGIN_HAS_UI 0
-// #endif
-//
-// #if DISTRHO_PLUGIN_HAS_UI && ! defined(HAVE_DGL) && ! DISTRHO_PLUGIN_HAS_EXTERNAL_UI
-// # undef DISTRHO_PLUGIN_HAS_UI
-// # define DISTRHO_PLUGIN_HAS_UI 0
-// #endif
-//
+#if DISTRHO_PLUGIN_HAS_UI && ! DISTRHO_PLUGIN_HAS_EMBED_UI
+# undef DISTRHO_PLUGIN_HAS_UI
+# define DISTRHO_PLUGIN_HAS_UI 0
+#endif
+
+#if DISTRHO_PLUGIN_HAS_UI && ! defined(HAVE_DGL) && ! DISTRHO_PLUGIN_HAS_EXTERNAL_UI
+# undef DISTRHO_PLUGIN_HAS_UI
+# define DISTRHO_PLUGIN_HAS_UI 0
+#endif
+
// #undef DISTRHO_PLUGIN_HAS_UI
// #define DISTRHO_PLUGIN_HAS_UI 1
@@ -38,93 +38,33 @@
# include "DistrhoUIInternal.hpp"
// #endif
-#include "travesty/audio_processor.h"
-#include "travesty/component.h"
#include "travesty/edit_controller.h"
-#include "travesty/factory.h"
#include "travesty/view.h"
-// --------------------------------------------------------------------------------------------------------------------
+/* TODO items:
+ * - see how to handle external non-embed UI build
+ * - program listener
+ * - state listener and sender
+ * - sample rate change listener
+ * - call component handler restart with params-changed flag when setting program
+ * - call component handler restart with latency-changed flag when latency changes
+ */
START_NAMESPACE_DISTRHO
// --------------------------------------------------------------------------------------------------------------------
#if ! DISTRHO_PLUGIN_WANT_MIDI_INPUT
-static const sendNoteFunc sendNoteCallback = nullptr;
+static constexpr const sendNoteFunc sendNoteCallback = nullptr;
#endif
#if ! DISTRHO_PLUGIN_WANT_STATE
-static const setStateFunc setStateCallback = nullptr;
+static constexpr const setStateFunc setStateCallback = nullptr;
#endif
// --------------------------------------------------------------------------------------------------------------------
-// custom v3_tuid compatible type
+// Utility functions (defined on plugin side)
-typedef uint32_t dpf_tuid[4];
-static_assert(sizeof(v3_tuid) == sizeof(dpf_tuid), "uid size mismatch");
-
-// --------------------------------------------------------------------------------------------------------------------
-// Utility functions
-
-const char* tuid2str(const v3_tuid iid)
-{
- if (v3_tuid_match(iid, v3_funknown_iid))
- return "{v3_funknown}";
- if (v3_tuid_match(iid, v3_plugin_base_iid))
- return "{v3_plugin_base}";
- if (v3_tuid_match(iid, v3_plugin_factory_iid))
- return "{v3_plugin_factory}";
- if (v3_tuid_match(iid, v3_plugin_factory_2_iid))
- return "{v3_plugin_factory_2}";
- if (v3_tuid_match(iid, v3_plugin_factory_3_iid))
- return "{v3_plugin_factory_3}";
- if (v3_tuid_match(iid, v3_component_iid))
- return "{v3_component}";
- if (v3_tuid_match(iid, v3_bstream_iid))
- return "{v3_bstream}";
- if (v3_tuid_match(iid, v3_event_list_iid))
- return "{v3_event_list}";
- if (v3_tuid_match(iid, v3_param_value_queue_iid))
- return "{v3_param_value_queue}";
- if (v3_tuid_match(iid, v3_param_changes_iid))
- return "{v3_param_changes}";
- if (v3_tuid_match(iid, v3_process_context_requirements_iid))
- return "{v3_process_context_requirements}";
- if (v3_tuid_match(iid, v3_audio_processor_iid))
- return "{v3_audio_processor}";
- if (v3_tuid_match(iid, v3_component_handler_iid))
- return "{v3_component_handler}";
- if (v3_tuid_match(iid, v3_edit_controller_iid))
- return "{v3_edit_controller}";
- if (v3_tuid_match(iid, v3_plugin_view_iid))
- return "{v3_plugin_view}";
- if (v3_tuid_match(iid, v3_plugin_frame_iid))
- return "{v3_plugin_frame}";
- if (v3_tuid_match(iid, v3_plugin_view_content_scale_steinberg_iid))
- return "{v3_plugin_view_content_scale_steinberg}";
- if (v3_tuid_match(iid, v3_plugin_view_parameter_finder_iid))
- return "{v3_plugin_view_parameter_finder}";
- /*
- if (std::memcmp(iid, dpf_tuid_class, sizeof(dpf_tuid)) == 0)
- return "{dpf_tuid_class}";
- if (std::memcmp(iid, dpf_tuid_component, sizeof(dpf_tuid)) == 0)
- return "{dpf_tuid_component}";
- if (std::memcmp(iid, dpf_tuid_controller, sizeof(dpf_tuid)) == 0)
- return "{dpf_tuid_controller}";
- if (std::memcmp(iid, dpf_tuid_processor, sizeof(dpf_tuid)) == 0)
- return "{dpf_tuid_processor}";
- if (std::memcmp(iid, dpf_tuid_view, sizeof(dpf_tuid)) == 0)
- return "{dpf_tuid_view}";
- */
-
- static char buf[46];
- std::snprintf(buf, sizeof(buf), "{0x%08X,0x%08X,0x%08X,0x%08X}",
- (uint32_t)d_cconst(iid[ 0], iid[ 1], iid[ 2], iid[ 3]),
- (uint32_t)d_cconst(iid[ 4], iid[ 5], iid[ 6], iid[ 7]),
- (uint32_t)d_cconst(iid[ 8], iid[ 9], iid[10], iid[11]),
- (uint32_t)d_cconst(iid[12], iid[13], iid[14], iid[15]));
- return buf;
-}
+const char* tuid2str(const v3_tuid iid);
// --------------------------------------------------------------------------------------------------------------------
@@ -145,7 +85,6 @@ public:
scaleFactor),
fView(view),
fFrame(nullptr),
- fFrameArg(nullptr),
fScaleFactor(scaleFactor)
{
// TESTING awful idea dont reuse
@@ -221,12 +160,9 @@ public:
#endif
}
- v3_result setFrame(v3_plugin_frame* const frame, void* const arg) noexcept
+ v3_result setFrame(v3_plugin_frame** const frame) noexcept
{
- d_stdout("setFrame %p %p", frame, arg);
fFrame = frame;
- fFrameArg = arg;
-
return V3_OK;
}
@@ -257,8 +193,7 @@ private:
// VST3 stuff
v3_plugin_view** const fView;
- v3_plugin_frame* fFrame;
- void* fFrameArg;
+ v3_plugin_frame** fFrame;
// v3_component_handler_cpp** handler = nullptr;
// Temporary data
@@ -304,8 +239,7 @@ private:
{
DISTRHO_SAFE_ASSERT_RETURN(fView != nullptr,);
DISTRHO_SAFE_ASSERT_RETURN(fFrame != nullptr,);
- DISTRHO_SAFE_ASSERT_RETURN(fFrameArg != nullptr,);
- d_stdout("from UI setSize %u %u | %p %p %p", width, height, fView, fFrame, fFrameArg);
+ d_stdout("from UI setSize %u %u | %p %p", width, height, fView, fFrame);
#ifdef DISTRHO_OS_MAC
const double scaleFactor = fUI.getScaleFactor();
@@ -317,7 +251,7 @@ private:
std::memset(&rect, 0, sizeof(rect));
rect.right = width;
rect.bottom = height;
- fFrame->resize_view(fFrameArg, fView, &rect);
+ v3_cpp_obj(fFrame)->resize_view(fFrame, fView, &rect);
}
static void setSizeCallback(void* ptr, uint width, uint height)
@@ -546,13 +480,7 @@ struct dpf_plugin_view : v3_plugin_view_cpp {
const float scaleFactor = view->scale != nullptr ? view->scale->scaleFactor : 0.0f;
view->uivst3 = new UIVst3((uintptr_t)parent, scaleFactor, view->sampleRate,
view->instancePointer, (v3_plugin_view**)self);
-
- // offset struct by sizeof(v3_funknown), because of differences between C and C++
- v3_plugin_frame* const frameptr
- = view->frame != nullptr ? (v3_plugin_frame*)((uint8_t*)*(view->frame)+sizeof(v3_funknown))
- : nullptr;
-
- view->uivst3->setFrame(frameptr, view->frame);
+ view->uivst3->setFrame(view->frame);
// view->uivst3->setHandler(view->handler);
return V3_OK;
}
@@ -613,11 +541,11 @@ struct dpf_plugin_view : v3_plugin_view_cpp {
dpf_plugin_view* const view = *(dpf_plugin_view**)self;
DISTRHO_SAFE_ASSERT_RETURN(view != nullptr, V3_NOT_INITIALISED);
- // special case: allow UI to not be attached yet, as a way to get size before window creation
-
if (UIVst3* const uivst3 = view->uivst3)
return uivst3->getSize(rect);
+ // special case: allow UI to not be attached yet, as a way to get size before window creation
+
const float scaleFactor = view->scale != nullptr ? view->scale->scaleFactor : 0.0f;
UIExporter tmpUI(nullptr, 0, view->sampleRate,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
@@ -660,14 +588,7 @@ struct dpf_plugin_view : v3_plugin_view_cpp {
view->frame = frame;
if (UIVst3* const uivst3 = view->uivst3)
- {
- // offset struct by sizeof(v3_funknown), because of differences between C and C++
- v3_plugin_frame* const frameptr
- = frame != nullptr ? (v3_plugin_frame*)((uint8_t*)*(frame)+sizeof(v3_funknown))
- : nullptr;
-
- return uivst3->setFrame(frameptr, frame);
- }
+ return uivst3->setFrame(frame);
return V3_NOT_INITIALISED;
};
@@ -697,7 +618,7 @@ struct dpf_plugin_view : v3_plugin_view_cpp {
};
// --------------------------------------------------------------------------------------------------------------------
-// dpf_plugin_view_create (called from DSP side)
+// dpf_plugin_view_create (called from plugin side)
v3_funknown** dpf_plugin_view_create(void* instancePointer, double sampleRate);
diff --git a/distrho/src/travesty/audio_processor.h b/distrho/src/travesty/audio_processor.h
@@ -28,8 +28,9 @@
typedef uint64_t v3_speaker_arrangement;
enum {
- V3_SPEAKER_L = 1,
- V3_SPEAKER_R = 1 << 1
+ V3_SPEAKER_L = 1 << 0,
+ V3_SPEAKER_R = 1 << 1,
+ V3_SPEAKER_M = 1 << 19
};
/**
@@ -42,14 +43,19 @@ enum v3_process_mode {
V3_OFFLINE
};
-inline static const char *
-v3_process_mode_str(int32_t d)
+static inline
+const char* v3_process_mode_str(int32_t d)
{
- switch (d) {
- case V3_REALTIME: return "V3_REALTIME";
- case V3_PREFETCH: return "V3_PREFETCH";
- case V3_OFFLINE: return "V3_OFFLINE";
- default: return "[unknown]";
+ switch (d)
+ {
+ case V3_REALTIME:
+ return "V3_REALTIME";
+ case V3_PREFETCH:
+ return "V3_PREFETCH";
+ case V3_OFFLINE:
+ return "V3_OFFLINE";
+ default:
+ return "[unknown]";
}
}
@@ -58,13 +64,17 @@ enum {
V3_SAMPLE_64
};
-inline static const char *
-v3_sample_size_str(int32_t d)
+static inline
+const char* v3_sample_size_str(int32_t d)
{
- switch (d) {
- case V3_SAMPLE_32: return "V3_SAMPLE_32";
- case V3_SAMPLE_64: return "V3_SAMPLE_64";
- default: return "[unknown]";
+ switch (d)
+ {
+ case V3_SAMPLE_32:
+ return "V3_SAMPLE_32";
+ case V3_SAMPLE_64:
+ return "V3_SAMPLE_64";
+ default:
+ return "[unknown]";
}
}
@@ -82,31 +92,24 @@ struct v3_process_setup {
struct v3_param_value_queue {
struct v3_funknown;
- V3_API v3_param_id (*get_param_id)(void *self);
- V3_API int32_t (*get_point_count)(void *self);
-
- V3_API v3_result (*get_point)
- (void *self, int32_t idx, int32_t *sample_offset, double *value);
- V3_API v3_result (*add_point)
- (void *self, int32_t sample_offset, double value, int32_t *idx);
+ V3_API v3_param_id (*get_param_id)(void* self);
+ V3_API int32_t (*get_point_count)(void* self);
+ V3_API v3_result (*get_point)(void* self, int32_t idx, int32_t* sample_offset, double* value);
+ V3_API v3_result (*add_point)(void* self, int32_t sample_offset, double value, int32_t* idx);
};
-static const v3_tuid v3_param_value_queue_iid =
+static constexpr const v3_tuid v3_param_value_queue_iid =
V3_ID(0x01263A18, 0xED074F6F, 0x98C9D356, 0x4686F9BA);
struct v3_param_changes {
struct v3_funknown;
- V3_API int32_t (*get_param_count)(void *self);
-
- V3_API struct v3_param_value_queue **(*get_param_data)
- (void *self, int32_t idx);
-
- V3_API struct v3_param_value_queue **(*add_param_data)
- (void *self, v3_param_id *id, int32_t *index);
+ V3_API int32_t (*get_param_count)(void* self);
+ V3_API struct v3_param_value_queue** (*get_param_data)(void* self, int32_t idx);
+ V3_API struct v3_param_value_queue** (*add_param_data)(void* self, v3_param_id* id, int32_t* index);
};
-static const v3_tuid v3_param_changes_iid =
+static constexpr const v3_tuid v3_param_changes_iid =
V3_ID(0xA4779663, 0x0BB64A56, 0xB44384A8, 0x466FEB9D);
/**
@@ -121,55 +124,41 @@ struct v3_frame_rate {
struct v3_chord {
uint8_t key_note;
uint8_t root_note;
-
int16_t chord_mask;
};
enum {
- V3_PROCESS_CTX_PLAYING = 1 << 1,
- V3_PROCESS_CTX_CYCLE_ACTIVE = 1 << 2,
- V3_PROCESS_CTX_RECORDING = 1 << 3,
-
+ V3_PROCESS_CTX_PLAYING = 1 << 1,
+ V3_PROCESS_CTX_CYCLE_ACTIVE = 1 << 2,
+ V3_PROCESS_CTX_RECORDING = 1 << 3,
V3_PROCESS_CTX_SYSTEM_TIME_VALID = 1 << 8,
- V3_PROCESS_CTX_CONT_TIME_VALID = 1 << 17,
V3_PROCESS_CTX_PROJECT_TIME_VALID = 1 << 9,
-
+ V3_PROCESS_CTX_TEMPO_VALID = 1 << 10,
V3_PROCESS_CTX_BAR_POSITION_VALID = 1 << 11,
V3_PROCESS_CTX_CYCLE_VALID = 1 << 12,
-
- V3_PROCESS_CTX_TEMPO_VALID = 1 << 10,
V3_PROCESS_CTX_TIME_SIG_VALID = 1 << 13,
- V3_PROCESS_CTX_CHORD_VALID = 1 << 18,
-
V3_PROCESS_CTX_SMPTE_VALID = 1 << 14,
-
- V3_PROCESS_CTX_NEXT_CLOCK_VALID = 1 << 15
+ V3_PROCESS_CTX_NEXT_CLOCK_VALID = 1 << 15,
+ V3_PROCESS_CTX_CONT_TIME_VALID = 1 << 17,
+ V3_PROCESS_CTX_CHORD_VALID = 1 << 18
};
struct v3_process_context {
uint32_t state;
-
double sample_rate;
int64_t project_time_in_samples; // with loop
-
int64_t system_time_ns;
int64_t continuous_time_in_samples; // without loop
-
double project_time_quarters;
double bar_position_quarters;
double cycle_start_quarters;
double cycle_end_quarters;
-
double bpm;
-
int32_t time_sig_numerator;
int32_t time_sig_denom;
-
struct v3_chord chord;
-
int32_t smpte_offset_subframes;
struct v3_frame_rate frame_rate;
-
int32_t samples_to_next_clock;
};
@@ -194,10 +183,10 @@ enum {
struct v3_process_context_requirements {
struct v3_funknown;
- V3_API uint32_t (*get_process_context_requirements)(void *self);
+ V3_API uint32_t (*get_process_context_requirements)(void* self);
};
-static const v3_tuid v3_process_context_requirements_iid =
+static constexpr const v3_tuid v3_process_context_requirements_iid =
V3_ID(0x2A654303, 0xEF764E3D, 0x95B5FE83, 0x730EF6D0);
/**
@@ -207,32 +196,25 @@ static const v3_tuid v3_process_context_requirements_iid =
struct v3_audio_bus_buffers {
int32_t num_channels;
uint64_t channel_silence_bitset;
-
union {
- float **channel_buffers_32;
- double **channel_buffers_64;
+ float** channel_buffers_32;
+ double** channel_buffers_64;
};
};
struct v3_process_data {
int32_t process_mode;
int32_t symbolic_sample_size;
-
int32_t nframes;
-
int32_t num_input_buses;
int32_t num_output_buses;
-
- struct v3_audio_bus_buffers *inputs;
- struct v3_audio_bus_buffers *outputs;
-
- struct v3_param_changes **input_params;
- struct v3_param_changes **output_params;
-
- struct v3_event_list **input_events;
- struct v3_event_list **output_events;
-
- struct v3_process_context *ctx;
+ struct v3_audio_bus_buffers* inputs;
+ struct v3_audio_bus_buffers* outputs;
+ struct v3_param_changes** input_params;
+ struct v3_param_changes** output_params;
+ struct v3_event_list** input_events;
+ struct v3_event_list** output_events;
+ struct v3_process_context* ctx;
};
/**
@@ -242,29 +224,18 @@ struct v3_process_data {
struct v3_audio_processor {
struct v3_funknown;
- V3_API v3_result (*set_bus_arrangements)
- (void *self, v3_speaker_arrangement *inputs, int32_t num_inputs,
- v3_speaker_arrangement *outputs, int32_t num_outputs);
- V3_API v3_result (*get_bus_arrangement)
- (void *self, int32_t bus_direction, int32_t idx, v3_speaker_arrangement *);
-
- V3_API v3_result (*can_process_sample_size)
- (void *self, int32_t symbolic_sample_size);
-
- V3_API uint32_t (*get_latency_samples)(void *self);
-
- V3_API v3_result (*setup_processing)
- (void *self, struct v3_process_setup *);
- V3_API v3_result (*set_processing)
- (void *self, v3_bool state);
-
- V3_API v3_result (*process)
- (void *self, struct v3_process_data *);
-
- V3_API uint32_t (*get_tail_samples)(void *self);
+ V3_API v3_result (*set_bus_arrangements)(void* self, v3_speaker_arrangement* inputs, int32_t num_inputs,
+ v3_speaker_arrangement* outputs, int32_t num_outputs);
+ V3_API v3_result (*get_bus_arrangement)(void* self, int32_t bus_direction, int32_t idx, v3_speaker_arrangement*);
+ V3_API v3_result (*can_process_sample_size)(void* self, int32_t symbolic_sample_size);
+ V3_API uint32_t (*get_latency_samples)(void* self);
+ V3_API v3_result (*setup_processing)(void* self, struct v3_process_setup* setup);
+ V3_API v3_result (*set_processing)(void* self, v3_bool state);
+ V3_API v3_result (*process)(void* self, struct v3_process_data* data);
+ V3_API uint32_t (*get_tail_samples)(void* self);
};
-static const v3_tuid v3_audio_processor_iid =
+static constexpr const v3_tuid v3_audio_processor_iid =
V3_ID(0x42043F99, 0xB7DA453C, 0xA569E79D, 0x9AAEC33D);
#include "align_pop.h"
diff --git a/distrho/src/travesty/base.h b/distrho/src/travesty/base.h
@@ -21,6 +21,23 @@
#include <string.h>
/**
+ * deal with C vs C++ differences
+ */
+
+#ifdef __cplusplus
+struct v3_funknown;
+template<class T> static inline
+constexpr T* v3_cpp_obj(T** obj)
+{
+ return (T*)((v3_funknown*)*obj + 1);
+}
+#else
+# ifndef constexpr
+# define constexpr
+# endif
+#endif
+
+/**
* various types
*/
@@ -31,15 +48,14 @@ typedef uint8_t v3_bool;
typedef uint32_t v3_param_id;
-
/**
* low-level ABI nonsense
*/
typedef uint8_t v3_tuid[16];
-inline static bool
-v3_tuid_match(const v3_tuid a, const v3_tuid b)
+static inline
+bool v3_tuid_match(const v3_tuid a, const v3_tuid b)
{
return memcmp(a, b, sizeof(v3_tuid)) == 0;
}
@@ -128,14 +144,12 @@ enum {
*/
struct v3_funknown {
- V3_API v3_result (*query_interface)
- (void *self, const v3_tuid iid, void **obj);
-
- V3_API uint32_t (*ref)(void *self);
- V3_API uint32_t (*unref)(void *self);
+ V3_API v3_result (*query_interface)(void* self, const v3_tuid iid, void** obj);
+ V3_API uint32_t (*ref)(void* self);
+ V3_API uint32_t (*unref)(void* self);
};
-static const v3_tuid v3_funknown_iid =
+static constexpr const v3_tuid v3_funknown_iid =
V3_ID(0x00000000, 0x00000000, 0xC0000000, 0x00000046);
/**
@@ -145,10 +159,9 @@ static const v3_tuid v3_funknown_iid =
struct v3_plugin_base {
struct v3_funknown;
- V3_API v3_result (*initialise)
- (void *self, struct v3_funknown *context);
- V3_API v3_result (*terminate)(void *self);
+ V3_API v3_result (*initialise)(void* self, struct v3_funknown* context);
+ V3_API v3_result (*terminate)(void* self);
};
-static const v3_tuid v3_plugin_base_iid =
+static constexpr const v3_tuid v3_plugin_base_iid =
V3_ID(0x22888DDB, 0x156E45AE, 0x8358B348, 0x08190625);
diff --git a/distrho/src/travesty/bstream.h b/distrho/src/travesty/bstream.h
@@ -27,15 +27,11 @@ enum v3_seek_mode {
struct v3_bstream {
struct v3_funknown;
- V3_API v3_result (*read)
- (void *self, void *buffer, int32_t num_bytes, int32_t *bytes_read);
- V3_API v3_result (*write)
- (void *self, void *buffer, int32_t num_bytes, int32_t *bytes_written);
- V3_API v3_result (*seek)
- (void *self, int64_t pos, int32_t seek_mode, int64_t *result);
- V3_API v3_result (*tell)
- (void *self, int64_t *pos);
+ V3_API v3_result (*read)(void* self, void* buffer, int32_t num_bytes, int32_t* bytes_read);
+ V3_API v3_result (*write)(void* self, void* buffer, int32_t num_bytes, int32_t* bytes_written);
+ V3_API v3_result (*seek)(void* self, int64_t pos, int32_t seek_mode, int64_t* result);
+ V3_API v3_result (*tell)(void* self, int64_t* pos);
};
-static const v3_tuid v3_bstream_iid =
+static constexpr const v3_tuid v3_bstream_iid =
V3_ID(0xC3BF6EA2, 0x30994752, 0x9B6BF990, 0x1EE33E9B);
diff --git a/distrho/src/travesty/component.h b/distrho/src/travesty/component.h
@@ -30,13 +30,17 @@ enum v3_media_types {
V3_EVENT
};
-inline static const char *
-v3_media_type_str(int32_t type)
+static inline
+const char* v3_media_type_str(int32_t type)
{
- switch (type) {
- case V3_AUDIO: return "V3_AUDIO";
- case V3_EVENT: return "V3_EVENT";
- default: return "[unknown]";
+ switch (type)
+ {
+ case V3_AUDIO:
+ return "V3_AUDIO";
+ case V3_EVENT:
+ return "V3_EVENT";
+ default:
+ return "[unknown]";
}
}
@@ -45,13 +49,17 @@ enum v3_bus_direction {
V3_OUTPUT
};
-inline static const char *
-v3_bus_direction_str(int32_t d)
+static inline
+const char* v3_bus_direction_str(int32_t d)
{
- switch (d) {
- case V3_INPUT: return "V3_INPUT";
- case V3_OUTPUT: return "V3_OUTPUT";
- default: return "[unknown]";
+ switch (d)
+ {
+ case V3_INPUT:
+ return "V3_INPUT";
+ case V3_OUTPUT:
+ return "V3_OUTPUT";
+ default:
+ return "[unknown]";
}
}
@@ -61,7 +69,7 @@ enum v3_bus_types {
};
enum v3_bus_flags {
- V3_DEFAULT_ACTIVE = 1,
+ V3_DEFAULT_ACTIVE = 1 << 0,
V3_IS_CONTROL_VOLTAGE = 1 << 1
};
@@ -69,7 +77,6 @@ struct v3_bus_info {
int32_t media_type;
int32_t direction;
int32_t channel_count;
-
v3_str_128 bus_name;
int32_t bus_type;
uint32_t flags;
@@ -84,34 +91,20 @@ struct v3_routing_info;
struct v3_component {
struct v3_plugin_base;
- V3_API v3_result (*get_controller_class_id)
- (void *self, v3_tuid class_id);
-
- V3_API v3_result (*set_io_mode)
- (void *self, int32_t io_mode);
-
- V3_API int32_t (*get_bus_count)
- (void *self, int32_t media_type, int32_t bus_direction);
- V3_API v3_result (*get_bus_info)
- (void *self, int32_t media_type, int32_t bus_direction,
- int32_t bus_idx, struct v3_bus_info *bus_info);
- V3_API v3_result (*get_routing_info)
- (void *self, struct v3_routing_info *input,
- struct v3_routing_info *output);
- V3_API v3_result (*activate_bus)
- (void *self, int32_t media_type, int32_t bus_direction,
- int32_t bus_idx, v3_bool state);
-
- V3_API v3_result (*set_active)
- (void *self, v3_bool state);
-
- V3_API v3_result (*set_state)
- (void *self, struct v3_bstream **);
- V3_API v3_result (*get_state)
- (void *self, struct v3_bstream **);
+ V3_API v3_result (*get_controller_class_id)(void* self, v3_tuid class_id);
+ V3_API v3_result (*set_io_mode)(void* self, int32_t io_mode);
+ V3_API int32_t (*get_bus_count)(void* self, int32_t media_type, int32_t bus_direction);
+ V3_API v3_result (*get_bus_info)(void* self, int32_t media_type, int32_t bus_direction,
+ int32_t bus_idx, struct v3_bus_info* bus_info);
+ V3_API v3_result (*get_routing_info)(void* self, struct v3_routing_info* input, struct v3_routing_info* output);
+ V3_API v3_result (*activate_bus)(void* self, int32_t media_type, int32_t bus_direction,
+ int32_t bus_idx, v3_bool state);
+ V3_API v3_result (*set_active)(void* self, v3_bool state);
+ V3_API v3_result (*set_state)(void* self, struct v3_bstream **);
+ V3_API v3_result (*get_state)(void* self, struct v3_bstream **);
};
-static const v3_tuid v3_component_iid =
+static constexpr const v3_tuid v3_component_iid =
V3_ID(0xE831FF31, 0xF2D54301, 0x928EBBEE, 0x25697802);
#include "align_pop.h"
diff --git a/distrho/src/travesty/edit_controller.h b/distrho/src/travesty/edit_controller.h
@@ -29,18 +29,13 @@
struct v3_component_handler {
struct v3_funknown;
- V3_API v3_result (*begin_edit)
- (void *self, v3_param_id);
- V3_API v3_result (*perform_edit)
- (void *self, v3_param_id, double value_normalised);
- V3_API v3_result (*end_edit)
- (void *self, v3_param_id);
-
- V3_API v3_result (*restart_component)
- (void *self, int32_t flags);
+ V3_API v3_result (*begin_edit)(void* self, v3_param_id);
+ V3_API v3_result (*perform_edit)(void* self, v3_param_id, double value_normalised);
+ V3_API v3_result (*end_edit)(void* self, v3_param_id);
+ V3_API v3_result (*restart_component)(void* self, int32_t flags);
};
-static const v3_tuid v3_component_handler_iid =
+static constexpr const v3_tuid v3_component_handler_iid =
V3_ID(0x93A0BEA3, 0x0BD045DB, 0x8E890B0C, 0xC1E46AC6);
/**
@@ -48,7 +43,7 @@ static const v3_tuid v3_component_handler_iid =
*/
enum {
- V3_PARAM_CAN_AUTOMATE = 1,
+ V3_PARAM_CAN_AUTOMATE = 1 << 0,
V3_PARAM_READ_ONLY = 1 << 1,
V3_PARAM_WRAP_AROUND = 1 << 2,
V3_PARAM_IS_LIST = 1 << 3,
@@ -59,15 +54,11 @@ enum {
struct v3_param_info {
v3_param_id param_id;
-
v3_str_128 title;
v3_str_128 short_title;
v3_str_128 units;
-
int32_t step_count;
-
double default_normalised_value;
-
int32_t unit_id;
int32_t flags;
};
@@ -75,39 +66,22 @@ struct v3_param_info {
struct v3_edit_controller {
struct v3_plugin_base;
- V3_API v3_result (*set_component_state)
- (void *self, struct v3_bstream *);
- V3_API v3_result (*set_state)
- (void *self, struct v3_bstream *);
- V3_API v3_result (*get_state)
- (void *self, struct v3_bstream *);
-
- V3_API int32_t (*get_parameter_count)(void *self);
- V3_API v3_result (*get_parameter_info)
- (void *self, int32_t param_idx, struct v3_param_info *);
-
- V3_API v3_result (*get_parameter_string_for_value)
- (void *self, v3_param_id, double normalised, v3_str_128 output);
- V3_API v3_result (*get_parameter_value_for_string)
- (void *self, v3_param_id, int16_t *input, double *output);
-
- V3_API double (*normalised_parameter_to_plain)
- (void *self, v3_param_id, double normalised);
- V3_API double (*plain_parameter_to_normalised)
- (void *self, v3_param_id, double plain);
-
- V3_API double (*get_parameter_normalised)(void *self, v3_param_id);
- V3_API v3_result (*set_parameter_normalised)
- (void *self, v3_param_id, double normalised);
-
- V3_API v3_result (*set_component_handler)
- (void *self, struct v3_component_handler **);
-
- V3_API struct v3_plugin_view **(*create_view)
- (void *self, const char *name);
+ V3_API v3_result (*set_component_state)(void* self, struct v3_bstream*);
+ V3_API v3_result (*set_state)(void* self, struct v3_bstream*);
+ V3_API v3_result (*get_state)(void* self, struct v3_bstream*);
+ V3_API int32_t (*get_parameter_count)(void* self);
+ V3_API v3_result (*get_parameter_info)(void* self, int32_t param_idx, struct v3_param_info*);
+ V3_API v3_result (*get_parameter_string_for_value)(void* self, v3_param_id, double normalised, v3_str_128 output);
+ V3_API v3_result (*get_parameter_value_for_string)(void* self, v3_param_id, int16_t* input, double* output);
+ V3_API double (*normalised_parameter_to_plain)(void* self, v3_param_id, double normalised);
+ V3_API double (*plain_parameter_to_normalised)(void* self, v3_param_id, double plain);
+ V3_API double (*get_parameter_normalised)(void* self, v3_param_id);
+ V3_API v3_result (*set_parameter_normalised)(void* self, v3_param_id, double normalised);
+ V3_API v3_result (*set_component_handler)(void* self, struct v3_component_handler**);
+ V3_API struct v3_plugin_view **(*create_view)(void* self, const char* name);
};
-static const v3_tuid v3_edit_controller_iid =
+static constexpr const v3_tuid v3_edit_controller_iid =
V3_ID(0xDCD7BBE3, 0x7742448D, 0xA874AACC, 0x979C759E);
#include "align_pop.h"
diff --git a/distrho/src/travesty/events.h b/distrho/src/travesty/events.h
@@ -30,10 +30,8 @@
struct v3_event_note_on {
int16_t channel;
int16_t pitch; // MIDI note number
-
float tuning;
float velocity;
-
int32_t length;
int32_t note_id;
};
@@ -41,9 +39,7 @@ struct v3_event_note_on {
struct v3_event_note_off {
int16_t channel;
int16_t pitch; // MIDI note number
-
float velocity;
-
int32_t note_id;
float tuning;
};
@@ -51,14 +47,12 @@ struct v3_event_note_off {
struct v3_event_data {
uint32_t size;
uint32_t type;
-
- const uint8_t *bytes;
+ const uint8_t* bytes;
};
struct v3_event_poly_pressure {
int16_t channel;
int16_t pitch;
-
float pressure;
int32_t note_id;
};
@@ -67,7 +61,6 @@ struct v3_event_chord {
int16_t root;
int16_t bass_note;
int16_t mask;
-
uint16_t text_len;
const int16_t *text;
};
@@ -75,14 +68,12 @@ struct v3_event_chord {
struct v3_event_scale {
int16_t root;
int16_t mask;
-
uint16_t text_len;
const int16_t *text;
};
struct v3_event_legacy_midi_cc_out {
uint8_t cc_number;
-
int8_t channel;
int8_t value;
int8_t value2;
@@ -96,7 +87,6 @@ struct v3_event_note_expression_value {
struct v3_event_note_expression_text {
int32_t note_id;
-
uint32_t text_len;
const int16_t *text;
};
@@ -106,7 +96,7 @@ struct v3_event_note_expression_text {
*/
enum v3_event_flags {
- V3_EVENT_IS_LIVE = 1
+ V3_EVENT_IS_LIVE = 1 << 0
};
enum v3_event_type {
@@ -118,19 +108,15 @@ enum v3_event_type {
V3_EVENT_NOTE_EXP_TEXT = 5,
V3_EVENT_CHORD = 6,
V3_EVENT_SCALE = 7,
-
V3_EVENT_LEGACY_MIDI_CC_OUT = 65535
};
struct v3_event {
int32_t bus_index;
int32_t sample_offset;
-
double ppq_position;
uint16_t flags;
-
uint16_t type;
-
union {
struct v3_event_note_on note_on;
struct v3_event_note_off note_off;
@@ -151,14 +137,12 @@ struct v3_event {
struct v3_event_list {
struct v3_funknown;
- V3_API uint32_t (*get_event_count)(void *self);
- V3_API v3_result (*get_event)
- (void *self, int32_t idx, struct v3_event *);
- V3_API v3_result (*add_event)
- (void *self, struct v3_event *);
+ V3_API uint32_t (*get_event_count)(void* self);
+ V3_API v3_result (*get_event)(void* self, int32_t idx, struct v3_event* event);
+ V3_API v3_result (*add_event)(void* self, struct v3_event* event);
};
-static const v3_tuid v3_event_list_iid =
+static constexpr const v3_tuid v3_event_list_iid =
V3_ID(0x3A2C4214, 0x346349FE, 0xB2C4F397, 0xB9695A44);
#include "align_pop.h"
diff --git a/distrho/src/travesty/factory.h b/distrho/src/travesty/factory.h
@@ -39,19 +39,13 @@ struct v3_class_info {
struct v3_plugin_factory {
struct v3_funknown;
- V3_API v3_result (*get_factory_info)
- (void *self, struct v3_factory_info *);
-
- V3_API int32_t (*num_classes)(void *self);
-
- V3_API v3_result (*get_class_info)
- (void *self, int32_t idx, struct v3_class_info *);
-
- V3_API v3_result (*create_instance)
- (void *self, const v3_tuid class_id, const v3_tuid iid, void **instance);
+ V3_API v3_result (*get_factory_info)(void* self, struct v3_factory_info*);
+ V3_API int32_t (*num_classes)(void* self);
+ V3_API v3_result (*get_class_info)(void* self, int32_t idx, struct v3_class_info*);
+ V3_API v3_result (*create_instance)(void* self, const v3_tuid class_id, const v3_tuid iid, void** instance);
};
-static const v3_tuid v3_plugin_factory_iid =
+static constexpr const v3_tuid v3_plugin_factory_iid =
V3_ID(0x7A4D811C, 0x52114A1F, 0xAED9D2EE, 0x0B43BF9F);
/**
@@ -63,7 +57,6 @@ struct v3_class_info_2 {
int32_t cardinality; // set to 0x7FFFFFFF
char category[32];
char name[64];
-
uint32_t class_flags;
char sub_categories[128];
char vendor[64];
@@ -74,11 +67,10 @@ struct v3_class_info_2 {
struct v3_plugin_factory_2 {
struct v3_plugin_factory;
- V3_API v3_result (*get_class_info_2)
- (void *self, int32_t idx, struct v3_class_info_2 *);
+ V3_API v3_result (*get_class_info_2)(void* self, int32_t idx, struct v3_class_info_2*);
};
-static const v3_tuid v3_plugin_factory_2_iid =
+static constexpr const v3_tuid v3_plugin_factory_2_iid =
V3_ID(0x0007B650, 0xF24B4C0B, 0xA464EDB9, 0xF00B2ABB);
/**
@@ -93,7 +85,6 @@ struct v3_class_info_3 {
int32_t cardinality; // set to 0x7FFFFFFF
char category[32];
int16_t name[64];
-
uint32_t class_flags;
char sub_categories[128];
int16_t vendor[64];
@@ -104,12 +95,9 @@ struct v3_class_info_3 {
struct v3_plugin_factory_3 {
struct v3_plugin_factory_2;
- V3_API v3_result (*get_class_info_utf16)
- (void *self, int32_t idx, struct v3_class_info_3 *);
-
- V3_API v3_result (*set_host_context)
- (void *self, struct v3_funknown *host);
+ V3_API v3_result (*get_class_info_utf16)(void* self, int32_t idx, struct v3_class_info_3*);
+ V3_API v3_result (*set_host_context)(void* self, struct v3_funknown* host);
};
-static const v3_tuid v3_plugin_factory_3_iid =
+static constexpr const v3_tuid v3_plugin_factory_3_iid =
V3_ID(0x4555A2AB, 0xC1234E57, 0x9B122910, 0x36878931);
diff --git a/distrho/src/travesty/view.h b/distrho/src/travesty/view.h
@@ -19,7 +19,7 @@
#include "base.h"
/**
- * base IPlugFrame stuff
+ * base view stuff
*/
struct v3_view_rect {
@@ -41,50 +41,43 @@ struct v3_view_rect {
# define V3_VIEW_PLATFORM_TYPE_NATIVE V3_VIEW_PLATFORM_TYPE_X11
#endif
+/**
+ * plugin view
+ */
+
struct v3_plugin_frame;
struct v3_plugin_view {
struct v3_funknown;
- V3_API v3_result (*is_platform_type_supported)
- (void *self, const char *platform_type);
-
- V3_API v3_result (*attached)
- (void *self, void *parent, const char *platform_type);
- V3_API v3_result (*removed)(void *self);
-
- V3_API v3_result (*on_wheel)(void *self, float distance);
- V3_API v3_result (*on_key_down)
- (void *self, int16_t key_char, int16_t key_code, int16_t modifiers);
- V3_API v3_result (*on_key_up)
- (void *self, int16_t key_char, int16_t key_code, int16_t modifiers);
-
- V3_API v3_result (*get_size)
- (void *self, struct v3_view_rect *);
- V3_API v3_result (*on_size)
- (void *self, struct v3_view_rect *);
-
- V3_API v3_result (*on_focus)
- (void *self, v3_bool state);
-
- V3_API v3_result (*set_frame)
- (void *self, struct v3_plugin_frame **);
- V3_API v3_result (*can_resize)(void *self);
- V3_API v3_result (*check_size_constraint)
- (void *self, struct v3_view_rect *);
+ V3_API v3_result (*is_platform_type_supported)(void* self, const char* platform_type);
+ V3_API v3_result (*attached)(void* self, void* parent, const char* platform_type);
+ V3_API v3_result (*removed)(void* self);
+ V3_API v3_result (*on_wheel)(void* self, float distance);
+ V3_API v3_result (*on_key_down)(void* self, int16_t key_char, int16_t key_code, int16_t modifiers);
+ V3_API v3_result (*on_key_up)(void* self, int16_t key_char, int16_t key_code, int16_t modifiers);
+ V3_API v3_result (*get_size)(void* self, struct v3_view_rect*);
+ V3_API v3_result (*on_size)(void* self, struct v3_view_rect*);
+ V3_API v3_result (*on_focus)(void* self, v3_bool state);
+ V3_API v3_result (*set_frame)(void* self, struct v3_plugin_frame**);
+ V3_API v3_result (*can_resize)(void* self);
+ V3_API v3_result (*check_size_constraint)(void* self, struct v3_view_rect*);
};
-static const v3_tuid v3_plugin_view_iid =
+static constexpr const v3_tuid v3_plugin_view_iid =
V3_ID(0x5BC32507, 0xD06049EA, 0xA6151B52, 0x2B755B29);
+/**
+ * plugin frame
+ */
+
struct v3_plugin_frame {
struct v3_funknown;
- V3_API v3_result (*resize_view)
- (void *self, struct v3_plugin_view **, struct v3_view_rect *);
+ V3_API v3_result (*resize_view)(void* self, struct v3_plugin_view**, struct v3_view_rect*);
};
-static const v3_tuid v3_plugin_frame_iid =
+static constexpr const v3_tuid v3_plugin_frame_iid =
V3_ID(0x367FAF01, 0xAFA94693, 0x8D4DA2A0, 0xED0882A3);
/**
@@ -95,11 +88,10 @@ static const v3_tuid v3_plugin_frame_iid =
struct v3_plugin_view_content_scale_steinberg {
struct v3_funknown;
- V3_API v3_result (*set_content_scale_factor)
- (void *self, float factor);
+ V3_API v3_result (*set_content_scale_factor)(void* self, float factor);
};
-static const v3_tuid v3_plugin_view_content_scale_steinberg_iid =
+static constexpr const v3_tuid v3_plugin_view_content_scale_steinberg_iid =
V3_ID(0x65ED9690, 0x8AC44525, 0x8AADEF7A, 0x72EA703F);
/**
@@ -109,9 +101,8 @@ static const v3_tuid v3_plugin_view_content_scale_steinberg_iid =
struct v3_plugin_view_parameter_finder {
struct v3_funknown;
- V3_API v3_result (*find_parameter)
- (void *self, int32_t x, int32_t y, v3_param_id *);
+ V3_API v3_result (*find_parameter)(void* self, int32_t x, int32_t y, v3_param_id *);
};
-static const v3_tuid v3_plugin_view_parameter_finder_iid =
+static constexpr const v3_tuid v3_plugin_view_parameter_finder_iid =
V3_ID(0x0F618302, 0x215D4587, 0xA512073C, 0x77B9D383);