Merge branch 'master' of ssh://carlh.dnsalias.org/home/carl/git/libdcp
[libdcp.git] / src / subtitle_asset.h
index d272957edc0346e175c48198094955bda364a98c..1b834522abff14126c6597143e19208b4d677c55 100644 (file)
@@ -24,6 +24,8 @@
 namespace libdcp
 {
 
+class FontNode;
+
 class TextNode : public XMLNode
 {
 public:
@@ -33,6 +35,7 @@ public:
        float v_position;
        VAlign v_align;
        std::string text;
+       std::list<boost::shared_ptr<FontNode> > font_nodes;
 };
 
 class SubtitleNode : public XMLNode
@@ -43,7 +46,13 @@ public:
 
        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 (std::string name);
 };
 
 class FontNode : public XMLNode
@@ -53,6 +62,7 @@ public:
        FontNode (xmlpp::Node const * node);
        FontNode (std::list<boost::shared_ptr<FontNode> > const & font_nodes);
 
+       std::string text;
        std::string id;
        int size;
        boost::optional<bool> italic;
@@ -62,6 +72,7 @@ public:
        
        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 XMLNode
@@ -88,7 +99,9 @@ public:
                VAlign v_align,
                std::string text,
                Effect effect,
-               Color effect_color
+               Color effect_color,
+               Time fade_up_time,
+               Time fade_down_time
                );
 
        std::string font () const {
@@ -131,6 +144,18 @@ public:
                return _effect_color;
        }
 
+       Time fade_up_time () const {
+               return _fade_up_time;
+       }
+
+       Time fade_down_time () const {
+               return _fade_down_time;
+       }
+
+       int size () const {
+               return _size;
+       }
+       
        int size_in_pixels (int screen_height) const;
 
 private:
@@ -145,17 +170,24 @@ private:
        std::string _text;
        Effect _effect;
        Color _effect_color;
+       Time _fade_up_time;
+       Time _fade_down_time;
 };
 
-class SubtitleAsset : public Asset, public XMLFile
+bool operator== (Subtitle const & a, Subtitle const & b);
+std::ostream& operator<< (std::ostream& s, Subtitle const & sub);
+
+class SubtitleAsset : public Asset
 {
 public:
-       SubtitleAsset (std::string directory, std::string xml);
+       SubtitleAsset (std::string directory, std::string xml_file);
+       SubtitleAsset (std::string directory, std::string movie_title, std::string language);
 
-       void write_to_cpl (std::ostream&) const {}
-       virtual std::list<std::string> equals (boost::shared_ptr<const Asset>, EqualityOptions) const {
+       void write_to_cpl (std::ostream&) const;
+       virtual bool equals (boost::shared_ptr<const Asset>, EqualityOptions, std::list<std::string>& notes) const {
                /* XXX */
-               return std::list<std::string> ();
+               notes.push_back ("subtitle assets not compared yet");
+               return true;
        }
 
        std::string language () const {
@@ -163,14 +195,40 @@ public:
        }
 
        std::list<boost::shared_ptr<Subtitle> > subtitles_at (Time t) const;
+       std::list<boost::shared_ptr<Subtitle> > const & subtitles () const {
+               return _subtitles;
+       }
+
+       void add (boost::shared_ptr<Subtitle>);
+
+       void write_xml ();
 
 private:
        std::string font_id_to_name (std::string id) const;
-       void examine_font_node (boost::shared_ptr<FontNode> font_node, std::list<boost::shared_ptr<FontNode> >& current_font_nodes);
+
+       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;
+       };
+
+       void maybe_add_subtitle (std::string text, ParseState const & parse_state);
+       
+       void examine_font_nodes (
+               boost::shared_ptr<XMLFile> xml,
+               std::list<boost::shared_ptr<FontNode> > const & font_nodes,
+               ParseState& parse_state
+               );
        
-       std::string _subtitle_id;
+       void examine_text_nodes (
+               boost::shared_ptr<XMLFile> xml,
+               std::list<boost::shared_ptr<TextNode> > const & text_nodes,
+               ParseState& parse_state
+               );
+
        std::string _movie_title;
-       int64_t _reel_number;
+       /* strangely, this is sometimes a string */
+       std::string _reel_number;
        std::string _language;
        std::list<boost::shared_ptr<LoadFontNode> > _load_font_nodes;