Merge branch 'master' of ssh://git.carlh.net/home/carl/git/dcpomatic
[dcpomatic.git] / src / wx / timeline.cc
index 5babcfea14547c4eefb9aea87dbbc7598e7f98ab..02f8be0597637b77b4fad5ab64aa525c3e691994 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"
 #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>
 #include <boost/weak_ptr.hpp>
 #include <boost/foreach.hpp>
 #include <list>
+#include <iterator>
 #include <iostream>
 
 using std::list;
@@ -227,8 +228,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)) {
@@ -248,6 +249,8 @@ Timeline::film_content_changed (int property, bool frequent)
 
        if (property == AudioContentProperty::STREAMS) {
                recreate_views ();
+       } else if (property == ContentProperty::POSITION || property == ContentProperty::LENGTH) {
+               _reels_view->force_redraw ();
        } else if (!frequent) {
                setup_scrollbars ();
                Refresh ();
@@ -306,15 +309,36 @@ place (TimelineViewList& views, int& tracks)
        return tracks - base;
 }
 
+/** Compare the mapped output channels of two TimelineViews, so we can into
+ *  order of first mapped DCP channel.
+ */
+struct AudioMappingComparator {
+       bool operator()(shared_ptr<TimelineView> a, shared_ptr<TimelineView> b) {
+               int la = -1;
+               shared_ptr<TimelineAudioContentView> cva = dynamic_pointer_cast<TimelineAudioContentView>(a);
+               if (cva) {
+                       list<int> oc = cva->content()->audio->mapping().mapped_output_channels();
+                       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(boost::begin(oc), boost::end(oc));
+               }
+               return la < lb;
+       }
+};
+
 void
 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
@@ -351,9 +375,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 */
 
@@ -373,13 +397,17 @@ Timeline::assign_tracks ()
                ++_tracks;
        }
 
-       /* Audio */
+       /* Audio.  We're sorting the views so that we get the audio views in order of increasing
+          DCP channel index.
+       */
 
-       int const audio_tracks = place<TimelineAudioContentView> (_views, _tracks);
+       TimelineViewList views = _views;
+       sort(views.begin(), views.end(), AudioMappingComparator());
+       int const audio_tracks = place<TimelineAudioContentView> (views, _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());
@@ -728,7 +756,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>