Metadata working based on Store signals (node positions restored)

git-svn-id: http://svn.drobilla.net/lad@29 a436a847-0d15-0410-975c-d299462d15a1
This commit is contained in:
dave 2006-06-12 00:41:00 +00:00
parent 2816a32a12
commit b6959dbc46
7 changed files with 38 additions and 22 deletions

View File

@ -23,6 +23,7 @@
#include <string>
#include <algorithm>
#include <cassert>
#include <sigc++/sigc++.h>
#include "util/Path.h"
using std::string; using std::map; using std::find;
@ -49,7 +50,7 @@ public:
const map<string, string>& metadata() const { return m_metadata; }
string get_metadata(const string& key) const;
void set_metadata(const string& key, const string& value)
{ assert(value.length() > 0); m_metadata[key] = value; }
{ assert(value.length() > 0); m_metadata[key] = value; metadata_update_sig.emit(key, value); }
inline const Path& path() const { return m_path; }
virtual void set_path(const Path& p) { m_path = p; }
@ -65,6 +66,8 @@ public:
string base_path() const;
const string name() const { return m_path.name(); }
// Signals
sigc::signal<void, const string&, const string&> metadata_update_sig;
protected:
Path m_path;
ObjectModel* m_parent;

View File

@ -33,6 +33,7 @@ Store::Store(SigClientInterface& emitter)
emitter.new_patch_sig.connect(sigc::mem_fun(this, &Store::new_patch_event));
emitter.new_node_sig.connect(sigc::mem_fun(this, &Store::new_node_event));
emitter.new_port_sig.connect(sigc::mem_fun(this, &Store::new_port_event));
emitter.metadata_update_sig.connect(sigc::mem_fun(this, &Store::metadata_update_event));
}
@ -259,5 +260,16 @@ Store::new_port_event(const string& path, const string& type, bool is_output)
}
void
Store::metadata_update_event(const string& subject_path, const string& predicate, const string& value)
{
CountedPtr<ObjectModel> subject = object(subject_path);
if (subject)
subject->set_metadata(predicate, value);
else
cerr << "ERROR: metadata for nonexistant object." << endl;
}
} // namespace LibOmClient

View File

@ -41,7 +41,7 @@ class PortModel;
*/
class Store {
public:
CountedPtr<PluginModel> plugin(const string& uri);
CountedPtr<PluginModel> plugin(const string& uri);
CountedPtr<ObjectModel> object(const string& path);
CountedPtr<PatchModel> patch(const string& path);
CountedPtr<NodeModel> node(const string& path);
@ -73,7 +73,8 @@ private:
void new_patch_event(const string& path, uint32_t poly);
void new_node_event(const string& plugin_type, const string& plugin_uri, const string& node_path, bool is_polyphonic, uint32_t num_ports);
void new_port_event(const string& path, const string& data_type, bool is_output);
void metadata_update_event(const string& subject_path, const string& predicate, const string& value);
map<string, CountedPtr<ObjectModel> > m_objects; ///< Keyed by Om path
map<string, CountedPtr<PluginModel> > m_plugins; ///< Keyed by URI
};

View File

@ -133,6 +133,11 @@ ObjectSender::send_node(ClientInterface* client, const Node* node)
}
client->bundle_end();
// Send metadata
const map<string, string>& data = node->metadata();
for (map<string, string>::const_iterator j = data.begin(); j != data.end(); ++j)
client->metadata_update(node->path(), (*j).first, (*j).second);
}

View File

@ -23,16 +23,7 @@ GtkObjectController::GtkObjectController(CountedPtr<ObjectModel> model)
: m_model(model)
{
assert(m_model);
}
/** Derived classes should override this to handle special metadata
* keys, then call this to set the model's metadata key.
*/
void
GtkObjectController::metadata_update(const string& key, const string& value)
{
m_model->set_metadata(key, value);
model->metadata_update_sig.connect(sigc::mem_fun(this, &GtkObjectController::metadata_update));
}

View File

@ -58,7 +58,12 @@ public:
virtual void add_to_store() = 0;
virtual void remove_from_store() = 0;
*/
virtual void metadata_update(const string& key, const string& value);
/** Derived classes should override this to handle special metadata
* keys, then call this to set the model's metadata key.
*/
virtual void metadata_update(const string& key, const string& value)
{ assert(m_model->get_metadata(key) != ""); }
/** Rename object */
virtual void set_path(const Path& new_path)

View File

@ -50,12 +50,11 @@ NodeController::NodeController(CountedPtr<NodeModel> model)
model->set_controller(this);
// Create port controllers
cerr << "FIXME: NodeController()" << endl;
/*
for (list<PortModel*>::const_iterator i = node_model()->ports().begin();
for (PortModelList::const_iterator i = node_model()->ports().begin();
i != node_model()->ports().end(); ++i) {
assert((*i)->controller() == NULL);
assert(!(*i)->controller());
assert((*i)->parent() == model.get());
// FIXME: leak
PortController* const pc = new PortController(*i);
assert((*i)->controller() == pc); // PortController() does this
}
@ -83,13 +82,12 @@ NodeController::NodeController(CountedPtr<NodeModel> model)
m_controls_menuitem->property_sensitive() = false;
if (node_model()->plugin()->type() == PluginModel::Internal
if (node_model()->plugin() && node_model()->plugin()->type() == PluginModel::Internal
&& node_model()->plugin()->plug_label() == "midi_control_in") {
Gtk::Menu::MenuList& items = m_menu.items();
items.push_back(Gtk::Menu_Helpers::MenuElem("Learn",
sigc::mem_fun(this, &NodeController::on_menu_learn)));
}
*/
model->new_port_sig.connect(sigc::mem_fun(this, &NodeController::add_port));
}
@ -227,11 +225,12 @@ NodeController::metadata_update(const string& key, const string& value)
void
NodeController::add_port(CountedPtr<PortModel> pm)
{
assert(pm->parent() == NULL);
assert(pm->parent() == node_model().get());
assert(node_model()->get_port(pm->name()) == pm);
cout << "[NodeController] Adding port " << pm->path() << endl;
node_model()->add_port(pm);
// FIXME: leak
PortController* pc = new PortController(pm);
assert(pm->controller() == pc);
//pc->add_to_store();