Set mixbufs count in the case of a panner being used, as
[ardour2.git] / gtk2_ardour / editor_route_groups.cc
bloba653644bdc579533f1d62e6c3031b304b28f4f94
1 /*
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.
20 #ifdef WAF_BUILD
21 #include "gtk2ardour-config.h"
22 #endif
24 #include <cstdlib>
25 #include <cmath>
27 #include <gtkmm2ext/gtk_ui.h>
28 #include "ardour/route_group.h"
30 #include "editor.h"
31 #include "keyboard.h"
32 #include "marker.h"
33 #include "time_axis_view.h"
34 #include "prompter.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"
42 #include "ardour/route.h"
43 #include "ardour/session.h"
45 #include "i18n.h"
47 using namespace std;
48 using namespace ARDOUR;
49 using namespace PBD;
50 using namespace Gtk;
51 using Gtkmm2ext::Keyboard;
53 EditorRouteGroups::EditorRouteGroups (Editor* e)
54 : EditorComponent (e)
55 , _all_group_active_button (_("No Selection = All Tracks"))
56 , _in_row_change (false)
57 , _in_rebuild (false)
59 _model = ListStore::create (_columns);
60 _display.set_model (_model);
62 _display.append_column (_("Name"), _columns.text);
64 _display.append_column (_("G"), _columns.gain);
65 _display.append_column (_("R"), _columns.record);
66 _display.append_column (_("M"), _columns.mute);
67 _display.append_column (_("S"), _columns.solo);
68 _display.append_column (_("Sel"), _columns.select);
69 _display.append_column (_("E"), _columns.edits);
71 _display.append_column (_("Show"), _columns.is_visible);
73 _display.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
74 _display.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
75 _display.get_column (2)->set_data (X_("colnum"), GUINT_TO_POINTER(2));
76 _display.get_column (3)->set_data (X_("colnum"), GUINT_TO_POINTER(3));
77 _display.get_column (4)->set_data (X_("colnum"), GUINT_TO_POINTER(4));
78 _display.get_column (5)->set_data (X_("colnum"), GUINT_TO_POINTER(5));
79 _display.get_column (6)->set_data (X_("colnum"), GUINT_TO_POINTER(6));
80 _display.get_column (7)->set_data (X_("colnum"), GUINT_TO_POINTER(7));
82 _display.get_column (0)->set_expand (true);
83 _display.get_column (1)->set_expand (false);
84 _display.get_column (2)->set_expand (false);
85 _display.get_column (3)->set_expand (false);
86 _display.get_column (4)->set_expand (false);
87 _display.get_column (5)->set_expand (false);
88 _display.get_column (6)->set_expand (false);
89 _display.get_column (7)->set_expand (false);
91 _display.set_headers_visible (true);
93 /* name is directly editable */
95 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(_display.get_column_cell_renderer (0));
96 name_cell->property_editable() = true;
97 name_cell->signal_edited().connect (sigc::mem_fun (*this, &EditorRouteGroups::name_edit));
99 /* use checkbox for the active + visible columns */
101 CellRendererToggle* active_cell = dynamic_cast<CellRendererToggle*>(_display.get_column_cell_renderer (1));
102 active_cell->property_activatable() = true;
103 active_cell->property_radio() = false;
105 active_cell = dynamic_cast<CellRendererToggle*>(_display.get_column_cell_renderer (2));
106 active_cell->property_activatable() = true;
107 active_cell->property_radio() = false;
109 active_cell = dynamic_cast<CellRendererToggle*>(_display.get_column_cell_renderer (3));
110 active_cell->property_activatable() = true;
111 active_cell->property_radio() = false;
113 active_cell = dynamic_cast<CellRendererToggle*>(_display.get_column_cell_renderer (4));
114 active_cell->property_activatable() = true;
115 active_cell->property_radio() = false;
117 active_cell = dynamic_cast<CellRendererToggle*>(_display.get_column_cell_renderer (5));
118 active_cell->property_activatable() = true;
119 active_cell->property_radio() = false;
121 active_cell = dynamic_cast<CellRendererToggle*>(_display.get_column_cell_renderer (6));
122 active_cell->property_activatable() = true;
123 active_cell->property_radio() = false;
125 active_cell = dynamic_cast<CellRendererToggle*>(_display.get_column_cell_renderer (7));
126 active_cell->property_activatable() = true;
127 active_cell->property_radio() = false;
129 _model->signal_row_changed().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_change));
130 /* What signal would you guess was emitted when the rows of your treeview are reordered
131 by a drag and drop? signal_rows_reordered? That would be far too easy.
132 No, signal_row_deleted().
134 _model->signal_row_deleted().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_deleted));
136 _display.set_name ("EditGroupList");
137 _display.get_selection()->set_mode (SELECTION_SINGLE);
138 _display.set_headers_visible (true);
139 _display.set_reorderable (true);
140 _display.set_rules_hint (true);
141 _display.set_size_request (75, -1);
143 _scroller.add (_display);
144 _scroller.set_policy (POLICY_AUTOMATIC, POLICY_AUTOMATIC);
146 _display.signal_button_press_event().connect (sigc::mem_fun(*this, &EditorRouteGroups::button_press_event), false);
148 HBox* button_box = manage (new HBox());
149 button_box->set_homogeneous (true);
151 Button* add_button = manage (new Button ());
152 Button* remove_button = manage (new Button ());
154 Widget* w;
156 w = manage (new Image (Stock::ADD, ICON_SIZE_BUTTON));
157 w->show();
158 add_button->add (*w);
160 w = manage (new Image (Stock::REMOVE, ICON_SIZE_BUTTON));
161 w->show();
162 remove_button->add (*w);
164 add_button->signal_clicked().connect (sigc::hide_return (sigc::mem_fun (*this, &EditorRouteGroups::run_new_group_dialog)));
165 remove_button->signal_clicked().connect (sigc::mem_fun (*this, &EditorRouteGroups::remove_selected));
167 button_box->pack_start (*add_button);
168 button_box->pack_start (*remove_button);
170 _all_group_active_button.show ();
172 _display_packer.pack_start (_scroller, true, true);
173 _display_packer.pack_start (_all_group_active_button, false, false);
174 _display_packer.pack_start (*button_box, false, false);
176 _all_group_active_button.signal_toggled().connect (sigc::mem_fun (*this, &EditorRouteGroups::all_group_toggled));
179 void
180 EditorRouteGroups::remove_selected ()
182 Glib::RefPtr<TreeSelection> selection = _display.get_selection();
183 TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
185 if (rows.empty()) {
186 return;
189 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
190 TreeIter iter;
192 /* selection mode is single, so rows.begin() is it */
194 if ((iter = _model->get_iter (*i))) {
196 RouteGroup* rg = (*iter)[_columns.routegroup];
198 if (rg) {
199 _session->remove_route_group (*rg);
204 void
205 EditorRouteGroups::button_clicked ()
207 run_new_group_dialog ();
210 gint
211 EditorRouteGroups::button_press_event (GdkEventButton* ev)
213 TreeModel::Path path;
214 TreeIter iter;
215 RouteGroup* group = 0;
216 TreeViewColumn* column;
217 int cellx;
218 int celly;
220 bool const p = _display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly);
222 if (p) {
223 iter = _model->get_iter (path);
226 if (iter) {
227 group = (*iter)[_columns.routegroup];
230 if (Keyboard::is_context_menu_event (ev)) {
231 _editor->_group_tabs->get_menu(group)->popup (1, ev->time);
232 return true;
235 if (!p) {
236 return 1;
239 switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
240 case 0:
241 if (Keyboard::is_edit_event (ev)) {
242 if ((iter = _model->get_iter (path))) {
243 if ((group = (*iter)[_columns.routegroup]) != 0) {
244 // edit_route_group (group);
245 #ifdef GTKOSX
246 _display.queue_draw();
247 #endif
248 return true;
253 break;
255 case 1:
256 if ((iter = _model->get_iter (path))) {
257 bool gain = (*iter)[_columns.gain];
258 (*iter)[_columns.gain] = !gain;
259 #ifdef GTKOSX
260 _display.queue_draw();
261 #endif
262 return true;
264 break;
266 case 2:
267 if ((iter = _model->get_iter (path))) {
268 bool record = (*iter)[_columns.record];
269 (*iter)[_columns.record] = !record;
270 #ifdef GTKOSX
271 _display.queue_draw();
272 #endif
273 return true;
275 break;
277 case 3:
278 if ((iter = _model->get_iter (path))) {
279 bool mute = (*iter)[_columns.mute];
280 (*iter)[_columns.mute] = !mute;
281 #ifdef GTKOSX
282 _display.queue_draw();
283 #endif
284 return true;
286 break;
288 case 4:
289 if ((iter = _model->get_iter (path))) {
290 bool solo = (*iter)[_columns.solo];
291 (*iter)[_columns.solo] = !solo;
292 #ifdef GTKOSX
293 _display.queue_draw();
294 #endif
295 return true;
297 break;
299 case 5:
300 if ((iter = _model->get_iter (path))) {
301 bool select = (*iter)[_columns.select];
302 (*iter)[_columns.select] = !select;
303 #ifdef GTKOSX
304 _display.queue_draw();
305 #endif
306 return true;
308 break;
310 case 6:
311 if ((iter = _model->get_iter (path))) {
312 bool edits = (*iter)[_columns.edits];
313 (*iter)[_columns.edits] = !edits;
314 #ifdef GTKOSX
315 _display.queue_draw();
316 #endif
317 return true;
319 break;
321 case 7:
322 if ((iter = _model->get_iter (path))) {
323 bool visible = (*iter)[_columns.is_visible];
324 (*iter)[_columns.is_visible] = !visible;
325 #ifdef GTKOSX
326 _display.queue_draw();
327 #endif
328 return true;
330 break;
332 default:
333 break;
336 return false;
339 void
340 EditorRouteGroups::row_change (const Gtk::TreeModel::Path&, const Gtk::TreeModel::iterator& iter)
342 RouteGroup* group;
344 if (_in_row_change) {
345 return;
348 if ((group = (*iter)[_columns.routegroup]) == 0) {
349 return;
352 PropertyList plist;
353 bool val = (*iter)[_columns.gain];
354 plist.add (Properties::gain, val);
355 val = (*iter)[_columns.record];
356 plist.add (Properties::recenable, val);
357 val = (*iter)[_columns.mute];
358 plist.add (Properties::mute, val);
359 val = (*iter)[_columns.solo];
360 plist.add (Properties::solo, val);
361 val = (*iter)[_columns.select];
362 plist.add (Properties::select, val);
363 val = (*iter)[_columns.edits];
364 plist.add (Properties::edit, val);
365 plist.add (Properties::name, string ((*iter)[_columns.text]));
367 group->set_hidden (!(*iter)[_columns.is_visible], this);
369 group->apply_changes (plist);
372 void
373 EditorRouteGroups::add (RouteGroup* group)
375 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::add, group)
376 bool focus = false;
378 TreeModel::Row row = *(_model->append());
380 row[_columns.is_visible] = !group->is_hidden();
381 row[_columns.gain] = group->is_gain ();
382 row[_columns.record] = group->is_recenable();
383 row[_columns.mute] = group->is_mute ();
384 row[_columns.solo] = group->is_solo ();
385 row[_columns.select] = group->is_select ();
386 row[_columns.edits] = group->is_edit ();
388 _in_row_change = true;
390 row[_columns.routegroup] = group;
392 if (!group->name().empty()) {
393 row[_columns.text] = group->name();
394 } else {
395 row[_columns.text] = _("unnamed");
396 focus = true;
399 group->PropertyChanged.connect (_property_changed_connections, MISSING_INVALIDATOR, ui_bind (&EditorRouteGroups::property_changed, this, group, _1), gui_context());
401 if (focus) {
402 TreeViewColumn* col = _display.get_column (0);
403 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(_display.get_column_cell_renderer (0));
404 _display.set_cursor (_model->get_path (row), *col, *name_cell, true);
407 _in_row_change = false;
409 _editor->_group_tabs->set_dirty ();
412 void
413 EditorRouteGroups::groups_changed ()
415 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::groups_changed);
417 _in_rebuild = true;
419 /* just rebuild the while thing */
421 _model->clear ();
423 if (_session) {
424 _session->foreach_route_group (sigc::mem_fun (*this, &EditorRouteGroups::add));
427 _in_rebuild = false;
430 void
431 EditorRouteGroups::property_changed (RouteGroup* group, const PropertyChange& change)
433 _in_row_change = true;
435 Gtk::TreeModel::Children children = _model->children();
437 for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
438 if (group == (*iter)[_columns.routegroup]) {
439 (*iter)[_columns.is_visible] = !group->is_hidden();
440 (*iter)[_columns.text] = group->name();
441 (*iter)[_columns.gain] = group->is_gain ();
442 (*iter)[_columns.record] = group->is_recenable ();
443 (*iter)[_columns.mute] = group->is_mute ();
444 (*iter)[_columns.solo] = group->is_solo ();
445 (*iter)[_columns.select] = group->is_select ();
446 (*iter)[_columns.edits] = group->is_edit ();
450 _in_row_change = false;
452 if (change.contains (Properties::name) || change.contains (Properties::active)) {
453 _editor->_group_tabs->set_dirty ();
456 for (TrackViewList::const_iterator i = _editor->get_track_views().begin(); i != _editor->get_track_views().end(); ++i) {
457 if ((*i)->route_group() == group) {
458 if (group->is_hidden ()) {
459 _editor->hide_track_in_display (*i);
460 } else {
461 _editor->_routes->show_track_in_display (**i);
467 void
468 EditorRouteGroups::name_edit (const std::string& path, const std::string& new_text)
470 RouteGroup* group;
471 TreeIter iter;
473 if ((iter = _model->get_iter (path))) {
475 if ((group = (*iter)[_columns.routegroup]) == 0) {
476 return;
479 if (new_text != group->name()) {
480 group->set_name (new_text);
485 void
486 EditorRouteGroups::clear ()
488 _display.set_model (Glib::RefPtr<Gtk::TreeStore> (0));
489 _model->clear ();
490 _display.set_model (_model);
493 void
494 EditorRouteGroups::set_session (Session* s)
496 SessionHandlePtr::set_session (s);
498 if (_session) {
500 RouteGroup& arg (_session->all_route_group());
502 arg.PropertyChanged.connect (all_route_groups_changed_connection, MISSING_INVALIDATOR, ui_bind (&EditorRouteGroups::all_group_changed, this, _1), gui_context());
504 _session->route_group_added.connect (_session_connections, MISSING_INVALIDATOR, ui_bind (&EditorRouteGroups::add, this, _1), gui_context());
505 _session->route_group_removed.connect (
506 _session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::groups_changed, this), gui_context()
508 _session->route_groups_reordered.connect (
509 _session_connections, MISSING_INVALIDATOR, boost::bind (&EditorRouteGroups::groups_changed, this), gui_context()
513 PBD::PropertyChange pc;
514 pc.add (Properties::select);
515 pc.add (Properties::active);
516 all_group_changed (pc);
518 groups_changed ();
521 void
522 EditorRouteGroups::run_new_group_dialog ()
524 RouteList rl;
526 return _editor->_group_tabs->run_new_group_dialog (rl);
529 void
530 EditorRouteGroups::all_group_toggled ()
532 if (_session) {
533 _session->all_route_group().set_select (_all_group_active_button.get_active());
537 void
538 EditorRouteGroups::all_group_changed (const PropertyChange&)
540 if (_session) {
541 RouteGroup& arg (_session->all_route_group());
542 _all_group_active_button.set_active (arg.is_active() && arg.is_select());
543 } else {
544 _all_group_active_button.set_active (false);
548 /** Called when a model row is deleted, but also when the model is
549 * reordered by a user drag-and-drop; the latter is what we are
550 * interested in here.
552 void
553 EditorRouteGroups::row_deleted (Gtk::TreeModel::Path const &)
555 if (_in_rebuild) {
556 /* We need to ignore this in cases where we're not doing a drag-and-drop
557 re-order.
559 return;
562 /* Re-write the session's route group list so that the new order is preserved */
564 list<RouteGroup*> new_list;
566 Gtk::TreeModel::Children children = _model->children();
567 for (Gtk::TreeModel::Children::iterator i = children.begin(); i != children.end(); ++i) {
568 new_list.push_back ((*i)[_columns.routegroup]);
571 _session->reorder_route_groups (new_list);