summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2007-02-09 03:36:00 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2007-02-09 03:36:00 +0000
commit14543eb1374dc51834385d2f3886f1e6068223c5 (patch)
tree5194d0a983b77d79f5310f1216129e84c64f6a42 /libs
parent138b12b1dd5b7e6175b3349b8ed7fa8b16721809 (diff)
strip X specific from keyboard.cc; fix up many buttons to avoid prelight (mostly) and make transport buttons bindable (state not saved yet); use const char* not string in route order keys to avoid pointless mallocs during route sorting
git-svn-id: svn://localhost/ardour2/trunk@1437 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/ardour/route.h15
-rw-r--r--libs/ardour/globals.cc2
-rw-r--r--libs/ardour/route.cc24
-rw-r--r--libs/gtkmm2ext/bindable_button.cc13
-rw-r--r--libs/gtkmm2ext/gtkmm2ext/bindable_button.h35
-rw-r--r--libs/gtkmm2ext/gtkmm2ext/stateful_button.h49
-rw-r--r--libs/gtkmm2ext/stateful_button.cc114
7 files changed, 167 insertions, 85 deletions
diff --git a/libs/ardour/ardour/route.h b/libs/ardour/ardour/route.h
index 869d7eb239..d4f94ed744 100644
--- a/libs/ardour/ardour/route.h
+++ b/libs/ardour/ardour/route.h
@@ -78,8 +78,8 @@ class Route : public IO
std::string comment() { return _comment; }
void set_comment (std::string str, void *src);
- long order_key(std::string name) const;
- void set_order_key (std::string name, long n);
+ long order_key (const char* name) const;
+ void set_order_key (const char* name, long n);
bool hidden() const { return _flags & Hidden; }
bool master() const { return _flags & MasterOut; }
@@ -321,7 +321,16 @@ class Route : public IO
void init ();
static uint32_t order_key_cnt;
- typedef std::map<std::string,long> OrderKeys;
+
+ struct ltstr
+ {
+ bool operator()(const char* s1, const char* s2) const
+ {
+ return strcmp(s1, s2) < 0;
+ }
+ };
+
+ typedef std::map<const char*,long,ltstr> OrderKeys;
OrderKeys order_keys;
void input_change_handler (IOChange, void *src);
diff --git a/libs/ardour/globals.cc b/libs/ardour/globals.cc
index d0ee94dca7..c9e663e984 100644
--- a/libs/ardour/globals.cc
+++ b/libs/ardour/globals.cc
@@ -279,8 +279,6 @@ ARDOUR::init (bool use_vst, bool try_optimization)
(void) bindtextdomain(PACKAGE, LOCALEDIR);
- PBD::ID::init ();
-
setup_enum_writer ();
lrdf_init();
diff --git a/libs/ardour/route.cc b/libs/ardour/route.cc
index 2ac94cd239..6915b32792 100644
--- a/libs/ardour/route.cc
+++ b/libs/ardour/route.cc
@@ -79,7 +79,7 @@ Route::init ()
_soloed = false;
_solo_safe = false;
_phase_invert = false;
- order_keys[N_("signal")] = order_key_cnt++;
+ order_keys[strdup (N_("signal"))] = order_key_cnt++;
_active = true;
_silent = false;
_meter_point = MeterPostFader;
@@ -115,6 +115,10 @@ Route::~Route ()
{
clear_redirects (this);
+ for (OrderKeys::iterator i = order_keys.begin(); i != order_keys.end(); ++i) {
+ free ((void*)(i->first));
+ }
+
if (_control_outs) {
delete _control_outs;
}
@@ -136,21 +140,23 @@ Route::remote_control_id() const
}
long
-Route::order_key (string name) const
+Route::order_key (const char* name) const
{
OrderKeys::const_iterator i;
- if ((i = order_keys.find (name)) == order_keys.end()) {
- return -1;
+ for (i = order_keys.begin(); i != order_keys.end(); ++i) {
+ if (!strcmp (name, i->first)) {
+ return i->second;
+ }
}
- return (*i).second;
+ return -1;
}
void
-Route::set_order_key (string name, long n)
+Route::set_order_key (const char* name, long n)
{
- order_keys[name] = n;
+ order_keys[strdup(name)] = n;
_session.set_dirty ();
}
@@ -1396,7 +1402,7 @@ Route::state(bool full_state)
OrderKeys::iterator x = order_keys.begin();
while (x != order_keys.end()) {
- order_string += (*x).first;
+ order_string += string ((*x).first);
order_string += '=';
snprintf (buf, sizeof(buf), "%ld", (*x).second);
order_string += buf;
@@ -1611,7 +1617,7 @@ Route::_set_state (const XMLNode& node, bool call_base)
error << string_compose (_("badly formed order key string in state file! [%1] ... ignored."), remaining)
<< endmsg;
} else {
- set_order_key (remaining.substr (0, equal), n);
+ set_order_key (remaining.substr (0, equal).c_str(), n);
}
}
diff --git a/libs/gtkmm2ext/bindable_button.cc b/libs/gtkmm2ext/bindable_button.cc
index 76b89deb02..3c3cad6e46 100644
--- a/libs/gtkmm2ext/bindable_button.cc
+++ b/libs/gtkmm2ext/bindable_button.cc
@@ -42,7 +42,7 @@ BindableToggleButton::BindableToggleButton (MIDI::Controllable *mc)
}
BindableToggleButton::BindableToggleButton(MIDI::Controllable *mc, const string &label)
- : ToggleButton (label),
+ : StatefulButton (label),
prompter (Gtk::WIN_POS_MOUSE, 30000, false),
midi_control (mc),
bind_button (2),
@@ -90,17 +90,6 @@ BindableToggleButton::midi_learn()
}
bool
-BindableToggleButton::on_button_press_event (GdkEventButton *ev)
-{
- if ((ev->state & bind_statemask) && ev->button == bind_button) {
- midi_learn ();
- return true;
- }
-
- return false;
-}
-
-bool
BindableToggleButton::prompter_hiding (GdkEventAny *ev)
{
if (unprompting) {
diff --git a/libs/gtkmm2ext/gtkmm2ext/bindable_button.h b/libs/gtkmm2ext/gtkmm2ext/bindable_button.h
index 1936125405..845d3fa49e 100644
--- a/libs/gtkmm2ext/gtkmm2ext/bindable_button.h
+++ b/libs/gtkmm2ext/gtkmm2ext/bindable_button.h
@@ -30,15 +30,44 @@ namespace PBD {
class Controllable;
}
-class BindableToggleButton : public Gtk::ToggleButton
+class BindableToggleButton : public Gtkmm2ext::StatefulToggleButton
{
public:
BindableToggleButton (PBD::Controllable& c) : binding_proxy (c) {}
- explicit BindableToggleButton (PBD::Controllable& c, const std::string &label) : Gtk::ToggleButton (label), binding_proxy (c) {}
+
+ explicit BindableToggleButton (PBD::Controllable& c, const std::string &label)
+ : Gtkmm2ext::StatefulToggleButton (label), binding_proxy (c) {}
+
virtual ~BindableToggleButton() {}
bool on_button_press_event (GdkEventButton *ev) {
- return binding_proxy.button_press_handler (ev);
+ if (!binding_proxy.button_press_handler (ev)) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ private:
+ BindingProxy binding_proxy;
+};
+
+class BindableButton : public Gtkmm2ext::StatefulButton
+{
+ public:
+ BindableButton (PBD::Controllable& c) : binding_proxy (c) {}
+
+ explicit BindableButton (PBD::Controllable& c, const std::string &label)
+ : Gtkmm2ext::StatefulButton (label), binding_proxy (c) {}
+
+ ~BindableButton() {}
+
+ bool on_button_press_event (GdkEventButton *ev) {
+ if (!binding_proxy.button_press_handler (ev)) {
+ return false;
+ } else {
+ return true;
+ }
}
private:
diff --git a/libs/gtkmm2ext/gtkmm2ext/stateful_button.h b/libs/gtkmm2ext/gtkmm2ext/stateful_button.h
index f684903836..fc62bd2999 100644
--- a/libs/gtkmm2ext/gtkmm2ext/stateful_button.h
+++ b/libs/gtkmm2ext/gtkmm2ext/stateful_button.h
@@ -27,28 +27,55 @@
namespace Gtkmm2ext {
-class StatefulButton : public Gtk::Button
+class StateButton
{
public:
- StatefulButton();
- explicit StatefulButton(const std::string &label);
- virtual ~StatefulButton() {}
+ StateButton();
+ virtual ~StateButton() {}
void set_colors (const std::vector<Gdk::Color>& colors);
- void set_state (int);
- int get_state () { return current_state; }
- void set_active (bool yn) {
- set_state (yn ? 1 : 0);
- }
-
+ void set_visual_state (int);
+ int get_visual_state () { return visual_state; }
protected:
std::vector<Gdk::Color> colors;
- int current_state;
+ int visual_state;
Gdk::Color saved_bg;
bool have_saved_bg;
+
+ virtual void bg_modify (Gtk::StateType, Gdk::Color) = 0;
+};
+
+
+class StatefulToggleButton : public StateButton, public Gtk::ToggleButton
+{
+ public:
+ StatefulToggleButton() {}
+ explicit StatefulToggleButton(const std::string &label) : Gtk::ToggleButton (label) {}
+ ~StatefulToggleButton() {}
+
+ protected:
+ void on_realize ();
+ void on_toggled ();
+
+ void bg_modify (Gtk::StateType state, Gdk::Color col) {
+ modify_bg (state, col);
+ }
+};
+class StatefulButton : public StateButton, public Gtk::Button
+{
+ public:
+ StatefulButton() {}
+ explicit StatefulButton(const std::string &label) : Gtk::Button (label) {}
+ virtual ~StatefulButton() {}
+
+ protected:
void on_realize ();
+
+ void bg_modify (Gtk::StateType state, Gdk::Color col) {
+ modify_bg (state, col);
+ }
};
};
diff --git a/libs/gtkmm2ext/stateful_button.cc b/libs/gtkmm2ext/stateful_button.cc
index 074d086651..6cc24de461 100644
--- a/libs/gtkmm2ext/stateful_button.cc
+++ b/libs/gtkmm2ext/stateful_button.cc
@@ -1,80 +1,104 @@
#include <string>
#include <iostream>
-#include "gtkmm2ext/stateful_button.h"
+
+#include <gtkmm/main.h>
+
+#include <gtkmm2ext/stateful_button.h>
using namespace Gtk;
using namespace Glib;
using namespace Gtkmm2ext;
using namespace std;
-StatefulButton::StatefulButton ()
+StateButton::StateButton ()
{
- current_state = 0;
+ visual_state = 0;
have_saved_bg = false;
}
-StatefulButton::StatefulButton (const string& label)
- : Button (label)
+void
+StateButton::set_colors (const vector<Gdk::Color>& c)
{
- current_state = 0;
- have_saved_bg = false;
+ colors = c;
+ visual_state++; // to force transition
+ set_visual_state (visual_state - 1);
}
void
-StatefulButton::set_colors (const vector<Gdk::Color>& c)
+StateButton::set_visual_state (int n)
{
- colors = c;
- current_state++; // to force transition
- set_state (current_state - 1);
+ if (!have_saved_bg) {
+ /* not yet realized */
+ visual_state = n;
+ return;
+ }
+
+ if (n == visual_state) {
+ return;
+ }
+
+ if (n == 0) {
+
+ /* back to the default color */
+
+ if (have_saved_bg) {
+ bg_modify (STATE_NORMAL, saved_bg);
+ bg_modify (STATE_ACTIVE, saved_bg);
+ bg_modify (STATE_SELECTED, saved_bg);
+ bg_modify (STATE_PRELIGHT, saved_bg);
+ }
+
+
+ } else {
+
+ int index = (n-1) % colors.size ();
+
+ bg_modify (STATE_NORMAL, colors[index]);
+ bg_modify (STATE_ACTIVE, colors[index]);
+ bg_modify (STATE_SELECTED, colors[index]);
+ bg_modify (STATE_PRELIGHT, colors[index]);
+ }
+
+ visual_state = n;
}
+/* ----------------------------------------------------------------- */
+
void
-StatefulButton::on_realize ()
+StatefulToggleButton::on_realize ()
{
- Button::on_realize ();
+ ToggleButton::on_realize ();
if (!have_saved_bg) {
saved_bg = get_style()->get_bg (STATE_NORMAL);
have_saved_bg = true;
}
- current_state++; // to force transition
- set_state (current_state - 1);
+ visual_state++; // to force transition
+ set_visual_state (visual_state - 1);
}
void
-StatefulButton::set_state (int n)
+StatefulButton::on_realize ()
{
- if (is_realized()) {
+ Button::on_realize ();
- if (n == current_state) {
- return;
- }
-
- if (n == 0) {
-
- /* back to the default color */
-
- if (have_saved_bg) {
- modify_bg (STATE_NORMAL, saved_bg);
- modify_bg (STATE_ACTIVE, saved_bg);
- modify_bg (STATE_SELECTED, saved_bg);
- modify_bg (STATE_PRELIGHT, saved_bg);
- }
-
-
- } else {
-
- int index = (n-1) % colors.size ();
-
- modify_bg (STATE_NORMAL, colors[index]);
- modify_bg (STATE_ACTIVE, colors[index]);
- modify_bg (STATE_SELECTED, colors[index]);
- modify_bg (STATE_PRELIGHT, colors[index]);
- }
-
- /* leave insensitive alone */
+ if (!have_saved_bg) {
+ saved_bg = get_style()->get_bg (STATE_NORMAL);
+ have_saved_bg = true;
}
- current_state = n;
+ visual_state++; // to force transition
+ set_visual_state (visual_state - 1);
+}
+
+void
+StatefulToggleButton::on_toggled ()
+{
+ if (get_active()) {
+ set_visual_state (1);
+ } else {
+ set_visual_state (0);
+ }
+
}