2 Copyright (C) 2015 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <gtkmm/alignment.h>
21 #include <gtkmm/label.h>
22 #include <gtkmm/liststore.h>
24 #include "pbd/unwind.h"
25 #include "pbd/strsplit.h"
26 #include "pbd/file_utils.h"
28 #include "gtkmm2ext/bindings.h"
29 #include "gtkmm2ext/gui_thread.h"
30 #include "gtkmm2ext/utils.h"
32 #include "ardour/audioengine.h"
33 #include "ardour/filesystem_paths.h"
34 #include "ardour/parameter_descriptor.h"
42 using namespace ARDOUR;
43 using namespace ArdourSurface;
46 using namespace Gtkmm2ext;
49 Push2::get_gui () const
52 const_cast<Push2*>(this)->build_gui ();
54 static_cast<Gtk::VBox*>(gui)->show_all();
59 Push2::tear_down_gui ()
62 Gtk::Widget *w = static_cast<Gtk::VBox*>(gui)->get_parent();
75 gui = new P2GUI (*this);
78 /*--------------------*/
80 P2GUI::P2GUI (Push2& p)
84 , ignore_active_change (false)
85 , pressure_mode_label (_("Pressure Mode"))
87 set_border_width (12);
89 table.set_row_spacings (4);
90 table.set_col_spacings (6);
91 table.set_border_width (12);
92 table.set_homogeneous (false);
94 std::string data_file_path;
95 string name = "push2-small.png";
96 Searchpath spath(ARDOUR::ardour_data_search_path());
97 spath.add_subdirectory_to_paths ("icons");
98 find_file (spath, name, data_file_path);
99 if (!data_file_path.empty()) {
100 image.set (data_file_path);
101 hpacker.pack_start (image, false, false);
107 input_combo.pack_start (midi_port_columns.short_name);
108 output_combo.pack_start (midi_port_columns.short_name);
110 input_combo.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &P2GUI::active_port_changed), &input_combo, true));
111 output_combo.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &P2GUI::active_port_changed), &output_combo, false));
113 l = manage (new Gtk::Label);
114 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Incoming MIDI on:")));
115 l->set_alignment (1.0, 0.5);
116 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
117 table.attach (input_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
120 l = manage (new Gtk::Label);
121 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Outgoing MIDI on:")));
122 l->set_alignment (1.0, 0.5);
123 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
124 table.attach (output_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
127 table.attach (pressure_mode_label, 0, 1, row, row+1, AttachOptions (0), AttachOptions (0));
128 table.attach (pressure_mode_selector, 1, 2, row, row+1, AttachOptions (FILL|EXPAND), AttachOptions (0));
131 hpacker.pack_start (table, true, true);
133 pressure_mode_selector.set_model (build_pressure_mode_columns());
134 pressure_mode_selector.pack_start (pressure_mode_columns.name);
135 pressure_mode_selector.set_active ((int) p2.pressure_mode());
136 pressure_mode_selector.signal_changed().connect (sigc::mem_fun (*this, &P2GUI::reprogram_pressure_mode));
140 pack_start (hpacker, false, false);
142 /* update the port connection combos */
144 update_port_combos ();
146 /* catch future changes to connection state */
148 // p2.ConnectionChange.connect (connection_change_connection, invalidator (*this), boost::bind (&P2GUI::connection_handler, this), gui_context());
156 P2GUI::connection_handler ()
158 /* ignore all changes to combobox active strings here, because we're
159 updating them to match a new ("external") reality - we were called
160 because port connections have changed.
163 PBD::Unwinder<bool> ici (ignore_active_change, true);
165 update_port_combos ();
169 P2GUI::update_port_combos ()
171 vector<string> midi_inputs;
172 vector<string> midi_outputs;
174 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsTerminal), midi_inputs);
175 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsTerminal), midi_outputs);
177 Glib::RefPtr<Gtk::ListStore> input = build_midi_port_list (midi_inputs, true);
178 Glib::RefPtr<Gtk::ListStore> output = build_midi_port_list (midi_outputs, false);
179 bool input_found = false;
180 bool output_found = false;
183 input_combo.set_model (input);
184 output_combo.set_model (output);
186 Gtk::TreeModel::Children children = input->children();
187 Gtk::TreeModel::Children::iterator i;
188 i = children.begin();
189 ++i; /* skip "Disconnected" */
192 for (n = 1; i != children.end(); ++i, ++n) {
193 string port_name = (*i)[midi_port_columns.full_name];
194 if (p2.input_port()->connected_to (port_name)) {
195 input_combo.set_active (n);
202 input_combo.set_active (0); /* disconnected */
205 children = output->children();
206 i = children.begin();
207 ++i; /* skip "Disconnected" */
209 for (n = 1; i != children.end(); ++i, ++n) {
210 string port_name = (*i)[midi_port_columns.full_name];
211 if (p2.output_port()->connected_to (port_name)) {
212 output_combo.set_active (n);
219 output_combo.set_active (0); /* disconnected */
224 P2GUI::build_available_action_menu ()
226 /* build a model of all available actions (needs to be tree structured
230 available_action_model = TreeStore::create (action_columns);
232 vector<string> paths;
233 vector<string> labels;
234 vector<string> tooltips;
236 vector<Glib::RefPtr<Gtk::Action> > actions;
238 Gtkmm2ext::ActionMap::get_all_actions (paths, labels, tooltips, keys, actions);
240 typedef std::map<string,TreeIter> NodeMap;
245 vector<string>::iterator k;
246 vector<string>::iterator p;
247 vector<string>::iterator t;
248 vector<string>::iterator l;
250 available_action_model->clear ();
253 TreeModel::Row parent;
255 /* Disabled item (row 0) */
257 rowp = available_action_model->append();
259 parent[action_columns.name] = _("Disabled");
263 rowp = available_action_model->append();
265 parent[action_columns.name] = _("Shift");
266 rowp = available_action_model->append();
268 parent[action_columns.name] = _("Control");
269 rowp = available_action_model->append();
271 parent[action_columns.name] = _("Option");
272 rowp = available_action_model->append();
274 parent[action_columns.name] = _("CmdAlt");
277 for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
280 vector<string> parts;
284 split (*p, parts, '/');
290 //kinda kludgy way to avoid displaying menu items as mappable
291 if ( parts[1] == _("Main_menu") )
293 if ( parts[1] == _("JACK") )
295 if ( parts[1] == _("redirectmenu") )
297 if ( parts[1] == _("Editor_menus") )
299 if ( parts[1] == _("RegionList") )
301 if ( parts[1] == _("ProcessorMenu") )
304 if ((r = nodes.find (parts[1])) == nodes.end()) {
306 /* top level is missing */
309 TreeModel::Row parent;
310 rowp = available_action_model->append();
311 nodes[parts[1]] = rowp;
313 parent[action_columns.name] = parts[1];
315 row = *(available_action_model->append (parent.children()));
319 row = *(available_action_model->append ((*r->second)->children()));
323 /* add this action */
326 row[action_columns.name] = *t;
329 row[action_columns.name] = *l;
334 /* ControlProtocol::access_action() is not interested in the
335 legacy "<Actions>/" prefix part of a path.
337 path = path.substr (strlen ("<Actions>/"));
339 row[action_columns.path] = path;
345 P2GUI::find_action_in_model (const TreeModel::iterator& iter, std::string const & action_path, TreeModel::iterator* found)
347 TreeModel::Row row = *iter;
348 string path = row[action_columns.path];
350 if (path == action_path) {
358 Glib::RefPtr<Gtk::ListStore>
359 P2GUI::build_midi_port_list (vector<string> const & ports, bool for_input)
361 Glib::RefPtr<Gtk::ListStore> store = ListStore::create (midi_port_columns);
364 row = *store->append ();
365 row[midi_port_columns.full_name] = string();
366 row[midi_port_columns.short_name] = _("Disconnected");
368 for (vector<string>::const_iterator p = ports.begin(); p != ports.end(); ++p) {
369 row = *store->append ();
370 row[midi_port_columns.full_name] = *p;
371 std::string pn = ARDOUR::AudioEngine::instance()->get_pretty_name_by_name (*p);
373 pn = (*p).substr ((*p).find (':') + 1);
375 row[midi_port_columns.short_name] = pn;
382 P2GUI::active_port_changed (Gtk::ComboBox* combo, bool for_input)
384 if (ignore_active_change) {
388 TreeModel::iterator active = combo->get_active ();
389 string new_port = (*active)[midi_port_columns.full_name];
391 if (new_port.empty()) {
393 p2.input_port()->disconnect_all ();
395 p2.output_port()->disconnect_all ();
402 if (!p2.input_port()->connected_to (new_port)) {
403 p2.input_port()->disconnect_all ();
404 p2.input_port()->connect (new_port);
407 if (!p2.output_port()->connected_to (new_port)) {
408 p2.output_port()->disconnect_all ();
409 p2.output_port()->connect (new_port);
414 Glib::RefPtr<Gtk::ListStore>
415 P2GUI::build_pressure_mode_columns ()
417 Glib::RefPtr<Gtk::ListStore> store = ListStore::create (pressure_mode_columns);
420 row = *store->append();
421 row[pressure_mode_columns.name] = _("AfterTouch (Channel Pressure)");
422 row[pressure_mode_columns.mode] = Push2::AfterTouch;
424 row = *store->append();
425 row[pressure_mode_columns.name] = _("Polyphonic Pressure (Note Pressure)");
426 row[pressure_mode_columns.mode] = Push2::PolyPressure;
432 P2GUI::reprogram_pressure_mode ()
434 Gtk::TreeModel::iterator iter = pressure_mode_selector.get_active();
435 Push2::PressureMode pm;
438 Gtk::TreeModel::Row row = *iter;
440 pm = row[pressure_mode_columns.mode];
442 pm = Push2::AfterTouch;
445 pm = Push2::AfterTouch;
448 cerr << "Reprogram pm to " << pm << endl;
449 p2.set_pressure_mode (pm);