Replace string port/message context using persist extension.

(cherry picked from commit b8e69ceb2ff7aca549efd939d04447e2f08ad5a8)
This commit is contained in:
Krzysztof Foltman
2010-09-21 00:07:46 +01:00
committed by Tobias Doerffel
parent f40e2c85bc
commit 9179bf41ee
7 changed files with 48 additions and 138 deletions

View File

@@ -28,8 +28,6 @@
#include <string>
#include <vector>
// #define USE_PERSIST_EXTENSION 1
namespace osctl {
struct osc_client;
}
@@ -49,7 +47,6 @@ enum parameter_flags
PF_BOOL = 0x0002, ///< bool value (usually >=0.5f is treated as TRUE, which is inconsistent with LV2 etc. which treats anything >0 as TRUE)
PF_ENUM = 0x0003, ///< enum value (min, min+1, ..., max, only guaranteed to work when min = 0)
PF_ENUM_MULTI = 0x0004, ///< SET / multiple-choice
PF_STRING = 0x0005, ///< see: http://lv2plug.in/docs/index.php?title=String_port
PF_SCALEMASK = 0xF0, ///< bit mask for scale
PF_SCALE_DEFAULT = 0x00, ///< no scale given
@@ -84,7 +81,6 @@ enum parameter_flags
PF_PROP_OUTPUT = 0x080000, ///< output port
PF_PROP_OPTIONAL = 0x100000, ///< connection optional
PF_PROP_GRAPH = 0x200000, ///< add graph
PF_PROP_MSGCONTEXT= 0x400000, ///< message context
PF_UNITMASK = 0xFF000000, ///< bit mask for units \todo reduce to use only 5 bits
PF_UNIT_DB = 0x01000000, ///< decibels
@@ -301,8 +297,6 @@ struct plugin_metadata_iface
virtual const char *get_label() const = 0;
/// @return total number of parameters
virtual int get_param_count() const = 0;
/// @return total number of parameters that aren't configure variables
virtual int get_nonstring_param_count() const = 0;
/// Return custom XML
virtual const char *get_gui_xml() const = 0;
/// @return number of audio inputs
@@ -335,12 +329,10 @@ struct plugin_metadata_iface
virtual bool is_cv(int param_no) const = 0;
/// is the given parameter non-interpolated?
virtual bool is_noisy(int param_no) const = 0;
/// does the plugin require message context? (or DSSI configure) may be slow
virtual bool requires_message_context() const = 0;
/// does the plugin require string port extension? (or DSSI configure) may be slow
virtual bool requires_string_ports() const = 0;
/// add all message context parameter numbers to the ports vector
virtual void get_message_context_parameters(std::vector<int> &ports) const = 0;
virtual bool requires_configure() const = 0;
/// obtain array of names of configure variables (or NULL is none needed)
virtual const char *const *get_configure_vars() const { return NULL; }
/// Do-nothing destructor to silence compiler warning
virtual ~plugin_metadata_iface() {}
@@ -431,7 +423,7 @@ struct audio_module_iface
virtual void set_sample_rate(uint32_t sr) = 0;
/// Execute menu command with given number
virtual void execute(int cmd_no) = 0;
/// DSSI configure call
/// DSSI configure call, value = NULL = reset to default
virtual char *configure(const char *key, const char *value) = 0;
/// Send all understood configure vars (none by default)
virtual void send_configures(send_configure_iface *sci) = 0;
@@ -556,9 +548,6 @@ public:
virtual const line_graph_iface *get_line_graph_iface() const { return dynamic_cast<const line_graph_iface *>(this); }
};
extern bool check_for_message_context_ports(const parameter_properties *parameters, int count);
extern bool check_for_string_ports(const parameter_properties *parameters, int count);
#if USE_EXEC_GUI || USE_DSSI
enum line_graph_item
@@ -629,20 +618,7 @@ public:
bool is_cv(int param_no) const { return true; }
bool is_noisy(int param_no) const { return false; }
const ladspa_plugin_info &get_plugin_info() const { return plugin_info; }
bool requires_message_context() const { return check_for_message_context_ports(param_props, Metadata::param_count); }
bool requires_string_ports() const { return check_for_string_ports(param_props, Metadata::param_count); }
void get_message_context_parameters(std::vector<int> &ports) const {
for (int i = 0; i < get_param_count(); ++i) {
if (get_param_props(i)->flags & PF_PROP_MSGCONTEXT)
ports.push_back(i);
}
}
int get_nonstring_param_count() const {
int i = Metadata::param_count;
while(i > 0 && (param_props[i - 1].flags & PF_TYPEMASK) == PF_STRING)
i--;
return i;
}
bool requires_configure() const { return false; }
};
#define CALF_PORT_NAMES(name) template<> const char *::plugin_metadata<name##_metadata>::port_names[]

