1 /*
2  * Copyright (C) 2006-2007 John Anderson
3  * Copyright (C) 2012-2016 Paul Davis <paul@linuxaudiosystems.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #include <vector>
21 
22 #include <gtkmm/combobox.h>
23 #include <gtkmm/box.h>
24 #include <gtkmm/spinbutton.h>
25 #include <gtkmm/table.h>
26 #include <gtkmm/treeview.h>
27 #include <gtkmm/liststore.h>
28 #include <gtkmm/notebook.h>
29 #include <gtkmm/scrolledwindow.h>
30 
31 namespace Gtk {
32 	class CellRendererCombo;
33 }
34 
35 #include "button.h"
36 
37 #include "pbd/i18n.h"
38 
39 namespace ActionManager {
40         class ActionModel;
41 }
42 
43 namespace ArdourSurface {
44 
45 class MackieControlProtocol;
46 
47 namespace Mackie {
48 	class Surface;
49 }
50 
51 class MackieControlProtocolGUI : public Gtk::Notebook
52 {
53    public:
54 	MackieControlProtocolGUI (MackieControlProtocol &);
55 
56    private:
57 	MackieControlProtocol& _cp;
58 	Gtk::Table         table;
59 	Gtk::ComboBoxText _surface_combo;
60 	Gtk::ComboBoxText _profile_combo;
61 
62 	typedef std::vector<Gtk::ComboBox*> PortCombos;
63 	PortCombos input_combos;
64 	PortCombos output_combos;
65 
66 	struct MidiPortColumns : public Gtk::TreeModel::ColumnRecord {
MidiPortColumnsMidiPortColumns67 		MidiPortColumns() {
68 			add (short_name);
69 			add (full_name);
70 		}
71 		Gtk::TreeModelColumn<std::string> short_name;
72 		Gtk::TreeModelColumn<std::string> full_name;
73 	};
74 
75 	struct FunctionKeyColumns : public Gtk::TreeModel::ColumnRecord {
FunctionKeyColumnsFunctionKeyColumns76 		FunctionKeyColumns() {
77 			add (name);
78 			add (id);
79 			add (plain);
80 			add (shift);
81 			add (control);
82 			add (option);
83 			add (cmdalt);
84 			add (shiftcontrol);
85 		};
86 		Gtk::TreeModelColumn<std::string> name;
87 		Gtk::TreeModelColumn<Mackie::Button::ID>  id;
88 		Gtk::TreeModelColumn<std::string> plain;
89 		Gtk::TreeModelColumn<std::string> shift;
90 		Gtk::TreeModelColumn<std::string> control;
91 		Gtk::TreeModelColumn<std::string> option;
92 		Gtk::TreeModelColumn<std::string> cmdalt;
93 		Gtk::TreeModelColumn<std::string> shiftcontrol;
94 	};
95 
96 	FunctionKeyColumns function_key_columns;
97 	MidiPortColumns midi_port_columns;
98 
99 	Gtk::ScrolledWindow function_key_scroller;
100 	Gtk::TreeView function_key_editor;
101 	Glib::RefPtr<Gtk::ListStore> function_key_model;
102 
103 	const ActionManager::ActionModel& action_model;
104 
105 	Glib::RefPtr<Gtk::ListStore> build_midi_port_list (bool for_input);
106 
107 	void refresh_function_key_editor ();
108 	void build_function_key_editor ();
109 	void action_changed (const Glib::ustring &sPath, const Gtk::TreeModel::iterator &, Gtk::TreeModelColumnBase);
110 	Gtk::CellRendererCombo* make_action_renderer (Glib::RefPtr<Gtk::TreeStore> model, Gtk::TreeModelColumnBase);
111 
112 	void surface_combo_changed ();
113 	void profile_combo_changed ();
114 	void ipmidi_spinner_changed ();
115 
116 	Gtk::CheckButton relay_click_button;
117 	Gtk::CheckButton backlight_button;
118 	Gtk::RadioButton absolute_touch_mode_button;
119 	Gtk::RadioButton touch_move_mode_button;
120 	Gtk::Adjustment  touch_sensitivity_adjustment;
121 	Gtk::HScale      touch_sensitivity_scale;
122 	Gtk::Button      recalibrate_fader_button;
123 	Gtk::Adjustment  ipmidi_base_port_adjustment;
124 	Gtk::Button      discover_button;
125 
126 	void discover_clicked ();
127 	void recalibrate_faders ();
128 	void toggle_backlight ();
129 	void touch_sensitive_change ();
130 
131 	Gtk::Widget* device_dependent_widget ();
132 	Gtk::Widget* _device_dependent_widget;
133 	int device_dependent_row;
134 
135 	PBD::ScopedConnection device_change_connection;
136 	void device_changed ();
137 
138 	void update_port_combos (std::vector<std::string> const&, std::vector<std::string> const&,
139 	                         Gtk::ComboBox* input_combo,
140 	                         Gtk::ComboBox* output_combo,
141 	                         boost::shared_ptr<Mackie::Surface> surface);
142 
143 	PBD::ScopedConnectionList _port_connections;
144 	void connection_handler ();
145 
146 	Glib::RefPtr<Gtk::ListStore> build_midi_port_list (std::vector<std::string> const & ports, bool for_input);
147 	bool _ignore_profile_changed;
148 	bool ignore_active_change;
149 	void active_port_changed (Gtk::ComboBox* combo, boost::weak_ptr<Mackie::Surface> ws, bool for_input);
150 };
151 
152 }
153