Switched to use libgnomecanvas (not the C++ one).
[ardour.git] / gtk2_ardour / editor_keyboard.cc
1 /*
2     Copyright (C) 2004 Paul Davis 
3
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.
8
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.
13
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.
17
18     $Id$
19 */
20
21 #include <ardour/audioregion.h>
22
23 #include "editor.h"
24 #include "regionview.h"
25 #include "selection.h"
26
27 void
28 Editor::kbd_driver (sigc::slot<void,GdkEvent*> theslot, bool use_track_canvas, bool use_time_canvas, bool can_select)
29 {
30         gint x, y;
31         double dx, dy;
32         GdkEvent ev;
33         GdkModifierType mask;
34         Gdk_Window evw (track_canvas->get_window().get_pointer (x, y, mask));
35         bool doit = false;
36
37         if (use_track_canvas && gdk_window_get_pointer (track_canvas_event_box.get_window(),
38                                                         &x, &y, &mask)) {
39                 doit = true;
40
41         } else if (use_time_canvas && gdk_window_get_pointer (time_canvas_event_box.get_window(),
42                                                               &x, &y, &mask)) {
43                 doit = true;
44         }
45
46         if (doit) {
47
48                 if (entered_regionview && can_select) {
49                         selection->set (entered_regionview);
50                 }
51
52                 gnome_canvas_window_to_world (GNOME_CANVAS(track_gnome_canvas), x, y, &dx, &dy);
53
54                 ev.type = GDK_BUTTON_PRESS;
55                 ev.button.x = dx;
56                 ev.button.y = dy;
57                 ev.button.state = 0;  /* XXX correct? */
58
59                 theslot (&ev);
60         }
61 }
62
63 void
64 Editor::kbd_set_playhead_cursor ()
65 {
66         kbd_driver (mem_fun(*this, &Editor::set_playhead_cursor), true, true, false);
67 }
68
69 void
70 Editor::kbd_set_edit_cursor ()
71 {
72         kbd_driver (mem_fun(*this, &Editor::set_edit_cursor), true, true, false);
73 }
74
75
76 void
77 Editor::kbd_do_split (GdkEvent* ev)
78 {
79         jack_nframes_t where = event_frame (ev);
80
81         if (entered_regionview) {
82                 if (selection->audio_regions.find (entered_regionview) != selection->audio_regions.end()) {
83                         split_regions_at (where, selection->audio_regions);
84                 } else {
85                         AudioRegionSelection s;
86                         s.add (entered_regionview);
87                         split_regions_at (where, s);
88                 }
89         }
90 }
91
92 void
93 Editor::kbd_split ()
94 {
95         kbd_driver (mem_fun(*this, &Editor::kbd_do_split), true, true, false);
96 }
97
98 void
99 Editor::kbd_do_align (GdkEvent* ev, ARDOUR::RegionPoint what)
100 {
101         align (what);
102 }
103
104 void
105 Editor::kbd_align (ARDOUR::RegionPoint what)
106 {
107         kbd_driver (bind (mem_fun(*this, &Editor::kbd_do_align), what));
108 }
109
110 void
111 Editor::kbd_do_align_relative (GdkEvent* ev, ARDOUR::RegionPoint what)
112 {
113         align (what);
114 }
115
116 void
117 Editor::kbd_align_relative (ARDOUR::RegionPoint what)
118 {
119         kbd_driver (bind (mem_fun(*this, &Editor::kbd_do_align), what), true, true, false);
120 }
121
122 void
123 Editor::kbd_do_brush (GdkEvent *ev)
124 {
125         brush (event_frame (ev, 0, 0));
126 }
127
128 void
129 Editor::kbd_brush ()
130 {
131         kbd_driver (mem_fun(*this, &Editor::kbd_do_brush), true, true, false);
132 }
133
134 void
135 Editor::kbd_do_audition (GdkEvent *ignored)
136 {
137         audition_selected_region ();
138 }
139
140 void
141 Editor::kbd_audition ()
142 {
143         kbd_driver (mem_fun(*this, &Editor::kbd_do_audition), true, false, true);
144 }