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"
35 #include "ardour/debug.h"
37 #include "launch_control_xl.h"
43 using namespace ARDOUR;
44 using namespace ArdourSurface;
47 using namespace Gtkmm2ext;
50 LaunchControlXL::get_gui () const
53 const_cast<LaunchControlXL*>(this)->build_gui ();
55 static_cast<Gtk::VBox*>(gui)->show_all();
60 LaunchControlXL::tear_down_gui ()
63 Gtk::Widget *w = static_cast<Gtk::VBox*>(gui)->get_parent();
74 LaunchControlXL::build_gui ()
76 gui = new LCXLGUI (*this);
79 /*--------------------*/
81 LCXLGUI::LCXLGUI (LaunchControlXL& p)
85 , ignore_active_change (false)
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 = "launch_control_xl.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);
105 Gtk::Alignment* align;
108 input_combo.pack_start (midi_port_columns.short_name);
109 output_combo.pack_start (midi_port_columns.short_name);
111 input_combo.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &LCXLGUI::active_port_changed), &input_combo, true));
112 output_combo.signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &LCXLGUI::active_port_changed), &output_combo, false));
114 l = manage (new Gtk::Label);
115 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Incoming MIDI on:")));
116 l->set_alignment (1.0, 0.5);
117 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
118 table.attach (input_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
121 l = manage (new Gtk::Label);
122 l->set_markup (string_compose ("<span weight=\"bold\">%1</span>", _("Outgoing MIDI on:")));
123 l->set_alignment (1.0, 0.5);
124 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
125 table.attach (output_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
130 l = manage (new Gtk::Label (_("Fader 8 Master")));
131 l->set_alignment (1.0, 0.5);
132 table.attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
133 align = manage (new Alignment);
134 align->set (0.0, 0.5);
135 align->add (fader8master_button);
136 table.attach (*align, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0),0,0);
137 fader8master_button.set_active (lcxl.fader8master());
138 fader8master_button.signal_toggled().connect (sigc::mem_fun (*this, &LCXLGUI::toggle_fader8master));
141 hpacker.pack_start (table, true, true);
145 pack_start (hpacker, false, false);
147 /* update the port connection combos */
149 update_port_combos ();
151 /* catch future changes to connection state */
153 ARDOUR::AudioEngine::instance()->PortRegisteredOrUnregistered.connect (port_reg_connection, invalidator (*this), boost::bind (&LCXLGUI::connection_handler, this), gui_context());
154 lcxl.ConnectionChange.connect (connection_change_connection, invalidator (*this), boost::bind (&LCXLGUI::connection_handler, this), gui_context());
162 LCXLGUI::connection_handler ()
164 /* ignore all changes to combobox active strings here, because we're
165 updating them to match a new ("external") reality - we were called
166 because port connections have changed.
169 PBD::Unwinder<bool> ici (ignore_active_change, true);
171 update_port_combos ();
175 LCXLGUI::update_port_combos ()
177 vector<string> midi_inputs;
178 vector<string> midi_outputs;
180 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsTerminal), midi_inputs);
181 ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsTerminal), midi_outputs);
183 Glib::RefPtr<Gtk::ListStore> input = build_midi_port_list (midi_inputs, true);
184 Glib::RefPtr<Gtk::ListStore> output = build_midi_port_list (midi_outputs, false);
185 bool input_found = false;
186 bool output_found = false;
189 input_combo.set_model (input);
190 output_combo.set_model (output);
192 Gtk::TreeModel::Children children = input->children();
193 Gtk::TreeModel::Children::iterator i;
194 i = children.begin();
195 ++i; /* skip "Disconnected" */
198 for (n = 1; i != children.end(); ++i, ++n) {
199 string port_name = (*i)[midi_port_columns.full_name];
200 if (lcxl.input_port()->connected_to (port_name)) {
201 input_combo.set_active (n);
208 input_combo.set_active (0); /* disconnected */
211 children = output->children();
212 i = children.begin();
213 ++i; /* skip "Disconnected" */
215 for (n = 1; i != children.end(); ++i, ++n) {
216 string port_name = (*i)[midi_port_columns.full_name];
217 if (lcxl.output_port()->connected_to (port_name)) {
218 output_combo.set_active (n);
225 output_combo.set_active (0); /* disconnected */
229 Glib::RefPtr<Gtk::ListStore>
230 LCXLGUI::build_midi_port_list (vector<string> const & ports, bool for_input)
232 Glib::RefPtr<Gtk::ListStore> store = ListStore::create (midi_port_columns);
235 row = *store->append ();
236 row[midi_port_columns.full_name] = string();
237 row[midi_port_columns.short_name] = _("Disconnected");
239 for (vector<string>::const_iterator p = ports.begin(); p != ports.end(); ++p) {
240 row = *store->append ();
241 row[midi_port_columns.full_name] = *p;
242 std::string pn = ARDOUR::AudioEngine::instance()->get_pretty_name_by_name (*p);
244 pn = (*p).substr ((*p).find (':') + 1);
246 row[midi_port_columns.short_name] = pn;
253 LCXLGUI::active_port_changed (Gtk::ComboBox* combo, bool for_input)
255 if (ignore_active_change) {
259 TreeModel::iterator active = combo->get_active ();
260 string new_port = (*active)[midi_port_columns.full_name];
262 if (new_port.empty()) {
264 lcxl.input_port()->disconnect_all ();
266 lcxl.output_port()->disconnect_all ();
273 if (!lcxl.input_port()->connected_to (new_port)) {
274 lcxl.input_port()->disconnect_all ();
275 lcxl.input_port()->connect (new_port);
278 if (!lcxl.output_port()->connected_to (new_port)) {
279 lcxl.output_port()->disconnect_all ();
280 lcxl.output_port()->connect (new_port);
286 LCXLGUI::toggle_fader8master ()
288 DEBUG_TRACE(DEBUG::LaunchControlXL, string_compose("use_fader8master WAS: %1\n", lcxl.fader8master()));
289 lcxl.set_fader8master (!lcxl.fader8master());
290 DEBUG_TRACE(DEBUG::LaunchControlXL, string_compose("use_fader8master IS: %1\n", lcxl.fader8master()));