+void
+MidiTrack::non_realtime_locate (framepos_t pos)
+{
+ Track::non_realtime_locate(pos);
+
+ boost::shared_ptr<MidiPlaylist> playlist = midi_diskstream()->midi_playlist();
+ if (!playlist) {
+ return;
+ }
+
+ /* Get the top unmuted region at this position. */
+ boost::shared_ptr<MidiRegion> region = boost::dynamic_pointer_cast<MidiRegion>(
+ playlist->top_unmuted_region_at(pos));
+ if (!region) {
+ return;
+ }
+
+ Glib::Threads::Mutex::Lock lm (_control_lock, Glib::Threads::TRY_LOCK);
+ if (!lm.locked()) {
+ return;
+ }
+
+ /* Update track controllers based on its "automation". */
+ const framepos_t origin = region->position() - region->start();
+ BeatsFramesConverter bfc(_session.tempo_map(), origin);
+ for (Controls::const_iterator c = _controls.begin(); c != _controls.end(); ++c) {
+ boost::shared_ptr<MidiTrack::MidiControl> tcontrol;
+ boost::shared_ptr<Evoral::Control> rcontrol;
+ if ((tcontrol = boost::dynamic_pointer_cast<MidiTrack::MidiControl>(c->second)) &&
+ (rcontrol = region->control(tcontrol->parameter()))) {
+ const Evoral::Beats pos_beats = bfc.from(pos - origin);
+ tcontrol->set_value(rcontrol->list()->eval(pos_beats.to_double()));
+ }
+ }
+}
+