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;
47 using namespace Editing;
50 Editor::handle_audio_region_removed (AudioRegion* region)
52 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::handle_audio_region_removed), region));
57 Editor::handle_new_audio_region (AudioRegion *region)
59 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::handle_new_audio_region), region));
61 /* don't copy region - the one we are being notified
62 about belongs to the session, and so it will
65 add_audio_region_to_region_display (region);
69 Editor::region_hidden (Region* r)
71 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::region_hidden), r));
77 Editor::add_audio_region_to_region_display (AudioRegion *region)
83 if (!show_automatic_regions_in_region_list && region->automatic()) {
87 if (region->hidden()) {
89 TreeModel::iterator iter = region_list_model->get_iter ("0");
90 TreeModel::Row parent;
93 if (iter == region_list_model->children().end()) {
95 parent = *(region_list_model->append());
97 parent[region_list_columns.name] = _("Hidden");
98 parent[region_list_columns.region] = 0;
102 if ((*iter)[region_list_columns.name] != _("Hidden")) {
104 parent = *(region_list_model->insert(iter));
105 parent[region_list_columns.name] = _("Hidden");
106 parent[region_list_columns.region] = 0;
114 row = *(region_list_model->append (parent.children()));
116 } else if (region->whole_file()) {
118 row = *(region_list_model->append());
119 set_color(c, rgba_from_style ("RegionListWholeFile", 0xff, 0, 0, 0, "fg", Gtk::STATE_NORMAL, false ));
120 row[region_list_columns.color_] = c;
122 if (region->source().name()[0] == '/') { // external file
124 if (region->whole_file()) {
126 str += PBD::basename_nosuffix (region->source().name());
129 str = region->name();
134 str = region->name();
138 row[region_list_columns.name] = str;
139 row[region_list_columns.region] = region;
145 /* find parent node, add as new child */
147 TreeModel::iterator i;
148 TreeModel::Children rows = region_list_model->children();
149 bool found_parent = false;
151 for (i = rows.begin(); i != rows.end(); ++i) {
153 Region* rr = (*i)[region_list_columns.region];
154 AudioRegion* r = dynamic_cast<AudioRegion*>(rr);
156 if (r && r->whole_file()) {
157 if (region->source_equivalent (*r)) {
158 row = *(region_list_model->append ((*i).children()));
166 row = *(region_list_model->append());
172 row[region_list_columns.region] = region;
174 if (region->n_channels() > 1) {
175 row[region_list_columns.name] = string_compose("%1 [%2]", region->name(), region->n_channels());
177 row[region_list_columns.name] = region->name();
182 Editor::region_list_selection_changed()
186 if (region_list_display.get_selection()->count_selected_rows() > 0) {
193 TreeView::Selection::ListHandle_Path rows = region_list_display.get_selection()->get_selected_rows ();
194 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
197 /* just set the first selected region (in fact, the selection model might be SINGLE, which
198 means there can only be one.
201 if ((iter = region_list_model->get_iter (*i))) {
202 set_selected_regionview_from_region_list (*((*iter)[region_list_columns.region]), Selection::Set);
208 Editor::insert_into_tmp_audio_regionlist(AudioRegion* region)
210 /* keep all whole files at the beginning */
212 if (region->whole_file()) {
213 tmp_audio_region_list.push_front (region);
215 tmp_audio_region_list.push_back (region);
220 Editor::redisplay_regions ()
224 region_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
225 region_list_model->clear ();
227 /* now add everything we have, via a temporary list used to help with
231 tmp_audio_region_list.clear();
232 session->foreach_audio_region (this, &Editor::insert_into_tmp_audio_regionlist);
234 for (list<AudioRegion*>::iterator r = tmp_audio_region_list.begin(); r != tmp_audio_region_list.end(); ++r) {
235 add_audio_region_to_region_display (*r);
238 region_list_display.set_model (region_list_model);
243 Editor::region_list_clear ()
245 region_list_model->clear();
249 Editor::build_region_list_menu ()
251 region_list_menu = dynamic_cast<Menu*>(ActionManager::get_widget ("/RegionListMenu"));
253 /* now grab specific menu items that we need */
255 Glib::RefPtr<Action> act;
257 act = ActionManager::get_action (X_("RegionList"), X_("rlShowAll"));
259 toggle_full_region_list_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
262 act = ActionManager::get_action (X_("RegionList"), X_("rlShowAuto"));
264 toggle_show_auto_regions_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
269 Editor::toggle_show_auto_regions ()
271 show_automatic_regions_in_region_list = toggle_show_auto_regions_action->get_active();
272 redisplay_regions ();
276 Editor::toggle_full_region_list ()
278 if (toggle_full_region_list_action->get_active()) {
279 region_list_display.expand_all ();
281 region_list_display.collapse_all ();
286 Editor::show_region_list_display_context_menu (int button, int time)
288 if (region_list_menu == 0) {
289 build_region_list_menu ();
292 if (region_list_display.get_selection()->count_selected_rows() > 0) {
293 ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions, true);
295 ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions, false);
298 region_list_menu->popup (button, time);
302 Editor::region_list_display_key_press (GdkEventKey* ev)
308 Editor::region_list_display_key_release (GdkEventKey* ev)
310 switch (ev->keyval) {
312 remove_region_from_region_list ();
323 Editor::region_list_display_button_press (GdkEventButton *ev)
327 TreeModel::Path path;
328 TreeViewColumn* column;
332 if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
333 if ((iter = region_list_model->get_iter (path))) {
334 region = (*iter)[region_list_columns.region];
342 if (Keyboard::is_delete_event (ev)) {
343 session->remove_region_from_region_list (*region);
347 if (Keyboard::is_context_menu_event (ev)) {
348 show_region_list_display_context_menu (ev->button, ev->time);
352 switch (ev->button) {
354 /* audition on double click */
355 if (ev->type == GDK_2BUTTON_PRESS) {
356 consider_auditioning (*region);
363 if (!Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
364 consider_auditioning (*region);
377 Editor::region_list_display_button_release (GdkEventButton *ev)
380 TreeModel::Path path;
381 TreeViewColumn* column;
386 if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
387 if ((iter = region_list_model->get_iter (path))) {
388 region = (*iter)[region_list_columns.region];
392 if (region && Keyboard::is_delete_event (ev)) {
393 session->remove_region_from_region_list (*region);
401 Editor::consider_auditioning (Region& region)
403 AudioRegion* r = dynamic_cast<AudioRegion*> (®ion);
406 session->cancel_audition ();
410 if (session->is_auditioning()) {
411 session->cancel_audition ();
412 if (r == last_audition_region) {
417 session->audition_region (*r);
418 last_audition_region = r;
422 Editor::region_list_sorter (TreeModel::iterator a, TreeModel::iterator b)
426 Region* r1 = (*a)[region_list_columns.region];
427 Region* r2 = (*b)[region_list_columns.region];
429 /* handle rows without regions, like "Hidden" */
439 AudioRegion* region1 = dynamic_cast<AudioRegion*> (r1);
440 AudioRegion* region2 = dynamic_cast<AudioRegion*> (r2);
442 if (region1 == 0 || region2 == 0) {
445 switch (region_list_sort_type) {
447 s1 = (*a)[region_list_columns.name];
448 s2 = (*b)[region_list_columns.name];
449 return (s1.compare (s2));
455 switch (region_list_sort_type) {
457 cmp = strcasecmp (region1->name().c_str(), region2->name().c_str());
461 cmp = region1->length() - region2->length();
465 cmp = region1->position() - region2->position();
469 cmp = region1->source().timestamp() - region2->source().timestamp();
473 cmp = region1->start() - region2->start();
477 cmp = (region1->start() + region1->length()) - (region2->start() + region2->length());
480 case BySourceFileName:
481 cmp = strcasecmp (region1->source().name().c_str(), region2->source().name().c_str());
484 case BySourceFileLength:
485 cmp = region1->source().length() - region2->source().length();
488 case BySourceFileCreationDate:
489 cmp = region1->source().timestamp() - region2->source().timestamp();
493 if (region1->source().name() == region2->source().name()) {
494 cmp = strcasecmp (region1->name().c_str(), region2->name().c_str());
496 cmp = strcasecmp (region1->source().name().c_str(), region2->source().name().c_str());
503 } else if (cmp > 0) {
511 Editor::reset_region_list_sort_type (RegionListSortType type)
513 if (type != region_list_sort_type) {
514 region_list_sort_type = type;
515 region_list_model->set_sort_func (0, (mem_fun (*this, &Editor::region_list_sorter)));
520 Editor::reset_region_list_sort_direction (bool up)
522 region_list_model->set_sort_column (0, up ? SORT_ASCENDING : SORT_DESCENDING);
526 Editor::region_list_selection_mapover (slot<void,Region&> sl)
528 Glib::RefPtr<TreeSelection> selection = region_list_display.get_selection();
529 TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
530 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
532 if (selection->count_selected_rows() == 0 || session == 0) {
536 for (; i != rows.end(); ++i) {
539 if ((iter = region_list_model->get_iter (*i))) {
540 sl (*((*iter)[region_list_columns.region]));
546 Editor::hide_a_region (Region& r)
552 Editor::remove_a_region (Region& r)
554 session->remove_region_from_region_list (r);
558 Editor::audition_region_from_region_list ()
560 region_list_selection_mapover (mem_fun (*this, &Editor::consider_auditioning));
564 Editor::hide_region_from_region_list ()
566 region_list_selection_mapover (mem_fun (*this, &Editor::hide_a_region));
570 Editor::remove_region_from_region_list ()
572 region_list_selection_mapover (mem_fun (*this, &Editor::remove_a_region));
576 Editor::region_list_display_drag_data_received (const RefPtr<Gdk::DragContext>& context,
578 const SelectionData& data,
579 guint info, guint time)
581 vector<ustring> paths;
583 if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
584 jack_nframes_t pos = 0;
585 do_embed (paths, false, ImportAsRegion, 0, pos, true);
586 context->drag_finish (true, false, time);
591 Editor::region_list_selection_filter (const RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
593 /* not possible to select rows that do not represent regions, like "Hidden" */
595 return (*(model->get_iter (path)))[region_list_columns.region] != 0;