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 int const columns
= 10;
64 _display
.append_column (_("Name"), _columns
.text
);
65 _display
.append_column (_("G"), _columns
.gain
);
66 _display
.append_column (_("Rel"), _columns
.gain_relative
);
67 _display
.append_column (_("M"), _columns
.mute
);
68 _display
.append_column (_("S"), _columns
.solo
);
69 _display
.append_column (_("Rec"), _columns
.record
);
70 _display
.append_column (_("Sel"), _columns
.select
);
71 _display
.append_column (_("E"), _columns
.edits
);
72 _display
.append_column (_("A"), _columns
.active_state
);
73 _display
.append_column (_("Show"), _columns
.is_visible
);
75 for (int i
= 0; i
< columns
; ++i
) {
76 _display
.get_column (i
)->set_data (X_("colnum"), GUINT_TO_POINTER(i
));
79 _display
.get_column (0)->set_expand (true);
81 for (int i
= 1; i
< columns
; ++i
) {
82 _display
.get_column (i
)->set_expand (false);
85 _display
.set_headers_visible (true);
87 /* name is directly editable */
89 CellRendererText
* name_cell
= dynamic_cast<CellRendererText
*>(_display
.get_column_cell_renderer (0));
90 name_cell
->property_editable() = true;
91 name_cell
->signal_edited().connect (sigc::mem_fun (*this, &EditorRouteGroups::name_edit
));
93 /* use checkbox for the active + visible columns */
95 for (int i
= 1; i
< columns
; ++i
) {
96 CellRendererToggle
* active_cell
= dynamic_cast <CellRendererToggle
*> (_display
.get_column_cell_renderer (i
));
97 active_cell
->property_activatable() = true;
98 active_cell
->property_radio() = false;
101 _model
->signal_row_changed().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_change
));
102 /* What signal would you guess was emitted when the rows of your treeview are reordered
103 by a drag and drop? signal_rows_reordered? That would be far too easy.
104 No, signal_row_deleted().
106 _model
->signal_row_deleted().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_deleted
));
108 _display
.set_name ("EditGroupList");
109 _display
.get_selection()->set_mode (SELECTION_SINGLE
);
110 _display
.set_headers_visible (true);
111 _display
.set_reorderable (true);
112 _display
.set_rules_hint (true);
113 _display
.set_size_request (75, -1);
115 _scroller
.add (_display
);
116 _scroller
.set_policy (POLICY_AUTOMATIC
, POLICY_AUTOMATIC
);
118 _display
.signal_button_press_event().connect (sigc::mem_fun(*this, &EditorRouteGroups::button_press_event
), false);
120 HBox
* button_box
= manage (new HBox());
121 button_box
->set_homogeneous (true);
123 Button
* add_button
= manage (new Button ());
124 Button
* remove_button
= manage (new Button ());
128 w
= manage (new Image (Stock::ADD
, ICON_SIZE_BUTTON
));
130 add_button
->add (*w
);
132 w
= manage (new Image (Stock::REMOVE
, ICON_SIZE_BUTTON
));
134 remove_button
->add (*w
);
136 add_button
->signal_clicked().connect (sigc::hide_return (sigc::mem_fun (*this, &EditorRouteGroups::run_new_group_dialog
)));
137 remove_button
->signal_clicked().connect (sigc::mem_fun (*this, &EditorRouteGroups::remove_selected
));
139 button_box
->pack_start (*add_button
);
140 button_box
->pack_start (*remove_button
);
142 _all_group_active_button
.show ();
144 _display_packer
.pack_start (_scroller
, true, true);
145 _display_packer
.pack_start (_all_group_active_button
, false, false);
146 _display_packer
.pack_start (*button_box
, false, false);
148 _all_group_active_button
.signal_toggled().connect (sigc::mem_fun (*this, &EditorRouteGroups::all_group_toggled
));
152 EditorRouteGroups::remove_selected ()
154 Glib::RefPtr
<TreeSelection
> selection
= _display
.get_selection();
155 TreeView::Selection::ListHandle_Path rows
= selection
->get_selected_rows ();
161 TreeView::Selection::ListHandle_Path::iterator i
= rows
.begin();
164 /* selection mode is single, so rows.begin() is it */
166 if ((iter
= _model
->get_iter (*i
))) {
168 RouteGroup
* rg
= (*iter
)[_columns
.routegroup
];
171 _session
->remove_route_group (*rg
);
177 EditorRouteGroups::button_clicked ()
179 run_new_group_dialog ();
183 EditorRouteGroups::button_press_event (GdkEventButton
* ev
)
185 TreeModel::Path path
;
187 RouteGroup
* group
= 0;
188 TreeViewColumn
* column
;
192 bool const p
= _display
.get_path_at_pos ((int)ev
->x
, (int)ev
->y
, path
, column
, cellx
, celly
);
195 iter
= _model
->get_iter (path
);
199 group
= (*iter
)[_columns
.routegroup
];
202 if (Keyboard::is_context_menu_event (ev
)) {
203 _editor
->_group_tabs
->get_menu(group
)->popup (1, ev
->time
);
211 switch (GPOINTER_TO_UINT (column
->get_data (X_("colnum")))) {
213 if (Keyboard::is_edit_event (ev
)) {
214 if ((iter
= _model
->get_iter (path
))) {
215 if ((group
= (*iter
)[_columns
.routegroup
]) != 0) {
217 _display
.queue_draw();
227 if ((iter
= _model
->get_iter (path
))) {
228 bool gain
= (*iter
)[_columns
.gain
];
229 (*iter
)[_columns
.gain
] = !gain
;
231 _display
.queue_draw();
238 if ((iter
= _model
->get_iter (path
))) {
239 bool gain_relative
= (*iter
)[_columns
.gain_relative
];
240 (*iter
)[_columns
.gain_relative
] = !gain_relative
;
242 _display
.queue_draw();
249 if ((iter
= _model
->get_iter (path
))) {
250 bool mute
= (*iter
)[_columns
.mute
];
251 (*iter
)[_columns
.mute
] = !mute
;
253 _display
.queue_draw();
260 if ((iter
= _model
->get_iter (path
))) {
261 bool solo
= (*iter
)[_columns
.solo
];
262 (*iter
)[_columns
.solo
] = !solo
;
264 _display
.queue_draw();
271 if ((iter
= _model
->get_iter (path
))) {
272 bool record
= (*iter
)[_columns
.record
];
273 (*iter
)[_columns
.record
] = !record
;
275 _display
.queue_draw();
282 if ((iter
= _model
->get_iter (path
))) {
283 bool select
= (*iter
)[_columns
.select
];
284 (*iter
)[_columns
.select
] = !select
;
286 _display
.queue_draw();
293 if ((iter
= _model
->get_iter (path
))) {
294 bool edits
= (*iter
)[_columns
.edits
];
295 (*iter
)[_columns
.edits
] = !edits
;
297 _display
.queue_draw();
304 if ((iter
= _model
->get_iter (path
))) {
305 bool active_state
= (*iter
)[_columns
.active_state
];
306 (*iter
)[_columns
.active_state
] = !active_state
;
308 _display
.queue_draw();
315 if ((iter
= _model
->get_iter (path
))) {
316 bool is_visible
= (*iter
)[_columns
.is_visible
];
317 (*iter
)[_columns
.is_visible
] = !is_visible
;
319 _display
.queue_draw();
333 EditorRouteGroups::row_change (const Gtk::TreeModel::Path
&, const Gtk::TreeModel::iterator
& iter
)
337 if (_in_row_change
) {
341 if ((group
= (*iter
)[_columns
.routegroup
]) == 0) {
346 plist
.add (Properties::name
, string ((*iter
)[_columns
.text
]));
348 bool val
= (*iter
)[_columns
.gain
];
349 plist
.add (Properties::gain
, val
);
350 val
= (*iter
)[_columns
.gain_relative
];
351 plist
.add (Properties::relative
, val
);
352 val
= (*iter
)[_columns
.mute
];
353 plist
.add (Properties::mute
, val
);
354 val
= (*iter
)[_columns
.solo
];
355 plist
.add (Properties::solo
, val
);
356 val
= (*iter
)[_columns
.record
];
357 plist
.add (Properties::recenable
, val
);
358 val
= (*iter
)[_columns
.select
];
359 plist
.add (Properties::select
, val
);
360 val
= (*iter
)[_columns
.edits
];
361 plist
.add (Properties::edit
, val
);
362 val
= (*iter
)[_columns
.active_state
];
363 plist
.add (Properties::route_active
, val
);
365 group
->set_hidden (!(*iter
)[_columns
.is_visible
], this);
367 group
->apply_changes (plist
);
371 EditorRouteGroups::add (RouteGroup
* group
)
373 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::add
, group
)
376 TreeModel::Row row
= *(_model
->append());
378 row
[_columns
.gain
] = group
->is_gain ();
379 row
[_columns
.gain_relative
] = group
->is_relative ();
380 row
[_columns
.mute
] = group
->is_mute ();
381 row
[_columns
.solo
] = group
->is_solo ();
382 row
[_columns
.record
] = group
->is_recenable();
383 row
[_columns
.select
] = group
->is_select ();
384 row
[_columns
.edits
] = group
->is_edit ();
385 row
[_columns
.active_state
] = group
->is_route_active ();
386 row
[_columns
.is_visible
] = !group
->is_hidden();
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
.text
] = group
->name();
440 (*iter
)[_columns
.gain
] = group
->is_gain ();
441 (*iter
)[_columns
.gain_relative
] = group
->is_relative ();
442 (*iter
)[_columns
.mute
] = group
->is_mute ();
443 (*iter
)[_columns
.solo
] = group
->is_solo ();
444 (*iter
)[_columns
.record
] = group
->is_recenable ();
445 (*iter
)[_columns
.select
] = group
->is_select ();
446 (*iter
)[_columns
.edits
] = group
->is_edit ();
447 (*iter
)[_columns
.active_state
] = group
->is_route_active ();
448 (*iter
)[_columns
.is_visible
] = !group
->is_hidden();
452 _in_row_change
= false;
454 if (change
.contains (Properties::name
) || change
.contains (Properties::active
)) {
455 _editor
->_group_tabs
->set_dirty ();
458 for (TrackViewList::const_iterator i
= _editor
->get_track_views().begin(); i
!= _editor
->get_track_views().end(); ++i
) {
459 if ((*i
)->route_group() == group
) {
460 if (group
->is_hidden ()) {
461 _editor
->hide_track_in_display (*i
);
463 _editor
->_routes
->show_track_in_display (**i
);
470 EditorRouteGroups::name_edit (const std::string
& path
, const std::string
& new_text
)
475 if ((iter
= _model
->get_iter (path
))) {
477 if ((group
= (*iter
)[_columns
.routegroup
]) == 0) {
481 if (new_text
!= group
->name()) {
482 group
->set_name (new_text
);
488 EditorRouteGroups::clear ()
490 _display
.set_model (Glib::RefPtr
<Gtk::TreeStore
> (0));
492 _display
.set_model (_model
);
496 EditorRouteGroups::set_session (Session
* s
)
498 SessionHandlePtr::set_session (s
);
502 RouteGroup
& arg (_session
->all_route_group());
504 arg
.PropertyChanged
.connect (all_route_groups_changed_connection
, MISSING_INVALIDATOR
, ui_bind (&EditorRouteGroups::all_group_changed
, this, _1
), gui_context());
506 _session
->route_group_added
.connect (_session_connections
, MISSING_INVALIDATOR
, ui_bind (&EditorRouteGroups::add
, this, _1
), gui_context());
507 _session
->route_group_removed
.connect (
508 _session_connections
, MISSING_INVALIDATOR
, boost::bind (&EditorRouteGroups::groups_changed
, this), gui_context()
510 _session
->route_groups_reordered
.connect (
511 _session_connections
, MISSING_INVALIDATOR
, boost::bind (&EditorRouteGroups::groups_changed
, this), gui_context()
515 PBD::PropertyChange pc
;
516 pc
.add (Properties::select
);
517 pc
.add (Properties::active
);
518 all_group_changed (pc
);
524 EditorRouteGroups::run_new_group_dialog ()
528 return _editor
->_group_tabs
->run_new_group_dialog (rl
);
532 EditorRouteGroups::all_group_toggled ()
535 _session
->all_route_group().set_select (_all_group_active_button
.get_active());
540 EditorRouteGroups::all_group_changed (const PropertyChange
&)
543 RouteGroup
& arg (_session
->all_route_group());
544 _all_group_active_button
.set_active (arg
.is_active() && arg
.is_select());
546 _all_group_active_button
.set_active (false);
550 /** Called when a model row is deleted, but also when the model is
551 * reordered by a user drag-and-drop; the latter is what we are
552 * interested in here.
555 EditorRouteGroups::row_deleted (Gtk::TreeModel::Path
const &)
558 /* We need to ignore this in cases where we're not doing a drag-and-drop
564 /* Re-write the session's route group list so that the new order is preserved */
566 list
<RouteGroup
*> new_list
;
568 Gtk::TreeModel::Children children
= _model
->children();
569 for (Gtk::TreeModel::Children::iterator i
= children
.begin(); i
!= children
.end(); ++i
) {
570 new_list
.push_back ((*i
)[_columns
.routegroup
]);
573 _session
->reorder_route_groups (new_list
);