From 7cbcf258ccac270d769ade00bc39edef518d679d Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sat, 27 Nov 2010 17:43:32 +0000 Subject: changes associated with save/restore of AutomationControl id's git-svn-id: svn://localhost/ardour2/branches/3.0@8111 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/pbd/controllable.cc | 13 ++++++++++++- libs/pbd/pbd/controllable.h | 2 +- libs/surfaces/generic_midi/generic_midi_control_protocol.cc | 12 ++++++++---- libs/surfaces/generic_midi/midicontrollable.cc | 6 ++++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/libs/pbd/controllable.cc b/libs/pbd/controllable.cc index 38780bddbe..b79a523a00 100644 --- a/libs/pbd/controllable.cc +++ b/libs/pbd/controllable.cc @@ -36,6 +36,7 @@ PBD::Signal1 Controllable::DeleteBinding; Glib::StaticRWLock Controllable::registry_lock = GLIBMM_STATIC_RW_LOCK_INIT; Controllable::Controllables Controllable::registry; PBD::ScopedConnectionList registry_connections; +const std::string Controllable::xml_node_name = X_("Controllable"); Controllable::Controllable (const string& name, Flag f) : _name (name) @@ -100,13 +101,15 @@ Controllable::by_name (const string& str) XMLNode& Controllable::get_state () { - XMLNode* node = new XMLNode (X_("Controllable")); + XMLNode* node = new XMLNode (xml_node_name); char buf[64]; node->add_property (X_("name"), _name); // not reloaded from XML state, just there to look at _id.print (buf, sizeof (buf)); node->add_property (X_("id"), buf); node->add_property (X_("flags"), enum_2_string (_flags)); + snprintf (buf, sizeof (buf), "%2.12f", get_value()); + node->add_property (X_("value"), buf); return *node; } @@ -127,6 +130,14 @@ Controllable::set_state (const XMLNode& node, int /*version*/) if ((prop = node.property (X_("flags"))) != 0) { _flags = (Flag) string_2_enum (prop->value(), _flags); } + + if ((prop = node.property (X_("value"))) != 0) { + float val; + + if (sscanf (prop->value().c_str(), "%f", &val) == 1) { + set_value (val); + } + } } void diff --git a/libs/pbd/pbd/controllable.h b/libs/pbd/pbd/controllable.h index 3ae27f72c2..d0769ffd01 100644 --- a/libs/pbd/pbd/controllable.h +++ b/libs/pbd/pbd/controllable.h @@ -82,7 +82,7 @@ class Controllable : public PBD::StatefulDestructible { static Controllable* by_id (const PBD::ID&); static Controllable* by_name (const std::string&); - + static const std::string xml_node_name; private: std::string _name; diff --git a/libs/surfaces/generic_midi/generic_midi_control_protocol.cc b/libs/surfaces/generic_midi/generic_midi_control_protocol.cc index 32f17e1156..1275eb2222 100644 --- a/libs/surfaces/generic_midi/generic_midi_control_protocol.cc +++ b/libs/surfaces/generic_midi/generic_midi_control_protocol.cc @@ -450,7 +450,7 @@ GenericMidiControlProtocol::get_state () node->add_property ("binding", _current_binding); } - XMLNode* children = new XMLNode (X_("controls")); + XMLNode* children = new XMLNode (X_("Controls")); node->add_child_nocopy (*children); @@ -504,7 +504,7 @@ GenericMidiControlProtocol::set_state (const XMLNode& node, int version) { Glib::Mutex::Lock lm2 (controllables_lock); controllables.clear (); - nlist = node.children(); // "controls" + nlist = node.children(); // "Controls" if (nlist.empty()) { return 0; @@ -515,13 +515,17 @@ GenericMidiControlProtocol::set_state (const XMLNode& node, int version) for (niter = nlist.begin(); niter != nlist.end(); ++niter) { if ((prop = (*niter)->property ("id")) != 0) { + + cerr << "Looking for MIDI Controllable with ID " << prop->value() << endl; ID id = prop->value (); - c = session->controllable_by_id (id); + Controllable* c = Controllable::by_id (id); + + cerr << "\tresult = " << c << endl; if (c) { MIDIControllable* mc = new MIDIControllable (*_input_port, *c, false); - + if (mc->set_state (**niter, version) == 0) { controllables.push_back (mc); } diff --git a/libs/surfaces/generic_midi/midicontrollable.cc b/libs/surfaces/generic_midi/midicontrollable.cc index 33780eea34..2319b6c433 100644 --- a/libs/surfaces/generic_midi/midicontrollable.cc +++ b/libs/surfaces/generic_midi/midicontrollable.cc @@ -430,9 +430,11 @@ MIDIControllable::get_state () XMLNode* node = new XMLNode ("MIDIControllable"); - if (!_current_uri.empty()) { + if (_current_uri.empty()) { + node->add_property ("id", controllable->id().to_s()); + } else { node->add_property ("uri", _current_uri); - } + } if (controllable) { snprintf (buf, sizeof(buf), "0x%x", (int) control_type); -- cgit v1.2.3