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* region)
51 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::handle_audio_region_removed), region));
56 Editor::handle_new_audio_region (AudioRegion *region)
58 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::handle_new_audio_region), region));
60 /* don't copy region - the one we are being notified
61 about belongs to the session, and so it will
64 add_audio_region_to_region_display (region);
68 Editor::region_hidden (Region* r)
70 ENSURE_GUI_THREAD(bind (mem_fun(*this, &Editor::region_hidden), r));
76 Editor::add_audio_region_to_region_display (AudioRegion *region)
82 if (!show_automatic_regions_in_region_list && region->automatic()) {
86 if (region->hidden()) {
88 TreeModel::iterator iter = region_list_model->get_iter ("0");
89 TreeModel::Row parent;
92 if (iter == region_list_model->children().end()) {
94 parent = *(region_list_model->append());
96 parent[region_list_columns.name] = _("Hidden");
97 parent[region_list_columns.region] = 0;
101 if ((*iter)[region_list_columns.name] != _("Hidden")) {
103 parent = *(region_list_model->insert(iter));
104 parent[region_list_columns.name] = _("Hidden");
105 parent[region_list_columns.region] = 0;
113 row = *(region_list_model->append (parent.children()));
115 } else if (region->whole_file()) {
117 row = *(region_list_model->append());
118 set_color(c, rgba_from_style ("RegionListWholeFile", 0xff, 0, 0, 0, "fg", Gtk::STATE_NORMAL, false ));
119 row[region_list_columns.color_] = c;
121 if (region->source().name()[0] == '/') { // external file
123 if (region->whole_file()) {
125 str += PBD::basename_nosuffix (region->source().name());
128 str = region->name();
133 str = region->name();
137 row[region_list_columns.name] = str;
138 row[region_list_columns.region] = region;
144 /* find parent node, add as new child */
146 TreeModel::iterator i;
147 TreeModel::Children rows = region_list_model->children();
148 bool found_parent = false;
150 for (i = rows.begin(); i != rows.end(); ++i) {
152 Region* rr = (*i)[region_list_columns.region];
153 AudioRegion* r = dynamic_cast<AudioRegion*>(rr);
155 if (r && r->whole_file()) {
156 if (region->source_equivalent (*r)) {
157 row = *(region_list_model->append ((*i).children()));
165 row = *(region_list_model->append());
171 row[region_list_columns.region] = region;
173 if (region->n_channels() > 1) {
174 row[region_list_columns.name] = string_compose("%1 [%2]", region->name(), region->n_channels());
176 row[region_list_columns.name] = region->name();
181 Editor::region_list_selection_changed()
185 if (region_list_display.get_selection()->count_selected_rows() > 0) {
192 TreeView::Selection::ListHandle_Path rows = region_list_display.get_selection()->get_selected_rows ();
193 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
196 /* just set the first selected region (in fact, the selection model might be SINGLE, which
197 means there can only be one.
200 if ((iter = region_list_model->get_iter (*i))) {
201 set_selected_regionview_from_region_list (*((*iter)[region_list_columns.region]), Selection::Set);
207 Editor::insert_into_tmp_audio_regionlist(AudioRegion* region)
209 /* keep all whole files at the beginning */
211 if (region->whole_file()) {
212 tmp_audio_region_list.push_front (region);
214 tmp_audio_region_list.push_back (region);
219 Editor::redisplay_regions ()
223 region_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
224 region_list_model->clear ();
226 /* now add everything we have, via a temporary list used to help with
230 tmp_audio_region_list.clear();
231 session->foreach_audio_region (this, &Editor::insert_into_tmp_audio_regionlist);
233 for (list<AudioRegion*>::iterator r = tmp_audio_region_list.begin(); r != tmp_audio_region_list.end(); ++r) {
234 add_audio_region_to_region_display (*r);
237 region_list_display.set_model (region_list_model);
242 Editor::region_list_clear ()
244 region_list_model->clear();
248 Editor::build_region_list_menu ()
250 region_list_menu = dynamic_cast<Menu*>(ActionManager::get_widget ("/RegionListMenu"));
252 /* now grab specific menu items that we need */
254 Glib::RefPtr<Action> act;
256 act = ActionManager::get_action (X_("RegionList"), X_("rlShowAll"));
258 toggle_full_region_list_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
261 act = ActionManager::get_action (X_("RegionList"), X_("rlShowAuto"));
263 toggle_show_auto_regions_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
268 Editor::toggle_show_auto_regions ()
270 show_automatic_regions_in_region_list = toggle_show_auto_regions_action->get_active();
271 redisplay_regions ();
275 Editor::toggle_full_region_list ()
277 if (toggle_full_region_list_action->get_active()) {
278 region_list_display.expand_all ();
280 region_list_display.collapse_all ();
285 Editor::show_region_list_display_context_menu (int button, int time)
287 if (region_list_menu == 0) {
288 build_region_list_menu ();
291 if (region_list_display.get_selection()->count_selected_rows() > 0) {
292 ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions, true);
294 ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions, false);
297 region_list_menu->popup (button, time);
301 Editor::region_list_display_key_press (GdkEventKey* ev)
307 Editor::region_list_display_key_release (GdkEventKey* ev)
309 switch (ev->keyval) {
311 remove_region_from_region_list ();
322 Editor::region_list_display_button_press (GdkEventButton *ev)
326 TreeModel::Path path;
327 TreeViewColumn* column;
331 if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
332 if ((iter = region_list_model->get_iter (path))) {
333 region = (*iter)[region_list_columns.region];
341 if (Keyboard::is_delete_event (ev)) {
342 session->remove_region_from_region_list (*region);
346 if (Keyboard::is_context_menu_event (ev)) {
347 show_region_list_display_context_menu (ev->button, ev->time);
351 switch (ev->button) {
353 /* audition on double click */
354 if (ev->type == GDK_2BUTTON_PRESS) {
355 consider_auditioning (*region);
362 if (!Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
363 consider_auditioning (*region);
376 Editor::region_list_display_button_release (GdkEventButton *ev)
379 TreeModel::Path path;
380 TreeViewColumn* column;
385 if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
386 if ((iter = region_list_model->get_iter (path))) {
387 region = (*iter)[region_list_columns.region];
391 if (region && Keyboard::is_delete_event (ev)) {
392 session->remove_region_from_region_list (*region);
400 Editor::consider_auditioning (Region& region)
402 AudioRegion* r = dynamic_cast<AudioRegion*> (®ion);
405 session->cancel_audition ();
409 if (session->is_auditioning()) {
410 session->cancel_audition ();
411 if (r == last_audition_region) {
416 session->audition_region (*r);
417 last_audition_region = r;
421 Editor::region_list_sorter (TreeModel::iterator a, TreeModel::iterator b)
425 Region* r1 = (*a)[region_list_columns.region];
426 Region* r2 = (*b)[region_list_columns.region];
428 /* handle rows without regions, like "Hidden" */
438 AudioRegion* region1 = dynamic_cast<AudioRegion*> (r1);
439 AudioRegion* region2 = dynamic_cast<AudioRegion*> (r2);
441 if (region1 == 0 || region2 == 0) {
444 switch (region_list_sort_type) {
446 s1 = (*a)[region_list_columns.name];
447 s2 = (*b)[region_list_columns.name];
448 return (s1.compare (s2));
454 switch (region_list_sort_type) {
456 cmp = strcasecmp (region1->name().c_str(), region2->name().c_str());
460 cmp = region1->length() - region2->length();
464 cmp = region1->position() - region2->position();
468 cmp = region1->source().timestamp() - region2->source().timestamp();
472 cmp = region1->start() - region2->start();
476 cmp = (region1->start() + region1->length()) - (region2->start() + region2->length());
479 case BySourceFileName:
480 cmp = strcasecmp (region1->source().name().c_str(), region2->source().name().c_str());
483 case BySourceFileLength:
484 cmp = region1->source().length() - region2->source().length();
487 case BySourceFileCreationDate:
488 cmp = region1->source().timestamp() - region2->source().timestamp();
492 if (region1->source().name() == region2->source().name()) {
493 cmp = strcasecmp (region1->name().c_str(), region2->name().c_str());
495 cmp = strcasecmp (region1->source().name().c_str(), region2->source().name().c_str());
502 } else if (cmp > 0) {
510 Editor::reset_region_list_sort_type (RegionListSortType type)
512 if (type != region_list_sort_type) {
513 region_list_sort_type = type;
514 region_list_model->set_sort_func (0, (mem_fun (*this, &Editor::region_list_sorter)));
519 Editor::reset_region_list_sort_direction (bool up)
521 region_list_model->set_sort_column (0, up ? SORT_ASCENDING : SORT_DESCENDING);
525 Editor::region_list_selection_mapover (slot<void,Region&> sl)
527 Glib::RefPtr<TreeSelection> selection = region_list_display.get_selection();
528 TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
529 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
531 if (selection->count_selected_rows() == 0 || session == 0) {
535 for (; i != rows.end(); ++i) {
538 if ((iter = region_list_model->get_iter (*i))) {
539 sl (*((*iter)[region_list_columns.region]));
545 Editor::hide_a_region (Region& r)
551 Editor::remove_a_region (Region& r)
553 session->remove_region_from_region_list (r);
557 Editor::audition_region_from_region_list ()
559 region_list_selection_mapover (mem_fun (*this, &Editor::consider_auditioning));
563 Editor::hide_region_from_region_list ()
565 region_list_selection_mapover (mem_fun (*this, &Editor::hide_a_region));
569 Editor::remove_region_from_region_list ()
571 region_list_selection_mapover (mem_fun (*this, &Editor::remove_a_region));
575 Editor::region_list_display_drag_data_received (const RefPtr<Gdk::DragContext>& context,
577 const SelectionData& data,
578 guint info, guint time)
580 vector<ustring> paths;
582 if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
583 jack_nframes_t pos = 0;
584 do_embed (paths, false, ImportAsRegion, 0, pos, true);
585 context->drag_finish (true, false, time);
590 Editor::region_list_selection_filter (const RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
592 /* not possible to select rows that do not represent regions, like "Hidden" */
594 return (*(model->get_iter (path)))[region_list_columns.region] != 0;