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/audiosource.h>
30 #include <ardour/session_region.h>
32 #include <gtkmm2ext/stop_signal.h>
36 #include "ardour_ui.h"
37 #include "gui_thread.h"
44 using namespace ARDOUR;
48 using namespace Editing;
51 Editor::handle_audio_region_removed (boost::weak_ptr<AudioRegion> wregion)
53 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::handle_audio_region_removed), wregion));
58 Editor::handle_new_audio_region (boost::weak_ptr<AudioRegion> wregion)
60 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::handle_new_audio_region), wregion));
62 /* don't copy region - the one we are being notified
63 about belongs to the session, and so it will
67 boost::shared_ptr<AudioRegion> region (wregion.lock());
70 add_audio_region_to_region_display (region);
75 Editor::region_hidden (boost::shared_ptr<Region> r)
77 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::region_hidden), r));
83 Editor::add_audio_region_to_region_display (boost::shared_ptr<AudioRegion> region)
89 if (!show_automatic_regions_in_region_list && region->automatic()) {
93 if (region->hidden()) {
95 TreeModel::iterator iter = region_list_model->get_iter ("0");
96 TreeModel::Row parent;
99 if (iter == region_list_model->children().end()) {
101 parent = *(region_list_model->append());
103 parent[region_list_columns.name] = _("Hidden");
104 /// XXX FIX ME parent[region_list_columns.region]->reset ();
108 if ((*iter)[region_list_columns.name] != _("Hidden")) {
110 parent = *(region_list_model->insert(iter));
111 parent[region_list_columns.name] = _("Hidden");
112 /// XXX FIX ME parent[region_list_columns.region]->reset ();
120 row = *(region_list_model->append (parent.children()));
122 } else if (region->whole_file()) {
124 row = *(region_list_model->append());
125 set_color(c, rgba_from_style ("RegionListWholeFile", 0xff, 0, 0, 0, "fg", Gtk::STATE_NORMAL, false ));
126 row[region_list_columns.color_] = c;
128 if (region->source()->name()[0] == '/') { // external file
130 if (region->whole_file()) {
132 str += PBD::basename_nosuffix (region->source()->name());
135 str = region->name();
140 str = region->name();
144 row[region_list_columns.name] = str;
145 row[region_list_columns.region] = region;
151 /* find parent node, add as new child */
153 TreeModel::iterator i;
154 TreeModel::Children rows = region_list_model->children();
155 bool found_parent = false;
157 for (i = rows.begin(); i != rows.end(); ++i) {
159 boost::shared_ptr<Region> rr = (*i)[region_list_columns.region];
160 boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion>(rr);
162 if (r && r->whole_file()) {
163 if (region->source_equivalent (r)) {
164 row = *(region_list_model->append ((*i).children()));
172 row = *(region_list_model->append());
178 row[region_list_columns.region] = region;
180 if (region->n_channels() > 1) {
181 row[region_list_columns.name] = string_compose("%1 [%2]", region->name(), region->n_channels());
183 row[region_list_columns.name] = region->name();
188 Editor::region_list_selection_changed()
192 if (region_list_display.get_selection()->count_selected_rows() > 0) {
199 TreeView::Selection::ListHandle_Path rows = region_list_display.get_selection()->get_selected_rows ();
200 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
203 /* just set the first selected region (in fact, the selection model might be SINGLE, which
204 means there can only be one.
207 if ((iter = region_list_model->get_iter (*i))) {
208 set_selected_regionview_from_region_list (((*iter)[region_list_columns.region]), Selection::Set);
214 Editor::insert_into_tmp_audio_regionlist(boost::shared_ptr<AudioRegion> region)
216 /* keep all whole files at the beginning */
218 if (region->whole_file()) {
219 tmp_audio_region_list.push_front (region);
221 tmp_audio_region_list.push_back (region);
226 Editor::redisplay_regions ()
230 region_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
231 region_list_model->clear ();
233 /* now add everything we have, via a temporary list used to help with
237 tmp_audio_region_list.clear();
238 session->foreach_audio_region (this, &Editor::insert_into_tmp_audio_regionlist);
240 for (list<boost::shared_ptr<AudioRegion> >::iterator r = tmp_audio_region_list.begin(); r != tmp_audio_region_list.end(); ++r) {
241 add_audio_region_to_region_display (*r);
243 tmp_audio_region_list.clear();
245 region_list_display.set_model (region_list_model);
250 Editor::region_list_clear ()
252 region_list_model->clear();
256 Editor::build_region_list_menu ()
258 region_list_menu = dynamic_cast<Menu*>(ActionManager::get_widget ("/RegionListMenu"));
260 /* now grab specific menu items that we need */
262 Glib::RefPtr<Action> act;
264 act = ActionManager::get_action (X_("RegionList"), X_("rlShowAll"));
266 toggle_full_region_list_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
269 act = ActionManager::get_action (X_("RegionList"), X_("rlShowAuto"));
271 toggle_show_auto_regions_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
276 Editor::toggle_show_auto_regions ()
278 show_automatic_regions_in_region_list = toggle_show_auto_regions_action->get_active();
279 redisplay_regions ();
283 Editor::toggle_full_region_list ()
285 if (toggle_full_region_list_action->get_active()) {
286 region_list_display.expand_all ();
288 region_list_display.collapse_all ();
293 Editor::show_region_list_display_context_menu (int button, int time)
295 if (region_list_menu == 0) {
296 build_region_list_menu ();
299 if (region_list_display.get_selection()->count_selected_rows() > 0) {
300 ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions, true);
302 ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions, false);
305 region_list_menu->popup (button, time);
309 Editor::region_list_display_key_press (GdkEventKey* ev)
315 Editor::region_list_display_key_release (GdkEventKey* ev)
317 switch (ev->keyval) {
319 remove_region_from_region_list ();
330 Editor::region_list_display_button_press (GdkEventButton *ev)
332 boost::shared_ptr<Region> region;
334 TreeModel::Path path;
335 TreeViewColumn* column;
339 if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
340 if ((iter = region_list_model->get_iter (path))) {
341 region = (*iter)[region_list_columns.region];
349 if (Keyboard::is_delete_event (ev)) {
350 session->remove_region_from_region_list (region);
354 if (Keyboard::is_context_menu_event (ev)) {
355 show_region_list_display_context_menu (ev->button, ev->time);
359 switch (ev->button) {
361 /* audition on double click */
362 if (ev->type == GDK_2BUTTON_PRESS) {
363 consider_auditioning (region);
370 if (!Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
371 consider_auditioning (region);
384 Editor::region_list_display_button_release (GdkEventButton *ev)
387 TreeModel::Path path;
388 TreeViewColumn* column;
391 boost::shared_ptr<Region> region;
393 if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
394 if ((iter = region_list_model->get_iter (path))) {
395 region = (*iter)[region_list_columns.region];
399 if (region && Keyboard::is_delete_event (ev)) {
400 session->remove_region_from_region_list (region);
408 Editor::consider_auditioning (boost::shared_ptr<Region> region)
410 boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion> (region);
413 session->cancel_audition ();
417 if (session->is_auditioning()) {
418 session->cancel_audition ();
419 if (r == last_audition_region) {
424 session->audition_region (r);
425 last_audition_region = r;
429 Editor::region_list_sorter (TreeModel::iterator a, TreeModel::iterator b)
433 boost::shared_ptr<Region> r1 = (*a)[region_list_columns.region];
434 boost::shared_ptr<Region> r2 = (*b)[region_list_columns.region];
436 /* handle rows without regions, like "Hidden" */
446 boost::shared_ptr<AudioRegion> region1 = boost::dynamic_pointer_cast<AudioRegion> (r1);
447 boost::shared_ptr<AudioRegion> region2 = boost::dynamic_pointer_cast<AudioRegion> (r2);
449 if (region1 == 0 || region2 == 0) {
452 switch (region_list_sort_type) {
454 s1 = (*a)[region_list_columns.name];
455 s2 = (*b)[region_list_columns.name];
456 return (s1.compare (s2));
462 switch (region_list_sort_type) {
464 cmp = strcasecmp (region1->name().c_str(), region2->name().c_str());
468 cmp = region1->length() - region2->length();
472 cmp = region1->position() - region2->position();
476 cmp = region1->source()->timestamp() - region2->source()->timestamp();
480 cmp = region1->start() - region2->start();
484 cmp = (region1->start() + region1->length()) - (region2->start() + region2->length());
487 case BySourceFileName:
488 cmp = strcasecmp (region1->source()->name().c_str(), region2->source()->name().c_str());
491 case BySourceFileLength:
492 cmp = region1->source()->length() - region2->source()->length();
495 case BySourceFileCreationDate:
496 cmp = region1->source()->timestamp() - region2->source()->timestamp();
500 if (region1->source()->name() == region2->source()->name()) {
501 cmp = strcasecmp (region1->name().c_str(), region2->name().c_str());
503 cmp = strcasecmp (region1->source()->name().c_str(), region2->source()->name().c_str());
510 } else if (cmp > 0) {
518 Editor::reset_region_list_sort_type (RegionListSortType type)
520 if (type != region_list_sort_type) {
521 region_list_sort_type = type;
522 region_list_model->set_sort_func (0, (mem_fun (*this, &Editor::region_list_sorter)));
527 Editor::reset_region_list_sort_direction (bool up)
529 region_list_model->set_sort_column (0, up ? SORT_ASCENDING : SORT_DESCENDING);
533 Editor::region_list_selection_mapover (slot<void,boost::shared_ptr<Region> > sl)
535 Glib::RefPtr<TreeSelection> selection = region_list_display.get_selection();
536 TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
537 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
539 if (selection->count_selected_rows() == 0 || session == 0) {
543 for (; i != rows.end(); ++i) {
546 if ((iter = region_list_model->get_iter (*i))) {
547 sl (((*iter)[region_list_columns.region]));
553 Editor::hide_a_region (boost::shared_ptr<Region> r)
555 r->set_hidden (true);
559 Editor::remove_a_region (boost::shared_ptr<Region> r)
561 session->remove_region_from_region_list (r);
565 Editor::audition_region_from_region_list ()
567 region_list_selection_mapover (mem_fun (*this, &Editor::consider_auditioning));
571 Editor::hide_region_from_region_list ()
573 region_list_selection_mapover (mem_fun (*this, &Editor::hide_a_region));
577 Editor::remove_region_from_region_list ()
579 region_list_selection_mapover (mem_fun (*this, &Editor::remove_a_region));
583 Editor::region_list_display_drag_data_received (const RefPtr<Gdk::DragContext>& context,
585 const SelectionData& data,
586 guint info, guint time)
588 vector<ustring> paths;
590 if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
592 do_embed (paths, false, ImportAsRegion, 0, pos, true);
593 context->drag_finish (true, false, time);
598 Editor::region_list_selection_filter (const RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
600 /* not possible to select rows that do not represent regions, like "Hidden" */
602 /// XXXX FIXME boost::shared_ptr<Region> r = ((model->get_iter (path)))[region_list_columns.region];