BOOST_FOREACH.
[dcpomatic.git] / src / wx / timeline.cc
index cac9318cca2eac486aee8ce30cb40c87f08a872f..e5182a0a4018139076f4e01b3e3e6fcea5209d93 100644 (file)
@@ -39,8 +39,6 @@
 #include "lib/video_content.h"
 #include "lib/atmos_mxf_content.h"
 #include <wx/graphics.h>
-#include <boost/weak_ptr.hpp>
-#include <boost/foreach.hpp>
 #include <list>
 #include <iterator>
 #include <iostream>
@@ -50,12 +48,15 @@ using std::cout;
 using std::min;
 using std::max;
 using std::abs;
-using boost::shared_ptr;
-using boost::weak_ptr;
-using boost::dynamic_pointer_cast;
+using std::shared_ptr;
+using std::weak_ptr;
+using std::dynamic_pointer_cast;
 using boost::bind;
 using boost::optional;
 using namespace dcpomatic;
+#if BOOST_VERSION >= 106100
+using namespace boost::placeholders;
+#endif
 
 /* 3 hours in 640 pixels */
 double const Timeline::_minimum_pixels_per_second = 640.0 / (60 * 60 * 3);
@@ -82,6 +83,7 @@ Timeline::Timeline (wxWindow* parent, ContentPanel* cp, shared_ptr<Film> film, w
        , _y_scroll_rate (16)
        , _pixels_per_track (48)
        , _first_resize (true)
+       , _timer (this)
 {
 #ifndef __WXOSX__
        _labels_canvas->SetDoubleBuffered (true);
@@ -116,16 +118,15 @@ Timeline::Timeline (wxWindow* parent, ContentPanel* cp, shared_ptr<Film> film, w
        _film_changed_connection = film->Change.connect (bind (&Timeline::film_change, this, _1, _2));
        _film_content_change_connection = film->ContentChange.connect (bind (&Timeline::film_content_change, this, _1, _3, _4));
 
-       shared_ptr<FilmViewer> vp = viewer.lock ();
-       DCPOMATIC_ASSERT (vp);
-       _viewer_position_change_connection = vp->PositionChanged.connect (bind(&Timeline::position_change, this));
+       Bind (wxEVT_TIMER, boost::bind(&Timeline::update_playhead, this));
+       _timer.Start (200, wxTIMER_CONTINUOUS);
 
        setup_scrollbars ();
        _labels_canvas->ShowScrollbars (wxSHOW_SB_NEVER, wxSHOW_SB_NEVER);
 }
 
 void
-Timeline::position_change ()
+Timeline::update_playhead ()
 {
        Refresh ();
 }
@@ -172,13 +173,13 @@ Timeline::paint_main ()
 
        gc->SetAntialiasMode (wxANTIALIAS_DEFAULT);
 
-       BOOST_FOREACH (shared_ptr<TimelineView> i, _views) {
+       for (auto i: _views) {
 
                shared_ptr<TimelineContentView> ic = dynamic_pointer_cast<TimelineContentView> (i);
 
                /* Find areas of overlap with other content views, so that we can plot them */
                list<dcpomatic::Rect<int> > overlaps;
-               BOOST_FOREACH (shared_ptr<TimelineView> j, _views) {
+               for (auto j: _views) {
                        shared_ptr<TimelineContentView> jc = dynamic_pointer_cast<TimelineContentView> (j);
                        /* No overlap with non-content views, views no different tracks, audio views or non-active views */
                        if (!ic || !jc || i == j || ic->track() != jc->track() || ic->track().get_value_or(2) >= 2 || !ic->active() || !jc->active()) {
@@ -249,7 +250,7 @@ Timeline::recreate_views ()
        _views.push_back (_time_axis_view);
        _views.push_back (_reels_view);
 
-       BOOST_FOREACH (shared_ptr<Content> i, film->content ()) {
+       for (auto i: film->content ()) {
                if (i->video) {
                        _views.push_back (shared_ptr<TimelineView> (new TimelineVideoContentView (*this, i)));
                }
@@ -258,12 +259,12 @@ Timeline::recreate_views ()
                        _views.push_back (shared_ptr<TimelineView> (new TimelineAudioContentView (*this, i)));
                }
 
-               BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
+               for (auto j: i->text) {
                        _views.push_back (shared_ptr<TimelineView> (new TimelineTextContentView (*this, i, j)));
                }
 
-               if (dynamic_pointer_cast<AtmosMXFContent> (i)) {
-                       _views.push_back (shared_ptr<TimelineView> (new TimelineAtmosContentView (*this, i)));
+               if (i->atmos) {
+                       _views.push_back (shared_ptr<TimelineView>(new TimelineAtmosContentView(*this, i)));
                }
        }
 
@@ -297,7 +298,7 @@ place (shared_ptr<const Film> film, TimelineViewList& views, int& tracks)
 {
        int const base = tracks;
 
-       BOOST_FOREACH (shared_ptr<TimelineView> i, views) {
+       for (auto i: views) {
                if (!dynamic_pointer_cast<T>(i)) {
                        continue;
                }
@@ -394,7 +395,7 @@ Timeline::assign_tracks ()
        /* Video */
 
        bool have_3d = false;
-       BOOST_FOREACH (shared_ptr<TimelineView> i, _views) {
+       for (auto i: _views) {
                shared_ptr<TimelineVideoContentView> cv = dynamic_pointer_cast<TimelineVideoContentView> (i);
                if (!cv) {
                        continue;
@@ -419,13 +420,10 @@ Timeline::assign_tracks ()
        /* Atmos */
 
        bool have_atmos = false;
-       BOOST_FOREACH (shared_ptr<TimelineView> i, _views) {
-               shared_ptr<TimelineVideoContentView> cv = dynamic_pointer_cast<TimelineVideoContentView> (i);
-               if (!cv) {
-                       continue;
-               }
-               if (dynamic_pointer_cast<TimelineAtmosContentView> (i)) {
-                       cv->set_track (_tracks - 1);
+       for (auto i: _views) {
+               shared_ptr<TimelineAtmosContentView> cv = dynamic_pointer_cast<TimelineAtmosContentView>(i);
+               if (cv) {
+                       cv->set_track (_tracks);
                        have_atmos = true;
                }
        }
@@ -478,7 +476,11 @@ Timeline::event_to_view (wxMouseEvent& ev)
 {
        /* Search backwards through views so that we find the uppermost one first */
        TimelineViewList::reverse_iterator i = _views.rbegin();
-       Position<int> const p (ev.GetX(), ev.GetY());
+
+       int vsx, vsy;
+       _main_canvas->GetViewStart (&vsx, &vsy);
+       Position<int> const p (ev.GetX() + vsx * _x_scroll_rate, ev.GetY() + vsy * _y_scroll_rate);
+
        while (i != _views.rend() && !(*i)->bbox().contains (p)) {
                shared_ptr<TimelineContentView> cv = dynamic_pointer_cast<TimelineContentView> (*i);
                ++i;
@@ -556,7 +558,7 @@ Timeline::left_down_select (wxMouseEvent& ev)
                        _start_snaps.push_back (cv->content()->end(film));
                        _end_snaps.push_back (cv->content()->end(film));
 
-                       BOOST_FOREACH (DCPTime i, cv->content()->reel_split_points(film)) {
+                       for (auto i: cv->content()->reel_split_points(film)) {
                                _start_snaps.push_back (i);
                        }
                }
@@ -773,11 +775,11 @@ Timeline::set_position_from_event (wxMouseEvent& ev, bool force_emit)
 
                /* Find the nearest snap point */
 
-               BOOST_FOREACH (DCPTime i, _start_snaps) {
+               for (auto i: _start_snaps) {
                        maybe_snap (i, new_position, nearest_distance);
                }
 
-               BOOST_FOREACH (DCPTime i, _end_snaps) {
+               for (auto i: _end_snaps) {
                        maybe_snap (i, new_end, nearest_distance);
                }