imported files retain BWF timestamp info (nick murtagh) ; logarithm plugin controls...
[ardour.git] / gtk2_ardour / editor_edit_groups.cc
1 /*
2     Copyright (C) 2000 Paul Davis 
3
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.
8
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.
13
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.
17
18 */
19
20 #include <cstdlib>
21 #include <cmath>
22
23 #include <gtkmm2ext/stop_signal.h>
24 #include <gtkmm2ext/gtk_ui.h>
25 #include <ardour/route_group.h>
26
27 #include "editor.h"
28 #include "keyboard.h"
29 #include "marker.h"
30 #include "time_axis_view.h"
31 #include "prompter.h"
32 #include "gui_thread.h"
33
34 #include <ardour/route.h>
35
36 #include "i18n.h"
37
38 using namespace sigc;
39 using namespace ARDOUR;
40 using namespace PBD;
41 using namespace Gtk;
42
43 void
44 Editor::build_edit_group_list_menu ()
45 {
46         using namespace Gtk::Menu_Helpers;
47
48         edit_group_list_menu = new Menu;
49         edit_group_list_menu->set_name ("ArdourContextMenu");
50         MenuList& items = edit_group_list_menu->items();
51
52         items.push_back (MenuElem (_("Activate All"), mem_fun(*this, &Editor::activate_all_edit_groups)));
53         items.push_back (MenuElem (_("Disable All"), mem_fun(*this, &Editor::disable_all_edit_groups)));
54         items.push_back (SeparatorElem());
55         items.push_back (MenuElem (_("Add group"), mem_fun(*this, &Editor::new_edit_group)));
56         
57 }
58
59 void
60 Editor::activate_all_edit_groups ()
61 {
62         Gtk::TreeModel::Children children = group_model->children();
63         for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
64                 (*iter)[group_columns.is_active] = true;
65         }
66 }
67
68 void
69 Editor::disable_all_edit_groups ()
70 {
71         Gtk::TreeModel::Children children = group_model->children();
72         for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
73                 (*iter)[group_columns.is_active] = false;
74         }
75 }
76
77 void
78 Editor::new_edit_group ()
79 {
80         session->add_edit_group ("");
81 }
82
83 void
84 Editor::remove_selected_edit_group ()
85 {
86         Glib::RefPtr<TreeSelection> selection = edit_group_display.get_selection();
87         TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
88
89         if (rows.empty()) {
90                 return;
91         }
92
93         TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
94         TreeIter iter;
95         
96         /* selection mode is single, so rows.begin() is it */
97
98         if ((iter = group_model->get_iter (*i))) {
99
100                 RouteGroup* rg = (*iter)[group_columns.routegroup];
101
102                 if (rg) {
103                         session->remove_edit_group (*rg);
104                 }
105         }
106 }
107
108 void
109 Editor::edit_group_list_button_clicked ()
110 {
111         new_edit_group ();
112 }
113
114 gint
115 Editor::edit_group_list_button_press_event (GdkEventButton* ev)
116 {
117         if (Keyboard::is_context_menu_event (ev)) {
118                 if (edit_group_list_menu == 0) {
119                         build_edit_group_list_menu ();
120                 }
121                 edit_group_list_menu->popup (1, ev->time);
122                 return true;
123         }
124
125
126         RouteGroup* group;
127         TreeIter iter;
128         TreeModel::Path path;
129         TreeViewColumn* column;
130         int cellx;
131         int celly;
132
133         if (!edit_group_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
134                 return false;
135         }
136
137         switch (GPOINTER_TO_UINT (column->get_data (X_("colnum")))) {
138         case 0:
139                 if (Keyboard::is_edit_event (ev)) {
140                         if ((iter = group_model->get_iter (path))) {
141                                 if ((group = (*iter)[group_columns.routegroup]) != 0) {
142                                         // edit_route_group (group);
143 #ifdef GTKOSX
144                                         edit_group_display.queue_draw();
145 #endif
146                                         return true;
147                                 }
148                         }
149                         
150                 } 
151                 break;
152
153         case 1:
154                 if ((iter = group_model->get_iter (path))) {
155                         bool active = (*iter)[group_columns.is_active];
156                         (*iter)[group_columns.is_active] = !active;
157 #ifdef GTKOSX
158                         edit_group_display.queue_draw();
159 #endif
160                         return true;
161                 }
162                 break;
163                 
164         case 2:
165                 if ((iter = group_model->get_iter (path))) {
166                         bool visible = (*iter)[group_columns.is_visible];
167                         (*iter)[group_columns.is_visible] = !visible;
168 #ifdef GTKOSX
169                         edit_group_display.queue_draw();
170 #endif
171                         return true;
172                 }
173                 break;
174
175         default:
176                 break;
177         }
178         
179         return false;
180  }
181
182 void 
183 Editor::edit_group_row_change (const Gtk::TreeModel::Path& path,const Gtk::TreeModel::iterator& iter)
184 {
185         RouteGroup* group;
186
187         if (in_edit_group_row_change) {
188                 return;
189         }
190
191         if ((group = (*iter)[group_columns.routegroup]) == 0) {
192                 return;
193         }
194
195         if ((*iter)[group_columns.is_visible]) {
196                 for (TrackViewList::iterator j = track_views.begin(); j != track_views.end(); ++j) {
197                         if ((*j)->edit_group() == group) {
198                                 show_track_in_display (**j);
199                         }
200                 }
201         } else {
202                 for (TrackViewList::iterator j = track_views.begin(); j != track_views.end(); ++j) {
203                         if ((*j)->edit_group() == group) {
204                                 hide_track_in_display (**j);
205                         }
206                 }
207         }
208
209         bool active = (*iter)[group_columns.is_active];
210         group->set_active (active, this);
211
212
213         string name = (*iter)[group_columns.text];
214
215         if (name != group->name()) {
216                 group->set_name (name);
217         }
218 }
219
220 void
221 Editor::add_edit_group (RouteGroup* group)
222 {
223         ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::add_edit_group), group));
224         bool focus = false;
225
226         TreeModel::Row row = *(group_model->append());
227         row[group_columns.is_active] = group->is_active();
228         row[group_columns.is_visible] = false;
229
230         in_edit_group_row_change = true;
231
232         row[group_columns.routegroup] = group;
233
234         if (!group->name().empty()) {
235                 row[group_columns.text] = group->name();
236         } else {
237                 row[group_columns.text] = _("unnamed");
238                 focus = true;
239         }
240
241         group->FlagsChanged.connect (bind (mem_fun(*this, &Editor::group_flags_changed), group));
242
243         if (focus) {
244                 TreeViewColumn* col = edit_group_display.get_column (0);
245                 CellRendererText* name_cell = dynamic_cast<CellRendererText*>(edit_group_display.get_column_cell_renderer (0));
246                 edit_group_display.set_cursor (group_model->get_path (row), *col, *name_cell, true);
247         }
248
249         in_edit_group_row_change = false;
250 }
251
252 void
253 Editor::edit_groups_changed ()
254 {
255         ENSURE_GUI_THREAD (mem_fun (*this, &Editor::edit_groups_changed));
256
257         /* just rebuild the while thing */
258
259         group_model->clear ();
260
261         {
262                 TreeModel::Row row;
263                 row = *(group_model->append());
264                 row[group_columns.is_active] = false;
265                 row[group_columns.is_visible] = true;
266                 row[group_columns.text] = (_("-all-"));
267                 row[group_columns.routegroup] = 0;
268         }
269
270         session->foreach_edit_group (mem_fun (*this, &Editor::add_edit_group));
271 }
272
273 void
274 Editor::group_flags_changed (void* src, RouteGroup* group)
275 {
276         ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::group_flags_changed), src, group));
277
278         in_edit_group_row_change = true;
279
280         Gtk::TreeModel::Children children = group_model->children();
281         for(Gtk::TreeModel::Children::iterator iter = children.begin(); iter != children.end(); ++iter) {
282                 if (group == (*iter)[group_columns.routegroup]) {
283                         (*iter)[group_columns.is_active] = group->is_active();
284                         (*iter)[group_columns.is_visible] = !group->is_hidden();
285                         (*iter)[group_columns.text] = group->name();
286                 }
287         }
288
289         in_edit_group_row_change = false;
290 }
291
292 void
293 Editor::edit_group_name_edit (const Glib::ustring& path, const Glib::ustring& new_text)
294 {
295         RouteGroup* group;
296         TreeIter iter;
297         
298         if ((iter = group_model->get_iter (path))) {
299         
300                 if ((group = (*iter)[group_columns.routegroup]) == 0) {
301                         return;
302                 }
303                 
304                 if (new_text != group->name()) {
305                         group->set_name (new_text);
306                 }
307         }
308 }