From 7394f50d8b5334a17cac37c8956b1b7e8e5e49c8 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 13 May 2013 14:45:16 +0100 Subject: Try to move XML bits out into parse/ subdir. --- src/asset_map.cc | 78 ------------------------ src/asset_map.h | 77 ----------------------- src/cpl.cc | 14 ++--- src/cpl.h | 7 ++- src/cpl_file.cc | 147 -------------------------------------------- src/cpl_file.h | 157 ----------------------------------------------- src/dcp.cc | 17 +++--- src/dcp.h | 1 - src/parse/asset_map.cc | 78 ++++++++++++++++++++++++ src/parse/asset_map.h | 81 +++++++++++++++++++++++++ src/parse/cpl.cc | 147 ++++++++++++++++++++++++++++++++++++++++++++ src/parse/cpl.h | 161 +++++++++++++++++++++++++++++++++++++++++++++++++ src/parse/pkl.cc | 51 ++++++++++++++++ src/parse/pkl.h | 60 ++++++++++++++++++ src/parse/subtitle.cc | 135 +++++++++++++++++++++++++++++++++++++++++ src/parse/subtitle.h | 93 ++++++++++++++++++++++++++++ src/pkl_file.cc | 51 ---------------- src/pkl_file.h | 56 ----------------- src/subtitle_asset.cc | 125 ++++---------------------------------- src/subtitle_asset.h | 74 +++-------------------- src/wscript | 8 ++- 21 files changed, 849 insertions(+), 769 deletions(-) delete mode 100644 src/asset_map.cc delete mode 100644 src/asset_map.h delete mode 100644 src/cpl_file.cc delete mode 100644 src/cpl_file.h create mode 100644 src/parse/asset_map.cc create mode 100644 src/parse/asset_map.h create mode 100644 src/parse/cpl.cc create mode 100644 src/parse/cpl.h create mode 100644 src/parse/pkl.cc create mode 100644 src/parse/pkl.h create mode 100644 src/parse/subtitle.cc create mode 100644 src/parse/subtitle.h delete mode 100644 src/pkl_file.cc delete mode 100644 src/pkl_file.h (limited to 'src') diff --git a/src/asset_map.cc b/src/asset_map.cc deleted file mode 100644 index fb42f363..00000000 --- a/src/asset_map.cc +++ /dev/null @@ -1,78 +0,0 @@ -/* - Copyright (C) 2012 Carl Hetherington - - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -/** @file src/asset_map.cc - * @brief Classes used to parse a AssetMap. - */ - -#include -#include "asset_map.h" -#include "util.h" -#include "xml.h" - -using std::string; -using std::list; -using boost::shared_ptr; -using namespace libdcp; - -AssetMap::AssetMap (string file) -{ - cxml::File f (file, "AssetMap"); - - id = f.string_child ("Id"); - creator = f.string_child ("Creator"); - volume_count = f.number_child ("VolumeCount"); - issue_date = f.string_child ("IssueDate"); - issuer = f.string_child ("Issuer"); - assets = type_grand_children (f, "AssetList", "Asset"); -} - -AssetMapAsset::AssetMapAsset (shared_ptr node) -{ - id = node->string_child ("Id"); - packing_list = node->optional_string_child ("PackingList").get_value_or (""); - chunks = type_grand_children (node, "ChunkList", "Chunk"); -} - -Chunk::Chunk (shared_ptr node) -{ - path = node->string_child ("Path"); - - string const prefix = "file://"; - - if (boost::algorithm::starts_with (path, prefix)) { - path = path.substr (prefix.length()); - } - - volume_index = node->optional_number_child ("VolumeIndex").get_value_or (0); - offset = node->optional_number_child ("Offset").get_value_or (0); - length = node->optional_number_child ("Length").get_value_or (0); -} - -shared_ptr -AssetMap::asset_from_id (string id) const -{ - for (list >::const_iterator i = assets.begin (); i != assets.end(); ++i) { - if ((*i)->id == id) { - return *i; - } - } - - return shared_ptr (); -} diff --git a/src/asset_map.h b/src/asset_map.h deleted file mode 100644 index e7ba6978..00000000 --- a/src/asset_map.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - Copyright (C) 2012 Carl Hetherington - - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -/** @file src/asset_map.h - * @brief Classes used to parse a AssetMap. - */ - -#include -#include -#include - -namespace libdcp { - -/** @class Chunk - * @brief A simple parser for and representation of a \ node within an asset map. - */ -class Chunk -{ -public: - Chunk (); - Chunk (boost::shared_ptr node); - - std::string path; - int64_t volume_index; - int64_t offset; - int64_t length; -}; - -/** @class AssetMapAsset - * @brief A simple parser for and representation of an \ node within an asset map. - */ -class AssetMapAsset -{ -public: - AssetMapAsset (); - AssetMapAsset (boost::shared_ptr node); - - std::string id; - std::string packing_list; - std::list > chunks; -}; - -/** @class AssetMap - * @brief A simple parser for and representation of an asset map file. - */ -class AssetMap -{ -public: - AssetMap (std::string file); - - boost::shared_ptr asset_from_id (std::string id) const; - - std::string id; - std::string creator; - int64_t volume_count; - std::string issue_date; - std::string issuer; - std::list > assets; -}; - -} diff --git a/src/cpl.cc b/src/cpl.cc index 10a83078..3a2ad0b3 100644 --- a/src/cpl.cc +++ b/src/cpl.cc @@ -19,12 +19,12 @@ #include #include "cpl.h" -#include "cpl_file.h" +#include "parse/cpl.h" #include "util.h" #include "picture_asset.h" #include "sound_asset.h" #include "subtitle_asset.h" -#include "asset_map.h" +#include "parse/asset_map.h" #include "reel.h" #include "metadata.h" @@ -52,16 +52,16 @@ CPL::CPL (string directory, string name, ContentKind content_kind, int length, i * @param asset_map The corresponding asset map. * @param require_mxfs true to throw an exception if a required MXF file does not exist. */ -CPL::CPL (string directory, string file, shared_ptr asset_map, bool require_mxfs) +CPL::CPL (string directory, string file, shared_ptr asset_map, bool require_mxfs) : _directory (directory) , _content_kind (FEATURE) , _length (0) , _fps (0) { /* Read the XML */ - shared_ptr cpl; + shared_ptr cpl; try { - cpl.reset (new CPLFile (file)); + cpl.reset (new parse::CPL (file)); } catch (FileError& e) { boost::throw_exception (FileError ("could not load CPL file", file)); } @@ -71,9 +71,9 @@ CPL::CPL (string directory, string file, shared_ptr asset_map, b _name = cpl->annotation_text; _content_kind = cpl->content_kind; - for (list >::iterator i = cpl->reels.begin(); i != cpl->reels.end(); ++i) { + for (list >::iterator i = cpl->reels.begin(); i != cpl->reels.end(); ++i) { - shared_ptr p; + shared_ptr p; if ((*i)->asset_list->main_picture) { p = (*i)->asset_list->main_picture; diff --git a/src/cpl.h b/src/cpl.h index 0abff749..c04fd6ad 100644 --- a/src/cpl.h +++ b/src/cpl.h @@ -24,7 +24,10 @@ namespace libdcp { -class AssetMap; +namespace parse { + class AssetMap; +} + class Asset; class Reel; class XMLMetadata; @@ -34,7 +37,7 @@ class CPL { public: CPL (std::string directory, std::string name, ContentKind content_kind, int length, int frames_per_second); - CPL (std::string directory, std::string file, boost::shared_ptr asset_map, bool require_mxfs = true); + CPL (std::string directory, std::string file, boost::shared_ptr asset_map, bool require_mxfs = true); void add_reel (boost::shared_ptr reel); diff --git a/src/cpl_file.cc b/src/cpl_file.cc deleted file mode 100644 index 3126b99c..00000000 --- a/src/cpl_file.cc +++ /dev/null @@ -1,147 +0,0 @@ -/* - Copyright (C) 2012 Carl Hetherington - - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -/** @file src/cpl_file.cc - * @brief Classes used to parse a CPL. - */ - -#include -#include "cpl_file.h" -#include "xml.h" -#include "util.h" - -using std::string; -using std::bad_cast; -using boost::shared_ptr; -using namespace libdcp; - -CPLFile::CPLFile (string file) -{ - cxml::File f (file, "CompositionPlaylist"); - - id = f.string_child ("Id"); - annotation_text = f.optional_string_child ("AnnotationText").get_value_or (""); - issue_date = f.string_child ("IssueDate"); - creator = f.optional_string_child ("Creator").get_value_or (""); - content_title_text = f.string_child ("ContentTitleText"); - content_kind = content_kind_from_string (f.string_child ("ContentKind")); - content_version = optional_type_child (f, "ContentVersion"); - f.ignore_child ("RatingList"); - reels = type_grand_children (f, "ReelList", "Reel"); - - f.ignore_child ("Issuer"); - f.ignore_child ("Signer"); - f.ignore_child ("Signature"); - - f.done (); -} - -ContentVersion::ContentVersion (shared_ptr node) -{ - id = node->optional_string_child ("Id").get_value_or (""); - label_text = node->string_child ("LabelText"); - node->done (); -} - -CPLReel::CPLReel (shared_ptr node) -{ - id = node->string_child ("Id"); - asset_list = type_child (node, "AssetList"); - - node->ignore_child ("AnnotationText"); - node->done (); -} - -CPLAssetList::CPLAssetList (shared_ptr node) -{ - main_picture = optional_type_child (node, "MainPicture"); - main_stereoscopic_picture = optional_type_child (node, "MainStereoscopicPicture"); - main_sound = optional_type_child (node, "MainSound"); - main_subtitle = optional_type_child (node, "MainSubtitle"); - - node->done (); -} - -MainPicture::MainPicture (shared_ptr node) - : Picture (node) -{ - -} - -MainStereoscopicPicture::MainStereoscopicPicture (shared_ptr node) - : Picture (node) -{ - -} - -Picture::Picture (shared_ptr node) -{ - id = node->string_child ("Id"); - annotation_text = node->optional_string_child ("AnnotationText").get_value_or (""); - edit_rate = Fraction (node->string_child ("EditRate")); - intrinsic_duration = node->number_child ("IntrinsicDuration"); - entry_point = node->number_child ("EntryPoint"); - duration = node->number_child ("Duration"); - frame_rate = Fraction (node->string_child ("FrameRate")); - try { - screen_aspect_ratio = Fraction (node->string_child ("ScreenAspectRatio")); - } catch (XMLError& e) { - /* Maybe it's not a fraction */ - } - try { - float f = node->number_child ("ScreenAspectRatio"); - screen_aspect_ratio = Fraction (f * 1000, 1000); - } catch (bad_cast& e) { - - } - - node->ignore_child ("Hash"); - - node->done (); -} - -MainSound::MainSound (shared_ptr node) -{ - id = node->string_child ("Id"); - annotation_text = node->optional_string_child ("AnnotationText").get_value_or (""); - edit_rate = Fraction (node->string_child ("EditRate")); - intrinsic_duration = node->number_child ("IntrinsicDuration"); - entry_point = node->number_child ("EntryPoint"); - duration = node->number_child ("Duration"); - - node->ignore_child ("Hash"); - node->ignore_child ("Language"); - - node->done (); -} - -MainSubtitle::MainSubtitle (shared_ptr node) -{ - id = node->string_child ("Id"); - annotation_text = node->optional_string_child ("AnnotationText").get_value_or (""); - edit_rate = Fraction (node->string_child ("EditRate")); - intrinsic_duration = node->number_child ("IntrinsicDuration"); - entry_point = node->number_child ("EntryPoint"); - duration = node->number_child ("Duration"); - - node->ignore_child ("Hash"); - node->ignore_child ("Language"); - - node->done (); -} diff --git a/src/cpl_file.h b/src/cpl_file.h deleted file mode 100644 index b17f47cd..00000000 --- a/src/cpl_file.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - Copyright (C) 2012 Carl Hetherington - - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -/** @file src/cpl_file.h - * @brief Classes used to parse a CPL. - */ - -#include -#include -#include -#include "types.h" - -namespace libdcp { - -/** @brief A simple representation of a CPL \ node */ -class Picture -{ -public: - Picture () {} - Picture (boost::shared_ptr node); - - std::string id; - std::string annotation_text; - Fraction edit_rate; - /** Duration of the whole thing */ - int64_t intrinsic_duration; - /** Start point in frames */ - int64_t entry_point; - /** Duration that will actually play */ - int64_t duration; - Fraction frame_rate; - Fraction screen_aspect_ratio; -}; - - -/** @brief A simple parser for and representation of a CPL \ node */ -class MainPicture : public Picture -{ -public: - MainPicture () {} - MainPicture (boost::shared_ptr node); -}; - -/** @brief A simple parser for and representation of a CPL \ node */ -class MainStereoscopicPicture : public Picture -{ -public: - MainStereoscopicPicture () {} - MainStereoscopicPicture (boost::shared_ptr node); -}; - -/** @brief A simple parser for and representation of a CPL \ node */ -class MainSound -{ -public: - MainSound () {} - MainSound (boost::shared_ptr node); - - std::string id; - std::string annotation_text; - Fraction edit_rate; - int64_t intrinsic_duration; - int64_t entry_point; - int64_t duration; -}; - -/** @brief A simple parser for and representation of a CPL \ node */ -class MainSubtitle -{ -public: - MainSubtitle () {} - MainSubtitle (boost::shared_ptr node); - - std::string id; - std::string annotation_text; - Fraction edit_rate; - int64_t intrinsic_duration; - int64_t entry_point; - int64_t duration; -}; - -/** @brief A simple parser for and representation of a CPL \ node */ -class CPLAssetList -{ -public: - CPLAssetList () {} - CPLAssetList (boost::shared_ptr node); - - boost::shared_ptr main_picture; - boost::shared_ptr main_stereoscopic_picture; - boost::shared_ptr main_sound; - boost::shared_ptr main_subtitle; -}; - -/** @brief A simple parser for and representation of a CPL \ node */ -class CPLReel -{ -public: - CPLReel () {} - CPLReel (boost::shared_ptr node); - - std::string id; - boost::shared_ptr asset_list; -}; - - -/** @brief A simple parser for and representation of a CPL \ node */ -class ContentVersion -{ -public: - ContentVersion () {} - ContentVersion (boost::shared_ptr node); - - std::string id; - std::string label_text; -}; - -/** @class CPLFile - * @brief Class to parse a CPL - * - * This class is used to parse XML CPL files. It is rarely necessary - * for the caller to use it outside libdcp. - */ -class CPLFile -{ -public: - /** Parse a CPL XML file into our member variables */ - CPLFile (std::string file); - - std::string id; - std::string annotation_text; - std::string issue_date; - std::string creator; - std::string content_title_text; - ContentKind content_kind; - boost::shared_ptr content_version; - std::list > reels; -}; - -} - diff --git a/src/dcp.cc b/src/dcp.cc index 7af3f353..7a43e9b2 100644 --- a/src/dcp.cc +++ b/src/dcp.cc @@ -37,9 +37,8 @@ #include "util.h" #include "metadata.h" #include "exceptions.h" -#include "cpl_file.h" -#include "pkl_file.h" -#include "asset_map.h" +#include "parse/pkl.h" +#include "parse/asset_map.h" #include "reel.h" #include "cpl.h" @@ -171,17 +170,17 @@ DCP::read (bool require_mxfs) { Files files; - shared_ptr asset_map; + shared_ptr asset_map; try { boost::filesystem::path p = _directory; p /= "ASSETMAP"; if (boost::filesystem::exists (p)) { - asset_map.reset (new AssetMap (p.string ())); + asset_map.reset (new libdcp::parse::AssetMap (p.string ())); } else { p = _directory; p /= "ASSETMAP.xml"; if (boost::filesystem::exists (p)) { - asset_map.reset (new AssetMap (p.string ())); + asset_map.reset (new libdcp::parse::AssetMap (p.string ())); } else { boost::throw_exception (DCPReadError ("could not find AssetMap file")); } @@ -191,7 +190,7 @@ DCP::read (bool require_mxfs) boost::throw_exception (FileError ("could not load AssetMap file", files.asset_map)); } - for (list >::const_iterator i = asset_map->assets.begin(); i != asset_map->assets.end(); ++i) { + for (list >::const_iterator i = asset_map->assets.begin(); i != asset_map->assets.end(); ++i) { if ((*i)->chunks.size() != 1) { boost::throw_exception (XMLError ("unsupported asset chunk count")); } @@ -233,9 +232,9 @@ DCP::read (bool require_mxfs) boost::throw_exception (FileError ("no PKL file found", "")); } - shared_ptr pkl; + shared_ptr pkl; try { - pkl.reset (new PKLFile (files.pkl)); + pkl.reset (new parse::PKL (files.pkl)); } catch (FileError& e) { boost::throw_exception (FileError ("could not load PKL file", files.pkl)); } diff --git a/src/dcp.h b/src/dcp.h index 42c0c6d9..eea043dd 100644 --- a/src/dcp.h +++ b/src/dcp.h @@ -43,7 +43,6 @@ class PictureAsset; class SoundAsset; class SubtitleAsset; class Reel; -class AssetMap; class CPL; class XMLMetadata; diff --git a/src/parse/asset_map.cc b/src/parse/asset_map.cc new file mode 100644 index 00000000..aedc931e --- /dev/null +++ b/src/parse/asset_map.cc @@ -0,0 +1,78 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +/** @file src/asset_map.cc + * @brief Classes used to parse a AssetMap. + */ + +#include +#include "asset_map.h" +#include "../util.h" +#include "../xml.h" + +using std::string; +using std::list; +using boost::shared_ptr; +using namespace libdcp::parse; + +AssetMap::AssetMap (string file) +{ + cxml::File f (file, "AssetMap"); + + id = f.string_child ("Id"); + creator = f.string_child ("Creator"); + volume_count = f.number_child ("VolumeCount"); + issue_date = f.string_child ("IssueDate"); + issuer = f.string_child ("Issuer"); + assets = type_grand_children (f, "AssetList", "Asset"); +} + +AssetMapAsset::AssetMapAsset (shared_ptr node) +{ + id = node->string_child ("Id"); + packing_list = node->optional_string_child ("PackingList").get_value_or (""); + chunks = type_grand_children (node, "ChunkList", "Chunk"); +} + +Chunk::Chunk (shared_ptr node) +{ + path = node->string_child ("Path"); + + string const prefix = "file://"; + + if (boost::algorithm::starts_with (path, prefix)) { + path = path.substr (prefix.length()); + } + + volume_index = node->optional_number_child ("VolumeIndex").get_value_or (0); + offset = node->optional_number_child ("Offset").get_value_or (0); + length = node->optional_number_child ("Length").get_value_or (0); +} + +shared_ptr +AssetMap::asset_from_id (string id) const +{ + for (list >::const_iterator i = assets.begin (); i != assets.end(); ++i) { + if ((*i)->id == id) { + return *i; + } + } + + return shared_ptr (); +} diff --git a/src/parse/asset_map.h b/src/parse/asset_map.h new file mode 100644 index 00000000..af3e8918 --- /dev/null +++ b/src/parse/asset_map.h @@ -0,0 +1,81 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +/** @file src/asset_map.h + * @brief Classes used to parse a AssetMap. + */ + +#include +#include +#include + +namespace libdcp { + +namespace parse { + +/** @class Chunk + * @brief A simple parser for and representation of a \ node within an asset map. + */ +class Chunk +{ +public: + Chunk (); + Chunk (boost::shared_ptr node); + + std::string path; + int64_t volume_index; + int64_t offset; + int64_t length; +}; + +/** @class AssetMapAsset + * @brief A simple parser for and representation of an \ node within an asset map. + */ +class AssetMapAsset +{ +public: + AssetMapAsset (); + AssetMapAsset (boost::shared_ptr node); + + std::string id; + std::string packing_list; + std::list > chunks; +}; + +/** @class AssetMap + * @brief A simple parser for and representation of an asset map file. + */ +class AssetMap +{ +public: + AssetMap (std::string file); + + boost::shared_ptr asset_from_id (std::string id) const; + + std::string id; + std::string creator; + int64_t volume_count; + std::string issue_date; + std::string issuer; + std::list > assets; +}; + +} + +} diff --git a/src/parse/cpl.cc b/src/parse/cpl.cc new file mode 100644 index 00000000..c4cf4374 --- /dev/null +++ b/src/parse/cpl.cc @@ -0,0 +1,147 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +/** @file src/cpl_file.cc + * @brief Classes used to parse a CPL. + */ + +#include +#include "cpl.h" +#include "../xml.h" +#include "../util.h" + +using std::string; +using std::bad_cast; +using boost::shared_ptr; +using namespace libdcp::parse; + +CPL::CPL (string file) +{ + cxml::File f (file, "CompositionPlaylist"); + + id = f.string_child ("Id"); + annotation_text = f.optional_string_child ("AnnotationText").get_value_or (""); + issue_date = f.string_child ("IssueDate"); + creator = f.optional_string_child ("Creator").get_value_or (""); + content_title_text = f.string_child ("ContentTitleText"); + content_kind = content_kind_from_string (f.string_child ("ContentKind")); + content_version = optional_type_child (f, "ContentVersion"); + f.ignore_child ("RatingList"); + reels = type_grand_children (f, "ReelList", "Reel"); + + f.ignore_child ("Issuer"); + f.ignore_child ("Signer"); + f.ignore_child ("Signature"); + + f.done (); +} + +ContentVersion::ContentVersion (shared_ptr node) +{ + id = node->optional_string_child ("Id").get_value_or (""); + label_text = node->string_child ("LabelText"); + node->done (); +} + +Reel::Reel (shared_ptr node) +{ + id = node->string_child ("Id"); + asset_list = type_child (node, "AssetList"); + + node->ignore_child ("AnnotationText"); + node->done (); +} + +CPLAssetList::CPLAssetList (shared_ptr node) +{ + main_picture = optional_type_child (node, "MainPicture"); + main_stereoscopic_picture = optional_type_child (node, "MainStereoscopicPicture"); + main_sound = optional_type_child (node, "MainSound"); + main_subtitle = optional_type_child (node, "MainSubtitle"); + + node->done (); +} + +MainPicture::MainPicture (shared_ptr node) + : Picture (node) +{ + +} + +MainStereoscopicPicture::MainStereoscopicPicture (shared_ptr node) + : Picture (node) +{ + +} + +Picture::Picture (shared_ptr node) +{ + id = node->string_child ("Id"); + annotation_text = node->optional_string_child ("AnnotationText").get_value_or (""); + edit_rate = Fraction (node->string_child ("EditRate")); + intrinsic_duration = node->number_child ("IntrinsicDuration"); + entry_point = node->number_child ("EntryPoint"); + duration = node->number_child ("Duration"); + frame_rate = Fraction (node->string_child ("FrameRate")); + try { + screen_aspect_ratio = Fraction (node->string_child ("ScreenAspectRatio")); + } catch (XMLError& e) { + /* Maybe it's not a fraction */ + } + try { + float f = node->number_child ("ScreenAspectRatio"); + screen_aspect_ratio = Fraction (f * 1000, 1000); + } catch (bad_cast& e) { + + } + + node->ignore_child ("Hash"); + + node->done (); +} + +MainSound::MainSound (shared_ptr node) +{ + id = node->string_child ("Id"); + annotation_text = node->optional_string_child ("AnnotationText").get_value_or (""); + edit_rate = Fraction (node->string_child ("EditRate")); + intrinsic_duration = node->number_child ("IntrinsicDuration"); + entry_point = node->number_child ("EntryPoint"); + duration = node->number_child ("Duration"); + + node->ignore_child ("Hash"); + node->ignore_child ("Language"); + + node->done (); +} + +MainSubtitle::MainSubtitle (shared_ptr node) +{ + id = node->string_child ("Id"); + annotation_text = node->optional_string_child ("AnnotationText").get_value_or (""); + edit_rate = Fraction (node->string_child ("EditRate")); + intrinsic_duration = node->number_child ("IntrinsicDuration"); + entry_point = node->number_child ("EntryPoint"); + duration = node->number_child ("Duration"); + + node->ignore_child ("Hash"); + node->ignore_child ("Language"); + + node->done (); +} diff --git a/src/parse/cpl.h b/src/parse/cpl.h new file mode 100644 index 00000000..434a244b --- /dev/null +++ b/src/parse/cpl.h @@ -0,0 +1,161 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +/** @file src/parse/cpl.h + * @brief Classes used to parse a CPL. + */ + +#include +#include +#include +#include "../types.h" + +namespace libdcp { + +namespace parse { + +/** @brief A simple representation of a CPL \ node */ +class Picture +{ +public: + Picture () {} + Picture (boost::shared_ptr node); + + std::string id; + std::string annotation_text; + Fraction edit_rate; + /** Duration of the whole thing */ + int64_t intrinsic_duration; + /** Start point in frames */ + int64_t entry_point; + /** Duration that will actually play */ + int64_t duration; + Fraction frame_rate; + Fraction screen_aspect_ratio; +}; + + +/** @brief A simple parser for and representation of a CPL \ node */ +class MainPicture : public Picture +{ +public: + MainPicture () {} + MainPicture (boost::shared_ptr node); +}; + +/** @brief A simple parser for and representation of a CPL \ node */ +class MainStereoscopicPicture : public Picture +{ +public: + MainStereoscopicPicture () {} + MainStereoscopicPicture (boost::shared_ptr node); +}; + +/** @brief A simple parser for and representation of a CPL \ node */ +class MainSound +{ +public: + MainSound () {} + MainSound (boost::shared_ptr node); + + std::string id; + std::string annotation_text; + Fraction edit_rate; + int64_t intrinsic_duration; + int64_t entry_point; + int64_t duration; +}; + +/** @brief A simple parser for and representation of a CPL \ node */ +class MainSubtitle +{ +public: + MainSubtitle () {} + MainSubtitle (boost::shared_ptr node); + + std::string id; + std::string annotation_text; + Fraction edit_rate; + int64_t intrinsic_duration; + int64_t entry_point; + int64_t duration; +}; + +/** @brief A simple parser for and representation of a CPL \ node */ +class CPLAssetList +{ +public: + CPLAssetList () {} + CPLAssetList (boost::shared_ptr node); + + boost::shared_ptr main_picture; + boost::shared_ptr main_stereoscopic_picture; + boost::shared_ptr main_sound; + boost::shared_ptr main_subtitle; +}; + +/** @brief A simple parser for and representation of a CPL \ node */ +class Reel +{ +public: + Reel () {} + Reel (boost::shared_ptr node); + + std::string id; + boost::shared_ptr asset_list; +}; + + +/** @brief A simple parser for and representation of a CPL \ node */ +class ContentVersion +{ +public: + ContentVersion () {} + ContentVersion (boost::shared_ptr node); + + std::string id; + std::string label_text; +}; + +/** @class CPL + * @brief Class to parse a CPL + * + * This class is used to parse XML CPL files. It is rarely necessary + * for the caller to use it outside libdcp. + */ +class CPL +{ +public: + /** Parse a CPL XML file into our member variables */ + CPL (std::string file); + + std::string id; + std::string annotation_text; + std::string issue_date; + std::string creator; + std::string content_title_text; + ContentKind content_kind; + boost::shared_ptr content_version; + std::list > reels; +}; + +} + +} + diff --git a/src/parse/pkl.cc b/src/parse/pkl.cc new file mode 100644 index 00000000..d790cfe4 --- /dev/null +++ b/src/parse/pkl.cc @@ -0,0 +1,51 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +/** @file src/pkl_file.cc + * @brief Classes used to parse a PKL. + */ + +#include +#include "pkl.h" + +using namespace std; +using namespace boost; +using namespace libdcp::parse; + +PKL::PKL (string file) +{ + cxml::File f (file, "PackingList"); + + id = f.string_child ("Id"); + annotation_text = f.optional_string_child ("AnnotationText").get_value_or (""); + issue_date = f.string_child ("IssueDate"); + issuer = f.string_child ("Issuer"); + creator = f.string_child ("Creator"); + assets = type_grand_children (f, "AssetList", "Asset"); +} + +PKLAsset::PKLAsset (boost::shared_ptr node) +{ + id = node->string_child ("Id"); + annotation_text = node->optional_string_child ("AnnotationText").get_value_or (""); + hash = node->string_child ("Hash"); + size = node->number_child ("Size"); + type = node->string_child ("Type"); + original_file_name = node->optional_string_child ("OriginalFileName").get_value_or (""); +} diff --git a/src/parse/pkl.h b/src/parse/pkl.h new file mode 100644 index 00000000..13d87fa1 --- /dev/null +++ b/src/parse/pkl.h @@ -0,0 +1,60 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +/** @file src/parse/pkl.h + * @brief Classes used to parse a PKL + */ + +#include +#include "../xml.h" + +namespace libdcp { + +namespace parse { + +class PKLAsset +{ +public: + PKLAsset () {} + PKLAsset (boost::shared_ptr); + + std::string id; + std::string annotation_text; + std::string hash; + int64_t size; + std::string type; + std::string original_file_name; +}; + +class PKL +{ +public: + PKL (std::string file); + + std::string id; + std::string annotation_text; + std::string issue_date; + std::string issuer; + std::string creator; + std::list > assets; +}; + +} + +} diff --git a/src/parse/subtitle.cc b/src/parse/subtitle.cc new file mode 100644 index 00000000..471d62b7 --- /dev/null +++ b/src/parse/subtitle.cc @@ -0,0 +1,135 @@ +/* + Copyright (C) 2012-2013 Carl Hetherington + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include +#include +#include "subtitle.h" +#include "../types.h" + +using std::string; +using std::list; +using boost::shared_ptr; +using boost::optional; +using boost::lexical_cast; +using namespace libdcp; +using namespace libdcp::parse; + +Font::Font (shared_ptr node) +{ + text = node->content (); + + id = node->optional_string_attribute ("Id").get_value_or (""); + size = node->optional_number_attribute ("Size").get_value_or (0); + italic = node->optional_bool_attribute ("Italic").get_value_or (false); + optional c = node->optional_string_attribute ("Color"); + if (c) { + color = Color (c.get ()); + } + optional const e = node->optional_string_attribute ("Effect"); + if (e) { + effect = string_to_effect (e.get ()); + } + c = node->optional_string_attribute ( "EffectColor"); + if (c) { + effect_color = Color (c.get ()); + } + subtitle_nodes = type_children (node, "Subtitle"); + font_nodes = type_children (node, "Font"); + text_nodes = type_children (node, "Text"); +} + +Font::Font (list > const & font_nodes) + : size (0) + , italic (false) + , color ("FFFFFFFF") + , effect_color ("FFFFFFFF") +{ + for (list >::const_iterator i = font_nodes.begin(); i != font_nodes.end(); ++i) { + if (!(*i)->id.empty ()) { + id = (*i)->id; + } + if ((*i)->size != 0) { + size = (*i)->size; + } + if ((*i)->italic) { + italic = (*i)->italic.get (); + } + if ((*i)->color) { + color = (*i)->color.get (); + } + if ((*i)->effect) { + effect = (*i)->effect.get (); + } + if ((*i)->effect_color) { + effect_color = (*i)->effect_color.get (); + } + } +} + +LoadFont::LoadFont (shared_ptr node) +{ + id = node->string_attribute ("Id"); + uri = node->string_attribute ("URI"); +} + + +Subtitle::Subtitle (shared_ptr node) +{ + in = Time (node->string_attribute ("TimeIn")); + out = Time (node->string_attribute ("TimeOut")); + font_nodes = type_children (node, "Font"); + text_nodes = type_children (node, "Text"); + fade_up_time = fade_time (node, "FadeUpTime"); + fade_down_time = fade_time (node, "FadeDownTime"); +} + +Time +Subtitle::fade_time (shared_ptr node, string name) +{ + string const u = node->optional_string_attribute (name).get_value_or (""); + Time t; + + if (u.empty ()) { + t = Time (0, 0, 0, 20); + } else if (u.find (":") != string::npos) { + t = Time (u); + } else { + t = Time (0, 0, 0, lexical_cast (u)); + } + + if (t > Time (0, 0, 8, 0)) { + t = Time (0, 0, 8, 0); + } + + return t; +} + +Text::Text (shared_ptr node) + : v_align (CENTER) +{ + text = node->content (); + v_position = node->number_attribute ("VPosition"); + optional v = node->optional_string_attribute ("VAlign"); + if (v) { + v_align = string_to_valign (v.get ()); + } + + font_nodes = type_children (node, "Font"); +} + diff --git a/src/parse/subtitle.h b/src/parse/subtitle.h new file mode 100644 index 00000000..34321545 --- /dev/null +++ b/src/parse/subtitle.h @@ -0,0 +1,93 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "../xml.h" +#include "../dcp_time.h" +#include "../types.h" + +namespace libdcp +{ + +namespace parse +{ + +class Font; + +class Text +{ +public: + Text () {} + Text (boost::shared_ptr node); + + float v_position; + VAlign v_align; + std::string text; + std::list > font_nodes; +}; + +class Subtitle +{ +public: + Subtitle () {} + Subtitle (boost::shared_ptr node); + + Time in; + Time out; + Time fade_up_time; + Time fade_down_time; + std::list > font_nodes; + std::list > text_nodes; + +private: + Time fade_time (boost::shared_ptr, std::string name); +}; + +class Font +{ +public: + Font () {} + Font (boost::shared_ptr node); + Font (std::list > const & font_nodes); + + std::string text; + std::string id; + int size; + boost::optional italic; + boost::optional color; + boost::optional effect; + boost::optional effect_color; + + std::list > subtitle_nodes; + std::list > font_nodes; + std::list > text_nodes; +}; + +class LoadFont +{ +public: + LoadFont () {} + LoadFont (boost::shared_ptr node); + + std::string id; + std::string uri; +}; + +} + +} diff --git a/src/pkl_file.cc b/src/pkl_file.cc deleted file mode 100644 index 9119d883..00000000 --- a/src/pkl_file.cc +++ /dev/null @@ -1,51 +0,0 @@ -/* - Copyright (C) 2012 Carl Hetherington - - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -/** @file src/pkl_file.cc - * @brief Classes used to parse a PKL. - */ - -#include -#include "pkl_file.h" - -using namespace std; -using namespace boost; -using namespace libdcp; - -PKLFile::PKLFile (string file) -{ - cxml::File f (file, "PackingList"); - - id = f.string_child ("Id"); - annotation_text = f.optional_string_child ("AnnotationText").get_value_or (""); - issue_date = f.string_child ("IssueDate"); - issuer = f.string_child ("Issuer"); - creator = f.string_child ("Creator"); - assets = type_grand_children (f, "AssetList", "Asset"); -} - -PKLAsset::PKLAsset (boost::shared_ptr node) -{ - id = node->string_child ("Id"); - annotation_text = node->optional_string_child ("AnnotationText").get_value_or (""); - hash = node->string_child ("Hash"); - size = node->number_child ("Size"); - type = node->string_child ("Type"); - original_file_name = node->optional_string_child ("OriginalFileName").get_value_or (""); -} diff --git a/src/pkl_file.h b/src/pkl_file.h deleted file mode 100644 index 77b83fca..00000000 --- a/src/pkl_file.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - Copyright (C) 2012 Carl Hetherington - - 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 - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -/** @file src/pkl_file.h - * @brief Classes used to parse a PKL - */ - -#include -#include "xml.h" - -namespace libdcp { - -class PKLAsset -{ -public: - PKLAsset () {} - PKLAsset (boost::shared_ptr); - - std::string id; - std::string annotation_text; - std::string hash; - int64_t size; - std::string type; - std::string original_file_name; -}; - -class PKLFile -{ -public: - PKLFile (std::string file); - - std::string id; - std::string annotation_text; - std::string issue_date; - std::string issuer; - std::string creator; - std::list > assets; -}; - -} diff --git a/src/subtitle_asset.cc b/src/subtitle_asset.cc index 1eae1fcc..d89d52de 100644 --- a/src/subtitle_asset.cc +++ b/src/subtitle_asset.cc @@ -63,8 +63,8 @@ SubtitleAsset::read_xml (string xml_file) xml->ignore_child ("LoadFont"); - list > font_nodes = type_children (xml, "Font"); - _load_font_nodes = type_children (xml, "LoadFont"); + list > font_nodes = type_children (xml, "Font"); + _load_font_nodes = type_children (xml, "LoadFont"); /* Now make Subtitle objects to represent the raw XML nodes in a sane way. @@ -77,16 +77,16 @@ SubtitleAsset::read_xml (string xml_file) void SubtitleAsset::examine_font_nodes ( shared_ptr xml, - list > const & font_nodes, + list > const & font_nodes, ParseState& parse_state ) { - for (list >::const_iterator i = font_nodes.begin(); i != font_nodes.end(); ++i) { + for (list >::const_iterator i = font_nodes.begin(); i != font_nodes.end(); ++i) { parse_state.font_nodes.push_back (*i); maybe_add_subtitle ((*i)->text, parse_state); - for (list >::iterator j = (*i)->subtitle_nodes.begin(); j != (*i)->subtitle_nodes.end(); ++j) { + for (list >::iterator j = (*i)->subtitle_nodes.begin(); j != (*i)->subtitle_nodes.end(); ++j) { parse_state.subtitle_nodes.push_back (*j); examine_text_nodes (xml, (*j)->text_nodes, parse_state); examine_font_nodes (xml, (*j)->font_nodes, parse_state); @@ -103,11 +103,11 @@ SubtitleAsset::examine_font_nodes ( void SubtitleAsset::examine_text_nodes ( shared_ptr xml, - list > const & text_nodes, + list > const & text_nodes, ParseState& parse_state ) { - for (list >::const_iterator i = text_nodes.begin(); i != text_nodes.end(); ++i) { + for (list >::const_iterator i = text_nodes.begin(); i != text_nodes.end(); ++i) { parse_state.text_nodes.push_back (*i); maybe_add_subtitle ((*i)->text, parse_state); examine_font_nodes (xml, (*i)->font_nodes, parse_state); @@ -129,9 +129,9 @@ SubtitleAsset::maybe_add_subtitle (string text, ParseState const & parse_state) assert (!parse_state.text_nodes.empty ()); assert (!parse_state.subtitle_nodes.empty ()); - FontNode effective_font (parse_state.font_nodes); - TextNode effective_text (*parse_state.text_nodes.back ()); - SubtitleNode effective_subtitle (*parse_state.subtitle_nodes.back ()); + libdcp::parse::Font effective_font (parse_state.font_nodes); + libdcp::parse::Text effective_text (*parse_state.text_nodes.back ()); + libdcp::parse::Subtitle effective_subtitle (*parse_state.subtitle_nodes.back ()); _subtitles.push_back ( shared_ptr ( @@ -154,109 +154,6 @@ SubtitleAsset::maybe_add_subtitle (string text, ParseState const & parse_state) ); } -FontNode::FontNode (shared_ptr node) -{ - text = node->content (); - - id = node->optional_string_attribute ("Id").get_value_or (""); - size = node->optional_number_attribute ("Size").get_value_or (0); - italic = node->optional_bool_attribute ("Italic").get_value_or (false); - optional c = node->optional_string_attribute ("Color"); - if (c) { - color = Color (c.get ()); - } - optional const e = node->optional_string_attribute ("Effect"); - if (e) { - effect = string_to_effect (e.get ()); - } - c = node->optional_string_attribute ( "EffectColor"); - if (c) { - effect_color = Color (c.get ()); - } - subtitle_nodes = type_children (node, "Subtitle"); - font_nodes = type_children (node, "Font"); - text_nodes = type_children (node, "Text"); -} - -FontNode::FontNode (list > const & font_nodes) - : size (0) - , italic (false) - , color ("FFFFFFFF") - , effect_color ("FFFFFFFF") -{ - for (list >::const_iterator i = font_nodes.begin(); i != font_nodes.end(); ++i) { - if (!(*i)->id.empty ()) { - id = (*i)->id; - } - if ((*i)->size != 0) { - size = (*i)->size; - } - if ((*i)->italic) { - italic = (*i)->italic.get (); - } - if ((*i)->color) { - color = (*i)->color.get (); - } - if ((*i)->effect) { - effect = (*i)->effect.get (); - } - if ((*i)->effect_color) { - effect_color = (*i)->effect_color.get (); - } - } -} - -LoadFontNode::LoadFontNode (shared_ptr node) -{ - id = node->string_attribute ("Id"); - uri = node->string_attribute ("URI"); -} - - -SubtitleNode::SubtitleNode (shared_ptr node) -{ - in = Time (node->string_attribute ("TimeIn")); - out = Time (node->string_attribute ("TimeOut")); - font_nodes = type_children (node, "Font"); - text_nodes = type_children (node, "Text"); - fade_up_time = fade_time (node, "FadeUpTime"); - fade_down_time = fade_time (node, "FadeDownTime"); -} - -Time -SubtitleNode::fade_time (shared_ptr node, string name) -{ - string const u = node->optional_string_attribute (name).get_value_or (""); - Time t; - - if (u.empty ()) { - t = Time (0, 0, 0, 20); - } else if (u.find (":") != string::npos) { - t = Time (u); - } else { - t = Time (0, 0, 0, lexical_cast (u)); - } - - if (t > Time (0, 0, 8, 0)) { - t = Time (0, 0, 8, 0); - } - - return t; -} - -TextNode::TextNode (shared_ptr node) - : v_align (CENTER) -{ - text = node->content (); - v_position = node->number_attribute ("VPosition"); - optional v = node->optional_string_attribute ("VAlign"); - if (v) { - v_align = string_to_valign (v.get ()); - } - - font_nodes = type_children (node, "Font"); -} - list > SubtitleAsset::subtitles_at (Time t) const { @@ -273,7 +170,7 @@ SubtitleAsset::subtitles_at (Time t) const std::string SubtitleAsset::font_id_to_name (string id) const { - list >::const_iterator i = _load_font_nodes.begin(); + list >::const_iterator i = _load_font_nodes.begin(); while (i != _load_font_nodes.end() && (*i)->id != id) { ++i; } diff --git a/src/subtitle_asset.h b/src/subtitle_asset.h index 591985d1..0d662d6c 100644 --- a/src/subtitle_asset.h +++ b/src/subtitle_asset.h @@ -20,71 +20,11 @@ #include "asset.h" #include "xml.h" #include "dcp_time.h" +#include "parse/subtitle.h" namespace libdcp { -class FontNode; - -class TextNode -{ -public: - TextNode () {} - TextNode (boost::shared_ptr node); - - float v_position; - VAlign v_align; - std::string text; - std::list > font_nodes; -}; - -class SubtitleNode -{ -public: - SubtitleNode () {} - SubtitleNode (boost::shared_ptr node); - - Time in; - Time out; - Time fade_up_time; - Time fade_down_time; - std::list > font_nodes; - std::list > text_nodes; - -private: - Time fade_time (boost::shared_ptr, std::string name); -}; - -class FontNode -{ -public: - FontNode () {} - FontNode (boost::shared_ptr node); - FontNode (std::list > const & font_nodes); - - std::string text; - std::string id; - int size; - boost::optional italic; - boost::optional color; - boost::optional effect; - boost::optional effect_color; - - std::list > subtitle_nodes; - std::list > font_nodes; - std::list > text_nodes; -}; - -class LoadFontNode -{ -public: - LoadFontNode () {} - LoadFontNode (boost::shared_ptr node); - - std::string id; - std::string uri; -}; - class Subtitle { public: @@ -210,22 +150,22 @@ private: std::string escape (std::string) const; struct ParseState { - std::list > font_nodes; - std::list > text_nodes; - std::list > subtitle_nodes; + std::list > font_nodes; + std::list > text_nodes; + std::list > subtitle_nodes; }; void maybe_add_subtitle (std::string text, ParseState const & parse_state); void examine_font_nodes ( boost::shared_ptr xml, - std::list > const & font_nodes, + std::list > const & font_nodes, ParseState& parse_state ); void examine_text_nodes ( boost::shared_ptr xml, - std::list > const & text_nodes, + std::list > const & text_nodes, ParseState& parse_state ); @@ -233,7 +173,7 @@ private: /* strangely, this is sometimes a string */ std::string _reel_number; std::string _language; - std::list > _load_font_nodes; + std::list > _load_font_nodes; std::list > _subtitles; bool _need_sort; diff --git a/src/wscript b/src/wscript index fb8f688e..37151e51 100644 --- a/src/wscript +++ b/src/wscript @@ -11,8 +11,6 @@ def build(bld): obj.use = 'libkumu-libdcp libasdcp-libdcp' obj.source = """ asset.cc - asset_map.cc - cpl_file.cc dcp.cc cpl.cc dcp_time.cc @@ -21,7 +19,6 @@ def build(bld): mxf_asset.cc picture_asset.cc picture_frame.cc - pkl_file.cc reel.cc argb_frame.cc sound_asset.cc @@ -30,6 +27,10 @@ def build(bld): types.cc util.cc version.cc + parse/asset_map.cc + parse/cpl.cc + parse/pkl.cc + parse/subtitle.cc """ headers = """ @@ -55,3 +56,4 @@ def build(bld): bld.install_files('${PREFIX}/include/libdcp', headers) if bld.env.STATIC: bld.install_files('${PREFIX}/lib', 'libdcp.a') + -- cgit v1.2.3