summaryrefslogtreecommitdiffstats
path: root/src/client
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-05-28 19:54:24 +0000
committerDavid Robillard <d@drobilla.net>2009-05-28 19:54:24 +0000
commitcf6e43bc6a14fc0fd290864b4f71aeb600a28e9d (patch)
tree9dca0dddfdb454e2db6d8e4c0c15adcafc140ee5 /src/client
parent939a16ee56b4ba58246a98afda203f714d7d17c8 (diff)
downloadingen-cf6e43bc6a14fc0fd290864b4f71aeb600a28e9d.tar.gz
ingen-cf6e43bc6a14fc0fd290864b4f71aeb600a28e9d.tar.bz2
ingen-cf6e43bc6a14fc0fd290864b4f71aeb600a28e9d.zip
Generic plugin property mechanism.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2031 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/client')
-rw-r--r--src/client/ObjectModel.hpp10
-rw-r--r--src/client/PatchModel.cpp5
-rw-r--r--src/client/PatchModel.hpp2
-rw-r--r--src/client/PluginModel.cpp114
-rw-r--r--src/client/PluginModel.hpp11
5 files changed, 68 insertions, 74 deletions
diff --git a/src/client/ObjectModel.hpp b/src/client/ObjectModel.hpp
index 5029f024..840f9339 100644
--- a/src/client/ObjectModel.hpp
+++ b/src/client/ObjectModel.hpp
@@ -54,16 +54,16 @@ class ObjectModel : virtual public Ingen::Shared::GraphObject
public:
virtual ~ObjectModel();
- const Raul::Atom& get_property(const Raul::URI& key) const;
+ virtual const Raul::Atom& get_property(const Raul::URI& key) const;
- virtual void set_property(const Raul::URI& key, const Raul::Atom& value) {
- ResourceImpl::set_property(key, value);
+ virtual Raul::Atom& set_property(const Raul::URI& key, const Raul::Atom& value) {
signal_property.emit(key, value);
+ return ResourceImpl::set_property(key, value);
}
- virtual void set_meta_property(const Raul::URI& key, const Raul::Atom& value) {
- _meta.set_property(key, value);
+ virtual Raul::Atom& set_meta_property(const Raul::URI& key, const Raul::Atom& value) {
signal_property.emit(key, value);
+ return _meta.set_property(key, value);
}
Resource& meta() { return _meta; }
diff --git a/src/client/PatchModel.cpp b/src/client/PatchModel.cpp
index baaa36ba..cec8b13b 100644
--- a/src/client/PatchModel.cpp
+++ b/src/client/PatchModel.cpp
@@ -169,12 +169,13 @@ PatchModel::enabled() const
}
-void
+Raul::Atom&
PatchModel::set_meta_property(const Raul::URI& key, const Atom& value)
{
- NodeModel::set_meta_property(key, value);
if (key.str() == "ingen:polyphony")
_poly = value.get_int32();
+
+ return NodeModel::set_meta_property(key, value);
}
diff --git a/src/client/PatchModel.hpp b/src/client/PatchModel.hpp
index b52a4f8d..6b8398ae 100644
--- a/src/client/PatchModel.hpp
+++ b/src/client/PatchModel.hpp
@@ -60,7 +60,7 @@ public:
signal_editable.emit(e);
} }
- virtual void set_meta_property(const Raul::URI& key, const Raul::Atom& value);
+ virtual Raul::Atom& set_meta_property(const Raul::URI& key, const Raul::Atom& value);
// Signals
sigc::signal<void, SharedPtr<NodeModel> > signal_new_node;
diff --git a/src/client/PluginModel.cpp b/src/client/PluginModel.cpp
index 0627326d..7998f8e2 100644
--- a/src/client/PluginModel.cpp
+++ b/src/client/PluginModel.cpp
@@ -17,6 +17,7 @@
#include <sstream>
#include <ctype.h>
+#include <boost/optional.hpp>
#include "ingen-config.h"
#include "raul/Path.hpp"
#include "raul/Atom.hpp"
@@ -40,22 +41,34 @@ Redland::World* PluginModel::_rdf_world = NULL;
PluginModel::PluginModel(const URI& uri, const URI& type_uri, const Resource::Properties& properties)
: ResourceImpl(uri)
- , _type(type_from_uri(_rdf_world->prefixes().qualify(type_uri.str())))
+ , _type(type_from_uri(type_uri.str()))
{
add_properties(properties);
Glib::Mutex::Lock lock(_rdf_world->mutex());
assert(_rdf_world);
- add_property("rdf:type", Raul::Atom(Raul::Atom::URI, this->type_uri()));
+ add_property("rdf:type", Atom(Atom::URI, this->type_uri()));
#ifdef HAVE_SLV2
SLV2Value plugin_uri = slv2_value_new_uri(_slv2_world, uri.c_str());
_slv2_plugin = slv2_plugins_get_by_uri(_slv2_plugins, plugin_uri);
slv2_value_free(plugin_uri);
#endif
if (_type == Internal)
- set_property("doap:name", Raul::Atom(uri.substr(uri.find_last_of("#") + 1).c_str()));
+ set_property("doap:name", Atom(uri.substr(uri.find_last_of("#") + 1).c_str()));
+}
+
- if (!get_property("lv2:symbol").is_valid()) {
+const Atom&
+PluginModel::get_property(const URI& key) const
+{
+ static Atom nil_atom(Atom::NIL);
+ const Atom& val = ResourceImpl::get_property(key);
+ if (val.is_valid())
+ return val;
+
+ // No lv2:symbol from data or engine, invent one
+ if (key.str() == "lv2:symbol") {
+ const URI& uri = this->uri();
size_t last_slash = uri.find_last_of("/");
size_t last_hash = uri.find_last_of("#");
string symbol;
@@ -78,48 +91,51 @@ PluginModel::PluginModel(const URI& uri, const URI& type_uri, const Resource::Pr
symbol = uri.str().substr(first_delim + 1, last_delim - first_delim - 1);
}
set_property("lv2:symbol", Atom(Atom::STRING, symbol));
+ return get_property(key);
}
-}
-
-
-const std::string
-PluginModel::symbol()
-{
- const Atom& val = get_property("lv2:symbol");
- if (val.is_valid() && val.type() == Atom::STRING)
- return val.get_string();
#ifdef HAVE_SLV2
- SLV2Value lv2_symbol_pred = slv2_value_new_uri(_slv2_world,
- "http://lv2plug.in/ns/lv2core#symbol");
- SLV2Values symbols = slv2_plugin_get_value(_slv2_plugin, lv2_symbol_pred);
- for (unsigned i = 0; i < slv2_values_size(symbols); ++i) {
- SLV2Value val = slv2_values_get_at(symbols, 0);
- if (slv2_value_is_string(val)) {
- cerr << uri() << " FOUND SYMBOL: " << slv2_value_as_string(val) << endl;
- set_property("lv2:symbol", Atom(Atom::STRING, slv2_value_as_string(val)));
- break;
+ if (_slv2_plugin) {
+ boost::optional<Raul::Atom&> ret;
+ SLV2Value lv2_pred = slv2_value_new_uri(_slv2_world,
+ _rdf_world->expand_uri(key.str()).c_str());
+ SLV2Values values = slv2_plugin_get_value(_slv2_plugin, lv2_pred);
+ slv2_value_free(lv2_pred);
+ for (unsigned i = 0; i < slv2_values_size(values); ++i) {
+ SLV2Value val = slv2_values_get_at(values, 0);
+ if (slv2_value_is_uri(val)) {
+ ret = set_property(key, Atom(Atom::URI, slv2_value_as_uri(val)));
+ break;
+ } else if (slv2_value_is_string(val)) {
+ ret = set_property(key, Atom(Atom::STRING, slv2_value_as_string(val)));
+ break;
+ } else if (slv2_value_is_float(val)) {
+ ret = set_property(key, Atom(slv2_value_as_float(val)));
+ break;
+ } else if (slv2_value_is_int(val)) {
+ ret = set_property(key, Atom(slv2_value_as_int(val)));
+ break;
+ }
}
+ slv2_values_free(values);
+
+ if (ret)
+ return *ret;
}
- slv2_values_free(symbols);
- slv2_value_free(lv2_symbol_pred);
#endif
- return string_property("lv2:symbol");
+ return nil_atom;
}
-const std::string
-PluginModel::name()
-{
- return string_property("doap:name");
-}
-
-
-string
+Symbol
PluginModel::default_node_symbol()
{
- return Raul::Path::nameify(symbol());
+ const Atom& name_atom = get_property("lv2:symbol");
+ if (name_atom.is_valid() && name_atom.type() == Atom::STRING)
+ return Symbol::symbolify(name_atom.get_string());
+ else
+ return "_";
}
@@ -127,20 +143,10 @@ string
PluginModel::human_name()
{
const Atom& name_atom = get_property("doap:name");
- if (name_atom.type() == Atom::STRING)
+ if (name_atom.is_valid() && name_atom.type() == Atom::STRING)
return name_atom.get_string();
-
-#ifdef HAVE_SLV2
- if (_slv2_plugin) {
- SLV2Value name = slv2_plugin_get_name(_slv2_plugin);
- string ret = slv2_value_as_string(name);
- slv2_value_free(name);
- set_property("doap:name", Raul::Atom(Raul::Atom::STRING, ret.c_str()));
- return ret;
- }
-#endif
-
- return default_node_symbol();
+ else
+ return default_node_symbol();
}
@@ -150,9 +156,9 @@ PluginModel::port_human_name(uint32_t index) const
#ifdef HAVE_SLV2
if (_slv2_plugin) {
Glib::Mutex::Lock lock(_rdf_world->mutex());
- SLV2Port port = slv2_plugin_get_port_by_index(_slv2_plugin, index);
+ SLV2Port port = slv2_plugin_get_port_by_index(_slv2_plugin, index);
SLV2Value name = slv2_port_get_name(_slv2_plugin, port);
- string ret = slv2_value_as_string(name);
+ string ret = slv2_value_as_string(name);
slv2_value_free(name);
return ret;
}
@@ -227,15 +233,5 @@ PluginModel::get_lv2_icon_path(SLV2Plugin plugin)
#endif
-const string
-PluginModel::string_property(const std::string& name) const
-{
- const Raul::Atom& atom = get_property(name);
- if (atom.type() == Raul::Atom::STRING)
- return atom.get_string();
- else
- return "";
-}
-
} // namespace Client
} // namespace Ingen
diff --git a/src/client/PluginModel.hpp b/src/client/PluginModel.hpp
index bc7271b9..90440efe 100644
--- a/src/client/PluginModel.hpp
+++ b/src/client/PluginModel.hpp
@@ -53,12 +53,11 @@ public:
Type type() const { return _type; }
- const std::string symbol();
- const std::string name();
+ virtual const Raul::Atom& get_property(const Raul::URI& key) const;
- std::string default_node_symbol();
- std::string human_name();
- std::string port_human_name(uint32_t index) const;
+ Raul::Symbol default_node_symbol();
+ std::string human_name();
+ std::string port_human_name(uint32_t index) const;
#ifdef HAVE_SLV2
static SLV2World slv2_world() { return _slv2_world; }
@@ -93,8 +92,6 @@ public:
private:
const Type _type;
- const std::string string_property(const std::string& name) const;
-
#ifdef HAVE_SLV2
static SLV2World _slv2_world;
static SLV2Plugins _slv2_plugins;