summaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2008-08-17 07:04:34 +0000
committerDavid Robillard <d@drobilla.net>2008-08-17 07:04:34 +0000
commit988bcdbcd2438d09f2d2b3f34bcaa403d10c9007 (patch)
tree6593a332a84e599870807daefde1413f40feb6fe /src/libs
parente0743e9d9b15fb2731e26bf5700413c083a89186 (diff)
downloadingen-988bcdbcd2438d09f2d2b3f34bcaa403d10c9007.tar.gz
ingen-988bcdbcd2438d09f2d2b3f34bcaa403d10c9007.tar.bz2
ingen-988bcdbcd2438d09f2d2b3f34bcaa403d10c9007.zip
Copyable models.
git-svn-id: http://svn.drobilla.net/lad/ingen@1416 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/client/NodeModel.cpp38
-rw-r--r--src/libs/client/NodeModel.hpp13
-rw-r--r--src/libs/client/ObjectModel.hpp2
-rw-r--r--src/libs/client/PatchModel.cpp16
-rw-r--r--src/libs/client/PatchModel.hpp11
5 files changed, 49 insertions, 31 deletions
diff --git a/src/libs/client/NodeModel.cpp b/src/libs/client/NodeModel.cpp
index 45d7cffe..02a0a678 100644
--- a/src/libs/client/NodeModel.cpp
+++ b/src/libs/client/NodeModel.cpp
@@ -31,6 +31,7 @@ NodeModel::NodeModel(SharedPtr<PluginModel> plugin, const Path& path)
: ObjectModel(path)
, _plugin_uri(plugin->uri())
, _plugin(plugin)
+ , _num_values(0)
, _min_values(0)
, _max_values(0)
{
@@ -39,12 +40,25 @@ NodeModel::NodeModel(SharedPtr<PluginModel> plugin, const Path& path)
NodeModel::NodeModel(const string& plugin_uri, const Path& path)
: ObjectModel(path)
, _plugin_uri(plugin_uri)
+ , _num_values(0)
, _min_values(0)
, _max_values(0)
{
}
+NodeModel::NodeModel(const NodeModel& copy)
+ : ObjectModel(copy)
+ , _plugin_uri(copy._plugin_uri)
+ , _num_values(copy._num_values)
+ , _min_values((float*)malloc(sizeof(float) * _num_values))
+ , _max_values((float*)malloc(sizeof(float) * _num_values))
+{
+ memcpy(_min_values, copy._min_values, sizeof(float) * _num_values);
+ memcpy(_max_values, copy._max_values, sizeof(float) * _num_values);
+}
+
+
NodeModel::~NodeModel()
{
clear();
@@ -83,8 +97,8 @@ NodeModel::clear()
{
_ports.clear();
assert(_ports.empty());
- delete [] _min_values;
- delete [] _max_values;
+ delete[] _min_values;
+ delete[] _max_values;
_min_values = 0;
_max_values = 0;
}
@@ -166,20 +180,20 @@ NodeModel::port_value_range(SharedPtr<PortModel> port, float& min, float& max)
if (_plugin && _plugin->type() == PluginModel::LV2) {
if (!_min_values) {
-
- Glib::Mutex::Lock lock(PluginModel::rdf_world()->mutex());
-
- uint32_t num_lv2_ports = slv2_plugin_get_num_ports(_plugin->slv2_plugin());
- _min_values = new float[num_lv2_ports];
- _max_values = new float[num_lv2_ports];
- slv2_plugin_get_port_ranges_float(_plugin->slv2_plugin(),
- _min_values, _max_values, 0);
+
+ Glib::Mutex::Lock lock(PluginModel::rdf_world()->mutex());
+
+ _num_values = slv2_plugin_get_num_ports(_plugin->slv2_plugin());
+ _min_values = new float[_num_values];
+ _max_values = new float[_num_values];
+ slv2_plugin_get_port_ranges_float(_plugin->slv2_plugin(),
+ _min_values, _max_values, 0);
}
if (!std::isnan(_min_values[port->index()]))
- min = _min_values[port->index()];
+ min = _min_values[port->index()];
if (!std::isnan(_max_values[port->index()]))
- max = _max_values[port->index()];
+ max = _max_values[port->index()];
}
#endif
diff --git a/src/libs/client/NodeModel.hpp b/src/libs/client/NodeModel.hpp
index 1f212b6b..a4bcf4d8 100644
--- a/src/libs/client/NodeModel.hpp
+++ b/src/libs/client/NodeModel.hpp
@@ -48,6 +48,7 @@ class ClientStore;
class NodeModel : public ObjectModel, virtual public Ingen::Shared::Node
{
public:
+ NodeModel(const NodeModel& copy);
virtual ~NodeModel();
SharedPtr<PortModel> get_port(const string& port_name) const;
@@ -83,12 +84,12 @@ protected:
virtual void clear();
- PortModelList _ports; ///< List of ports (not a Table to preserve order)
- string _plugin_uri; ///< Plugin URI (if PluginModel is unknown)
- SharedPtr<PluginModel> _plugin; ///< The plugin this node is an instance of
-
- float* _min_values; ///< The min values for the node ports (only used for LV2 so far)
- float* _max_values; ///< The max values for the node ports (only used for LV2 so far)
+ PortModelList _ports; ///< List of ports (not a Table to preserve order)
+ string _plugin_uri; ///< Plugin URI (if PluginModel is unknown)
+ SharedPtr<PluginModel> _plugin; ///< The plugin this node is an instance of
+ uint32_t _num_values; ///< Size of _min_values and _max_values
+ float* _min_values; ///< Port min values (cached for LV2)
+ float* _max_values; ///< Port max values (cached for LV2)
};
diff --git a/src/libs/client/ObjectModel.hpp b/src/libs/client/ObjectModel.hpp
index 2b465fe8..2b4642da 100644
--- a/src/libs/client/ObjectModel.hpp
+++ b/src/libs/client/ObjectModel.hpp
@@ -54,7 +54,7 @@ class ClientStore;
*
* \ingroup IngenClient
*/
-class ObjectModel : virtual public Ingen::Shared::GraphObject, public boost::noncopyable
+class ObjectModel : virtual public Ingen::Shared::GraphObject
{
public:
virtual ~ObjectModel();
diff --git a/src/libs/client/PatchModel.cpp b/src/libs/client/PatchModel.cpp
index 9b109bd6..69365719 100644
--- a/src/libs/client/PatchModel.cpp
+++ b/src/libs/client/PatchModel.cpp
@@ -57,7 +57,7 @@ PatchModel::remove_child(SharedPtr<ObjectModel> o)
// Remove any connections which referred to this object,
// since they can't possibly exist anymore
- for (Connections::iterator j = _connections.begin(); j != _connections.end() ; ) {
+ for (Connections::iterator j = _connections->begin(); j != _connections->end() ; ) {
Connections::iterator next = j;
++next;
@@ -70,7 +70,7 @@ PatchModel::remove_child(SharedPtr<ObjectModel> o)
|| cm->dst_port_path().parent() == o->path()
|| cm->dst_port_path() == o->path()) {
signal_removed_connection.emit(cm);
- _connections.erase(j); // cuts our reference
+ _connections->erase(j); // cuts our reference
assert(!get_connection(cm->src_port_path(), cm->dst_port_path())); // no duplicates
}
j = next;
@@ -87,11 +87,11 @@ PatchModel::remove_child(SharedPtr<ObjectModel> o)
void
PatchModel::clear()
{
- _connections.clear();
+ _connections->clear();
NodeModel::clear();
- assert(_connections.empty());
+ assert(_connections->empty());
assert(_ports.empty());
}
@@ -99,7 +99,7 @@ PatchModel::clear()
SharedPtr<ConnectionModel>
PatchModel::get_connection(const string& src_port_path, const string& dst_port_path) const
{
- for (Connections::const_iterator i = _connections.begin(); i != _connections.end(); ++i)
+ for (Connections::const_iterator i = _connections->begin(); i != _connections->end(); ++i)
if ((*i)->src_port_path() == src_port_path && (*i)->dst_port_path() == dst_port_path)
return PtrCast<ConnectionModel>(*i);
@@ -135,7 +135,7 @@ PatchModel::add_connection(SharedPtr<ConnectionModel> cm)
assert(cm->src_port() == existing->src_port());
assert(cm->dst_port() == existing->dst_port());
} else {
- _connections.push_back(new Connections::Node(cm));
+ _connections->push_back(new Connections::Node(cm));
signal_new_connection.emit(cm);
}
}
@@ -144,12 +144,12 @@ PatchModel::add_connection(SharedPtr<ConnectionModel> cm)
void
PatchModel::remove_connection(const string& src_port_path, const string& dst_port_path)
{
- for (Connections::iterator i = _connections.begin(); i != _connections.end(); ++i) {
+ for (Connections::iterator i = _connections->begin(); i != _connections->end(); ++i) {
SharedPtr<ConnectionModel> cm = PtrCast<ConnectionModel>(*i);
assert(cm);
if (cm->src_port_path() == src_port_path && cm->dst_port_path() == dst_port_path) {
signal_removed_connection.emit(cm);
- delete _connections.erase(i); // cuts our reference
+ delete _connections->erase(i); // cuts our reference
assert(!get_connection(src_port_path, dst_port_path)); // no duplicates
return;
}
diff --git a/src/libs/client/PatchModel.hpp b/src/libs/client/PatchModel.hpp
index 8c60e884..b1c03cd0 100644
--- a/src/libs/client/PatchModel.hpp
+++ b/src/libs/client/PatchModel.hpp
@@ -43,7 +43,9 @@ class ClientStore;
class PatchModel : public NodeModel, public Ingen::Shared::Patch
{
public:
- const Connections& connections() const { return _connections; }
+ /* WARNING: Copy constructor creates a shallow copy WRT connections */
+
+ const Connections& connections() const { return *_connections.get(); }
SharedPtr<ConnectionModel> get_connection(const string& src_port_path,
const string& dst_port_path) const;
@@ -80,6 +82,7 @@ private:
PatchModel(const Path& patch_path, size_t internal_poly)
: NodeModel("ingen:Patch", patch_path)
+ , _connections(new Connections())
, _poly(internal_poly)
, _editable(true)
{
@@ -92,9 +95,9 @@ private:
void add_connection(SharedPtr<ConnectionModel> cm);
void remove_connection(const string& src_port_path, const string& dst_port_path);
- Connections _connections;
- uint32_t _poly;
- bool _editable;
+ SharedPtr<Connections> _connections;
+ uint32_t _poly;
+ bool _editable;
};
typedef Table<string, SharedPtr<PatchModel> > PatchModelMap;