X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fcontrols.cc;h=804b59daec390173e28931f9e65fb6c2f8397f8e;hb=b7e65adf286ce20918797a06a910ededf8f07b7b;hp=c02581cc0ec3ad3dff7833481ea5bc1cf89394ba;hpb=db845a29ef318bc08c4d713c4c47ec5203867c0d;p=dcpomatic.git diff --git a/src/wx/controls.cc b/src/wx/controls.cc index c02581cc0..804b59dae 100644 --- a/src/wx/controls.cc +++ b/src/wx/controls.cc @@ -36,6 +36,7 @@ #include "lib/job.h" #include "lib/job_manager.h" #include "lib/player_video.h" +#include "lib/scope_guard.h" #include #include #include @@ -64,7 +65,7 @@ using namespace boost::placeholders; using namespace dcpomatic; -Controls::Controls (wxWindow* parent, shared_ptr viewer, bool editor_controls) +Controls::Controls(wxWindow* parent, FilmViewer& viewer, bool editor_controls) : wxPanel (parent) , _markers (new MarkersPanel(this, viewer)) , _slider (new wxSlider(this, wxID_ANY, 0, 0, 4096)) @@ -137,7 +138,7 @@ Controls::Controls (wxWindow* parent, shared_ptr viewer, bool editor _eye->Bind (wxEVT_CHOICE, boost::bind (&Controls::eye_changed, this)); } if (_outline_content) { - _outline_content->Bind (wxEVT_CHECKBOX, boost::bind (&Controls::outline_content_changed, this)); + _outline_content->bind(&Controls::outline_content_changed, this); } _slider->Bind (wxEVT_SCROLL_THUMBTRACK, boost::bind(&Controls::slider_moved, this, false)); @@ -150,17 +151,17 @@ Controls::Controls (wxWindow* parent, shared_ptr viewer, bool editor _frame_number->Bind (wxEVT_LEFT_DOWN, boost::bind(&Controls::frame_number_clicked, this)); _timecode->Bind (wxEVT_LEFT_DOWN, boost::bind(&Controls::timecode_clicked, this)); if (_jump_to_selected) { - _jump_to_selected->Bind (wxEVT_CHECKBOX, boost::bind (&Controls::jump_to_selected_clicked, this)); + _jump_to_selected->bind(&Controls::jump_to_selected_clicked, this); _jump_to_selected->SetValue (Config::instance()->jump_to_selected ()); } - viewer->Started.connect (boost::bind(&Controls::started, this)); - viewer->Stopped.connect (boost::bind(&Controls::stopped, 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()); + set_film(viewer.film()); setup_sensitivity (); @@ -196,12 +197,7 @@ Controls::stopped () void Controls::update_position () { - auto viewer = _viewer.lock (); - if (!viewer) { - return; - } - - if (!_slider_being_moved && !viewer->pending_idle_get()) { + if (!_slider_being_moved && !_viewer.pending_idle_get()) { update_position_label (); update_position_slider (); } @@ -211,24 +207,14 @@ Controls::update_position () void Controls::eye_changed () { - auto viewer = _viewer.lock (); - if (!viewer) { - return; - } - - viewer->set_eyes (_eye->GetSelection() == 0 ? Eyes::LEFT : Eyes::RIGHT); + _viewer.set_eyes(_eye->GetSelection() == 0 ? Eyes::LEFT : Eyes::RIGHT); } void Controls::outline_content_changed () { - auto viewer = _viewer.lock (); - if (!viewer) { - return; - } - - viewer->set_outline_content (_outline_content->GetValue()); + _viewer.set_outline_content(_outline_content->GetValue()); } @@ -236,14 +222,13 @@ Controls::outline_content_changed () void Controls::slider_moved (bool page) { - auto viewer = _viewer.lock (); - if (!_film || !viewer) { + if (!_film) { return; } if (!page && !_slider_being_moved) { /* This is the first event of a drag; stop playback for the duration of the drag */ - viewer->suspend (); + _viewer.suspend(); _slider_being_moved = true; } @@ -254,10 +239,10 @@ Controls::slider_moved (bool page) */ bool accurate = false; if (t >= _film->length ()) { - t = _film->length() - viewer->one_video_frame(); + t = _film->length() - _viewer.one_video_frame(); accurate = true; } - viewer->seek (t, accurate); + _viewer.seek(t, accurate); update_position_label (); } @@ -265,13 +250,8 @@ Controls::slider_moved (bool page) void Controls::slider_released () { - auto viewer = _viewer.lock (); - if (!viewer) { - return; - } - /* Restart after a drag */ - viewer->resume (); + _viewer.resume(); _slider_being_moved = false; } @@ -284,15 +264,10 @@ Controls::update_position_slider () return; } - auto viewer = _viewer.lock (); - if (!viewer) { - return; - } - auto const len = _film->length (); if (len.get ()) { - int const new_slider_position = 4096 * viewer->position().get() / len.get(); + int const new_slider_position = 4096 * _viewer.position().get() / len.get(); if (new_slider_position != _slider->GetValue()) { _slider->SetValue (new_slider_position); } @@ -309,15 +284,10 @@ Controls::update_position_label () return; } - auto viewer = _viewer.lock (); - if (!viewer) { - return; - } - double const fps = _film->video_frame_rate (); /* Count frame number from 1 ... not sure if this is the best idea */ - checked_set (_frame_number, wxString::Format (wxT("%ld"), lrint (viewer->position().seconds() * fps) + 1)); - checked_set (_timecode, time_to_timecode (viewer->position(), fps)); + checked_set(_frame_number, wxString::Format (wxT("%ld"), lrint(_viewer.position().seconds() * fps) + 1)); + checked_set(_timecode, time_to_timecode(_viewer.position(), fps)); } @@ -332,12 +302,7 @@ Controls::active_jobs_changed (optional j) DCPTime Controls::nudge_amount (wxKeyboardState& ev) { - auto viewer = _viewer.lock (); - if (!viewer) { - return {}; - } - - auto amount = viewer->one_video_frame (); + auto amount = _viewer.one_video_frame(); if (ev.ShiftDown() && !ev.ControlDown()) { amount = DCPTime::from_seconds (1); @@ -354,10 +319,7 @@ Controls::nudge_amount (wxKeyboardState& ev) void Controls::rewind_clicked (wxMouseEvent& ev) { - auto viewer = _viewer.lock (); - if (viewer) { - viewer->seek (DCPTime(), true); - } + _viewer.seek(DCPTime(), true); ev.Skip(); } @@ -365,40 +327,28 @@ Controls::rewind_clicked (wxMouseEvent& ev) void Controls::back_frame () { - auto viewer = _viewer.lock (); - if (viewer) { - viewer->seek_by (-viewer->one_video_frame(), true); - } + _viewer.seek_by(-_viewer.one_video_frame(), true); } void Controls::forward_frame () { - auto viewer = _viewer.lock (); - if (viewer) { - viewer->seek_by (viewer->one_video_frame(), true); - } + _viewer.seek_by(_viewer.one_video_frame(), true); } void Controls::back_clicked (wxKeyboardState& ev) { - auto viewer = _viewer.lock (); - if (viewer) { - viewer->seek_by (-nudge_amount(ev), true); - } + _viewer.seek_by(-nudge_amount(ev), true); } void Controls::forward_clicked (wxKeyboardState& ev) { - auto viewer = _viewer.lock (); - if (viewer) { - viewer->seek_by (nudge_amount(ev), true); - } + _viewer.seek_by(nudge_amount(ev), true); } @@ -431,32 +381,24 @@ Controls::setup_sensitivity () void Controls::timecode_clicked () { - auto viewer = _viewer.lock (); - if (!viewer) { - return; - } + auto dialog = new PlayheadToTimecodeDialog(this, _viewer.position(), _film->video_frame_rate()); + ScopeGuard sg = [dialog]() { dialog->Destroy(); }; - auto dialog = new PlayheadToTimecodeDialog (this, viewer->position(), _film->video_frame_rate()); if (dialog->ShowModal() == wxID_OK) { - viewer->seek (dialog->get(), true); + _viewer.seek(dialog->get(), true); } - dialog->Destroy (); } void Controls::frame_number_clicked () { - auto viewer = _viewer.lock (); - if (!viewer) { - return; - } + auto dialog = new PlayheadToFrameDialog(this, _viewer.position(), _film->video_frame_rate()); + ScopeGuard sg = [dialog]() { dialog->Destroy(); }; - auto dialog = new PlayheadToFrameDialog (this, viewer->position(), _film->video_frame_rate()); if (dialog->ShowModal() == wxID_OK) { - viewer->seek (dialog->get(), true); + _viewer.seek(dialog->get(), true); } - dialog->Destroy (); }