diff options
author | David Robillard <d@drobilla.net> | 2009-05-27 17:42:51 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-05-27 17:42:51 +0000 |
commit | c11ecf0fd10641218326ae384e80413ba3cdf46c (patch) | |
tree | 52ea61f88167a2e7eacc8fa5ff0ee39ee25b2e7e /src/shared | |
parent | 8feac4ed0e764c677d4d208377e956c6db94d2dd (diff) | |
download | ingen-c11ecf0fd10641218326ae384e80413ba3cdf46c.tar.gz ingen-c11ecf0fd10641218326ae384e80413ba3cdf46c.tar.bz2 ingen-c11ecf0fd10641218326ae384e80413ba3cdf46c.zip |
Remove 'new_patch', 'new_node', and 'new_port' from interface in favour of generic 'put'.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2011 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/Builder.cpp | 18 | ||||
-rw-r--r-- | src/shared/ClashAvoider.cpp | 32 | ||||
-rw-r--r-- | src/shared/ClashAvoider.hpp | 14 | ||||
-rw-r--r-- | src/shared/ResourceImpl.cpp | 90 | ||||
-rw-r--r-- | src/shared/ResourceImpl.hpp | 15 |
5 files changed, 119 insertions, 50 deletions
diff --git a/src/shared/Builder.cpp b/src/shared/Builder.cpp index 45c4badf..ba26d962 100644 --- a/src/shared/Builder.cpp +++ b/src/shared/Builder.cpp @@ -25,6 +25,7 @@ #include "common/interface/Plugin.hpp" using namespace std; +using namespace Raul; namespace Ingen { namespace Shared { @@ -41,8 +42,12 @@ Builder::build(SharedPtr<const GraphObject> object) { SharedPtr<const Patch> patch = PtrCast<const Patch>(object); if (patch) { - if (!object->path().is_root()) - _interface.new_patch(object->path(), patch->internal_polyphony()); + if (!object->path().is_root()) { + Resource::Properties props; + props.insert(make_pair("rdf:type", Atom(Atom::URI, "ingen:Patch"))); + props.insert(make_pair("ingen:polyphony", Atom(int32_t(patch->internal_polyphony())))); + _interface.put(object->path(), props); + } build_object(object); /*for (Patch::Connections::const_iterator i = patch->connections().begin(); @@ -54,16 +59,17 @@ Builder::build(SharedPtr<const GraphObject> object) SharedPtr<const Node> node = PtrCast<const Node>(object); if (node) { - Raul::Path path = node->path(); - _interface.new_node(path, node->plugin()->uri()); + Resource::Properties props; + props.insert(make_pair("rdf:type", Atom(Atom::URI, "ingen:Node"))); + props.insert(make_pair("rdf:instanceOf", Atom(Atom::URI, node->plugin()->uri().str()))); + _interface.put(node->path(), props); build_object(object); return; } SharedPtr<const Port> port = PtrCast<const Port>(object); if (port) { - Raul::Path path = port->path(); - _interface.new_port(path, port->type().uri(), port->index(), !port->is_input()); + _interface.put(port->path(), port->properties()); build_object(object); return; } diff --git a/src/shared/ClashAvoider.cpp b/src/shared/ClashAvoider.cpp index 1fd2124c..e553364b 100644 --- a/src/shared/ClashAvoider.cpp +++ b/src/shared/ClashAvoider.cpp @@ -142,37 +142,11 @@ ClashAvoider::exists(const Raul::Path& path) const } -bool -ClashAvoider::new_object(const GraphObject* object) -{ - return false; -} - - -void -ClashAvoider::new_patch(const Raul::Path& path, - uint32_t poly) -{ - if (!path.is_root()) - _target.new_patch(map_path(path), poly); -} - - -void -ClashAvoider::new_node(const Raul::Path& path, - const Raul::URI& plugin_uri) -{ - _target.new_node(map_path(path), plugin_uri); -} - - void -ClashAvoider::new_port(const Raul::Path& path, - const Raul::URI& type, - uint32_t index, - bool is_output) +ClashAvoider::put(const Raul::Path& path, + const Shared::Resource::Properties& properties) { - _target.new_port(map_path(path), type, index, is_output); + _target.put(map_path(path), properties); } diff --git a/src/shared/ClashAvoider.hpp b/src/shared/ClashAvoider.hpp index 376738a3..007331bc 100644 --- a/src/shared/ClashAvoider.hpp +++ b/src/shared/ClashAvoider.hpp @@ -48,18 +48,8 @@ public: // Object commands - virtual bool new_object(const GraphObject* object); - - virtual void new_patch(const Raul::Path& path, - uint32_t poly); - - virtual void new_node(const Raul::Path& path, - const Raul::URI& plugin_uri); - - virtual void new_port(const Raul::Path& path, - const Raul::URI& type, - uint32_t index, - bool is_output); + virtual void put(const Raul::Path& path, + const Resource::Properties& properties); virtual void rename(const Raul::Path& old_path, const Raul::Path& new_path); diff --git a/src/shared/ResourceImpl.cpp b/src/shared/ResourceImpl.cpp index 20a44167..27a33e07 100644 --- a/src/shared/ResourceImpl.cpp +++ b/src/shared/ResourceImpl.cpp @@ -18,18 +18,36 @@ #include "raul/Atom.hpp" #include "ResourceImpl.hpp" +using namespace std; +using namespace Raul; + namespace Ingen { namespace Shared { void -ResourceImpl::set_property(const Raul::URI& uri, const Raul::Atom& value) +ResourceImpl::add_property(const Raul::URI& uri, const Raul::Atom& value) { - _properties[uri] = value; + // Ignore duplicate statements + typedef Resource::Properties::const_iterator iterator; + const std::pair<iterator,iterator> range = _properties.equal_range(uri); + for (iterator i = range.first; i != range.second; ++i) + if (i->second == value) + return; + + _properties.insert(make_pair(uri, value)); signal_property.emit(uri, value); } +void +ResourceImpl::set_property(const Raul::URI& uri, const Raul::Atom& value) +{ + _properties.erase(uri); + _properties.insert(make_pair(uri, value)); +} + + const Raul::Atom& ResourceImpl::get_property(const Raul::URI& uri) const { @@ -39,5 +57,73 @@ ResourceImpl::get_property(const Raul::URI& uri) const } +bool +ResourceImpl::type( + const Properties& properties, + bool& patch, + bool& node, + bool& port, bool& is_output, DataType& data_type) +{ + typedef Resource::Properties::const_iterator iterator; + const std::pair<iterator,iterator> types_range = properties.equal_range("rdf:type"); + + patch = node = port = is_output = false; + data_type = DataType::UNKNOWN; + for (iterator i = types_range.first; i != types_range.second; ++i) { + const Atom& atom = i->second; + if (atom.type() == Atom::URI) { + if (!strncmp(atom.get_uri(), "ingen:", 6)) { + const char* suffix = atom.get_uri() + 6; + if (!strcmp(suffix, "Patch")) { + patch = true; + } else if (!strcmp(suffix, "Node")) { + node = true; + } + } else if (!strncmp(atom.get_uri(), "lv2:", 4)) { + const char* suffix = atom.get_uri() + 4; + port = true; + if (!strcmp(suffix, "InputPort")) { + is_output = false; + port = true; + } else if (!strcmp(suffix, "OutputPort")) { + is_output = true; + port = true; + } else if (!strcmp(suffix, "AudioPort")) { + data_type = DataType::AUDIO; + port = true; + } else if (!strcmp(suffix, "ControlPort")) { + data_type = DataType::CONTROL; + port = true; + } + } else if (!strcmp(atom.get_uri(), "lv2ev:EventPort")) { + data_type = DataType::EVENT; + port = true; + } + } + } + + if (patch && node && !port) { // => patch + node = false; + return true; + } else if (port && (patch || node)) { // nonsense + port = false; + return false; + } else if (patch || node || port) { // recognized type + return true; + } else { // unknown + return false; + } +} + + +void +ResourceImpl::merge_properties(const Properties& p) +{ + typedef Resource::Properties::const_iterator iterator; + for (iterator i = p.begin(); i != p.end(); ++i) + set_property(i->first, i->second); +} + + } // namespace Shared } // namespace Ingen diff --git a/src/shared/ResourceImpl.hpp b/src/shared/ResourceImpl.hpp index 059e3844..b436ddc9 100644 --- a/src/shared/ResourceImpl.hpp +++ b/src/shared/ResourceImpl.hpp @@ -22,11 +22,11 @@ #include <sigc++/sigc++.h> #include "raul/URI.hpp" #include "interface/Resource.hpp" +#include "interface/DataType.hpp" namespace Ingen { namespace Shared { - class ResourceImpl : virtual public Resource { public: @@ -39,6 +39,19 @@ public: const Raul::Atom& get_property(const Raul::URI& uri) const; void set_property(const Raul::URI& uri, const Raul::Atom& value); + void add_property(const Raul::URI& uri, const Raul::Atom& value); + + /** Get the ingen type from a set of Properties. + * If some coherent ingen type is found, true is returned and the appropriate + * output parameter set to true. Otherwise false is returned. + */ + static bool type( + const Properties& properties, + bool& patch, + bool& node, + bool& port, bool& is_output, DataType& data_type); + + void merge_properties(const Properties& p); sigc::signal<void, const Raul::URI&, const Raul::Atom&> signal_property; |