Scroll labels view with zoom.
[dcpomatic.git] / src / wx / timeline.cc
1 /*
2     Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "film_editor.h"
22 #include "timeline.h"
23 #include "timeline_time_axis_view.h"
24 #include "timeline_reels_view.h"
25 #include "timeline_labels_view.h"
26 #include "timeline_video_content_view.h"
27 #include "timeline_audio_content_view.h"
28 #include "timeline_subtitle_content_view.h"
29 #include "timeline_atmos_content_view.h"
30 #include "content_panel.h"
31 #include "wx_util.h"
32 #include "lib/film.h"
33 #include "lib/playlist.h"
34 #include "lib/image_content.h"
35 #include "lib/timer.h"
36 #include "lib/audio_content.h"
37 #include "lib/subtitle_content.h"
38 #include "lib/video_content.h"
39 #include "lib/atmos_mxf_content.h"
40 #include <wx/graphics.h>
41 #include <boost/weak_ptr.hpp>
42 #include <boost/foreach.hpp>
43 #include <list>
44 #include <iostream>
45
46 using std::list;
47 using std::cout;
48 using std::min;
49 using std::max;
50 using boost::shared_ptr;
51 using boost::weak_ptr;
52 using boost::dynamic_pointer_cast;
53 using boost::bind;
54 using boost::optional;
55
56 Timeline::Timeline (wxWindow* parent, ContentPanel* cp, shared_ptr<Film> film)
57         : wxPanel (parent, wxID_ANY)
58         , _labels_canvas (new wxScrolledCanvas (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE))
59         , _main_canvas (new wxScrolledCanvas (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE))
60         , _content_panel (cp)
61         , _film (film)
62         , _time_axis_view (new TimelineTimeAxisView (*this, 64))
63         , _reels_view (new TimelineReelsView (*this, 32))
64         , _labels_view (new TimelineLabelsView (*this))
65         , _tracks (0)
66         , _left_down (false)
67         , _down_view_position (0)
68         , _first_move (false)
69         , _menu (this)
70         , _snap (true)
71         , _tool (SELECT)
72         , _x_scroll_rate (16)
73         , _y_scroll_rate (16)
74         , _track_height (48)
75 {
76 #ifndef __WXOSX__
77         _labels_canvas->SetDoubleBuffered (true);
78         _main_canvas->SetDoubleBuffered (true);
79 #endif
80
81         wxSizer* sizer = new wxBoxSizer (wxHORIZONTAL);
82         sizer->Add (_labels_canvas, 0, wxEXPAND);
83         _labels_canvas->SetMinSize (wxSize (_labels_view->bbox().width, -1));
84         sizer->Add (_main_canvas, 1, wxEXPAND);
85         SetSizer (sizer);
86
87         _labels_canvas->Bind (wxEVT_PAINT,      boost::bind (&Timeline::paint_labels, this));
88         _main_canvas->Bind   (wxEVT_PAINT,      boost::bind (&Timeline::paint_main,   this));
89         _main_canvas->Bind   (wxEVT_LEFT_DOWN,  boost::bind (&Timeline::left_down,    this, _1));
90         _main_canvas->Bind   (wxEVT_LEFT_UP,    boost::bind (&Timeline::left_up,      this, _1));
91         _main_canvas->Bind   (wxEVT_RIGHT_DOWN, boost::bind (&Timeline::right_down,   this, _1));
92         _main_canvas->Bind   (wxEVT_MOTION,     boost::bind (&Timeline::mouse_moved,  this, _1));
93         _main_canvas->Bind   (wxEVT_SIZE,       boost::bind (&Timeline::resized,      this));
94
95         film_changed (Film::CONTENT);
96
97         SetMinSize (wxSize (640, 4 * track_height() + 96));
98
99         _film_changed_connection = film->Changed.connect (bind (&Timeline::film_changed, this, _1));
100         _film_content_changed_connection = film->ContentChanged.connect (bind (&Timeline::film_content_changed, this, _2, _3));
101
102         _pixels_per_second = max (0.01, static_cast<double>(640) / film->length().seconds ());
103
104         setup_scrollbars ();
105         _labels_canvas->ShowScrollbars (wxSHOW_SB_NEVER, wxSHOW_SB_NEVER);
106 }
107
108 void
109 Timeline::paint_labels ()
110 {
111         wxPaintDC dc (_labels_canvas);
112
113         wxGraphicsContext* gc = wxGraphicsContext::Create (dc);
114         if (!gc) {
115                 return;
116         }
117
118         int vsx, vsy;
119         _labels_canvas->GetViewStart (&vsx, &vsy);
120         gc->Translate (-vsx * _x_scroll_rate, -vsy * _y_scroll_rate);
121
122         _labels_view->paint (gc, list<dcpomatic::Rect<int> >());
123
124         delete gc;
125 }
126
127 void
128 Timeline::paint_main ()
129 {
130         wxPaintDC dc (_main_canvas);
131         _main_canvas->DoPrepareDC (dc);
132
133         wxGraphicsContext* gc = wxGraphicsContext::Create (dc);
134         if (!gc) {
135                 return;
136         }
137
138         int vsx, vsy;
139         _main_canvas->GetViewStart (&vsx, &vsy);
140         gc->Translate (-vsx * _x_scroll_rate, -vsy * _y_scroll_rate);
141
142         gc->SetAntialiasMode (wxANTIALIAS_DEFAULT);
143
144         BOOST_FOREACH (shared_ptr<TimelineView> i, _views) {
145
146                 shared_ptr<TimelineContentView> ic = dynamic_pointer_cast<TimelineContentView> (i);
147
148                 /* Find areas of overlap with other content views, so that we can plot them */
149                 list<dcpomatic::Rect<int> > overlaps;
150                 BOOST_FOREACH (shared_ptr<TimelineView> j, _views) {
151                         shared_ptr<TimelineContentView> jc = dynamic_pointer_cast<TimelineContentView> (j);
152                         /* No overlap with non-content views, views no different tracks, audio views or non-active views */
153                         if (!ic || !jc || i == j || ic->track() != jc->track() || ic->track().get_value_or(2) >= 2 || !ic->active() || !jc->active()) {
154                                 continue;
155                         }
156
157                         optional<dcpomatic::Rect<int> > r = j->bbox().intersection (i->bbox());
158                         if (r) {
159                                 overlaps.push_back (r.get ());
160                         }
161                 }
162
163                 i->paint (gc, overlaps);
164         }
165
166         if (_zoom_point) {
167                 /* Translate back as _down_point and _zoom_point do not take scroll into account */
168                 gc->Translate (vsx * _x_scroll_rate, vsy * _y_scroll_rate);
169                 gc->SetPen (*wxBLACK_PEN);
170                 gc->SetBrush (*wxTRANSPARENT_BRUSH);
171                 gc->DrawRectangle (
172                         min (_down_point.x, _zoom_point->x),
173                         min (_down_point.y, _zoom_point->y),
174                         fabs (_down_point.x - _zoom_point->x),
175                         fabs (_down_point.y - _zoom_point->y)
176                         );
177         }
178
179         delete gc;
180 }
181
182 void
183 Timeline::film_changed (Film::Property p)
184 {
185         if (p == Film::CONTENT || p == Film::REEL_TYPE || p == Film::REEL_LENGTH) {
186                 ensure_ui_thread ();
187                 recreate_views ();
188         } else if (p == Film::CONTENT_ORDER) {
189                 Refresh ();
190         }
191 }
192
193 void
194 Timeline::recreate_views ()
195 {
196         shared_ptr<const Film> film = _film.lock ();
197         if (!film) {
198                 return;
199         }
200
201         _views.clear ();
202         _views.push_back (_time_axis_view);
203         _views.push_back (_reels_view);
204
205         BOOST_FOREACH (shared_ptr<Content> i, film->content ()) {
206                 if (i->video) {
207                         _views.push_back (shared_ptr<TimelineView> (new TimelineVideoContentView (*this, i)));
208                 }
209
210                 if (i->audio && !i->audio->mapping().mapped_output_channels().empty ()) {
211                         _views.push_back (shared_ptr<TimelineView> (new TimelineAudioContentView (*this, i)));
212                 }
213
214                 if (i->subtitle) {
215                         _views.push_back (shared_ptr<TimelineView> (new TimelineSubtitleContentView (*this, i)));
216                 }
217
218                 if (dynamic_pointer_cast<AtmosMXFContent> (i)) {
219                         _views.push_back (shared_ptr<TimelineView> (new TimelineAtmosContentView (*this, i)));
220                 }
221         }
222
223         assign_tracks ();
224         setup_scrollbars ();
225         Refresh ();
226 }
227
228 void
229 Timeline::film_content_changed (int property, bool frequent)
230 {
231         ensure_ui_thread ();
232
233         if (property == AudioContentProperty::STREAMS) {
234                 recreate_views ();
235         } else if (!frequent) {
236                 setup_scrollbars ();
237                 Refresh ();
238         }
239 }
240
241 template <class T>
242 int
243 place (TimelineViewList& views, int& tracks)
244 {
245         int const base = tracks;
246
247         BOOST_FOREACH (shared_ptr<TimelineView> i, views) {
248                 if (!dynamic_pointer_cast<T>(i)) {
249                         continue;
250                 }
251
252                 shared_ptr<TimelineContentView> cv = dynamic_pointer_cast<TimelineContentView> (i);
253
254                 int t = base;
255
256                 shared_ptr<Content> content = cv->content();
257                 DCPTimePeriod const content_period (content->position(), content->end());
258
259                 while (true) {
260                         TimelineViewList::iterator j = views.begin();
261                         while (j != views.end()) {
262                                 shared_ptr<T> test = dynamic_pointer_cast<T> (*j);
263                                 if (!test) {
264                                         ++j;
265                                         continue;
266                                 }
267
268                                 shared_ptr<Content> test_content = test->content();
269                                 if (
270                                         test->track() && test->track().get() == t &&
271                                         content_period.overlap(DCPTimePeriod(test_content->position(), test_content->end()))) {
272                                         /* we have an overlap on track `t' */
273                                         ++t;
274                                         break;
275                                 }
276
277                                 ++j;
278                         }
279
280                         if (j == views.end ()) {
281                                 /* no overlap on `t' */
282                                 break;
283                         }
284                 }
285
286                 cv->set_track (t);
287                 tracks = max (tracks, t + 1);
288         }
289
290         return tracks - base;
291 }
292
293 void
294 Timeline::assign_tracks ()
295 {
296         /* Tracks are:
297            Video (mono or left-eye)
298            Video (right-eye)
299            Subtitle 1
300            Subtitle 2
301            Subtitle N
302            Atmos
303            Audio 1
304            Audio 2
305            Audio N
306         */
307
308         _tracks = 0;
309
310         for (TimelineViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
311                 shared_ptr<TimelineContentView> c = dynamic_pointer_cast<TimelineContentView> (*i);
312                 if (c) {
313                         c->unset_track ();
314                 }
315         }
316
317         /* Video */
318
319         bool have_3d = false;
320         BOOST_FOREACH (shared_ptr<TimelineView> i, _views) {
321                 shared_ptr<TimelineVideoContentView> cv = dynamic_pointer_cast<TimelineVideoContentView> (i);
322                 if (!cv) {
323                         continue;
324                 }
325
326                 /* Video on tracks 0 and maybe 1 (left and right eye) */
327                 if (cv->content()->video->frame_type() == VIDEO_FRAME_TYPE_3D_RIGHT) {
328                         cv->set_track (1);
329                         _tracks = max (_tracks, 2);
330                         have_3d = true;
331                 } else {
332                         cv->set_track (0);
333                 }
334         }
335
336         _tracks = max (_tracks, 1);
337
338         /* Subtitle */
339
340         int const subtitle_tracks = place<TimelineSubtitleContentView> (_views, _tracks);
341
342         /* Atmos */
343
344         bool have_atmos = false;
345         BOOST_FOREACH (shared_ptr<TimelineView> i, _views) {
346                 shared_ptr<TimelineVideoContentView> cv = dynamic_pointer_cast<TimelineVideoContentView> (i);
347                 if (!cv) {
348                         continue;
349                 }
350                 if (dynamic_pointer_cast<TimelineAtmosContentView> (i)) {
351                         cv->set_track (_tracks - 1);
352                         have_atmos = true;
353                 }
354         }
355
356         if (have_atmos) {
357                 ++_tracks;
358         }
359
360         /* Audio */
361
362         place<TimelineAudioContentView> (_views, _tracks);
363
364         _labels_view->set_3d (have_3d);
365         _labels_view->set_subtitle_tracks (subtitle_tracks);
366         _labels_view->set_atmos (have_atmos);
367
368         _time_axis_view->set_y (tracks() * track_height() + 64);
369         _reels_view->set_y (8);
370 }
371
372 int
373 Timeline::tracks () const
374 {
375         return _tracks;
376 }
377
378 void
379 Timeline::setup_scrollbars ()
380 {
381         shared_ptr<const Film> film = _film.lock ();
382         if (!film || !_pixels_per_second) {
383                 return;
384         }
385         _labels_canvas->SetVirtualSize (_labels_view->bbox().width, tracks() * track_height() + 96);
386         _labels_canvas->SetScrollRate (_x_scroll_rate, _y_scroll_rate);
387         _main_canvas->SetVirtualSize (*_pixels_per_second * film->length().seconds(), tracks() * track_height() + 96);
388         _main_canvas->SetScrollRate (_x_scroll_rate, _y_scroll_rate);
389 }
390
391 shared_ptr<TimelineView>
392 Timeline::event_to_view (wxMouseEvent& ev)
393 {
394         /* Search backwards through views so that we find the uppermost one first */
395         TimelineViewList::reverse_iterator i = _views.rbegin();
396         Position<int> const p (ev.GetX(), ev.GetY());
397         while (i != _views.rend() && !(*i)->bbox().contains (p)) {
398                 shared_ptr<TimelineContentView> cv = dynamic_pointer_cast<TimelineContentView> (*i);
399                 ++i;
400         }
401
402         if (i == _views.rend ()) {
403                 return shared_ptr<TimelineView> ();
404         }
405
406         return *i;
407 }
408
409 void
410 Timeline::left_down (wxMouseEvent& ev)
411 {
412         _left_down = true;
413         _down_point = ev.GetPosition ();
414
415         switch (_tool) {
416         case SELECT:
417                 left_down_select (ev);
418                 break;
419         case ZOOM:
420                 /* Nothing to do */
421                 break;
422         }
423 }
424
425 void
426 Timeline::left_down_select (wxMouseEvent& ev)
427 {
428         shared_ptr<TimelineView> view = event_to_view (ev);
429         shared_ptr<TimelineContentView> content_view = dynamic_pointer_cast<TimelineContentView> (view);
430
431         _down_view.reset ();
432
433         if (content_view) {
434                 _down_view = content_view;
435                 _down_view_position = content_view->content()->position ();
436         }
437
438         for (TimelineViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
439                 shared_ptr<TimelineContentView> cv = dynamic_pointer_cast<TimelineContentView> (*i);
440                 if (!cv) {
441                         continue;
442                 }
443
444                 if (!ev.ShiftDown ()) {
445                         cv->set_selected (view == *i);
446                 }
447         }
448
449         if (content_view && ev.ShiftDown ()) {
450                 content_view->set_selected (!content_view->selected ());
451         }
452
453         _first_move = false;
454
455         if (_down_view) {
456                 /* Pre-compute the points that we might snap to */
457                 for (TimelineViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
458                         shared_ptr<TimelineContentView> cv = dynamic_pointer_cast<TimelineContentView> (*i);
459                         if (!cv || cv == _down_view || cv->content() == _down_view->content()) {
460                                 continue;
461                         }
462
463                         _start_snaps.push_back (cv->content()->position());
464                         _end_snaps.push_back (cv->content()->position());
465                         _start_snaps.push_back (cv->content()->end());
466                         _end_snaps.push_back (cv->content()->end());
467
468                         BOOST_FOREACH (DCPTime i, cv->content()->reel_split_points()) {
469                                 _start_snaps.push_back (i);
470                         }
471                 }
472
473                 /* Tell everyone that things might change frequently during the drag */
474                 _down_view->content()->set_change_signals_frequent (true);
475         }
476 }
477
478 void
479 Timeline::left_up (wxMouseEvent& ev)
480 {
481         _left_down = false;
482
483         switch (_tool) {
484         case SELECT:
485                 left_up_select (ev);
486                 break;
487         case ZOOM:
488                 left_up_zoom (ev);
489                 break;
490         }
491 }
492
493 void
494 Timeline::left_up_select (wxMouseEvent& ev)
495 {
496         if (_down_view) {
497                 _down_view->content()->set_change_signals_frequent (false);
498         }
499
500         _content_panel->set_selection (selected_content ());
501         set_position_from_event (ev);
502
503         /* Clear up up the stuff we don't do during drag */
504         assign_tracks ();
505         setup_scrollbars ();
506         Refresh ();
507
508         _start_snaps.clear ();
509         _end_snaps.clear ();
510 }
511
512 void
513 Timeline::left_up_zoom (wxMouseEvent& ev)
514 {
515         _zoom_point = ev.GetPosition ();
516
517         int vsx, vsy;
518         _main_canvas->GetViewStart (&vsx, &vsy);
519
520         wxPoint top_left(min(_down_point.x, _zoom_point->x), min(_down_point.y, _zoom_point->y));
521         wxPoint bottom_right(max(_down_point.x, _zoom_point->x), max(_down_point.y, _zoom_point->y));
522
523         DCPTime const time_left = DCPTime::from_seconds((top_left.x + vsx) / *_pixels_per_second);
524         DCPTime const time_right = DCPTime::from_seconds((bottom_right.x + vsx) / *_pixels_per_second);
525         _pixels_per_second = GetSize().GetWidth() / (time_right.seconds() - time_left.seconds());
526
527         double const tracks_top = double(top_left.y) / _track_height;
528         double const tracks_bottom = double(bottom_right.y) / _track_height;
529         _track_height = GetSize().GetHeight() / (tracks_bottom - tracks_top);
530
531         setup_scrollbars ();
532         _main_canvas->Scroll (time_left.seconds() * *_pixels_per_second / _x_scroll_rate, tracks_top * _track_height / _y_scroll_rate);
533         _labels_canvas->Scroll (0, tracks_top * _track_height / _y_scroll_rate);
534
535         _zoom_point = optional<wxPoint> ();
536         Refresh ();
537 }
538
539 void
540 Timeline::mouse_moved (wxMouseEvent& ev)
541 {
542         switch (_tool) {
543         case SELECT:
544                 mouse_moved_select (ev);
545                 break;
546         case ZOOM:
547                 mouse_moved_zoom (ev);
548                 break;
549         }
550 }
551
552 void
553 Timeline::mouse_moved_select (wxMouseEvent& ev)
554 {
555         if (!_left_down) {
556                 return;
557         }
558
559         set_position_from_event (ev);
560 }
561
562 void
563 Timeline::mouse_moved_zoom (wxMouseEvent& ev)
564 {
565         if (!_left_down) {
566                 return;
567         }
568
569         _zoom_point = ev.GetPosition ();
570         Refresh ();
571 }
572
573 void
574 Timeline::right_down (wxMouseEvent& ev)
575 {
576         switch (_tool) {
577         case SELECT:
578                 right_down_select (ev);
579                 break;
580         case ZOOM:
581                 /* Zoom out */
582                 _pixels_per_second = *_pixels_per_second / 2;
583                 _track_height = max (8, _track_height / 2);
584                 setup_scrollbars ();
585                 break;
586         }
587 }
588
589 void
590 Timeline::right_down_select (wxMouseEvent& ev)
591 {
592         shared_ptr<TimelineView> view = event_to_view (ev);
593         shared_ptr<TimelineContentView> cv = dynamic_pointer_cast<TimelineContentView> (view);
594         if (!cv) {
595                 return;
596         }
597
598         if (!cv->selected ()) {
599                 clear_selection ();
600                 cv->set_selected (true);
601         }
602
603         _menu.popup (_film, selected_content (), selected_views (), ev.GetPosition ());
604 }
605
606 void
607 Timeline::maybe_snap (DCPTime a, DCPTime b, optional<DCPTime>& nearest_distance) const
608 {
609         DCPTime const d = a - b;
610         if (!nearest_distance || d.abs() < nearest_distance.get().abs()) {
611                 nearest_distance = d;
612         }
613 }
614
615 void
616 Timeline::set_position_from_event (wxMouseEvent& ev)
617 {
618         if (!_pixels_per_second) {
619                 return;
620         }
621
622         double const pps = _pixels_per_second.get ();
623
624         wxPoint const p = ev.GetPosition();
625
626         if (!_first_move) {
627                 /* We haven't moved yet; in that case, we must move the mouse some reasonable distance
628                    before the drag is considered to have started.
629                 */
630                 int const dist = sqrt (pow (p.x - _down_point.x, 2) + pow (p.y - _down_point.y, 2));
631                 if (dist < 8) {
632                         return;
633                 }
634                 _first_move = true;
635         }
636
637         if (!_down_view) {
638                 return;
639         }
640
641         DCPTime new_position = _down_view_position + DCPTime::from_seconds ((p.x - _down_point.x) / pps);
642
643         if (_snap) {
644
645                 DCPTime const new_end = new_position + _down_view->content()->length_after_trim();
646                 /* Signed `distance' to nearest thing (i.e. negative is left on the timeline,
647                    positive is right).
648                 */
649                 optional<DCPTime> nearest_distance;
650
651                 /* Find the nearest snap point */
652
653                 BOOST_FOREACH (DCPTime i, _start_snaps) {
654                         maybe_snap (i, new_position, nearest_distance);
655                 }
656
657                 BOOST_FOREACH (DCPTime i, _end_snaps) {
658                         maybe_snap (i, new_end, nearest_distance);
659                 }
660
661                 if (nearest_distance) {
662                         /* Snap if it's close; `close' means within a proportion of the time on the timeline */
663                         if (nearest_distance.get().abs() < DCPTime::from_seconds ((width() / pps) / 64)) {
664                                 new_position += nearest_distance.get ();
665                         }
666                 }
667         }
668
669         if (new_position < DCPTime ()) {
670                 new_position = DCPTime ();
671         }
672
673         _down_view->content()->set_position (new_position);
674
675         shared_ptr<Film> film = _film.lock ();
676         DCPOMATIC_ASSERT (film);
677         film->set_sequence (false);
678 }
679
680 void
681 Timeline::force_redraw (dcpomatic::Rect<int> const & r)
682 {
683         RefreshRect (wxRect (r.x, r.y, r.width, r.height), false);
684 }
685
686 shared_ptr<const Film>
687 Timeline::film () const
688 {
689         return _film.lock ();
690 }
691
692 void
693 Timeline::resized ()
694 {
695         setup_scrollbars ();
696 }
697
698 void
699 Timeline::clear_selection ()
700 {
701         for (TimelineViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
702                 shared_ptr<TimelineContentView> cv = dynamic_pointer_cast<TimelineContentView> (*i);
703                 if (cv) {
704                         cv->set_selected (false);
705                 }
706         }
707 }
708
709 TimelineContentViewList
710 Timeline::selected_views () const
711 {
712         TimelineContentViewList sel;
713
714         for (TimelineViewList::const_iterator i = _views.begin(); i != _views.end(); ++i) {
715                 shared_ptr<TimelineContentView> cv = dynamic_pointer_cast<TimelineContentView> (*i);
716                 if (cv && cv->selected()) {
717                         sel.push_back (cv);
718                 }
719         }
720
721         return sel;
722 }
723
724 ContentList
725 Timeline::selected_content () const
726 {
727         ContentList sel;
728         TimelineContentViewList views = selected_views ();
729
730         for (TimelineContentViewList::const_iterator i = views.begin(); i != views.end(); ++i) {
731                 sel.push_back ((*i)->content ());
732         }
733
734         return sel;
735 }
736
737 void
738 Timeline::set_selection (ContentList selection)
739 {
740         for (TimelineViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
741                 shared_ptr<TimelineContentView> cv = dynamic_pointer_cast<TimelineContentView> (*i);
742                 if (cv) {
743                         cv->set_selected (find (selection.begin(), selection.end(), cv->content ()) != selection.end ());
744                 }
745         }
746 }