AutomationTimeAxisView* atv = dynamic_cast<AutomationTimeAxisView*> (clicked_axisview);
assert (atv);
if (parent && dynamic_cast<MidiTimeAxisView*> (parent) && atv->show_regions ()) {
- /* create a MIDI region so that we have somewhere to put automation */
- _drags->set (new RegionCreateDrag (this, item, parent), event);
+
+ RouteTimeAxisView* p = dynamic_cast<RouteTimeAxisView*> (parent);
+ assert (p);
+ boost::shared_ptr<Playlist> pl = p->track()->playlist ();
+ if (pl->n_regions() == 0) {
+ /* Parent has no regions; create one so that we have somewhere to put automation */
+ _drags->set (new RegionCreateDrag (this, item, parent), event);
+ } else {
+ /* See if there's a region before the click that we can extend, and extend it if so */
+ framepos_t const t = event_frame (event);
+ boost::shared_ptr<Region> prev = pl->find_next_region (t, End, -1);
+ if (!prev) {
+ _drags->set (new RegionCreateDrag (this, item, parent), event);
+ } else {
+ prev->set_length (t - prev->position ());
+ }
+ }
} else {
/* rubberband drag to select automation points */
_drags->set (new EditorRubberbandSelectDrag (this, item), event);