Remove PositionChanged in favour of consumers having their own GUI-thread timers.
authorCarl Hetherington <cth@carlh.net>
Tue, 5 Nov 2019 22:51:20 +0000 (23:51 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 8 Jan 2020 20:56:47 +0000 (21:56 +0100)
src/wx/controls.cc
src/wx/controls.h
src/wx/film_viewer.cc
src/wx/film_viewer.h
src/wx/simple_video_view.cc
src/wx/swaroop_controls.cc
src/wx/swaroop_controls.h
src/wx/timeline.cc
src/wx/timeline.h

index b173b43..71af4e8 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2018 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2018-2019 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
@@ -67,6 +67,7 @@ Controls::Controls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor
        , _forward_button (new Button (this, wxT(">")))
        , _frame_number (new StaticText (this, wxT("")))
        , _timecode (new StaticText (this, wxT("")))
+       , _timer (this)
 {
        _v_sizer = new wxBoxSizer (wxVERTICAL);
        SetSizer (_v_sizer);
@@ -137,10 +138,12 @@ Controls::Controls (wxWindow* parent, shared_ptr<FilmViewer> viewer, bool editor
                _jump_to_selected->SetValue (Config::instance()->jump_to_selected ());
        }
 
-       _viewer->PositionChanged.connect (boost::bind(&Controls::position_changed, this));
        _viewer->Started.connect (boost::bind(&Controls::started, this));
        _viewer->Stopped.connect (boost::bind(&Controls::stopped, this));
 
+       Bind (wxEVT_TIMER, boost::bind(&Controls::update_position, this));
+       _timer.Start (80, wxTIMER_CONTINUOUS);
+
        set_film (_viewer->film());
 
        setup_sensitivity ();
@@ -172,7 +175,7 @@ Controls::stopped ()
 }
 
 void
-Controls::position_changed ()
+Controls::update_position ()
 {
        if (!_slider_being_moved) {
                update_position_label ();
index dfa11e6..0144644 100644 (file)
@@ -87,7 +87,7 @@ private:
        void image_changed (boost::weak_ptr<PlayerVideo>);
        void outline_content_changed ();
        void eye_changed ();
-       void position_changed ();
+       void update_position ();
        void film_change (ChangeType, Film::Property);
 
        typedef std::pair<boost::shared_ptr<dcp::CPL>, boost::filesystem::path> CPL;
@@ -105,6 +105,8 @@ private:
 
        ClosedCaptionsDialog* _closed_captions_dialog;
 
+       wxTimer _timer;
+
        boost::signals2::scoped_connection _film_change_connection;
        boost::signals2::scoped_connection _config_changed_connection;
 };
index dc6ed10..5c73f29 100644 (file)
@@ -256,7 +256,6 @@ FilmViewer::video_view_sized ()
        if (!quick_refresh()) {
                slow_refresh ();
        }
-       PositionChanged ();
 }
 
 void
@@ -380,7 +379,6 @@ FilmViewer::player_change (ChangeType type, int property, bool frequent)
        if (!refreshed) {
                slow_refresh ();
        }
-       PositionChanged ();
 }
 
 void
index a59468c..6b6aa78 100644 (file)
@@ -141,7 +141,6 @@ public:
        int time_until_next_frame () const;
 
        boost::signals2::signal<void (boost::weak_ptr<PlayerVideo>)> ImageChanged;
-       boost::signals2::signal<void ()> PositionChanged;
        boost::signals2::signal<void (dcpomatic::DCPTime)> Started;
        boost::signals2::signal<void (dcpomatic::DCPTime)> Stopped;
        /** While playing back we reached the end of the film (emitted from GUI thread) */
index 1e97adb..619a35c 100644 (file)
@@ -193,7 +193,6 @@ SimpleVideoView::get (bool lazy)
        }
 
        display_player_video ();
-       _viewer->PositionChanged ();
 
        return true;
 }
index 5ce6c45..add9bf3 100644 (file)
@@ -54,6 +54,7 @@ SwaroopControls::SwaroopControls (wxWindow* parent, shared_ptr<FilmViewer> viewe
        , _previous_button (new Button(this, "Previous"))
        , _current_disable_timeline (false)
        , _current_disable_next (false)
+       , _timer (this)
 {
        _button_sizer->Add (_previous_button, 0, wxEXPAND);
        _button_sizer->Add (_play_button, 0, wxEXPAND);
@@ -112,10 +113,13 @@ SwaroopControls::SwaroopControls (wxWindow* parent, shared_ptr<FilmViewer> viewe
        _spl_view->Bind        (wxEVT_LIST_ITEM_SELECTED,   boost::bind(&SwaroopControls::spl_selection_changed, this));
        _spl_view->Bind        (wxEVT_LIST_ITEM_DESELECTED, boost::bind(&SwaroopControls::spl_selection_changed, this));
        _viewer->Finished.connect (boost::bind(&SwaroopControls::viewer_finished, this));
-       _viewer->PositionChanged.connect (boost::bind(&SwaroopControls::viewer_position_changed, this));
        _refresh_spl_view->Bind (wxEVT_BUTTON, boost::bind(&SwaroopControls::update_playlist_directory, this));
        _refresh_content_view->Bind (wxEVT_BUTTON, boost::bind(&ContentView::update, _content_view));
 
+       /* Write position every two minutes if we're playing */
+       Bind (wxEVT_TIMER, boost::bind(&SwaroopControls::write_position, this));
+       _timer.Start (2 * 60 * 1000, wxTIMER_CONTINUOUS);
+
        _content_view->update ();
        update_playlist_directory ();
 
@@ -153,10 +157,9 @@ SwaroopControls::check_restart ()
 }
 
 void
-SwaroopControls::viewer_position_changed ()
+SwaroopControls::write_position ()
 {
-       /* Write position every two minutes if we're playing */
-       if (!_selected_playlist || !_viewer->playing() || _viewer->position().get() % (2 * 60 * DCPTime::HZ)) {
+       if (!_selected_playlist || !_viewer->playing()) {
                return;
        }
 
index 11dbcfc..a8bb41d 100644 (file)
@@ -54,7 +54,7 @@ private:
        void setup_sensitivity ();
        void config_changed (int);
        void viewer_finished ();
-       void viewer_position_changed ();
+       void write_position ();
        void reset_film ();
        void update_current_content ();
        bool can_do_previous ();
@@ -84,4 +84,6 @@ private:
        std::vector<SPL> _playlists;
        boost::optional<int> _selected_playlist;
        int _selected_playlist_position;
+
+       wxTimer _timer;
 };
index daeeb0a..9f71847 100644 (file)
@@ -82,6 +82,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 +117,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 ();
 }
index ef887da..44a8973 100644 (file)
@@ -104,7 +104,7 @@ private:
        void set_pixels_per_second (double pps);
        void set_pixels_per_track (int h);
        void zoom_all ();
-       void position_change ();
+       void update_playhead ();
 
        boost::shared_ptr<TimelineView> event_to_view (wxMouseEvent &);
        TimelineContentViewList selected_views () const;
@@ -137,11 +137,11 @@ private:
        int _y_scroll_rate;
        int _pixels_per_track;
        bool _first_resize;
+       wxTimer _timer;
 
        static double const _minimum_pixels_per_second;
        static int const _minimum_pixels_per_track;
 
        boost::signals2::scoped_connection _film_changed_connection;
        boost::signals2::scoped_connection _film_content_change_connection;
-       boost::signals2::scoped_connection _viewer_position_change_connection;
 };