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 "gtkmm2ext/gtk_ui.h"
28 #include "gtkmm2ext/cell_renderer_color_selector.h"
30 #include "ardour/route_group.h"
35 #include "time_axis_view.h"
37 #include "gui_thread.h"
38 #include "editor_group_tabs.h"
39 #include "route_group_dialog.h"
40 #include "route_time_axis.h"
41 #include "editor_routes.h"
42 #include "editor_route_groups.h"
43 #include "ardour_ui.h"
45 #include "ardour/route.h"
46 #include "ardour/session.h"
51 using namespace ARDOUR;
54 using Gtkmm2ext::Keyboard;
62 EditorRouteGroups::EditorRouteGroups (Editor* e)
64 , _all_group_active_button (_("No Selection = All Tracks?"))
65 , _in_row_change (false)
68 _model = ListStore::create (_columns);
69 _display.set_model (_model);
71 Gtkmm2ext::CellRendererColorSelector* color_renderer = manage (new Gtkmm2ext::CellRendererColorSelector);
72 TreeViewColumn* color_column = manage (new TreeViewColumn ("", *color_renderer));
73 color_column->add_attribute (color_renderer->property_color(), _columns.gdkcolor);
75 _display.append_column (*color_column);
77 _display.append_column ("", _columns.text);
78 _display.append_column ("", _columns.gain);
79 _display.append_column ("", _columns.gain_relative);
80 _display.append_column ("", _columns.mute);
81 _display.append_column ("", _columns.solo);
82 _display.append_column ("", _columns.record);
83 _display.append_column ("", _columns.monitoring);
84 _display.append_column ("", _columns.select);
85 _display.append_column ("", _columns.edits);
86 _display.append_column ("", _columns.active_state);
87 _display.append_column ("", _columns.is_visible);
93 { 0, _("Col"), _("Group Tab Color") },
94 { 1, _("Name"), _("Name of Group") },
95 { 2, S_("group|G"), _("Sharing Gain?") },
96 { 3, S_("relative|Rel"), _("Relevative Gain Changes?") },
97 { 4, S_("mute|M"), _("Sharing Mute?") },
98 { 5, S_("solo|S"), _("Sharing Solo?") },
99 { 6, _("Rec"), _("Sharing Record-enable Status?") },
100 { 7, S_("monitoring|Mon"), _("Sharing Monitoring Choice?") },
101 { 8, S_("selection|Sel"), _("Sharing Selected Status?") },
102 { 9, S_("editing|E"), _("Sharing Editing?") },
103 { 10, S_("active|A"), _("Sharing Active Status?") },
104 { 11, _("Show"), _("Group is visible?") },
109 for (int i = 0; ci[i].index >= 0; ++i) {
110 col = _display.get_column (ci[i].index);
111 l = manage (new Label (ci[i].label));
112 ARDOUR_UI::instance()->set_tip (*l, ci[i].tooltip);
113 col->set_widget (*l);
116 col->set_data (X_("colnum"), GUINT_TO_POINTER(i));
118 col->set_expand (true);
120 col->set_expand (false);
121 col->set_alignment (ALIGN_CENTER);
125 _display.set_headers_visible (true);
127 color_dialog.get_colorsel()->set_has_opacity_control (false);
128 color_dialog.get_colorsel()->set_has_palette (true);
129 color_dialog.get_ok_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_ACCEPT));
130 color_dialog.get_cancel_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_CANCEL));
132 /* name is directly editable */
134 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(_display.get_column_cell_renderer (1));
135 name_cell->property_editable() = true;
136 name_cell->signal_edited().connect (sigc::mem_fun (*this, &EditorRouteGroups::name_edit));
138 for (int i = 1; ci[i].index >= 0; ++i) {
139 CellRendererToggle* active_cell = dynamic_cast <CellRendererToggle*> (_display.get_column_cell_renderer (i));
142 active_cell->property_activatable() = true;
143 active_cell->property_radio() = false;
147 _model->signal_row_changed().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_change));
148 /* What signal would you guess was emitted when the rows of your treeview are reordered
149 by a drag and drop? signal_rows_reordered? That would be far too easy.
150 No, signal_row_deleted().
152 _model->signal_row_deleted().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_deleted));
154 _display.set_name ("EditGroupList");
155 _display.get_selection()->set_mode (SELECTION_SINGLE);
156 _display.set_headers_visible (true);
157 _display.set_reorderable (false);
158 _display.set_rules_hint (true);
160 _scroller.add (_display);
161 _scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
163 _display.signal_button_press_event().connect (sigc::mem_fun(*this, &EditorRouteGroups::button_press_event), false);
165 HBox* button_box = manage (new HBox());
166 button_box->set_homogeneous (true);
168 Button* add_button = manage (new Button ());
169 Button* remove_button = manage (new Button ());
173 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
175 add_button->add (*w);
177 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
179 remove_button->add (*w);
181 add_button->signal_clicked().connect (sigc::hide_return (sigc::mem_fun (*this, &EditorRouteGroups::run_new_group_dialog)));
182 remove_button->signal_clicked().connect (sigc::mem_fun (*this, &EditorRouteGroups::remove_selected));
184 button_box->pack_start (*add_button);
185 button_box->pack_start (*remove_button);
187 _all_group_active_button.show ();
189 _display_packer.pack_start (_scroller, true, true);
190 _display_packer.pack_start (_all_group_active_button, false, false);
191 _display_packer.pack_start (*button_box, false, false);
193 _all_group_active_button.signal_toggled().connect (sigc::mem_fun (*this, &EditorRouteGroups::all_group_toggled));
194 _all_group_active_button.set_name (X_("EditorRouteGroupsAllGroupButton"));
195 ARDOUR_UI::instance()->set_tip (_all_group_active_button, _("Activate this button to operate on all tracks when none are selected."));
199 EditorRouteGroups::remove_selected ()
201 Glib::RefPtr<TreeSelection> selection = _display.get_selection();
202 TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
208 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
211 /* selection mode is single, so rows.begin() is it */
213 if ((iter = _model->get_iter (*i))) {
215 RouteGroup* rg = (*iter)[_columns.routegroup];
218 _session->remove_route_group (*rg);
224 EditorRouteGroups::button_clicked ()
226 run_new_group_dialog ();
230 EditorRouteGroups::button_press_event (GdkEventButton* ev)
232 TreeModel::Path path;
234 RouteGroup* group = 0;
235 TreeViewColumn* column;
241 bool const p = _display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly);
244 iter = _model->get_iter (path);
248 group = (*iter)[_columns.routegroup];
251 if (Keyboard::is_context_menu_event (ev)) {
252 _editor->_group_tabs->get_menu(group)->popup (1, ev->time);
257 /* cancel selection */
258 _display.get_selection()->unselect_all ();
259 /* end any editing by grabbing focus */
260 _display.grab_focus ();
264 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
266 c = (*iter)[_columns.gdkcolor];
268 color_dialog.get_colorsel()->set_previous_color (c);
269 color_dialog.get_colorsel()->set_current_color (c);
271 switch (color_dialog.run()) {
272 case RESPONSE_CANCEL:
274 case RESPONSE_ACCEPT:
275 c = color_dialog.get_colorsel()->get_current_color();
276 (*iter)[_columns.gdkcolor] = c;
277 GroupTabs::set_group_color ((*iter)[_columns.routegroup], c);
278 ARDOUR_UI::config()->set_dirty ();
286 color_dialog.hide ();
291 if (Keyboard::is_edit_event (ev)) {
292 if ((iter = _model->get_iter (path))) {
293 if ((group = (*iter)[_columns.routegroup]) != 0) {
302 if ((iter = _model->get_iter (path))) {
303 bool gain = (*iter)[_columns.gain];
304 (*iter)[_columns.gain] = !gain;
310 if ((iter = _model->get_iter (path))) {
311 bool gain_relative = (*iter)[_columns.gain_relative];
312 (*iter)[_columns.gain_relative] = !gain_relative;
318 if ((iter = _model->get_iter (path))) {
319 bool mute = (*iter)[_columns.mute];
320 (*iter)[_columns.mute] = !mute;
326 if ((iter = _model->get_iter (path))) {
327 bool solo = (*iter)[_columns.solo];
328 (*iter)[_columns.solo] = !solo;
334 if ((iter = _model->get_iter (path))) {
335 bool record = (*iter)[_columns.record];
336 (*iter)[_columns.record] = !record;
342 if ((iter = _model->get_iter (path))) {
343 bool monitoring = (*iter)[_columns.monitoring];
344 (*iter)[_columns.monitoring] = !monitoring;
350 if ((iter = _model->get_iter (path))) {
351 bool select = (*iter)[_columns.select];
352 (*iter)[_columns.select] = !select;
358 if ((iter = _model->get_iter (path))) {
359 bool edits = (*iter)[_columns.edits];
360 (*iter)[_columns.edits] = !edits;
366 if ((iter = _model->get_iter (path))) {
367 bool active_state = (*iter)[_columns.active_state];
368 (*iter)[_columns.active_state] = !active_state;
374 if ((iter = _model->get_iter (path))) {
375 bool is_visible = (*iter)[_columns.is_visible];
376 (*iter)[_columns.is_visible] = !is_visible;
388 _display.queue_draw();
396 EditorRouteGroups::row_change (const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter)
400 if (_in_row_change) {
404 if ((group = (*iter)[_columns.routegroup]) == 0) {
409 plist.add (Properties::name, string ((*iter)[_columns.text]));
411 bool val = (*iter)[_columns.gain];
412 plist.add (Properties::gain, val);
413 val = (*iter)[_columns.gain_relative];
414 plist.add (Properties::relative, val);
415 val = (*iter)[_columns.mute];
416 plist.add (Properties::mute, val);
417 val = (*iter)[_columns.solo];
418 plist.add (Properties::solo, val);
419 val = (*iter)[_columns.record];
420 plist.add (Properties::recenable, val);
421 val = (*iter)[_columns.monitoring];
422 plist.add (Properties::monitoring, val);
423 val = (*iter)[_columns.select];
424 plist.add (Properties::select, val);
425 val = (*iter)[_columns.edits];
426 plist.add (Properties::edit, val);
427 val = (*iter)[_columns.active_state];
428 plist.add (Properties::route_active, val);
430 GroupTabs::set_group_color ((*iter)[_columns.routegroup], (*iter)[_columns.gdkcolor]);
432 group->set_hidden (!(*iter)[_columns.is_visible], this);
434 /* XXX set color here */
436 group->apply_changes (plist);
440 EditorRouteGroups::add (RouteGroup* group)
442 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::add, group)
445 TreeModel::Row row = *(_model->append());
447 row[_columns.gain] = group->is_gain ();
448 row[_columns.gain_relative] = group->is_relative ();
449 row[_columns.mute] = group->is_mute ();
450 row[_columns.solo] = group->is_solo ();
451 row[_columns.record] = group->is_recenable();
452 row[_columns.monitoring] = group->is_monitoring();
453 row[_columns.select] = group->is_select ();
454 row[_columns.edits] = group->is_edit ();
455 row[_columns.active_state] = group->is_route_active ();
456 row[_columns.is_visible] = !group->is_hidden();
457 row[_columns.gdkcolor] = GroupTabs::group_color (group);
459 _in_row_change = true;
461 row[_columns.routegroup] = group;
463 if (!group->name().empty()) {
464 row[_columns.text] = group->name();
466 row[_columns.text] = _("unnamed");
470 group->PropertyChanged.connect (_property_changed_connections, MISSING_INVALIDATOR, ui_bind (&EditorRouteGroups::property_changed, this, group, _1), gui_context());
473 TreeViewColumn* col = _display.get_column (0);
474 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(_display.get_column_cell_renderer (0));
475 _display.set_cursor (_model->get_path (row), *col, *name_cell, true);
478 _in_row_change = false;
480 _editor->_group_tabs->set_dirty ();
484 EditorRouteGroups::groups_changed ()
486 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::groups_changed);
490 /* just rebuild the while thing */
495 _session->foreach_route_group (sigc::mem_fun (*this, &EditorRouteGroups::add));
502 EditorRouteGroups::property_changed (RouteGroup* group, const PropertyChange& change)
504 _in_row_change = true;
506 Gtk::TreeModel::Children children = _model->children();
508 for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
509 if (group == (*iter)[_columns.routegroup]) {
510 (*iter)[_columns.text] = group->name();
511 (*iter)[_columns.gain] = group->is_gain ();
512 (*iter)[_columns.gain_relative] = group->is_relative ();
513 (*iter)[_columns.mute] = group->is_mute ();
514 (*iter)[_columns.solo] = group->is_solo ();
515 (*iter)[_columns.record] = group->is_recenable ();
516 (*iter)[_columns.monitoring] = group->is_monitoring ();
517 (*iter)[_columns.select] = group->is_select ();
518 (*iter)[_columns.edits] = group->is_edit ();
519 (*iter)[_columns.active_state] = group->is_route_active ();
520 (*iter)[_columns.is_visible] = !group->is_hidden();
521 (*iter)[_columns.gdkcolor] = GroupTabs::group_color (group);
525 _in_row_change = false;
527 if (change.contains (Properties::name) || change.contains (Properties::color) || change.contains (Properties::active)) {
528 _editor->_group_tabs->set_dirty ();
531 for (TrackViewList::const_iterator i = _editor->get_track_views().begin(); i != _editor->get_track_views().end(); ++i) {
532 if ((*i)->route_group() == group) {
533 if (group->is_hidden ()) {
534 _editor->hide_track_in_display (*i);
536 _editor->_routes->show_track_in_display (**i);
543 EditorRouteGroups::name_edit (const std::string& path, const std::string& new_text)
548 if ((iter = _model->get_iter (path))) {
550 if ((group = (*iter)[_columns.routegroup]) == 0) {
554 if (new_text != group->name()) {
555 group->set_name (new_text);
561 EditorRouteGroups::clear ()
563 _display.set_model (Glib::RefPtr<Gtk::TreeStore> (0));
565 _display.set_model (_model);
569 EditorRouteGroups::set_session (Session* s)
571 SessionHandlePtr::set_session (s);
575 RouteGroup& arg (_session->all_route_group());
577 arg.PropertyChanged.connect (all_route_groups_changed_connection, MISSING_INVALIDATOR, ui_bind (&EditorRouteGroups::all_group_changed, this, _1), gui_context());
579 _session->route_group_added.connect (_session_connections, MISSING_INVALIDATOR, ui_bind (&EditorRouteGroups::add, this, _1), gui_context());
580 _session->route_group_removed.connect (
581 _session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::groups_changed, this), gui_context()
583 _session->route_groups_reordered.connect (
584 _session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::groups_changed, this), gui_context()
588 PBD::PropertyChange pc;
589 pc.add (Properties::select);
590 pc.add (Properties::active);
591 all_group_changed (pc);
597 EditorRouteGroups::run_new_group_dialog ()
601 return _editor->_group_tabs->run_new_group_dialog (rl);
605 EditorRouteGroups::all_group_toggled ()
608 _session->all_route_group().set_select (_all_group_active_button.get_active());
613 EditorRouteGroups::all_group_changed (const PropertyChange&)
616 RouteGroup& arg (_session->all_route_group());
617 _all_group_active_button.set_active (arg.is_active() && arg.is_select());
619 _all_group_active_button.set_active (false);
623 /** Called when a model row is deleted, but also when the model is
624 * reordered by a user drag-and-drop; the latter is what we are
625 * interested in here.
628 EditorRouteGroups::row_deleted (Gtk::TreeModel::Path const &)
631 /* We need to ignore this in cases where we're not doing a drag-and-drop
637 /* Re-write the session's route group list so that the new order is preserved */
639 list<RouteGroup*> new_list;
641 Gtk::TreeModel::Children children = _model->children();
642 for (Gtk::TreeModel::Children::iterator i = children.begin(); i != children.end(); ++i) {
643 new_list.push_back ((*i)[_columns.routegroup]);
646 _session->reorder_route_groups (new_list);