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 <gtkmm/stock.h>
31 #include "gtkmm2ext/gtk_ui.h"
32 #include "gtkmm2ext/cell_renderer_color_selector.h"
34 #include "widgets/tooltips.h"
36 #include "ardour/route_group.h"
37 #include "ardour/route.h"
38 #include "ardour/session.h"
40 #include "ardour_ui.h"
42 #include "editor_group_tabs.h"
43 #include "editor_route_groups.h"
44 #include "editor_routes.h"
45 #include "gui_thread.h"
48 #include "route_group_dialog.h"
49 #include "route_time_axis.h"
50 #include "time_axis_view.h"
56 using namespace ARDOUR;
57 using namespace ARDOUR_UI_UTILS;
58 using namespace ArdourWidgets;
61 using Gtkmm2ext::Keyboard;
69 EditorRouteGroups::EditorRouteGroups (Editor* e)
71 , _in_row_change (false)
74 _model = ListStore::create (_columns);
75 _display.set_model (_model);
77 Gtkmm2ext::CellRendererColorSelector* color_renderer = manage (new Gtkmm2ext::CellRendererColorSelector);
78 TreeViewColumn* color_column = manage (new TreeViewColumn ("", *color_renderer));
80 color_column->add_attribute (color_renderer->property_color(), _columns.gdkcolor);
82 _display.append_column (*color_column);
84 _display.append_column ("", _columns.text);
85 _display.append_column ("", _columns.is_visible);
86 _display.append_column ("", _columns.active_state);
87 _display.append_column ("", _columns.gain);
88 _display.append_column ("", _columns.gain_relative);
89 _display.append_column ("", _columns.mute);
90 _display.append_column ("", _columns.solo);
91 _display.append_column ("", _columns.record);
92 _display.append_column ("", _columns.monitoring);
93 _display.append_column ("", _columns.select);
94 _display.append_column ("", _columns.active_shared);
100 { 0, _("Col"), _("Group Tab Color") },
101 { 1, _("Name"), _("Name of Group") },
102 { 2, S_("Visible|V"), _("Group is visible?") },
103 { 3, _("On"), _("Group is enabled?") },
104 { 4, S_("Group|G"), _("Sharing Gain?") },
105 { 5, S_("Relative|Rel"), _("Relative Gain Changes?") },
106 { 6, S_("Mute|M"), _("Sharing Mute?") },
107 { 7, S_("Solo|S"), _("Sharing Solo?") },
108 { 8, _("Rec"), _("Sharing Record-enable Status?") },
109 { 9, S_("Monitoring|Mon"), _("Sharing Monitoring Choice?") },
110 { 10, S_("Selection|Sel"), _("Sharing Selected/Editing Status?") },
111 { 11, S_("Active|A"), _("Sharing Active Status?") },
116 for (int i = 0; ci[i].index >= 0; ++i) {
117 col = _display.get_column (ci[i].index);
118 l = manage (new Label (ci[i].label));
119 set_tooltip (*l, ci[i].tooltip);
120 col->set_widget (*l);
123 col->set_data (X_("colnum"), GUINT_TO_POINTER(i));
125 col->set_expand (true);
127 col->set_expand (false);
128 col->set_alignment (ALIGN_CENTER);
132 _display.set_headers_visible (true);
134 color_dialog.get_colorsel()->set_has_opacity_control (false);
135 color_dialog.get_colorsel()->set_has_palette (true);
136 color_dialog.get_ok_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_ACCEPT));
137 color_dialog.get_cancel_button()->signal_clicked().connect (sigc::bind (sigc::mem_fun (color_dialog, &Gtk::Dialog::response), RESPONSE_CANCEL));
139 /* name is directly editable */
141 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(_display.get_column_cell_renderer (1));
142 name_cell->property_editable() = true;
143 name_cell->signal_edited().connect (sigc::mem_fun (*this, &EditorRouteGroups::name_edit));
145 for (int i = 1; ci[i].index >= 0; ++i) {
146 CellRendererToggle* active_cell = dynamic_cast <CellRendererToggle*> (_display.get_column_cell_renderer (i));
149 active_cell->property_activatable() = true;
150 active_cell->property_radio() = false;
154 _model->signal_row_changed().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_change));
155 /* What signal would you guess was emitted when the rows of your treeview are reordered
156 by a drag and drop? signal_rows_reordered? That would be far too easy.
157 No, signal_row_deleted().
159 _model->signal_row_deleted().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_deleted));
161 _display.set_name ("EditGroupList");
162 _display.get_selection()->set_mode (SELECTION_SINGLE);
163 _display.set_headers_visible (true);
164 _display.set_reorderable (false);
165 _display.set_rules_hint (true);
167 _scroller.add (_display);
168 _scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
170 _display.signal_button_press_event().connect (sigc::mem_fun(*this, &EditorRouteGroups::button_press_event), false);
172 HBox* button_box = manage (new HBox());
173 button_box->set_homogeneous (true);
175 Button* add_button = manage (new Button ());
176 Button* remove_button = manage (new Button ());
180 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
182 add_button->add (*w);
184 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
186 remove_button->add (*w);
188 add_button->signal_clicked().connect (sigc::hide_return (sigc::mem_fun (*this, &EditorRouteGroups::run_new_group_dialog)));
189 remove_button->signal_clicked().connect (sigc::mem_fun (*this, &EditorRouteGroups::remove_selected));
191 button_box->pack_start (*add_button);
192 button_box->pack_start (*remove_button);
194 _display_packer.pack_start (_scroller, true, true);
195 _display_packer.pack_start (*button_box, false, false);
199 EditorRouteGroups::remove_selected ()
201 Glib::RefPtr<TreeSelection> selection = _display.get_selection();
202 TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
204 if (rows.empty() || _session->deletion_in_progress()) {
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;
242 bool const p = _display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly);
245 iter = _model->get_iter (path);
249 group = (*iter)[_columns.routegroup];
252 if (Keyboard::is_context_menu_event (ev)) {
253 _editor->_group_tabs->get_menu(group)->popup (1, ev->time);
258 /* cancel selection */
259 _display.get_selection()->unselect_all ();
260 /* end any editing by grabbing focus */
261 _display.grab_focus ();
265 group = (*iter)[_columns.routegroup];
267 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
269 c = (*iter)[_columns.gdkcolor];
270 color_dialog.get_colorsel()->set_previous_color (c);
271 color_dialog.get_colorsel()->set_current_color (c);
273 switch (color_dialog.run()) {
274 case RESPONSE_CANCEL:
276 case RESPONSE_ACCEPT:
277 c = color_dialog.get_colorsel()->get_current_color();
278 GroupTabs::set_group_color (group, gdk_color_to_rgba (c));
286 color_dialog.hide ();
291 if (Keyboard::is_edit_event (ev) && group) {
292 /* we'll be editing now ... */
298 val = (*iter)[_columns.is_visible];
299 /* note subtle logic inverse here: we set the new value with
300 "val", rather than !val, because we're using ::set_hidden()
301 not a (non-existent) ::set_visible() call.
303 group->set_hidden (val, this);
309 val = (*iter)[_columns.active_state];
310 group->set_active (!val, this);
315 val = (*iter)[_columns.gain];
316 group->set_gain (!val);
321 val = (*iter)[_columns.gain_relative];
322 group->set_relative (!val, this);
327 val = (*iter)[_columns.mute];
328 group->set_mute (!val);
333 val = (*iter)[_columns.solo];
334 group->set_solo (!val);
339 val = (*iter)[_columns.record];
340 group->set_recenable (!val);
345 val = (*iter)[_columns.monitoring];
346 group->set_monitoring (!val);
351 val = (*iter)[_columns.select];
352 group->set_select (!val);
357 val = (*iter)[_columns.active_shared];
358 group->set_route_active (!val);
370 EditorRouteGroups::row_change (const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter)
374 if (_in_row_change) {
378 if ((group = (*iter)[_columns.routegroup]) == 0) {
383 plist.add (Properties::name, string ((*iter)[_columns.text]));
385 bool val = (*iter)[_columns.gain];
386 plist.add (Properties::group_gain, val);
387 val = (*iter)[_columns.gain_relative];
388 plist.add (Properties::group_relative, val);
389 val = (*iter)[_columns.mute];
390 plist.add (Properties::group_mute, val);
391 val = (*iter)[_columns.solo];
392 plist.add (Properties::group_solo, val);
393 val = (*iter)[_columns.record];
394 plist.add (Properties::group_recenable, val);
395 val = (*iter)[_columns.monitoring];
396 plist.add (Properties::group_monitoring, val);
397 val = (*iter)[_columns.select];
398 plist.add (Properties::group_select, val);
399 val = (*iter)[_columns.active_shared];
400 plist.add (Properties::group_route_active, val);
402 val = (*iter)[_columns.active_state];
403 plist.add (Properties::active, val);
404 val = (*iter)[_columns.is_visible];
405 plist.add (Properties::hidden, !val);
407 group->apply_changes (plist);
409 GroupTabs::set_group_color ((*iter)[_columns.routegroup], gdk_color_to_rgba ((*iter)[_columns.gdkcolor]));
413 EditorRouteGroups::add (RouteGroup* group)
415 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::add, group)
418 TreeModel::Row row = *(_model->append());
420 row[_columns.gain] = group->is_gain ();
421 row[_columns.gain_relative] = group->is_relative ();
422 row[_columns.mute] = group->is_mute ();
423 row[_columns.solo] = group->is_solo ();
424 row[_columns.record] = group->is_recenable();
425 row[_columns.monitoring] = group->is_monitoring();
426 row[_columns.select] = group->is_select ();
427 row[_columns.active_shared] = group->is_route_active ();
428 row[_columns.active_state] = group->is_active ();
429 row[_columns.is_visible] = !group->is_hidden();
432 set_color_from_rgba (c, GroupTabs::group_color (group));
433 row[_columns.gdkcolor] = c;
435 _in_row_change = true;
437 row[_columns.routegroup] = group;
439 if (!group->name().empty()) {
440 row[_columns.text] = group->name();
442 row[_columns.text] = _("unnamed");
446 group->PropertyChanged.connect (_property_changed_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::property_changed, this, group, _1), gui_context());
449 TreeViewColumn* col = _display.get_column (0);
450 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(_display.get_column_cell_renderer (1));
451 _display.set_cursor (_model->get_path (row), *col, *name_cell, true);
454 _in_row_change = false;
456 _editor->_group_tabs->set_dirty ();
460 EditorRouteGroups::groups_changed ()
462 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::groups_changed);
466 /* just rebuild the while thing */
471 _session->foreach_route_group (sigc::mem_fun (*this, &EditorRouteGroups::add));
478 EditorRouteGroups::property_changed (RouteGroup* group, const PropertyChange&)
481 _in_row_change = true;
483 Gtk::TreeModel::Children children = _model->children();
485 for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
486 if (group == (*iter)[_columns.routegroup]) {
488 /* we could check the PropertyChange and only set
489 * appropriate fields. but the amount of saved by doing
490 * that is pretty minimal, and this is nice and simple.
493 (*iter)[_columns.text] = group->name();
494 (*iter)[_columns.gain] = group->is_gain ();
495 (*iter)[_columns.gain_relative] = group->is_relative ();
496 (*iter)[_columns.mute] = group->is_mute ();
497 (*iter)[_columns.solo] = group->is_solo ();
498 (*iter)[_columns.record] = group->is_recenable ();
499 (*iter)[_columns.monitoring] = group->is_monitoring ();
500 (*iter)[_columns.select] = group->is_select ();
501 (*iter)[_columns.active_shared] = group->is_route_active ();
502 (*iter)[_columns.active_state] = group->is_active ();
503 (*iter)[_columns.is_visible] = !group->is_hidden();
506 set_color_from_rgba (c, GroupTabs::group_color (group));
507 (*iter)[_columns.gdkcolor] = c;
513 _in_row_change = false;
515 for (TrackViewList::const_iterator i = _editor->get_track_views().begin(); i != _editor->get_track_views().end(); ++i) {
516 if ((*i)->route_group() == group) {
517 if (group->is_hidden ()) {
518 _editor->hide_track_in_display (*i);
520 _editor->_routes->show_track_in_display (**i);
527 EditorRouteGroups::name_edit (const std::string& path, const std::string& new_text)
532 if ((iter = _model->get_iter (path))) {
534 if ((group = (*iter)[_columns.routegroup]) == 0) {
538 if (new_text != group->name()) {
539 group->set_name (new_text);
545 EditorRouteGroups::clear ()
547 _display.set_model (Glib::RefPtr<Gtk::TreeStore> (0));
549 _display.set_model (_model);
553 EditorRouteGroups::set_session (Session* s)
555 SessionHandlePtr::set_session (s);
559 _session->route_group_added.connect (_session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::add, this, _1), gui_context());
560 _session->route_group_removed.connect (
561 _session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::groups_changed, this), gui_context()
563 _session->route_groups_reordered.connect (
564 _session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::groups_changed, this), gui_context()
568 PBD::PropertyChange pc;
569 pc.add (Properties::group_select);
570 pc.add (Properties::active);
576 EditorRouteGroups::run_new_group_dialog ()
578 return _editor->_group_tabs->run_new_group_dialog (0, false);
581 /** Called when a model row is deleted, but also when the model is
582 * reordered by a user drag-and-drop; the latter is what we are
583 * interested in here.
586 EditorRouteGroups::row_deleted (Gtk::TreeModel::Path const &)
588 if (_in_rebuild || !_session || _session->deletion_in_progress()) {
589 /* We need to ignore this in cases where we're not doing a drag-and-drop
595 /* Re-write the session's route group list so that the new order is preserved */
597 list<RouteGroup*> new_list;
599 Gtk::TreeModel::Children children = _model->children();
600 for (Gtk::TreeModel::Children::iterator i = children.begin(); i != children.end(); ++i) {
601 new_list.push_back ((*i)[_columns.routegroup]);
604 _session->reorder_route_groups (new_list);