Load midi region length and start correctly in sessions modified by v5.0 -> 5.3-41
authornick_m <mainsbridge@gmail.com>
Tue, 6 Sep 2016 14:18:35 +0000 (00:18 +1000)
committernick_m <mainsbridge@gmail.com>
Tue, 6 Sep 2016 14:18:35 +0000 (00:18 +1000)
libs/ardour/ardour/session.h
libs/ardour/midi_region.cc
libs/ardour/session.cc
libs/ardour/session_state.cc

index 858a2c6d97e51e93cfdf888e72de5a81975cc8ef..bb2da411c851b4a18a544e8e90a954aa7170229c 100644 (file)
@@ -1128,6 +1128,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
 
        VCAManager& vca_manager() { return *_vca_manager; }
 
+       bool midi_regions_use_bbt_beats () { return _midi_regions_use_bbt_beats; }
+
   protected:
        friend class AudioEngine;
        void set_block_size (pframes_t nframes);
@@ -2016,6 +2018,8 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop
        boost::shared_ptr<Route> get_midi_nth_route_by_id (PresentationInfo::order_t n) const;
 
        std::string created_with;
+
+       bool _midi_regions_use_bbt_beats;
 };
 
 
index cf723792116b276a2e5659853981caf193a122b1..67bd7a1b3d8fc94a7883b82b1c0967b8c0321de4 100644 (file)
@@ -439,10 +439,18 @@ MidiRegion::set_state (const XMLNode& node, int version)
                if (position_lock_style() == AudioTime) {
                        update_length_beats (0);
                }
-       }
 
-       _start_pulse = _start_beats.val().to_double() / 4.0;
-       _length_pulse = _length_beats.val().to_double() / 4.0;
+               if (_session.midi_regions_use_bbt_beats()) {
+                       info << _("Updating midi region start and length beats") << endmsg;
+                       TempoMap& map (_session.tempo_map());
+                       _start_beats = Evoral::Beats ((map.pulse_at_beat (_beat) - map.pulse_at_beat (_beat - _start_beats.val().to_double())) * 4.0);
+                       _length_beats = Evoral::Beats ((map.pulse_at_beat (_beat + _length_beats.val().to_double()) - map.pulse_at_beat (_beat)) * 4.0);
+
+               }
+
+               _start_pulse = _start_beats.val().to_double() / 4.0;
+               _length_pulse = _length_beats.val().to_double() / 4.0;
+       }
 
        return ret;
 }
index fc66dfe602ff38f512dfacba71436eceaa7ad4c7..9fd3539dae045990b31957393a49b92465e95566 100644 (file)
@@ -318,6 +318,7 @@ Session::Session (AudioEngine &eng,
        , _midi_ports (0)
        , _mmc (0)
        , _vca_manager (new VCAManager (*this))
+       , _midi_regions_use_bbt_beats (false)
 {
        uint32_t sr = 0;
 
@@ -477,10 +478,10 @@ Session::Session (AudioEngine &eng,
                }
        }
 #endif
+       _midi_regions_use_bbt_beats = false;
 
        _is_new = false;
        session_loaded ();
-
        BootMessage (_("Session loading complete"));
 }
 
index 41d6d519795efbe04fc39d17e211dc7d52372754..48048ba764d31edfd78d0b66a5124c601f0d9999 100644 (file)
@@ -1000,6 +1000,20 @@ Session::load_state (string snapshot_name)
                                return -1;
                        }
                }
+       } else {
+               XMLNode* child;
+               if ((child = find_named_node (root, "ProgramVersion")) != 0) {
+                       if ((prop = child->property ("modified-with")) != 0) {
+                               std::string modified_with = prop->value ();
+
+                               const double modified_with_version = atof (modified_with.substr ( modified_with.find(" ", 0) + 1, string::npos).c_str());
+                               const int modified_with_revision = atoi (modified_with.substr (modified_with.find("-", 0) + 1, string::npos).c_str());
+
+                               if (modified_with_version <= 5.3 && !(modified_with_version == 5.3 && modified_with_revision >= 42)) {
+                                       _midi_regions_use_bbt_beats = true;
+                               }
+                       }
+               }
        }
 
        save_snapshot_name (snapshot_name);