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 ARDOUR::AudioEngine::instance()->PortRegisteredOrUnregistered.connect (port_reg_connection, invalidator (*this), boost::bind (&P2GUI::connection_handler, this), gui_context());
149 p2.ConnectionChange.connect (connection_change_connection, invalidator (*this), boost::bind (&P2GUI::connection_handler, this), gui_context());
157 P2GUI::connection_handler ()
159 /* ignore all changes to combobox active strings here, because we're
160 updating them to match a new ("external") reality - we were called
161 because port connections have changed.
164 PBD::Unwinder<bool> ici (ignore_active_change, true);
166 update_port_combos ();
170 P2GUI::update_port_combos ()
172 vector<string> midi_inputs;
173 vector<string> midi_outputs;
175 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsTerminal), midi_inputs);
176 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsTerminal), midi_outputs);
178 Glib::RefPtr<Gtk::ListStore> input = build_midi_port_list (midi_inputs, true);
179 Glib::RefPtr<Gtk::ListStore> output = build_midi_port_list (midi_outputs, false);
180 bool input_found = false;
181 bool output_found = false;
184 input_combo.set_model (input);
185 output_combo.set_model (output);
187 Gtk::TreeModel::Children children = input->children();
188 Gtk::TreeModel::Children::iterator i;
189 i = children.begin();
190 ++i; /* skip "Disconnected" */
193 for (n = 1; i != children.end(); ++i, ++n) {
194 string port_name = (*i)[midi_port_columns.full_name];
195 if (p2.input_port()->connected_to (port_name)) {
196 input_combo.set_active (n);
203 input_combo.set_active (0); /* disconnected */
206 children = output->children();
207 i = children.begin();
208 ++i; /* skip "Disconnected" */
210 for (n = 1; i != children.end(); ++i, ++n) {
211 string port_name = (*i)[midi_port_columns.full_name];
212 if (p2.output_port()->connected_to (port_name)) {
213 output_combo.set_active (n);
220 output_combo.set_active (0); /* disconnected */
224 Glib::RefPtr<Gtk::ListStore>
225 P2GUI::build_midi_port_list (vector<string> const & ports, bool for_input)
227 Glib::RefPtr<Gtk::ListStore> store = ListStore::create (midi_port_columns);
230 row = *store->append ();
231 row[midi_port_columns.full_name] = string();
232 row[midi_port_columns.short_name] = _("Disconnected");
234 for (vector<string>::const_iterator p = ports.begin(); p != ports.end(); ++p) {
235 row = *store->append ();
236 row[midi_port_columns.full_name] = *p;
237 std::string pn = ARDOUR::AudioEngine::instance()->get_pretty_name_by_name (*p);
239 pn = (*p).substr ((*p).find (':') + 1);
241 row[midi_port_columns.short_name] = pn;
248 P2GUI::active_port_changed (Gtk::ComboBox* combo, bool for_input)
250 if (ignore_active_change) {
254 TreeModel::iterator active = combo->get_active ();
255 string new_port = (*active)[midi_port_columns.full_name];
257 if (new_port.empty()) {
259 p2.input_port()->disconnect_all ();
261 p2.output_port()->disconnect_all ();
268 if (!p2.input_port()->connected_to (new_port)) {
269 p2.input_port()->disconnect_all ();
270 p2.input_port()->connect (new_port);
273 if (!p2.output_port()->connected_to (new_port)) {
274 p2.output_port()->disconnect_all ();
275 p2.output_port()->connect (new_port);
280 Glib::RefPtr<Gtk::ListStore>
281 P2GUI::build_pressure_mode_columns ()
283 Glib::RefPtr<Gtk::ListStore> store = ListStore::create (pressure_mode_columns);
286 row = *store->append();
287 row[pressure_mode_columns.name] = _("AfterTouch (Channel Pressure)");
288 row[pressure_mode_columns.mode] = Push2::AfterTouch;
290 row = *store->append();
291 row[pressure_mode_columns.name] = _("Polyphonic Pressure (Note Pressure)");
292 row[pressure_mode_columns.mode] = Push2::PolyPressure;
298 P2GUI::reprogram_pressure_mode ()
300 Gtk::TreeModel::iterator iter = pressure_mode_selector.get_active();
301 Push2::PressureMode pm;
304 Gtk::TreeModel::Row row = *iter;
306 pm = row[pressure_mode_columns.mode];
308 pm = Push2::AfterTouch;
311 pm = Push2::AfterTouch;
314 cerr << "Reprogram pm to " << pm << endl;
315 p2.set_pressure_mode (pm);