fix duplicating multiple selected regions - fixes #6202
[ardour.git] / gtk2_ardour / editor_ops.cc
index 52ef86771a2febaf3e68910d07d779fa1fca481f..cc67e02ee8ebca0fe21c0c3354b939a2402644cf 100644 (file)
@@ -61,7 +61,6 @@
 #include "canvas/canvas.h"
 
 #include "actions.h"
-#include "ardour_ui.h"
 #include "audio_region_view.h"
 #include "audio_streamview.h"
 #include "audio_time_axis.h"
@@ -98,6 +97,7 @@
 #include "time_axis_view.h"
 #include "transpose_dialog.h"
 #include "transform_dialog.h"
+#include "ui_config.h"
 
 #include "i18n.h"
 
@@ -2045,7 +2045,7 @@ Editor::temporal_zoom_to_frame (bool coarser, framepos_t frame)
 bool
 Editor::choose_new_marker_name(string &name) {
 
-       if (!ARDOUR_UI::config()->get_name_new_markers()) {
+       if (!UIConfiguration::instance().get_name_new_markers()) {
                /* don't prompt user for a new name */
                return true;
        }
@@ -2537,7 +2537,7 @@ Editor::get_preroll ()
 void
 Editor::maybe_locate_with_edit_preroll ( framepos_t location )
 {
-       if ( _session->transport_rolling() || !ARDOUR_UI::config()->get_follow_edits() || _ignore_follow_edits )
+       if ( _session->transport_rolling() || !UIConfiguration::instance().get_follow_edits() || _ignore_follow_edits )
                return;
 
        location -= get_preroll();
@@ -4792,6 +4792,7 @@ Editor::duplicate_some_regions (RegionSelection& regions, float times)
 
        framepos_t const start_frame = regions.start ();
        framepos_t const end_frame = regions.end_frame ();
+       framecnt_t const gap = end_frame - start_frame;
 
        begin_reversible_command (Operations::duplicate_region);
 
@@ -4806,9 +4807,10 @@ Editor::duplicate_some_regions (RegionSelection& regions, float times)
                latest_regionviews.clear ();
                sigc::connection c = rtv->view()->RegionViewAdded.connect (sigc::mem_fun(*this, &Editor::collect_new_region_view));
 
+               framepos_t const position = end_frame + (r->first_frame() - start_frame);
                playlist = (*i)->region()->playlist();
                playlist->clear_changes ();
-               playlist->duplicate (r, end_frame + (r->first_frame() - start_frame), times);
+               playlist->duplicate (r, position, gap, times);
                _session->add_command(new StatefulDiffCommand (playlist));
 
                c.disconnect ();
@@ -5177,6 +5179,8 @@ Editor::strip_region_silence ()
                }
        }
 
+       assert (!audio_only.empty());
+
        StripSilenceDialog d (_session, audio_only);
        int const r = d.run ();
 
@@ -5469,9 +5473,6 @@ Editor::apply_filter (Filter& filter, string command, ProgressReporter* progress
                                _session->add_commands (cmds);
                                
                                _session->add_command(new StatefulDiffCommand (playlist));
-
-                       } else {
-                               continue;
                        }
 
                        if (progress) {
@@ -6115,7 +6116,7 @@ Editor::set_playhead_cursor ()
                }
        }
 
-       if (ARDOUR_UI::config()->get_follow_edits()) {
+       if (UIConfiguration::instance().get_follow_edits()) {
                cancel_time_selection();
        }
 }
