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"
42 #include "ardour/route.h"
43 #include "ardour/session.h"
48 using namespace ARDOUR
;
51 using Gtkmm2ext::Keyboard
;
53 EditorRouteGroups::EditorRouteGroups (Editor
* e
)
55 , _all_group_active_button (_("No Selection = All Tracks"))
56 , _in_row_change (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 ());
156 w
= manage (new Image (Stock::ADD
, ICON_SIZE_BUTTON
));
158 add_button
->add (*w
);
160 w
= manage (new Image (Stock::REMOVE
, ICON_SIZE_BUTTON
));
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
));
180 EditorRouteGroups::remove_selected ()
182 Glib::RefPtr
<TreeSelection
> selection
= _display
.get_selection();
183 TreeView::Selection::ListHandle_Path rows
= selection
->get_selected_rows ();
189 TreeView::Selection::ListHandle_Path::iterator i
= rows
.begin();
192 /* selection mode is single, so rows.begin() is it */
194 if ((iter
= _model
->get_iter (*i
))) {
196 RouteGroup
* rg
= (*iter
)[_columns
.routegroup
];
199 _session
->remove_route_group (*rg
);
205 EditorRouteGroups::button_clicked ()
207 run_new_group_dialog ();
211 EditorRouteGroups::button_press_event (GdkEventButton
* ev
)
213 TreeModel::Path path
;
215 RouteGroup
* group
= 0;
216 TreeViewColumn
* column
;
220 bool const p
= _display
.get_path_at_pos ((int)ev
->x
, (int)ev
->y
, path
, column
, cellx
, celly
);
223 iter
= _model
->get_iter (path
);
227 group
= (*iter
)[_columns
.routegroup
];
230 if (Keyboard::is_context_menu_event (ev
)) {
231 _editor
->_group_tabs
->get_menu(group
)->popup (1, ev
->time
);
239 switch (GPOINTER_TO_UINT (column
->get_data (X_("colnum")))) {
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);
246 _display
.queue_draw();
256 if ((iter
= _model
->get_iter (path
))) {
257 bool gain
= (*iter
)[_columns
.gain
];
258 (*iter
)[_columns
.gain
] = !gain
;
260 _display
.queue_draw();
267 if ((iter
= _model
->get_iter (path
))) {
268 bool record
= (*iter
)[_columns
.record
];
269 (*iter
)[_columns
.record
] = !record
;
271 _display
.queue_draw();
278 if ((iter
= _model
->get_iter (path
))) {
279 bool mute
= (*iter
)[_columns
.mute
];
280 (*iter
)[_columns
.mute
] = !mute
;
282 _display
.queue_draw();
289 if ((iter
= _model
->get_iter (path
))) {
290 bool solo
= (*iter
)[_columns
.solo
];
291 (*iter
)[_columns
.solo
] = !solo
;
293 _display
.queue_draw();
300 if ((iter
= _model
->get_iter (path
))) {
301 bool select
= (*iter
)[_columns
.select
];
302 (*iter
)[_columns
.select
] = !select
;
304 _display
.queue_draw();
311 if ((iter
= _model
->get_iter (path
))) {
312 bool edits
= (*iter
)[_columns
.edits
];
313 (*iter
)[_columns
.edits
] = !edits
;
315 _display
.queue_draw();
322 if ((iter
= _model
->get_iter (path
))) {
323 bool visible
= (*iter
)[_columns
.is_visible
];
324 (*iter
)[_columns
.is_visible
] = !visible
;
326 _display
.queue_draw();
340 EditorRouteGroups::row_change (const Gtk::TreeModel::Path
&, const Gtk::TreeModel::iterator
& iter
)
344 if (_in_row_change
) {
348 if ((group
= (*iter
)[_columns
.routegroup
]) == 0) {
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
);
373 EditorRouteGroups::add (RouteGroup
* group
)
375 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::add
, group
)
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();
395 row
[_columns
.text
] = _("unnamed");
399 group
->PropertyChanged
.connect (_property_changed_connections
, MISSING_INVALIDATOR
, ui_bind (&EditorRouteGroups::property_changed
, this, group
, _1
), gui_context());
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 ();
413 EditorRouteGroups::groups_changed ()
415 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::groups_changed
);
419 /* just rebuild the while thing */
424 _session
->foreach_route_group (sigc::mem_fun (*this, &EditorRouteGroups::add
));
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
);
461 _editor
->_routes
->show_track_in_display (**i
);
468 EditorRouteGroups::name_edit (const std::string
& path
, const std::string
& new_text
)
473 if ((iter
= _model
->get_iter (path
))) {
475 if ((group
= (*iter
)[_columns
.routegroup
]) == 0) {
479 if (new_text
!= group
->name()) {
480 group
->set_name (new_text
);
486 EditorRouteGroups::clear ()
488 _display
.set_model (Glib::RefPtr
<Gtk::TreeStore
> (0));
490 _display
.set_model (_model
);
494 EditorRouteGroups::set_session (Session
* s
)
496 SessionHandlePtr::set_session (s
);
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
);
522 EditorRouteGroups::run_new_group_dialog ()
526 return _editor
->_group_tabs
->run_new_group_dialog (rl
);
530 EditorRouteGroups::all_group_toggled ()
533 _session
->all_route_group().set_select (_all_group_active_button
.get_active());
538 EditorRouteGroups::all_group_changed (const PropertyChange
&)
541 RouteGroup
& arg (_session
->all_route_group());
542 _all_group_active_button
.set_active (arg
.is_active() && arg
.is_select());
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.
553 EditorRouteGroups::row_deleted (Gtk::TreeModel::Path
const &)
556 /* We need to ignore this in cases where we're not doing a drag-and-drop
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
);