Fix assertion failure on opening content properties (#816).
[dcpomatic.git] / src / lib / audio_content.cc
index 838fdcae2b570c3bdd594f95ca131bc40878f21f..ee5bb69a2831cca2479c4034661b32a68012d54a 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -36,6 +36,8 @@ using std::cout;
 using std::vector;
 using std::stringstream;
 using std::fixed;
+using std::list;
+using std::pair;
 using std::setprecision;
 using boost::shared_ptr;
 using boost::dynamic_pointer_cast;
@@ -73,7 +75,7 @@ AudioContent::AudioContent (shared_ptr<const Film> film, boost::filesystem::path
 AudioContent::AudioContent (shared_ptr<const Film> film, cxml::ConstNodePtr node)
        : Content (film, node)
 {
-       _audio_gain = node->number_child<float> ("AudioGain");
+       _audio_gain = node->number_child<double> ("AudioGain");
        _audio_delay = node->number_child<int> ("AudioDelay");
 }
 
@@ -168,6 +170,7 @@ AudioContent::audio_mapping () const
        }
 
        AudioMapping merged (channels, MAX_DCP_AUDIO_CHANNELS);
+       merged.make_zero ();
 
        int c = 0;
        int s = 0;
@@ -175,7 +178,9 @@ AudioContent::audio_mapping () const
                AudioMapping mapping = i->mapping ();
                for (int j = 0; j < mapping.input_channels(); ++j) {
                        for (int k = 0; k < MAX_DCP_AUDIO_CHANNELS; ++k) {
-                               merged.set (c, k, mapping.get (j, k));
+                               if (k < mapping.output_channels()) {
+                                       merged.set (c, k, mapping.get (j, k));
+                               }
                        }
                        ++c;
                }
@@ -289,3 +294,50 @@ AudioContent::audio_channel_names () const
 
        return n;
 }
+
+void
+AudioContent::add_properties (list<UserProperty>& p) const
+{
+       shared_ptr<const AudioStream> stream;
+       if (audio_streams().size() == 1) {
+               stream = audio_streams().front ();
+       }
+
+       if (stream) {
+               p.push_back (UserProperty (_("Audio"), _("Channels"), stream->channels ()));
+               p.push_back (UserProperty (_("Audio"), _("Content audio frame rate"), stream->frame_rate(), _("Hz")));
+       }
+
+       shared_ptr<const Film> film = _film.lock ();
+       DCPOMATIC_ASSERT (film);
+
+       FrameRateChange const frc = film->active_frame_rate_change (position ());
+       ContentTime const c (full_length(), frc);
+
+       p.push_back (
+               UserProperty (_("Length"), _("Full length in video frames at content rate"), c.frames_round(frc.source))
+               );
+
+       if (stream) {
+               p.push_back (
+                       UserProperty (
+                               _("Length"),
+                               _("Full length in audio frames at content rate"),
+                               c.frames_round (stream->frame_rate ())
+                               )
+                       );
+       }
+
+       p.push_back (UserProperty (_("Audio"), _("DCP frame rate"), resampled_audio_frame_rate (), _("Hz")));
+       p.push_back (UserProperty (_("Length"), _("Full length in video frames at DCP rate"), c.frames_round (frc.dcp)));
+
+       if (stream) {
+               p.push_back (
+                       UserProperty (
+                               _("Length"),
+                               _("Full length in audio frames at DCP rate"),
+                               c.frames_round (resampled_audio_frame_rate ())
+                               )
+                       );
+       }
+}