leftmost_position => leftmost_sample, current_page_frames => current_page_samples
[ardour.git] / gtk2_ardour / editor_canvas_events.cc
index 631137fd2f6ed4be386ab82e3554307ace7f6645..86577f44af3c657a4ef30c4584d6773aa1d28288 100644 (file)
 
 #include "ardour/midi_region.h"
 #include "ardour/region_factory.h"
+#include "ardour/profile.h"
+
+#include "canvas/canvas.h"
+#include "canvas/text.h"
 
 #include "editor.h"
 #include "keyboard.h"
 #include "public_editor.h"
 #include "audio_region_view.h"
 #include "audio_streamview.h"
-#include "canvas-noevent-text.h"
 #include "audio_time_axis.h"
 #include "region_gain_line.h"
 #include "automation_line.h"
 #include "automation_time_axis.h"
 #include "automation_line.h"
 #include "control_point.h"
-#include "canvas_impl.h"
-#include "simplerect.h"
 #include "editor_drag.h"
 #include "midi_time_axis.h"
 #include "editor_regions.h"
@@ -78,7 +79,7 @@ Editor::track_canvas_scroll (GdkEventScroll* ev)
                } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
                        if (!current_stepping_trackview) {
                                step_timeout = Glib::signal_timeout().connect (sigc::mem_fun(*this, &Editor::track_height_step_timeout), 500);
-                               std::pair<TimeAxisView*, int> const p = trackview_by_y_position (ev->y + vertical_adjustment.get_value() - canvas_timebars_vsize);
+                               std::pair<TimeAxisView*, int> const p = trackview_by_y_position (ev->y + vertical_adjustment.get_value());
                                current_stepping_trackview = p.first;
                                if (!current_stepping_trackview) {
                                        return false;
@@ -107,7 +108,7 @@ Editor::track_canvas_scroll (GdkEventScroll* ev)
                } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
                        if (!current_stepping_trackview) {
                                step_timeout = Glib::signal_timeout().connect (sigc::mem_fun(*this, &Editor::track_height_step_timeout), 500);
-                               std::pair<TimeAxisView*, int> const p = trackview_by_y_position (ev->y + vertical_adjustment.get_value() - canvas_timebars_vsize);
+                               std::pair<TimeAxisView*, int> const p = trackview_by_y_position (ev->y + vertical_adjustment.get_value());
                                current_stepping_trackview = p.first;
                                if (!current_stepping_trackview) {
                                        return false;
@@ -123,7 +124,7 @@ Editor::track_canvas_scroll (GdkEventScroll* ev)
                break;
 
        case GDK_SCROLL_LEFT:
-               xdelta = (current_page_frames() / 8);
+               xdelta = (current_page_samples() / 8);
                if (leftmost_frame > xdelta) {
                        reset_x_origin (leftmost_frame - xdelta);
                } else {
@@ -132,11 +133,11 @@ Editor::track_canvas_scroll (GdkEventScroll* ev)
                break;
 
        case GDK_SCROLL_RIGHT:
-               xdelta = (current_page_frames() / 8);
+               xdelta = (current_page_samples() / 8);
                if (max_framepos - xdelta > leftmost_frame) {
                        reset_x_origin (leftmost_frame + xdelta);
                } else {
-                       reset_x_origin (max_framepos - current_page_frames());
+                       reset_x_origin (max_framepos - current_page_samples());
                }
                break;
 
@@ -151,7 +152,7 @@ Editor::track_canvas_scroll (GdkEventScroll* ev)
 bool
 Editor::track_canvas_scroll_event (GdkEventScroll *event)
 {
-       track_canvas->grab_focus();
+       _track_canvas->grab_focus();
        return track_canvas_scroll (event);
 }
 
@@ -159,7 +160,7 @@ bool
 Editor::track_canvas_button_press_event (GdkEventButton */*event*/)
 {
        selection->clear ();
-       track_canvas->grab_focus();
+       _track_canvas->grab_focus();
        return false;
 }
 
@@ -177,7 +178,7 @@ Editor::track_canvas_motion_notify_event (GdkEventMotion */*event*/)
 {
        int x, y;
        /* keep those motion events coming */
-       track_canvas->get_pointer (x, y);
+       _track_canvas->get_pointer (x, y);
        return false;
 }
 
@@ -947,13 +948,11 @@ Editor::canvas_cd_marker_bar_event (GdkEvent *event, ArdourCanvas::Item* item)
        return typed_event (item, event, CdMarkerBarItem);
 }
 
-#ifdef WITH_VIDEOTIMELINE
 bool
 Editor::canvas_videotl_bar_event (GdkEvent *event, ArdourCanvas::Item* item)
 {
        return typed_event (item, event, VideoBarItem);
 }
-#endif
 
 bool
 Editor::canvas_tempo_marker_event (GdkEvent *event, ArdourCanvas::Item* item, TempoMarker* /*marker*/)
@@ -1004,8 +1003,6 @@ Editor::canvas_note_event (GdkEvent *event, ArdourCanvas::Item* item)
 bool
 Editor::track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const& context, int x, int y, guint time)
 {
-       double wx;
-       double wy;
        boost::shared_ptr<Region> region;
        boost::shared_ptr<Region> region_copy;
        RouteTimeAxisView* rtav;
@@ -1013,48 +1010,74 @@ Editor::track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const& context,
        double px;
        double py;
 
-       string target = track_canvas->drag_dest_find_target (context, track_canvas->drag_dest_get_target_list());
+       string target = _track_canvas->drag_dest_find_target (context, _track_canvas->drag_dest_get_target_list());
 
        if (target.empty()) {
                return false;
        }
 
-       track_canvas->window_to_world (x, y, wx, wy);
-
        event.type = GDK_MOTION_NOTIFY;
-       event.button.x = wx;
-       event.button.y = wy;
+       event.button.x = x;
+       event.button.y = y;
        /* assume we're dragging with button 1 */
        event.motion.state = Gdk::BUTTON1_MASK;
 
-       (void) event_frame (&event, &px, &py);
+       (void) window_event_frame (&event, &px, &py);
 
        std::pair<TimeAxisView*, int> const tv = trackview_by_y_position (py);
-
+       bool can_drop = false;
+       
        if (tv.first != 0) {
 
+               /* over a time axis view of some kind */
+
                rtav = dynamic_cast<RouteTimeAxisView*> (tv.first);
                
                if (rtav != 0 && rtav->is_track ()) {
-
-                       region = _regions->get_dragged_region ();
+                       /* over a track, not a bus */
+                       can_drop = true;
+               }
                        
-                       if (region) {
-       
-                               if ((boost::dynamic_pointer_cast<AudioRegion> (region) != 0 &&
-                                   dynamic_cast<AudioTimeAxisView*> (tv.first) != 0) ||
-                                   (boost::dynamic_pointer_cast<MidiRegion> (region) != 0 &&
-                                    dynamic_cast<MidiTimeAxisView*> (tv.first) != 0)) {
 
-                                       /* audio to audio 
-                                          OR 
-                                          midi to midi
-                                       */
+       } else {
+               /* not over a time axis view, so drop is possible */
+               can_drop = true;
+       }
 
-                                       context->drag_status (context->get_suggested_action(), time);
-                                       return true;
+       if (can_drop) {
+               region = _regions->get_dragged_region ();
+               
+               if (region) {
+                       
+                       if ((boost::dynamic_pointer_cast<AudioRegion> (region) != 0 &&
+                            dynamic_cast<AudioTimeAxisView*> (tv.first) != 0) ||
+                           (boost::dynamic_pointer_cast<MidiRegion> (region) != 0 &&
+                            dynamic_cast<MidiTimeAxisView*> (tv.first) != 0)) {
+                               
+                               /* audio to audio 
+                                  OR 
+                                  midi to midi
+                               */
+                               
+                               context->drag_status (context->get_suggested_action(), time);
+                               return true;
+                       }
+               } else {
+                       /* DND originating from outside ardour
+                        *
+                        * TODO: check if file is audio/midi, allow drops on same track-type only,
+                        * currently: if audio is dropped on a midi-track, it is only added to the region-list
+                        */
+                       if (Profile->get_sae() || Config->get_only_copy_imported_files()) {
+                               context->drag_status(Gdk::ACTION_COPY, time);
+                       } else {
+                               if ((context->get_actions() & (Gdk::ACTION_COPY | Gdk::ACTION_LINK | Gdk::ACTION_MOVE)) == Gdk::ACTION_COPY) {
+                                       context->drag_status(Gdk::ACTION_COPY, time);
+                               } else {
+                                       context->drag_status(Gdk::ACTION_LINK, time);
                                }
                        }
+                       return true;
                }
        }
 
@@ -1069,8 +1092,6 @@ Editor::drop_regions (const Glib::RefPtr<Gdk::DragContext>& /*context*/,
                      const SelectionData& /*data*/,
                      guint /*info*/, guint /*time*/)
 {
-       double wx;
-       double wy;
        boost::shared_ptr<Region> region;
        boost::shared_ptr<Region> region_copy;
        RouteTimeAxisView* rtav;
@@ -1078,15 +1099,13 @@ Editor::drop_regions (const Glib::RefPtr<Gdk::DragContext>& /*context*/,
        double px;
        double py;
 
-       track_canvas->window_to_world (x, y, wx, wy);
-
        event.type = GDK_MOTION_NOTIFY;
-       event.button.x = wx;
-       event.button.y = wy;
+       event.button.x = x;
+       event.button.y = y;
        /* assume we're dragging with button 1 */
        event.motion.state = Gdk::BUTTON1_MASK;
 
-       framepos_t const pos = event_frame (&event, &px, &py);
+       framepos_t const pos = window_event_frame (&event, &px, &py);
 
        std::pair<TimeAxisView*, int> const tv = trackview_by_y_position (py);