mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-15 19:16:40 +01:00
Use ActionModel API in the Control Surfaces that can make use of it
This commit is contained in:
parent
b141d17274
commit
5b7bcec529
10 changed files with 78 additions and 630 deletions
|
|
@ -26,6 +26,7 @@
|
|||
#include "pbd/unwind.h"
|
||||
|
||||
#include "gtkmm2ext/actions.h"
|
||||
#include "gtkmm2ext/action_model.h"
|
||||
#include "gtkmm2ext/bindings.h"
|
||||
#include "gtkmm2ext/gtk_ui.h"
|
||||
#include "gtkmm2ext/gui_thread.h"
|
||||
|
|
@ -83,6 +84,7 @@ FPGUI::FPGUI (FaderPort& p)
|
|||
, table (2, 5)
|
||||
, action_table (5, 4)
|
||||
, ignore_active_change (false)
|
||||
, action_model (ActionManager::ActionModel::instance ())
|
||||
{
|
||||
set_border_width (12);
|
||||
|
||||
|
|
@ -137,8 +139,6 @@ FPGUI::FPGUI (FaderPort& p)
|
|||
build_trns_action_combo (trns_combo[1], FaderPort::ShiftDown);
|
||||
build_trns_action_combo (trns_combo[2], FaderPort::LongPress);
|
||||
|
||||
build_available_action_menu ();
|
||||
|
||||
build_foot_action_combo (foot_combo[0], FaderPort::ButtonState(0));
|
||||
build_foot_action_combo (foot_combo[1], FaderPort::ShiftDown);
|
||||
build_foot_action_combo (foot_combo[2], FaderPort::LongPress);
|
||||
|
|
@ -345,123 +345,11 @@ FPGUI::update_port_combos ()
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
FPGUI::build_available_action_menu ()
|
||||
{
|
||||
/* build a model of all available actions (needs to be tree structured
|
||||
* more)
|
||||
*/
|
||||
|
||||
available_action_model = TreeStore::create (action_columns);
|
||||
|
||||
vector<string> paths;
|
||||
vector<string> labels;
|
||||
vector<string> tooltips;
|
||||
vector<string> keys;
|
||||
vector<Glib::RefPtr<Gtk::Action> > actions;
|
||||
|
||||
ActionManager::get_all_actions (paths, labels, tooltips, keys, actions);
|
||||
|
||||
typedef std::map<string,TreeIter> NodeMap;
|
||||
NodeMap nodes;
|
||||
NodeMap::iterator r;
|
||||
|
||||
|
||||
vector<string>::iterator k;
|
||||
vector<string>::iterator p;
|
||||
vector<string>::iterator t;
|
||||
vector<string>::iterator l;
|
||||
|
||||
available_action_model->clear ();
|
||||
|
||||
TreeIter rowp;
|
||||
TreeModel::Row parent;
|
||||
|
||||
/* Disabled item (row 0) */
|
||||
|
||||
rowp = available_action_model->append();
|
||||
parent = *(rowp);
|
||||
parent[action_columns.name] = _("Disabled");
|
||||
|
||||
/* Key aliasing */
|
||||
|
||||
rowp = available_action_model->append();
|
||||
parent = *(rowp);
|
||||
parent[action_columns.name] = _("Shift");
|
||||
rowp = available_action_model->append();
|
||||
parent = *(rowp);
|
||||
parent[action_columns.name] = _("Control");
|
||||
rowp = available_action_model->append();
|
||||
parent = *(rowp);
|
||||
parent[action_columns.name] = _("Option");
|
||||
rowp = available_action_model->append();
|
||||
parent = *(rowp);
|
||||
parent[action_columns.name] = _("CmdAlt");
|
||||
|
||||
|
||||
for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
|
||||
|
||||
TreeModel::Row row;
|
||||
vector<string> parts;
|
||||
|
||||
parts.clear ();
|
||||
|
||||
split (*p, parts, '/');
|
||||
|
||||
if (parts.empty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//kinda kludgy way to avoid displaying menu items as mappable
|
||||
if (parts[0] == _("Main Menu") )
|
||||
continue;
|
||||
if (parts[0] == _("JACK") )
|
||||
continue;
|
||||
if (parts[0] == _("redirectmenu") )
|
||||
continue;
|
||||
if (parts[0] == _("RegionList") )
|
||||
continue;
|
||||
if (parts[0] == _("ProcessorMenu") )
|
||||
continue;
|
||||
|
||||
if ((r = nodes.find (parts[0])) == nodes.end()) {
|
||||
|
||||
/* top level is missing */
|
||||
|
||||
TreeIter rowp;
|
||||
TreeModel::Row parent;
|
||||
rowp = available_action_model->append();
|
||||
nodes[parts[0]] = rowp;
|
||||
parent = *(rowp);
|
||||
parent[action_columns.name] = parts[0];
|
||||
|
||||
row = *(available_action_model->append (parent.children()));
|
||||
|
||||
} else {
|
||||
|
||||
row = *(available_action_model->append ((*r->second)->children()));
|
||||
|
||||
}
|
||||
|
||||
/* add this action */
|
||||
|
||||
if (l->empty ()) {
|
||||
row[action_columns.name] = *t;
|
||||
action_map[*t] = *p;
|
||||
} else {
|
||||
row[action_columns.name] = *l;
|
||||
action_map[*l] = *p;
|
||||
}
|
||||
|
||||
row[action_columns.path] = *p;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FPGUI::action_changed (Gtk::ComboBox* cb, FaderPort::ButtonID id, FaderPort::ButtonState bs)
|
||||
{
|
||||
TreeModel::const_iterator row = cb->get_active ();
|
||||
string action_path = (*row)[action_columns.path];
|
||||
string action_path = (*row)[action_model.path()];
|
||||
|
||||
/* release binding */
|
||||
fp.set_action (id, action_path, false, bs);
|
||||
|
|
@ -470,7 +358,7 @@ FPGUI::action_changed (Gtk::ComboBox* cb, FaderPort::ButtonID id, FaderPort::But
|
|||
void
|
||||
FPGUI::build_action_combo (Gtk::ComboBox& cb, vector<pair<string,string> > const & actions, FaderPort::ButtonID id, FaderPort::ButtonState bs)
|
||||
{
|
||||
Glib::RefPtr<Gtk::ListStore> model (Gtk::ListStore::create (action_columns));
|
||||
Glib::RefPtr<Gtk::ListStore> model (Gtk::ListStore::create (action_model.columns()));
|
||||
TreeIter rowp;
|
||||
TreeModel::Row row;
|
||||
string current_action = fp.get_action (id, false, bs); /* lookup release action */
|
||||
|
|
@ -480,8 +368,8 @@ FPGUI::build_action_combo (Gtk::ComboBox& cb, vector<pair<string,string> > const
|
|||
|
||||
rowp = model->append();
|
||||
row = *(rowp);
|
||||
row[action_columns.name] = _("Disabled");
|
||||
row[action_columns.path] = string();
|
||||
row[action_model.name()] = _("Disabled");
|
||||
row[action_model.path()] = string();
|
||||
|
||||
if (current_action.empty()) {
|
||||
active_row = 0;
|
||||
|
|
@ -490,15 +378,15 @@ FPGUI::build_action_combo (Gtk::ComboBox& cb, vector<pair<string,string> > const
|
|||
for (i = actions.begin(), n = 0; i != actions.end(); ++i, ++n) {
|
||||
rowp = model->append();
|
||||
row = *(rowp);
|
||||
row[action_columns.name] = i->first;
|
||||
row[action_columns.path] = i->second;
|
||||
row[action_model.name()] = i->first;
|
||||
row[action_model.path()] = i->second;
|
||||
if (current_action == i->second) {
|
||||
active_row = n+1;
|
||||
}
|
||||
}
|
||||
|
||||
cb.set_model (model);
|
||||
cb.pack_start (action_columns.name);
|
||||
cb.pack_start (action_model.name());
|
||||
|
||||
if (active_row >= 0) {
|
||||
cb.set_active (active_row);
|
||||
|
|
@ -576,7 +464,7 @@ bool
|
|||
FPGUI::find_action_in_model (const TreeModel::iterator& iter, std::string const & action_path, TreeModel::iterator* found)
|
||||
{
|
||||
TreeModel::Row row = *iter;
|
||||
string path = row[action_columns.path];
|
||||
string path = row[action_model.path()];
|
||||
|
||||
if (path == action_path) {
|
||||
*found = iter;
|
||||
|
|
@ -592,8 +480,8 @@ FPGUI::build_user_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
|
|||
#ifndef MIXBUS
|
||||
bs = FaderPort::ButtonState (bs|FaderPort::UserDown);
|
||||
#endif
|
||||
cb.set_model (available_action_model);
|
||||
cb.pack_start (action_columns.name);
|
||||
cb.set_model (action_model.model());
|
||||
cb.pack_start (action_model.name());
|
||||
cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FPGUI::action_changed), &cb, FaderPort::User, bs));
|
||||
|
||||
/* set the active "row" to the right value for the current button binding */
|
||||
|
|
@ -605,11 +493,11 @@ FPGUI::build_user_action_combo (Gtk::ComboBox& cb, FaderPort::ButtonState bs)
|
|||
return;
|
||||
}
|
||||
|
||||
TreeModel::iterator iter = available_action_model->children().end();
|
||||
TreeModel::iterator iter = action_model.model()->children().end();
|
||||
|
||||
available_action_model->foreach_iter (sigc::bind (sigc::mem_fun (*this, &FPGUI::find_action_in_model), current_action, &iter));
|
||||
action_model.model()->foreach_iter (sigc::bind (sigc::mem_fun (*this, &FPGUI::find_action_in_model), current_action, &iter));
|
||||
|
||||
if (iter != available_action_model->children().end()) {
|
||||
if (iter != action_model.model()->children().end()) {
|
||||
cb.set_active (iter);
|
||||
} else {
|
||||
cb.set_active (0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue