Cleanup: move EqualityOptions into its own file.
[libdcp.git] / src / sound_asset.cc
index e3b8e38297c246b9570e87db8d5443f8f0430a87..57110b4f82e3b16a78913e7c7f6792b8366b8551 100644 (file)
@@ -39,6 +39,7 @@
 
 #include "compose.hpp"
 #include "dcp_assert.h"
+#include "equality_options.h"
 #include "exceptions.h"
 #include "sound_asset.h"
 #include "sound_asset_reader.h"
@@ -56,11 +57,12 @@ LIBDCP_ENABLE_WARNINGS
 #include <stdexcept>
 
 
-using std::string;
-using std::vector;
+using std::dynamic_pointer_cast;
 using std::list;
 using std::shared_ptr;
-using std::dynamic_pointer_cast;
+using std::string;
+using std::vector;
+using boost::optional;
 using namespace dcp;
 
 
@@ -103,6 +105,16 @@ SoundAsset::SoundAsset (boost::filesystem::path file)
                }
        }
 
+       list<ASDCP::MXF::InterchangeObject*> channel_labels;
+       rr = reader.OP1aHeader().GetMDObjectsByType(
+               asdcp_smpte_dict->ul(ASDCP::MDD_AudioChannelLabelSubDescriptor),
+               channel_labels
+               );
+
+       if (KM_SUCCESS(rr)) {
+               _active_channels = channel_labels.size();
+       }
+
        _id = read_writer_info (info);
 }
 
@@ -119,7 +131,7 @@ SoundAsset::SoundAsset (Fraction edit_rate, int sampling_rate, int channels, Lan
 
 
 bool
-SoundAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, NoteHandler note) const
+SoundAsset::equals(shared_ptr<const Asset> other, EqualityOptions const& opt, NoteHandler note) const
 {
        ASDCP::PCM::MXFReader reader_A;
        DCP_ASSERT (file());
@@ -220,13 +232,20 @@ SoundAsset::equals (shared_ptr<const Asset> other, EqualityOptions opt, NoteHand
 
 
 shared_ptr<SoundAssetWriter>
-SoundAsset::start_write(boost::filesystem::path file, bool atmos_sync, bool include_mca_subdescriptors)
+SoundAsset::start_write(
+       boost::filesystem::path file,
+       vector<dcp::Channel> extra_active_channels,
+       AtmosSync atmos_sync,
+       MCASubDescriptors include_mca_subdescriptors
+       )
 {
-       if (atmos_sync && _channels < 14) {
+       if (atmos_sync == AtmosSync::ENABLED && _channels < 14) {
                throw MiscError ("Insufficient channels to write ATMOS sync (there must be at least 14)");
        }
 
-       return shared_ptr<SoundAssetWriter>(new SoundAssetWriter(this, file, atmos_sync, include_mca_subdescriptors));
+       return shared_ptr<SoundAssetWriter>(
+               new SoundAssetWriter(this, file, extra_active_channels, atmos_sync == AtmosSync::ENABLED, include_mca_subdescriptors == MCASubDescriptors::ENABLED)
+               );
 }
 
 
@@ -258,3 +277,11 @@ SoundAsset::valid_mxf (boost::filesystem::path file)
        Kumu::Result_t r = reader.OpenRead (file.string().c_str());
        return !ASDCP_FAILURE (r);
 }
+
+
+int
+SoundAsset::active_channels() const
+{
+       return _active_channels.get_value_or(_channels);
+}
+