Create a new layer if required on record to a track in stacked mode. Fixes #3391.
[ardour.git] / gtk2_ardour / streamview.cc
index 5201cf295ce0c29c4d36767c4881e2a1605d87d2..9f56f8c692930e8e1abc49429ff435349dcfa5bd 100644 (file)
@@ -578,7 +578,16 @@ StreamView::update_contents_height ()
        }
 
        for (vector<RecBoxInfo>::iterator i = rec_rects.begin(); i != rec_rects.end(); ++i) {
-               i->rectangle->property_y2() = height;
+               switch (_layer_display) {
+               case Overlaid:
+                       i->rectangle->property_y2() = height;
+                       break;
+               case Stacked:
+                       /* In stacked displays, the recregion is always at the top */
+                       i->rectangle->property_y1() = 0;
+                       i->rectangle->property_y2() = h;
+                       break;
+               }
        }
 }
 
@@ -598,3 +607,41 @@ StreamView::update_coverage_frames ()
                (*i)->update_coverage_frames (_layer_display);
        }
 }
+
+void
+StreamView::check_record_layers (boost::shared_ptr<Region> region, framepos_t to)
+{
+       if (_new_rec_layer_time < to) {
+               /* The region being recorded has overlapped the start of a top-layered region, so
+                  `fake' a new visual layer for the recording.  This is only a visual thing for now,
+                  as the proper layering will get sorted out when the recorded region is added to
+                  its playlist.
+               */
+
+               /* Stop this happening again */
+               _new_rec_layer_time = max_framepos;
+               
+               /* Make space in the view for the new layer */
+               ++_layers;
+               
+               /* Set the temporary region to the correct layer so that it gets drawn correctly */
+               region->set_layer (_layers - 1);
+               
+               /* and reset the view */
+               update_contents_height ();
+       }
+}
+
+void
+StreamView::setup_new_rec_layer_time (boost::shared_ptr<Region> region)
+{
+       /* If we are in Stacked mode, we may need to (visually) create a new layer to put the
+          recorded region in.  To work out where this needs to happen, find the start of the next
+          top-layered region after the start of the region we are recording and make a note of it.
+       */
+       if (_layer_display == Stacked) {
+               _new_rec_layer_time = _trackview.track()->playlist()->find_next_top_layer_position (region->start());
+       } else {
+               _new_rec_layer_time = max_framepos;
+       }
+}