2 * Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
3 * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
4 * Copyright (C) 2009-2016 Paul Davis <paul@linuxaudiosystems.com>
5 * Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "gtk2ardour-config.h"
29 #include "fix_carbon.h"
31 #include <gtkmm/stock.h>
33 #include "gtkmm2ext/gtk_ui.h"
34 #include "gtkmm2ext/cell_renderer_color_selector.h"
36 #include "widgets/tooltips.h"
38 #include "ardour/route_group.h"
39 #include "ardour/route.h"
40 #include "ardour/session.h"
42 #include "ardour_ui.h"
44 #include "editor_group_tabs.h"
45 #include "editor_route_groups.h"
46 #include "editor_routes.h"
47 #include "gui_thread.h"
50 #include "route_group_dialog.h"
51 #include "route_time_axis.h"
52 #include "time_axis_view.h"
58 using namespace ARDOUR;
59 using namespace ARDOUR_UI_UTILS;
60 using namespace ArdourWidgets;
63 using Gtkmm2ext::Keyboard;
71 EditorRouteGroups::EditorRouteGroups (Editor* e)
73 , _in_row_change (false)
76 _model = ListStore::create (_columns);
77 _display.set_model (_model);
79 Gtkmm2ext::CellRendererColorSelector* color_renderer = manage (new Gtkmm2ext::CellRendererColorSelector);
80 TreeViewColumn* color_column = manage (new TreeViewColumn ("", *color_renderer));
82 color_column->add_attribute (color_renderer->property_color(), _columns.gdkcolor);
84 _display.append_column (*color_column);
86 _display.append_column ("", _columns.text);
87 _display.append_column ("", _columns.is_visible);
88 _display.append_column ("", _columns.active_state);
89 _display.append_column ("", _columns.gain);
90 _display.append_column ("", _columns.gain_relative);
91 _display.append_column ("", _columns.mute);
92 _display.append_column ("", _columns.solo);
93 _display.append_column ("", _columns.record);
94 _display.append_column ("", _columns.monitoring);
95 _display.append_column ("", _columns.select);
96 _display.append_column ("", _columns.active_shared);
102 { 0, _("Col"), _("Group Tab Color") },
103 { 1, _("Name"), _("Name of Group") },
104 { 2, S_("Visible|V"), _("Group is visible?") },
105 { 3, _("On"), _("Group is enabled?") },
106 { 4, S_("Group|G"), _("Sharing Gain?") },
107 { 5, S_("Relative|Rel"), _("Relative Gain Changes?") },
108 { 6, S_("Mute|M"), _("Sharing Mute?") },
109 { 7, S_("Solo|S"), _("Sharing Solo?") },
110 { 8, _("Rec"), _("Sharing Record-enable Status?") },
111 { 9, S_("Monitoring|Mon"), _("Sharing Monitoring Choice?") },
112 { 10, S_("Selection|Sel"), _("Sharing Selected/Editing Status?") },
113 { 11, S_("Active|A"), _("Sharing Active Status?") },
118 for (int i = 0; ci[i].index >= 0; ++i) {
119 col = _display.get_column (ci[i].index);
120 l = manage (new Label (ci[i].label));
121 set_tooltip (*l, ci[i].tooltip);
122 col->set_widget (*l);
125 col->set_data (X_("colnum"), GUINT_TO_POINTER(i));
127 col->set_expand (true);
129 col->set_expand (false);
130 col->set_alignment (ALIGN_CENTER);
134 _display.set_headers_visible (true);
136 color_dialog.get_colorsel()->set_has_opacity_control (false);
137 color_dialog.get_colorsel()->set_has_palette (true);
138 color_dialog.get_ok_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_ACCEPT));
139 color_dialog.get_cancel_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_CANCEL));
141 /* name is directly editable */
143 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(_display.get_column_cell_renderer (1));
144 name_cell->property_editable() = true;
145 name_cell->signal_edited().connect (sigc::mem_fun (*this, &EditorRouteGroups::name_edit));
147 for (int i = 1; ci[i].index >= 0; ++i) {
148 CellRendererToggle* active_cell = dynamic_cast <CellRendererToggle*> (_display.get_column_cell_renderer (i));
151 active_cell->property_activatable() = true;
152 active_cell->property_radio() = false;
156 _model->signal_row_changed().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_change));
157 /* What signal would you guess was emitted when the rows of your treeview are reordered
158 by a drag and drop? signal_rows_reordered? That would be far too easy.
159 No, signal_row_deleted().
161 _model->signal_row_deleted().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_deleted));
163 _display.set_name ("EditGroupList");
164 _display.get_selection()->set_mode (SELECTION_SINGLE);
165 _display.set_headers_visible (true);
166 _display.set_reorderable (false);
167 _display.set_rules_hint (true);
169 _scroller.add (_display);
170 _scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
172 _display.signal_button_press_event().connect (sigc::mem_fun(*this, &EditorRouteGroups::button_press_event), false);
174 HBox* button_box = manage (new HBox());
175 button_box->set_homogeneous (true);
177 Button* add_button = manage (new Button ());
178 Button* remove_button = manage (new Button ());
182 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
184 add_button->add (*w);
186 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
188 remove_button->add (*w);
190 add_button->signal_clicked().connect (sigc::hide_return (sigc::mem_fun (*this, &EditorRouteGroups::run_new_group_dialog)));
191 remove_button->signal_clicked().connect (sigc::mem_fun (*this, &EditorRouteGroups::remove_selected));
193 button_box->pack_start (*add_button);
194 button_box->pack_start (*remove_button);
196 _display_packer.pack_start (_scroller, true, true);
197 _display_packer.pack_start (*button_box, false, false);
201 EditorRouteGroups::remove_selected ()
203 Glib::RefPtr<TreeSelection> selection = _display.get_selection();
204 TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
206 if (rows.empty() || _session->deletion_in_progress()) {
210 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
213 /* selection mode is single, so rows.begin() is it */
215 if ((iter = _model->get_iter (*i))) {
217 RouteGroup* rg = (*iter)[_columns.routegroup];
220 _session->remove_route_group (*rg);
226 EditorRouteGroups::button_clicked ()
228 run_new_group_dialog ();
232 EditorRouteGroups::button_press_event (GdkEventButton* ev)
234 TreeModel::Path path;
236 RouteGroup* group = 0;
237 TreeViewColumn* column;
244 bool const p = _display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly);
247 iter = _model->get_iter (path);
251 group = (*iter)[_columns.routegroup];
254 if (Keyboard::is_context_menu_event (ev)) {
255 _editor->_group_tabs->get_menu(group)->popup (1, ev->time);
260 /* cancel selection */
261 _display.get_selection()->unselect_all ();
262 /* end any editing by grabbing focus */
263 _display.grab_focus ();
267 group = (*iter)[_columns.routegroup];
269 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
271 c = (*iter)[_columns.gdkcolor];
272 color_dialog.get_colorsel()->set_previous_color (c);
273 color_dialog.get_colorsel()->set_current_color (c);
275 switch (color_dialog.run()) {
276 case RESPONSE_CANCEL:
278 case RESPONSE_ACCEPT:
279 c = color_dialog.get_colorsel()->get_current_color();
280 GroupTabs::set_group_color (group, gdk_color_to_rgba (c));
288 color_dialog.hide ();
293 if (Keyboard::is_edit_event (ev) && group) {
294 /* we'll be editing now ... */
300 val = (*iter)[_columns.is_visible];
301 /* note subtle logic inverse here: we set the new value with
302 "val", rather than !val, because we're using ::set_hidden()
303 not a (non-existent) ::set_visible() call.
305 group->set_hidden (val, this);
311 val = (*iter)[_columns.active_state];
312 group->set_active (!val, this);
317 val = (*iter)[_columns.gain];
318 group->set_gain (!val);
323 val = (*iter)[_columns.gain_relative];
324 group->set_relative (!val, this);
329 val = (*iter)[_columns.mute];
330 group->set_mute (!val);
335 val = (*iter)[_columns.solo];
336 group->set_solo (!val);
341 val = (*iter)[_columns.record];
342 group->set_recenable (!val);
347 val = (*iter)[_columns.monitoring];
348 group->set_monitoring (!val);
353 val = (*iter)[_columns.select];
354 group->set_select (!val);
359 val = (*iter)[_columns.active_shared];
360 group->set_route_active (!val);
372 EditorRouteGroups::row_change (const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter)
376 if (_in_row_change) {
380 if ((group = (*iter)[_columns.routegroup]) == 0) {
385 plist.add (Properties::name, string ((*iter)[_columns.text]));
387 bool val = (*iter)[_columns.gain];
388 plist.add (Properties::group_gain, val);
389 val = (*iter)[_columns.gain_relative];
390 plist.add (Properties::group_relative, val);
391 val = (*iter)[_columns.mute];
392 plist.add (Properties::group_mute, val);
393 val = (*iter)[_columns.solo];
394 plist.add (Properties::group_solo, val);
395 val = (*iter)[_columns.record];
396 plist.add (Properties::group_recenable, val);
397 val = (*iter)[_columns.monitoring];
398 plist.add (Properties::group_monitoring, val);
399 val = (*iter)[_columns.select];
400 plist.add (Properties::group_select, val);
401 val = (*iter)[_columns.active_shared];
402 plist.add (Properties::group_route_active, val);
404 val = (*iter)[_columns.active_state];
405 plist.add (Properties::active, val);
406 val = (*iter)[_columns.is_visible];
407 plist.add (Properties::hidden, !val);
409 group->apply_changes (plist);
411 GroupTabs::set_group_color ((*iter)[_columns.routegroup], gdk_color_to_rgba ((*iter)[_columns.gdkcolor]));
415 EditorRouteGroups::add (RouteGroup* group)
417 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::add, group)
420 TreeModel::Row row = *(_model->append());
422 row[_columns.gain] = group->is_gain ();
423 row[_columns.gain_relative] = group->is_relative ();
424 row[_columns.mute] = group->is_mute ();
425 row[_columns.solo] = group->is_solo ();
426 row[_columns.record] = group->is_recenable();
427 row[_columns.monitoring] = group->is_monitoring();
428 row[_columns.select] = group->is_select ();
429 row[_columns.active_shared] = group->is_route_active ();
430 row[_columns.active_state] = group->is_active ();
431 row[_columns.is_visible] = !group->is_hidden();
434 set_color_from_rgba (c, GroupTabs::group_color (group));
435 row[_columns.gdkcolor] = c;
437 _in_row_change = true;
439 row[_columns.routegroup] = group;
441 if (!group->name().empty()) {
442 row[_columns.text] = group->name();
444 row[_columns.text] = _("unnamed");
448 group->PropertyChanged.connect (_property_changed_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::property_changed, this, group, _1), gui_context());
451 TreeViewColumn* col = _display.get_column (0);
452 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(_display.get_column_cell_renderer (1));
453 _display.set_cursor (_model->get_path (row), *col, *name_cell, true);
456 _in_row_change = false;
458 _editor->_group_tabs->set_dirty ();
462 EditorRouteGroups::groups_changed ()
464 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::groups_changed);
468 /* just rebuild the while thing */
473 _session->foreach_route_group (sigc::mem_fun (*this, &EditorRouteGroups::add));
480 EditorRouteGroups::property_changed (RouteGroup* group, const PropertyChange&)
483 _in_row_change = true;
485 Gtk::TreeModel::Children children = _model->children();
487 for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
488 if (group == (*iter)[_columns.routegroup]) {
490 /* we could check the PropertyChange and only set
491 * appropriate fields. but the amount of saved by doing
492 * that is pretty minimal, and this is nice and simple.
495 (*iter)[_columns.text] = group->name();
496 (*iter)[_columns.gain] = group->is_gain ();
497 (*iter)[_columns.gain_relative] = group->is_relative ();
498 (*iter)[_columns.mute] = group->is_mute ();
499 (*iter)[_columns.solo] = group->is_solo ();
500 (*iter)[_columns.record] = group->is_recenable ();
501 (*iter)[_columns.monitoring] = group->is_monitoring ();
502 (*iter)[_columns.select] = group->is_select ();
503 (*iter)[_columns.active_shared] = group->is_route_active ();
504 (*iter)[_columns.active_state] = group->is_active ();
505 (*iter)[_columns.is_visible] = !group->is_hidden();
508 set_color_from_rgba (c, GroupTabs::group_color (group));
509 (*iter)[_columns.gdkcolor] = c;
515 _in_row_change = false;
517 for (TrackViewList::const_iterator i = _editor->get_track_views().begin(); i != _editor->get_track_views().end(); ++i) {
518 if ((*i)->route_group() == group) {
519 if (group->is_hidden ()) {
520 _editor->hide_track_in_display (*i);
522 _editor->_routes->show_track_in_display (**i);
529 EditorRouteGroups::name_edit (const std::string& path, const std::string& new_text)
534 if ((iter = _model->get_iter (path))) {
536 if ((group = (*iter)[_columns.routegroup]) == 0) {
540 if (new_text != group->name()) {
541 group->set_name (new_text);
547 EditorRouteGroups::clear ()
549 _display.set_model (Glib::RefPtr<Gtk::TreeStore> (0));
551 _display.set_model (_model);
555 EditorRouteGroups::set_session (Session* s)
557 SessionHandlePtr::set_session (s);
561 _session->route_group_added.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::add, this, _1), gui_context());
562 _session->route_group_removed.connect (
563 _session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::groups_changed, this), gui_context()
565 _session->route_groups_reordered.connect (
566 _session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::groups_changed, this), gui_context()
570 PBD::PropertyChange pc;
571 pc.add (Properties::group_select);
572 pc.add (Properties::active);
578 EditorRouteGroups::run_new_group_dialog ()
580 return _editor->_group_tabs->run_new_group_dialog (0, false);
583 /** Called when a model row is deleted, but also when the model is
584 * reordered by a user drag-and-drop; the latter is what we are
585 * interested in here.
588 EditorRouteGroups::row_deleted (Gtk::TreeModel::Path const &)
590 if (_in_rebuild || !_session || _session->deletion_in_progress()) {
591 /* We need to ignore this in cases where we're not doing a drag-and-drop
597 /* Re-write the session's route group list so that the new order is preserved */
599 list<RouteGroup*> new_list;
601 Gtk::TreeModel::Children children = _model->children();
602 for (Gtk::TreeModel::Children::iterator i = children.begin(); i != children.end(); ++i) {
603 new_list.push_back ((*i)[_columns.routegroup]);
606 _session->reorder_route_groups (new_list);