2008-06-02 17:41:35 -04:00
|
|
|
|
/*
|
2015-10-04 14:51:05 -04:00
|
|
|
|
Copyright (C) 2000-2007 Paul Davis
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
|
#include "pbd/controllable.h"
|
2009-12-30 11:48:58 -05:00
|
|
|
|
#include "pbd/enumwriter.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
|
#include "pbd/xml++.h"
|
|
|
|
|
#include "pbd/error.h"
|
2010-11-28 13:31:18 -05:00
|
|
|
|
#include "pbd/locale_guard.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
|
#include "pbd/i18n.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
|
|
using namespace PBD;
|
2009-12-10 22:18:17 -05:00
|
|
|
|
using namespace std;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
2009-12-19 15:26:31 -05:00
|
|
|
|
PBD::Signal1<void,Controllable*> Controllable::Destroyed;
|
|
|
|
|
PBD::Signal1<bool,Controllable*> Controllable::StartLearning;
|
|
|
|
|
PBD::Signal1<void,Controllable*> Controllable::StopLearning;
|
|
|
|
|
PBD::Signal3<void,Controllable*,int,int> Controllable::CreateBinding;
|
|
|
|
|
PBD::Signal1<void,Controllable*> Controllable::DeleteBinding;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
2012-07-25 13:48:55 -04:00
|
|
|
|
Glib::Threads::RWLock Controllable::registry_lock;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
Controllable::Controllables Controllable::registry;
|
2012-05-15 11:32:53 -04:00
|
|
|
|
PBD::ScopedConnectionList* registry_connections = 0;
|
2010-11-27 12:43:32 -05:00
|
|
|
|
const std::string Controllable::xml_node_name = X_("Controllable");
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
2009-12-30 11:48:58 -05:00
|
|
|
|
Controllable::Controllable (const string& name, Flag f)
|
2008-06-02 17:41:35 -04:00
|
|
|
|
: _name (name)
|
2009-12-30 11:48:58 -05:00
|
|
|
|
, _flags (f)
|
2009-12-31 14:49:22 -05:00
|
|
|
|
, _touching (false)
|
2008-06-02 17:41:35 -04:00
|
|
|
|
{
|
2009-12-17 13:24:23 -05:00
|
|
|
|
add (*this);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-12-17 13:24:23 -05:00
|
|
|
|
Controllable::add (Controllable& ctl)
|
2008-06-02 17:41:35 -04:00
|
|
|
|
{
|
2009-12-17 13:24:23 -05:00
|
|
|
|
using namespace boost;
|
|
|
|
|
|
2012-07-25 13:48:55 -04:00
|
|
|
|
Glib::Threads::RWLock::WriterLock lm (registry_lock);
|
2009-12-17 13:24:23 -05:00
|
|
|
|
registry.insert (&ctl);
|
2009-12-10 21:00:22 -05:00
|
|
|
|
|
2012-05-15 11:32:53 -04:00
|
|
|
|
if (!registry_connections) {
|
|
|
|
|
registry_connections = new ScopedConnectionList;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-17 13:24:23 -05:00
|
|
|
|
/* Controllable::remove() is static - no need to manage this connection */
|
|
|
|
|
|
2012-05-15 11:32:53 -04:00
|
|
|
|
ctl.DropReferences.connect_same_thread (*registry_connections, boost::bind (&Controllable::remove, &ctl));
|
2008-06-02 17:41:35 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2009-12-22 15:21:43 -05:00
|
|
|
|
Controllable::remove (Controllable* ctl)
|
2008-06-02 17:41:35 -04:00
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
|
Glib::Threads::RWLock::WriterLock lm (registry_lock);
|
2009-12-10 21:00:22 -05:00
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
|
for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
|
2009-12-22 15:21:43 -05:00
|
|
|
|
if ((*i) == ctl) {
|
2008-06-02 17:41:35 -04:00
|
|
|
|
registry.erase (i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Controllable*
|
|
|
|
|
Controllable::by_id (const ID& id)
|
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
|
Glib::Threads::RWLock::ReaderLock lm (registry_lock);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
|
|
for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
|
|
|
|
|
if ((*i)->id() == id) {
|
|
|
|
|
return (*i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Controllable*
|
2009-12-10 22:18:17 -05:00
|
|
|
|
Controllable::by_name (const string& str)
|
2008-06-02 17:41:35 -04:00
|
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
|
Glib::Threads::RWLock::ReaderLock lm (registry_lock);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
|
|
for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
|
|
|
|
|
if ((*i)->_name == str) {
|
|
|
|
|
return (*i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
XMLNode&
|
|
|
|
|
Controllable::get_state ()
|
|
|
|
|
{
|
2010-11-27 12:43:32 -05:00
|
|
|
|
XMLNode* node = new XMLNode (xml_node_name);
|
2016-05-07 06:19:41 -04:00
|
|
|
|
LocaleGuard lg;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
char buf[64];
|
|
|
|
|
|
2016-01-27 17:39:35 -05:00
|
|
|
|
/* Waves' "Pressure3" has a parameter called "µ-iness"
|
|
|
|
|
* which causes a parser error : Input is not proper UTF-8, indicate encoding !
|
|
|
|
|
* Bytes: 0xB5 0x2D 0x69 0x6E
|
|
|
|
|
* <Controllable name="<EFBFBD>-iness" id="2391" flags="" value="0.000000000000" p
|
|
|
|
|
*/
|
2016-02-03 11:42:40 -05:00
|
|
|
|
|
|
|
|
|
// this is not reloaded from XML, but it must be present because it is
|
|
|
|
|
// used to find and identify XML nodes by various Controllable-derived objects
|
|
|
|
|
|
|
|
|
|
node->add_property (X_("name"), _name);
|
2016-01-27 17:39:35 -05:00
|
|
|
|
|
2011-10-18 09:18:47 -04:00
|
|
|
|
id().print (buf, sizeof (buf));
|
2008-06-02 17:41:35 -04:00
|
|
|
|
node->add_property (X_("id"), buf);
|
2009-12-30 11:48:58 -05:00
|
|
|
|
node->add_property (X_("flags"), enum_2_string (_flags));
|
2010-11-27 12:43:32 -05:00
|
|
|
|
snprintf (buf, sizeof (buf), "%2.12f", get_value());
|
|
|
|
|
node->add_property (X_("value"), buf);
|
2009-12-10 21:00:22 -05:00
|
|
|
|
|
2011-06-11 11:35:34 -04:00
|
|
|
|
if (_extra_xml) {
|
|
|
|
|
node->add_child_copy (*_extra_xml);
|
|
|
|
|
}
|
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
|
return *node;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-28 13:31:18 -05:00
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
|
int
|
2009-10-20 20:15:42 -04:00
|
|
|
|
Controllable::set_state (const XMLNode& node, int /*version*/)
|
2008-06-02 17:41:35 -04:00
|
|
|
|
{
|
2016-05-07 06:19:41 -04:00
|
|
|
|
LocaleGuard lg;
|
2009-12-10 21:00:22 -05:00
|
|
|
|
const XMLProperty* prop;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
2011-06-11 11:35:34 -04:00
|
|
|
|
Stateful::save_extra_xml (node);
|
|
|
|
|
|
2011-11-16 18:03:59 -05:00
|
|
|
|
set_id (node);
|
2009-12-10 21:00:22 -05:00
|
|
|
|
|
2009-12-30 11:48:58 -05:00
|
|
|
|
if ((prop = node.property (X_("flags"))) != 0) {
|
|
|
|
|
_flags = (Flag) string_2_enum (prop->value(), _flags);
|
2009-12-10 21:00:22 -05:00
|
|
|
|
}
|
2010-11-27 12:43:32 -05:00
|
|
|
|
|
|
|
|
|
if ((prop = node.property (X_("value"))) != 0) {
|
|
|
|
|
float val;
|
|
|
|
|
|
|
|
|
|
if (sscanf (prop->value().c_str(), "%f", &val) == 1) {
|
2016-01-02 04:58:23 -05:00
|
|
|
|
set_value (val, NoGroup);
|
2015-10-04 14:51:05 -04:00
|
|
|
|
}
|
2010-11-28 13:31:18 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
}
|
2009-12-30 11:48:58 -05:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Controllable::set_flags (Flag f)
|
|
|
|
|
{
|
|
|
|
|
_flags = f;
|
|
|
|
|
}
|