2 * Copyright (C) 2017 Robin Gareus <robin@gareus.org>
3 * Copyright (C) 2015 Paul Davis
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include <gtkmm/alignment.h>
21 #include <gtkmm/label.h>
22 #include <gtkmm/liststore.h>
23 #include <gtkmm/separator.h>
25 #include "pbd/unwind.h"
26 #include "pbd/strsplit.h"
27 #include "pbd/file_utils.h"
29 #include "gtkmm2ext/bindings.h"
30 #include "gtkmm2ext/gtk_ui.h"
31 #include "gtkmm2ext/gui_thread.h"
32 #include "gtkmm2ext/utils.h"
34 #include "ardour/audioengine.h"
35 #include "ardour/filesystem_paths.h"
37 #include "faderport8.h"
43 using namespace ARDOUR;
44 using namespace ArdourSurface;
47 using namespace Gtkmm2ext;
50 FaderPort8::get_gui () const
53 const_cast<FaderPort8*>(this)->build_gui ();
55 static_cast<Gtk::VBox*>(gui)->show_all();
60 FaderPort8::tear_down_gui ()
63 Gtk::Widget *w = static_cast<Gtk::VBox*>(gui)->get_parent();
69 delete static_cast<FP8GUI*> (gui);
74 FaderPort8::build_gui ()
76 gui = (void*) new FP8GUI (*this);
79 /* ****************************************************************************/
81 FP8GUI::FP8GUI (FaderPort8& p)
84 , ignore_active_change (false)
86 set_border_width (12);
88 table.set_row_spacings (4);
89 table.set_col_spacings (6);
90 table.set_border_width (12);
91 table.set_homogeneous (false);
93 std::string data_file_path;
94 string name = "faderport8-small.png";
95 Searchpath spath(ARDOUR::ardour_data_search_path());
96 spath.add_subdirectory_to_paths ("icons");
97 find_file (spath, name, data_file_path);
98 if (!data_file_path.empty()) {
99 image.set (data_file_path);
100 hpacker.pack_start (image, false, false);
106 input_combo.pack_start (midi_port_columns.short_name);
107 output_combo.pack_start (midi_port_columns.short_name);
109 input_combo.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FP8GUI::active_port_changed), &input_combo, true));
110 output_combo.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FP8GUI::active_port_changed), &output_combo, false));
112 l = manage (new Gtk::Label);
113 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Incoming MIDI on:")));
114 l->set_alignment (1.0, 0.5);
115 table.attach (*l, 1, 4, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
116 table.attach (input_combo, 4, 8, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
119 l = manage (new Gtk::Label);
120 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Outgoing MIDI on:")));
121 l->set_alignment (1.0, 0.5);
122 table.attach (*l, 1, 4, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
123 table.attach (output_combo, 4, 8, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
126 Gtk::HSeparator *hsep = manage(new Gtk::HSeparator);
127 table.attach (*hsep, 0, 8, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 6);
130 hpacker.pack_start (table, true, true);
131 pack_start (hpacker, false, false);
134 build_available_action_menu ();
138 Gtk::Alignment* align;
140 for (FP8Controls::UserButtonMap::const_iterator i = fp.control().user_buttons ().begin ();
141 i != fp.control().user_buttons ().end (); ++i) {
142 Gtk::ComboBox* user_combo = manage (new Gtk::ComboBox);
143 build_action_combo (*user_combo, i->first);
144 l = manage (new Gtk::Label);
145 l->set_markup (string_compose ("<span weight=\"bold\">%1:</span>", i->second));
146 l->set_alignment (1.0, 0.5);
147 table.attach (*l, 3 * action_col, 3 * action_col + 1, row + action_row, row + action_row + 1, AttachOptions(FILL|EXPAND), AttachOptions (0));
148 align = manage (new Alignment);
149 align->set (0.0, 0.5);
150 align->add (*user_combo);
151 table.attach (*align, 3 * action_col + 1, 3 * action_col + 2, row + action_row, row + action_row + 1, AttachOptions(FILL|EXPAND), AttachOptions (0));
153 if (++action_row == 4) {
159 for (int c = 0; c < 2; ++c) {
160 Gtk::VSeparator *vsep = manage(new Gtk::VSeparator);
161 table.attach (*vsep, 3 * c + 2, 3 * c + 3, row, row + 4, AttachOptions(0), AttachOptions(FILL), 6, 0);
164 /* update the port connection combos */
165 update_port_combos ();
167 /* catch future changes to connection state */
168 fp.ConnectionChange.connect (connection_change_connection, invalidator (*this), boost::bind (&FP8GUI::connection_handler, this), gui_context());
176 FP8GUI::connection_handler ()
178 PBD::Unwinder<bool> ici (ignore_active_change, true);
179 update_port_combos ();
183 FP8GUI::update_port_combos ()
185 vector<string> midi_inputs;
186 vector<string> midi_outputs;
188 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsTerminal), midi_inputs);
189 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsTerminal), midi_outputs);
191 Glib::RefPtr<Gtk::ListStore> input = build_midi_port_list (midi_inputs, true);
192 Glib::RefPtr<Gtk::ListStore> output = build_midi_port_list (midi_outputs, false);
193 bool input_found = false;
194 bool output_found = false;
197 input_combo.set_model (input);
198 output_combo.set_model (output);
200 Gtk::TreeModel::Children children = input->children();
201 Gtk::TreeModel::Children::iterator i;
202 i = children.begin();
203 ++i; /* skip "Disconnected" */
205 for (n = 1; i != children.end(); ++i, ++n) {
206 string port_name = (*i)[midi_port_columns.full_name];
207 if (fp.input_port()->connected_to (port_name)) {
208 input_combo.set_active (n);
215 input_combo.set_active (0); /* disconnected */
218 children = output->children();
219 i = children.begin();
220 ++i; /* skip "Disconnected" */
222 for (n = 1; i != children.end(); ++i, ++n) {
223 string port_name = (*i)[midi_port_columns.full_name];
224 if (fp.output_port()->connected_to (port_name)) {
225 output_combo.set_active (n);
232 output_combo.set_active (0); /* disconnected */
237 Glib::RefPtr<Gtk::ListStore>
238 FP8GUI::build_midi_port_list (vector<string> const & ports, bool for_input)
240 Glib::RefPtr<Gtk::ListStore> store = ListStore::create (midi_port_columns);
243 row = *store->append ();
244 row[midi_port_columns.full_name] = string();
245 row[midi_port_columns.short_name] = _("Disconnected");
247 for (vector<string>::const_iterator p = ports.begin(); p != ports.end(); ++p) {
248 row = *store->append ();
249 row[midi_port_columns.full_name] = *p;
250 std::string pn = ARDOUR::AudioEngine::instance()->get_pretty_name_by_name (*p);
252 pn = (*p).substr ((*p).find (':') + 1);
254 row[midi_port_columns.short_name] = pn;
261 FP8GUI::active_port_changed (Gtk::ComboBox* combo, bool for_input)
263 if (ignore_active_change) {
267 TreeModel::iterator active = combo->get_active ();
268 string new_port = (*active)[midi_port_columns.full_name];
270 if (new_port.empty()) {
272 fp.input_port()->disconnect_all ();
274 fp.output_port()->disconnect_all ();
281 if (!fp.input_port()->connected_to (new_port)) {
282 fp.input_port()->disconnect_all ();
283 fp.input_port()->connect (new_port);
286 if (!fp.output_port()->connected_to (new_port)) {
287 fp.output_port()->disconnect_all ();
288 fp.output_port()->connect (new_port);
296 FP8GUI::build_available_action_menu ()
298 /* build a model of all available actions (needs to be tree structured
302 available_action_model = TreeStore::create (action_columns);
304 vector<string> paths;
305 vector<string> labels;
306 vector<string> tooltips;
308 vector<Glib::RefPtr<Gtk::Action> > actions;
310 Gtkmm2ext::ActionMap::get_all_actions (paths, labels, tooltips, keys, actions);
312 typedef std::map<string,TreeIter> NodeMap;
317 vector<string>::iterator k;
318 vector<string>::iterator p;
319 vector<string>::iterator t;
320 vector<string>::iterator l;
322 available_action_model->clear ();
325 TreeModel::Row parent;
327 /* Disabled item (row 0) */
329 rowp = available_action_model->append();
331 parent[action_columns.name] = _("Disabled");
333 for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
336 vector<string> parts;
340 split (*p, parts, '/');
346 //kinda kludgy way to avoid displaying menu items as mappable
347 if ( parts[1] == _("Main_menu") )
349 if ( parts[1] == _("JACK") )
351 if ( parts[1] == _("redirectmenu") )
353 if ( parts[1] == _("Editor_menus") )
355 if ( parts[1] == _("RegionList") )
357 if ( parts[1] == _("ProcessorMenu") )
360 if ((r = nodes.find (parts[1])) == nodes.end()) {
362 /* top level is missing */
365 TreeModel::Row parent;
366 rowp = available_action_model->append();
367 nodes[parts[1]] = rowp;
369 parent[action_columns.name] = parts[1];
371 row = *(available_action_model->append (parent.children()));
375 row = *(available_action_model->append ((*r->second)->children()));
379 /* add this action */
382 row[action_columns.name] = *t;
385 row[action_columns.name] = *l;
390 /* ControlProtocol::access_action() is not interested in the
391 legacy "<Actions>/" prefix part of a path.
393 path = path.substr (strlen ("<Actions>/"));
395 row[action_columns.path] = path;
400 FP8GUI::find_action_in_model (const TreeModel::iterator& iter, std::string const& action_path, TreeModel::iterator* found)
402 TreeModel::Row row = *iter;
403 string path = row[action_columns.path];
405 if (path == action_path) {
414 FP8GUI::build_action_combo (Gtk::ComboBox& cb, FP8Controls::ButtonId id)
416 cb.set_model (available_action_model);
417 cb.pack_start (action_columns.name);
419 /* set the active "row" to the right value for the current button binding */
420 string current_action = fp.get_button_action (id, false); /* lookup release action */
422 if (current_action.empty()) {
423 cb.set_active (0); /* "disabled" */
425 TreeModel::iterator iter = available_action_model->children().end();
427 available_action_model->foreach_iter (sigc::bind (sigc::mem_fun (*this, &FP8GUI::find_action_in_model), current_action, &iter));
429 if (iter != available_action_model->children().end()) {
430 cb.set_active (iter);
435 /* bind signal _after_ setting the current value */
436 cb.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &FP8GUI::action_changed), &cb, id));
440 FP8GUI::action_changed (Gtk::ComboBox* cb, FP8Controls::ButtonId id)
442 TreeModel::const_iterator row = cb->get_active ();
443 string action_path = (*row)[action_columns.path];
444 fp.set_button_action (id, false, action_path);