View File

@@ -88,7 +88,7 @@ struct ladspa_plugin_metadata_set
std::vector<DSSI_Program_Descriptor> *preset_descs;
#endif
int input_count, output_count, param_count, real_param_count;
int input_count, output_count, param_count;
const plugin_metadata_iface *metadata;
ladspa_plugin_metadata_set();

View File

@@ -28,11 +28,9 @@
#include <lv2.h>
#include <calf/giface.h>
#include <calf/lv2-midiport.h>
#include <calf/lv2_contexts.h>
#include <calf/lv2_event.h>
#include <calf/lv2_persist.h>
#include <calf/lv2_progress.h>
#include <calf/lv2_string_port.h>
#include <calf/lv2_uri_map.h>
#include <string.h>
@@ -49,7 +47,6 @@ struct lv2_instance: public plugin_ctl_iface, public progress_report_iface
LV2_URI_Map_Feature *uri_map;
LV2_Event_Feature *event_feature;
uint32_t midi_event_type;
std::vector<int> message_params;
LV2_Progress *progress_report_feature;
float **ins, **outs, **params;
int out_count;
@@ -59,13 +56,8 @@ struct lv2_instance: public plugin_ctl_iface, public progress_report_iface
module = _module;
module->get_port_arrays(ins, outs, params);
metadata = module->get_metadata_iface();
metadata->get_message_context_parameters(message_params);
out_count = metadata->get_output_count();
#if USE_PERSIST_EXTENSION
real_param_count = metadata->get_nonstring_param_count();
#else
real_param_count = metadata->get_param_count();
#endif
uri_map = NULL;
midi_data = NULL;
@@ -75,7 +67,6 @@ struct lv2_instance: public plugin_ctl_iface, public progress_report_iface
srate_to_set = 44100;
set_srate = true;
// printf("message params %d\n", (int)message_params.size());
}
/// This, and not Module::post_instantiate, is actually called by lv2_wrapper class
void post_instantiate()
@@ -98,43 +89,24 @@ struct lv2_instance: public plugin_ctl_iface, public progress_report_iface
void send_configures(send_configure_iface *sci) {
module->send_configures(sci);
}
uint32_t impl_message_run(const void *valid_inputs, void *output_ports) {
uint8_t *vi = (uint8_t *)valid_inputs;
int ofs = metadata->get_param_port_offset();
for (unsigned int i = 0; i < message_params.size(); i++)
{
int pn = message_params[i];
const parameter_properties &pp = *metadata->get_param_props(pn);
int ppn = pn + ofs;
if ((pp.flags & PF_TYPEMASK) == PF_STRING && (vi[ppn >> 3] & (1 << (ppn & 7)))
&& (((LV2_String_Data *)params[pn])->flags & LV2_STRING_DATA_CHANGED_FLAG)) {
// printf("Calling configure on %s\n", pp.short_name);
configure(pp.short_name, ((LV2_String_Data *)params[pn])->data);
}
}
return module->message_run(valid_inputs, output_ports);
}
#if USE_PERSIST_EXTENSION
void impl_restore(LV2_Persist_Retrieve_Function retrieve, void *callback_data)
{
for (unsigned int i = 0; i < message_params.size(); i++)
const char *const *vars = module->get_metadata_iface()->get_configure_vars();
if (!vars)
return;
for (unsigned int i = 0; vars[i]; i++)
{
int pn = message_params[i];
const parameter_properties &pp = *metadata->get_param_props(pn);
if ((pp.flags & PF_TYPEMASK) == PF_STRING) {
size_t len = 0;
const void *ptr = (*retrieve)(callback_data, pp.short_name, &len);
if (ptr)
{
printf("Calling configure on %s\n", pp.short_name);
configure(pp.short_name, std::string((const char *)ptr, len).c_str());
}
else
configure(pp.short_name, pp.choices[0]);
size_t len = 0;
const void *ptr = (*retrieve)(callback_data, vars[i], &len);
if (ptr)
{
printf("Calling configure on %s\n", vars[i]);
configure(vars[i], std::string((const char *)ptr, len).c_str());
}
else
configure(vars[i], NULL);
}
}
#endif
char *configure(const char *key, const char *value) {
// disambiguation - the plugin_ctl_iface version is just a stub, so don't use it
return module->configure(key, value);
@@ -204,7 +176,6 @@ struct lv2_wrapper
typedef lv2_instance instance;
static LV2_Descriptor descriptor;
static LV2_Calf_Descriptor calf_descriptor;
static LV2MessageContext message_context;
static LV2_Persist persist;
std::string uri;
@@ -220,13 +191,9 @@ struct lv2_wrapper
descriptor.deactivate = cb_deactivate;
descriptor.cleanup = cb_cleanup;
descriptor.extension_data = cb_ext_data;
#if USE_PERSIST_EXTENSION
persist.save = cb_persist_save;
persist.restore = cb_persist_restore;
#endif
calf_descriptor.get_pci = cb_get_pci;
message_context.message_connect_port = cb_connect;
message_context.message_run = cb_message_run;
}
static void cb_connect(LV2_Handle Instance, uint32_t port, void *DataLocation)
@@ -235,11 +202,7 @@ struct lv2_wrapper
const plugin_metadata_iface *md = mod->metadata;
unsigned long ins = md->get_input_count();
unsigned long outs = md->get_output_count();
#if USE_PERSIST_EXTENSION
unsigned long params = md->get_nonstring_param_count();
#else
unsigned long params = md->get_param_count();
#endif
if (port < ins)
mod->ins[port] = (float *)DataLocation;
else if (port < ins + outs)
@@ -299,11 +262,6 @@ struct lv2_wrapper
return static_cast<plugin_ctl_iface *>(Instance);
}
static uint32_t cb_message_run(LV2_Handle Instance, const void *valid_inputs, void *outputs_written)
{
instance *mod = (instance *)Instance;
return mod->impl_message_run(valid_inputs, outputs_written);
}
static void cb_run(LV2_Handle Instance, uint32_t SampleCount)
{
instance *const inst = (instance *)Instance;
@@ -330,15 +288,10 @@ struct lv2_wrapper
{
if (!strcmp(URI, "http://foltman.com/ns/calf-plugin-instance"))
return &calf_descriptor;
if (!strcmp(URI, LV2_CONTEXT_MESSAGE))
return &message_context;
#if USE_PERSIST_EXTENSION
if (!strcmp(URI, LV2_PERSIST_URI))
return &persist;
#endif
return NULL;
}
#if USE_PERSIST_EXTENSION
static void cb_persist_save(LV2_Handle Instance, LV2_Persist_Store_Function store, void *callback_data)
{
instance *const inst = (instance *)Instance;
@@ -362,7 +315,6 @@ struct lv2_wrapper
instance *const inst = (instance *)Instance;
inst->impl_restore(retrieve, callback_data);
}
#endif
static lv2_wrapper &get() {
static lv2_wrapper *instance = new lv2_wrapper;

View File

@@ -403,7 +403,10 @@ struct organ_metadata: public organ_enums, public plugin_metadata<organ_metadata
{
enum { in_count = 0, out_count = 2, ins_optional = 0, outs_optional = 0, support_midi = true, require_midi = true, rt_capable = true };
PLUGIN_NAME_ID_LABEL("organ", "organ", "Organ")
public:
plugin_command_info *get_commands();
const char *const *get_configure_vars() const;
};
/// FluidSynth - metadata
@@ -412,6 +415,9 @@ struct fluidsynth_metadata: public plugin_metadata<fluidsynth_metadata>
enum { par_master, par_interpolation, par_reverb, par_chorus, par_soundfont, par_preset_key_set, param_count };
enum { in_count = 0, out_count = 2, ins_optional = 0, outs_optional = 0, support_midi = true, require_midi = true, rt_capable = false };
PLUGIN_NAME_ID_LABEL("fluidsynth", "fluidsynth", "Fluidsynth")
public:
const char *const *get_configure_vars() const;
};
/// Wavetable - metadata

View File

@@ -150,8 +150,6 @@ std::string parameter_properties::to_string(float value) const
}
switch(flags & PF_TYPEMASK)
{
case PF_STRING:
return "N/A";
case PF_INT:
case PF_BOOL:
case PF_ENUM:
@@ -190,16 +188,14 @@ std::string parameter_properties::to_string(float value) const
void calf_plugins::plugin_ctl_iface::clear_preset() {
int param_count = get_metadata_iface()->get_param_count();
for (int i=0; i < param_count; i++)
for (int i = 0; i < param_count; i++)
{
const parameter_properties &pp = *get_metadata_iface()->get_param_props(i);
if ((pp.flags & PF_TYPEMASK) == PF_STRING)
{
configure(pp.short_name, pp.choices ? pp.choices[0] : "");
}
else
set_param_value(i, pp.def_value);
set_param_value(i, pp.def_value);
}
const char *const *vars = get_metadata_iface()->get_configure_vars();
for (int i = 0; vars[i]; i++)
configure(vars[i], NULL);
}
const char *calf_plugins::load_gui_xml(const std::string &plugin_id)
@@ -209,32 +205,10 @@ const char *calf_plugins::load_gui_xml(const std::string &plugin_id)
return strdup(calf_utils::load_file((std::string(PKGLIBDIR) + "/gui-" + plugin_id + ".xml").c_str()).c_str());
}
catch(file_exception e)
#endif
{
return NULL;
}
}
bool calf_plugins::check_for_message_context_ports(const parameter_properties *parameters, int count)
{
for (int i = count - 1; i >= 0; i--)
{
if (parameters[i].flags & PF_PROP_MSGCONTEXT)
return true;
}
return false;
}
bool calf_plugins::check_for_string_ports(const parameter_properties *parameters, int count)
{
for (int i = count - 1; i >= 0; i--)
{
if ((parameters[i].flags & PF_TYPEMASK) == PF_STRING)
return true;
if ((parameters[i].flags & PF_TYPEMASK) < PF_STRING)
return false;
}
return false;
#endif
}
bool calf_plugins::get_freq_gridline(int subindex, float &pos, bool &vertical, std::string &legend, cairo_iface *context, bool use_frequencies)

