From: Carl Hetherington Date: Wed, 13 Apr 2016 16:09:33 +0000 (+0100) Subject: Add maybe_set to ContentPart. X-Git-Tag: v2.8.4~49 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=7749e3cc9ac7b51c2a77ee4f2c3c99e381747716 Add maybe_set to ContentPart. --- diff --git a/src/lib/content_part.h b/src/lib/content_part.h index 9ee26cbdb..dbc523239 100644 --- a/src/lib/content_part.h +++ b/src/lib/content_part.h @@ -20,6 +20,7 @@ #ifndef DCPOMATIC_CONTENT_PART_H #define DCPOMATIC_CONTENT_PART_H +#include "content.h" #include #include @@ -35,6 +36,34 @@ public: {} protected: + template + void + maybe_set (T& member, T new_value, int property) const + { + { + boost::mutex::scoped_lock lm (_mutex); + if (member == new_value) { + return; + } + member = new_value; + } + _parent->signal_changed (property); + } + + template + void + maybe_set (boost::optional& member, T new_value, int property) const + { + { + boost::mutex::scoped_lock lm (_mutex); + if (member && member.get() == new_value) { + return; + } + member = new_value; + } + _parent->signal_changed (property); + } + Content* _parent; boost::weak_ptr _film; mutable boost::mutex _mutex; diff --git a/src/lib/subtitle_content.cc b/src/lib/subtitle_content.cc index a6dcbf9ae..03c188b89 100644 --- a/src/lib/subtitle_content.cc +++ b/src/lib/subtitle_content.cc @@ -204,76 +204,6 @@ SubtitleContent::as_xml (xmlpp::Node* root) const } } -void -SubtitleContent::set_use_subtitles (bool u) -{ - { - boost::mutex::scoped_lock lm (_mutex); - _use_subtitles = u; - } - _parent->signal_changed (SubtitleContentProperty::USE_SUBTITLES); -} - -void -SubtitleContent::set_burn_subtitles (bool b) -{ - { - boost::mutex::scoped_lock lm (_mutex); - _burn_subtitles = b; - } - _parent->signal_changed (SubtitleContentProperty::BURN_SUBTITLES); -} - -void -SubtitleContent::set_subtitle_x_offset (double o) -{ - { - boost::mutex::scoped_lock lm (_mutex); - _subtitle_x_offset = o; - } - _parent->signal_changed (SubtitleContentProperty::SUBTITLE_X_OFFSET); -} - -void -SubtitleContent::set_subtitle_y_offset (double o) -{ - { - boost::mutex::scoped_lock lm (_mutex); - _subtitle_y_offset = o; - } - _parent->signal_changed (SubtitleContentProperty::SUBTITLE_Y_OFFSET); -} - -void -SubtitleContent::set_subtitle_x_scale (double s) -{ - { - boost::mutex::scoped_lock lm (_mutex); - _subtitle_x_scale = s; - } - _parent->signal_changed (SubtitleContentProperty::SUBTITLE_X_SCALE); -} - -void -SubtitleContent::set_subtitle_y_scale (double s) -{ - { - boost::mutex::scoped_lock lm (_mutex); - _subtitle_y_scale = s; - } - _parent->signal_changed (SubtitleContentProperty::SUBTITLE_Y_SCALE); -} - -void -SubtitleContent::set_subtitle_language (string language) -{ - { - boost::mutex::scoped_lock lm (_mutex); - _subtitle_language = language; - } - _parent->signal_changed (SubtitleContentProperty::SUBTITLE_LANGUAGE); -} - string SubtitleContent::identifier () const { @@ -329,44 +259,59 @@ SubtitleContent::font_changed () void SubtitleContent::set_colour (dcp::Colour colour) { - { - boost::mutex::scoped_lock lm (_mutex); - if (_colour == colour) { - return; - } + maybe_set (_colour, colour, SubtitleContentProperty::SUBTITLE_COLOUR); +} - _colour = colour; - } +void +SubtitleContent::set_outline (bool o) +{ + maybe_set (_outline, o, SubtitleContentProperty::SUBTITLE_OUTLINE); +} - _parent->signal_changed (SubtitleContentProperty::SUBTITLE_COLOUR); +void +SubtitleContent::set_outline_colour (dcp::Colour colour) +{ + maybe_set (_outline_colour, colour, SubtitleContentProperty::SUBTITLE_OUTLINE_COLOUR); } void -SubtitleContent::set_outline (bool o) +SubtitleContent::set_use_subtitles (bool u) { - { - boost::mutex::scoped_lock lm (_mutex); - if (_outline == o) { - return; - } + maybe_set (_use_subtitles, u, SubtitleContentProperty::USE_SUBTITLES); +} - _outline = o; - } +void +SubtitleContent::set_burn_subtitles (bool b) +{ + maybe_set (_burn_subtitles, b, SubtitleContentProperty::BURN_SUBTITLES); +} - _parent->signal_changed (SubtitleContentProperty::SUBTITLE_OUTLINE); +void +SubtitleContent::set_subtitle_x_offset (double o) +{ + maybe_set (_subtitle_x_offset, o, SubtitleContentProperty::SUBTITLE_X_OFFSET); } void -SubtitleContent::set_outline_colour (dcp::Colour colour) +SubtitleContent::set_subtitle_y_offset (double o) { - { - boost::mutex::scoped_lock lm (_mutex); - if (_outline_colour == colour) { - return; - } + maybe_set (_subtitle_y_offset, o, SubtitleContentProperty::SUBTITLE_Y_OFFSET); +} - _outline_colour = colour; - } +void +SubtitleContent::set_subtitle_x_scale (double s) +{ + maybe_set (_subtitle_x_scale, s, SubtitleContentProperty::SUBTITLE_X_SCALE); +} + +void +SubtitleContent::set_subtitle_y_scale (double s) +{ + maybe_set (_subtitle_y_scale, s, SubtitleContentProperty::SUBTITLE_Y_SCALE); +} - _parent->signal_changed (SubtitleContentProperty::SUBTITLE_OUTLINE_COLOUR); +void +SubtitleContent::set_subtitle_language (string language) +{ + maybe_set (_subtitle_language, language, SubtitleContentProperty::SUBTITLE_LANGUAGE); } diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc index 4059c29d1..561ebb62c 100644 --- a/src/lib/video_content.cc +++ b/src/lib/video_content.cc @@ -236,82 +236,6 @@ VideoContent::take_from_video_examiner (shared_ptr d) _parent->signal_changed (ContentProperty::LENGTH); } -void -VideoContent::set_left_crop (int c) -{ - { - boost::mutex::scoped_lock lm (_mutex); - - if (_crop.left == c) { - return; - } - - _crop.left = c; - } - - _parent->signal_changed (VideoContentProperty::VIDEO_CROP); -} - -void -VideoContent::set_right_crop (int c) -{ - { - boost::mutex::scoped_lock lm (_mutex); - if (_crop.right == c) { - return; - } - - _crop.right = c; - } - - _parent->signal_changed (VideoContentProperty::VIDEO_CROP); -} - -void -VideoContent::set_top_crop (int c) -{ - { - boost::mutex::scoped_lock lm (_mutex); - if (_crop.top == c) { - return; - } - - _crop.top = c; - } - - _parent->signal_changed (VideoContentProperty::VIDEO_CROP); -} - -void -VideoContent::set_bottom_crop (int c) -{ - { - boost::mutex::scoped_lock lm (_mutex); - if (_crop.bottom == c) { - return; - } - - _crop.bottom = c; - } - - _parent->signal_changed (VideoContentProperty::VIDEO_CROP); -} - -void -VideoContent::set_scale (VideoContentScale s) -{ - { - boost::mutex::scoped_lock lm (_mutex); - if (_scale == s) { - return; - } - - _scale = s; - } - - _parent->signal_changed (VideoContentProperty::VIDEO_SCALE); -} - /** @return string which includes everything about how this content looks */ string VideoContent::identifier () const @@ -332,17 +256,6 @@ VideoContent::identifier () const return s.str (); } -void -VideoContent::set_video_frame_type (VideoFrameType t) -{ - { - boost::mutex::scoped_lock lm (_mutex); - _video_frame_type = t; - } - - _parent->signal_changed (VideoContentProperty::VIDEO_FRAME_TYPE); -} - string VideoContent::technical_summary () const { @@ -380,50 +293,6 @@ VideoContent::video_size_after_3d_split () const DCPOMATIC_ASSERT (false); } -void -VideoContent::unset_colour_conversion () -{ - { - boost::mutex::scoped_lock lm (_mutex); - _colour_conversion = boost::optional (); - } - - _parent->signal_changed (VideoContentProperty::COLOUR_CONVERSION); -} - -void -VideoContent::set_colour_conversion (ColourConversion c) -{ - { - boost::mutex::scoped_lock lm (_mutex); - _colour_conversion = c; - } - - _parent->signal_changed (VideoContentProperty::COLOUR_CONVERSION); -} - -void -VideoContent::set_fade_in (Frame t) -{ - { - boost::mutex::scoped_lock lm (_mutex); - _fade_in = t; - } - - _parent->signal_changed (VideoContentProperty::VIDEO_FADE_IN); -} - -void -VideoContent::set_fade_out (Frame t) -{ - { - boost::mutex::scoped_lock lm (_mutex); - _fade_out = t; - } - - _parent->signal_changed (VideoContentProperty::VIDEO_FADE_OUT); -} - /** @return Video size after 3D split and crop */ dcp::Size VideoContent::video_size_after_crop () const @@ -459,21 +328,6 @@ VideoContent::scale_and_crop_to_fit_height () set_bottom_crop (0); } -void -VideoContent::set_video_frame_rate (double r) -{ - { - boost::mutex::scoped_lock lm (_mutex); - if (_video_frame_rate == r) { - return; - } - - _video_frame_rate = r; - } - - _parent->signal_changed (VideoContentProperty::VIDEO_FRAME_RATE); -} - /** @param f Frame index within the whole (untrimmed) content */ optional VideoContent::fade (Frame f) const @@ -580,10 +434,71 @@ VideoContent::video_frame_rate () const void VideoContent::set_video_length (Frame len) { - { - boost::mutex::scoped_lock lm (_mutex); - _video_length = len; - } + maybe_set (_video_length, len, ContentProperty::LENGTH); +} - _parent->signal_changed (ContentProperty::LENGTH); +void +VideoContent::set_left_crop (int c) +{ + maybe_set (_crop.left, c, VideoContentProperty::VIDEO_CROP); +} + +void +VideoContent::set_right_crop (int c) +{ + maybe_set (_crop.right, c, VideoContentProperty::VIDEO_CROP); +} + +void +VideoContent::set_top_crop (int c) +{ + maybe_set (_crop.top, c, VideoContentProperty::VIDEO_CROP); +} + +void +VideoContent::set_bottom_crop (int c) +{ + maybe_set (_crop.bottom, c, VideoContentProperty::VIDEO_CROP); +} + +void +VideoContent::set_scale (VideoContentScale s) +{ + maybe_set (_scale, s, VideoContentProperty::VIDEO_SCALE); +} + +void +VideoContent::set_video_frame_rate (double r) +{ + maybe_set (_video_frame_rate, r, VideoContentProperty::VIDEO_FRAME_RATE); +} + +void +VideoContent::set_video_frame_type (VideoFrameType t) +{ + maybe_set (_video_frame_type, t, VideoContentProperty::VIDEO_FRAME_TYPE); +} + +void +VideoContent::unset_colour_conversion () +{ + maybe_set (_colour_conversion, boost::optional (), VideoContentProperty::COLOUR_CONVERSION); +} + +void +VideoContent::set_colour_conversion (ColourConversion c) +{ + maybe_set (_colour_conversion, c, VideoContentProperty::COLOUR_CONVERSION); +} + +void +VideoContent::set_fade_in (Frame t) +{ + maybe_set (_fade_in, t, VideoContentProperty::VIDEO_FADE_IN); +} + +void +VideoContent::set_fade_out (Frame t) +{ + maybe_set (_fade_out, t, VideoContentProperty::VIDEO_FADE_OUT); }