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/audiofilesource.h>
30 #include <ardour/silentfilesource.h>
31 #include <ardour/session_region.h>
33 #include <gtkmm2ext/stop_signal.h>
38 #include "ardour_ui.h"
39 #include "gui_thread.h"
46 using namespace ARDOUR;
50 using namespace Editing;
53 Editor::handle_region_removed (boost::weak_ptr<Region> wregion)
55 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::redisplay_regions));
60 Editor::handle_new_region (boost::weak_ptr<Region> wregion)
62 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::handle_new_region), wregion));
64 /* don't copy region - the one we are being notified
65 about belongs to the session, and so it will
69 boost::shared_ptr<Region> region (wregion.lock());
72 add_region_to_region_display (region);
77 Editor::region_hidden (boost::shared_ptr<Region> r)
79 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::region_hidden), r));
85 Editor::add_region_to_region_display (boost::shared_ptr<Region> region)
92 missing_source = boost::dynamic_pointer_cast<SilentFileSource>(region->source());
94 if (!show_automatic_regions_in_region_list && region->automatic()) {
98 if (region->hidden()) {
100 TreeModel::iterator iter = region_list_model->get_iter ("0");
101 TreeModel::Row parent;
102 TreeModel::Row child;
107 parent = *(region_list_model->append());
109 parent[region_list_columns.name] = _("Hidden");
110 boost::shared_ptr<Region> proxy = parent[region_list_columns.region];
115 if ((*iter)[region_list_columns.name] != _("Hidden")) {
117 parent = *(region_list_model->insert(iter));
118 parent[region_list_columns.name] = _("Hidden");
119 boost::shared_ptr<Region> proxy = parent[region_list_columns.region];
129 row = *(region_list_model->append (parent.children()));
131 } else if (region->whole_file()) {
133 row = *(region_list_model->append());
134 if (missing_source) {
135 c.set_rgb(65535,0,0); // FIXME: error color from style
137 set_color(c, rgba_from_style ("RegionListWholeFile", 0xff, 0, 0, 0, "fg", Gtk::STATE_NORMAL, false ));
139 row[region_list_columns.color_] = c;
141 if (region->source()->name()[0] == '/') { // external file
143 if (region->whole_file()) {
145 boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource>(region->source());
150 str = region_name_from_path (afs->path(), region->n_channels() > 1);
152 str += region->source()->name();
156 str = region->name();
161 str = region->name();
165 if (region->n_channels() > 1) {
166 std::stringstream foo;
167 foo << region->n_channels ();
173 if (missing_source) {
174 str += _(" (MISSING)");
177 row[region_list_columns.name] = str;
178 row[region_list_columns.region] = region;
184 /* find parent node, add as new child */
186 TreeModel::iterator i;
187 TreeModel::Children rows = region_list_model->children();
188 bool found_parent = false;
190 for (i = rows.begin(); i != rows.end(); ++i) {
192 boost::shared_ptr<Region> rr = (*i)[region_list_columns.region];
193 boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion>(rr);
195 if (r && r->whole_file()) {
196 if (region->source_equivalent (r)) {
197 row = *(region_list_model->append ((*i).children()));
205 row = *(region_list_model->append());
211 row[region_list_columns.region] = region;
213 if (region->n_channels() > 1) {
214 row[region_list_columns.name] = string_compose("%1 [%2]", region->name(), region->n_channels());
216 row[region_list_columns.name] = region->name();
221 Editor::region_list_selection_changed()
225 if (region_list_display.get_selection()->count_selected_rows() > 0) {
232 TreeView::Selection::ListHandle_Path rows = region_list_display.get_selection()->get_selected_rows ();
233 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
236 if ((iter = region_list_model->get_iter (*i))) {
237 boost::shared_ptr<Region> r = (*iter)[region_list_columns.region];
239 /* they could have clicked on a row that is just a placeholder, like "Hidden" */
243 /* just set the first selected region (in fact, the selection model might be SINGLE, which
244 means there can only be one.
247 set_selected_regionview_from_region_list (r, Selection::Set);
254 Editor::insert_into_tmp_regionlist(boost::shared_ptr<Region> region)
256 /* keep all whole files at the beginning */
258 if (region->whole_file()) {
259 tmp_region_list.push_front (region);
261 tmp_region_list.push_back (region);
266 Editor::redisplay_regions ()
270 region_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
271 region_list_model->clear ();
273 /* now add everything we have, via a temporary list used to help with
277 tmp_region_list.clear();
278 session->foreach_region (this, &Editor::insert_into_tmp_regionlist);
280 for (list<boost::shared_ptr<Region> >::iterator r = tmp_region_list.begin(); r != tmp_region_list.end(); ++r) {
281 add_region_to_region_display (*r);
283 tmp_region_list.clear();
285 region_list_display.set_model (region_list_model);
290 Editor::build_region_list_menu ()
292 region_list_menu = dynamic_cast<Menu*>(ActionManager::get_widget ("/RegionListMenu"));
294 /* now grab specific menu items that we need */
296 Glib::RefPtr<Action> act;
298 act = ActionManager::get_action (X_("RegionList"), X_("rlShowAll"));
300 toggle_full_region_list_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
303 act = ActionManager::get_action (X_("RegionList"), X_("rlShowAuto"));
305 toggle_show_auto_regions_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
310 Editor::toggle_show_auto_regions ()
312 show_automatic_regions_in_region_list = toggle_show_auto_regions_action->get_active();
313 redisplay_regions ();
317 Editor::toggle_full_region_list ()
319 if (toggle_full_region_list_action->get_active()) {
320 region_list_display.expand_all ();
322 region_list_display.collapse_all ();
327 Editor::show_region_list_display_context_menu (int button, int time)
329 if (region_list_menu == 0) {
330 build_region_list_menu ();
333 if (region_list_display.get_selection()->count_selected_rows() > 0) {
334 ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions, true);
336 ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions, false);
339 region_list_menu->popup (button, time);
343 Editor::region_list_display_key_press (GdkEventKey* ev)
349 Editor::region_list_display_key_release (GdkEventKey* ev)
351 switch (ev->keyval) {
353 remove_region_from_region_list ();
364 Editor::region_list_display_button_press (GdkEventButton *ev)
366 boost::shared_ptr<Region> region;
368 TreeModel::Path path;
369 TreeViewColumn* column;
373 if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
374 if ((iter = region_list_model->get_iter (path))) {
375 region = (*iter)[region_list_columns.region];
379 if (Keyboard::is_context_menu_event (ev)) {
380 show_region_list_display_context_menu (ev->button, ev->time);
388 switch (ev->button) {
390 /* audition on double click */
391 if (ev->type == GDK_2BUTTON_PRESS) {
392 consider_auditioning (region);
399 if (!Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
400 consider_auditioning (region);
413 Editor::region_list_display_button_release (GdkEventButton *ev)
416 TreeModel::Path path;
417 TreeViewColumn* column;
420 boost::shared_ptr<Region> region;
422 if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
423 if ((iter = region_list_model->get_iter (path))) {
424 region = (*iter)[region_list_columns.region];
428 if (region && Keyboard::is_delete_event (ev)) {
429 session->remove_region_from_region_list (region);
437 Editor::consider_auditioning (boost::shared_ptr<Region> region)
439 boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion> (region);
442 session->cancel_audition ();
446 if (session->is_auditioning()) {
447 session->cancel_audition ();
448 if (r == last_audition_region) {
453 session->audition_region (r);
454 last_audition_region = r;
458 Editor::region_list_sorter (TreeModel::iterator a, TreeModel::iterator b)
462 boost::shared_ptr<Region> r1 = (*a)[region_list_columns.region];
463 boost::shared_ptr<Region> r2 = (*b)[region_list_columns.region];
465 /* handle rows without regions, like "Hidden" */
475 boost::shared_ptr<AudioRegion> region1 = boost::dynamic_pointer_cast<AudioRegion> (r1);
476 boost::shared_ptr<AudioRegion> region2 = boost::dynamic_pointer_cast<AudioRegion> (r2);
478 if (region1 == 0 || region2 == 0) {
481 switch (region_list_sort_type) {
483 s1 = (*a)[region_list_columns.name];
484 s2 = (*b)[region_list_columns.name];
485 return (s1.compare (s2));
491 switch (region_list_sort_type) {
493 cmp = strcasecmp (region1->name().c_str(), region2->name().c_str());
497 cmp = region1->length() - region2->length();
501 cmp = region1->position() - region2->position();
505 cmp = region1->source()->timestamp() - region2->source()->timestamp();
509 cmp = region1->start() - region2->start();
513 cmp = (region1->start() + region1->length()) - (region2->start() + region2->length());
516 case BySourceFileName:
517 cmp = strcasecmp (region1->source()->name().c_str(), region2->source()->name().c_str());
520 case BySourceFileLength:
521 cmp = region1->source()->length() - region2->source()->length();
524 case BySourceFileCreationDate:
525 cmp = region1->source()->timestamp() - region2->source()->timestamp();
529 if (region1->source()->name() == region2->source()->name()) {
530 cmp = strcasecmp (region1->name().c_str(), region2->name().c_str());
532 cmp = strcasecmp (region1->source()->name().c_str(), region2->source()->name().c_str());
539 } else if (cmp > 0) {
547 Editor::reset_region_list_sort_type (RegionListSortType type)
549 if (type != region_list_sort_type) {
550 region_list_sort_type = type;
551 region_list_model->set_sort_func (0, (mem_fun (*this, &Editor::region_list_sorter)));
556 Editor::reset_region_list_sort_direction (bool up)
558 region_list_model->set_sort_column (0, up ? SORT_ASCENDING : SORT_DESCENDING);
562 Editor::region_list_selection_mapover (slot<void,boost::shared_ptr<Region> > sl)
564 Glib::RefPtr<TreeSelection> selection = region_list_display.get_selection();
565 TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
566 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
568 if (selection->count_selected_rows() == 0 || session == 0) {
572 for (; i != rows.end(); ++i) {
575 if ((iter = region_list_model->get_iter (*i))) {
577 /* some rows don't have a region associated with them, but can still be
578 selected (XXX maybe prevent them from being selected)
581 boost::shared_ptr<Region> r = (*iter)[region_list_columns.region];
591 Editor::hide_a_region (boost::shared_ptr<Region> r)
593 r->set_hidden (true);
597 Editor::remove_a_region (boost::shared_ptr<Region> r)
599 session->remove_region_from_region_list (r);
603 Editor::audition_region_from_region_list ()
605 region_list_selection_mapover (mem_fun (*this, &Editor::consider_auditioning));
609 Editor::hide_region_from_region_list ()
611 region_list_selection_mapover (mem_fun (*this, &Editor::hide_a_region));
615 Editor::remove_region_from_region_list ()
617 region_list_selection_mapover (mem_fun (*this, &Editor::remove_a_region));
621 Editor::region_list_display_drag_data_received (const RefPtr<Gdk::DragContext>& context,
623 const SelectionData& data,
624 guint info, guint time)
626 vector<ustring> paths;
628 if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
630 do_embed (paths, false, ImportAsRegion, 0, pos, true);
631 context->drag_finish (true, false, time);
636 Editor::region_list_selection_filter (const RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
638 /* not possible to select rows that do not represent regions, like "Hidden" */
640 TreeModel::iterator iter = model->get_iter (path);
643 boost::shared_ptr<Region> r =(*iter)[region_list_columns.region];