2 Copyright (C) 2000-2005 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.
26 #include <pbd/basename.h>
28 #include <ardour/audioregion.h>
29 #include <ardour/session_region.h>
31 #include <gtkmm2ext/stop_signal.h>
35 #include "ardour_ui.h"
36 #include "gui_thread.h"
43 using namespace ARDOUR;
46 using namespace Editing;
49 Editor::handle_audio_region_removed (AudioRegion* ignored)
55 Editor::handle_new_audio_region (AudioRegion *region)
57 /* don't copy region - the one we are being notified
58 about belongs to the session, and so it will
61 add_audio_region_to_region_display (region);
65 Editor::region_hidden (Region* r)
67 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::region_hidden), r));
73 Editor::add_audio_region_to_region_display (AudioRegion *region)
79 if (!show_automatic_regions_in_region_list && region->automatic()) {
83 if (region->hidden()) {
85 TreeModel::iterator iter = region_list_model->get_iter ("0");
86 TreeModel::Row parent;
89 if (iter == region_list_model->children().end()) {
91 parent = *(region_list_model->append());
93 parent[region_list_columns.name] = _("Hidden");
94 parent[region_list_columns.region] = 0;
98 if ((*iter)[region_list_columns.name] != _("Hidden")) {
100 parent = *(region_list_model->insert(iter));
101 parent[region_list_columns.name] = _("Hidden");
102 parent[region_list_columns.region] = 0;
110 row = *(region_list_model->append (parent.children()));
112 } else if (region->whole_file()) {
114 row = *(region_list_model->append());
115 set_color(c, 65535, 0, 0);
116 row[region_list_columns.color_] = c;
118 if (region->source().name()[0] == '/') { // external file
120 if (region->whole_file()) {
122 str += PBD::basename_nosuffix (region->source().name());
125 str = region->name();
130 str = region->name();
134 row[region_list_columns.name] = str;
135 row[region_list_columns.region] = region;
141 /* find parent node, add as new child */
143 TreeModel::iterator i;
144 TreeModel::Children rows = region_list_model->children();
145 bool found_parent = false;
147 for (i = rows.begin(); i != rows.end(); ++i) {
149 Region* rr = (*i)[region_list_columns.region];
150 AudioRegion* r = dynamic_cast<AudioRegion*>(rr);
152 if (r && r->whole_file()) {
153 if (region->source_equivalent (*r)) {
154 row = *(region_list_model->append ((*i).children()));
162 row = *(region_list_model->append());
168 row[region_list_columns.region] = region;
170 if (region->n_channels() > 1) {
171 row[region_list_columns.name] = string_compose("%1 [%2]", region->name(), region->n_channels());
173 row[region_list_columns.name] = region->name();
178 Editor::region_list_selection_changed()
182 if (region_list_display.get_selection()->count_selected_rows() > 0) {
189 TreeView::Selection::ListHandle_Path rows = region_list_display.get_selection()->get_selected_rows ();
190 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
193 /* just set the first selected region (in fact, the selection model might be SINGLE, which
194 means there can only be one.
197 if ((iter = region_list_model->get_iter (*i))) {
198 set_selected_regionview_from_region_list (*((*iter)[region_list_columns.region]), false);
204 Editor::insert_into_tmp_audio_regionlist(AudioRegion* region)
206 /* keep all whole files at the beginning */
208 if (region->whole_file()) {
209 tmp_audio_region_list.push_front (region);
211 tmp_audio_region_list.push_back (region);
216 Editor::redisplay_regions ()
220 region_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
221 region_list_model->clear ();
223 /* now add everything we have, via a temporary list used to help with
227 tmp_audio_region_list.clear();
228 session->foreach_audio_region (this, &Editor::insert_into_tmp_audio_regionlist);
230 for (list<AudioRegion*>::iterator r = tmp_audio_region_list.begin(); r != tmp_audio_region_list.end(); ++r) {
231 add_audio_region_to_region_display (*r);
234 region_list_display.set_model (region_list_model);
239 Editor::region_list_clear ()
241 region_list_model->clear();
245 Editor::build_region_list_menu ()
247 region_list_menu = dynamic_cast<Menu*>(ActionManager::get_widget ("/RegionListMenu"));
249 /* now grab specific menu items that we need */
251 Glib::RefPtr<Action> act;
253 act = ActionManager::get_action (X_("RegionList"), X_("rlShowAll"));
255 toggle_full_region_list_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
258 act = ActionManager::get_action (X_("RegionList"), X_("rlShowAuto"));
260 toggle_show_auto_regions_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
265 Editor::toggle_show_auto_regions ()
267 show_automatic_regions_in_region_list = toggle_show_auto_regions_action->get_active();
268 redisplay_regions ();
272 Editor::toggle_full_region_list ()
274 if (toggle_full_region_list_action->get_active()) {
275 region_list_display.expand_all ();
277 region_list_display.collapse_all ();
282 Editor::show_region_list_display_context_menu (int button, int time)
284 if (region_list_menu == 0) {
285 build_region_list_menu ();
288 if (region_list_display.get_selection()->count_selected_rows() > 0) {
289 ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions, true);
291 ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions, false);
294 region_list_menu->popup (button, time);
298 Editor::region_list_display_key_press (GdkEventKey* ev)
304 Editor::region_list_display_key_release (GdkEventKey* ev)
306 switch (ev->keyval) {
308 remove_region_from_region_list ();
319 Editor::region_list_display_button_press (GdkEventButton *ev)
323 TreeModel::Path path;
324 TreeViewColumn* column;
328 if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
329 if ((iter = region_list_model->get_iter (path))) {
330 region = (*iter)[region_list_columns.region];
338 if (Keyboard::is_delete_event (ev)) {
339 session->remove_region_from_region_list (*region);
343 if (Keyboard::is_context_menu_event (ev)) {
344 show_region_list_display_context_menu (ev->button, ev->time);
348 switch (ev->button) {
350 /* audition on double click */
351 if (ev->type == GDK_2BUTTON_PRESS) {
352 consider_auditioning (*region);
359 if (!Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
360 consider_auditioning (*region);
373 Editor::region_list_display_button_release (GdkEventButton *ev)
376 TreeModel::Path path;
377 TreeViewColumn* column;
382 if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
383 if ((iter = region_list_model->get_iter (path))) {
384 region = (*iter)[region_list_columns.region];
388 if (region && Keyboard::is_delete_event (ev)) {
389 session->remove_region_from_region_list (*region);
397 Editor::consider_auditioning (Region& region)
399 AudioRegion* r = dynamic_cast<AudioRegion*> (®ion);
402 session->cancel_audition ();
406 if (session->is_auditioning()) {
407 session->cancel_audition ();
408 if (r == last_audition_region) {
413 session->audition_region (*r);
414 last_audition_region = r;
418 Editor::region_list_sorter (TreeModel::iterator a, TreeModel::iterator b)
422 Region* r1 = (*a)[region_list_columns.region];
423 Region* r2 = (*b)[region_list_columns.region];
425 /* handle rows without regions, like "Hidden" */
435 AudioRegion* region1 = dynamic_cast<AudioRegion*> (r1);
436 AudioRegion* region2 = dynamic_cast<AudioRegion*> (r2);
438 if (region1 == 0 || region2 == 0) {
441 switch (region_list_sort_type) {
443 s1 = (*a)[region_list_columns.name];
444 s2 = (*b)[region_list_columns.name];
445 return (s1.compare (s2));
451 switch (region_list_sort_type) {
453 cmp = strcasecmp (region1->name().c_str(), region2->name().c_str());
457 cmp = region1->length() - region2->length();
461 cmp = region1->position() - region2->position();
465 cmp = region1->source().timestamp() - region2->source().timestamp();
469 cmp = region1->start() - region2->start();
473 cmp = (region1->start() + region1->length()) - (region2->start() + region2->length());
476 case BySourceFileName:
477 cmp = strcasecmp (region1->source().name().c_str(), region2->source().name().c_str());
480 case BySourceFileLength:
481 cmp = region1->source().length() - region2->source().length();
484 case BySourceFileCreationDate:
485 cmp = region1->source().timestamp() - region2->source().timestamp();
489 if (region1->source().name() == region2->source().name()) {
490 cmp = strcasecmp (region1->name().c_str(), region2->name().c_str());
492 cmp = strcasecmp (region1->source().name().c_str(), region2->source().name().c_str());
499 } else if (cmp > 0) {
507 Editor::reset_region_list_sort_type (RegionListSortType type)
509 if (type != region_list_sort_type) {
510 region_list_sort_type = type;
511 region_list_model->set_sort_func (0, (mem_fun (*this, &Editor::region_list_sorter)));
516 Editor::reset_region_list_sort_direction (bool up)
518 region_list_model->set_sort_column (0, up ? SORT_ASCENDING : SORT_DESCENDING);
522 Editor::region_list_selection_mapover (slot<void,Region&> sl)
524 Glib::RefPtr<TreeSelection> selection = region_list_display.get_selection();
525 TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
526 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
528 if (selection->count_selected_rows() == 0 || session == 0) {
532 for (; i != rows.end(); ++i) {
535 if ((iter = region_list_model->get_iter (*i))) {
536 sl (*((*iter)[region_list_columns.region]));
542 Editor::hide_a_region (Region& r)
548 Editor::remove_a_region (Region& r)
550 session->remove_region_from_region_list (r);
554 Editor::audition_region_from_region_list ()
556 region_list_selection_mapover (mem_fun (*this, &Editor::consider_auditioning));
560 Editor::hide_region_from_region_list ()
562 region_list_selection_mapover (mem_fun (*this, &Editor::hide_a_region));
566 Editor::remove_region_from_region_list ()
568 region_list_selection_mapover (mem_fun (*this, &Editor::remove_a_region));
572 Editor::region_list_display_drag_data_received (const RefPtr<Gdk::DragContext>& context,
574 const SelectionData& data,
575 guint info, guint time)
577 vector<string> paths;
579 if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
580 do_embed_sndfiles (paths, false);
581 context->drag_finish (true, false, time);
586 Editor::region_list_selection_filter (const RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
588 /* not possible to select rows that do not represent regions, like "Hidden" */
590 return (*(model->get_iter (path)))[region_list_columns.region] != 0;