summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2014-10-31 20:44:02 -0400
committerDavid Robillard <d@drobilla.net>2014-10-31 20:46:43 -0400
commit5de6c21ec1d1c6dde705df6cbe47d4aa5e711b55 (patch)
tree3a26cf24f14591a8d54eed1579a2decf0fd0b2db /libs/ardour/ardour
parent324ab35abca1ee8dbf24842dc149b15dd54d23e3 (diff)
More generic RT-safe implementation of LV2 properties.
Diffstat (limited to 'libs/ardour/ardour')
-rw-r--r--libs/ardour/ardour/lv2_plugin.h22
-rw-r--r--libs/ardour/ardour/plugin.h32
-rw-r--r--libs/ardour/ardour/variant.h102
3 files changed, 140 insertions, 16 deletions
diff --git a/libs/ardour/ardour/lv2_plugin.h b/libs/ardour/ardour/lv2_plugin.h
index 3c8f94855d..9e0bebad5a 100644
--- a/libs/ardour/ardour/lv2_plugin.h
+++ b/libs/ardour/ardour/lv2_plugin.h
@@ -146,16 +146,13 @@ class LIBARDOUR_API LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee
Worker* worker() { return _worker; }
- uint32_t patch_count() const { return _patch_count; }
- const char * patch_uri(const uint32_t p) const { if (p < _patch_count) return _patch_value_uri[p]; else return NULL; }
- const char * patch_key(const uint32_t p) const { if (p < _patch_count) return _patch_value_key[p]; else return NULL; }
- const char * patch_val(const uint32_t p) const { if (p < _patch_count) return _patch_value_cur[p]; else return NULL; }
- bool patch_set(const uint32_t p, const char * val);
- PBD::Signal1<void,const uint32_t> PatchChanged;
-
int work(uint32_t size, const void* data);
int work_response(uint32_t size, const void* data);
+ void set_property(uint32_t key, const Variant& value);
+ void get_supported_properties(std::vector<ParameterDescriptor>& descs);
+ void announce_property_values();
+
static URIMap _uri_map;
struct URIDs {
@@ -165,6 +162,7 @@ class LIBARDOUR_API LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee
uint32_t atom_eventTransfer;
uint32_t atom_URID;
uint32_t atom_Blank;
+ uint32_t atom_Object;
uint32_t log_Error;
uint32_t log_Note;
uint32_t log_Warning;
@@ -177,6 +175,7 @@ class LIBARDOUR_API LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee
uint32_t time_beatsPerMinute;
uint32_t time_frame;
uint32_t time_speed;
+ uint32_t patch_Get;
uint32_t patch_Set;
uint32_t patch_property;
uint32_t patch_value;
@@ -202,13 +201,8 @@ class LIBARDOUR_API LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee
framepos_t _next_cycle_start; ///< Expected start frame of next run cycle
double _next_cycle_speed; ///< Expected start frame of next run cycle
PBD::ID _insert_id;
-
- uint32_t _patch_count;
- char ** _patch_value_uri;
- char ** _patch_value_key;
- char (*_patch_value_cur)[PATH_MAX]; ///< current value
- char (*_patch_value_set)[PATH_MAX]; ///< new value to set
- Glib::Threads::Mutex _patch_set_lock;
+ uint32_t _patch_port_in_index;
+ uint32_t _patch_port_out_index;
friend const void* lv2plugin_get_port_value(const char* port_symbol,
void* user_data,
diff --git a/libs/ardour/ardour/plugin.h b/libs/ardour/ardour/plugin.h
index c485243bd4..08f242c7b4 100644
--- a/libs/ardour/ardour/plugin.h
+++ b/libs/ardour/ardour/plugin.h
@@ -30,10 +30,11 @@
#include "ardour/chan_mapping.h"
#include "ardour/cycles.h"
#include "ardour/latent.h"
-#include "ardour/plugin_insert.h"
#include "ardour/libardour_visibility.h"
-#include "ardour/types.h"
#include "ardour/midi_state_tracker.h"
+#include "ardour/plugin_insert.h"
+#include "ardour/types.h"
+#include "ardour/variant.h"
#include <vector>
#include <set>
@@ -128,6 +129,8 @@ class LIBARDOUR_API Plugin : public PBD::StatefulDestructible, public Latent
bool max_unbound;
bool enumeration;
bool midinote; ///< only used if integer_step is also true
+ uint32_t key; ///< for properties
+ Variant::Type datatype; ///< for properties
};
XMLNode& get_state ();
@@ -267,6 +270,31 @@ class LIBARDOUR_API Plugin : public PBD::StatefulDestructible, public Latent
void set_cycles (uint32_t c) { _cycles = c; }
cycles_t cycles() const { return _cycles; }
+ /** Get a descrption of all properties supported by this plugin.
+ *
+ * Properties are distinct from parameters in that they are potentially
+ * dynamic, referred to by key, and do not correspond 1:1 with ports.
+ *
+ * For LV2 plugins, properties are implemented by sending/receiving set/get
+ * messages to/from the plugin via event ports.
+ */
+ virtual void get_supported_properties(std::vector<ParameterDescriptor>& descs) {}
+
+ /** Set a property from the UI.
+ *
+ * This is not UI-specific, but may only be used by one thread. If the
+ * Ardour UI is present, that is the UI thread, but otherwise, any thread
+ * except the audio thread may call this function as long as it is not
+ * called concurrently.
+ */
+ virtual void set_property(uint32_t key, const Variant& value) {}
+
+ /** Emit PropertyChanged for all current property values. */
+ virtual void announce_property_values() {}
+
+ /** Emitted when a property is changed in the plugin. */
+ PBD::Signal2<void, uint32_t, Variant> PropertyChanged;
+
PBD::Signal1<void,uint32_t> StartTouch;
PBD::Signal1<void,uint32_t> EndTouch;
diff --git a/libs/ardour/ardour/variant.h b/libs/ardour/ardour/variant.h
new file mode 100644
index 0000000000..00b9c3acf8
--- /dev/null
+++ b/libs/ardour/ardour/variant.h
@@ -0,0 +1,102 @@
+/*
+ Copyright (C) 2014 Paul Davis
+ Author: David Robillard
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2 of the License, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef __ardour_variant_h__
+#define __ardour_variant_h__
+
+#include <stdint.h>
+
+#include <stdexcept>
+
+#include "ardour/libardour_visibility.h"
+#include "pbd/compose.h"
+
+namespace ARDOUR {
+
+/** A value with dynamic type (tagged union). */
+class LIBARDOUR_API Variant
+{
+public:
+ enum Type {
+ BOOL, ///< Boolean
+ DOUBLE, ///< C double (64-bit IEEE-754)
+ FLOAT, ///< C float (32-bit IEEE-754)
+ INT, ///< Signed 32-bit int
+ LONG, ///< Signed 64-bit int
+ PATH, ///< File path string
+ STRING, ///< Raw string (no semantics)
+ URI ///< URI string
+ };
+
+ explicit Variant(bool value) : _type(BOOL) { _bool = value; }
+ explicit Variant(double value) : _type(DOUBLE) { _double = value; }
+ explicit Variant(float value) : _type(FLOAT) { _float = value; }
+ explicit Variant(int value) : _type(INT) { _int = value; }
+ explicit Variant(long value) : _type(LONG) { _long = value; }
+
+ Variant(Type type, const std::string& value)
+ : _type(type)
+ , _string(value)
+ {}
+
+ bool get_bool() const { ensure_type(BOOL); return _bool; }
+ double get_double() const { ensure_type(DOUBLE); return _double; }
+ float get_float() const { ensure_type(FLOAT); return _float; }
+ int get_int() const { ensure_type(INT); return _int; }
+ long get_long() const { ensure_type(LONG); return _long; }
+
+ const std::string& get_path() const { ensure_type(PATH); return _string; }
+ const std::string& get_string() const { ensure_type(STRING); return _string; }
+ const std::string& get_uri() const { ensure_type(URI); return _string; }
+
+ Type type() const { return _type; }
+
+private:
+ static const char* type_name(const Type type) {
+ static const char* names[] = {
+ "bool", "double", "float", "int", "long", "path", "string", "uri"
+ };
+
+ return names[type];
+ }
+
+ void ensure_type(const Type type) const {
+ if (_type != type) {
+ throw std::domain_error(
+ string_compose("get_%1 called on %2 variant",
+ type_name(type), type_name(_type)));
+ }
+ }
+
+ Type _type; ///< Type tag
+ std::string _string; ///< For all string types (PATH, STRING, URI)
+
+ // Union of all primitive numeric types
+ union {
+ bool _bool;
+ double _double;
+ float _float;
+ int32_t _int;
+ int64_t _long;
+ };
+};
+
+} // namespace ARDOUR
+
+#endif // __ardour_variant_h__