summaryrefslogtreecommitdiff
path: root/libs/pbd
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2009-12-30 16:48:58 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2009-12-30 16:48:58 +0000
commit74933f58659051f6d4ef52d1103b2b7ba4643883 (patch)
tree93069fda3163dce2e97b61a845863b68b300200d /libs/pbd
parent8a17b0fb9073bb21ef2c718113f9e41359faf4fe (diff)
restore excess calls to sync-order stuff (for now); allow MIDI controllers to use the same non-linear fader response as the gui; add various flags to PBD::Controllable and remove URI from that class
git-svn-id: svn://localhost/ardour2/branches/3.0@6414 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd')
-rw-r--r--libs/pbd/controllable.cc70
-rw-r--r--libs/pbd/enums.cc47
-rw-r--r--libs/pbd/enumwriter.cc13
-rw-r--r--libs/pbd/pbd/controllable.h34
-rw-r--r--libs/pbd/pbd/enumwriter.h8
-rw-r--r--libs/pbd/wscript1
6 files changed, 97 insertions, 76 deletions
diff --git a/libs/pbd/controllable.cc b/libs/pbd/controllable.cc
index be487a0a87..d5b81a73ed 100644
--- a/libs/pbd/controllable.cc
+++ b/libs/pbd/controllable.cc
@@ -18,6 +18,7 @@
*/
#include "pbd/controllable.h"
+#include "pbd/enumwriter.h"
#include "pbd/xml++.h"
#include "pbd/error.h"
@@ -34,13 +35,11 @@ PBD::Signal1<void,Controllable*> Controllable::DeleteBinding;
Glib::StaticRWLock Controllable::registry_lock = GLIBMM_STATIC_RW_LOCK_INIT;
Controllable::Controllables Controllable::registry;
-Controllable::ControllablesByURI Controllable::registry_by_uri;
PBD::ScopedConnectionList registry_connections;
-Controllable::Controllable (const string& name, const string& uri)
+Controllable::Controllable (const string& name, Flag f)
: _name (name)
- , _uri (uri)
- , _touching (false)
+ , _flags (f)
{
add (*this);
}
@@ -53,13 +52,6 @@ Controllable::add (Controllable& ctl)
Glib::RWLock::WriterLock lm (registry_lock);
registry.insert (&ctl);
- if (!ctl.uri().empty()) {
- pair<string,Controllable*> newpair;
- newpair.first = ctl.uri();
- newpair.second = &ctl;
- registry_by_uri.insert (newpair);
- }
-
/* Controllable::remove() is static - no need to manage this connection */
ctl.DropReferences.connect_same_thread (registry_connections, boost::bind (&Controllable::remove, &ctl));
@@ -76,35 +68,6 @@ Controllable::remove (Controllable* ctl)
break;
}
}
-
- if (!ctl->uri().empty()) {
- ControllablesByURI::iterator i = registry_by_uri.find (ctl->uri());
- if (i != registry_by_uri.end()) {
- registry_by_uri.erase (i);
- }
- }
-}
-
-void
-Controllable::set_uri (const string& new_uri)
-{
- Glib::RWLock::WriterLock lm (registry_lock);
-
- if (!_uri.empty()) {
- ControllablesByURI::iterator i = registry_by_uri.find (_uri);
- if (i != registry_by_uri.end()) {
- registry_by_uri.erase (i);
- }
- }
-
- _uri = new_uri;
-
- if (!_uri.empty()) {
- pair<string,Controllable*> newpair;
- newpair.first = _uri;
- newpair.second = this;
- registry_by_uri.insert (newpair);
- }
}
Controllable*
@@ -121,18 +84,6 @@ Controllable::by_id (const ID& id)
}
Controllable*
-Controllable::by_uri (const string& uri)
-{
- Glib::RWLock::ReaderLock lm (registry_lock);
- ControllablesByURI::iterator i;
-
- if ((i = registry_by_uri.find (uri)) != registry_by_uri.end()) {
- return i->second;
- }
- return 0;
-}
-
-Controllable*
Controllable::by_name (const string& str)
{
Glib::RWLock::ReaderLock lm (registry_lock);
@@ -154,11 +105,8 @@ Controllable::get_state ()
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));
- if (!_uri.empty()) {
- node->add_property (X_("uri"), _uri);
- }
-
return *node;
}
@@ -175,7 +123,13 @@ Controllable::set_state (const XMLNode& node, int /*version*/)
return -1;
}
- if ((prop = node.property (X_("uri"))) != 0) {
- set_uri (prop->value());
+ if ((prop = node.property (X_("flags"))) != 0) {
+ _flags = (Flag) string_2_enum (prop->value(), _flags);
}
}
+
+void
+Controllable::set_flags (Flag f)
+{
+ _flags = f;
+}
diff --git a/libs/pbd/enums.cc b/libs/pbd/enums.cc
new file mode 100644
index 0000000000..559af3a307
--- /dev/null
+++ b/libs/pbd/enums.cc
@@ -0,0 +1,47 @@
+/*
+ Copyright (C) 2009 Paul Davis
+
+ 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.
+
+*/
+
+#include "pbd/controllable.h"
+#include "pbd/enumwriter.h"
+
+void setup_libpbd_enums () __attribute__ ((constructor));
+
+using namespace PBD;
+using namespace std;
+
+void
+setup_libpbd_enums ()
+{
+ EnumWriter& enum_writer (EnumWriter::instance());
+ vector<int> i;
+ vector<string> s;
+
+ Controllable::Flag controllable_flags;
+
+#define REGISTER(e) enum_writer.register_distinct (typeid(e).name(), i, s); i.clear(); s.clear()
+#define REGISTER_BITS(e) enum_writer.register_bits (typeid(e).name(), i, s); i.clear(); s.clear()
+#define REGISTER_ENUM(e) i.push_back (e); s.push_back (#e)
+#define REGISTER_CLASS_ENUM(t,e) i.push_back (t::e); s.push_back (#e)
+
+ REGISTER_CLASS_ENUM (Controllable, Toggle);
+ REGISTER_CLASS_ENUM (Controllable, Discrete);
+ REGISTER_CLASS_ENUM (Controllable, GainLike);
+ REGISTER_CLASS_ENUM (Controllable, IntegerOnly);
+ REGISTER (controllable_flags);
+}
diff --git a/libs/pbd/enumwriter.cc b/libs/pbd/enumwriter.cc
index 134a00a207..2c6e5c73c8 100644
--- a/libs/pbd/enumwriter.cc
+++ b/libs/pbd/enumwriter.cc
@@ -63,11 +63,18 @@ nocase_cmp(const string & s1, const string& s2)
return (size1 < size2) ? -1 : 1;
}
-EnumWriter::EnumWriter ()
+EnumWriter&
+EnumWriter::instance()
{
if (_instance == 0) {
- _instance = this;
- }
+ _instance = new EnumWriter;
+ }
+
+ return *_instance;
+}
+
+EnumWriter::EnumWriter ()
+{
}
EnumWriter::~EnumWriter ()
diff --git a/libs/pbd/pbd/controllable.h b/libs/pbd/pbd/controllable.h
index 28dd4b7a31..f8d8f82855 100644
--- a/libs/pbd/pbd/controllable.h
+++ b/libs/pbd/pbd/controllable.h
@@ -35,12 +35,16 @@ namespace PBD {
class Controllable : public PBD::StatefulDestructible {
public:
- Controllable (const std::string& name, const std::string& uri);
+ enum Flag {
+ Toggle = 0x1,
+ Discrete = 0x2,
+ GainLike = 0x4,
+ IntegerOnly = 0x8
+ };
+
+ Controllable (const std::string& name, Flag f = Flag (0));
virtual ~Controllable() { Destroyed (this); }
- void set_uri (const std::string&);
- const std::string& uri() const { return _uri; }
-
virtual void set_value (float) = 0;
virtual float get_value (void) const = 0;
@@ -59,27 +63,35 @@ class Controllable : public PBD::StatefulDestructible {
XMLNode& get_state ();
std::string name() const { return _name; }
- bool touching () const { return _touching; }
-
+
+ bool touching () const { return _touching; }
void set_touching (bool yn) { _touching = yn; }
+ bool is_toggle() const { return _flags & Toggle; }
+ bool is_discrete() const { return _flags & Discrete; }
+ bool is_gain_like() const { return _flags & GainLike; }
+ bool is_integral_only() const { return _flags & IntegerOnly; }
+
+ Flag flags() const { return _flags; }
+ void set_flags (Flag f);
+
+ virtual uint32_t get_discrete_values (std::list<float>&) { return 0; /* no values returned */ }
+
static Controllable* by_id (const PBD::ID&);
static Controllable* by_name (const std::string&);
- static Controllable* by_uri (const std::string&);
private:
std::string _name;
- std::string _uri;
+
+ Flag _flags;
bool _touching;
static void add (Controllable&);
static void remove (Controllable*);
typedef std::set<PBD::Controllable*> Controllables;
- typedef std::map<std::string,PBD::Controllable*> ControllablesByURI;
static Glib::StaticRWLock registry_lock;
static Controllables registry;
- static ControllablesByURI registry_by_uri;
};
/* a utility class for the occasions when you need but do not have
@@ -89,7 +101,7 @@ class Controllable : public PBD::StatefulDestructible {
class IgnorableControllable : public Controllable
{
public:
- IgnorableControllable () : PBD::Controllable ("ignoreMe", std::string()) {}
+ IgnorableControllable () : PBD::Controllable ("ignoreMe") {}
~IgnorableControllable () {}
void set_value (float /*v*/) {}
diff --git a/libs/pbd/pbd/enumwriter.h b/libs/pbd/pbd/enumwriter.h
index 63a8ef6f6e..461665d739 100644
--- a/libs/pbd/pbd/enumwriter.h
+++ b/libs/pbd/pbd/enumwriter.h
@@ -36,10 +36,7 @@ class unknown_enumeration : public std::exception {
class EnumWriter {
public:
- EnumWriter ();
- ~EnumWriter ();
-
- static EnumWriter& instance() { return *_instance; }
+ static EnumWriter& instance();
void register_distinct (std::string type, std::vector<int>, std::vector<std::string>);
void register_bits (std::string type, std::vector<int>, std::vector<std::string>);
@@ -50,6 +47,9 @@ class EnumWriter {
void add_to_hack_table (std::string str, std::string hacked_str);
private:
+ EnumWriter ();
+ ~EnumWriter ();
+
struct EnumRegistration {
std::vector<int> values;
std::vector<std::string> names;
diff --git a/libs/pbd/wscript b/libs/pbd/wscript
index b25d8059ce..3794a37e81 100644
--- a/libs/pbd/wscript
+++ b/libs/pbd/wscript
@@ -61,6 +61,7 @@ def build(bld):
enumwriter.cc
event_loop.cc
dmalloc.cc
+ enums.cc
error.cc
filesystem.cc
filesystem_paths.cc