X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fsubrip_content.cc;h=a6eb0762927cd908eeb728a167d4d0a546345c0d;hb=db3cd90dadf60df72ebbd95c59b32954f29b9c38;hp=892578adecc11595bf8059ee2530f87bf88dca14;hpb=f1d30fb114b3b2c6ccd8fdf5823e7cd6b26c1eef;p=dcpomatic.git diff --git a/src/lib/subrip_content.cc b/src/lib/subrip_content.cc index 892578ade..a6eb07629 100644 --- a/src/lib/subrip_content.cc +++ b/src/lib/subrip_content.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014 Carl Hetherington + Copyright (C) 2014-2015 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 @@ -21,20 +21,30 @@ #include "util.h" #include "subrip.h" #include "film.h" -#include +#include "font.h" +#include "raw_convert.h" +#include +#include #include "i18n.h" -using std::stringstream; using std::string; using std::cout; -using dcp::raw_convert; using boost::shared_ptr; using boost::lexical_cast; +std::string const SubRipContent::font_id = "font"; + +int const SubRipContentProperty::SUBTITLE_COLOUR = 300; +int const SubRipContentProperty::SUBTITLE_OUTLINE = 301; +int const SubRipContentProperty::SUBTITLE_OUTLINE_COLOUR = 302; + SubRipContent::SubRipContent (shared_ptr film, boost::filesystem::path path) : Content (film, path) , SubtitleContent (film, path) + , _colour (255, 255, 255) + , _outline (false) + , _outline_colour (0, 0, 0) { } @@ -42,7 +52,19 @@ SubRipContent::SubRipContent (shared_ptr film, boost::filesystem::pa SubRipContent::SubRipContent (shared_ptr film, cxml::ConstNodePtr node, int version) : Content (film, node) , SubtitleContent (film, node, version) - , _length (node->number_child ("Length")) + , _length (node->number_child ("Length")) + , _frame_rate (node->optional_number_child("SubtitleFrameRate")) + , _colour ( + node->optional_number_child("Red").get_value_or(255), + node->optional_number_child("Green").get_value_or(255), + node->optional_number_child("Blue").get_value_or(255) + ) + , _outline (node->optional_bool_child("Outline").get_value_or(false)) + , _outline_colour ( + node->optional_number_child("OutlineRed").get_value_or(255), + node->optional_number_child("OutlineGreen").get_value_or(255), + node->optional_number_child("OutlineBlue").get_value_or(255) + ) { } @@ -53,13 +75,12 @@ SubRipContent::examine (boost::shared_ptr job) Content::examine (job); SubRip s (shared_from_this ()); - shared_ptr film = _film.lock (); - assert (film); - - DCPTime len (s.length (), film->active_frame_rate_change (position ())); + /* Default to turning these subtitles on */ + set_use_subtitles (true); boost::mutex::scoped_lock lm (_mutex); - _length = len; + _length = s.length (); + add_font (shared_ptr (new Font (font_id))); } string @@ -74,12 +95,6 @@ SubRipContent::technical_summary () const return Content::technical_summary() + " - " + _("SubRip subtitles"); } -string -SubRipContent::information () const -{ - -} - void SubRipContent::as_xml (xmlpp::Node* node) const { @@ -87,25 +102,90 @@ SubRipContent::as_xml (xmlpp::Node* node) const Content::as_xml (node); SubtitleContent::as_xml (node); node->add_child("Length")->add_child_text (raw_convert (_length.get ())); + node->add_child("Red")->add_child_text (raw_convert (_colour.r)); + node->add_child("Green")->add_child_text (raw_convert (_colour.g)); + node->add_child("Blue")->add_child_text (raw_convert (_colour.b)); + node->add_child("Outline")->add_child_text (raw_convert (_outline)); + node->add_child("OutlineRed")->add_child_text (raw_convert (_outline_colour.r)); + node->add_child("OutlineGreen")->add_child_text (raw_convert (_outline_colour.g)); + node->add_child("OutlineBlue")->add_child_text (raw_convert (_outline_colour.b)); } DCPTime SubRipContent::full_length () const { - /* XXX: this assumes that the timing of the SubRip file is appropriate - for the DCP's frame rate. + FrameRateChange const frc (subtitle_video_frame_rate(), film()->video_frame_rate ()); + return DCPTime (_length, frc); +} + +void +SubRipContent::set_subtitle_video_frame_rate (int r) +{ + { + boost::mutex::scoped_lock lm (_mutex); + _frame_rate = r; + } + + signal_changed (SubtitleContentProperty::SUBTITLE_VIDEO_FRAME_RATE); +} + +double +SubRipContent::subtitle_video_frame_rate () const +{ + { + boost::mutex::scoped_lock lm (_mutex); + if (_frame_rate) { + return _frame_rate.get (); + } + } + + /* No frame rate specified, so assume this content has been + prepared for any concurrent video content. */ - return _length; + return film()->active_frame_rate_change(position()).source; } -string -SubRipContent::identifier () const +void +SubRipContent::set_colour (dcp::Colour colour) +{ + { + boost::mutex::scoped_lock lm (_mutex); + if (_colour == colour) { + return; + } + + _colour = colour; + } + + signal_changed (SubRipContentProperty::SUBTITLE_COLOUR); +} + +void +SubRipContent::set_outline (bool o) { - stringstream s; - s << Content::identifier() - << "_" << raw_convert (subtitle_scale()) - << "_" << raw_convert (subtitle_x_offset()) - << "_" << raw_convert (subtitle_y_offset()); + { + boost::mutex::scoped_lock lm (_mutex); + if (_outline == o) { + return; + } + + _outline = o; + } + + signal_changed (SubRipContentProperty::SUBTITLE_OUTLINE); +} + +void +SubRipContent::set_outline_colour (dcp::Colour colour) +{ + { + boost::mutex::scoped_lock lm (_mutex); + if (_outline_colour == colour) { + return; + } + + _outline_colour = colour; + } - return s.str (); + signal_changed (SubRipContentProperty::SUBTITLE_OUTLINE_COLOUR); }