1ffaf2146d906878cf9a5f7287b93d29349f5af6
[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 #include <ardour/playlist.h>
23
24 #include "editor.h"
25 #include "regionview.h"
26 #include "selection.h"
27
28 #include "i18n.h"
29
30 void
31 Editor::kbd_driver (sigc::slot<void,GdkEvent*> theslot, bool use_track_canvas, bool use_time_canvas, bool can_select)
32 {
33         gint x, y;
34         double worldx, worldy;
35         GdkEvent ev;
36         Gdk::ModifierType mask;
37         Glib::RefPtr<Gdk::Window> evw = track_canvas.get_window()->get_pointer (x, y, mask);
38         bool doit = false;
39
40         if (use_track_canvas && track_canvas_event_box.get_window()->get_pointer(x, y, mask) != 0) {
41                 doit = true;
42         } else if (use_time_canvas && time_canvas_event_box.get_window()->get_pointer(x, y, mask)!= 0) {
43                 doit = true;
44         }
45
46         if (doit) {
47
48                 if (entered_regionview && can_select) {
49                         selection->set (entered_regionview);
50                 }
51
52                 track_canvas.window_to_world (x, y, worldx, worldy);
53                 worldx += horizontal_adjustment.get_value();
54                 worldy += vertical_adjustment.get_value();
55
56                 ev.type = GDK_BUTTON_PRESS;
57                 ev.button.x = worldx;
58                 ev.button.y = worldy;
59                 ev.button.state = 0;  /* XXX correct? */
60
61                 theslot (&ev);
62         }
63 }
64
65 void
66 Editor::kbd_set_playhead_cursor ()
67 {
68         kbd_driver (mem_fun(*this, &Editor::set_playhead_cursor), true, true, false);
69 }
70
71 void
72 Editor::kbd_set_edit_cursor ()
73 {
74         kbd_driver (mem_fun(*this, &Editor::set_edit_cursor), true, true, false);
75 }
76
77
78 void
79 Editor::kbd_do_split (GdkEvent* ev)
80 {
81         jack_nframes_t where = event_frame (ev);
82
83         if (entered_regionview) {
84                 if (selection->audio_regions.find (entered_regionview) != selection->audio_regions.end()) {
85                         split_regions_at (where, selection->audio_regions);
86                 } else {
87                         AudioRegionSelection s;
88                         s.add (entered_regionview);
89                         split_regions_at (where, s);
90                 }
91         }
92 }
93
94 void
95 Editor::kbd_split ()
96 {
97         kbd_driver (mem_fun(*this, &Editor::kbd_do_split), true, true, false);
98 }
99
100 void
101 Editor::kbd_mute_unmute_region ()
102 {
103         if (entered_regionview) {
104                 begin_reversible_command (_("mute region"));
105                 session->add_undo (entered_regionview->region.playlist()->get_memento());
106                 
107             entered_regionview->region.set_muted (!entered_regionview->region.muted());
108                 
109                 session->add_redo_no_execute (entered_regionview->region.playlist()->get_memento());
110                 commit_reversible_command();
111         }
112 }
113
114 void
115 Editor::kbd_set_sync_position ()
116 {
117         kbd_driver (mem_fun(*this, &Editor::kbd_do_set_sync_position), true, true, false);
118 }
119
120 void
121 Editor::kbd_do_set_sync_position (GdkEvent* ev)
122 {
123     jack_nframes_t where = event_frame (ev);
124         snap_to (where);
125
126         if (entered_regionview) {
127           set_a_regions_sync_position (entered_regionview->region, where);
128         }
129 }
130
131 void
132 Editor::kbd_do_align (GdkEvent* ev, ARDOUR::RegionPoint what)
133 {
134         align (what);
135 }
136
137 void
138 Editor::kbd_align (ARDOUR::RegionPoint what)
139 {
140         kbd_driver (bind (mem_fun(*this, &Editor::kbd_do_align), what));
141 }
142
143 void
144 Editor::kbd_do_align_relative (GdkEvent* ev, ARDOUR::RegionPoint what)
145 {
146         align (what);
147 }
148
149 void
150 Editor::kbd_align_relative (ARDOUR::RegionPoint what)
151 {
152         kbd_driver (bind (mem_fun(*this, &Editor::kbd_do_align), what), true, true, false);
153 }
154
155 void
156 Editor::kbd_do_brush (GdkEvent *ev)
157 {
158         brush (event_frame (ev, 0, 0));
159 }
160
161 void
162 Editor::kbd_brush ()
163 {
164         kbd_driver (mem_fun(*this, &Editor::kbd_do_brush), true, true, false);
165 }
166
167 void
168 Editor::kbd_do_audition (GdkEvent *ignored)
169 {
170         audition_selected_region ();
171 }
172
173 void
174 Editor::kbd_audition ()
175 {
176         kbd_driver (mem_fun(*this, &Editor::kbd_do_audition), true, false, true);
177 }