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"
27 #include "pbd/enumwriter.h"
29 #include "ardour/audioregion.h"
30 #include "ardour/audiofilesource.h"
31 #include "ardour/region_factory.h"
32 #include "ardour/session.h"
33 #include "ardour/session_playlists.h"
34 #include "ardour/silentfilesource.h"
35 #include "ardour/profile.h"
37 #include "gtkmm2ext/choice.h"
38 #include "gtkmm2ext/treeutils.h"
43 #include "ardour_ui.h"
44 #include "gui_thread.h"
46 #include "region_view.h"
48 #include "editor_regions.h"
49 #include "editor_drag.h"
54 using namespace ARDOUR
;
58 using namespace Editing
;
59 using Gtkmm2ext::Keyboard
;
61 EditorRegions::EditorRegions (Editor
* e
)
66 , _show_automatic_regions (true)
67 , ignore_region_list_selection_change (false)
68 , ignore_selected_region_change (false)
69 , _no_redisplay (false)
70 , _sort_type ((Editing::RegionListSortType
) 0)
73 _display
.set_size_request (100, -1);
74 _display
.set_name ("RegionListDisplay");
75 _display
.set_rules_hint (true);
77 /* Try to prevent single mouse presses from initiating edits.
78 This relies on a hack in gtktreeview.c:gtk_treeview_button_press()
80 _display
.set_data ("mouse-edits-require-mod1", (gpointer
) 0x1);
82 _model
= TreeStore::create (_columns
);
83 _model
->set_sort_func (0, sigc::mem_fun (*this, &EditorRegions::sorter
));
84 _model
->set_sort_column (0, SORT_ASCENDING
);
86 _display
.set_model (_model
);
88 _display
.append_column (_("Regions"), _columns
.name
);
89 _display
.append_column (_("Position"), _columns
.position
);
90 _display
.append_column (_("End"), _columns
.end
);
91 _display
.append_column (_("Length"), _columns
.length
);
92 _display
.append_column (_("Sync"), _columns
.sync
);
93 _display
.append_column (_("Fade In"), _columns
.fadein
);
94 _display
.append_column (_("Fade Out"), _columns
.fadeout
);
95 _display
.append_column (_("L"), _columns
.locked
);
96 _display
.append_column (_("G"), _columns
.glued
);
97 _display
.append_column (_("M"), _columns
.muted
);
98 _display
.append_column (_("O"), _columns
.opaque
);
99 // _display.append_column (_("Used"), _columns.used);
100 // _display.append_column (_("Path"), _columns.path);
101 _display
.set_headers_visible (true);
102 //_display.set_grid_lines (TREE_VIEW_GRID_LINES_BOTH);
104 /* show path as the row tooltip */
105 _display
.set_tooltip_column (15); /* path */
107 CellRendererText
* region_name_cell
= dynamic_cast<CellRendererText
*>(_display
.get_column_cell_renderer (0));
108 region_name_cell
->property_editable() = true;
109 region_name_cell
->signal_edited().connect (sigc::mem_fun (*this, &EditorRegions::name_edit
));
110 region_name_cell
->signal_editing_started().connect (sigc::mem_fun (*this, &EditorRegions::name_editing_started
));
112 _display
.get_selection()->set_select_function (sigc::mem_fun (*this, &EditorRegions::selection_filter
));
114 TreeViewColumn
* tv_col
= _display
.get_column(0);
115 CellRendererText
* renderer
= dynamic_cast<CellRendererText
*>(_display
.get_column_cell_renderer (0));
116 tv_col
->add_attribute(renderer
->property_text(), _columns
.name
);
117 tv_col
->add_attribute(renderer
->property_foreground_gdk(), _columns
.color_
);
119 CellRendererToggle
* locked_cell
= dynamic_cast<CellRendererToggle
*> (_display
.get_column_cell_renderer (7));
120 locked_cell
->property_activatable() = true;
121 locked_cell
->signal_toggled().connect (sigc::mem_fun (*this, &EditorRegions::locked_changed
));
123 TreeViewColumn
* locked_col
= _display
.get_column (7);
124 locked_col
->add_attribute (locked_cell
->property_visible(), _columns
.property_toggles_visible
);
126 CellRendererToggle
* glued_cell
= dynamic_cast<CellRendererToggle
*> (_display
.get_column_cell_renderer (8));
127 glued_cell
->property_activatable() = true;
128 glued_cell
->signal_toggled().connect (sigc::mem_fun (*this, &EditorRegions::glued_changed
));
130 TreeViewColumn
* glued_col
= _display
.get_column (8);
131 glued_col
->add_attribute (glued_cell
->property_visible(), _columns
.property_toggles_visible
);
133 CellRendererToggle
* muted_cell
= dynamic_cast<CellRendererToggle
*> (_display
.get_column_cell_renderer (9));
134 muted_cell
->property_activatable() = true;
135 muted_cell
->signal_toggled().connect (sigc::mem_fun (*this, &EditorRegions::muted_changed
));
137 TreeViewColumn
* muted_col
= _display
.get_column (9);
138 muted_col
->add_attribute (muted_cell
->property_visible(), _columns
.property_toggles_visible
);
140 CellRendererToggle
* opaque_cell
= dynamic_cast<CellRendererToggle
*> (_display
.get_column_cell_renderer (10));
141 opaque_cell
->property_activatable() = true;
142 opaque_cell
->signal_toggled().connect (sigc::mem_fun (*this, &EditorRegions::opaque_changed
));
144 TreeViewColumn
* opaque_col
= _display
.get_column (10);
145 opaque_col
->add_attribute (opaque_cell
->property_visible(), _columns
.property_toggles_visible
);
147 _display
.get_selection()->set_mode (SELECTION_MULTIPLE
);
148 _display
.add_object_drag (_columns
.region
.index(), "regions");
150 /* setup DnD handling */
152 list
<TargetEntry
> region_list_target_table
;
154 region_list_target_table
.push_back (TargetEntry ("text/plain"));
155 region_list_target_table
.push_back (TargetEntry ("text/uri-list"));
156 region_list_target_table
.push_back (TargetEntry ("application/x-rootwin-drop"));
158 _display
.add_drop_targets (region_list_target_table
);
159 _display
.signal_drag_data_received().connect (sigc::mem_fun(*this, &EditorRegions::drag_data_received
));
161 _scroller
.add (_display
);
162 _scroller
.set_policy (POLICY_AUTOMATIC
, POLICY_AUTOMATIC
);
164 _display
.signal_button_press_event().connect (sigc::mem_fun(*this, &EditorRegions::button_press
), false);
165 _change_connection
= _display
.get_selection()->signal_changed().connect (sigc::mem_fun(*this, &EditorRegions::selection_changed
));
167 _scroller
.signal_key_press_event().connect (sigc::mem_fun(*this, &EditorRegions::key_press
), false);
168 _scroller
.signal_focus_in_event().connect (sigc::mem_fun (*this, &EditorRegions::focus_in
), false);
169 _scroller
.signal_focus_out_event().connect (sigc::mem_fun (*this, &EditorRegions::focus_out
));
171 _display
.signal_enter_notify_event().connect (sigc::mem_fun (*this, &EditorRegions::enter_notify
), false);
172 _display
.signal_leave_notify_event().connect (sigc::mem_fun (*this, &EditorRegions::leave_notify
), false);
174 // _display.signal_popup_menu().connect (sigc::bind (sigc::mem_fun (*this, &Editor::show__display_context_menu), 1, 0));
176 //ARDOUR_UI::instance()->secondary_clock.mode_changed.connect (sigc::mem_fun(*this, &Editor::redisplay_regions));
177 ARDOUR_UI::instance()->secondary_clock
.mode_changed
.connect (sigc::mem_fun(*this, &EditorRegions::update_all_rows
));
178 ARDOUR::Region::RegionPropertyChanged
.connect (region_property_connection
, MISSING_INVALIDATOR
, ui_bind (&EditorRegions::region_changed
, this, _1
, _2
), gui_context());
179 ARDOUR::RegionFactory::CheckNewRegion
.connect (check_new_region_connection
, MISSING_INVALIDATOR
, ui_bind (&EditorRegions::add_region
, this, _1
), gui_context());
181 e
->EditorFreeze
.connect (editor_freeze_connection
, MISSING_INVALIDATOR
, ui_bind (&EditorRegions::freeze_tree_model
, this), gui_context());
182 e
->EditorThaw
.connect (editor_thaw_connection
, MISSING_INVALIDATOR
, ui_bind (&EditorRegions::thaw_tree_model
, this), gui_context());
186 EditorRegions::focus_in (GdkEventFocus
*)
188 Window
* win
= dynamic_cast<Window
*> (_scroller
.get_toplevel ());
191 old_focus
= win
->get_focus ();
198 /* try to do nothing on focus in (doesn't work, hence selection_count nonsense) */
203 EditorRegions::focus_out (GdkEventFocus
*)
206 old_focus
->grab_focus ();
216 EditorRegions::enter_notify (GdkEventCrossing
* ev
)
222 /* arm counter so that ::selection_filter() will deny selecting anything for the
223 next two attempts to change selection status.
225 _scroller
.grab_focus ();
226 Keyboard::magic_widget_grab_focus ();
231 EditorRegions::leave_notify (GdkEventCrossing
*)
234 old_focus
->grab_focus ();
238 Keyboard::magic_widget_drop_focus ();
243 EditorRegions::set_session (ARDOUR::Session
* s
)
245 SessionHandlePtr::set_session (s
);
250 EditorRegions::add_region (boost::shared_ptr
<Region
> region
)
252 if (!region
|| !_session
) {
259 bool missing_source
= boost::dynamic_pointer_cast
<SilentFileSource
>(region
->source());
261 if (!_show_automatic_regions
&& region
->automatic()) {
265 if (region
->hidden()) {
267 TreeModel::iterator iter
= _model
->get_iter ("0");
268 TreeModel::Row parent
;
269 TreeModel::Row child
;
272 parent
= *(_model
->append());
273 parent
[_columns
.name
] = _("Hidden");
274 boost::shared_ptr
<Region
> proxy
= parent
[_columns
.region
];
277 string s
= (*iter
)[_columns
.name
];
278 if (s
!= _("Hidden")) {
279 parent
= *(_model
->insert(iter
));
280 parent
[_columns
.name
] = _("Hidden");
281 boost::shared_ptr
<Region
> proxy
= parent
[_columns
.region
];
288 row
= *(_model
->append (parent
.children()));
290 } else if (region
->whole_file()) {
292 TreeModel::iterator i
;
293 TreeModel::Children rows
= _model
->children();
295 for (i
= rows
.begin(); i
!= rows
.end(); ++i
) {
296 boost::shared_ptr
<Region
> rr
= (*i
)[_columns
.region
];
298 if (rr
&& region
->region_list_equivalent (rr
)) {
303 row
= *(_model
->append());
305 if (missing_source
) {
306 c
.set_rgb(65535,0,0); // FIXME: error color from style
308 } else if (region
->automatic()){
309 c
.set_rgb(0,65535,0); // FIXME: error color from style
312 set_color(c
, rgba_from_style ("RegionListWholeFile", 0xff, 0, 0, 0, "fg", Gtk::STATE_NORMAL
, false ));
316 row
[_columns
.color_
] = c
;
318 if (region
->source()->name()[0] == '/') { // external file
320 if (region
->whole_file()) {
322 boost::shared_ptr
<AudioFileSource
> afs
= boost::dynamic_pointer_cast
<AudioFileSource
>(region
->source());
326 str
= region_name_from_path (afs
->path(), region
->n_channels() > 1);
328 str
+= region
->source()->name();
332 str
= region
->name();
336 str
= region
->name();
339 if (region
->n_channels() > 1) {
340 std::stringstream foo
;
341 foo
<< region
->n_channels ();
347 row
[_columns
.name
] = str
;
348 row
[_columns
.region
] = region
;
349 row
[_columns
.property_toggles_visible
] = false;
351 if (missing_source
) {
352 row
[_columns
.path
] = _("(MISSING) ") + region
->source()->name();
355 boost::shared_ptr
<FileSource
> fs
= boost::dynamic_pointer_cast
<FileSource
>(region
->source());
357 row
[_columns
.path
] = fs
->path();
359 row
[_columns
.path
] = region
->source()->name();
363 region_row_map
.insert(pair
<boost::shared_ptr
<ARDOUR::Region
>, Gtk::TreeModel::RowReference
>(region
, TreeRowReference(_model
, TreePath (row
))) );
364 parent_regions_sources_map
.insert(pair
<string
, Gtk::TreeModel::RowReference
>(region
->source_string(), TreeRowReference(_model
, TreePath (row
))) );
369 // find parent node, add as new child
370 TreeModel::iterator i
;
371 TreeModel::Children rows
= _model
->children();
373 boost::unordered_map
<string
, Gtk::TreeModel::RowReference
>::iterator it
;
375 it
= parent_regions_sources_map
.find (region
->source_string());
377 if (it
!= parent_regions_sources_map
.end()){
379 TreeModel::iterator j
= _model
->get_iter ((*it
).second
.get_path());
381 TreeModel::iterator ii
;
382 TreeModel::Children subrows
= (*j
).children();
384 /* XXXX: should we be accounting for all regions? */
386 for (ii = subrows.begin(); ii != subrows.end(); ++ii) {
387 boost::shared_ptr<Region> rr = (*ii)[_columns.region];
389 if (region->region_list_equivalent (rr)) {
395 row
= *(_model
->insert (subrows
.end()));
398 row
= *(_model
->append());
401 row
[_columns
.property_toggles_visible
] = true;
404 row
[_columns
.region
] = region
;
406 region_row_map
.insert(pair
<boost::shared_ptr
<ARDOUR::Region
>, Gtk::TreeModel::RowReference
>(region
, TreeRowReference(_model
, TreePath (row
))) );
408 populate_row(region
, (*row
));
412 EditorRegions::delete_unused_regions ()
414 vector
<string
> choices
;
421 prompt
= _("Do you really want to remove unused regions?"
422 "\n(This is destructive and cannot be undone)");
424 choices
.push_back (_("No, do nothing."));
425 choices
.push_back (_("Yes, remove."));
427 Gtkmm2ext::Choice
prompter (_("Remove unused regions"), prompt
, choices
);
429 if (prompter
.run () == 1) {
430 _no_redisplay
= true;
431 _session
->cleanup_regions ();
432 _no_redisplay
= false;
438 EditorRegions::region_changed (boost::shared_ptr
<Region
> r
, const PropertyChange
& what_changed
)
440 PropertyChange our_interests
;
442 our_interests
.add (ARDOUR::Properties::name
);
443 our_interests
.add (ARDOUR::Properties::position
);
444 our_interests
.add (ARDOUR::Properties::length
);
445 our_interests
.add (ARDOUR::Properties::start
);
446 our_interests
.add (ARDOUR::Properties::locked
);
447 our_interests
.add (ARDOUR::Properties::position_lock_style
);
448 our_interests
.add (ARDOUR::Properties::muted
);
449 our_interests
.add (ARDOUR::Properties::opaque
);
450 our_interests
.add (ARDOUR::Properties::fade_in
);
451 our_interests
.add (ARDOUR::Properties::fade_out
);
453 if (what_changed
.contains (our_interests
)) {
457 TreeModel::iterator j
= _model
->get_iter (last_row
.get_path());
458 boost::shared_ptr
<Region
> c
= (*j
)[_columns
.region
];
461 populate_row (r
, (*j
));
463 if (what_changed
.contains (ARDOUR::Properties::hidden
)) {
471 RegionRowMap::iterator it
;
473 it
= region_row_map
.find (r
);
475 if (it
!= region_row_map
.end()){
477 TreeModel::iterator j
= _model
->get_iter ((*it
).second
.get_path());
478 boost::shared_ptr
<Region
> c
= (*j
)[_columns
.region
];
481 populate_row (r
, (*j
));
483 if (what_changed
.contains (ARDOUR::Properties::hidden
)) {
491 /* find the region in our model and update its row */
492 TreeModel::Children rows
= _model
->children ();
493 TreeModel::iterator i
= rows
.begin ();
497 if (what_changed
.contains (ARDOUR::Properties::hidden
)) {
503 EditorRegions::selection_changed ()
505 if (ignore_region_list_selection_change
) {
509 _editor
->_region_selection_change_updates_region_list
= false;
511 if (_display
.get_selection()->count_selected_rows() > 0) {
514 TreeView::Selection::ListHandle_Path rows
= _display
.get_selection()->get_selected_rows ();
516 _editor
->get_selection().clear_regions ();
518 for (TreeView::Selection::ListHandle_Path::iterator i
= rows
.begin(); i
!= rows
.end(); ++i
) {
520 if (iter
= _model
->get_iter (*i
)) {
521 boost::shared_ptr
<Region
> region
= (*iter
)[_columns
.region
];
523 // they could have clicked on a row that is just a placeholder, like "Hidden"
524 // although that is not allowed by our selection filter. check it anyway
525 // since we need a region ptr.
529 if (region
->automatic()) {
531 _display
.get_selection()->unselect(*i
);
534 _change_connection
.block (true);
535 _editor
->set_selected_regionview_from_region_list (region
, Selection::Add
);
537 _change_connection
.block (false);
543 _editor
->get_selection().clear_regions ();
546 _editor
->_region_selection_change_updates_region_list
= true;
550 EditorRegions::set_selected (RegionSelection
& regions
)
552 for (RegionSelection::iterator i
= regions
.begin(); i
!= regions
.end(); ++i
) {
554 boost::shared_ptr
<Region
> r ((*i
)->region());
556 RegionRowMap::iterator it
;
558 it
= region_row_map
.find (r
);
560 if (it
!= region_row_map
.end()){
561 TreeModel::iterator j
= _model
->get_iter ((*it
).second
.get_path());
562 _display
.get_selection()->select(*j
);
568 EditorRegions::redisplay ()
570 if (_no_redisplay
|| !_session
) {
574 bool tree_expanded
= false;
576 /* If the list was expanded prior to rebuilding, expand it again afterwards */
577 if (toggle_full_action()->get_active()) {
578 tree_expanded
= true;
581 _display
.set_model (Glib::RefPtr
<Gtk::TreeStore
>(0));
583 _model
->set_sort_column (-2, SORT_ASCENDING
); //Disable sorting to gain performance
586 region_row_map
.clear();
587 parent_regions_sources_map
.clear();
589 /* now add everything we have, via a temporary list used to help with sorting */
591 const RegionFactory::RegionMap
& regions (RegionFactory::regions());
593 for (RegionFactory::RegionMap::const_iterator i
= regions
.begin(); i
!= regions
.end(); ++i
) {
595 if ( i
->second
->whole_file()) {
596 /* add automatic regions first so that children can find their parents as we add them */
597 add_region (i
->second
);
601 tmp_region_list
.push_front (i
->second
);
604 for (list
<boost::shared_ptr
<Region
> >::iterator r
= tmp_region_list
.begin(); r
!= tmp_region_list
.end(); ++r
) {
608 _model
->set_sort_column (0, SORT_ASCENDING
); // renabale sorting
609 _display
.set_model (_model
);
611 tmp_region_list
.clear();
614 _display
.expand_all();
619 EditorRegions::update_row (boost::shared_ptr
<Region
> region
)
621 if (!region
|| !_session
) {
625 RegionRowMap::iterator it
;
627 it
= region_row_map
.find (region
);
629 if (it
!= region_row_map
.end()){
631 TreeModel::iterator j
= _model
->get_iter ((*it
).second
.get_path());
632 populate_row(region
, (*j
));
637 EditorRegions::update_all_rows ()
643 RegionRowMap::iterator i
;
645 for (i
= region_row_map
.begin(); i
!= region_row_map
.end(); ++i
) {
647 TreeModel::iterator j
= _model
->get_iter ((*i
).second
.get_path());
649 boost::shared_ptr
<Region
> region
= (*j
)[_columns
.region
];
651 if (!region
->automatic()) {
652 populate_row(region
, (*j
));
658 EditorRegions::format_position (framepos_t pos
, char* buf
, size_t bufsize
)
660 Timecode::BBT_Time bbt
;
661 Timecode::Time timecode
;
663 switch (ARDOUR_UI::instance()->secondary_clock
.mode ()) {
664 case AudioClock::BBT
:
665 _session
->tempo_map().bbt_time (pos
, bbt
);
666 snprintf (buf
, bufsize
, "%03d|%02d|%04d" , bbt
.bars
, bbt
.beats
, bbt
.ticks
);
669 case AudioClock::MinSec
:
676 hrs
= (int) floor (left
/ (_session
->frame_rate() * 60.0f
* 60.0f
));
677 left
-= (framecnt_t
) floor (hrs
* _session
->frame_rate() * 60.0f
* 60.0f
);
678 mins
= (int) floor (left
/ (_session
->frame_rate() * 60.0f
));
679 left
-= (framecnt_t
) floor (mins
* _session
->frame_rate() * 60.0f
);
680 secs
= left
/ (float) _session
->frame_rate();
681 snprintf (buf
, bufsize
, "%02d:%02d:%06.3f", hrs
, mins
, secs
);
684 case AudioClock::Frames
:
685 snprintf (buf
, bufsize
, "%" PRId64
, pos
);
688 case AudioClock::Timecode
:
689 case AudioClock::Off
: /* If the secondary clock is off, default to Timecode */
691 _session
->timecode_time (pos
, timecode
);
692 snprintf (buf
, bufsize
, "%02d:%02d:%02d:%02d", timecode
.hours
, timecode
.minutes
, timecode
.seconds
, timecode
.frames
);
698 EditorRegions::populate_row (boost::shared_ptr
<Region
> region
, TreeModel::Row
const &row
)
700 boost::shared_ptr
<AudioRegion
> audioregion
= boost::dynamic_pointer_cast
<AudioRegion
>(region
);
701 //uint32_t used = _session->playlists->region_use_count (region);
702 /* Presently a region is only used once so let's save on the sequential scan to determine use count */
705 populate_row_position (region
, row
, used
);
706 populate_row_end (region
, row
, used
);
707 populate_row_sync (region
, row
, used
);
708 populate_row_fade_in (region
, row
, used
, audioregion
);
709 populate_row_fade_out (region
, row
, used
, audioregion
);
710 populate_row_locked (region
, row
, used
);
711 populate_row_glued (region
, row
, used
);
712 populate_row_muted (region
, row
, used
);
713 populate_row_opaque (region
, row
, used
);
714 populate_row_length (region
, row
);
715 populate_row_source (region
, row
);
716 populate_row_name (region
, row
);
717 populate_row_used (region
, row
, used
);
721 if (audioRegion
&& fades_in_seconds
) {
727 left
= audioRegion
->fade_in()->back()->when
;
728 mins
= (int) floor (left
/ (_session
->frame_rate() * 60.0f
));
729 left
-= (framepos_t
) floor (mins
* _session
->frame_rate() * 60.0f
);
730 millisecs
= (int) floor ((left
* 1000.0f
) / _session
->frame_rate());
732 if (audioRegion
->fade_in()->back()->when
>= _session
->frame_rate()) {
733 sprintf (fadein_str
, "%01dM %01dmS", mins
, millisecs
);
735 sprintf (fadein_str
, "%01dmS", millisecs
);
738 left
= audioRegion
->fade_out()->back()->when
;
739 mins
= (int) floor (left
/ (_session
->frame_rate() * 60.0f
));
740 left
-= (framepos_t
) floor (mins
* _session
->frame_rate() * 60.0f
);
741 millisecs
= (int) floor ((left
* 1000.0f
) / _session
->frame_rate());
743 if (audioRegion
->fade_out()->back()->when
>= _session
->frame_rate()) {
744 sprintf (fadeout_str
, "%01dM %01dmS", mins
, millisecs
);
746 sprintf (fadeout_str
, "%01dmS", millisecs
);
752 EditorRegions::populate_row_used (boost::shared_ptr
<Region
> region
, TreeModel::Row
const& row
, uint32_t used
)
755 snprintf (buf
, sizeof (buf
), "%4d" , used
);
756 row
[_columns
.used
] = buf
;
760 EditorRegions::populate_row_length (boost::shared_ptr
<Region
> region
, TreeModel::Row
const &row
)
763 format_position (region
->length(), buf
, sizeof (buf
));
764 row
[_columns
.length
] = buf
;
768 EditorRegions::populate_row_end (boost::shared_ptr
<Region
> region
, TreeModel::Row
const &row
, uint32_t used
)
770 if (region
->whole_file()) {
771 row
[_columns
.end
] = "";
772 } else if (used
> 1) {
773 row
[_columns
.end
] = _("Mult.");
776 format_position (region
->last_frame(), buf
, sizeof (buf
));
777 row
[_columns
.end
] = buf
;
782 EditorRegions::populate_row_position (boost::shared_ptr
<Region
> region
, TreeModel::Row
const &row
, uint32_t used
)
784 if (region
->whole_file()) {
785 row
[_columns
.position
] = "";
786 } else if (used
> 1) {
787 row
[_columns
.position
] = _("Mult.");
790 format_position (region
->position(), buf
, sizeof (buf
));
791 row
[_columns
.position
] = buf
;
796 EditorRegions::populate_row_sync (boost::shared_ptr
<Region
> region
, TreeModel::Row
const &row
, uint32_t used
)
798 if (region
->whole_file()) {
799 row
[_columns
.sync
] = "";
800 } else if (used
> 1) {
801 row
[_columns
.sync
] = _("Mult."); /* translators: a short phrase for "multiple" as in "many" */
803 if (region
->sync_position() == region
->position()) {
804 row
[_columns
.sync
] = _("Start");
805 } else if (region
->sync_position() == (region
->last_frame())) {
806 row
[_columns
.sync
] = _("End");
809 format_position (region
->sync_position(), buf
, sizeof (buf
));
810 row
[_columns
.sync
] = buf
;
816 EditorRegions::populate_row_fade_in (boost::shared_ptr
<Region
> region
, TreeModel::Row
const &row
, uint32_t used
, boost::shared_ptr
<AudioRegion
> audioregion
)
818 if (!audioregion
|| region
->whole_file()) {
819 row
[_columns
.fadein
] = "";
822 row
[_columns
.fadein
] = _("Multiple");
826 format_position (audioregion
->fade_in()->back()->when
, buf
, sizeof (buf
));
827 row
[_columns
.fadein
] = buf
;
829 if (audioregion
->fade_in_active()) {
830 row
[_columns
.fadein
] = string_compose("%1%2%3", " ", buf
, " ");
832 row
[_columns
.fadein
] = string_compose("%1%2%3", "(", buf
, ")");
839 EditorRegions::populate_row_fade_out (boost::shared_ptr
<Region
> region
, TreeModel::Row
const &row
, uint32_t used
, boost::shared_ptr
<AudioRegion
> audioregion
)
841 if (!audioregion
|| region
->whole_file()) {
842 row
[_columns
.fadeout
] = "";
845 row
[_columns
.fadeout
] = _("Multiple");
848 format_position (audioregion
->fade_out()->back()->when
, buf
, sizeof (buf
));
850 if (audioregion
->fade_out_active()) {
851 row
[_columns
.fadeout
] = string_compose("%1%2%3", " ", buf
, " ");
853 row
[_columns
.fadeout
] = string_compose("%1%2%3", "(", buf
, ")");
860 EditorRegions::populate_row_locked (boost::shared_ptr
<Region
> region
, TreeModel::Row
const &row
, uint32_t used
)
862 if (region
->whole_file()) {
863 row
[_columns
.locked
] = false;
864 } else if (used
> 1) {
865 row
[_columns
.locked
] = false;
867 row
[_columns
.locked
] = region
->locked();
872 EditorRegions::populate_row_glued (boost::shared_ptr
<Region
> region
, TreeModel::Row
const &row
, uint32_t used
)
874 if (region
->whole_file() || used
> 1) {
875 row
[_columns
.glued
] = false;
877 if (region
->position_lock_style() == MusicTime
) {
878 row
[_columns
.glued
] = true;
880 row
[_columns
.glued
] = false;
886 EditorRegions::populate_row_muted (boost::shared_ptr
<Region
> region
, TreeModel::Row
const &row
, uint32_t used
)
888 if (region
->whole_file() || used
> 1) {
889 row
[_columns
.muted
] = false;
891 row
[_columns
.muted
] = region
->muted();
896 EditorRegions::populate_row_opaque (boost::shared_ptr
<Region
> region
, TreeModel::Row
const &row
, uint32_t used
)
898 if (region
->whole_file() || used
> 1) {
899 row
[_columns
.opaque
] = false;
901 row
[_columns
.opaque
] = region
->opaque();
906 EditorRegions::populate_row_name (boost::shared_ptr
<Region
> region
, TreeModel::Row
const &row
)
908 if (region
->n_channels() > 1) {
909 row
[_columns
.name
] = string_compose("%1 [%2]", region
->name(), region
->n_channels());
911 row
[_columns
.name
] = region
->name();
916 EditorRegions::populate_row_source (boost::shared_ptr
<Region
> region
, TreeModel::Row
const &row
)
918 if (boost::dynamic_pointer_cast
<SilentFileSource
>(region
->source())) {
919 row
[_columns
.path
] = _("MISSING ") + region
->source()->name();
921 row
[_columns
.path
] = region
->source()->name();
926 EditorRegions::toggle_show_auto_regions ()
928 _show_automatic_regions
= toggle_show_auto_regions_action()->get_active();
933 EditorRegions::toggle_full ()
935 set_full (toggle_full_action()->get_active ());
939 EditorRegions::set_full (bool f
)
942 _display
.expand_all ();
945 _display
.collapse_all ();
951 EditorRegions::show_context_menu (int button
, int time
)
954 _menu
= dynamic_cast<Menu
*> (ActionManager::get_widget ("/RegionListMenu"));
957 if (_display
.get_selection()->count_selected_rows() > 0) {
958 ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions
, true);
960 ActionManager::set_sensitive (ActionManager::region_list_selection_sensitive_actions
, false);
963 /* Enable the "Show" option if any selected regions are hidden, and vice versa for "Hide" */
965 bool have_shown
= false;
966 bool have_hidden
= false;
968 TreeView::Selection::ListHandle_Path rows
= _display
.get_selection()->get_selected_rows ();
969 for (TreeView::Selection::ListHandle_Path::iterator i
= rows
.begin(); i
!= rows
.end(); ++i
) {
970 TreeIter t
= _model
->get_iter (*i
);
971 boost::shared_ptr
<Region
> r
= (*t
)[_columns
.region
];
981 hide_action()->set_sensitive (have_shown
);
982 show_action()->set_sensitive (have_hidden
);
984 _menu
->popup (button
, time
);
988 EditorRegions::key_press (GdkEventKey
* ev
)
992 switch (ev
->keyval
) {
994 case GDK_ISO_Left_Tab
:
997 name_editable
->editing_done ();
1001 col
= _display
.get_column (0); // select&focus on name column
1003 if (Keyboard::modifier_state_equals (ev
->state
, Keyboard::TertiaryModifier
)) {
1004 treeview_select_previous (_display
, _model
, col
);
1006 treeview_select_next (_display
, _model
, col
);
1020 EditorRegions::button_press (GdkEventButton
*ev
)
1022 boost::shared_ptr
<Region
> region
;
1024 TreeModel::Path path
;
1025 TreeViewColumn
* column
;
1029 if (_display
.get_path_at_pos ((int)ev
->x
, (int)ev
->y
, path
, column
, cellx
, celly
)) {
1030 if ((iter
= _model
->get_iter (path
))) {
1031 region
= (*iter
)[_columns
.region
];
1035 if (Keyboard::is_context_menu_event (ev
)) {
1036 show_context_menu (ev
->button
, ev
->time
);
1040 if (region
!= 0 && Keyboard::is_button2_event (ev
)) {
1041 // start/stop audition
1042 if (!Keyboard::modifier_state_equals (ev
->state
, Keyboard::PrimaryModifier
)) {
1043 _editor
->consider_auditioning (region
);
1052 EditorRegions::sorter (TreeModel::iterator a
, TreeModel::iterator b
)
1056 boost::shared_ptr
<Region
> r1
= (*a
)[_columns
.region
];
1057 boost::shared_ptr
<Region
> r2
= (*b
)[_columns
.region
];
1059 /* handle rows without regions, like "Hidden" */
1069 boost::shared_ptr
<AudioRegion
> region1
= boost::dynamic_pointer_cast
<AudioRegion
> (r1
);
1070 boost::shared_ptr
<AudioRegion
> region2
= boost::dynamic_pointer_cast
<AudioRegion
> (r2
);
1072 if (region1
== 0 || region2
== 0) {
1075 switch (_sort_type
) {
1077 s1
= (*a
)[_columns
.name
];
1078 s2
= (*b
)[_columns
.name
];
1079 return (s1
.compare (s2
));
1085 switch (_sort_type
) {
1087 cmp
= strcasecmp (region1
->name().c_str(), region2
->name().c_str());
1091 cmp
= region1
->length() - region2
->length();
1095 cmp
= region1
->position() - region2
->position();
1099 cmp
= region1
->source()->timestamp() - region2
->source()->timestamp();
1103 cmp
= region1
->start() - region2
->start();
1107 // cerr << "Compare " << (region1->start() + region1->length()) << " and " << (region2->start() + region2->length()) << endl;
1108 cmp
= (region1
->start() + region1
->length()) - (region2
->start() + region2
->length());
1111 case BySourceFileName
:
1112 cmp
= strcasecmp (region1
->source()->name().c_str(), region2
->source()->name().c_str());
1115 case BySourceFileLength
:
1116 cmp
= region1
->source_length(0) - region2
->source_length(0);
1119 case BySourceFileCreationDate
:
1120 cmp
= region1
->source()->timestamp() - region2
->source()->timestamp();
1123 case BySourceFileFS
:
1124 if (region1
->source()->name() == region2
->source()->name()) {
1125 cmp
= strcasecmp (region1
->name().c_str(), region2
->name().c_str());
1127 cmp
= strcasecmp (region1
->source()->name().c_str(), region2
->source()->name().c_str());
1132 // cerr << "Comparison on " << enum_2_string (_sort_type) << " gives " << cmp << endl;
1136 } else if (cmp
> 0) {
1144 EditorRegions::reset_sort_type (RegionListSortType type
, bool force
)
1146 if (type
!= _sort_type
|| force
) {
1148 _model
->set_sort_func (0, (sigc::mem_fun (*this, &EditorRegions::sorter
)));
1153 EditorRegions::reset_sort_direction (bool up
)
1155 _model
->set_sort_column (0, up
? SORT_ASCENDING
: SORT_DESCENDING
);
1159 EditorRegions::selection_mapover (sigc::slot
<void,boost::shared_ptr
<Region
> > sl
)
1161 Glib::RefPtr
<TreeSelection
> selection
= _display
.get_selection();
1162 TreeView::Selection::ListHandle_Path rows
= selection
->get_selected_rows ();
1163 TreeView::Selection::ListHandle_Path::iterator i
= rows
.begin();
1165 if (selection
->count_selected_rows() == 0 || _session
== 0) {
1169 for (; i
!= rows
.end(); ++i
) {
1172 if ((iter
= _model
->get_iter (*i
))) {
1174 /* some rows don't have a region associated with them, but can still be
1175 selected (XXX maybe prevent them from being selected)
1178 boost::shared_ptr
<Region
> r
= (*iter
)[_columns
.region
];
1189 EditorRegions::drag_data_received (const RefPtr
<Gdk::DragContext
>& context
,
1191 const SelectionData
& data
,
1192 guint info
, guint time
)
1194 vector
<string
> paths
;
1196 if (data
.get_target() == "GTK_TREE_MODEL_ROW") {
1197 /* something is being dragged over the region list */
1198 _editor
->_drags
->abort ();
1199 _display
.on_drag_data_received (context
, x
, y
, data
, info
, time
);
1203 if (_editor
->convert_drop_to_paths (paths
, context
, x
, y
, data
, info
, time
) == 0) {
1205 if (Profile
->get_sae() || Config
->get_only_copy_imported_files()) {
1206 _editor
->do_import (paths
, Editing::ImportDistinctFiles
, Editing::ImportAsRegion
, SrcBest
, pos
);
1208 _editor
->do_embed (paths
, Editing::ImportDistinctFiles
, ImportAsRegion
, pos
);
1210 context
->drag_finish (true, false, time
);
1215 EditorRegions::selection_filter (const RefPtr
<TreeModel
>& model
, const TreeModel::Path
& path
, bool already_selected
)
1217 /* not possible to select rows that do not represent regions, like "Hidden" */
1219 if (already_selected
) {
1220 /* deselecting anything is OK with us */
1224 TreeModel::iterator iter
= model
->get_iter (path
);
1227 boost::shared_ptr
<Region
> r
=(*iter
)[_columns
.region
];
1237 EditorRegions::name_editing_started (CellEditable
* ce
, const Glib::ustring
&)
1241 /* give it a special name */
1243 Gtk::Entry
*e
= dynamic_cast<Gtk::Entry
*> (ce
);
1246 e
->set_name (X_("RegionNameEditorEntry"));
1251 EditorRegions::name_edit (const std::string
& path
, const std::string
& new_text
)
1255 boost::shared_ptr
<Region
> region
;
1258 if ((iter
= _model
->get_iter (path
))) {
1259 region
= (*iter
)[_columns
.region
];
1260 (*iter
)[_columns
.name
] = new_text
;
1263 /* now mapover everything */
1266 vector
<RegionView
*> equivalents
;
1267 _editor
->get_regions_corresponding_to (region
, equivalents
);
1269 for (vector
<RegionView
*>::iterator i
= equivalents
.begin(); i
!= equivalents
.end(); ++i
) {
1270 if (new_text
!= (*i
)->region()->name()) {
1271 (*i
)->region()->set_name (new_text
);
1278 /** @return Region that has been dragged out of the list, or 0 */
1279 boost::shared_ptr
<Region
>
1280 EditorRegions::get_dragged_region ()
1282 list
<boost::shared_ptr
<Region
> > regions
;
1284 _display
.get_object_drag_data (regions
, &source
);
1286 if (regions
.empty()) {
1287 return boost::shared_ptr
<Region
> ();
1290 assert (regions
.size() == 1);
1291 return regions
.front ();
1295 EditorRegions::clear ()
1297 _display
.set_model (Glib::RefPtr
<Gtk::TreeStore
> (0));
1299 _display
.set_model (_model
);
1301 /* Clean up the maps */
1302 region_row_map
.clear();
1303 parent_regions_sources_map
.clear();
1306 boost::shared_ptr
<Region
>
1307 EditorRegions::get_single_selection ()
1309 Glib::RefPtr
<TreeSelection
> selected
= _display
.get_selection();
1311 if (selected
->count_selected_rows() != 1) {
1312 return boost::shared_ptr
<Region
> ();
1315 TreeView::Selection::ListHandle_Path rows
= selected
->get_selected_rows ();
1317 /* only one row selected, so rows.begin() is it */
1319 TreeIter iter
= _model
->get_iter (*rows
.begin());
1322 return boost::shared_ptr
<Region
> ();
1325 return (*iter
)[_columns
.region
];
1329 EditorRegions::freeze_tree_model (){
1331 _display
.set_model (Glib::RefPtr
<Gtk::TreeStore
>(0));
1332 _model
->set_sort_column (-2, SORT_ASCENDING
); //Disable sorting to gain performance
1337 EditorRegions::thaw_tree_model (){
1339 _model
->set_sort_column (0, SORT_ASCENDING
); // renabale sorting
1340 _display
.set_model (_model
);
1342 if (toggle_full_action()->get_active()) {
1343 _display
.expand_all();
1348 EditorRegions::locked_changed (std::string
const & path
)
1350 TreeIter i
= _model
->get_iter (path
);
1352 boost::shared_ptr
<ARDOUR::Region
> region
= (*i
)[_columns
.region
];
1354 region
->set_locked (!(*i
)[_columns
.locked
]);
1360 EditorRegions::glued_changed (std::string
const & path
)
1362 TreeIter i
= _model
->get_iter (path
);
1364 boost::shared_ptr
<ARDOUR::Region
> region
= (*i
)[_columns
.region
];
1366 /* `glued' means MusicTime, and we're toggling here */
1367 region
->set_position_lock_style ((*i
)[_columns
.glued
] ? AudioTime
: MusicTime
);
1374 EditorRegions::muted_changed (std::string
const & path
)
1376 TreeIter i
= _model
->get_iter (path
);
1378 boost::shared_ptr
<ARDOUR::Region
> region
= (*i
)[_columns
.region
];
1380 region
->set_muted (!(*i
)[_columns
.muted
]);
1387 EditorRegions::opaque_changed (std::string
const & path
)
1389 TreeIter i
= _model
->get_iter (path
);
1391 boost::shared_ptr
<ARDOUR::Region
> region
= (*i
)[_columns
.region
];
1393 region
->set_opaque (!(*i
)[_columns
.opaque
]);
1400 EditorRegions::get_state () const
1402 XMLNode
* node
= new XMLNode (X_("RegionList"));
1404 node
->add_property (X_("sort-type"), enum_2_string (_sort_type
));
1406 RefPtr
<Action
> act
= ActionManager::get_action (X_("RegionList"), X_("SortAscending"));
1407 bool const ascending
= RefPtr
<RadioAction
>::cast_dynamic(act
)->get_active ();
1408 node
->add_property (X_("sort-ascending"), ascending
? "yes" : "no");
1409 node
->add_property (X_("show-all"), toggle_full_action()->get_active() ? "yes" : "no");
1410 node
->add_property (X_("show-automatic-regions"), _show_automatic_regions
? "yes" : "no");
1416 EditorRegions::set_state (const XMLNode
& node
)
1418 bool changed
= false;
1420 if (node
.name() != X_("RegionList")) {
1424 XMLProperty
const * p
= node
.property (X_("sort-type"));
1427 Editing::RegionListSortType
const t
= static_cast<Editing::RegionListSortType
> (string_2_enum (p
->value(), _sort_type
));
1429 if (_sort_type
!= t
) {
1433 reset_sort_type (t
, true);
1434 RefPtr
<RadioAction
> ract
= sort_type_action (t
);
1435 ract
->set_active ();
1438 p
= node
.property (X_("sort-ascending"));
1441 bool const yn
= string_is_affirmative (p
->value ());
1442 SortType old_sort_type
;
1443 int old_sort_column
;
1445 _model
->get_sort_column_id (old_sort_column
, old_sort_type
);
1447 if (old_sort_type
!= (yn
? SORT_ASCENDING
: SORT_DESCENDING
)) {
1451 reset_sort_direction (yn
);
1455 act
= ActionManager::get_action (X_("RegionList"), X_("SortAscending"));
1457 act
= ActionManager::get_action (X_("RegionList"), X_("SortDescending"));
1460 RefPtr
<RadioAction
>::cast_dynamic(act
)->set_active ();
1463 p
= node
.property (X_("show-all"));
1465 bool const yn
= string_is_affirmative (p
->value ());
1467 if (expanded
!= yn
) {
1472 toggle_full_action()->set_active (yn
);
1475 p
= node
.property (X_("show-automatic-regions"));
1477 bool const yn
= string_is_affirmative (p
->value ());
1479 if (yn
!= _show_automatic_regions
) {
1480 _show_automatic_regions
= yn
;
1481 toggle_show_auto_regions_action()->set_active (yn
);
1492 EditorRegions::sort_type_action (Editing::RegionListSortType t
) const
1494 const char* action
= 0;
1497 case Editing::ByName
:
1498 action
= X_("SortByRegionName");
1500 case Editing::ByLength
:
1501 action
= X_("SortByRegionLength");
1503 case Editing::ByPosition
:
1504 action
= X_("SortByRegionPosition");
1506 case Editing::ByTimestamp
:
1507 action
= X_("SortByRegionTimestamp");
1509 case Editing::ByStartInFile
:
1510 action
= X_("SortByRegionStartinFile");
1512 case Editing::ByEndInFile
:
1513 action
= X_("SortByRegionEndinFile");
1515 case Editing::BySourceFileName
:
1516 action
= X_("SortBySourceFileName");
1518 case Editing::BySourceFileLength
:
1519 action
= X_("SortBySourceFileLength");
1521 case Editing::BySourceFileCreationDate
:
1522 action
= X_("SortBySourceFileCreationDate");
1524 case Editing::BySourceFileFS
:
1525 action
= X_("SortBySourceFilesystem");
1528 fatal
<< string_compose (_("programming error: %1: %2"), "EditorRegions: impossible sort type", (int) t
) << endmsg
;
1532 RefPtr
<Action
> act
= ActionManager::get_action (X_("RegionList"), action
);
1535 return RefPtr
<RadioAction
>::cast_dynamic (act
);
1539 EditorRegions::hide_action () const
1541 return ActionManager::get_action (X_("RegionList"), X_("rlHide"));
1546 EditorRegions::show_action () const
1548 return ActionManager::get_action (X_("RegionList"), X_("rlShow"));
1552 EditorRegions::delete_unused_regions_action () const
1554 return ActionManager::get_action (X_("RegionList"), X_("removeUnusedRegions"));
1557 RefPtr
<ToggleAction
>
1558 EditorRegions::toggle_full_action () const
1560 Glib::RefPtr
<Action
> act
= ActionManager::get_action (X_("RegionList"), X_("rlShowAll"));
1562 return Glib::RefPtr
<ToggleAction
>::cast_dynamic (act
);
1565 RefPtr
<ToggleAction
>
1566 EditorRegions::toggle_show_auto_regions_action () const
1568 Glib::RefPtr
<Action
> act
= ActionManager::get_action (X_("RegionList"), X_("rlShowAuto"));
1570 return Glib::RefPtr
<ToggleAction
>::cast_dynamic (act
);