Add maybe_set to ContentPart.
authorCarl Hetherington <cth@carlh.net>
Wed, 13 Apr 2016 16:09:33 +0000 (17:09 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 18 May 2016 10:50:29 +0000 (11:50 +0100)
src/lib/content_part.h
src/lib/subtitle_content.cc
src/lib/video_content.cc

index 9ee26cbdb1d47378ac3502202aa473ffbfe5cd7b..dbc5232395bed3c49b8db3215b19b644df55b3cb 100644 (file)
@@ -20,6 +20,7 @@
 #ifndef DCPOMATIC_CONTENT_PART_H
 #define DCPOMATIC_CONTENT_PART_H
 
+#include "content.h"
 #include <boost/weak_ptr.hpp>
 #include <boost/thread/mutex.hpp>
 
@@ -35,6 +36,34 @@ public:
        {}
 
 protected:
+       template <class T>
+       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 <class T>
+       void
+       maybe_set (boost::optional<T>& 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<const Film> _film;
        mutable boost::mutex _mutex;
index a6dcbf9aef40dea4763802cdc336dbc77967889a..03c188b896b2c2a3c893689f72ac77c8ff3e7b13 100644 (file)
@@ -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);
 }
index 4059c29d1eb9395894d21543bbaa5d2b93ed0ea5..561ebb62cfcbc16da2ca7961941990858e66b0f0 100644 (file)
@@ -236,82 +236,6 @@ VideoContent::take_from_video_examiner (shared_ptr<VideoExaminer> 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<ColourConversion> ();
-       }
-
-       _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<double>
 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<ColourConversion> (), 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);
 }