Prevent selection of too few DCP channels (#611).
authorCarl Hetherington <cth@carlh.net>
Tue, 16 Jun 2015 16:01:32 +0000 (17:01 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 16 Jun 2015 16:01:32 +0000 (17:01 +0100)
This makes Film::audio_channels() return a minimum of any active
processor's output channel count, even if fewer DCP channels have
been selected.  It may have been neater code-wise to make Player cope
if such a setting is made, but it would probably confuse people
if we don't auto-fix it (like this commit does).

ChangeLog
src/lib/film.cc
src/lib/film.h
src/wx/dcp_panel.cc
src/wx/dcp_panel.h

index 688e933b4bf9328eab4e1b848360313602437924..2b0f1fef6eb9f7a2e3a1b1047170ce6c05244620 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-06-16  c.hetherington  <cth@carlh.net>
+
+       * Prevent selection of fewer DCP channels than
+       are present in the output of an active processor (#611).
+
 2015-06-15  Carl Hetherington  <cth@carlh.net>
 
        * Select newly-added content (#455).
index d671820226633ad01e69247566c06c10e09697b9..98b9210293f34ac3e4df539425596920ff3b778a 100644 (file)
@@ -72,6 +72,7 @@ using std::map;
 using std::vector;
 using std::setfill;
 using std::min;
+using std::max;
 using std::make_pair;
 using std::endl;
 using std::cout;
@@ -805,6 +806,7 @@ Film::set_audio_processor (AudioProcessor const * processor)
 {
        _audio_processor = processor;
        signal_changed (AUDIO_PROCESSOR);
+       signal_changed (AUDIO_CHANNELS);
 }
 
 void
@@ -1230,3 +1232,18 @@ Film::audio_output_names () const
 
        return vector<string> (n.begin(), n.begin() + audio_channels ());
 }
+
+int
+Film::audio_channels () const
+{
+       int minimum = 0;
+       if (_audio_processor) {
+               minimum = _audio_processor->out_channels ();
+       }
+
+       if (minimum % 2 == 1) {
+               ++minimum;
+       }
+
+       return max (minimum, _audio_channels);
+}
index f9dc0ed9ce7e40df64324b80ed315978da9dab27..a1daebe783f854d5e422a44bbc6dad47985cd0f2 100644 (file)
@@ -223,9 +223,7 @@ public:
                return _video_frame_rate;
        }
 
-       int audio_channels () const {
-               return _audio_channels;
-       }
+       int audio_channels () const;
 
        bool three_d () const {
                return _three_d;
@@ -326,7 +324,9 @@ private:
        int _video_frame_rate;
        /** The date that we should use in a ISDCF name */
        boost::gregorian::date _isdcf_date;
-       /** Number of audio channels to put in the DCP */
+       /** Number of audio channels requested for the DCP; this will be overridden
+           if we are using an audio processor which outputs more channels.
+       */
        int _audio_channels;
        /** If true, the DCP will be written in 3D mode; otherwise in 2D.
            This will be regardless of what content is on the playlist.
index 24c678c576edbc3bb4ca925e4b41b2316c4bc10b..0759694f8802db016c07506b36559049c95e0ba0 100644 (file)
@@ -30,6 +30,7 @@
 #include "lib/ffmpeg_content.h"
 #include "lib/audio_processor.h"
 #include <dcp/key.h>
+#include <dcp/raw_convert.h>
 #include <wx/wx.h>
 #include <wx/notebook.h>
 #include <wx/gbsizer.h>
@@ -41,6 +42,8 @@ using std::cout;
 using std::list;
 using std::string;
 using std::vector;
+using std::pair;
+using std::make_pair;
 using boost::lexical_cast;
 using boost::shared_ptr;
 
@@ -245,7 +248,7 @@ DCPPanel::audio_channels_changed ()
                return;
        }
 
-       _film->set_audio_channels ((_audio_channels->GetSelection () + 1) * 2);
+       _film->set_audio_channels (dcp::raw_convert<int> (string_client_data (_audio_channels->GetClientObject (_audio_channels->GetSelection ()))));
 }
 
 void
@@ -346,7 +349,7 @@ DCPPanel::film_changed (int p)
                break;
        }
        case Film::AUDIO_CHANNELS:
-               checked_set (_audio_channels, (_film->audio_channels () / 2) - 1);
+               checked_set (_audio_channels, dcp::raw_convert<string> (_film->audio_channels ()));
                setup_dcp_name ();
                break;
        case Film::THREE_D:
@@ -363,6 +366,8 @@ DCPPanel::film_changed (int p)
                } else {
                        checked_set (_audio_processor, 0);
                }
+               setup_audio_channels_choice ();
+               film_changed (Film::AUDIO_CHANNELS);
                break;
        default:
                break;
@@ -648,6 +653,26 @@ DCPPanel::make_video_panel ()
        return panel;
 }
 
+void
+DCPPanel::setup_audio_channels_choice ()
+{
+       int min = 2;
+       if (_film && _film->audio_processor ()) {
+               min = _film->audio_processor()->out_channels ();
+       }
+
+       if (min % 2 == 1) {
+               ++min;
+       }
+
+       vector<pair<string, string> > items;
+       for (int i = min; i <= 12; i += 2) {
+               items.push_back (make_pair (dcp::raw_convert<string> (i), dcp::raw_convert<string> (i)));
+       }
+
+       checked_set (_audio_channels, items);
+}
+
 wxPanel *
 DCPPanel::make_audio_panel ()
 {
@@ -661,9 +686,7 @@ DCPPanel::make_audio_panel ()
        
        add_label_to_grid_bag_sizer (grid, panel, _("Channels"), true, wxGBPosition (r, 0));
        _audio_channels = new wxChoice (panel, wxID_ANY);
-       for (int i = 2; i <= 12; i += 2) {
-               _audio_channels->Append (wxString::Format ("%d", i));
-       }
+       setup_audio_channels_choice ();
        grid->Add (_audio_channels, wxGBPosition (r, 1));
        ++r;
 
index 3179ad73ae26ec3be20922b491a3edf6661340cf..ab4e7f1d3cbc0cc9b033dee4955d0c9fd95c05de 100644 (file)
@@ -76,6 +76,7 @@ private:
        void setup_frame_rate_widget ();
        void setup_container ();
        void setup_dcp_name ();
+       void setup_audio_channels_choice ();
 
        wxPanel* make_general_panel ();
        wxPanel* make_video_panel ();