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 "ardour/route_group.h"
33 #include "time_axis_view.h"
35 #include "gui_thread.h"
36 #include "editor_group_tabs.h"
37 #include "route_group_dialog.h"
38 #include "route_time_axis.h"
39 #include "editor_routes.h"
40 #include "editor_route_groups.h"
41 #include "ardour_ui.h"
43 #include "ardour/route.h"
44 #include "ardour/session.h"
49 using namespace ARDOUR;
52 using Gtkmm2ext::Keyboard;
54 EditorRouteGroups::EditorRouteGroups (Editor* e)
56 , _all_group_active_button (_("No Selection = All Tracks"))
57 , _in_row_change (false)
60 _model = ListStore::create (_columns);
61 _display.set_model (_model);
63 int const columns = 10;
65 _display.append_column (_("Name"), _columns.text);
66 _display.append_column (_("G"), _columns.gain);
67 _display.append_column (_("Rel"), _columns.gain_relative);
68 _display.append_column (_("M"), _columns.mute);
69 _display.append_column (_("S"), _columns.solo);
70 _display.append_column (_("Rec"), _columns.record);
71 _display.append_column (_("Sel"), _columns.select);
72 _display.append_column (_("E"), _columns.edits);
73 _display.append_column (_("A"), _columns.active_state);
74 _display.append_column (_("Show"), _columns.is_visible);
76 for (int i = 0; i < columns; ++i) {
77 _display.get_column (i)->set_data (X_("colnum"), GUINT_TO_POINTER(i));
80 _display.get_column (0)->set_expand (true);
82 for (int i = 1; i < columns; ++i) {
83 _display.get_column (i)->set_expand (false);
86 _display.set_headers_visible (true);
88 /* name is directly editable */
90 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(_display.get_column_cell_renderer (0));
91 name_cell->property_editable() = true;
92 name_cell->signal_edited().connect (sigc::mem_fun (*this, &EditorRouteGroups::name_edit));
94 /* use checkbox for the active + visible columns */
96 for (int i = 1; i < columns; ++i) {
97 CellRendererToggle* active_cell = dynamic_cast <CellRendererToggle*> (_display.get_column_cell_renderer (i));
98 active_cell->property_activatable() = true;
99 active_cell->property_radio() = false;
102 _model->signal_row_changed().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_change));
103 /* What signal would you guess was emitted when the rows of your treeview are reordered
104 by a drag and drop? signal_rows_reordered? That would be far too easy.
105 No, signal_row_deleted().
107 _model->signal_row_deleted().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_deleted));
109 _display.set_name ("EditGroupList");
110 _display.get_selection()->set_mode (SELECTION_SINGLE);
111 _display.set_headers_visible (true);
112 _display.set_reorderable (true);
113 _display.set_rules_hint (true);
114 _display.set_size_request (75, -1);
116 _scroller.add (_display);
117 _scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
119 _display.signal_button_press_event().connect (sigc::mem_fun(*this, &EditorRouteGroups::button_press_event), false);
121 HBox* button_box = manage (new HBox());
122 button_box->set_homogeneous (true);
124 Button* add_button = manage (new Button ());
125 Button* remove_button = manage (new Button ());
129 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
131 add_button->add (*w);
133 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
135 remove_button->add (*w);
137 add_button->signal_clicked().connect (sigc::hide_return (sigc::mem_fun (*this, &EditorRouteGroups::run_new_group_dialog)));
138 remove_button->signal_clicked().connect (sigc::mem_fun (*this, &EditorRouteGroups::remove_selected));
140 button_box->pack_start (*add_button);
141 button_box->pack_start (*remove_button);
143 _all_group_active_button.show ();
145 _display_packer.pack_start (_scroller, true, true);
146 _display_packer.pack_start (_all_group_active_button, false, false);
147 _display_packer.pack_start (*button_box, false, false);
149 _all_group_active_button.signal_toggled().connect (sigc::mem_fun (*this, &EditorRouteGroups::all_group_toggled));
150 _all_group_active_button.set_name (X_("EditorRouteGroupsAllGroupButton"));
151 ARDOUR_UI::instance()->set_tip (_all_group_active_button, _("Activate this button to operate on all tracks when none are selected."));
155 EditorRouteGroups::remove_selected ()
157 Glib::RefPtr<TreeSelection> selection = _display.get_selection();
158 TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
164 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
167 /* selection mode is single, so rows.begin() is it */
169 if ((iter = _model->get_iter (*i))) {
171 RouteGroup* rg = (*iter)[_columns.routegroup];
174 _session->remove_route_group (*rg);
180 EditorRouteGroups::button_clicked ()
182 run_new_group_dialog ();
186 EditorRouteGroups::button_press_event (GdkEventButton* ev)
188 TreeModel::Path path;
190 RouteGroup* group = 0;
191 TreeViewColumn* column;
195 bool const p = _display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly);
198 iter = _model->get_iter (path);
202 group = (*iter)[_columns.routegroup];
205 if (Keyboard::is_context_menu_event (ev)) {
206 _editor->_group_tabs->get_menu(group)->popup (1, ev->time);
214 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
216 if (Keyboard::is_edit_event (ev)) {
217 if ((iter = _model->get_iter (path))) {
218 if ((group = (*iter)[_columns.routegroup]) != 0) {
220 _display.queue_draw();
230 if ((iter = _model->get_iter (path))) {
231 bool gain = (*iter)[_columns.gain];
232 (*iter)[_columns.gain] = !gain;
234 _display.queue_draw();
241 if ((iter = _model->get_iter (path))) {
242 bool gain_relative = (*iter)[_columns.gain_relative];
243 (*iter)[_columns.gain_relative] = !gain_relative;
245 _display.queue_draw();
252 if ((iter = _model->get_iter (path))) {
253 bool mute = (*iter)[_columns.mute];
254 (*iter)[_columns.mute] = !mute;
256 _display.queue_draw();
263 if ((iter = _model->get_iter (path))) {
264 bool solo = (*iter)[_columns.solo];
265 (*iter)[_columns.solo] = !solo;
267 _display.queue_draw();
274 if ((iter = _model->get_iter (path))) {
275 bool record = (*iter)[_columns.record];
276 (*iter)[_columns.record] = !record;
278 _display.queue_draw();
285 if ((iter = _model->get_iter (path))) {
286 bool select = (*iter)[_columns.select];
287 (*iter)[_columns.select] = !select;
289 _display.queue_draw();
296 if ((iter = _model->get_iter (path))) {
297 bool edits = (*iter)[_columns.edits];
298 (*iter)[_columns.edits] = !edits;
300 _display.queue_draw();
307 if ((iter = _model->get_iter (path))) {
308 bool active_state = (*iter)[_columns.active_state];
309 (*iter)[_columns.active_state] = !active_state;
311 _display.queue_draw();
318 if ((iter = _model->get_iter (path))) {
319 bool is_visible = (*iter)[_columns.is_visible];
320 (*iter)[_columns.is_visible] = !is_visible;
322 _display.queue_draw();
336 EditorRouteGroups::row_change (const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter)
340 if (_in_row_change) {
344 if ((group = (*iter)[_columns.routegroup]) == 0) {
349 plist.add (Properties::name, string ((*iter)[_columns.text]));
351 bool val = (*iter)[_columns.gain];
352 plist.add (Properties::gain, val);
353 val = (*iter)[_columns.gain_relative];
354 plist.add (Properties::relative, val);
355 val = (*iter)[_columns.mute];
356 plist.add (Properties::mute, val);
357 val = (*iter)[_columns.solo];
358 plist.add (Properties::solo, val);
359 val = (*iter)[_columns.record];
360 plist.add (Properties::recenable, val);
361 val = (*iter)[_columns.select];
362 plist.add (Properties::select, val);
363 val = (*iter)[_columns.edits];
364 plist.add (Properties::edit, val);
365 val = (*iter)[_columns.active_state];
366 plist.add (Properties::route_active, val);
368 group->set_hidden (!(*iter)[_columns.is_visible], this);
370 group->apply_changes (plist);
374 EditorRouteGroups::add (RouteGroup* group)
376 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::add, group)
379 TreeModel::Row row = *(_model->append());
381 row[_columns.gain] = group->is_gain ();
382 row[_columns.gain_relative] = group->is_relative ();
383 row[_columns.mute] = group->is_mute ();
384 row[_columns.solo] = group->is_solo ();
385 row[_columns.record] = group->is_recenable();
386 row[_columns.select] = group->is_select ();
387 row[_columns.edits] = group->is_edit ();
388 row[_columns.active_state] = group->is_route_active ();
389 row[_columns.is_visible] = !group->is_hidden();
391 _in_row_change = true;
393 row[_columns.routegroup] = group;
395 if (!group->name().empty()) {
396 row[_columns.text] = group->name();
398 row[_columns.text] = _("unnamed");
402 group->PropertyChanged.connect (_property_changed_connections, MISSING_INVALIDATOR, ui_bind (&EditorRouteGroups::property_changed, this, group, _1), gui_context());
405 TreeViewColumn* col = _display.get_column (0);
406 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(_display.get_column_cell_renderer (0));
407 _display.set_cursor (_model->get_path (row), *col, *name_cell, true);
410 _in_row_change = false;
412 _editor->_group_tabs->set_dirty ();
416 EditorRouteGroups::groups_changed ()
418 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::groups_changed);
422 /* just rebuild the while thing */
427 _session->foreach_route_group (sigc::mem_fun (*this, &EditorRouteGroups::add));
434 EditorRouteGroups::property_changed (RouteGroup* group, const PropertyChange& change)
436 _in_row_change = true;
438 Gtk::TreeModel::Children children = _model->children();
440 for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
441 if (group == (*iter)[_columns.routegroup]) {
442 (*iter)[_columns.text] = group->name();
443 (*iter)[_columns.gain] = group->is_gain ();
444 (*iter)[_columns.gain_relative] = group->is_relative ();
445 (*iter)[_columns.mute] = group->is_mute ();
446 (*iter)[_columns.solo] = group->is_solo ();
447 (*iter)[_columns.record] = group->is_recenable ();
448 (*iter)[_columns.select] = group->is_select ();
449 (*iter)[_columns.edits] = group->is_edit ();
450 (*iter)[_columns.active_state] = group->is_route_active ();
451 (*iter)[_columns.is_visible] = !group->is_hidden();
455 _in_row_change = false;
457 if (change.contains (Properties::name) || change.contains (Properties::active)) {
458 _editor->_group_tabs->set_dirty ();
461 for (TrackViewList::const_iterator i = _editor->get_track_views().begin(); i != _editor->get_track_views().end(); ++i) {
462 if ((*i)->route_group() == group) {
463 if (group->is_hidden ()) {
464 _editor->hide_track_in_display (*i);
466 _editor->_routes->show_track_in_display (**i);
473 EditorRouteGroups::name_edit (const std::string& path, const std::string& new_text)
478 if ((iter = _model->get_iter (path))) {
480 if ((group = (*iter)[_columns.routegroup]) == 0) {
484 if (new_text != group->name()) {
485 group->set_name (new_text);
491 EditorRouteGroups::clear ()
493 _display.set_model (Glib::RefPtr<Gtk::TreeStore> (0));
495 _display.set_model (_model);
499 EditorRouteGroups::set_session (Session* s)
501 SessionHandlePtr::set_session (s);
505 RouteGroup& arg (_session->all_route_group());
507 arg.PropertyChanged.connect (all_route_groups_changed_connection, MISSING_INVALIDATOR, ui_bind (&EditorRouteGroups::all_group_changed, this, _1), gui_context());
509 _session->route_group_added.connect (_session_connections, MISSING_INVALIDATOR, ui_bind (&EditorRouteGroups::add, this, _1), gui_context());
510 _session->route_group_removed.connect (
511 _session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::groups_changed, this), gui_context()
513 _session->route_groups_reordered.connect (
514 _session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::groups_changed, this), gui_context()
518 PBD::PropertyChange pc;
519 pc.add (Properties::select);
520 pc.add (Properties::active);
521 all_group_changed (pc);
527 EditorRouteGroups::run_new_group_dialog ()
531 return _editor->_group_tabs->run_new_group_dialog (rl);
535 EditorRouteGroups::all_group_toggled ()
538 _session->all_route_group().set_select (_all_group_active_button.get_active());
543 EditorRouteGroups::all_group_changed (const PropertyChange&)
546 RouteGroup& arg (_session->all_route_group());
547 _all_group_active_button.set_active (arg.is_active() && arg.is_select());
549 _all_group_active_button.set_active (false);
553 /** Called when a model row is deleted, but also when the model is
554 * reordered by a user drag-and-drop; the latter is what we are
555 * interested in here.
558 EditorRouteGroups::row_deleted (Gtk::TreeModel::Path const &)
561 /* We need to ignore this in cases where we're not doing a drag-and-drop
567 /* Re-write the session's route group list so that the new order is preserved */
569 list<RouteGroup*> new_list;
571 Gtk::TreeModel::Children children = _model->children();
572 for (Gtk::TreeModel::Children::iterator i = children.begin(); i != children.end(); ++i) {
573 new_list.push_back ((*i)[_columns.routegroup]);
576 _session->reorder_route_groups (new_list);