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_audio_region_removed (boost::weak_ptr<AudioRegion> wregion)
55 ENSURE_GUI_THREAD (mem_fun (*this, &Editor::redisplay_regions));
60 Editor::handle_new_audio_region (boost::weak_ptr<AudioRegion> wregion)
62 ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::handle_new_audio_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<AudioRegion> region (wregion.lock());
72 add_audio_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_audio_region_to_region_display (boost::shared_ptr<AudioRegion> 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;
104 if (iter == region_list_model->children().end()) {
106 parent = *(region_list_model->append());
108 parent[region_list_columns.name] = _("Hidden");
109 boost::shared_ptr<Region> proxy = parent[region_list_columns.region];
114 if ((*iter)[region_list_columns.name] != _("Hidden")) {
116 parent = *(region_list_model->insert(iter));
117 parent[region_list_columns.name] = _("Hidden");
118 boost::shared_ptr<Region> proxy = parent[region_list_columns.region];
127 row = *(region_list_model->append (parent.children()));
129 } else if (region->whole_file()) {
131 row = *(region_list_model->append());
132 if (missing_source) {
133 c.set_rgb(65535,0,0); // FIXME: error color from style
135 set_color(c, rgba_from_style ("RegionListWholeFile", 0xff, 0, 0, 0, "fg", Gtk::STATE_NORMAL, false ));
137 row[region_list_columns.color_] = c;
139 if (region->source()->name()[0] == '/') { // external file
141 if (region->whole_file()) {
143 boost::shared_ptr<AudioFileSource> afs = boost::dynamic_pointer_cast<AudioFileSource>(region->source());
148 str = region_name_from_path (afs->path(), region->n_channels() > 1);
150 str += region->source()->name();
154 str = region->name();
159 str = region->name();
163 if (region->n_channels() > 1) {
164 std::stringstream foo;
165 foo << region->n_channels ();
171 if (missing_source) {
172 str += _(" (MISSING)");
175 row[region_list_columns.name] = str;
176 row[region_list_columns.region] = region;
182 /* find parent node, add as new child */
184 TreeModel::iterator i;
185 TreeModel::Children rows = region_list_model->children();
186 bool found_parent = false;
188 for (i = rows.begin(); i != rows.end(); ++i) {
190 boost::shared_ptr<Region> rr = (*i)[region_list_columns.region];
191 boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion>(rr);
193 if (r && r->whole_file()) {
194 if (region->source_equivalent (r)) {
195 row = *(region_list_model->append ((*i).children()));
203 row = *(region_list_model->append());
209 row[region_list_columns.region] = region;
211 if (region->n_channels() > 1) {
212 row[region_list_columns.name] = string_compose("%1 [%2]", region->name(), region->n_channels());
214 row[region_list_columns.name] = region->name();
219 Editor::region_list_selection_changed()
223 if (region_list_display.get_selection()->count_selected_rows() > 0) {
230 TreeView::Selection::ListHandle_Path rows = region_list_display.get_selection()->get_selected_rows ();
231 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
234 /* just set the first selected region (in fact, the selection model might be SINGLE, which
235 means there can only be one.
238 if ((iter = region_list_model->get_iter (*i))) {
239 set_selected_regionview_from_region_list (((*iter)[region_list_columns.region]), Selection::Set);
245 Editor::insert_into_tmp_audio_regionlist(boost::shared_ptr<AudioRegion> region)
247 /* keep all whole files at the beginning */
249 if (region->whole_file()) {
250 tmp_audio_region_list.push_front (region);
252 tmp_audio_region_list.push_back (region);
257 Editor::redisplay_regions ()
261 region_list_display.set_model (Glib::RefPtr<Gtk::TreeStore>(0));
262 region_list_model->clear ();
264 /* now add everything we have, via a temporary list used to help with
268 tmp_audio_region_list.clear();
269 session->foreach_audio_region (this, &Editor::insert_into_tmp_audio_regionlist);
271 for (list<boost::shared_ptr<AudioRegion> >::iterator r = tmp_audio_region_list.begin(); r != tmp_audio_region_list.end(); ++r) {
272 add_audio_region_to_region_display (*r);
274 tmp_audio_region_list.clear();
276 region_list_display.set_model (region_list_model);
281 Editor::build_region_list_menu ()
283 region_list_menu = dynamic_cast<Menu*>(ActionManager::get_widget ("/RegionListMenu"));
285 /* now grab specific menu items that we need */
287 Glib::RefPtr<Action> act;
289 act = ActionManager::get_action (X_("RegionList"), X_("rlShowAll"));
291 toggle_full_region_list_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
294 act = ActionManager::get_action (X_("RegionList"), X_("rlShowAuto"));
296 toggle_show_auto_regions_action = Glib::RefPtr<ToggleAction>::cast_dynamic (act);
301 Editor::toggle_show_auto_regions ()
303 show_automatic_regions_in_region_list = toggle_show_auto_regions_action->get_active();
304 redisplay_regions ();
308 Editor::toggle_full_region_list ()
310 if (toggle_full_region_list_action->get_active()) {
311 region_list_display.expand_all ();
313 region_list_display.collapse_all ();
318 Editor::show_region_list_display_context_menu (int button, int time)
320 if (region_list_menu == 0) {
321 build_region_list_menu ();
324 if (region_list_display.get_selection()->count_selected_rows() > 0) {
325 ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions, true);
327 ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions, false);
330 region_list_menu->popup (button, time);
334 Editor::region_list_display_key_press (GdkEventKey* ev)
340 Editor::region_list_display_key_release (GdkEventKey* ev)
342 switch (ev->keyval) {
344 remove_region_from_region_list ();
355 Editor::region_list_display_button_press (GdkEventButton *ev)
357 boost::shared_ptr<Region> region;
359 TreeModel::Path path;
360 TreeViewColumn* column;
364 if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
365 if ((iter = region_list_model->get_iter (path))) {
366 region = (*iter)[region_list_columns.region];
370 if (Keyboard::is_context_menu_event (ev)) {
371 show_region_list_display_context_menu (ev->button, ev->time);
379 switch (ev->button) {
381 /* audition on double click */
382 if (ev->type == GDK_2BUTTON_PRESS) {
383 consider_auditioning (region);
390 if (!Keyboard::modifier_state_equals (ev->state, Keyboard::Control)) {
391 consider_auditioning (region);
404 Editor::region_list_display_button_release (GdkEventButton *ev)
407 TreeModel::Path path;
408 TreeViewColumn* column;
411 boost::shared_ptr<Region> region;
413 if (region_list_display.get_path_at_pos ((int)ev->x, (int)ev->y, path, column, cellx, celly)) {
414 if ((iter = region_list_model->get_iter (path))) {
415 region = (*iter)[region_list_columns.region];
419 if (region && Keyboard::is_delete_event (ev)) {
420 session->remove_region_from_region_list (region);
428 Editor::consider_auditioning (boost::shared_ptr<Region> region)
430 boost::shared_ptr<AudioRegion> r = boost::dynamic_pointer_cast<AudioRegion> (region);
433 session->cancel_audition ();
437 if (session->is_auditioning()) {
438 session->cancel_audition ();
439 if (r == last_audition_region) {
444 session->audition_region (r);
445 last_audition_region = r;
449 Editor::region_list_sorter (TreeModel::iterator a, TreeModel::iterator b)
453 boost::shared_ptr<Region> r1 = (*a)[region_list_columns.region];
454 boost::shared_ptr<Region> r2 = (*b)[region_list_columns.region];
456 /* handle rows without regions, like "Hidden" */
466 boost::shared_ptr<AudioRegion> region1 = boost::dynamic_pointer_cast<AudioRegion> (r1);
467 boost::shared_ptr<AudioRegion> region2 = boost::dynamic_pointer_cast<AudioRegion> (r2);
469 if (region1 == 0 || region2 == 0) {
472 switch (region_list_sort_type) {
474 s1 = (*a)[region_list_columns.name];
475 s2 = (*b)[region_list_columns.name];
476 return (s1.compare (s2));
482 switch (region_list_sort_type) {
484 cmp = strcasecmp (region1->name().c_str(), region2->name().c_str());
488 cmp = region1->length() - region2->length();
492 cmp = region1->position() - region2->position();
496 cmp = region1->source()->timestamp() - region2->source()->timestamp();
500 cmp = region1->start() - region2->start();
504 cmp = (region1->start() + region1->length()) - (region2->start() + region2->length());
507 case BySourceFileName:
508 cmp = strcasecmp (region1->source()->name().c_str(), region2->source()->name().c_str());
511 case BySourceFileLength:
512 cmp = region1->source()->length() - region2->source()->length();
515 case BySourceFileCreationDate:
516 cmp = region1->source()->timestamp() - region2->source()->timestamp();
520 if (region1->source()->name() == region2->source()->name()) {
521 cmp = strcasecmp (region1->name().c_str(), region2->name().c_str());
523 cmp = strcasecmp (region1->source()->name().c_str(), region2->source()->name().c_str());
530 } else if (cmp > 0) {
538 Editor::reset_region_list_sort_type (RegionListSortType type)
540 if (type != region_list_sort_type) {
541 region_list_sort_type = type;
542 region_list_model->set_sort_func (0, (mem_fun (*this, &Editor::region_list_sorter)));
547 Editor::reset_region_list_sort_direction (bool up)
549 region_list_model->set_sort_column (0, up ? SORT_ASCENDING : SORT_DESCENDING);
553 Editor::region_list_selection_mapover (slot<void,boost::shared_ptr<Region> > sl)
555 Glib::RefPtr<TreeSelection> selection = region_list_display.get_selection();
556 TreeView::Selection::ListHandle_Path rows = selection->get_selected_rows ();
557 TreeView::Selection::ListHandle_Path::iterator i = rows.begin();
559 if (selection->count_selected_rows() == 0 || session == 0) {
563 for (; i != rows.end(); ++i) {
566 if ((iter = region_list_model->get_iter (*i))) {
567 sl (((*iter)[region_list_columns.region]));
573 Editor::hide_a_region (boost::shared_ptr<Region> r)
575 r->set_hidden (true);
579 Editor::remove_a_region (boost::shared_ptr<Region> r)
581 cerr << "remove " << r->name();
582 session->remove_region_from_region_list (r);
586 Editor::audition_region_from_region_list ()
588 region_list_selection_mapover (mem_fun (*this, &Editor::consider_auditioning));
592 Editor::hide_region_from_region_list ()
594 region_list_selection_mapover (mem_fun (*this, &Editor::hide_a_region));
598 Editor::remove_region_from_region_list ()
600 cerr << "Mapping remove over region selection\n";
601 region_list_selection_mapover (mem_fun (*this, &Editor::remove_a_region));
605 Editor::region_list_display_drag_data_received (const RefPtr<Gdk::DragContext>& context,
607 const SelectionData& data,
608 guint info, guint time)
610 vector<ustring> paths;
612 if (convert_drop_to_paths (paths, context, x, y, data, info, time) == 0) {
614 do_embed (paths, false, ImportAsRegion, 0, pos, true);
615 context->drag_finish (true, false, time);
620 Editor::region_list_selection_filter (const RefPtr<TreeModel>& model, const TreeModel::Path& path, bool yn)
622 /* not possible to select rows that do not represent regions, like "Hidden" */
624 /// XXXX FIXME boost::shared_ptr<Region> r = ((model->get_iter (path)))[region_list_columns.region];