Fix crash on emitting a signal during a constructor.
[dcpomatic.git] / src / lib / content.cc
index a8e592ba75d88d2d19b054cbbba5c9a93ac72499..3b9c3e3a1e55e13503641b4fd6d8c3586f87122f 100644 (file)
@@ -33,6 +33,7 @@
 #include <libcxml/cxml.h>
 #include <libxml++/libxml++.h>
 #include <boost/thread/mutex.hpp>
+#include <iostream>
 
 #include "i18n.h"
 
@@ -154,7 +155,12 @@ Content::examine (shared_ptr<Job> job)
 void
 Content::signal_changed (int p)
 {
-       emit (boost::bind (boost::ref (Changed), shared_from_this (), p, _change_signals_frequent));
+       try {
+               emit (boost::bind (boost::ref (Changed), shared_from_this (), p, _change_signals_frequent));
+               changed (p);
+       } catch (boost::bad_weak_ptr) {
+               /* This must be during construction; never mind */
+       }
 }
 
 void
@@ -222,13 +228,11 @@ Content::technical_summary () const
 DCPTime
 Content::length_after_trim () const
 {
-       shared_ptr<const Film> film = _film.lock ();
-       DCPOMATIC_ASSERT (film);
-       return max (DCPTime (), full_length() - DCPTime (trim_start() + trim_end(), film->active_frame_rate_change (position ())));
+       return max (DCPTime (), full_length() - DCPTime (trim_start() + trim_end(), film()->active_frame_rate_change (position ())));
 }
 
-/** @return string which includes everything about how this content affects
- *  its playlist.
+/** @return string which changes when something about this content changes which affects
+ *  the appearance of its video.
  */
 string
 Content::identifier () const
@@ -278,13 +282,29 @@ Content::path_summary () const
        return s;
 }
 
-/** @return a list of properties that might be interesting to the user; first string is the property name,
- *  second is the value.
- */
-list<pair<string, string> >
-Content::properties () const
+/** @return a list of properties that might be interesting to the user */
+list<UserProperty>
+Content::user_properties () const
 {
-       list<pair<string, string> > p;
+       list<UserProperty> p;
        add_properties (p);
        return p;
 }
+
+shared_ptr<const Film>
+Content::film () const
+{
+       shared_ptr<const Film> film = _film.lock ();
+       DCPOMATIC_ASSERT (film);
+       return film;
+}
+
+/** @return DCP times of points within this content where a reel split could occur */
+list<DCPTime>
+Content::reel_split_points () const
+{
+       list<DCPTime> t;
+       /* XXX: this is questionable; perhaps the position itself should be forced to be on a frame boundary */
+       t.push_back (position().round_up (film()->video_frame_rate()));
+       return t;
+}