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::shared_ptr<AudioRegion> region)
53 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::handle_audio_region_removed), region));
58 Editor::handle_new_audio_region (boost::shared_ptr<AudioRegion> region)
60 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::handle_new_audio_region), region));
62 /* don't copy region - the one we are being notified
63 about belongs to the session, and so it will
66 add_audio_region_to_region_display (region);
70 Editor::region_hidden (boost::shared_ptr<Region> r)
72 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::region_hidden), r));
78 Editor::add_audio_region_to_region_display (boost::shared_ptr<AudioRegion> region)
84 if (!show_automatic_regions_in_region_list && region->automatic()) {
88 if (region->hidden()) {
90 TreeModel::iterator iter = region_list_model->get_iter ("0");
91 TreeModel::Row parent;
94 if (iter == region_list_model->children().end()) {
96 parent = *(region_list_model->append());
98 parent[region_list_columns.name] = _("Hidden");
99 /// XXX FIX ME parent[region_list_columns.region]->reset ();
103 if ((*iter)[region_list_columns.name] != _("Hidden")) {
105 parent = *(region_list_model->insert(iter));
106 parent[region_list_columns.name] = _("Hidden");
107 /// XXX FIX ME parent[region_list_columns.region]->reset ();
115 row = *(region_list_model->append (parent.children()));
117 } else if (region->whole_file()) {
119 row = *(region_list_model->append());
120 set_color(c, rgba_from_style ("RegionListWholeFile", 0xff, 0, 0, 0, "fg", Gtk::STATE_NORMAL, false ));
121 row[region_list_columns.color_] = c;
123 if (region->source()->name()[0] == '/') { // external file
125 if (region->whole_file()) {
127 str += PBD::basename_nosuffix (region->source()->name());
130 str = region->name();
135 str = region->name();
139 row[region_list_columns.name] = str;
140 row[region_list_columns.region] = region;
146 /* find parent node, add as new child */
148 TreeModel::iterator i;
149 TreeModel::Children rows = region_list_model->children();
150 bool found_parent = false;
152 for (i = rows.begin(); i != rows.end(); ++i) {
154 boost::shared_ptr<Region> rr = (*i)[region_list_columns.region];
155 boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion>(rr);
157 if (r && r->whole_file()) {
158 if (region->source_equivalent (r)) {
159 row = *(region_list_model->append ((*i).children()));
167 row = *(region_list_model->append());
173 row[region_list_columns.region] = region;
175 if (region->n_channels() > 1) {
176 row[region_list_columns.name] = string_compose("%1 [%2]", region->name(), region->n_channels());
178 row[region_list_columns.name] = region->name();
183 Editor::region_list_selection_changed()
187 if (region_list_display.get_selection()->count_selected_rows() > 0) {
194 TreeView::Selection::ListHandle_Path rows = region_list_display.get_selection()->get_selected_rows ();
195 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
198 /* just set the first selected region (in fact, the selection model might be SINGLE, which
199 means there can only be one.
202 if ((iter = region_list_model->get_iter (*i))) {
203 set_selected_regionview_from_region_list (((*iter)[region_list_columns.region]), Selection::Set);
209 Editor::insert_into_tmp_audio_regionlist(boost::shared_ptr<AudioRegion> region)
211 /* keep all whole files at the beginning */
213 if (region->whole_file()) {
214 tmp_audio_region_list.push_front (region);
216 tmp_audio_region_list.push_back (region);
221 Editor::redisplay_regions ()
225 region_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
226 region_list_model->clear ();
228 /* now add everything we have, via a temporary list used to help with
232 tmp_audio_region_list.clear();
233 session->foreach_audio_region (this, &Editor::insert_into_tmp_audio_regionlist);
235 for (list<boost::shared_ptr<AudioRegion> >::iterator r = tmp_audio_region_list.begin(); r != tmp_audio_region_list.end(); ++r) {
236 add_audio_region_to_region_display (*r);
238 tmp_audio_region_list.clear();
240 region_list_display.set_model (region_list_model);
245 Editor::region_list_clear ()
247 region_list_model->clear();
251 Editor::build_region_list_menu ()
253 region_list_menu = dynamic_cast<Menu*>(ActionManager::get_widget ("/RegionListMenu"));
255 /* now grab specific menu items that we need */
257 Glib::RefPtr<Action> act;
259 act = ActionManager::get_action (X_("RegionList"), X_("rlShowAll"));
261 toggle_full_region_list_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
264 act = ActionManager::get_action (X_("RegionList"), X_("rlShowAuto"));
266 toggle_show_auto_regions_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
271 Editor::toggle_show_auto_regions ()
273 show_automatic_regions_in_region_list = toggle_show_auto_regions_action->get_active();
274 redisplay_regions ();
278 Editor::toggle_full_region_list ()
280 if (toggle_full_region_list_action->get_active()) {
281 region_list_display.expand_all ();
283 region_list_display.collapse_all ();
288 Editor::show_region_list_display_context_menu (int button, int time)
290 if (region_list_menu == 0) {
291 build_region_list_menu ();
294 if (region_list_display.get_selection()->count_selected_rows() > 0) {
295 ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions, true);
297 ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions, false);
300 region_list_menu->popup (button, time);
304 Editor::region_list_display_key_press (GdkEventKey* ev)
310 Editor::region_list_display_key_release (GdkEventKey* ev)
312 switch (ev->keyval) {
314 remove_region_from_region_list ();
325 Editor::region_list_display_button_press (GdkEventButton *ev)
327 boost::shared_ptr<Region> region;
329 TreeModel::Path path;
330 TreeViewColumn* column;
334 if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
335 if ((iter = region_list_model->get_iter (path))) {
336 region = (*iter)[region_list_columns.region];
344 if (Keyboard::is_delete_event (ev)) {
345 session->remove_region_from_region_list (region);
349 if (Keyboard::is_context_menu_event (ev)) {
350 show_region_list_display_context_menu (ev->button, ev->time);
354 switch (ev->button) {
356 /* audition on double click */
357 if (ev->type == GDK_2BUTTON_PRESS) {
358 consider_auditioning (region);
365 if (!Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
366 consider_auditioning (region);
379 Editor::region_list_display_button_release (GdkEventButton *ev)
382 TreeModel::Path path;
383 TreeViewColumn* column;
386 boost::shared_ptr<Region> region;
388 if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
389 if ((iter = region_list_model->get_iter (path))) {
390 region = (*iter)[region_list_columns.region];
394 if (region && Keyboard::is_delete_event (ev)) {
395 session->remove_region_from_region_list (region);
403 Editor::consider_auditioning (boost::shared_ptr<Region> region)
405 boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion> (region);
408 session->cancel_audition ();
412 if (session->is_auditioning()) {
413 session->cancel_audition ();
414 if (r == last_audition_region) {
419 session->audition_region (r);
420 last_audition_region = r;
424 Editor::region_list_sorter (TreeModel::iterator a, TreeModel::iterator b)
428 boost::shared_ptr<Region> r1 = (*a)[region_list_columns.region];
429 boost::shared_ptr<Region> r2 = (*b)[region_list_columns.region];
431 /* handle rows without regions, like "Hidden" */
441 boost::shared_ptr<AudioRegion> region1 = boost::dynamic_pointer_cast<AudioRegion> (r1);
442 boost::shared_ptr<AudioRegion> region2 = boost::dynamic_pointer_cast<AudioRegion> (r2);
444 if (region1 == 0 || region2 == 0) {
447 switch (region_list_sort_type) {
449 s1 = (*a)[region_list_columns.name];
450 s2 = (*b)[region_list_columns.name];
451 return (s1.compare (s2));
457 switch (region_list_sort_type) {
459 cmp = strcasecmp (region1->name().c_str(), region2->name().c_str());
463 cmp = region1->length() - region2->length();
467 cmp = region1->position() - region2->position();
471 cmp = region1->source()->timestamp() - region2->source()->timestamp();
475 cmp = region1->start() - region2->start();
479 cmp = (region1->start() + region1->length()) - (region2->start() + region2->length());
482 case BySourceFileName:
483 cmp = strcasecmp (region1->source()->name().c_str(), region2->source()->name().c_str());
486 case BySourceFileLength:
487 cmp = region1->source()->length() - region2->source()->length();
490 case BySourceFileCreationDate:
491 cmp = region1->source()->timestamp() - region2->source()->timestamp();
495 if (region1->source()->name() == region2->source()->name()) {
496 cmp = strcasecmp (region1->name().c_str(), region2->name().c_str());
498 cmp = strcasecmp (region1->source()->name().c_str(), region2->source()->name().c_str());
505 } else if (cmp > 0) {
513 Editor::reset_region_list_sort_type (RegionListSortType type)
515 if (type != region_list_sort_type) {
516 region_list_sort_type = type;
517 region_list_model->set_sort_func (0, (mem_fun (*this, &Editor::region_list_sorter)));
522 Editor::reset_region_list_sort_direction (bool up)
524 region_list_model->set_sort_column (0, up ? SORT_ASCENDING : SORT_DESCENDING);
528 Editor::region_list_selection_mapover (slot<void,boost::shared_ptr<Region> > sl)
530 Glib::RefPtr<TreeSelection> selection = region_list_display.get_selection();
531 TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
532 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
534 if (selection->count_selected_rows() == 0 || session == 0) {
538 for (; i != rows.end(); ++i) {
541 if ((iter = region_list_model->get_iter (*i))) {
542 sl (((*iter)[region_list_columns.region]));
548 Editor::hide_a_region (boost::shared_ptr<Region> r)
550 r->set_hidden (true);
554 Editor::remove_a_region (boost::shared_ptr<Region> r)
556 session->remove_region_from_region_list (r);
560 Editor::audition_region_from_region_list ()
562 region_list_selection_mapover (mem_fun (*this, &Editor::consider_auditioning));
566 Editor::hide_region_from_region_list ()
568 region_list_selection_mapover (mem_fun (*this, &Editor::hide_a_region));
572 Editor::remove_region_from_region_list ()
574 region_list_selection_mapover (mem_fun (*this, &Editor::remove_a_region));
578 Editor::region_list_display_drag_data_received (const RefPtr<Gdk::DragContext>& context,
580 const SelectionData& data,
581 guint info, guint time)
583 vector<ustring> paths;
585 if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
587 do_embed (paths, false, ImportAsRegion, 0, pos, true);
588 context->drag_finish (true, false, time);
593 Editor::region_list_selection_filter (const RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
595 /* not possible to select rows that do not represent regions, like "Hidden" */
597 /// XXXX FIXME boost::shared_ptr<Region> r = ((model->get_iter (path)))[region_list_columns.region];