summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2013-05-13 14:45:16 +0100
committerCarl Hetherington <cth@carlh.net>2013-05-13 14:45:16 +0100
commit7394f50d8b5334a17cac37c8956b1b7e8e5e49c8 (patch)
tree26a0d79b5ea6a2932bcc1ffbe75c8110716ebf26 /src
parent797916ae28d976f3c5be62d37b45864219af6098 (diff)
Try to move XML bits out into parse/ subdir.
Diffstat (limited to 'src')
-rw-r--r--src/cpl.cc14
-rw-r--r--src/cpl.h7
-rw-r--r--src/dcp.cc17
-rw-r--r--src/dcp.h1
-rw-r--r--src/parse/asset_map.cc (renamed from src/asset_map.cc)6
-rw-r--r--src/parse/asset_map.h (renamed from src/asset_map.h)4
-rw-r--r--src/parse/cpl.cc (renamed from src/cpl_file.cc)14
-rw-r--r--src/parse/cpl.h (renamed from src/cpl_file.h)22
-rw-r--r--src/parse/pkl.cc (renamed from src/pkl_file.cc)6
-rw-r--r--src/parse/pkl.h (renamed from src/pkl_file.h)12
-rw-r--r--src/parse/subtitle.cc135
-rw-r--r--src/parse/subtitle.h93
-rw-r--r--src/subtitle_asset.cc125
-rw-r--r--src/subtitle_asset.h74
-rw-r--r--src/wscript8
15 files changed, 309 insertions, 229 deletions
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 <fstream>
#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<const AssetMap> asset_map, bool require_mxfs)
+CPL::CPL (string directory, string file, shared_ptr<const libdcp::parse::AssetMap> asset_map, bool require_mxfs)
: _directory (directory)
, _content_kind (FEATURE)
, _length (0)
, _fps (0)
{
/* Read the XML */
- shared_ptr<CPLFile> cpl;
+ shared_ptr<parse::CPL> 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<const AssetMap> asset_map, b
_name = cpl->annotation_text;
_content_kind = cpl->content_kind;
- for (list<shared_ptr<CPLReel> >::iterator i = cpl->reels.begin(); i != cpl->reels.end(); ++i) {
+ for (list<shared_ptr<libdcp::parse::Reel> >::iterator i = cpl->reels.begin(); i != cpl->reels.end(); ++i) {
- shared_ptr<Picture> p;
+ shared_ptr<parse::Picture> 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<const AssetMap> asset_map, bool require_mxfs = true);
+ CPL (std::string directory, std::string file, boost::shared_ptr<const parse::AssetMap> asset_map, bool require_mxfs = true);
void add_reel (boost::shared_ptr<const Reel> reel);
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<AssetMap> asset_map;
+ shared_ptr<parse::AssetMap> 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<shared_ptr<AssetMapAsset> >::const_iterator i = asset_map->assets.begin(); i != asset_map->assets.end(); ++i) {
+ for (list<shared_ptr<libdcp::parse::AssetMapAsset> >::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<PKLFile> pkl;
+ shared_ptr<parse::PKL> 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/asset_map.cc b/src/parse/asset_map.cc
index fb42f363..aedc931e 100644
--- a/src/asset_map.cc
+++ b/src/parse/asset_map.cc
@@ -23,13 +23,13 @@
#include <boost/algorithm/string.hpp>
#include "asset_map.h"
-#include "util.h"
-#include "xml.h"
+#include "../util.h"
+#include "../xml.h"
using std::string;
using std::list;
using boost::shared_ptr;
-using namespace libdcp;
+using namespace libdcp::parse;
AssetMap::AssetMap (string file)
{
diff --git a/src/asset_map.h b/src/parse/asset_map.h
index e7ba6978..af3e8918 100644
--- a/src/asset_map.h
+++ b/src/parse/asset_map.h
@@ -27,6 +27,8 @@
namespace libdcp {
+namespace parse {
+
/** @class Chunk
* @brief A simple parser for and representation of a \<Chunk\> node within an asset map.
*/
@@ -75,3 +77,5 @@ public:
};
}
+
+}
diff --git a/src/cpl_file.cc b/src/parse/cpl.cc
index 3126b99c..c4cf4374 100644
--- a/src/cpl_file.cc
+++ b/src/parse/cpl.cc
@@ -22,16 +22,16 @@
*/
#include <iostream>
-#include "cpl_file.h"
-#include "xml.h"
-#include "util.h"
+#include "cpl.h"
+#include "../xml.h"
+#include "../util.h"
using std::string;
using std::bad_cast;
using boost::shared_ptr;
-using namespace libdcp;
+using namespace libdcp::parse;
-CPLFile::CPLFile (string file)
+CPL::CPL (string file)
{
cxml::File f (file, "CompositionPlaylist");
@@ -43,7 +43,7 @@ CPLFile::CPLFile (string file)
content_kind = content_kind_from_string (f.string_child ("ContentKind"));
content_version = optional_type_child<ContentVersion> (f, "ContentVersion");
f.ignore_child ("RatingList");
- reels = type_grand_children<CPLReel> (f, "ReelList", "Reel");
+ reels = type_grand_children<Reel> (f, "ReelList", "Reel");
f.ignore_child ("Issuer");
f.ignore_child ("Signer");
@@ -59,7 +59,7 @@ ContentVersion::ContentVersion (shared_ptr<const cxml::Node> node)
node->done ();
}
-CPLReel::CPLReel (shared_ptr<const cxml::Node> node)
+Reel::Reel (shared_ptr<const cxml::Node> node)
{
id = node->string_child ("Id");
asset_list = type_child<CPLAssetList> (node, "AssetList");
diff --git a/src/cpl_file.h b/src/parse/cpl.h
index b17f47cd..434a244b 100644
--- a/src/cpl_file.h
+++ b/src/parse/cpl.h
@@ -17,17 +17,19 @@
*/
-/** @file src/cpl_file.h
+/** @file src/parse/cpl.h
* @brief Classes used to parse a CPL.
*/
#include <stdint.h>
#include <boost/shared_ptr.hpp>
#include <libcxml/cxml.h>
-#include "types.h"
+#include "../types.h"
namespace libdcp {
+namespace parse {
+
/** @brief A simple representation of a CPL \<Picture\> node */
class Picture
{
@@ -109,11 +111,11 @@ public:
};
/** @brief A simple parser for and representation of a CPL \<Reel\> node */
-class CPLReel
+class Reel
{
public:
- CPLReel () {}
- CPLReel (boost::shared_ptr<const cxml::Node> node);
+ Reel () {}
+ Reel (boost::shared_ptr<const cxml::Node> node);
std::string id;
boost::shared_ptr<CPLAssetList> asset_list;
@@ -131,17 +133,17 @@ public:
std::string label_text;
};
-/** @class CPLFile
+/** @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 CPLFile
+class CPL
{
public:
/** Parse a CPL XML file into our member variables */
- CPLFile (std::string file);
+ CPL (std::string file);
std::string id;
std::string annotation_text;
@@ -150,8 +152,10 @@ public:
std::string content_title_text;
ContentKind content_kind;
boost::shared_ptr<ContentVersion> content_version;
- std::list<boost::shared_ptr<CPLReel> > reels;
+ std::list<boost::shared_ptr<Reel> > reels;
};
}
+}
+
diff --git a/src/pkl_file.cc b/src/parse/pkl.cc
index 9119d883..d790cfe4 100644
--- a/src/pkl_file.cc
+++ b/src/parse/pkl.cc
@@ -22,13 +22,13 @@
*/
#include <iostream>
-#include "pkl_file.h"
+#include "pkl.h"
using namespace std;
using namespace boost;
-using namespace libdcp;
+using namespace libdcp::parse;
-PKLFile::PKLFile (string file)
+PKL::PKL (string file)
{
cxml::File f (file, "PackingList");
diff --git a/src/pkl_file.h b/src/parse/pkl.h
index 77b83fca..13d87fa1 100644
--- a/src/pkl_file.h
+++ b/src/parse/pkl.h
@@ -17,15 +17,17 @@
*/
-/** @file src/pkl_file.h
+/** @file src/parse/pkl.h
* @brief Classes used to parse a PKL
*/
#include <boost/shared_ptr.hpp>
-#include "xml.h"
+#include "../xml.h"
namespace libdcp {
+namespace parse {
+
class PKLAsset
{
public:
@@ -40,10 +42,10 @@ public:
std::string original_file_name;
};
-class PKLFile
+class PKL
{
public:
- PKLFile (std::string file);
+ PKL (std::string file);
std::string id;
std::string annotation_text;
@@ -54,3 +56,5 @@ public:
};
}
+
+}
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 <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
+ 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 <boost/shared_ptr.hpp>
+#include <boost/optional.hpp>
+#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<const cxml::Node> node)
+{
+ text = node->content ();
+
+ id = node->optional_string_attribute ("Id").get_value_or ("");
+ size = node->optional_number_attribute<int64_t> ("Size").get_value_or (0);
+ italic = node->optional_bool_attribute ("Italic").get_value_or (false);
+ optional<string> c = node->optional_string_attribute ("Color");
+ if (c) {
+ color = Color (c.get ());
+ }
+ optional<string> 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<Subtitle> (node, "Subtitle");
+ font_nodes = type_children<Font> (node, "Font");
+ text_nodes = type_children<Text> (node, "Text");
+}
+
+Font::Font (list<shared_ptr<Font> > const & font_nodes)
+ : size (0)
+ , italic (false)
+ , color ("FFFFFFFF")
+ , effect_color ("FFFFFFFF")
+{
+ for (list<shared_ptr<Font> >::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<const cxml::Node> node)
+{
+ id = node->string_attribute ("Id");
+ uri = node->string_attribute ("URI");
+}
+
+
+Subtitle::Subtitle (shared_ptr<const cxml::Node> node)
+{
+ in = Time (node->string_attribute ("TimeIn"));
+ out = Time (node->string_attribute ("TimeOut"));
+ font_nodes = type_children<Font> (node, "Font");
+ text_nodes = type_children<Text> (node, "Text");
+ fade_up_time = fade_time (node, "FadeUpTime");
+ fade_down_time = fade_time (node, "FadeDownTime");
+}
+
+Time
+Subtitle::fade_time (shared_ptr<const cxml::Node> 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<int> (u));
+ }
+
+ if (t > Time (0, 0, 8, 0)) {
+ t = Time (0, 0, 8, 0);
+ }
+
+ return t;
+}
+
+Text::Text (shared_ptr<const cxml::Node> node)
+ : v_align (CENTER)
+{
+ text = node->content ();
+ v_position = node->number_attribute<float> ("VPosition");
+ optional<string> v = node->optional_string_attribute ("VAlign");
+ if (v) {
+ v_align = string_to_valign (v.get ());
+ }
+
+ font_nodes = type_children<Font> (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 <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
+ 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<const cxml::Node> node);
+
+ float v_position;
+ VAlign v_align;
+ std::string text;
+ std::list<boost::shared_ptr<Font> > font_nodes;
+};
+
+class Subtitle
+{
+public:
+ Subtitle () {}
+ Subtitle (boost::shared_ptr<const cxml::Node> node);
+
+ Time in;
+ Time out;
+ Time fade_up_time;
+ Time fade_down_time;
+ std::list<boost::shared_ptr<Font> > font_nodes;
+ std::list<boost::shared_ptr<Text> > text_nodes;
+
+private:
+ Time fade_time (boost::shared_ptr<const cxml::Node>, std::string name);
+};
+
+class Font
+{
+public:
+ Font () {}
+ Font (boost::shared_ptr<const cxml::Node> node);
+ Font (std::list<boost::shared_ptr<Font> > const & font_nodes);
+
+ std::string text;
+ std::string id;
+ int size;
+ boost::optional<bool> italic;
+ boost::optional<Color> color;
+ boost::optional<Effect> effect;
+ boost::optional<Color> effect_color;
+
+ std::list<boost::shared_ptr<Subtitle> > subtitle_nodes;
+ std::list<boost::shared_ptr<Font> > font_nodes;
+ std::list<boost::shared_ptr<Text> > text_nodes;
+};
+
+class LoadFont
+{
+public:
+ LoadFont () {}
+ LoadFont (boost::shared_ptr<const cxml::Node> node);
+
+ std::string id;
+ std::string uri;
+};
+
+}
+
+}
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<shared_ptr<FontNode> > font_nodes = type_children<FontNode> (xml, "Font");
- _load_font_nodes = type_children<LoadFontNode> (xml, "LoadFont");
+ list<shared_ptr<libdcp::parse::Font> > font_nodes = type_children<libdcp::parse::Font> (xml, "Font");
+ _load_font_nodes = type_children<libdcp::parse::LoadFont> (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<const cxml::Node> xml,
- list<shared_ptr<FontNode> > const & font_nodes,
+ list<shared_ptr<libdcp::parse::Font> > const & font_nodes,
ParseState& parse_state
)
{
- for (list<shared_ptr<FontNode> >::const_iterator i = font_nodes.begin(); i != font_nodes.end(); ++i) {
+ for (list<shared_ptr<libdcp::parse::Font> >::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<shared_ptr<SubtitleNode> >::iterator j = (*i)->subtitle_nodes.begin(); j != (*i)->subtitle_nodes.end(); ++j) {
+ for (list<shared_ptr<libdcp::parse::Subtitle> >::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<const cxml::Node> xml,
- list<shared_ptr<TextNode> > const & text_nodes,
+ list<shared_ptr<libdcp::parse::Text> > const & text_nodes,
ParseState& parse_state
)
{
- for (list<shared_ptr<TextNode> >::const_iterator i = text_nodes.begin(); i != text_nodes.end(); ++i) {
+ for (list<shared_ptr<libdcp::parse::Text> >::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<Subtitle> (
@@ -154,109 +154,6 @@ SubtitleAsset::maybe_add_subtitle (string text, ParseState const & parse_state)
);
}
-FontNode::FontNode (shared_ptr<const cxml::Node> node)
-{
- text = node->content ();
-
- id = node->optional_string_attribute ("Id").get_value_or ("");
- size = node->optional_number_attribute<int64_t> ("Size").get_value_or (0);
- italic = node->optional_bool_attribute ("Italic").get_value_or (false);
- optional<string> c = node->optional_string_attribute ("Color");
- if (c) {
- color = Color (c.get ());
- }
- optional<string> 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<SubtitleNode> (node, "Subtitle");
- font_nodes = type_children<FontNode> (node, "Font");
- text_nodes = type_children<TextNode> (node, "Text");
-}
-
-FontNode::FontNode (list<shared_ptr<FontNode> > const & font_nodes)
- : size (0)
- , italic (false)
- , color ("FFFFFFFF")
- , effect_color ("FFFFFFFF")
-{
- for (list<shared_ptr<FontNode> >::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<const cxml::Node> node)
-{
- id = node->string_attribute ("Id");
- uri = node->string_attribute ("URI");
-}
-
-
-SubtitleNode::SubtitleNode (shared_ptr<const cxml::Node> node)
-{
- in = Time (node->string_attribute ("TimeIn"));
- out = Time (node->string_attribute ("TimeOut"));
- font_nodes = type_children<FontNode> (node, "Font");
- text_nodes = type_children<TextNode> (node, "Text");
- fade_up_time = fade_time (node, "FadeUpTime");
- fade_down_time = fade_time (node, "FadeDownTime");
-}
-
-Time
-SubtitleNode::fade_time (shared_ptr<const cxml::Node> 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<int> (u));
- }
-
- if (t > Time (0, 0, 8, 0)) {
- t = Time (0, 0, 8, 0);
- }
-
- return t;
-}
-
-TextNode::TextNode (shared_ptr<const cxml::Node> node)
- : v_align (CENTER)
-{
- text = node->content ();
- v_position = node->number_attribute<float> ("VPosition");
- optional<string> v = node->optional_string_attribute ("VAlign");
- if (v) {
- v_align = string_to_valign (v.get ());
- }
-
- font_nodes = type_children<FontNode> (node, "Font");
-}
-
list<shared_ptr<Subtitle> >
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<shared_ptr<LoadFontNode> >::const_iterator i = _load_font_nodes.begin();
+ list<shared_ptr<libdcp::parse::LoadFont> >::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<const cxml::Node> node);
-
- float v_position;
- VAlign v_align;
- std::string text;
- std::list<boost::shared_ptr<FontNode> > font_nodes;
-};
-
-class SubtitleNode
-{
-public:
- SubtitleNode () {}
- SubtitleNode (boost::shared_ptr<const cxml::Node> node);
-
- Time in;
- Time out;
- Time fade_up_time;
- Time fade_down_time;
- std::list<boost::shared_ptr<FontNode> > font_nodes;
- std::list<boost::shared_ptr<TextNode> > text_nodes;
-
-private:
- Time fade_time (boost::shared_ptr<const cxml::Node>, std::string name);
-};
-
-class FontNode
-{
-public:
- FontNode () {}
- FontNode (boost::shared_ptr<const cxml::Node> node);
- FontNode (std::list<boost::shared_ptr<FontNode> > const & font_nodes);
-
- std::string text;
- std::string id;
- int size;
- boost::optional<bool> italic;
- boost::optional<Color> color;
- boost::optional<Effect> effect;
- boost::optional<Color> effect_color;
-
- std::list<boost::shared_ptr<SubtitleNode> > subtitle_nodes;
- std::list<boost::shared_ptr<FontNode> > font_nodes;
- std::list<boost::shared_ptr<TextNode> > text_nodes;
-};
-
-class LoadFontNode
-{
-public:
- LoadFontNode () {}
- LoadFontNode (boost::shared_ptr<const cxml::Node> 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<boost::shared_ptr<FontNode> > font_nodes;
- std::list<boost::shared_ptr<TextNode> > text_nodes;
- std::list<boost::shared_ptr<SubtitleNode> > subtitle_nodes;
+ std::list<boost::shared_ptr<parse::Font> > font_nodes;
+ std::list<boost::shared_ptr<parse::Text> > text_nodes;
+ std::list<boost::shared_ptr<parse::Subtitle> > subtitle_nodes;
};
void maybe_add_subtitle (std::string text, ParseState const & parse_state);
void examine_font_nodes (
boost::shared_ptr<const cxml::Node> xml,
- std::list<boost::shared_ptr<FontNode> > const & font_nodes,
+ std::list<boost::shared_ptr<parse::Font> > const & font_nodes,
ParseState& parse_state
);
void examine_text_nodes (
boost::shared_ptr<const cxml::Node> xml,
- std::list<boost::shared_ptr<TextNode> > const & text_nodes,
+ std::list<boost::shared_ptr<parse::Text> > 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<boost::shared_ptr<LoadFontNode> > _load_font_nodes;
+ std::list<boost::shared_ptr<parse::LoadFont> > _load_font_nodes;
std::list<boost::shared_ptr<Subtitle> > _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')
+