2008-06-02 17:41:35 -04:00
|
|
|
|
/*
|
2019-08-02 23:10:55 -04:00
|
|
|
|
* Copyright (C) 2006-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
|
* Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
|
|
|
|
|
* Copyright (C) 2009 David Robillard <d@drobilla.net>
|
|
|
|
|
* Copyright (C) 2016-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
|
* Copyright (C) 2016 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* 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.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*/
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
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"
|
2016-09-03 08:11:19 -04:00
|
|
|
|
#include "pbd/types_convert.h"
|
|
|
|
|
#include "pbd/string_convert.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
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
|
PBD::Signal1<bool, std::weak_ptr<PBD::Controllable> > Controllable::StartLearning;
|
|
|
|
|
PBD::Signal1<void, std::weak_ptr<PBD::Controllable> > Controllable::StopLearning;
|
|
|
|
|
PBD::Signal1<void, std::weak_ptr<PBD::Controllable> > Controllable::GUIFocusChanged;
|
|
|
|
|
PBD::Signal1<void, std::weak_ptr<PBD::Controllable> > Controllable::ControlTouched;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
2019-03-22 22:10:49 -04:00
|
|
|
|
Glib::Threads::RWLock Controllable::registry_lock;
|
|
|
|
|
Controllable::Controllables Controllable::registry;
|
|
|
|
|
PBD::ScopedConnectionList Controllable::registry_connections;
|
|
|
|
|
|
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)
|
2019-03-22 22:10:49 -04:00
|
|
|
|
{
|
|
|
|
|
add (*this);
|
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
|
|
XMLNode&
|
2022-04-06 23:56:32 -04:00
|
|
|
|
Controllable::get_state () const
|
2008-06-02 17:41:35 -04:00
|
|
|
|
{
|
2010-11-27 12:43:32 -05:00
|
|
|
|
XMLNode* node = new XMLNode (xml_node_name);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
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
|
|
|
|
|
|
2016-09-03 08:11:19 -04:00
|
|
|
|
node->set_property (X_("name"), _name);
|
|
|
|
|
node->set_property (X_("id"), id());
|
|
|
|
|
node->set_property (X_("flags"), _flags);
|
|
|
|
|
node->set_property (X_("value"), get_save_value());
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
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
|
|
|
|
|
2016-09-03 08:11:19 -04:00
|
|
|
|
if (node.get_property (X_("flags"), _flags)) {
|
|
|
|
|
_flags = Flag(_flags | (_flags & Controllable::RealTime));
|
2009-12-10 21:00:22 -05:00
|
|
|
|
}
|
2010-11-27 12:43:32 -05:00
|
|
|
|
|
2016-09-03 08:11:19 -04:00
|
|
|
|
float val;
|
|
|
|
|
if (node.get_property (X_("value"), val)) {
|
2016-01-02 04:58:23 -05:00
|
|
|
|
set_value (val, NoGroup);
|
2016-09-03 08:11:19 -04: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;
|
|
|
|
|
}
|
2019-03-22 22:10:49 -04:00
|
|
|
|
|
2020-03-10 15:17:40 -04:00
|
|
|
|
void
|
|
|
|
|
Controllable::set_flag (Flag f)
|
|
|
|
|
{
|
|
|
|
|
_flags = Flag ((int)_flags | f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Controllable::clear_flag (Flag f)
|
|
|
|
|
{
|
|
|
|
|
_flags = Flag ((int)_flags & ~f);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-22 22:10:49 -04:00
|
|
|
|
void
|
|
|
|
|
Controllable::add (Controllable& ctl)
|
|
|
|
|
{
|
|
|
|
|
Glib::Threads::RWLock::WriterLock lm (registry_lock);
|
|
|
|
|
registry.insert (&ctl);
|
|
|
|
|
ctl.DropReferences.connect_same_thread (registry_connections, boost::bind (&Controllable::remove, &ctl));
|
2019-03-23 09:32:00 -04:00
|
|
|
|
ctl.Destroyed.connect_same_thread (registry_connections, boost::bind (&Controllable::remove, &ctl));
|
2019-03-22 22:10:49 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Controllable::remove (Controllable* ctl)
|
|
|
|
|
{
|
|
|
|
|
Glib::Threads::RWLock::WriterLock lm (registry_lock);
|
|
|
|
|
Controllables::iterator i = std::find (registry.begin(), registry.end(), ctl);
|
|
|
|
|
if (i != registry.end()) {
|
|
|
|
|
registry.erase (i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
|
std::shared_ptr<Controllable>
|
2019-03-22 22:10:49 -04:00
|
|
|
|
Controllable::by_id (const ID& id)
|
|
|
|
|
{
|
|
|
|
|
Glib::Threads::RWLock::ReaderLock lm (registry_lock);
|
|
|
|
|
|
|
|
|
|
for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i) {
|
|
|
|
|
if ((*i)->id() == id) {
|
|
|
|
|
return (*i)->shared_from_this ();
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-16 18:33:28 -05:00
|
|
|
|
return std::shared_ptr<Controllable>();
|
2019-03-22 22:10:49 -04:00
|
|
|
|
}
|
2019-03-23 09:32:00 -04:00
|
|
|
|
|
2022-10-17 17:22:39 -04:00
|
|
|
|
ControllableSet
|
2022-05-17 17:29:08 -04:00
|
|
|
|
Controllable::registered_controllables ()
|
|
|
|
|
{
|
|
|
|
|
ControllableSet rv;
|
|
|
|
|
Glib::Threads::RWLock::ReaderLock lm (registry_lock);
|
|
|
|
|
for (auto const& i : registry) {
|
2022-07-07 10:04:56 -04:00
|
|
|
|
try {
|
|
|
|
|
rv.insert (i->shared_from_this ());
|
|
|
|
|
} catch (...) {
|
|
|
|
|
/* ignore boost::bad_weak_ptr */
|
|
|
|
|
// cout << "No shared ctrl: " << i->name() << "\n";
|
|
|
|
|
}
|
2022-05-17 17:29:08 -04:00
|
|
|
|
}
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-23 09:32:00 -04:00
|
|
|
|
void
|
|
|
|
|
Controllable::dump_registry ()
|
|
|
|
|
{
|
|
|
|
|
Glib::Threads::RWLock::ReaderLock lm (registry_lock);
|
2019-09-05 13:04:32 -04:00
|
|
|
|
if (registry.size() == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-03-23 09:32:00 -04:00
|
|
|
|
unsigned int cnt = 0;
|
|
|
|
|
cout << "-- List Of Registered Controllables\n";
|
|
|
|
|
for (Controllables::iterator i = registry.begin(); i != registry.end(); ++i, ++cnt) {
|
|
|
|
|
cout << "CTRL: " << (*i)->name() << "\n";
|
|
|
|
|
}
|
2020-08-03 09:39:14 -04:00
|
|
|
|
cout << "Total number of registered controllables: " << cnt << "\n";
|
2019-03-23 09:32:00 -04:00
|
|
|
|
}
|
2020-06-18 18:26:44 -04:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Controllable::set_interface (float fraction, bool rotary, GroupControlDisposition gcd)
|
|
|
|
|
{
|
|
|
|
|
fraction = std::min (std::max (0.0f, fraction), 1.0f);
|
|
|
|
|
set_value (interface_to_internal (fraction, rotary), gcd);
|
|
|
|
|
}
|