- AutomationList::const_iterator j = (*i)->model ();
- lists[al].copy->add ((*j)->when, (*j)->value);
+ AutomationList::const_iterator j = (*i)->model();
+
+ lists[al].copy->fast_simple_add ((*j)->when, (*j)->value);
+ if (midi) {
+ /* Update earliest MIDI start time in beats */
+ earliest = std::min(earliest, Evoral::Beats((*j)->when));
+ } else {
+ /* Update earliest session start time in frames */
+ start = std::min(start, (*i)->line().session_position(j));
+ }
+ }
+
+ /* Snap start time backwards, so copy/paste is snap aligned. */
+ if (midi) {
+ if (earliest == Evoral::Beats::max()) {
+ earliest = Evoral::Beats(); // Weird... don't offset
+ }
+ earliest.round_down_to_beat();
+ } else {
+ if (start == std::numeric_limits<double>::max()) {
+ start = 0; // Weird... don't offset
+ }
+ snap_to(start, RoundDownMaybe);