Merge branch 'master' of ssh://git.carlh.net/home/carl/git/dcpomatic
[dcpomatic.git] / src / wx / timeline.cc
index 0ddd78ae006099cb2d4d8504121b32387e4cda00..a607b1eb170fac26507bf8822a7a421a5fc8dafb 100644 (file)
@@ -25,7 +25,7 @@
 #include "timeline_labels_view.h"
 #include "timeline_video_content_view.h"
 #include "timeline_audio_content_view.h"
-#include "timeline_subtitle_content_view.h"
+#include "timeline_text_content_view.h"
 #include "timeline_atmos_content_view.h"
 #include "content_panel.h"
 #include "wx_util.h"
@@ -34,7 +34,7 @@
 #include "lib/image_content.h"
 #include "lib/timer.h"
 #include "lib/audio_content.h"
-#include "lib/subtitle_content.h"
+#include "lib/text_content.h"
 #include "lib/video_content.h"
 #include "lib/atmos_mxf_content.h"
 #include <wx/graphics.h>
@@ -48,8 +48,7 @@ using std::list;
 using std::cout;
 using std::min;
 using std::max;
-using std::begin;
-using std::end;
+using std::abs;
 using boost::shared_ptr;
 using boost::weak_ptr;
 using boost::dynamic_pointer_cast;
@@ -107,12 +106,12 @@ Timeline::Timeline (wxWindow* parent, ContentPanel* cp, shared_ptr<Film> film)
        _main_canvas->Bind   (wxEVT_SCROLLWIN_PAGEDOWN,   boost::bind (&Timeline::scrolled,     this, _1));
        _main_canvas->Bind   (wxEVT_SCROLLWIN_THUMBTRACK, boost::bind (&Timeline::scrolled,     this, _1));
 
-       film_changed (Film::CONTENT);
+       film_change (CHANGE_TYPE_DONE, Film::CONTENT);
 
        SetMinSize (wxSize (640, 4 * pixels_per_track() + 96));
 
-       _film_changed_connection = film->Changed.connect (bind (&Timeline::film_changed, this, _1));
-       _film_content_changed_connection = film->ContentChanged.connect (bind (&Timeline::film_content_changed, this, _2, _3));
+       _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));
 
        setup_scrollbars ();
        _labels_canvas->ShowScrollbars (wxSHOW_SB_NEVER, wxSHOW_SB_NEVER);
@@ -190,8 +189,8 @@ Timeline::paint_main ()
                gc->DrawRectangle (
                        min (_down_point.x, _zoom_point->x),
                        min (_down_point.y, _zoom_point->y),
-                       fabs (_down_point.x - _zoom_point->x),
-                       fabs (_down_point.y - _zoom_point->y)
+                       abs (_down_point.x - _zoom_point->x),
+                       abs (_down_point.y - _zoom_point->y)
                        );
        }
 
@@ -199,8 +198,12 @@ Timeline::paint_main ()
 }
 
 void
-Timeline::film_changed (Film::Property p)
+Timeline::film_change (ChangeType type, Film::Property p)
 {
+       if (type != CHANGE_TYPE_DONE) {
+               return;
+       }
+
        if (p == Film::CONTENT || p == Film::REEL_TYPE || p == Film::REEL_LENGTH) {
                ensure_ui_thread ();
                recreate_views ();
@@ -230,8 +233,8 @@ Timeline::recreate_views ()
                        _views.push_back (shared_ptr<TimelineView> (new TimelineAudioContentView (*this, i)));
                }
 
-               if (i->subtitle) {
-                       _views.push_back (shared_ptr<TimelineView> (new TimelineSubtitleContentView (*this, i)));
+               BOOST_FOREACH (shared_ptr<TextContent> j, i->text) {
+                       _views.push_back (shared_ptr<TimelineView> (new TimelineTextContentView (*this, i, j)));
                }
 
                if (dynamic_pointer_cast<AtmosMXFContent> (i)) {
@@ -245,12 +248,18 @@ Timeline::recreate_views ()
 }
 
 void
-Timeline::film_content_changed (int property, bool frequent)
+Timeline::film_content_change (ChangeType type, int property, bool frequent)
 {
+       if (type != CHANGE_TYPE_DONE) {
+               return;
+       }
+
        ensure_ui_thread ();
 
        if (property == AudioContentProperty::STREAMS) {
                recreate_views ();
+       } else if (property == ContentProperty::POSITION || property == ContentProperty::LENGTH) {
+               _reels_view->force_redraw ();
        } else if (!frequent) {
                setup_scrollbars ();
                Refresh ();
@@ -318,13 +327,13 @@ struct AudioMappingComparator {
                shared_ptr<TimelineAudioContentView> cva = dynamic_pointer_cast<TimelineAudioContentView>(a);
                if (cva) {
                        list<int> oc = cva->content()->audio->mapping().mapped_output_channels();
-                       la = *min_element(begin(oc), end(oc));
+                       la = *min_element(boost::begin(oc), boost::end(oc));
                }
                int lb = -1;
                shared_ptr<TimelineAudioContentView> cvb = dynamic_pointer_cast<TimelineAudioContentView>(b);
                if (cvb) {
                        list<int> oc = cvb->content()->audio->mapping().mapped_output_channels();
-                       lb = *min_element(begin(oc), end(oc));
+                       lb = *min_element(boost::begin(oc), boost::end(oc));
                }
                return la < lb;
        }
@@ -336,9 +345,9 @@ Timeline::assign_tracks ()
        /* Tracks are:
           Video (mono or left-eye)
           Video (right-eye)
-          Subtitle 1
-          Subtitle 2
-          Subtitle N
+          Text 1
+          Text 2
+          Text N
           Atmos
           Audio 1
           Audio 2
@@ -375,9 +384,9 @@ Timeline::assign_tracks ()
 
        _tracks = max (_tracks, 1);
 
-       /* Subtitle */
+       /* Texts */
 
-       int const subtitle_tracks = place<TimelineSubtitleContentView> (_views, _tracks);
+       int const text_tracks = place<TimelineTextContentView> (_views, _tracks);
 
        /* Atmos */
 
@@ -407,7 +416,7 @@ Timeline::assign_tracks ()
 
        _labels_view->set_3d (have_3d);
        _labels_view->set_audio_tracks (audio_tracks);
-       _labels_view->set_subtitle_tracks (subtitle_tracks);
+       _labels_view->set_text_tracks (text_tracks);
        _labels_view->set_atmos (have_atmos);
 
        _time_axis_view->set_y (tracks());
@@ -756,7 +765,7 @@ Timeline::set_position_from_event (wxMouseEvent& ev)
 void
 Timeline::force_redraw (dcpomatic::Rect<int> const & r)
 {
-       RefreshRect (wxRect (r.x, r.y, r.width, r.height), false);
+       _main_canvas->RefreshRect (wxRect (r.x, r.y, r.width, r.height), false);
 }
 
 shared_ptr<const Film>