beat slicing patch #1 from lincoln spiteri
[ardour2.git] / gtk2_ardour / editor_canvas_events.cc
blob34a73d318c029f79d4a1489e7cfef7274130b1d6
1 /*
2 Copyright (C) 2000 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <cstdlib>
21 #include <cmath>
22 #include <algorithm>
23 #include <typeinfo>
25 #include "pbd/stacktrace.h"
27 #include "ardour/audioplaylist.h"
28 #include "ardour/audioregion.h"
29 #include "ardour/region_factory.h"
30 #include "ardour/midi_region.h"
32 #include "editor.h"
33 #include "keyboard.h"
34 #include "public_editor.h"
35 #include "audio_region_view.h"
36 #include "audio_streamview.h"
37 #include "canvas-noevent-text.h"
38 #include "crossfade_view.h"
39 #include "audio_time_axis.h"
40 #include "region_gain_line.h"
41 #include "automation_line.h"
42 #include "automation_time_axis.h"
43 #include "automation_line.h"
44 #include "control_point.h"
45 #include "canvas_impl.h"
46 #include "simplerect.h"
47 #include "editor_drag.h"
48 #include "midi_time_axis.h"
49 #include "editor_regions.h"
51 #include "i18n.h"
53 using namespace std;
54 using namespace ARDOUR;
55 using namespace PBD;
56 using namespace Gtk;
57 using namespace ArdourCanvas;
59 using Gtkmm2ext::Keyboard;
61 bool
62 Editor::track_canvas_scroll (GdkEventScroll* ev)
64 nframes64_t xdelta;
65 int direction = ev->direction;
67 retry:
68 switch (direction) {
69 case GDK_SCROLL_UP:
70 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
71 temporal_zoom_step (false);
72 return true;
73 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::SecondaryModifier)) {
74 direction = GDK_SCROLL_LEFT;
75 goto retry;
76 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
77 if (!current_stepping_trackview) {
78 step_timeout = Glib::signal_timeout().connect (sigc::mem_fun(*this, &Editor::track_height_step_timeout), 500);
79 std::pair<TimeAxisView*, int> const p = trackview_by_y_position (ev->y + vertical_adjustment.get_value() - canvas_timebars_vsize);
80 current_stepping_trackview = p.first;
81 if (!current_stepping_trackview) {
82 return false;
85 last_track_height_step_timestamp = get_microseconds();
86 current_stepping_trackview->step_height (true);
87 return true;
88 } else {
89 scroll_tracks_up_line ();
90 return true;
92 break;
94 case GDK_SCROLL_DOWN:
95 if (Keyboard::modifier_state_equals (ev->state, Keyboard::PrimaryModifier)) {
96 temporal_zoom_step (true);
97 return true;
98 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::SecondaryModifier)) {
99 direction = GDK_SCROLL_RIGHT;
100 goto retry;
101 } else if (Keyboard::modifier_state_equals (ev->state, Keyboard::TertiaryModifier)) {
102 if (!current_stepping_trackview) {
103 step_timeout = Glib::signal_timeout().connect (sigc::mem_fun(*this, &Editor::track_height_step_timeout), 500);
104 std::pair<TimeAxisView*, int> const p = trackview_by_y_position (ev->y + vertical_adjustment.get_value() - canvas_timebars_vsize);
105 current_stepping_trackview = p.first;
106 if (!current_stepping_trackview) {
107 return false;
110 last_track_height_step_timestamp = get_microseconds();
111 current_stepping_trackview->step_height (false);
112 return true;
113 } else {
114 scroll_tracks_down_line ();
115 return true;
117 break;
119 case GDK_SCROLL_LEFT:
120 xdelta = (current_page_frames() / 8);
121 if (leftmost_frame > xdelta) {
122 reset_x_origin (leftmost_frame - xdelta);
123 } else {
124 reset_x_origin (0);
126 break;
128 case GDK_SCROLL_RIGHT:
129 xdelta = (current_page_frames() / 8);
130 if (max_frames - xdelta > leftmost_frame) {
131 reset_x_origin (leftmost_frame + xdelta);
132 } else {
133 reset_x_origin (max_frames - current_page_frames());
135 break;
137 default:
138 /* what? */
139 break;
142 return false;
145 bool
146 Editor::track_canvas_scroll_event (GdkEventScroll *event)
148 track_canvas->grab_focus();
149 return track_canvas_scroll (event);
152 bool
153 Editor::track_canvas_button_press_event (GdkEventButton */*event*/)
155 selection->clear ();
156 track_canvas->grab_focus();
157 return false;
160 bool
161 Editor::track_canvas_button_release_event (GdkEventButton *event)
163 if (_drags->active ()) {
164 _drags->end_grab ((GdkEvent*) event);
166 return false;
169 bool
170 Editor::track_canvas_motion_notify_event (GdkEventMotion */*event*/)
172 int x, y;
173 /* keep those motion events coming */
174 track_canvas->get_pointer (x, y);
175 return false;
178 bool
179 Editor::track_canvas_motion (GdkEvent *ev)
181 if (verbose_cursor_visible) {
182 verbose_canvas_cursor->property_x() = clamp_verbose_cursor_x (ev->motion.x + 10);
183 verbose_canvas_cursor->property_y() = clamp_verbose_cursor_y (ev->motion.y + 10);
186 return false;
189 bool
190 Editor::typed_event (ArdourCanvas::Item* item, GdkEvent *event, ItemType type)
192 gint ret = FALSE;
194 switch (event->type) {
195 case GDK_BUTTON_PRESS:
196 case GDK_2BUTTON_PRESS:
197 case GDK_3BUTTON_PRESS:
198 ret = button_press_handler (item, event, type);
199 break;
200 case GDK_BUTTON_RELEASE:
201 ret = button_release_handler (item, event, type);
202 break;
203 case GDK_MOTION_NOTIFY:
204 ret = motion_handler (item, event);
205 break;
207 case GDK_ENTER_NOTIFY:
208 ret = enter_handler (item, event, type);
209 break;
211 case GDK_LEAVE_NOTIFY:
212 ret = leave_handler (item, event, type);
213 break;
215 default:
216 break;
218 return ret;
221 bool
222 Editor::canvas_region_view_event (GdkEvent *event, ArdourCanvas::Item* item, RegionView *rv)
224 bool ret = false;
226 if (!rv->sensitive ()) {
227 return false;
230 switch (event->type) {
231 case GDK_BUTTON_PRESS:
232 case GDK_2BUTTON_PRESS:
233 case GDK_3BUTTON_PRESS:
234 clicked_regionview = rv;
235 clicked_control_point = 0;
236 clicked_axisview = &rv->get_time_axis_view();
237 clicked_routeview = dynamic_cast<RouteTimeAxisView*>(clicked_axisview);
238 ret = button_press_handler (item, event, RegionItem);
239 break;
241 case GDK_BUTTON_RELEASE:
242 ret = button_release_handler (item, event, RegionItem);
243 break;
245 case GDK_MOTION_NOTIFY:
246 ret = motion_handler (item, event);
247 break;
249 case GDK_ENTER_NOTIFY:
250 set_entered_track (&rv->get_time_axis_view ());
251 set_entered_regionview (rv);
252 break;
254 case GDK_LEAVE_NOTIFY:
255 set_entered_track (0);
256 set_entered_regionview (0);
257 break;
259 default:
260 break;
263 return ret;
266 bool
267 Editor::canvas_stream_view_event (GdkEvent *event, ArdourCanvas::Item* item, RouteTimeAxisView *tv)
269 bool ret = FALSE;
271 switch (event->type) {
272 case GDK_BUTTON_PRESS:
273 case GDK_2BUTTON_PRESS:
274 case GDK_3BUTTON_PRESS:
275 clicked_regionview = 0;
276 clicked_control_point = 0;
277 clicked_axisview = tv;
278 clicked_routeview = dynamic_cast<RouteTimeAxisView*>(tv);
279 ret = button_press_handler (item, event, StreamItem);
280 break;
282 case GDK_BUTTON_RELEASE:
283 ret = button_release_handler (item, event, StreamItem);
284 break;
286 case GDK_MOTION_NOTIFY:
287 ret = motion_handler (item, event);
288 break;
290 case GDK_ENTER_NOTIFY:
291 set_entered_track (tv);
292 break;
294 case GDK_LEAVE_NOTIFY:
295 set_entered_track (0);
296 break;
298 default:
299 break;
302 return ret;
305 bool
306 Editor::canvas_automation_track_event (GdkEvent *event, ArdourCanvas::Item* item, AutomationTimeAxisView *atv)
308 bool ret = false;
310 switch (event->type) {
311 case GDK_BUTTON_PRESS:
312 case GDK_2BUTTON_PRESS:
313 case GDK_3BUTTON_PRESS:
314 clicked_regionview = 0;
315 clicked_control_point = 0;
316 clicked_axisview = atv;
317 clicked_routeview = 0;
318 ret = button_press_handler (item, event, AutomationTrackItem);
319 break;
321 case GDK_BUTTON_RELEASE:
322 ret = button_release_handler (item, event, AutomationTrackItem);
323 break;
325 case GDK_MOTION_NOTIFY:
326 ret = motion_handler (item, event);
327 break;
329 case GDK_ENTER_NOTIFY:
330 ret = enter_handler (item, event, AutomationTrackItem);
331 break;
333 case GDK_LEAVE_NOTIFY:
334 ret = leave_handler (item, event, AutomationTrackItem);
335 break;
337 default:
338 break;
341 return ret;
344 bool
345 Editor::canvas_fade_in_event (GdkEvent *event, ArdourCanvas::Item* item, AudioRegionView *rv)
347 /* we handle only button 3 press/release events */
349 if (!rv->sensitive()) {
350 return false;
353 switch (event->type) {
354 case GDK_BUTTON_PRESS:
355 clicked_regionview = rv;
356 clicked_control_point = 0;
357 clicked_axisview = &rv->get_time_axis_view();
358 clicked_routeview = dynamic_cast<RouteTimeAxisView*>(clicked_axisview);
359 if (event->button.button == 3) {
360 return button_press_handler (item, event, FadeInItem);
362 break;
364 case GDK_BUTTON_RELEASE:
365 if (event->button.button == 3) {
366 return button_release_handler (item, event, FadeInItem);
368 break;
370 default:
371 break;
375 /* proxy for the regionview */
377 return canvas_region_view_event (event, rv->get_canvas_group(), rv);
380 bool
381 Editor::canvas_fade_in_handle_event (GdkEvent *event, ArdourCanvas::Item* item, AudioRegionView *rv)
383 bool ret = false;
385 if (!rv->sensitive()) {
386 return false;
389 switch (event->type) {
390 case GDK_BUTTON_PRESS:
391 case GDK_2BUTTON_PRESS:
392 case GDK_3BUTTON_PRESS:
393 clicked_regionview = rv;
394 clicked_control_point = 0;
395 clicked_axisview = &rv->get_time_axis_view();
396 clicked_routeview = dynamic_cast<RouteTimeAxisView*>(clicked_axisview);
397 ret = button_press_handler (item, event, FadeInHandleItem);
398 break;
400 case GDK_BUTTON_RELEASE:
401 ret = button_release_handler (item, event, FadeInHandleItem);
402 break;
404 case GDK_MOTION_NOTIFY:
405 ret = motion_handler (item, event);
406 break;
408 case GDK_ENTER_NOTIFY:
409 set_entered_regionview (rv);
410 ret = enter_handler (item, event, FadeInHandleItem);
411 break;
413 case GDK_LEAVE_NOTIFY:
414 set_entered_regionview (0);
415 ret = leave_handler (item, event, FadeInHandleItem);
416 break;
418 default:
419 break;
422 return ret;
425 bool
426 Editor::canvas_fade_out_event (GdkEvent *event, ArdourCanvas::Item* item, AudioRegionView *rv)
428 /* we handle only button 3 press/release events */
430 if (!rv->sensitive()) {
431 return false;
434 switch (event->type) {
435 case GDK_BUTTON_PRESS:
436 clicked_regionview = rv;
437 clicked_control_point = 0;
438 clicked_axisview = &rv->get_time_axis_view();
439 clicked_routeview = dynamic_cast<RouteTimeAxisView*>(clicked_axisview);
440 if (event->button.button == 3) {
441 return button_press_handler (item, event, FadeOutItem);
443 break;
445 case GDK_BUTTON_RELEASE:
446 if (event->button.button == 3) {
447 return button_release_handler (item, event, FadeOutItem);
449 break;
451 default:
452 break;
456 /* proxy for the regionview */
458 return canvas_region_view_event (event, rv->get_canvas_group(), rv);
461 bool
462 Editor::canvas_fade_out_handle_event (GdkEvent *event, ArdourCanvas::Item* item, AudioRegionView *rv)
464 bool ret = false;
466 if (!rv->sensitive()) {
467 return false;
470 switch (event->type) {
471 case GDK_BUTTON_PRESS:
472 case GDK_2BUTTON_PRESS:
473 case GDK_3BUTTON_PRESS:
474 clicked_regionview = rv;
475 clicked_control_point = 0;
476 clicked_axisview = &rv->get_time_axis_view();
477 clicked_routeview = dynamic_cast<RouteTimeAxisView*>(clicked_axisview);
478 ret = button_press_handler (item, event, FadeOutHandleItem);
479 break;
481 case GDK_BUTTON_RELEASE:
482 ret = button_release_handler (item, event, FadeOutHandleItem);
483 break;
485 case GDK_MOTION_NOTIFY:
486 ret = motion_handler (item, event);
487 break;
489 case GDK_ENTER_NOTIFY:
490 set_entered_regionview (rv);
491 ret = enter_handler (item, event, FadeOutHandleItem);
492 break;
494 case GDK_LEAVE_NOTIFY:
495 set_entered_regionview (0);
496 ret = leave_handler (item, event, FadeOutHandleItem);
497 break;
499 default:
500 break;
503 return ret;
506 struct DescendingRegionLayerSorter {
507 bool operator()(boost::shared_ptr<Region> a, boost::shared_ptr<Region> b) {
508 return a->layer() > b->layer();
512 bool
513 Editor::canvas_crossfade_view_event (GdkEvent* event, ArdourCanvas::Item* item, CrossfadeView* xfv)
515 /* we handle only button 3 press/release events */
517 switch (event->type) {
518 case GDK_BUTTON_PRESS:
519 clicked_crossfadeview = xfv;
520 clicked_axisview = &clicked_crossfadeview->get_time_axis_view();
521 if (event->button.button == 3) {
522 return button_press_handler (item, event, CrossfadeViewItem);
524 break;
526 case GDK_BUTTON_RELEASE:
527 if (event->button.button == 3) {
528 bool ret = button_release_handler (item, event, CrossfadeViewItem);
529 return ret;
531 break;
533 default:
534 break;
538 /* XXX do not forward double clicks */
540 if (event->type == GDK_2BUTTON_PRESS) {
541 return false;
544 /* proxy for an underlying regionview */
546 /* XXX really need to check if we are in the name highlight,
547 and proxy to that when required.
550 TimeAxisView& tv (xfv->get_time_axis_view());
551 AudioTimeAxisView* atv;
553 if ((atv = dynamic_cast<AudioTimeAxisView*>(&tv)) != 0) {
555 if (atv->is_audio_track()) {
557 boost::shared_ptr<AudioPlaylist> pl;
558 if ((pl = boost::dynamic_pointer_cast<AudioPlaylist> (atv->track()->playlist())) != 0) {
560 Playlist::RegionList* rl = pl->regions_at (event_frame (event));
561 if (!rl->empty()) {
563 if (atv->layer_display() == Overlaid) {
565 /* we're in overlaid mode; proxy to the uppermost region view */
567 DescendingRegionLayerSorter cmp;
568 rl->sort (cmp);
570 RegionView* rv = atv->view()->find_view (rl->front());
572 delete rl;
574 /* proxy */
575 return canvas_region_view_event (event, rv->get_canvas_group(), rv);
577 } else {
579 /* we're in stacked mode; proxy to the region view under the mouse */
581 /* XXX: FIXME: this is an evil hack; it assumes that any event for which
582 this proxy is being used has its GdkEvent laid out such that the y
583 member is in the same place as that for a GdkEventButton */
585 /* position of the event within the track */
586 double cx = event->button.x;
587 double cy = event->button.y;
588 atv->view()->canvas_item()->w2i (cx, cy);
590 /* hence layer that we're over */
591 double const c = atv->view()->child_height ();
592 layer_t const l = pl->top_layer () + 1 - (cy / c);
594 /* hence region */
595 Playlist::RegionList::iterator i = rl->begin();
596 while (i != rl->end() && (*i)->layer() != l) {
597 ++i;
600 if (i != rl->end()) {
601 RegionView* rv = atv->view()->find_view (*i);
602 delete rl;
604 /* proxy */
605 return canvas_region_view_event (event, rv->get_canvas_group(), rv);
610 delete rl;
615 return TRUE;
618 bool
619 Editor::canvas_control_point_event (GdkEvent *event, ArdourCanvas::Item* item, ControlPoint* cp)
621 switch (event->type) {
622 case GDK_BUTTON_PRESS:
623 case GDK_2BUTTON_PRESS:
624 case GDK_3BUTTON_PRESS:
625 clicked_control_point = cp;
626 clicked_axisview = &cp->line().trackview;
627 clicked_routeview = dynamic_cast<RouteTimeAxisView*>(clicked_axisview);
628 clicked_regionview = 0;
629 break;
631 case GDK_SCROLL_UP:
632 break;
634 case GDK_SCROLL_DOWN:
635 break;
637 default:
638 break;
641 return typed_event (item, event, ControlPointItem);
644 bool
645 Editor::canvas_line_event (GdkEvent *event, ArdourCanvas::Item* item, AutomationLine* al)
647 ItemType type;
649 if (dynamic_cast<AudioRegionGainLine*> (al) != 0) {
650 type = GainLineItem;
651 } else {
652 type = AutomationLineItem;
655 return typed_event (item, event, type);
658 bool
659 Editor::canvas_selection_rect_event (GdkEvent *event, ArdourCanvas::Item* item, SelectionRect* rect)
661 bool ret = false;
663 switch (event->type) {
664 case GDK_BUTTON_PRESS:
665 case GDK_2BUTTON_PRESS:
666 case GDK_3BUTTON_PRESS:
667 clicked_selection = rect->id;
668 ret = button_press_handler (item, event, SelectionItem);
669 break;
670 case GDK_BUTTON_RELEASE:
671 ret = button_release_handler (item, event, SelectionItem);
672 break;
673 case GDK_MOTION_NOTIFY:
674 ret = motion_handler (item, event);
675 break;
676 /* Don't need these at the moment. */
677 case GDK_ENTER_NOTIFY:
678 ret = enter_handler (item, event, SelectionItem);
679 break;
681 case GDK_LEAVE_NOTIFY:
682 ret = leave_handler (item, event, SelectionItem);
683 break;
685 default:
686 break;
689 return ret;
692 bool
693 Editor::canvas_selection_start_trim_event (GdkEvent *event, ArdourCanvas::Item* item, SelectionRect* rect)
695 bool ret = false;
697 switch (event->type) {
698 case GDK_BUTTON_PRESS:
699 case GDK_2BUTTON_PRESS:
700 case GDK_3BUTTON_PRESS:
701 clicked_selection = rect->id;
702 ret = button_press_handler (item, event, StartSelectionTrimItem);
703 break;
704 case GDK_BUTTON_RELEASE:
705 ret = button_release_handler (item, event, StartSelectionTrimItem);
706 break;
707 case GDK_MOTION_NOTIFY:
708 ret = motion_handler (item, event);
709 break;
710 case GDK_ENTER_NOTIFY:
711 ret = enter_handler (item, event, StartSelectionTrimItem);
712 break;
714 case GDK_LEAVE_NOTIFY:
715 ret = leave_handler (item, event, StartSelectionTrimItem);
716 break;
718 default:
719 break;
722 return ret;
725 bool
726 Editor::canvas_selection_end_trim_event (GdkEvent *event, ArdourCanvas::Item* item, SelectionRect* rect)
728 bool ret = false;
730 switch (event->type) {
731 case GDK_BUTTON_PRESS:
732 case GDK_2BUTTON_PRESS:
733 case GDK_3BUTTON_PRESS:
734 clicked_selection = rect->id;
735 ret = button_press_handler (item, event, EndSelectionTrimItem);
736 break;
737 case GDK_BUTTON_RELEASE:
738 ret = button_release_handler (item, event, EndSelectionTrimItem);
739 break;
740 case GDK_MOTION_NOTIFY:
741 ret = motion_handler (item, event);
742 break;
743 case GDK_ENTER_NOTIFY:
744 ret = enter_handler (item, event, EndSelectionTrimItem);
745 break;
747 case GDK_LEAVE_NOTIFY:
748 ret = leave_handler (item, event, EndSelectionTrimItem);
749 break;
751 default:
752 break;
755 return ret;
758 bool
759 Editor::canvas_frame_handle_event (GdkEvent* event, ArdourCanvas::Item* item, RegionView* rv)
761 bool ret = false;
763 /* frame handles are not active when in internal edit mode, because actual notes
764 might be in the area occupied by the handle - we want them to be editable as normal.
767 if (internal_editing() || !rv->sensitive()) {
768 return false;
771 /* NOTE: frame handles pretend to be the colored trim bar from an event handling
772 perspective. XXX change this ??
775 ItemType type;
777 if (item->get_data ("isleft")) {
778 type = LeftFrameHandle;
779 } else {
780 type = RightFrameHandle;
783 switch (event->type) {
784 case GDK_BUTTON_PRESS:
785 case GDK_2BUTTON_PRESS:
786 case GDK_3BUTTON_PRESS:
787 clicked_regionview = rv;
788 clicked_control_point = 0;
789 clicked_axisview = &clicked_regionview->get_time_axis_view();
790 clicked_routeview = dynamic_cast<RouteTimeAxisView*>(clicked_axisview);
791 ret = button_press_handler (item, event, type);
792 break;
793 case GDK_BUTTON_RELEASE:
794 ret = button_release_handler (item, event, type);
795 break;
796 case GDK_MOTION_NOTIFY:
797 ret = motion_handler (item, event);
798 break;
799 case GDK_ENTER_NOTIFY:
800 set_entered_regionview (rv);
801 ret = enter_handler (item, event, type);
802 break;
804 case GDK_LEAVE_NOTIFY:
805 set_entered_regionview (0);
806 ret = leave_handler (item, event, type);
807 break;
809 default:
810 break;
813 return ret;
817 bool
818 Editor::canvas_region_view_name_highlight_event (GdkEvent* event, ArdourCanvas::Item* item, RegionView* rv)
820 bool ret = false;
822 if (!rv->sensitive()) {
823 return false;
826 switch (event->type) {
827 case GDK_BUTTON_PRESS:
828 case GDK_2BUTTON_PRESS:
829 case GDK_3BUTTON_PRESS:
830 clicked_regionview = rv;
831 clicked_control_point = 0;
832 clicked_axisview = &clicked_regionview->get_time_axis_view();
833 clicked_routeview = dynamic_cast<RouteTimeAxisView*>(clicked_axisview);
834 ret = button_press_handler (item, event, RegionViewNameHighlight);
835 break;
836 case GDK_BUTTON_RELEASE:
837 ret = button_release_handler (item, event, RegionViewNameHighlight);
838 break;
839 case GDK_MOTION_NOTIFY:
840 motion_handler (item, event);
841 ret = true; // force this to avoid progagating the event into the regionview
842 break;
843 case GDK_ENTER_NOTIFY:
844 set_entered_regionview (rv);
845 ret = enter_handler (item, event, RegionViewNameHighlight);
846 break;
848 case GDK_LEAVE_NOTIFY:
849 set_entered_regionview (0);
850 ret = leave_handler (item, event, RegionViewNameHighlight);
851 break;
853 default:
854 break;
857 return ret;
860 bool
861 Editor::canvas_region_view_name_event (GdkEvent *event, ArdourCanvas::Item* item, RegionView* rv)
863 bool ret = false;
865 if (!rv->sensitive()) {
866 return false;
869 switch (event->type) {
870 case GDK_BUTTON_PRESS:
871 case GDK_2BUTTON_PRESS:
872 case GDK_3BUTTON_PRESS:
873 clicked_regionview = rv;
874 clicked_control_point = 0;
875 clicked_axisview = &clicked_regionview->get_time_axis_view();
876 clicked_routeview = dynamic_cast<RouteTimeAxisView*>(clicked_axisview);
877 ret = button_press_handler (item, event, RegionViewName);
878 break;
879 case GDK_BUTTON_RELEASE:
880 ret = button_release_handler (item, event, RegionViewName);
881 break;
882 case GDK_MOTION_NOTIFY:
883 ret = motion_handler (item, event);
884 break;
885 case GDK_ENTER_NOTIFY:
886 set_entered_regionview (rv);
887 ret = enter_handler (item, event, RegionViewName);
888 break;
890 case GDK_LEAVE_NOTIFY:
891 set_entered_regionview (0);
892 ret = leave_handler (item, event, RegionViewName);
893 break;
895 default:
896 break;
899 return ret;
902 bool
903 Editor::canvas_feature_line_event (GdkEvent *event, ArdourCanvas::Item* item, RegionView *rv)
905 bool ret = false;
907 switch (event->type) {
908 case GDK_BUTTON_PRESS:
909 case GDK_2BUTTON_PRESS:
910 case GDK_3BUTTON_PRESS:
911 clicked_regionview = 0;
912 clicked_control_point = 0;
913 clicked_axisview = 0;
914 clicked_routeview = 0; //dynamic_cast<RouteTimeAxisView*>(clicked_axisview);
915 ret = button_press_handler (item, event, FeatureLineItem);
916 break;
918 case GDK_BUTTON_RELEASE:
919 ret = button_release_handler (item, event, FeatureLineItem);
920 break;
922 case GDK_MOTION_NOTIFY:
923 ret = motion_handler (item, event);
924 break;
926 case GDK_ENTER_NOTIFY:
927 ret = enter_handler (item, event, FeatureLineItem);
928 break;
930 case GDK_LEAVE_NOTIFY:
931 ret = leave_handler (item, event, FeatureLineItem);
932 break;
934 default:
935 break;
938 return ret;
941 bool
942 Editor::canvas_marker_event (GdkEvent *event, ArdourCanvas::Item* item, Marker* /*marker*/)
944 return typed_event (item, event, MarkerItem);
947 bool
948 Editor::canvas_marker_bar_event (GdkEvent *event, ArdourCanvas::Item* item)
950 return typed_event (item, event, MarkerBarItem);
953 bool
954 Editor::canvas_range_marker_bar_event (GdkEvent *event, ArdourCanvas::Item* item)
956 return typed_event (item, event, RangeMarkerBarItem);
959 bool
960 Editor::canvas_transport_marker_bar_event (GdkEvent *event, ArdourCanvas::Item* item)
962 return typed_event (item, event, TransportMarkerBarItem);
965 bool
966 Editor::canvas_cd_marker_bar_event (GdkEvent *event, ArdourCanvas::Item* item)
968 return typed_event (item, event, CdMarkerBarItem);
971 bool
972 Editor::canvas_tempo_marker_event (GdkEvent *event, ArdourCanvas::Item* item, TempoMarker* /*marker*/)
974 return typed_event (item, event, TempoMarkerItem);
977 bool
978 Editor::canvas_meter_marker_event (GdkEvent *event, ArdourCanvas::Item* item, MeterMarker* /*marker*/)
980 return typed_event (item, event, MeterMarkerItem);
983 bool
984 Editor::canvas_tempo_bar_event (GdkEvent *event, ArdourCanvas::Item* item)
986 return typed_event (item, event, TempoBarItem);
989 bool
990 Editor::canvas_meter_bar_event (GdkEvent *event, ArdourCanvas::Item* item)
992 return typed_event (item, event, MeterBarItem);
995 bool
996 Editor::canvas_playhead_cursor_event (GdkEvent *event, ArdourCanvas::Item* item)
998 return typed_event (item, event, PlayheadCursorItem);
1001 bool
1002 Editor::canvas_zoom_rect_event (GdkEvent *event, ArdourCanvas::Item* item)
1004 return typed_event (item, event, NoItem);
1007 bool
1008 Editor::canvas_note_event (GdkEvent *event, ArdourCanvas::Item* item)
1010 if (!internal_editing()) {
1011 return false;
1014 return typed_event (item, event, NoteItem);
1017 bool
1018 Editor::track_canvas_drag_motion (Glib::RefPtr<Gdk::DragContext> const & /*c*/, int x, int y, guint /*time*/)
1020 double wx;
1021 double wy;
1022 track_canvas->window_to_world (x, y, wx, wy);
1024 GdkEvent event;
1025 event.type = GDK_MOTION_NOTIFY;
1026 event.button.x = wx;
1027 event.button.y = wy;
1028 /* assume we're dragging with button 1 */
1029 event.motion.state = Gdk::BUTTON1_MASK;
1031 if (!_drags->active ()) {
1033 double px;
1034 double py;
1035 nframes64_t const pos = event_frame (&event, &px, &py);
1037 std::pair<TimeAxisView*, int> const tv = trackview_by_y_position (py);
1038 if (tv.first == 0) {
1039 return true;
1042 RouteTimeAxisView* rtav = dynamic_cast<RouteTimeAxisView*> (tv.first);
1043 if (rtav == 0 || !rtav->is_track ()) {
1044 return true;
1047 boost::shared_ptr<Region> region = _regions->get_dragged_region ();
1049 if (!region) {
1050 return true;
1053 boost::shared_ptr<Region> region_copy = RegionFactory::create (region);
1055 if (boost::dynamic_pointer_cast<AudioRegion> (region_copy) != 0 &&
1056 dynamic_cast<AudioTimeAxisView*> (tv.first) == 0) {
1058 /* audio -> non-audio */
1059 return true;
1062 if (boost::dynamic_pointer_cast<MidiRegion> (region_copy) == 0 &&
1063 dynamic_cast<MidiTimeAxisView*> (tv.first) != 0) {
1065 /* MIDI -> non-MIDI */
1066 return true;
1069 _drags->set (new RegionInsertDrag (this, region_copy, rtav, pos), &event);
1072 _drags->motion_handler (&event, false);
1074 return true;