first part of MIDI cut/copy/paste ; fix for input/output_streams of an IOProcessor...
[ardour.git] / gtk2_ardour / editor_ops.cc
index 0570a436481891c2deb17a11939a44aa31a94c95..0a7543b214a4ae6ce233a47bd7fbd5a06c253a07 100644 (file)
@@ -198,7 +198,7 @@ Editor::split_regions_at (nframes64_t where, RegionSelection& regions)
 }
 
 boost::shared_ptr<Region>
-Editor::select_region_for_operation (int dir, TimeAxisView **tv)
+Editor::select_region_for_operation (int /*dir*/, TimeAxisView **tv)
 {
        RegionView* rv;
        boost::shared_ptr<Region> region;
@@ -1800,7 +1800,7 @@ Editor::temporal_zoom_session ()
 }
 
 void
-Editor::temporal_zoom_by_frame (nframes64_t start, nframes64_t end, const string & op)
+Editor::temporal_zoom_by_frame (nframes64_t start, nframes64_t end, const string & /*op*/)
 {
        if (!session) return;
 
@@ -2693,9 +2693,11 @@ Editor::region_from_selection ()
        nframes64_t start = selection->time[clicked_selection].start;
        nframes64_t end = selection->time[clicked_selection].end;
 
+       TrackSelection tracks = get_tracks_for_range_action ();
+
        nframes64_t selection_cnt = end - start + 1;
        
-       for (TrackSelection::iterator i = selection->tracks.begin(); i != selection->tracks.end(); ++i) {
+       for (TrackSelection::iterator i = tracks.begin(); i != tracks.end(); ++i) {
                boost::shared_ptr<Region> current;
                boost::shared_ptr<Playlist> pl;
                nframes64_t internal_start;
@@ -2786,41 +2788,52 @@ add_if_covered (RegionView* rv, const AudioRange* ar, RegionSelection* rs)
        }
 }
 
-void
-Editor::separate_regions_between (const TimeSelection& ts)
+/** Return either:
+ *    - selected tracks, or if there are none...
+ *    - tracks containing selected regions, or if there are none...
+ *    - all tracks
+ * @return tracks.
+ */
+TrackSelection
+Editor::get_tracks_for_range_action () const
 {
-       bool in_command = false;
-       boost::shared_ptr<Playlist> playlist;
-       RegionSelection new_selection;
-       TrackSelection tmptracks;
-
+       TrackSelection t;
+       
        if (selection->tracks.empty()) {
                
                /* use tracks with selected regions */
 
-               RegionSelection rs; 
-
-               get_regions_for_action (rs);
+               RegionSelection rs = selection->regions;
 
                for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
                        TimeAxisView* tv = &(*i)->get_time_axis_view();
 
-                       if (find (tmptracks.begin(), tmptracks.end(), tv) == tmptracks.end()) {
-                               tmptracks.push_back (tv);
+                       if (!t.contains (tv)) {
+                               t.push_back (tv);
                        }
                }
 
-               if (tmptracks.empty()) {
-                       /* no regions selected: do nothing */
-                       return;
+               if (t.empty()) {
+                       /* no regions and no tracks: use all tracks */
+                       t = track_views;
                }
 
        } else {
 
-               tmptracks = selection->tracks;
-
+               t = selection->tracks;
        }
 
+       return t;
+}
+
+void
+Editor::separate_regions_between (const TimeSelection& ts)
+{
+       bool in_command = false;
+       boost::shared_ptr<Playlist> playlist;
+       RegionSelection new_selection;
+
+       TrackSelection tmptracks = get_tracks_for_range_action ();
        sort_track_selection (&tmptracks);
 
        for (TrackSelection::iterator i = tmptracks.begin(); i != tmptracks.end(); ++i) {
@@ -2895,6 +2908,10 @@ Editor::separate_regions_between (const TimeSelection& ts)
        }
 }
 
+/** Take tracks from get_tracks_for_range_action and cut any regions
+ *  on those tracks so that the tracks are empty over the time
+ *  selection.
+ */
 void
 Editor::separate_region_from_selection ()
 {
@@ -3684,7 +3701,7 @@ Editor::freeze_thread ()
 }
 
 gint
-Editor::freeze_progress_timeout (void *arg)
+Editor::freeze_progress_timeout (void */*arg*/)
 {
        interthread_progress_bar.set_fraction (current_interthread_info->progress);
        return !(current_interthread_info->done || current_interthread_info->cancel);
@@ -3889,69 +3906,82 @@ Editor::cut_copy (CutCopyOp op)
                return;
        }
 
-       RegionSelection rs; 
-
-       /* we only want to cut regions if some are selected */
-
-       if (!selection->regions.empty()) {
-               get_regions_for_action (rs);
-       }
+       if (internal_editing()) {
 
-       switch (current_mouse_mode()) {
-       case MouseObject: 
-               if (!rs.empty() || !selection->points.empty()) {
+               switch (current_mouse_mode()) {
+               case MouseObject:
+               case MouseRange:
+                       cut_copy_midi (op);
+                       break;
+               default:
+                       break;
+               }
+       } else {
+               
+               RegionSelection rs; 
+               
+               /* we only want to cut regions if some are selected */
+               
+               if (!selection->regions.empty()) {
+                       get_regions_for_action (rs);
+               }
+               
+               switch (current_mouse_mode()) {
+               case MouseObject: 
+                       if (!rs.empty() || !selection->points.empty()) {
 
-                       begin_reversible_command (opname + _(" objects"));
+                               begin_reversible_command (opname + _(" objects"));
 
-                       if (!rs.empty()) {
-                               cut_copy_regions (op, rs);
+                               if (!rs.empty()) {
+                                       cut_copy_regions (op, rs);
                                
-                               if (op == Cut) {
-                                       selection->clear_regions ();
+                                       if (op == Cut) {
+                                               selection->clear_regions ();
+                                       }
                                }
-                       }
 
-                       if (!selection->points.empty()) {
-                               cut_copy_points (op);
+                               if (!selection->points.empty()) {
+                                       cut_copy_points (op);
 
-                               if (op == Cut) {
-                                       selection->clear_points ();
+                                       if (op == Cut) {
+                                               selection->clear_points ();
+                                       }
                                }
-                       }
 
-                       commit_reversible_command ();   
-                       break; // terminate case statement here
-               } 
-               if (!selection->time.empty()) {
-                       /* don't cause suprises */
-                       break;
-               }
-               // fall thru if there was nothing selected
+                               commit_reversible_command ();   
+                               break; // terminate case statement here
+                       
+                       if (!selection->time.empty()) {
+                               /* don't cause suprises */
+                               break;
+                       }
+                       // fall thru if there was nothing selected
                
-       case MouseRange:
-               if (selection->time.empty()) {
-                       nframes64_t start, end;
-                       if (!get_edit_op_range (start, end)) {
-                               return;
+               case MouseRange:
+                       if (selection->time.empty()) {
+                               nframes64_t start, end;
+                               if (!get_edit_op_range (start, end)) {
+                                       return;
+                               }
+                               selection->set ((TimeAxisView*) 0, start, end);
                        }
-                       selection->set ((TimeAxisView*) 0, start, end);
-               }
                        
-               begin_reversible_command (opname + _(" range"));
-               cut_copy_ranges (op);
-               commit_reversible_command ();
+                       begin_reversible_command (opname + _(" range"));
+                       cut_copy_ranges (op);
+                       commit_reversible_command ();
                
-               if (op == Cut) {
-                       selection->clear_time ();
-               }
+                       if (op == Cut) {
+                               selection->clear_time ();
+                       }
 
-               break;
+                       break;
                
-       default:
-               break;
+               default:
+                       break;
+               }
        }
-
-
+               
        if (op == Cut || op == Clear) {
                break_drag ();
                delete _drag;
@@ -3975,6 +4005,20 @@ Editor::cut_copy_points (CutCopyOp op)
        }
 }
 
+/** Cut, copy or clear selected automation points.
+ * @param op Operation (Cut, Copy or Clear)
+ */
+void
+Editor::cut_copy_midi (CutCopyOp op)
+{
+       cerr << "CCM: there are " << selection->midi.size() << " MRV's to work on\n";
+
+       for (MidiSelection::iterator i = selection->midi.begin(); i != selection->midi.end(); ++i) {
+               MidiRegionView* mrv = *i;
+               mrv->cut_copy_clear (op);
+       }
+}
+
 struct PlaylistState {
     boost::shared_ptr<Playlist> playlist;
     XMLNode*  before;
@@ -4290,7 +4334,6 @@ Editor::paste_internal (nframes64_t position, float times)
 
        /* get everything in the correct order */
 
-
        if (!selection->tracks.empty()) {
                sort_track_selection ();
                ts = selection->tracks;