Cleanup: extract VAlign to its own files.
[libdcp.git] / src / types.cc
index c990479238fbae09db13e533d52bc903fca893a8..809319225eb997baa29df9019fe91cb6e76dbb63 100644 (file)
@@ -109,12 +109,6 @@ dcp::operator!= (Fraction const & a, Fraction const & b)
 }
 
 
-Colour::Colour ()
-{
-
-}
-
-
 Colour::Colour (int r_, int g_, int b_)
        : r (r_)
        , g (g_)
@@ -227,37 +221,6 @@ dcp::string_to_halign (string s)
 }
 
 
-string
-dcp::valign_to_string (VAlign v)
-{
-       switch (v) {
-       case VAlign::TOP:
-               return "top";
-       case VAlign::CENTER:
-               return "center";
-       case VAlign::BOTTOM:
-               return "bottom";
-       }
-
-       boost::throw_exception (MiscError("unknown subtitle valign type"));
-}
-
-
-VAlign
-dcp::string_to_valign (string s)
-{
-       if (s == "top") {
-               return VAlign::TOP;
-       } else if (s == "center") {
-               return VAlign::CENTER;
-       } else if (s == "bottom") {
-               return VAlign::BOTTOM;
-       }
-
-       boost::throw_exception (ReadError("unknown subtitle valign type"));
-}
-
-
 string
 dcp::direction_to_string (Direction v)
 {
@@ -293,85 +256,6 @@ dcp::string_to_direction (string s)
 }
 
 
-/** Convert a content kind to a string which can be used in a
- *  <ContentKind> node
- *  @param kind ContentKind
- *  @return string
- */
-string
-dcp::content_kind_to_string (ContentKind kind)
-{
-       switch (kind) {
-       case ContentKind::FEATURE:
-               return "feature";
-       case ContentKind::SHORT:
-               return "short";
-       case ContentKind::TRAILER:
-               return "trailer";
-       case ContentKind::TEST:
-               return "test";
-       case ContentKind::TRANSITIONAL:
-               return "transitional";
-       case ContentKind::RATING:
-               return "rating";
-       case ContentKind::TEASER:
-               return "teaser";
-       case ContentKind::POLICY:
-               return "policy";
-       case ContentKind::PUBLIC_SERVICE_ANNOUNCEMENT:
-               return "psa";
-       case ContentKind::ADVERTISEMENT:
-               return "advertisement";
-       case ContentKind::EPISODE:
-               return "episode";
-       case ContentKind::PROMO:
-               return "promo";
-       }
-
-       DCP_ASSERT (false);
-}
-
-
-/** Convert a string from a <ContentKind> node to a libdcp ContentKind.
- *  Reasonably tolerant about varying case
- *  @param kind Content kind string
- *  @return libdcp ContentKind
- */
-dcp::ContentKind
-dcp::content_kind_from_string (string kind)
-{
-       transform (kind.begin(), kind.end(), kind.begin(), ::tolower);
-
-       if (kind == "feature") {
-               return ContentKind::FEATURE;
-       } else if (kind == "short") {
-               return ContentKind::SHORT;
-       } else if (kind == "trailer") {
-               return ContentKind::TRAILER;
-       } else if (kind == "test") {
-               return ContentKind::TEST;
-       } else if (kind == "transitional") {
-               return ContentKind::TRANSITIONAL;
-       } else if (kind == "rating") {
-               return ContentKind::RATING;
-       } else if (kind == "teaser") {
-               return ContentKind::TEASER;
-       } else if (kind == "policy") {
-               return ContentKind::POLICY;
-       } else if (kind == "psa") {
-               return ContentKind::PUBLIC_SERVICE_ANNOUNCEMENT;
-       } else if (kind == "advertisement") {
-               return ContentKind::ADVERTISEMENT;
-       } else if (kind == "episode") {
-               return ContentKind::EPISODE;
-       } else if (kind == "promo") {
-               return ContentKind::PROMO;
-       }
-
-       throw BadContentKindError (kind);
-}
-
-
 string
 dcp::marker_to_string (dcp::Marker m)
 {
@@ -552,8 +436,8 @@ MainSoundConfiguration::MainSoundConfiguration (string s)
 {
        vector<string> parts;
        boost::split (parts, s, boost::is_any_of("/"));
-       if (parts.size() != 2) {
-               throw MainSoundConfigurationError (s);
+       if (parts.empty()) {
+               throw MainSoundConfigurationError(s);
        }
 
        if (parts[0] == "51") {
@@ -561,7 +445,14 @@ MainSoundConfiguration::MainSoundConfiguration (string s)
        } else if (parts[0] == "71") {
                _field = MCASoundField::SEVEN_POINT_ONE;
        } else {
-               throw MainSoundConfigurationError (s);
+               _field = MCASoundField::OTHER;
+       }
+
+       if (parts.size() < 2) {
+               /* I think it's OK to just have the sound field descriptor with no channels, though
+                * to me it's not clear and I might be wrong.
+                */
+               return;
        }
 
        vector<string> channels;
@@ -592,10 +483,15 @@ string
 MainSoundConfiguration::to_string () const
 {
        string c;
-       if (_field == MCASoundField::FIVE_POINT_ONE) {
+       switch (_field) {
+       case MCASoundField::FIVE_POINT_ONE:
                c = "51/";
-       } else {
+               break;
+       case MCASoundField::SEVEN_POINT_ONE:
                c = "71/";
+               break;
+       default:
+               DCP_ASSERT(false);
        }
 
        for (auto i: _channels) {
@@ -664,31 +560,33 @@ dcp::string_to_status (string s)
 Channel
 dcp::mca_id_to_channel (string id)
 {
-       if (id == "L") {
+       transform(id.begin(), id.end(), id.begin(), ::tolower);
+
+       if (id == "l") {
                return Channel::LEFT;
-       } else if (id == "R") {
+       } else if (id == "r") {
                return Channel::RIGHT;
-       } else if (id == "C") {
+       } else if (id == "c") {
                return Channel::CENTRE;
-       } else if (id == "LFE") {
+       } else if (id == "lfe") {
                return Channel::LFE;
-       } else if (id == "Ls" || id == "Lss") {
+       } else if (id == "ls" || id == "lss") {
                return Channel::LS;
-       } else if (id == "Rs" || id == "Rss") {
+       } else if (id == "rs" || id == "rss") {
                return Channel::RS;
-       } else if (id == "HI") {
+       } else if (id == "hi") {
                return Channel::HI;
-       } else if (id == "VIN") {
+       } else if (id == "vin") {
                return Channel::VI;
-       } else if (id == "Lrs") {
+       } else if (id == "lrs") {
                return Channel::BSL;
-       } else if (id == "Rrs") {
+       } else if (id == "rrs") {
                return Channel::BSR;
-       } else if (id == "DBOX") {
+       } else if (id == "dbox") {
                return Channel::MOTION_DATA;
-       } else if (id == "FSKSync") {
+       } else if (id == "sync" || id == "fsksync") {
                return Channel::SYNC_SIGNAL;
-       } else if (id == "SLVS") {
+       } else if (id == "slvs") {
                return Channel::SIGN_LANGUAGE;
        }
 
@@ -838,3 +736,38 @@ dcp::used_audio_channels ()
        };
 }
 
+
+string
+dcp::formulation_to_string (dcp::Formulation formulation)
+{
+       switch (formulation) {
+       case Formulation::MODIFIED_TRANSITIONAL_1:
+               return "modified-transitional-1";
+       case Formulation::MULTIPLE_MODIFIED_TRANSITIONAL_1:
+               return "multiple-modified-transitional-1";
+       case Formulation::DCI_ANY:
+               return "dci-any";
+       case Formulation::DCI_SPECIFIC:
+               return "dci-specific";
+       }
+
+       DCP_ASSERT (false);
+}
+
+
+dcp::Formulation
+dcp::string_to_formulation (string formulation)
+{
+       if (formulation == "modified-transitional-1") {
+               return Formulation::MODIFIED_TRANSITIONAL_1;
+       } else if (formulation == "multiple-modified-transitional-1") {
+               return Formulation::MULTIPLE_MODIFIED_TRANSITIONAL_1;
+       } else if (formulation == "dci-any") {
+               return Formulation::DCI_ANY;
+       } else if (formulation == "dci-specific") {
+               return Formulation::DCI_SPECIFIC;
+       }
+
+       DCP_ASSERT (false);
+}
+