extensive changes to PresentationInfo API
[ardour.git] / libs / ardour / region.cc
index 8db3aa097a8e821134ba70a1344960c440847b04..1b9793313df485b1c081c701d086fb3cab33e3f5 100644 (file)
@@ -546,21 +546,24 @@ 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());
 
        if (!pl || _position_lock_style != MusicTime) {
                return;
        }
-       TempoMap& map (_session.tempo_map());
-       framepos_t pos = map.frame_at_beat (_beat);
+
+       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
@@ -1197,9 +1200,8 @@ Region::state ()
        /* note: flags are stored by derived classes */
 
        if (_position_lock_style != AudioTime) {
-               stringstream str;
-               str << _beat;
-               node->add_property ("beat", str.str());
+               snprintf (buf, sizeof(buf), "%lf", _beat);
+               node->add_property ("beat", buf);
        }
 
        for (uint32_t n=0; n < _sources.size(); ++n) {
@@ -1270,26 +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) {
                                _position_lock_style = AudioTime;
-                       }
-                       _beat = _session.tempo_map().bbt_to_beats (bbt_time);
-               }
-       }
-
-       if (_position_lock_style == MusicTime) {
-               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 {
+                               _beat = _session.tempo_map().beat_at_bbt (bbt_time);
                        }
                }
        }