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 if (Keyboard::is_edit_event (ev)) {
267 if ((iter = _model->get_iter (path))) {
268 if ((group = (*iter)[_columns.routegroup]) != 0) {
277 if ((iter = _model->get_iter (path))) {
278 bool gain = (*iter)[_columns.gain];
279 (*iter)[_columns.gain] = !gain;
285 if ((iter = _model->get_iter (path))) {
286 bool gain_relative = (*iter)[_columns.gain_relative];
287 (*iter)[_columns.gain_relative] = !gain_relative;
293 if ((iter = _model->get_iter (path))) {
294 bool mute = (*iter)[_columns.mute];
295 (*iter)[_columns.mute] = !mute;
301 if ((iter = _model->get_iter (path))) {
302 bool solo = (*iter)[_columns.solo];
303 (*iter)[_columns.solo] = !solo;
309 if ((iter = _model->get_iter (path))) {
310 bool record = (*iter)[_columns.record];
311 (*iter)[_columns.record] = !record;
317 if ((iter = _model->get_iter (path))) {
318 bool monitoring = (*iter)[_columns.monitoring];
319 (*iter)[_columns.monitoring] = !monitoring;
325 if ((iter = _model->get_iter (path))) {
326 bool select = (*iter)[_columns.select];
327 (*iter)[_columns.select] = !select;
333 if ((iter = _model->get_iter (path))) {
334 bool edits = (*iter)[_columns.edits];
335 (*iter)[_columns.edits] = !edits;
341 if ((iter = _model->get_iter (path))) {
342 bool active_state = (*iter)[_columns.active_state];
343 (*iter)[_columns.active_state] = !active_state;
349 if ((iter = _model->get_iter (path))) {
350 bool is_visible = (*iter)[_columns.is_visible];
351 (*iter)[_columns.is_visible] = !is_visible;
357 c = (*iter)[_columns.gdkcolor];
359 color_dialog.get_colorsel()->set_previous_color (c);
360 color_dialog.get_colorsel()->set_current_color (c);
362 switch (color_dialog.run()) {
363 case RESPONSE_CANCEL:
365 case RESPONSE_ACCEPT:
366 c = color_dialog.get_colorsel()->get_current_color();
367 (*iter)[_columns.gdkcolor] = c;
368 GroupTabs::set_group_color ((*iter)[_columns.routegroup], c);
369 ARDOUR_UI::config()->set_dirty ();
377 color_dialog.hide ();
387 _display.queue_draw();
395 EditorRouteGroups::row_change (const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter)
399 if (_in_row_change) {
403 if ((group = (*iter)[_columns.routegroup]) == 0) {
408 plist.add (Properties::name, string ((*iter)[_columns.text]));
410 bool val = (*iter)[_columns.gain];
411 plist.add (Properties::gain, val);
412 val = (*iter)[_columns.gain_relative];
413 plist.add (Properties::relative, val);
414 val = (*iter)[_columns.mute];
415 plist.add (Properties::mute, val);
416 val = (*iter)[_columns.solo];
417 plist.add (Properties::solo, val);
418 val = (*iter)[_columns.record];
419 plist.add (Properties::recenable, val);
420 val = (*iter)[_columns.monitoring];
421 plist.add (Properties::monitoring, val);
422 val = (*iter)[_columns.select];
423 plist.add (Properties::select, val);
424 val = (*iter)[_columns.edits];
425 plist.add (Properties::edit, val);
426 val = (*iter)[_columns.active_state];
427 plist.add (Properties::route_active, val);
429 GroupTabs::set_group_color ((*iter)[_columns.routegroup], (*iter)[_columns.gdkcolor]);
431 group->set_hidden (!(*iter)[_columns.is_visible], this);
433 /* XXX set color here */
435 group->apply_changes (plist);
439 EditorRouteGroups::add (RouteGroup* group)
441 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::add, group)
444 TreeModel::Row row = *(_model->append());
446 row[_columns.gain] = group->is_gain ();
447 row[_columns.gain_relative] = group->is_relative ();
448 row[_columns.mute] = group->is_mute ();
449 row[_columns.solo] = group->is_solo ();
450 row[_columns.record] = group->is_recenable();
451 row[_columns.monitoring] = group->is_monitoring();
452 row[_columns.select] = group->is_select ();
453 row[_columns.edits] = group->is_edit ();
454 row[_columns.active_state] = group->is_route_active ();
455 row[_columns.is_visible] = !group->is_hidden();
456 row[_columns.gdkcolor] = GroupTabs::group_color (group);
458 _in_row_change = true;
460 row[_columns.routegroup] = group;
462 if (!group->name().empty()) {
463 row[_columns.text] = group->name();
465 row[_columns.text] = _("unnamed");
469 group->PropertyChanged.connect (_property_changed_connections, MISSING_INVALIDATOR, ui_bind (&EditorRouteGroups::property_changed, this, group, _1), gui_context());
472 TreeViewColumn* col = _display.get_column (0);
473 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(_display.get_column_cell_renderer (0));
474 _display.set_cursor (_model->get_path (row), *col, *name_cell, true);
477 _in_row_change = false;
479 _editor->_group_tabs->set_dirty ();
483 EditorRouteGroups::groups_changed ()
485 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::groups_changed);
489 /* just rebuild the while thing */
494 _session->foreach_route_group (sigc::mem_fun (*this, &EditorRouteGroups::add));
501 EditorRouteGroups::property_changed (RouteGroup* group, const PropertyChange& change)
503 _in_row_change = true;
505 Gtk::TreeModel::Children children = _model->children();
507 for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
508 if (group == (*iter)[_columns.routegroup]) {
509 (*iter)[_columns.text] = group->name();
510 (*iter)[_columns.gain] = group->is_gain ();
511 (*iter)[_columns.gain_relative] = group->is_relative ();
512 (*iter)[_columns.mute] = group->is_mute ();
513 (*iter)[_columns.solo] = group->is_solo ();
514 (*iter)[_columns.record] = group->is_recenable ();
515 (*iter)[_columns.monitoring] = group->is_monitoring ();
516 (*iter)[_columns.select] = group->is_select ();
517 (*iter)[_columns.edits] = group->is_edit ();
518 (*iter)[_columns.active_state] = group->is_route_active ();
519 (*iter)[_columns.is_visible] = !group->is_hidden();
520 (*iter)[_columns.gdkcolor] = GroupTabs::group_color (group);
524 _in_row_change = false;
526 if (change.contains (Properties::name) || change.contains (Properties::color) || change.contains (Properties::active)) {
527 _editor->_group_tabs->set_dirty ();
530 for (TrackViewList::const_iterator i = _editor->get_track_views().begin(); i != _editor->get_track_views().end(); ++i) {
531 if ((*i)->route_group() == group) {
532 if (group->is_hidden ()) {
533 _editor->hide_track_in_display (*i);
535 _editor->_routes->show_track_in_display (**i);
542 EditorRouteGroups::name_edit (const std::string& path, const std::string& new_text)
547 if ((iter = _model->get_iter (path))) {
549 if ((group = (*iter)[_columns.routegroup]) == 0) {
553 if (new_text != group->name()) {
554 group->set_name (new_text);
560 EditorRouteGroups::clear ()
562 _display.set_model (Glib::RefPtr<Gtk::TreeStore> (0));
564 _display.set_model (_model);
568 EditorRouteGroups::set_session (Session* s)
570 SessionHandlePtr::set_session (s);
574 RouteGroup& arg (_session->all_route_group());
576 arg.PropertyChanged.connect (all_route_groups_changed_connection, MISSING_INVALIDATOR, ui_bind (&EditorRouteGroups::all_group_changed, this, _1), gui_context());
578 _session->route_group_added.connect (_session_connections, MISSING_INVALIDATOR, ui_bind (&EditorRouteGroups::add, this, _1), gui_context());
579 _session->route_group_removed.connect (
580 _session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::groups_changed, this), gui_context()
582 _session->route_groups_reordered.connect (
583 _session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::groups_changed, this), gui_context()
587 PBD::PropertyChange pc;
588 pc.add (Properties::select);
589 pc.add (Properties::active);
590 all_group_changed (pc);
596 EditorRouteGroups::run_new_group_dialog ()
600 return _editor->_group_tabs->run_new_group_dialog (rl);
604 EditorRouteGroups::all_group_toggled ()
607 _session->all_route_group().set_select (_all_group_active_button.get_active());
612 EditorRouteGroups::all_group_changed (const PropertyChange&)
615 RouteGroup& arg (_session->all_route_group());
616 _all_group_active_button.set_active (arg.is_active() && arg.is_select());
618 _all_group_active_button.set_active (false);
622 /** Called when a model row is deleted, but also when the model is
623 * reordered by a user drag-and-drop; the latter is what we are
624 * interested in here.
627 EditorRouteGroups::row_deleted (Gtk::TreeModel::Path const &)
630 /* We need to ignore this in cases where we're not doing a drag-and-drop
636 /* Re-write the session's route group list so that the new order is preserved */
638 list<RouteGroup*> new_list;
640 Gtk::TreeModel::Children children = _model->children();
641 for (Gtk::TreeModel::Children::iterator i = children.begin(); i != children.end(); ++i) {
642 new_list.push_back ((*i)[_columns.routegroup]);
645 _session->reorder_route_groups (new_list);