View File

@@ -950,10 +950,14 @@ CALF_PORT_PROPS(organ) = {
{ 1, 0.1, 10, 0, PF_FLOAT | PF_SCALE_GAIN | PF_CTL_KNOB | PF_UNIT_COEF | PF_PROP_NOBOUNDS, NULL, "bass_gain", "Bass Gain" },
{ 12000, 20, 20000, 0, PF_FLOAT | PF_SCALE_LOG | PF_CTL_KNOB | PF_UNIT_HZ, NULL, "treble_freq", "Treble Freq" },
{ 1, 0.1, 10, 0, PF_FLOAT | PF_SCALE_GAIN | PF_CTL_KNOB | PF_UNIT_COEF | PF_PROP_NOBOUNDS, NULL, "treble_gain", "Treble Gain" },
{ 0, 0, 0, 0, PF_STRING | PF_PROP_MSGCONTEXT, &organ_init_map_curve, "map_curve", "Key mapping curve" },
};
const char *const *organ_metadata::get_configure_vars() const
{
static const char *names[] = {"map_curve", NULL};
return names;
}
////////////////////////////////////////////////////////////////////////////
const char *fluidsynth_init_soundfont = "";
@@ -972,10 +976,14 @@ CALF_PORT_PROPS(fluidsynth) = {
{ 2, 0, 3, 0, PF_ENUM | PF_CTL_COMBO, fluidsynth_interpolation_names, "interpolation", "Interpolation" },
{ 1, 0, 1, 0, PF_BOOL | PF_CTL_TOGGLE, NULL, "reverb", "Reverb" },
{ 1, 0, 1, 0, PF_BOOL | PF_CTL_TOGGLE, NULL, "chorus", "Chorus" },
{ 0, 0, 0, 0, PF_STRING | PF_PROP_MSGCONTEXT, &fluidsynth_init_soundfont, "soundfont", "Soundfont" },
{ 0, 0, 0, 0, PF_STRING | PF_PROP_MSGCONTEXT, &fluidsynth_init_presetkeyset, "preset_key_set", "Set Preset" },
};
const char *const *fluidsynth_metadata::get_configure_vars() const
{
static const char *names[] = {"soundfont", "preset_key_set", NULL};
return names;
}
////////////////////////////////////////////////////////////////////////////
const char *wavetable_names[] = {

View File

@@ -58,7 +58,7 @@ ladspa_instance::ladspa_instance(audio_module_iface *_module, ladspa_plugin_meta
float ladspa_instance::get_param_value(int param_no)
{
// XXXKF hack
if (param_no >= ladspa->real_param_count)
if (param_no >= ladspa->param_count)
return 0;
return *params[param_no];
}
@@ -66,7 +66,7 @@ float ladspa_instance::get_param_value(int param_no)
void ladspa_instance::set_param_value(int param_no, float value)
{
// XXXKF hack
if (param_no >= ladspa->real_param_count)
if (param_no >= ladspa->param_count)
return;
*params[param_no] = value;
}
@@ -231,7 +231,7 @@ static void cb_connect(LADSPA_Handle Instance, unsigned long port, LADSPA_Data *
int first_out = mod->ladspa->input_count;
int first_param = first_out + mod->ladspa->output_count;
int ladspa_port_count = first_param + mod->ladspa->real_param_count;
int ladspa_port_count = first_param + mod->ladspa->param_count;
if ((int)port < first_out)
mod->ins[port] = DataLocation;
@@ -292,7 +292,7 @@ static void cb_select_program(LADSPA_Handle Instance, unsigned long Bank, unsign
unsigned int no = (Bank << 7) + Program - 1;
// printf("no = %d presets = %p:%d\n", no, presets, presets->size());
if (no == -1U) {
int rpc = ladspa->real_param_count;
int rpc = ladspa->param_count;
for (int i =0 ; i < rpc; i++)
*mod->params[i] = mod->metadata->get_param_props(i)->def_value;
return;
@@ -328,9 +328,6 @@ void ladspa_plugin_metadata_set::prepare(const plugin_metadata_iface *md, LADSPA
input_count = md->get_input_count();
output_count = md->get_output_count();
param_count = md->get_param_count(); // XXXKF ladspa_instance<Module>::real_param_count();
real_param_count = 0;
while(real_param_count < md->get_param_count() && (metadata->get_param_props(real_param_count)->flags & PF_TYPEMASK) < PF_STRING)
real_param_count++;
const ladspa_plugin_info &plugin_info = md->get_plugin_info();
descriptor.UniqueID = plugin_info.unique_id;
@@ -339,7 +336,7 @@ void ladspa_plugin_metadata_set::prepare(const plugin_metadata_iface *md, LADSPA
descriptor.Maker = plugin_info.maker;
descriptor.Copyright = plugin_info.copyright;
descriptor.Properties = md->is_rt_capable() ? LADSPA_PROPERTY_HARD_RT_CAPABLE : 0;
descriptor.PortCount = input_count + output_count + real_param_count;
descriptor.PortCount = input_count + output_count + param_count;
descriptor.PortNames = new char *[descriptor.PortCount];
descriptor.PortDescriptors = new LADSPA_PortDescriptor[descriptor.PortCount];
descriptor.PortRangeHints = new LADSPA_PortRangeHint[descriptor.PortCount];
@@ -352,7 +349,7 @@ void ladspa_plugin_metadata_set::prepare(const plugin_metadata_iface *md, LADSPA
prh.HintDescriptor = 0;
((const char **)descriptor.PortNames)[i] = md->get_port_names()[i];
}
for (; i < input_count + output_count + real_param_count; i++)
for (; i < input_count + output_count + param_count; i++)
{
LADSPA_PortRangeHint &prh = ((LADSPA_PortRangeHint *)descriptor.PortRangeHints)[i];
const parameter_properties &pp = *md->get_param_props(i - input_count - output_count);
@@ -484,10 +481,7 @@ ladspa_plugin_metadata_set::~ladspa_plugin_metadata_set()
// instantiate descriptor templates
template<class Module> LV2_Descriptor calf_plugins::lv2_wrapper<Module>::descriptor;
template<class Module> LV2_Calf_Descriptor calf_plugins::lv2_wrapper<Module>::calf_descriptor;
template<class Module> LV2MessageContext calf_plugins::lv2_wrapper<Module>::message_context;
#if USE_PERSIST_EXTENSION
template<class Module> LV2_Persist calf_plugins::lv2_wrapper<Module>::persist;
#endif
extern "C" {