Tidy up and fix assertion failure when selecting a CPL from the menu.
[dcpomatic.git] / src / wx / content_menu.cc
index 78b6469a043249605873dff4889175e8183ca2d6..642457d933e0f64aa99b8cc05388b48478ca4806 100644 (file)
@@ -137,7 +137,7 @@ ContentMenu::popup (weak_ptr<Film> film, ContentList c, TimelineContentViewList
        _views = v;
 
        int const N = _cpl_menu->GetMenuItemCount();
-       for (int i = 1; i <= N; ++i) {
+       for (int i = DCPOMATIC_CPL_MENU; i < DCPOMATIC_CPL_MENU + N; ++i) {
                _cpl_menu->Delete (i);
        }
 
@@ -520,15 +520,11 @@ ContentMenu::cpl_selected (wxCommandEvent& ev)
        DCPOMATIC_ASSERT (dcp);
 
        auto cpls = dcp::find_and_resolve_cpls (dcp->directories(), true);
-       DCPOMATIC_ASSERT (ev.GetId() > 0);
-       DCPOMATIC_ASSERT (ev.GetId() <= int (cpls.size()));
 
-       auto i = cpls.begin ();
-       for (int j = 0; j < ev.GetId() - 1; ++j) {
-               ++i;
-       }
+       DCPOMATIC_ASSERT(ev.GetId() >= DCPOMATIC_CPL_MENU);
+       DCPOMATIC_ASSERT(ev.GetId() < int(DCPOMATIC_CPL_MENU + cpls.size()));
+       dcp->set_cpl(cpls[ev.GetId() - DCPOMATIC_CPL_MENU]->id());
 
-       dcp->set_cpl ((*i)->id ());
        auto film = _film.lock ();
        DCPOMATIC_ASSERT (film);
        JobManager::instance()->add (make_shared<ExamineContentJob>(film, dcp));
@@ -548,12 +544,13 @@ ContentMenu::auto_crop ()
                DCPOMATIC_ASSERT (film);
                auto const content = _content.front();
                auto const current_crop = content->video->actual_crop();
+               auto const video_size_guess = content->video->size().get_value_or(dcp::Size(1998, 1080));
                _viewer.set_crop_guess(
                        dcpomatic::Rect<float>(
-                               static_cast<float>(std::max(0, crop.left - current_crop.left)) / content->video->size().width,
-                               static_cast<float>(std::max(0, crop.top - current_crop.top)) / content->video->size().height,
-                               1.0f - (static_cast<float>(std::max(0, crop.left - current_crop.left + crop.right - current_crop.right)) / content->video->size().width),
-                               1.0f - (static_cast<float>(std::max(0, crop.top - current_crop.top + crop.bottom - current_crop.bottom)) / content->video->size().height)
+                               static_cast<float>(std::max(0, crop.left - current_crop.left)) / video_size_guess.width,
+                               static_cast<float>(std::max(0, crop.top - current_crop.top)) / video_size_guess.height,
+                               1.0f - (static_cast<float>(std::max(0, crop.left - current_crop.left + crop.right - current_crop.right)) / video_size_guess.width),
+                               1.0f - (static_cast<float>(std::max(0, crop.top - current_crop.top + crop.bottom - current_crop.bottom)) / video_size_guess.height)
                                ));
        };