extensive changes to PresentationInfo API
[ardour.git] / libs / ardour / region.cc
index ee666e51f02db0bb5a77f1eeb77cb1b64af7e6d3..1b9793313df485b1c081c701d086fb3cab33e3f5 100644 (file)
@@ -538,7 +538,7 @@ Region::set_position_lock_style (PositionLockStyle ps)
                _position_lock_style = ps;
 
                if (_position_lock_style == MusicTime) {
-                       _session.bbt_time (_position, _bbt_time);
+                       _beat = _session.tempo_map().beat_at_frame (_position);
                }
 
                send_change (Properties::position_lock_style);
@@ -546,7 +546,7 @@ Region::set_position_lock_style (PositionLockStyle ps)
 }
 
 void
-Region::update_after_tempo_map_change ()
+Region::update_after_tempo_map_change (bool send)
 {
        boost::shared_ptr<Playlist> pl (playlist());
 
@@ -554,14 +554,16 @@ Region::update_after_tempo_map_change ()
                return;
        }
 
-       TempoMap& map (_session.tempo_map());
-       framepos_t pos = map.frame_time (_bbt_time);
+       const framepos_t pos = _session.tempo_map().frame_at_beat (_beat);
        set_position_internal (pos, false);
 
        /* do this even if the position is the same. this helps out
           a GUI that has moved its representation already.
        */
-       send_change (Properties::position);
+
+       if (send) {
+               send_change (Properties::position);
+       }
 }
 
 void
@@ -651,7 +653,7 @@ void
 Region::recompute_position_from_lock_style ()
 {
        if (_position_lock_style == MusicTime) {
-               _session.bbt_time (_position, _bbt_time);
+               _beat = _session.tempo_map().beat_at_frame (_position);
        }
 }
 
@@ -1198,9 +1200,8 @@ Region::state ()
        /* note: flags are stored by derived classes */
 
        if (_position_lock_style != AudioTime) {
-               stringstream str;
-               str << _bbt_time;
-               node->add_property ("bbt-position", str.str());
+               snprintf (buf, sizeof(buf), "%lf", _beat);
+               node->add_property ("beat", buf);
        }
 
        for (uint32_t n=0; n < _sources.size(); ++n) {
@@ -1261,6 +1262,7 @@ int
 Region::_set_state (const XMLNode& node, int /*version*/, PropertyChange& what_changed, bool send)
 {
        XMLProperty const * prop;
+       Timecode::BBT_Time bbt_time;
 
        Stateful::save_extra_xml (node);
 
@@ -1270,14 +1272,23 @@ Region::_set_state (const XMLNode& node, int /*version*/, PropertyChange& what_c
 
        if (_position_lock_style == MusicTime) {
                if ((prop = node.property ("bbt-position")) == 0) {
-                       /* missing BBT info, revert to audio time locking */
-                       _position_lock_style = AudioTime;
+                       if ((prop = node.property ("beat")) == 0) {
+                               /* missing BBT info, revert to audio time locking */
+                               _position_lock_style = AudioTime;
+                       } else {
+                               if (sscanf (prop->value().c_str(), "%lf", &_beat) != 1) {
+                                       _position_lock_style = AudioTime;
+                               }
+                       }
+
                } else {
                        if (sscanf (prop->value().c_str(), "%d|%d|%d",
-                                   &_bbt_time.bars,
-                                   &_bbt_time.beats,
-                                   &_bbt_time.ticks) != 3) {
+                                   &bbt_time.bars,
+                                   &bbt_time.beats,
+                                   &bbt_time.ticks) != 3) {
                                _position_lock_style = AudioTime;
+                       } else {
+                               _beat = _session.tempo_map().beat_at_bbt (bbt_time);
                        }
                }
        }