Extend a previous region if we click in a MIDI automation lane where there is no...
authorCarl Hetherington <carl@carlh.net>
Sat, 9 Jun 2012 00:36:21 +0000 (00:36 +0000)
committerCarl Hetherington <carl@carlh.net>
Sat, 9 Jun 2012 00:36:21 +0000 (00:36 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@12622 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor_mouse.cc

index 1ce02457fc847271026edba4108a77accc30671e..011374f9511ac0077652ed99f43a4041c9158c9e 100644 (file)
@@ -1003,8 +1003,23 @@ Editor::button_press_handler_1 (ArdourCanvas::Item* item, GdkEvent* event, ItemT
                                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);