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 _display.append_column ("", _columns.text);
72 _display.append_column ("", _columns.gain);
73 _display.append_column ("", _columns.gain_relative);
74 _display.append_column ("", _columns.mute);
75 _display.append_column ("", _columns.solo);
76 _display.append_column ("", _columns.record);
77 _display.append_column ("", _columns.monitoring);
78 _display.append_column ("", _columns.select);
79 _display.append_column ("", _columns.edits);
80 _display.append_column ("", _columns.active_state);
81 _display.append_column ("", _columns.is_visible);
83 Gtkmm2ext::CellRendererColorSelector* color_renderer = manage (new Gtkmm2ext::CellRendererColorSelector);
84 TreeViewColumn* color_column = manage (new TreeViewColumn ("", *color_renderer));
85 color_column->add_attribute (color_renderer->property_color(), _columns.gdkcolor);
87 _display.append_column (*color_column);
93 { 0, _("Name"), _("Name of Group") },
94 { 1, S_("group|G"), _("Sharing Gain?") },
95 { 2, S_("relative|Rel"), _("Relevative Gain Changes?") },
96 { 3, S_("mute|M"), _("Sharing Mute?") },
97 { 4, S_("solo|S"), _("Sharing Solo?") },
98 { 5, _("Rec"), _("Sharing Record-enable Status?") },
99 { 6, S_("monitoring|Mon"), _("Sharing Monitoring Choice?") },
100 { 7, S_("selection|Sel"), _("Sharing Selected Status?") },
101 { 8, S_("editing|E"), _("Sharing Editing?") },
102 { 9, S_("active|A"), _("Sharing Active Status?") },
103 { 10, _("Show"), _("Group is visible?") },
104 { 11, _("Col"), _("Group Tab Color") },
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 (0));
135 name_cell->property_editable() = true;
136 name_cell->signal_edited().connect (sigc::mem_fun (*this, &EditorRouteGroups::name_edit));
138 /* use checkbox for the active + visible columns */
140 for (int i = 1; ci[i].index >= 0; ++i) {
141 CellRendererToggle* active_cell = dynamic_cast <CellRendererToggle*> (_display.get_column_cell_renderer (i));
144 active_cell->property_activatable() = true;
145 active_cell->property_radio() = false;
149 _model->signal_row_changed().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_change));
150 /* What signal would you guess was emitted when the rows of your treeview are reordered
151 by a drag and drop? signal_rows_reordered? That would be far too easy.
152 No, signal_row_deleted().
154 _model->signal_row_deleted().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_deleted));
156 _display.set_name ("EditGroupList");
157 _display.get_selection()->set_mode (SELECTION_SINGLE);
158 _display.set_headers_visible (true);
159 _display.set_reorderable (false);
160 _display.set_rules_hint (true);
162 _scroller.add (_display);
163 _scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
165 _display.signal_button_press_event().connect (sigc::mem_fun(*this, &EditorRouteGroups::button_press_event), false);
167 HBox* button_box = manage (new HBox());
168 button_box->set_homogeneous (true);
170 Button* add_button = manage (new Button ());
171 Button* remove_button = manage (new Button ());
175 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
177 add_button->add (*w);
179 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
181 remove_button->add (*w);
183 add_button->signal_clicked().connect (sigc::hide_return (sigc::mem_fun (*this, &EditorRouteGroups::run_new_group_dialog)));
184 remove_button->signal_clicked().connect (sigc::mem_fun (*this, &EditorRouteGroups::remove_selected));
186 button_box->pack_start (*add_button);
187 button_box->pack_start (*remove_button);
189 _all_group_active_button.show ();
191 _display_packer.pack_start (_scroller, true, true);
192 _display_packer.pack_start (_all_group_active_button, false, false);
193 _display_packer.pack_start (*button_box, false, false);
195 _all_group_active_button.signal_toggled().connect (sigc::mem_fun (*this, &EditorRouteGroups::all_group_toggled));
196 _all_group_active_button.set_name (X_("EditorRouteGroupsAllGroupButton"));
197 ARDOUR_UI::instance()->set_tip (_all_group_active_button, _("Activate this button to operate on all tracks when none are selected."));
201 EditorRouteGroups::remove_selected ()
203 Glib::RefPtr<TreeSelection> selection = _display.get_selection();
204 TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
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;
243 bool const p = _display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly);
246 iter = _model->get_iter (path);
250 group = (*iter)[_columns.routegroup];
253 if (Keyboard::is_context_menu_event (ev)) {
254 _editor->_group_tabs->get_menu(group)->popup (1, ev->time);
259 /* cancel selection */
260 _display.get_selection()->unselect_all ();
261 /* end any editing by grabbing focus */
262 _display.grab_focus ();
266 cerr << "click on col " << GPOINTER_TO_UINT (column->get_data (X_("colnum"))) << endl;
268 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
270 if (Keyboard::is_edit_event (ev)) {
271 if ((iter = _model->get_iter (path))) {
272 if ((group = (*iter)[_columns.routegroup]) != 0) {
281 if ((iter = _model->get_iter (path))) {
282 bool gain = (*iter)[_columns.gain];
283 (*iter)[_columns.gain] = !gain;
289 if ((iter = _model->get_iter (path))) {
290 bool gain_relative = (*iter)[_columns.gain_relative];
291 (*iter)[_columns.gain_relative] = !gain_relative;
297 if ((iter = _model->get_iter (path))) {
298 bool mute = (*iter)[_columns.mute];
299 (*iter)[_columns.mute] = !mute;
305 if ((iter = _model->get_iter (path))) {
306 bool solo = (*iter)[_columns.solo];
307 (*iter)[_columns.solo] = !solo;
313 if ((iter = _model->get_iter (path))) {
314 bool record = (*iter)[_columns.record];
315 (*iter)[_columns.record] = !record;
321 if ((iter = _model->get_iter (path))) {
322 bool monitoring = (*iter)[_columns.monitoring];
323 (*iter)[_columns.monitoring] = !monitoring;
329 if ((iter = _model->get_iter (path))) {
330 bool select = (*iter)[_columns.select];
331 (*iter)[_columns.select] = !select;
337 if ((iter = _model->get_iter (path))) {
338 bool edits = (*iter)[_columns.edits];
339 (*iter)[_columns.edits] = !edits;
345 if ((iter = _model->get_iter (path))) {
346 bool active_state = (*iter)[_columns.active_state];
347 (*iter)[_columns.active_state] = !active_state;
353 if ((iter = _model->get_iter (path))) {
354 bool is_visible = (*iter)[_columns.is_visible];
355 (*iter)[_columns.is_visible] = !is_visible;
361 c = (*iter)[_columns.gdkcolor];
363 color_dialog.get_colorsel()->set_previous_color (c);
364 color_dialog.get_colorsel()->set_current_color (c);
366 switch (color_dialog.run()) {
367 case RESPONSE_CANCEL:
370 case RESPONSE_ACCEPT:
371 c = color_dialog.get_colorsel()->get_current_color();
372 (*iter)[_columns.gdkcolor] = c;
373 cerr << "Set group " << (*iter)[_columns.routegroup] << " color to "
374 << c.get_red_p() << ':' << c.get_green_p() << ':'
375 << c.get_blue_p() << endl;
376 GroupTabs::set_group_color ((*iter)[_columns.routegroup], c);
377 ARDOUR_UI::config()->set_dirty ();
381 cerr << "no accept nor cancel\n";
386 color_dialog.hide ();
396 _display.queue_draw();
404 EditorRouteGroups::row_change (const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter)
408 if (_in_row_change) {
412 if ((group = (*iter)[_columns.routegroup]) == 0) {
417 plist.add (Properties::name, string ((*iter)[_columns.text]));
419 bool val = (*iter)[_columns.gain];
420 plist.add (Properties::gain, val);
421 val = (*iter)[_columns.gain_relative];
422 plist.add (Properties::relative, val);
423 val = (*iter)[_columns.mute];
424 plist.add (Properties::mute, val);
425 val = (*iter)[_columns.solo];
426 plist.add (Properties::solo, val);
427 val = (*iter)[_columns.record];
428 plist.add (Properties::recenable, val);
429 val = (*iter)[_columns.monitoring];
430 plist.add (Properties::monitoring, val);
431 val = (*iter)[_columns.select];
432 plist.add (Properties::select, val);
433 val = (*iter)[_columns.edits];
434 plist.add (Properties::edit, val);
435 val = (*iter)[_columns.active_state];
436 plist.add (Properties::route_active, val);
438 GroupTabs::set_group_color ((*iter)[_columns.routegroup], (*iter)[_columns.gdkcolor]);
440 group->set_hidden (!(*iter)[_columns.is_visible], this);
442 /* XXX set color here */
444 group->apply_changes (plist);
448 EditorRouteGroups::add (RouteGroup* group)
450 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::add, group)
453 TreeModel::Row row = *(_model->append());
455 row[_columns.gain] = group->is_gain ();
456 row[_columns.gain_relative] = group->is_relative ();
457 row[_columns.mute] = group->is_mute ();
458 row[_columns.solo] = group->is_solo ();
459 row[_columns.record] = group->is_recenable();
460 row[_columns.monitoring] = group->is_monitoring();
461 row[_columns.select] = group->is_select ();
462 row[_columns.edits] = group->is_edit ();
463 row[_columns.active_state] = group->is_route_active ();
464 row[_columns.is_visible] = !group->is_hidden();
465 row[_columns.gdkcolor] = GroupTabs::group_color (group);
467 _in_row_change = true;
469 row[_columns.routegroup] = group;
471 if (!group->name().empty()) {
472 row[_columns.text] = group->name();
474 row[_columns.text] = _("unnamed");
478 group->PropertyChanged.connect (_property_changed_connections, MISSING_INVALIDATOR, ui_bind (&EditorRouteGroups::property_changed, this, group, _1), gui_context());
481 TreeViewColumn* col = _display.get_column (0);
482 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(_display.get_column_cell_renderer (0));
483 _display.set_cursor (_model->get_path (row), *col, *name_cell, true);
486 _in_row_change = false;
488 _editor->_group_tabs->set_dirty ();
492 EditorRouteGroups::groups_changed ()
494 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::groups_changed);
498 /* just rebuild the while thing */
503 _session->foreach_route_group (sigc::mem_fun (*this, &EditorRouteGroups::add));
510 EditorRouteGroups::property_changed (RouteGroup* group, const PropertyChange& change)
512 _in_row_change = true;
514 Gtk::TreeModel::Children children = _model->children();
516 for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
517 if (group == (*iter)[_columns.routegroup]) {
518 (*iter)[_columns.text] = group->name();
519 (*iter)[_columns.gain] = group->is_gain ();
520 (*iter)[_columns.gain_relative] = group->is_relative ();
521 (*iter)[_columns.mute] = group->is_mute ();
522 (*iter)[_columns.solo] = group->is_solo ();
523 (*iter)[_columns.record] = group->is_recenable ();
524 (*iter)[_columns.monitoring] = group->is_monitoring ();
525 (*iter)[_columns.select] = group->is_select ();
526 (*iter)[_columns.edits] = group->is_edit ();
527 (*iter)[_columns.active_state] = group->is_route_active ();
528 (*iter)[_columns.is_visible] = !group->is_hidden();
529 (*iter)[_columns.gdkcolor] = GroupTabs::group_color (group);
533 _in_row_change = false;
535 if (change.contains (Properties::name) || change.contains (Properties::color) || change.contains (Properties::active)) {
536 _editor->_group_tabs->set_dirty ();
539 for (TrackViewList::const_iterator i = _editor->get_track_views().begin(); i != _editor->get_track_views().end(); ++i) {
540 if ((*i)->route_group() == group) {
541 if (group->is_hidden ()) {
542 _editor->hide_track_in_display (*i);
544 _editor->_routes->show_track_in_display (**i);
551 EditorRouteGroups::name_edit (const std::string& path, const std::string& new_text)
556 if ((iter = _model->get_iter (path))) {
558 if ((group = (*iter)[_columns.routegroup]) == 0) {
562 if (new_text != group->name()) {
563 group->set_name (new_text);
569 EditorRouteGroups::clear ()
571 _display.set_model (Glib::RefPtr<Gtk::TreeStore> (0));
573 _display.set_model (_model);
577 EditorRouteGroups::set_session (Session* s)
579 SessionHandlePtr::set_session (s);
583 RouteGroup& arg (_session->all_route_group());
585 arg.PropertyChanged.connect (all_route_groups_changed_connection, MISSING_INVALIDATOR, ui_bind (&EditorRouteGroups::all_group_changed, this, _1), gui_context());
587 _session->route_group_added.connect (_session_connections, MISSING_INVALIDATOR, ui_bind (&EditorRouteGroups::add, this, _1), gui_context());
588 _session->route_group_removed.connect (
589 _session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::groups_changed, this), gui_context()
591 _session->route_groups_reordered.connect (
592 _session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::groups_changed, this), gui_context()
596 PBD::PropertyChange pc;
597 pc.add (Properties::select);
598 pc.add (Properties::active);
599 all_group_changed (pc);
605 EditorRouteGroups::run_new_group_dialog ()
609 return _editor->_group_tabs->run_new_group_dialog (rl);
613 EditorRouteGroups::all_group_toggled ()
616 _session->all_route_group().set_select (_all_group_active_button.get_active());
621 EditorRouteGroups::all_group_changed (const PropertyChange&)
624 RouteGroup& arg (_session->all_route_group());
625 _all_group_active_button.set_active (arg.is_active() && arg.is_select());
627 _all_group_active_button.set_active (false);
631 /** Called when a model row is deleted, but also when the model is
632 * reordered by a user drag-and-drop; the latter is what we are
633 * interested in here.
636 EditorRouteGroups::row_deleted (Gtk::TreeModel::Path const &)
639 /* We need to ignore this in cases where we're not doing a drag-and-drop
645 /* Re-write the session's route group list so that the new order is preserved */
647 list<RouteGroup*> new_list;
649 Gtk::TreeModel::Children children = _model->children();
650 for (Gtk::TreeModel::Children::iterator i = children.begin(); i != children.end(); ++i) {
651 new_list.push_back ((*i)[_columns.routegroup]);
654 _session->reorder_route_groups (new_list);