diff options
author | David Robillard <d@drobilla.net> | 2007-01-12 18:12:06 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-01-12 18:12:06 +0000 |
commit | 09a4ea31dc9ce8ef4cd399a6c68054aafe31c325 (patch) | |
tree | c41cd0b337b951ce02890635d19c9c6a5ec6bafc | |
parent | b162a604d0452752c679e31fd6b3f3de0687151c (diff) | |
download | ingen-09a4ea31dc9ce8ef4cd399a6c68054aafe31c325.tar.gz ingen-09a4ea31dc9ce8ef4cd399a6c68054aafe31c325.tar.bz2 ingen-09a4ea31dc9ce8ef4cd399a6c68054aafe31c325.zip |
Control value persistence/serialization.
git-svn-id: http://svn.drobilla.net/lad/ingen@252 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | src/libs/client/Loader.cpp | 66 | ||||
-rw-r--r-- | src/libs/client/OSCClientReceiver.cpp | 12 | ||||
-rw-r--r-- | src/libs/client/PortModel.h | 66 | ||||
-rw-r--r-- | src/libs/engine/GraphObject.h | 6 | ||||
-rw-r--r-- | src/progs/ingenuity/ControlGroups.cpp | 14 | ||||
-rw-r--r-- | src/progs/ingenuity/ControlGroups.h | 7 | ||||
-rw-r--r-- | src/progs/ingenuity/ControlPanel.cpp | 11 | ||||
-rw-r--r-- | src/progs/ingenuity/ControlPanel.h | 6 | ||||
-rw-r--r-- | src/progs/ingenuity/Makefile.am | 4 | ||||
-rw-r--r-- | src/progs/ingenuity/main.cpp | 3 |
10 files changed, 127 insertions, 68 deletions
diff --git a/src/libs/client/Loader.cpp b/src/libs/client/Loader.cpp index 4ceb34d2..9c6f7fb0 100644 --- a/src/libs/client/Loader.cpp +++ b/src/libs/client/Loader.cpp @@ -52,7 +52,7 @@ Loader::load(const Glib::ustring& filename, { // FIXME: this whole thing is a mess - std::map<Glib::ustring, bool> created; + std::map<Path, bool> created; // FIXME: kluge unsigned char* document_uri_str = raptor_uri_filename_to_uri_string(filename.c_str()); @@ -60,7 +60,7 @@ Loader::load(const Glib::ustring& filename, //Glib::ustring document_uri = "file:///home/dave/code/codesonnet/ingen/src/progs/ingenuity/test2.ingen.ttl"; if (patch_uri == "") - patch_uri = "<>"; + patch_uri = "<>"; // FIXME: Will load every patch in the file? cerr << "[Loader] Loading " << patch_uri << " from " << document_uri << " under " << parent << endl; @@ -122,9 +122,11 @@ Loader::load(const Glib::ustring& filename, const Glib::ustring& name = (*i)["name"]; const Glib::ustring& plugin = (*i)["plugin"]; - if (created.find(name) == created.end()) { - _engine->create_node(patch_path.base() + name, plugin, false); - created[name] = true; + const Path node_path = patch_path.base() + (string)name; + + if (created.find(node_path) == created.end()) { + _engine->create_node(node_path, plugin, false); + created[node_path] = true; } Glib::ustring floatkey = _namespaces->qualify((*i)["floatkey"]); @@ -139,16 +141,47 @@ Loader::load(const Glib::ustring& filename, created.clear(); + /* Set node port control values */ + + query = RDFQuery(Glib::ustring( + "SELECT DISTINCT ?nodename ?portname ?portval FROM <") + document_uri + "> WHERE {\n" + + patch_uri + " ingen:node ?node .\n" + "?node ingen:name ?nodename ;\n" + " ingen:port ?port .\n" + "?port ingen:name ?portname ;\n" + " ingen:value ?portval .\n" + "}\n"); + + results = query.run(document_uri); + + for (RDFQuery::Results::iterator i = results.begin(); i != results.end(); ++i) { + + const Glib::ustring& node_name = (*i)["nodename"]; + const Glib::ustring& port_name = (*i)["portname"]; + const Glib::ustring& portval = (*i)["portval"]; + + Path port_path = patch_path.base() + (const string&)node_name +"/"+ (const string&)port_name; + + if (portval != "") { + const float val = atof(portval.c_str()); + cerr << port_path << " VALUE: " << val << endl; + _engine->set_port_value(port_path, val); + } + } + + /* Load this patch's ports */ query = RDFQuery(Glib::ustring( - "SELECT DISTINCT ?port ?type ?name ?datatype ?floatkey ?floatval FROM <") + document_uri + "> WHERE {\n" + + "SELECT DISTINCT ?port ?type ?name ?datatype ?floatkey ?floatval ?portval FROM <") + document_uri + "> WHERE {\n" + patch_uri + " ingen:port ?port .\n" "?port a ?type ;\n" " ingen:name ?name ;\n" " ingen:dataType ?datatype .\n" "OPTIONAL { ?port ?floatkey ?floatval . \n" " FILTER ( datatype(?floatval) = xsd:decimal ) }\n" + "OPTIONAL { ?port ingen:value ?portval . \n" + " FILTER ( datatype(?portval) = xsd:decimal ) }\n" "}"); results = query.run(document_uri); @@ -158,21 +191,32 @@ Loader::load(const Glib::ustring& filename, const Glib::ustring& type = _namespaces->qualify((*i)["type"]); const Glib::ustring& datatype = (*i)["datatype"]; - if (created.find(name) == created.end()) { + const Path port_path = patch_path.base() + (string)name; + + if (created.find(port_path) == created.end()) { //cerr << "TYPE: " << type << endl; bool is_output = (type == "ingen:OutputPort"); // FIXME: check validity - _engine->create_port(patch_path.base() + name, datatype, is_output); - created[name] = true; + _engine->create_port(port_path, datatype, is_output); + created[port_path] = true; } - Glib::ustring floatkey = _namespaces->qualify((*i)["floatkey"]); - Glib::ustring floatval = (*i)["floatval"]; + const Glib::ustring& portval = (*i)["portval"]; + if (portval != "") { + const float val = atof(portval.c_str()); + cerr << name << " VALUE: " << val << endl; + _engine->set_port_value(patch_path.base() + name, val); + } + + const Glib::ustring& floatkey = _namespaces->qualify((*i)["floatkey"]); + const Glib::ustring& floatval = (*i)["floatval"]; if (floatkey != "" && floatval != "") { const float val = atof(floatval.c_str()); _engine->set_metadata(patch_path.base() + name, floatkey, Atom(val)); } } + + created.clear(); /* Load connections */ diff --git a/src/libs/client/OSCClientReceiver.cpp b/src/libs/client/OSCClientReceiver.cpp index 0dbf49ec..45b8d794 100644 --- a/src/libs/client/OSCClientReceiver.cpp +++ b/src/libs/client/OSCClientReceiver.cpp @@ -50,15 +50,19 @@ OSCClientReceiver::start() if (_st != NULL) return; - if (_listen_port == 0) { - _st = lo_server_thread_new(NULL, error_cb); - _listen_port = lo_server_thread_get_port(_st); - } else { + // Attempt preferred port + if (_listen_port != 0) { char port_str[8]; snprintf(port_str, 8, "%d", _listen_port); _st = lo_server_thread_new(port_str, error_cb); } + // Find a free port + if (!_st) { + _st = lo_server_thread_new(NULL, error_cb); + _listen_port = lo_server_thread_get_port(_st); + } + if (_st == NULL) { cerr << "[OSCClientReceiver] Could not start OSC listener. Aborting." << endl; exit(EXIT_FAILURE); diff --git a/src/libs/client/PortModel.h b/src/libs/client/PortModel.h index adaaf803..eaea8f71 100644 --- a/src/libs/client/PortModel.h +++ b/src/libs/client/PortModel.h @@ -43,19 +43,27 @@ public: // FIXME: metadataify enum Hint { NONE, INTEGER, TOGGLE, LOGARITHMIC }; - inline float value() const { return m_current_val; } - inline bool connected() const { return (m_connections > 0); } - inline string type() const { return m_type; } - inline bool is_input() const { return (m_direction == INPUT); } - inline bool is_output() const { return (m_direction == OUTPUT); } - inline bool is_audio() const { return (m_type == "ingen:audio"); } - inline bool is_control() const { return (m_type == "ingen:control"); } - inline bool is_midi() const { return (m_type == "ingen:midi"); } - inline bool is_logarithmic() const { return (m_hint == LOGARITHMIC); } - inline bool is_integer() const { return (m_hint == INTEGER); } - inline bool is_toggle() const { return (m_hint == TOGGLE); } + inline string type() const { return _type; } + inline float value() const { return _current_val; } + inline bool connected() const { return (_connections > 0); } + inline bool is_input() const { return (_direction == INPUT); } + inline bool is_output() const { return (_direction == OUTPUT); } + inline bool is_audio() const { return (_type == "ingen:audio"); } + inline bool is_control() const { return (_type == "ingen:control"); } + inline bool is_midi() const { return (_type == "ingen:midi"); } + inline bool is_logarithmic() const { return (_hint == LOGARITHMIC); } + inline bool is_integer() const { return (_hint == INTEGER); } + inline bool is_toggle() const { return (_hint == TOGGLE); } inline bool operator==(const PortModel& pm) const { return (_path == pm._path); } + + inline void value(float val) + { + if (val != _current_val) { + _current_val = val; + control_change_sig.emit(val); + } + } // Signals sigc::signal<void, float> control_change_sig; ///< "Control" ports only @@ -67,11 +75,11 @@ private: PortModel(const Path& path, const string& type, Direction dir, Hint hint) : ObjectModel(path), - m_type(type), - m_direction(dir), - m_hint(hint), - m_current_val(0.0f), - m_connections(0) + _type(type), + _direction(dir), + _hint(hint), + _current_val(0.0f), + _connections(0) { if (!is_audio() && !is_control() && !is_input()) cerr << "[PortModel] Warning: Unknown port type" << endl; @@ -79,29 +87,27 @@ private: PortModel(const Path& path, const string& type, Direction dir) : ObjectModel(path), - m_type(type), - m_direction(dir), - m_hint(NONE), - m_current_val(0.0f), - m_connections(0) + _type(type), + _direction(dir), + _hint(NONE), + _current_val(0.0f), + _connections(0) { if (!is_audio() && !is_control() && !is_input()) cerr << "[PortModel] Warning: Unknown port type" << endl; } - - inline void value(float f) { m_current_val = f; control_change_sig.emit(f); } void add_child(SharedPtr<ObjectModel> c) { throw; } void remove_child(SharedPtr<ObjectModel> c) { throw; } - void connected_to(SharedPtr<PortModel> p) { ++m_connections; connection_sig.emit(p); } - void disconnected_from(SharedPtr<PortModel> p) { --m_connections; disconnection_sig.emit(p); } + void connected_to(SharedPtr<PortModel> p) { ++_connections; connection_sig.emit(p); } + void disconnected_from(SharedPtr<PortModel> p) { --_connections; disconnection_sig.emit(p); } - string m_type; - Direction m_direction; - Hint m_hint; - float m_current_val; - size_t m_connections; + string _type; + Direction _direction; + Hint _hint; + float _current_val; + size_t _connections; }; typedef list<SharedPtr<PortModel> > PortModelList; diff --git a/src/libs/engine/GraphObject.h b/src/libs/engine/GraphObject.h index 1f3caa7b..b43ddf88 100644 --- a/src/libs/engine/GraphObject.h +++ b/src/libs/engine/GraphObject.h @@ -14,8 +14,8 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef OMOBJECT_H -#define OMOBJECT_H +#ifndef GRAPHOBJECT_H +#define GRAPHOBJECT_H #include <string> #include <map> @@ -113,4 +113,4 @@ private: } // namespace Ingen -#endif // OMOBJECT_H +#endif // GRAPHOBJECT_H diff --git a/src/progs/ingenuity/ControlGroups.cpp b/src/progs/ingenuity/ControlGroups.cpp index e228c140..bbd83ee8 100644 --- a/src/progs/ingenuity/ControlGroups.cpp +++ b/src/progs/ingenuity/ControlGroups.cpp @@ -118,6 +118,8 @@ SliderControlGroup::init(ControlPanel* panel, SharedPtr<PortModel> pm, bool sepa m_slider->set_range(min, max); + set_value(pm->value()); + m_enable_signal = true; show_all(); @@ -218,9 +220,9 @@ SliderControlGroup::update_value_from_slider() const float value = m_slider->get_value(); // Prevent spinner signal from doing all this over again (slow) m_enable_signal = false; - //m_value_spinner.set_value(value); - m_control_panel->value_changed(m_port_model->path(), value); - //m_port_model->value(value); + + m_control_panel->value_changed(m_port_model, value); + m_enable_signal = true; } } @@ -245,7 +247,7 @@ SliderControlGroup::update_value_from_spinner() m_slider->set_value(m_value_spinner.get_value()); - m_control_panel->value_changed(m_port_model->path(), value); + m_control_panel->value_changed(m_port_model, value); //m_port_model->value(value); m_enable_signal = true; @@ -342,7 +344,7 @@ IntegerControlGroup::update_value() { if (m_enable_signal) { float value = m_spinner.get_value(); - m_control_panel->value_changed(m_port_model->path(), value); + m_control_panel->value_changed(m_port_model, value); //m_port_model->value(value); } } @@ -413,7 +415,7 @@ ToggleControlGroup::update_value() { if (m_enable_signal) { float value = m_checkbutton.get_active() ? 1.0f : 0.0f; - m_control_panel->value_changed(m_port_model->path(), value); + m_control_panel->value_changed(m_port_model, value); //m_port_model->value(value); } } diff --git a/src/progs/ingenuity/ControlGroups.h b/src/progs/ingenuity/ControlGroups.h index 4994a809..fa43b77e 100644 --- a/src/progs/ingenuity/ControlGroups.h +++ b/src/progs/ingenuity/ControlGroups.h @@ -109,10 +109,11 @@ inline void SliderControlGroup::set_value(const float val) { m_enable_signal = false; - if (m_enabled) { - m_slider->set_value(val); + //if (m_enabled) { + if (m_slider->get_value() != val) + m_slider->set_value(val); //m_value_spinner->set_value(val); - } + //} m_enable_signal = true; } diff --git a/src/progs/ingenuity/ControlPanel.cpp b/src/progs/ingenuity/ControlPanel.cpp index faffae7a..4a96b480 100644 --- a/src/progs/ingenuity/ControlPanel.cpp +++ b/src/progs/ingenuity/ControlPanel.cpp @@ -211,16 +211,21 @@ ControlPanel::disable_port(const Path& path) /** Callback for ControlGroups to notify this of a change. */ void -ControlPanel::value_changed(const Path& port_path, float val) +ControlPanel::value_changed(SharedPtr<PortModel> port, float val) { if (m_callback_enabled) { App::instance().engine()->disable_responses(); + /* Send the message, but set the client-side model's value to the new + * setting right away (so the value doesn't need to be echoed back) */ + if (m_all_voices_radio->get_active()) { - App::instance().engine()->set_port_value(port_path, val); + App::instance().engine()->set_port_value(port->path(), val); + port->value(val); } else { int voice = m_voice_spinbutton->get_value_as_int(); - App::instance().engine()->set_port_value(port_path, voice, val); + App::instance().engine()->set_port_value(port->path(), voice, val); + port->value(val); } App::instance().engine()->set_next_response_id(rand()); // FIXME: inefficient, probably not good diff --git a/src/progs/ingenuity/ControlPanel.h b/src/progs/ingenuity/ControlPanel.h index 8d91df8d..f7a1cc5b 100644 --- a/src/progs/ingenuity/ControlPanel.h +++ b/src/progs/ingenuity/ControlPanel.h @@ -64,9 +64,9 @@ public: size_t num_controls() const { return m_controls.size(); } pair<int,int> ideal_size() const { return m_ideal_size; } - // Callback for ControlGroup (FIXME: ugly) - void value_changed(const Path& port_path, float val); - + // Callback for ControlGroup + void value_changed(SharedPtr<PortModel> port_path, float val); + private: void all_voices_selected(); void specific_voice_selected(); diff --git a/src/progs/ingenuity/Makefile.am b/src/progs/ingenuity/Makefile.am index 898a8b83..33829b9b 100644 --- a/src/progs/ingenuity/Makefile.am +++ b/src/progs/ingenuity/Makefile.am @@ -12,8 +12,8 @@ dist_desktopfiles_DATA = ingenuity.desktop globalpixmapsdir = $(datadir)/pixmaps dist_globalpixmaps_DATA = ingen-icon.svg -ingenuity_CXXFLAGS = -DGTK_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -I$(top_srcdir)/src/common -I$(top_srcdir)/src/libs/client -DPKGDATADIR=\"$(pkgdatadir)\" @GTKMM_CFLAGS@ @LIBGLADEMM_CFLAGS@ @GNOMECANVASMM_CFLAGS@ @LOSC_CFLAGS@ @LASH_CFLAGS@ @FLOWCANVAS_CFLAGS@ @RAUL_CFLAGS@ -ingenuity_LDADD = @GTKMM_LIBS@ @LIBGLADEMM_LIBS@ @GNOMECANVASMM_LIBS@ @LOSC_LIBS@ @LASH_LIBS@ @FLOWCANVAS_LIBS@ @RAUL_LIBS@ ../../libs/client/libingenclient.la +ingenuity_CXXFLAGS = -DGTK_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -I$(top_srcdir)/src/common -I$(top_srcdir)/src/libs/client -DPKGDATADIR=\"$(pkgdatadir)\" @RAUL_CFLAGS@ @GTKMM_CFLAGS@ @LIBGLADEMM_CFLAGS@ @GNOMECANVASMM_CFLAGS@ @LOSC_CFLAGS@ @LASH_CFLAGS@ @FLOWCANVAS_CFLAGS@ +ingenuity_LDADD = @RAUL_LIBS@ @GTKMM_LIBS@ @LIBGLADEMM_LIBS@ @GNOMECANVASMM_LIBS@ @LOSC_LIBS@ @LASH_LIBS@ @FLOWCANVAS_LIBS@ ../../libs/client/libingenclient.la ingenuity_DEPENDENCIES = ../../libs/client/libingenclient.la # FIXME: make engine have a separate include dir diff --git a/src/progs/ingenuity/main.cpp b/src/progs/ingenuity/main.cpp index d200c3d6..2456ff66 100644 --- a/src/progs/ingenuity/main.cpp +++ b/src/progs/ingenuity/main.cpp @@ -42,9 +42,6 @@ main(int argc, char** argv) if (args_info.client_port_given) client_port = args_info.client_port_arg; - // FIXME: - client_port = 16181; - Gnome::Canvas::init(); Gtk::Main gtk_main(argc, argv); |