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.
23 #include <gtkmm2ext/stop_signal.h>
24 #include <gtkmm2ext/gtk_ui.h>
25 #include "ardour/route_group.h"
30 #include "time_axis_view.h"
32 #include "gui_thread.h"
33 #include "editor_group_tabs.h"
34 #include "route_group_dialog.h"
35 #include "route_time_axis.h"
36 #include "editor_routes.h"
37 #include "editor_route_groups.h"
39 #include "ardour/route.h"
40 #include "ardour/session.h"
45 using namespace ARDOUR
;
48 using Gtkmm2ext::Keyboard
;
50 EditorRouteGroups::EditorRouteGroups (Editor
* e
)
51 : EditorComponent (e
),
53 _in_row_change (false)
56 _model
= ListStore::create (_columns
);
57 _display
.set_model (_model
);
59 _display
.append_column (_("Name"), _columns
.text
);
61 _display
.append_column (_("G"), _columns
.gain
);
62 _display
.append_column (_("R"), _columns
.record
);
63 _display
.append_column (_("M"), _columns
.mute
);
64 _display
.append_column (_("S"), _columns
.solo
);
65 _display
.append_column (_("Sel"), _columns
.select
);
66 _display
.append_column (_("E"), _columns
.edits
);
68 _display
.append_column (_("Show"), _columns
.is_visible
);
70 _display
.get_column (0)->set_data (X_("colnum"), GUINT_TO_POINTER(0));
71 _display
.get_column (1)->set_data (X_("colnum"), GUINT_TO_POINTER(1));
72 _display
.get_column (2)->set_data (X_("colnum"), GUINT_TO_POINTER(2));
73 _display
.get_column (3)->set_data (X_("colnum"), GUINT_TO_POINTER(3));
74 _display
.get_column (4)->set_data (X_("colnum"), GUINT_TO_POINTER(4));
75 _display
.get_column (5)->set_data (X_("colnum"), GUINT_TO_POINTER(5));
76 _display
.get_column (6)->set_data (X_("colnum"), GUINT_TO_POINTER(6));
77 _display
.get_column (7)->set_data (X_("colnum"), GUINT_TO_POINTER(7));
79 _display
.get_column (0)->set_expand (true);
80 _display
.get_column (1)->set_expand (false);
81 _display
.get_column (2)->set_expand (false);
82 _display
.get_column (3)->set_expand (false);
83 _display
.get_column (4)->set_expand (false);
84 _display
.get_column (5)->set_expand (false);
85 _display
.get_column (6)->set_expand (false);
86 _display
.get_column (7)->set_expand (false);
88 _display
.set_headers_visible (true);
90 /* name is directly editable */
92 CellRendererText
* name_cell
= dynamic_cast<CellRendererText
*>(_display
.get_column_cell_renderer (0));
93 name_cell
->property_editable() = true;
94 name_cell
->signal_edited().connect (sigc::mem_fun (*this, &EditorRouteGroups::name_edit
));
96 /* use checkbox for the active + visible columns */
98 CellRendererToggle
* active_cell
= dynamic_cast<CellRendererToggle
*>(_display
.get_column_cell_renderer (1));
99 active_cell
->property_activatable() = true;
100 active_cell
->property_radio() = false;
102 active_cell
= dynamic_cast<CellRendererToggle
*>(_display
.get_column_cell_renderer (2));
103 active_cell
->property_activatable() = true;
104 active_cell
->property_radio() = false;
106 active_cell
= dynamic_cast<CellRendererToggle
*>(_display
.get_column_cell_renderer (3));
107 active_cell
->property_activatable() = true;
108 active_cell
->property_radio() = false;
110 active_cell
= dynamic_cast<CellRendererToggle
*>(_display
.get_column_cell_renderer (4));
111 active_cell
->property_activatable() = true;
112 active_cell
->property_radio() = false;
114 active_cell
= dynamic_cast<CellRendererToggle
*>(_display
.get_column_cell_renderer (5));
115 active_cell
->property_activatable() = true;
116 active_cell
->property_radio() = false;
118 active_cell
= dynamic_cast<CellRendererToggle
*>(_display
.get_column_cell_renderer (6));
119 active_cell
->property_activatable() = true;
120 active_cell
->property_radio() = false;
122 active_cell
= dynamic_cast<CellRendererToggle
*>(_display
.get_column_cell_renderer (7));
123 active_cell
->property_activatable() = true;
124 active_cell
->property_radio() = false;
126 _model
->signal_row_changed().connect (sigc::mem_fun (*this, &EditorRouteGroups::row_change
));
128 _display
.set_name ("EditGroupList");
129 _display
.get_selection()->set_mode (SELECTION_SINGLE
);
130 _display
.set_headers_visible (true);
131 _display
.set_reorderable (false);
132 _display
.set_rules_hint (true);
133 _display
.set_size_request (75, -1);
135 _scroller
.add (_display
);
136 _scroller
.set_policy (POLICY_AUTOMATIC
, POLICY_AUTOMATIC
);
138 _display
.signal_button_press_event().connect (sigc::mem_fun(*this, &EditorRouteGroups::button_press_event
), false);
140 _display_packer
= new VBox
;
141 HBox
* button_box
= manage (new HBox());
142 button_box
->set_homogeneous (true);
144 Button
* add_button
= manage (new Button ());
145 Button
* remove_button
= manage (new Button ());
149 w
= manage (new Image (Stock::ADD
, ICON_SIZE_BUTTON
));
151 add_button
->add (*w
);
153 w
= manage (new Image (Stock::REMOVE
, ICON_SIZE_BUTTON
));
155 remove_button
->add (*w
);
157 add_button
->signal_clicked().connect (hide_return (sigc::mem_fun (*this, &EditorRouteGroups::new_route_group
)));
158 remove_button
->signal_clicked().connect (sigc::mem_fun (*this, &EditorRouteGroups::remove_selected
));
160 button_box
->pack_start (*add_button
);
161 button_box
->pack_start (*remove_button
);
163 _display_packer
->pack_start (_scroller
, true, true);
164 _display_packer
->pack_start (*button_box
, false, false);
169 EditorRouteGroups::menu (RouteGroup
* g
)
171 using namespace Gtk::Menu_Helpers
;
175 Menu
* new_from
= new Menu
;
176 MenuList
& f
= new_from
->items ();
177 f
.push_back (MenuElem (_("Selection..."), sigc::mem_fun (*this, &EditorRouteGroups::new_from_selection
)));
178 f
.push_back (MenuElem (_("Record Enabled..."), sigc::mem_fun (*this, &EditorRouteGroups::new_from_rec_enabled
)));
179 f
.push_back (MenuElem (_("Soloed..."), sigc::mem_fun (*this, &EditorRouteGroups::new_from_soloed
)));
182 _menu
->set_name ("ArdourContextMenu");
183 MenuList
& items
= _menu
->items();
185 items
.push_back (MenuElem (_("New..."), hide_return (sigc::mem_fun(*this, &EditorRouteGroups::new_route_group
))));
186 items
.push_back (MenuElem (_("New From"), *new_from
));
188 items
.push_back (MenuElem (_("Edit..."), sigc::bind (sigc::mem_fun (*this, &EditorRouteGroups::edit
), g
)));
189 items
.push_back (MenuElem (_("Fit to Window"), sigc::bind (sigc::mem_fun (*_editor
, &Editor::fit_route_group
), g
)));
190 items
.push_back (MenuElem (_("Subgroup"), sigc::bind (sigc::mem_fun (*this, &EditorRouteGroups::subgroup
), g
)));
191 items
.push_back (MenuElem (_("Collect"), sigc::bind (sigc::mem_fun (*this, &EditorRouteGroups::collect
), g
)));
193 items
.push_back (SeparatorElem());
194 items
.push_back (MenuElem (_("Activate All"), sigc::mem_fun(*this, &EditorRouteGroups::activate_all
)));
195 items
.push_back (MenuElem (_("Disable All"), sigc::mem_fun(*this, &EditorRouteGroups::disable_all
)));
201 EditorRouteGroups::subgroup (RouteGroup
* g
)
207 EditorRouteGroups::unsubgroup (RouteGroup
* g
)
209 g
->destroy_subgroup ();
213 EditorRouteGroups::activate_all ()
215 _session
->foreach_route_group (
216 sigc::bind (sigc::mem_fun (*this, &EditorRouteGroups::set_activation
), true)
221 EditorRouteGroups::disable_all ()
223 _session
->foreach_route_group (
224 sigc::bind (sigc::mem_fun (*this, &EditorRouteGroups::set_activation
), false)
229 EditorRouteGroups::set_activation (RouteGroup
* g
, bool a
)
231 g
->set_active (a
, this);
235 EditorRouteGroups::new_route_group () const
239 plist
.add (Properties::active
, true);
240 plist
.add (Properties::mute
, true);
241 plist
.add (Properties::solo
, true);
242 plist
.add (Properties::edit
, true);
244 RouteGroup
* g
= new RouteGroup (*_session
, "");
246 g
->set_properties (plist
);
248 RouteGroupDialog
d (g
, Gtk::Stock::NEW
);
249 int const r
= d
.do_run ();
251 if (r
!= Gtk::RESPONSE_OK
) {
256 _session
->add_route_group (g
);
260 EditorRouteGroups::run_new_group_dialog (const RouteList
& rl
)
264 plist
.add (Properties::active
, true);
265 plist
.add (Properties::mute
, true);
266 plist
.add (Properties::solo
, true);
267 plist
.add (Properties::recenable
, true);
268 plist
.add (Properties::edit
, true);
270 RouteGroup
* g
= new RouteGroup (*_session
, "");
271 g
->set_properties (plist
);
273 RouteGroupDialog
d (g
, Gtk::Stock::NEW
);
274 int const r
= d
.do_run ();
277 case Gtk::RESPONSE_OK
:
278 case Gtk::RESPONSE_ACCEPT
:
279 _session
->add_route_group (g
);
280 for (RouteList::const_iterator i
= rl
.begin(); i
!= rl
.end(); ++i
) {
290 EditorRouteGroups::new_from_selection ()
292 if (_editor
->get_selection().tracks
.empty()) {
298 for (TrackSelection::iterator i
= _editor
->get_selection().tracks
.begin(); i
!= _editor
->get_selection().tracks
.end(); ++i
) {
299 RouteTimeAxisView
* rtv
= dynamic_cast<RouteTimeAxisView
*> (*i
);
301 rl
.push_back (rtv
->route());
309 run_new_group_dialog (rl
);
313 EditorRouteGroups::new_from_rec_enabled ()
317 for (TrackViewList::const_iterator i
= _editor
->get_track_views().begin(); i
!= _editor
->get_track_views().end(); ++i
) {
318 RouteTimeAxisView
* rtv
= dynamic_cast<RouteTimeAxisView
*> (*i
);
319 if (rtv
&& rtv
->route()->record_enabled()) {
320 rl
.push_back (rtv
->route());
328 run_new_group_dialog (rl
);
332 EditorRouteGroups::new_from_soloed ()
336 for (TrackViewList::const_iterator i
= _editor
->get_track_views().begin(); i
!= _editor
->get_track_views().end(); ++i
) {
337 RouteTimeAxisView
* rtv
= dynamic_cast<RouteTimeAxisView
*> (*i
);
338 if (rtv
&& !rtv
->route()->is_master() && rtv
->route()->soloed()) {
339 rl
.push_back (rtv
->route());
347 run_new_group_dialog (rl
);
351 EditorRouteGroups::edit (RouteGroup
* g
)
353 RouteGroupDialog
d (g
, Gtk::Stock::APPLY
);
358 EditorRouteGroups::remove_selected ()
360 Glib::RefPtr
<TreeSelection
> selection
= _display
.get_selection();
361 TreeView::Selection::ListHandle_Path rows
= selection
->get_selected_rows ();
367 TreeView::Selection::ListHandle_Path::iterator i
= rows
.begin();
370 /* selection mode is single, so rows.begin() is it */
372 if ((iter
= _model
->get_iter (*i
))) {
374 RouteGroup
* rg
= (*iter
)[_columns
.routegroup
];
377 _session
->remove_route_group (*rg
);
383 EditorRouteGroups::button_clicked ()
389 EditorRouteGroups::button_press_event (GdkEventButton
* ev
)
391 TreeModel::Path path
;
393 RouteGroup
* group
= 0;
394 TreeViewColumn
* column
;
398 bool const p
= _display
.get_path_at_pos ((int)ev
->x
, (int)ev
->y
, path
, column
, cellx
, celly
);
401 iter
= _model
->get_iter (path
);
405 group
= (*iter
)[_columns
.routegroup
];
408 if (Keyboard::is_context_menu_event (ev
)) {
409 menu(group
)->popup (1, ev
->time
);
417 switch (GPOINTER_TO_UINT (column
->get_data (X_("colnum")))) {
419 if (Keyboard::is_edit_event (ev
)) {
420 if ((iter
= _model
->get_iter (path
))) {
421 if ((group
= (*iter
)[_columns
.routegroup
]) != 0) {
422 // edit_route_group (group);
424 _display
.queue_draw();
434 if ((iter
= _model
->get_iter (path
))) {
435 bool gain
= (*iter
)[_columns
.gain
];
436 (*iter
)[_columns
.gain
] = !gain
;
438 _display
.queue_draw();
445 if ((iter
= _model
->get_iter (path
))) {
446 bool record
= (*iter
)[_columns
.record
];
447 (*iter
)[_columns
.record
] = !record
;
449 _display
.queue_draw();
456 if ((iter
= _model
->get_iter (path
))) {
457 bool mute
= (*iter
)[_columns
.mute
];
458 (*iter
)[_columns
.mute
] = !mute
;
460 _display
.queue_draw();
467 if ((iter
= _model
->get_iter (path
))) {
468 bool solo
= (*iter
)[_columns
.solo
];
469 (*iter
)[_columns
.solo
] = !solo
;
471 _display
.queue_draw();
478 if ((iter
= _model
->get_iter (path
))) {
479 bool select
= (*iter
)[_columns
.select
];
480 (*iter
)[_columns
.select
] = !select
;
482 _display
.queue_draw();
489 if ((iter
= _model
->get_iter (path
))) {
490 bool edits
= (*iter
)[_columns
.edits
];
491 (*iter
)[_columns
.edits
] = !edits
;
493 _display
.queue_draw();
500 if ((iter
= _model
->get_iter (path
))) {
501 bool visible
= (*iter
)[_columns
.is_visible
];
502 (*iter
)[_columns
.is_visible
] = !visible
;
504 _display
.queue_draw();
518 EditorRouteGroups::row_change (const Gtk::TreeModel::Path
&, const Gtk::TreeModel::iterator
& iter
)
522 if (_in_row_change
) {
526 if ((group
= (*iter
)[_columns
.routegroup
]) == 0) {
530 if ((*iter
)[_columns
.is_visible
]) {
531 for (TrackViewList::const_iterator j
= _editor
->get_track_views().begin(); j
!= _editor
->get_track_views().end(); ++j
) {
532 if ((*j
)->route_group() == group
) {
533 _editor
->_routes
->show_track_in_display (**j
);
537 for (TrackViewList::const_iterator j
= _editor
->get_track_views().begin(); j
!= _editor
->get_track_views().end(); ++j
) {
538 if ((*j
)->route_group() == group
) {
539 _editor
->hide_track_in_display (*j
);
545 bool val
= (*iter
)[_columns
.gain
];
546 plist
.add (Properties::gain
, val
);
547 val
= (*iter
)[_columns
.record
];
548 plist
.add (Properties::recenable
, val
);
549 val
= (*iter
)[_columns
.mute
];
550 plist
.add (Properties::mute
, val
);
551 val
= (*iter
)[_columns
.solo
];
552 plist
.add (Properties::solo
, val
);
553 val
= (*iter
)[_columns
.select
];
554 plist
.add (Properties::select
, val
);
555 val
= (*iter
)[_columns
.edits
];
556 plist
.add (Properties::edit
, val
);
557 plist
.add (Properties::name
, string ((*iter
)[_columns
.text
]));
559 group
->set_hidden (!(*iter
)[_columns
.is_visible
], this);
561 group
->set_properties (plist
);
565 EditorRouteGroups::add (RouteGroup
* group
)
567 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::add
, group
)
570 TreeModel::Row row
= *(_model
->append());
572 row
[_columns
.is_visible
] = !group
->is_hidden();
573 row
[_columns
.gain
] = group
->is_gain ();
574 row
[_columns
.record
] = group
->is_recenable();
575 row
[_columns
.mute
] = group
->is_mute ();
576 row
[_columns
.solo
] = group
->is_solo ();
577 row
[_columns
.select
] = group
->is_select ();
578 row
[_columns
.edits
] = group
->is_edit ();
580 _in_row_change
= true;
582 row
[_columns
.routegroup
] = group
;
584 if (!group
->name().empty()) {
585 row
[_columns
.text
] = group
->name();
587 row
[_columns
.text
] = _("unnamed");
591 group
->PropertyChanged
.connect (property_changed_connection
, MISSING_INVALIDATOR
, ui_bind (&EditorRouteGroups::property_changed
, this, group
, _1
), gui_context());
594 TreeViewColumn
* col
= _display
.get_column (0);
595 CellRendererText
* name_cell
= dynamic_cast<CellRendererText
*>(_display
.get_column_cell_renderer (0));
596 _display
.set_cursor (_model
->get_path (row
), *col
, *name_cell
, true);
599 _in_row_change
= false;
601 _editor
->_group_tabs
->set_dirty ();
605 EditorRouteGroups::groups_changed ()
607 ENSURE_GUI_THREAD (*this, &EditorRouteGroups::groups_changed
)
609 /* just rebuild the while thing */
615 row
= *(_model
->append());
616 row
[_columns
.is_visible
] = true;
617 row
[_columns
.text
] = (_("-all-"));
618 row
[_columns
.routegroup
] = 0;
622 _session
->foreach_route_group (sigc::mem_fun (*this, &EditorRouteGroups::add
));
627 EditorRouteGroups::property_changed (RouteGroup
* group
, const PropertyChange
& change
)
629 _in_row_change
= true;
631 Gtk::TreeModel::Children children
= _model
->children();
633 for(Gtk::TreeModel::Children::iterator iter
= children
.begin(); iter
!= children
.end(); ++iter
) {
634 if (group
== (*iter
)[_columns
.routegroup
]) {
635 (*iter
)[_columns
.is_visible
] = !group
->is_hidden();
636 (*iter
)[_columns
.text
] = group
->name();
637 (*iter
)[_columns
.gain
] = group
->is_gain ();
638 (*iter
)[_columns
.record
] = group
->is_recenable ();
639 (*iter
)[_columns
.mute
] = group
->is_mute ();
640 (*iter
)[_columns
.solo
] = group
->is_solo ();
641 (*iter
)[_columns
.select
] = group
->is_select ();
642 (*iter
)[_columns
.edits
] = group
->is_edit ();
646 _in_row_change
= false;
648 if (change
.contains (Properties::name
) || change
.contains (Properties::active
)) {
649 _editor
->_group_tabs
->set_dirty ();
654 EditorRouteGroups::name_edit (const Glib::ustring
& path
, const Glib::ustring
& new_text
)
659 if ((iter
= _model
->get_iter (path
))) {
661 if ((group
= (*iter
)[_columns
.routegroup
]) == 0) {
665 if (new_text
!= group
->name()) {
666 group
->set_name (new_text
);
672 EditorRouteGroups::clear ()
674 _display
.set_model (Glib::RefPtr
<Gtk::TreeStore
> (0));
676 _display
.set_model (_model
);
680 EditorRouteGroups::set_session (Session
* s
)
682 EditorComponent::set_session (s
);
685 _session
->route_group_added
.connect (_session_connections
, MISSING_INVALIDATOR
, ui_bind (&EditorRouteGroups::add
, this, _1
), gui_context());
686 _session
->route_group_removed
.connect (_session_connections
, MISSING_INVALIDATOR
, boost::bind (&EditorRouteGroups::groups_changed
, this), gui_context());
692 struct CollectSorter
{
693 bool operator () (boost::shared_ptr
<Route
> a
, boost::shared_ptr
<Route
> b
) {
694 return a
->order_key (N_ ("editor")) < b
->order_key (N_ ("editor"));
698 /** Collect all members of a RouteGroup so that they are together in the Editor.
699 * @param g Group to collect.
702 EditorRouteGroups::collect (RouteGroup
* g
)
704 boost::shared_ptr
<RouteList
> routes
= g
->route_list ();
705 routes
->sort (CollectSorter ());
706 int const N
= routes
->size ();
708 RouteList::iterator i
= routes
->begin ();
709 TrackViewList::const_iterator j
= _editor
->get_track_views().begin();
713 while (i
!= routes
->end() && j
!= _editor
->get_track_views().end()) {
715 RouteTimeAxisView
* rtv
= dynamic_cast<RouteTimeAxisView
*> (*j
);
718 boost::shared_ptr
<Route
> r
= rtv
->route ();
719 int const k
= r
->order_key (N_ ("editor"));
730 r
->set_order_key (N_ ("editor"), coll
);
737 r
->set_order_key (N_ ("editor"), k
+ diff
);
745 _editor
->_routes
->sync_order_keys ("");