Handle changed session duration & resizing canvas better wrt end marker, remove unuse...
[ardour.git] / gtk2_ardour / editor_mouse.cc
index 5c7c679d726d13fd4559e11fe541aaab6fc64020..1a03f66f2427935d32794bd4281fd5d4f0f7731e 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <pbd/error.h>
 #include <gtkmm2ext/utils.h>
+#include <gtkmm2ext/tearoff.h>
 #include <pbd/memento_command.h>
 #include <pbd/basename.h>
 
@@ -348,11 +349,14 @@ Editor::set_mouse_mode (MouseMode m, bool force)
                break;
        }
 
-       if (mouse_mode == MouseNote)
-               midi_toolbar_frame.show();
-       else
-               midi_toolbar_frame.hide();
-
+       if (midi_tools_tearoff) {
+               if (mouse_mode == MouseNote) {
+                       midi_tools_tearoff->show();
+               } else {
+                       midi_tools_tearoff->hide();
+               }
+       }
+       
        ignore_mouse_mode_toggle = false;
        
        set_canvas_cursor ();
@@ -3137,7 +3141,6 @@ Editor::line_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                dy *= 0.1;
        }
 
-       double cx = drag_info.current_pointer_x;
        double cy = drag_info.grab_y + drag_info.cumulative_y_drag + dy;
 
        // calculate zero crossing point. back off by .01 to stay on the
@@ -3154,8 +3157,6 @@ Editor::line_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 
        drag_info.cumulative_y_drag = cy - drag_info.grab_y;
 
-       line->parent_group().w2i (cx, cy);
-
        cy = max (0.0, cy);
        cy = min ((double) line->height(), cy);
 
@@ -3473,7 +3474,6 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 {
        double x_delta;
        double y_delta = 0;
-       RegionView* rv = reinterpret_cast<RegionView*> (drag_info.data); 
        nframes64_t pending_region_position = 0;
        int32_t pointer_y_span = 0, canvas_pointer_y_span = 0, original_pointer_order;
        int32_t visible_y_high = 0, visible_y_low = 512;  //high meaning higher numbered.. not the height on the screen
@@ -3669,7 +3669,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
 
                        pending_region_position = drag_info.current_pointer_frame - drag_info.pointer_frame_offset;
 
-                       sync_offset = rv->region()->sync_offset (sync_dir);
+                       sync_offset = clicked_regionview->region()->sync_offset (sync_dir);
 
                        /* we don't handle a sync point that lies before zero.
                         */
@@ -3683,7 +3683,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                                        snap_to (sync_frame);   
                                }
            
-                               pending_region_position = rv->region()->adjust_to_sync (sync_frame);
+                               pending_region_position = clicked_regionview->region()->adjust_to_sync (sync_frame);
 
                        } else {
                                pending_region_position = drag_info.last_frame_position;
@@ -3693,7 +3693,7 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                        pending_region_position = 0;
                }
          
-               if (pending_region_position > max_frames - rv->region()->length()) {
+               if (pending_region_position > max_frames - clicked_regionview->region()->length()) {
                        pending_region_position = drag_info.last_frame_position;
                }
 
@@ -3886,19 +3886,6 @@ Editor::region_drag_motion_callback (ArdourCanvas::Item* item, GdkEvent* event)
                                }
                        }
 
-                       /* prevent the regionview from being moved to before 
-                          the zero position on the canvas.
-                       */
-                       /* clamp */
-               
-                       if (x_delta < 0) {
-                               if (-x_delta > ix1) {
-                                       x_delta = -ix1;
-                               }
-                       } else if ((x_delta > 0) && (rv->region()->last_frame() > max_frames - x_delta)) {
-                               x_delta = max_frames - rv->region()->last_frame();
-                       }
-
                        if (drag_info.brushing) {
                                mouse_brush_insert_region (rv, pending_region_position);
                        } else {
@@ -3933,6 +3920,8 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
        PlaylistSet frozen_playlists;
        list <sigc::connection> modified_playlist_connections;
        pair<PlaylistSet::iterator,bool> insert_result, frozen_insert_result;
+       nframes64_t drag_delta;
+       bool changed_tracks, changed_position;
 
        /* first_move is set to false if the regionview has been moved in the 
           motion handler. 
@@ -3988,6 +3977,13 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
 
        begin_reversible_command (op_string);
 
+       changed_position = (drag_info.last_frame_position != (nframes64_t) (clicked_regionview->region()->position()));
+       changed_tracks = (trackview_by_y_position (drag_info.current_pointer_y) != &clicked_regionview->get_time_axis_view());
+
+       drag_delta = clicked_regionview->region()->position() - drag_info.last_frame_position;
+
+       track_canvas->update_now ();
+
        for (list<RegionView*>::const_iterator i = selection->regions.by_layer().begin(); i != selection->regions.by_layer().end(); ) {
                        
                RegionView* rv = (*i);              
@@ -3998,36 +3994,21 @@ Editor::region_drag_finished_callback (ArdourCanvas::Item* item, GdkEvent* event
 
                TimeAxisView* dest_tv = trackview_by_y_position (iy1);
                RouteTimeAxisView* dest_rtv = dynamic_cast<RouteTimeAxisView*>(dest_tv);
-               double speed;
-               bool changed_tracks, changed_position;
                nframes64_t where;
 
                if (rv->region()->locked()) {
                        ++i;
                        continue;
                }
-
-               /* adjust for track speed */
-
-               speed = 1.0;
-               
-               if (dest_rtv && dest_rtv->get_diskstream()) {
-                       speed = dest_rtv->get_diskstream()->speed();
-               }
                
-               changed_position = (drag_info.last_frame_position != (nframes64_t) (rv->region()->position()/speed));
-               changed_tracks = (dest_tv != &rv->get_time_axis_view());
-
                if (changed_position && !drag_info.x_constrained) {
-                       _master_group->w2i(ix1, iy1);
-                       where = (nframes64_t) (unit_to_frame (ix1) * speed);
+                       where = rv->region()->position() - drag_delta;
                } else {
                        where = rv->region()->position();
                }
                        
                boost::shared_ptr<Region> new_region;
 
-
                if (drag_info.copy) {
                        /* we already made a copy */
                        new_region = rv->region();