2 Copyright (C) 2000 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.
21 #include "gtk2ardour-config.h"
27 #include "fix_carbon.h"
29 #include "gtkmm2ext/gtk_ui.h"
30 #include "gtkmm2ext/cell_renderer_color_selector.h"
32 #include "ardour/route_group.h"
33 #include "ardour/route.h"
34 #include "ardour/session.h"
36 #include "ardour_ui.h"
38 #include "editor_group_tabs.h"
39 #include "editor_route_groups.h"
40 #include "editor_routes.h"
41 #include "gui_thread.h"
45 #include "route_group_dialog.h"
46 #include "route_time_axis.h"
47 #include "time_axis_view.h"
53 using namespace ARDOUR;
56 using Gtkmm2ext::Keyboard;
64 EditorRouteGroups::EditorRouteGroups (Editor* e)
66 , _all_group_active_button (_("No Selection = All Tracks?"))
67 , _in_row_change (false)
70 _model = ListStore::create (_columns);
71 _display.set_model (_model);
73 Gtkmm2ext::CellRendererColorSelector* color_renderer = manage (new Gtkmm2ext::CellRendererColorSelector);
74 TreeViewColumn* color_column = manage (new TreeViewColumn ("", *color_renderer));
76 color_column->add_attribute (color_renderer->property_color(), _columns.gdkcolor);
78 _display.append_column (*color_column);
80 _display.append_column ("", _columns.text);
81 _display.append_column ("", _columns.is_visible);
82 _display.append_column ("", _columns.active_state);
83 _display.append_column ("", _columns.gain);
84 _display.append_column ("", _columns.gain_relative);
85 _display.append_column ("", _columns.mute);
86 _display.append_column ("", _columns.solo);
87 _display.append_column ("", _columns.record);
88 _display.append_column ("", _columns.monitoring);
89 _display.append_column ("", _columns.select);
90 _display.append_column ("", _columns.active_shared);
96 { 0, _("Col"), _("Group Tab Color") },
97 { 1, _("Name"), _("Name of Group") },
98 { 2, _("V"), _("Group is visible?") },
99 { 3, _("On"), _("Group is enabled?") },
100 { 4, S_("group|G"), _("Sharing Gain?") },
101 { 5, S_("relative|Rel"), _("Relative Gain Changes?") },
102 { 6, S_("mute|M"), _("Sharing Mute?") },
103 { 7, S_("solo|S"), _("Sharing Solo?") },
104 { 8, _("Rec"), _("Sharing Record-enable Status?") },
105 { 9, S_("monitoring|Mon"), _("Sharing Monitoring Choice?") },
106 { 10, S_("selection|Sel"), _("Sharing Selected/Editing Status?") },
107 { 11, S_("active|A"), _("Sharing Active Status?") },
112 for (int i = 0; ci[i].index >= 0; ++i) {
113 col = _display.get_column (ci[i].index);
114 l = manage (new Label (ci[i].label));
115 ARDOUR_UI::instance()->set_tip (*l, ci[i].tooltip);
116 col->set_widget (*l);
119 col->set_data (X_("colnum"), GUINT_TO_POINTER(i));
121 col->set_expand (true);
123 col->set_expand (false);
124 col->set_alignment (ALIGN_CENTER);
128 _display.set_headers_visible (true);
130 color_dialog.get_colorsel()->set_has_opacity_control (false);
131 color_dialog.get_colorsel()->set_has_palette (true);
132 color_dialog.get_ok_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_ACCEPT));
133 color_dialog.get_cancel_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_CANCEL));
135 /* name is directly editable */
137 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(_display.get_column_cell_renderer (1));
138 name_cell->property_editable() = true;
139 name_cell->signal_edited().connect (sigc::mem_fun (*this, &EditorRouteGroups::name_edit));
141 for (int i = 1; ci[i].index >= 0; ++i) {
142 CellRendererToggle* active_cell = dynamic_cast <CellRendererToggle*> (_display.get_column_cell_renderer (i));
145 active_cell->property_activatable() = true;
146 active_cell->property_radio() = false;
150 _model->signal_row_changed().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_change));
151 /* What signal would you guess was emitted when the rows of your treeview are reordered
152 by a drag and drop? signal_rows_reordered? That would be far too easy.
153 No, signal_row_deleted().
155 _model->signal_row_deleted().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_deleted));
157 _display.set_name ("EditGroupList");
158 _display.get_selection()->set_mode (SELECTION_SINGLE);
159 _display.set_headers_visible (true);
160 _display.set_reorderable (false);
161 _display.set_rules_hint (true);
163 _scroller.add (_display);
164 _scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
166 _display.signal_button_press_event().connect (sigc::mem_fun(*this, &EditorRouteGroups::button_press_event), false);
168 HBox* button_box = manage (new HBox());
169 button_box->set_homogeneous (true);
171 Button* add_button = manage (new Button ());
172 Button* remove_button = manage (new Button ());
176 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
178 add_button->add (*w);
180 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
182 remove_button->add (*w);
184 add_button->signal_clicked().connect (sigc::hide_return (sigc::mem_fun (*this, &EditorRouteGroups::run_new_group_dialog)));
185 remove_button->signal_clicked().connect (sigc::mem_fun (*this, &EditorRouteGroups::remove_selected));
187 button_box->pack_start (*add_button);
188 button_box->pack_start (*remove_button);
190 _all_group_active_button.show ();
192 _display_packer.pack_start (_scroller, true, true);
193 _display_packer.pack_start (_all_group_active_button, false, false);
194 _display_packer.pack_start (*button_box, false, false);
196 _all_group_active_button.signal_toggled().connect (sigc::mem_fun (*this, &EditorRouteGroups::all_group_toggled));
197 _all_group_active_button.set_name (X_("EditorRouteGroupsAllGroupButton"));
198 ARDOUR_UI::instance()->set_tip (_all_group_active_button, _("Activate this button to operate on all tracks when none are selected."));
202 EditorRouteGroups::remove_selected ()
204 Glib::RefPtr<TreeSelection> selection = _display.get_selection();
205 TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
211 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
214 /* selection mode is single, so rows.begin() is it */
216 if ((iter = _model->get_iter (*i))) {
218 RouteGroup* rg = (*iter)[_columns.routegroup];
221 _session->remove_route_group (*rg);
227 EditorRouteGroups::button_clicked ()
229 run_new_group_dialog ();
233 EditorRouteGroups::button_press_event (GdkEventButton* ev)
235 TreeModel::Path path;
237 RouteGroup* group = 0;
238 TreeViewColumn* column;
245 bool const p = _display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly);
248 iter = _model->get_iter (path);
252 group = (*iter)[_columns.routegroup];
255 if (Keyboard::is_context_menu_event (ev)) {
256 _editor->_group_tabs->get_menu(group)->popup (1, ev->time);
261 /* cancel selection */
262 _display.get_selection()->unselect_all ();
263 /* end any editing by grabbing focus */
264 _display.grab_focus ();
268 group = (*iter)[_columns.routegroup];
270 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
272 c = (*iter)[_columns.gdkcolor];
273 color_dialog.get_colorsel()->set_previous_color (c);
274 color_dialog.get_colorsel()->set_current_color (c);
276 switch (color_dialog.run()) {
277 case RESPONSE_CANCEL:
279 case RESPONSE_ACCEPT:
280 c = color_dialog.get_colorsel()->get_current_color();
281 GroupTabs::set_group_color (group, gdk_color_to_rgba (c));
282 ARDOUR_UI::config()->set_dirty ();
290 color_dialog.hide ();
295 if (Keyboard::is_edit_event (ev) && group) {
296 /* we'll be editing now ... */
302 val = (*iter)[_columns.is_visible];
303 /* note subtle logic inverse here: we set the new value with
304 "val", rather than !val, because we're using ::set_hidden()
305 not a (non-existent) ::set_visible() call.
307 group->set_hidden (val, this);
313 val = (*iter)[_columns.active_state];
314 group->set_active (!val, this);
319 val = (*iter)[_columns.gain];
320 group->set_gain (!val);
325 val = (*iter)[_columns.gain_relative];
326 group->set_relative (!val, this);
331 val = (*iter)[_columns.mute];
332 group->set_mute (!val);
337 val = (*iter)[_columns.solo];
338 group->set_solo (!val);
343 val = (*iter)[_columns.record];
344 group->set_recenable (!val);
349 val = (*iter)[_columns.monitoring];
350 group->set_monitoring (!val);
355 val = (*iter)[_columns.select];
356 group->set_select (!val);
361 val = (*iter)[_columns.active_shared];
362 group->set_route_active (!val);
374 EditorRouteGroups::row_change (const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter)
378 if (_in_row_change) {
382 if ((group = (*iter)[_columns.routegroup]) == 0) {
387 plist.add (Properties::name, string ((*iter)[_columns.text]));
389 bool val = (*iter)[_columns.gain];
390 plist.add (Properties::gain, val);
391 val = (*iter)[_columns.gain_relative];
392 plist.add (Properties::relative, val);
393 val = (*iter)[_columns.mute];
394 plist.add (Properties::mute, val);
395 val = (*iter)[_columns.solo];
396 plist.add (Properties::solo, val);
397 val = (*iter)[_columns.record];
398 plist.add (Properties::recenable, val);
399 val = (*iter)[_columns.monitoring];
400 plist.add (Properties::monitoring, val);
401 val = (*iter)[_columns.select];
402 plist.add (Properties::select, val);
403 val = (*iter)[_columns.active_shared];
404 plist.add (Properties::route_active, val);
405 val = (*iter)[_columns.active_state];
406 plist.add (Properties::active, val);
407 val = (*iter)[_columns.is_visible];
408 plist.add (Properties::hidden, !val);
410 group->apply_changes (plist);
412 GroupTabs::set_group_color ((*iter)[_columns.routegroup], gdk_color_to_rgba ((*iter)[_columns.gdkcolor]));
416 EditorRouteGroups::add (RouteGroup* group)
418 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::add, group)
421 TreeModel::Row row = *(_model->append());
423 row[_columns.gain] = group->is_gain ();
424 row[_columns.gain_relative] = group->is_relative ();
425 row[_columns.mute] = group->is_mute ();
426 row[_columns.solo] = group->is_solo ();
427 row[_columns.record] = group->is_recenable();
428 row[_columns.monitoring] = group->is_monitoring();
429 row[_columns.select] = group->is_select ();
430 row[_columns.active_shared] = group->is_route_active ();
431 row[_columns.active_state] = group->is_active ();
432 row[_columns.is_visible] = !group->is_hidden();
435 set_color_from_rgba (c, GroupTabs::group_color (group));
436 row[_columns.gdkcolor] = c;
438 _in_row_change = true;
440 row[_columns.routegroup] = group;
442 if (!group->name().empty()) {
443 row[_columns.text] = group->name();
445 row[_columns.text] = _("unnamed");
449 group->PropertyChanged.connect (_property_changed_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::property_changed, this, group, _1), gui_context());
452 TreeViewColumn* col = _display.get_column (0);
453 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(_display.get_column_cell_renderer (1));
454 _display.set_cursor (_model->get_path (row), *col, *name_cell, true);
457 _in_row_change = false;
459 _editor->_group_tabs->set_dirty ();
463 EditorRouteGroups::groups_changed ()
465 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::groups_changed);
469 /* just rebuild the while thing */
474 _session->foreach_route_group (sigc::mem_fun (*this, &EditorRouteGroups::add));
481 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 RouteGroup& arg (_session->all_route_group());
563 arg.PropertyChanged.connect (all_route_groups_changed_connection, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::all_group_changed, this, _1), gui_context());
565 _session->route_group_added.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::add, this, _1), gui_context());
566 _session->route_group_removed.connect (
567 _session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::groups_changed, this), gui_context()
569 _session->route_groups_reordered.connect (
570 _session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::groups_changed, this), gui_context()
574 PBD::PropertyChange pc;
575 pc.add (Properties::select);
576 pc.add (Properties::active);
577 all_group_changed (pc);
583 EditorRouteGroups::run_new_group_dialog ()
587 return _editor->_group_tabs->run_new_group_dialog (rl);
591 EditorRouteGroups::all_group_toggled ()
594 _session->all_route_group().set_select (_all_group_active_button.get_active());
599 EditorRouteGroups::all_group_changed (const PropertyChange&)
602 RouteGroup& arg (_session->all_route_group());
603 _all_group_active_button.set_active (arg.is_active() && arg.is_select());
605 _all_group_active_button.set_active (false);
609 /** Called when a model row is deleted, but also when the model is
610 * reordered by a user drag-and-drop; the latter is what we are
611 * interested in here.
614 EditorRouteGroups::row_deleted (Gtk::TreeModel::Path const &)
617 /* We need to ignore this in cases where we're not doing a drag-and-drop
623 /* Re-write the session's route group list so that the new order is preserved */
625 list<RouteGroup*> new_list;
627 Gtk::TreeModel::Children children = _model->children();
628 for (Gtk::TreeModel::Children::iterator i = children.begin(); i != children.end(); ++i) {
629 new_list.push_back ((*i)[_columns.routegroup]);
632 _session->reorder_route_groups (new_list);