@@ -6123,6 +6124,10 @@ Editor::set_playhead_cursor ()
 void
 Editor::split_region ()
 {
+       if (_drags->active ()) {
+               return;
+       }
+
        //if a range is selected, separate it
        if ( !selection->time.empty()) {
                separate_regions_between (selection->time);
@@ -6294,14 +6299,15 @@ Editor::set_punch_start_from_edit_point ()
 {
        if (_session) {
 
-               framepos_t start;
-               framepos_t end;
+               framepos_t start = 0;
+               framepos_t end = max_framepos;
                
-               //use the existing loop end, if any
+               //use the existing punch end, if any
                Location* tpl = transport_punch_location();
-               if (tpl)
+               if (tpl) {
                        end = tpl->end();
-
+               }
+               
                if ((_edit_point == EditAtPlayhead) && _session->transport_rolling()) {
                        start = _session->audible_frame();
                } else {
@@ -6324,16 +6330,16 @@ Editor::set_punch_start_from_edit_point ()
 void
 Editor::set_punch_end_from_edit_point ()
 {
-printf("set punch end\n");
        if (_session) {
 
-               framepos_t start;
-               framepos_t end;
+               framepos_t start = 0;
+               framepos_t end = max_framepos;
                
-               //use the existing loop end, if any
+               //use the existing punch start, if any
                Location* tpl = transport_punch_location();
-               if (tpl)
+               if (tpl) {
                        start = tpl->start();
+               }
                
                if ((_edit_point == EditAtPlayhead) && _session->transport_rolling()) {
                        end = _session->audible_frame();
@@ -6344,7 +6350,6 @@ printf("set punch end\n");
                //snap the selection start/end
                snap_to(end);
                
-printf("set punch %d, %d\n", start, end);
                set_punch_range (start, end, _("set punch end from EP"));
 
        }
@@ -6353,17 +6358,17 @@ printf("set punch %d, %d\n", start, end);
 void
 Editor::set_loop_start_from_edit_point ()
 {
-printf("set loop start\n");
        if (_session) {
 
-               framepos_t start;
-               framepos_t end;
+               framepos_t start = 0;
+               framepos_t end = max_framepos;
                
                //use the existing loop end, if any
                Location* tpl = transport_loop_location();
-               if (tpl)
+               if (tpl) {
                        end = tpl->end();
-
+               }
+               
                if ((_edit_point == EditAtPlayhead) && _session->transport_rolling()) {
                        start = _session->audible_frame();
                } else {
@@ -6377,8 +6382,7 @@ printf("set loop start\n");
                if ( start > end ) {
                        end = max_framepos;
                }
-                               
-printf("set loop %d, %d\n", start, end);
+
                set_loop_range (start, end, _("set loop start from EP"));
        }
 
@@ -6389,13 +6393,14 @@ Editor::set_loop_end_from_edit_point ()
 {
        if (_session) {
 
-               framepos_t start;
-               framepos_t end;
+               framepos_t start = 0;
+               framepos_t end = max_framepos;
                
-               //use the existing loop end, if any
+               //use the existing loop start, if any
                Location* tpl = transport_loop_location();
-               if (tpl)
+               if (tpl) {
                        start = tpl->start();
+               }
                
                if ((_edit_point == EditAtPlayhead) && _session->transport_rolling()) {
                        end = _session->audible_frame();
@@ -6407,7 +6412,6 @@ Editor::set_loop_end_from_edit_point ()
                snap_to(end);
                
                set_loop_range (start, end, _("set loop end from EP"));
-
        }
 }
 
@@ -7286,7 +7290,7 @@ Editor::insert_time (
 
                if (all_playlists) {
                        RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (*x);
-                       if (rtav) {
+                       if (rtav && rtav->track ()) {
                                vector<boost::shared_ptr<Playlist> > all = _session->playlists->playlists_for_track (rtav->track ());
                                for (vector<boost::shared_ptr<Playlist> >::iterator p = all.begin(); p != all.end(); ++p) {
                                        pl.insert (*p);
@@ -7886,7 +7890,7 @@ Editor::unlock ()
        
        delete _main_menu_disabler;
 
-       if (ARDOUR_UI::config()->get_lock_gui_after_seconds()) {
+       if (UIConfiguration::instance().get_lock_gui_after_seconds()) {
                start_lock_event_timing ();
        }
 }