2 cleanup patches from nickm, plus work on mixer_ui.cc so that it compiles
[ardour.git] / gtk2_ardour / editor_keys.cc
1 /*
2     Copyright (C) 2000 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 <cstdlib>
22 #include <cmath>
23 #include <string>
24
25 #include <pbd/error.h>
26
27 #include <ardour/session.h>
28 #include <ardour/region.h>
29
30 #include "ardour_ui.h"
31 #include "editor.h"
32 #include "time_axis_view.h"
33 #include "regionview.h"
34 #include "selection.h"
35
36 #include "i18n.h"
37
38 using namespace ARDOUR;
39 using namespace sigc;
40
41 void
42 Editor::install_keybindings ()
43 {
44         /* add named actions for the editor */
45
46         add_action ("toggle-xfades-active", mem_fun(*this, &Editor::toggle_xfades_active));
47
48         add_action ("playhead-to-next-region-start", bind (mem_fun(*this, &Editor::cursor_to_next_region_point), playhead_cursor, RegionPoint (Start)));
49         add_action ("playhead-to-next-region-end", bind (mem_fun(*this, &Editor::cursor_to_next_region_point), playhead_cursor, RegionPoint (End)));
50         add_action ("playhead-to-next-region-sync", bind (mem_fun(*this, &Editor::cursor_to_next_region_point), playhead_cursor, RegionPoint (SyncPoint)));
51
52         add_action ("playhead-to-previous-region-start", bind (mem_fun(*this, &Editor::cursor_to_previous_region_point), playhead_cursor, RegionPoint (Start)));
53         add_action ("playhead-to-previous-region-end", bind (mem_fun(*this, &Editor::cursor_to_previous_region_point), playhead_cursor, RegionPoint (End)));
54         add_action ("playhead-to-previous-region-sync", bind (mem_fun(*this, &Editor::cursor_to_previous_region_point), playhead_cursor, RegionPoint (SyncPoint)));
55
56         add_action ("edit-cursor-to-next-region-start", bind (mem_fun(*this, &Editor::cursor_to_next_region_point), edit_cursor, RegionPoint (Start)));
57         add_action ("edit-cursor-to-next-region-end", bind (mem_fun(*this, &Editor::cursor_to_next_region_point), edit_cursor, RegionPoint (End)));
58         add_action ("edit-cursor-to-next-region-sync", bind (mem_fun(*this, &Editor::cursor_to_next_region_point), edit_cursor, RegionPoint (SyncPoint)));
59
60         add_action ("edit-cursor-to-previous-region-start", bind (mem_fun(*this, &Editor::cursor_to_previous_region_point), edit_cursor, RegionPoint (Start)));
61         add_action ("edit-cursor-to-previous-region-end", bind (mem_fun(*this, &Editor::cursor_to_previous_region_point), edit_cursor, RegionPoint (End)));
62         add_action ("edit-cursor-to-previous-region-sync", bind (mem_fun(*this, &Editor::cursor_to_previous_region_point), edit_cursor, RegionPoint (SyncPoint)));
63
64         add_action ("playhead-to-range-start", bind (mem_fun(*this, &Editor::cursor_to_selection_start), playhead_cursor));
65         add_action ("playhead-to-range-end", bind (mem_fun(*this, &Editor::cursor_to_selection_end), playhead_cursor));
66
67         add_action ("edit-cursor-to-range-start", bind (mem_fun(*this, &Editor::cursor_to_selection_start), edit_cursor));
68         add_action ("edit-cursor-to-range-end", bind (mem_fun(*this, &Editor::cursor_to_selection_end), edit_cursor));
69
70         add_action ("jump-forward-to-mark", mem_fun(*this, &Editor::jump_forward_to_mark));
71         add_action ("jump-backward-to-mark", mem_fun(*this, &Editor::jump_backward_to_mark));
72         add_action ("add-location-from-playhead", mem_fun(*this, &Editor::add_location_from_playhead_cursor));
73
74         add_action ("nudge-forward", bind (mem_fun(*this, &Editor::nudge_forward), false));
75         add_action ("nudge-next-forward", bind (mem_fun(*this, &Editor::nudge_forward), true));
76         add_action ("nudge-backward", bind (mem_fun(*this, &Editor::nudge_backward), false));
77         add_action ("nudge-next-backward", bind (mem_fun(*this, &Editor::nudge_backward), true));
78
79         add_action ("toggle-playback", bind (mem_fun(*this, &Editor::toggle_playback), false));
80         add_action ("toggle-playback-forget-capture", bind (mem_fun(*this, &Editor::toggle_playback), true));
81
82         add_action ("toggle-loop-playback", mem_fun(*this, &Editor::toggle_loop_playback));
83         
84         add_action ("temporal-zoom-out", bind (mem_fun(*this, &Editor::temporal_zoom_step), true));
85         add_action ("temporal-zoom-in", bind (mem_fun(*this, &Editor::temporal_zoom_step), false));
86         add_action ("zoom-to-session", mem_fun(*this, &Editor::temporal_zoom_session));
87
88         add_action ("scroll-tracks-up", mem_fun(*this, &Editor::scroll_tracks_up));
89         add_action ("scroll-tracks-down", mem_fun(*this, &Editor::scroll_tracks_down));
90         add_action ("step-tracks-up", mem_fun(*this, &Editor::scroll_tracks_up_line));
91         add_action ("step-tracks-down", mem_fun(*this, &Editor::scroll_tracks_down_line));
92
93         add_action ("scroll-backward", bind (mem_fun(*this, &Editor::scroll_backward), 0.8f));
94         add_action ("scroll-forward", bind (mem_fun(*this, &Editor::scroll_forward), 0.8f));
95         add_action ("goto", mem_fun(*this, &Editor::goto_frame));
96         add_action ("center-playhead", mem_fun(*this, &Editor::center_playhead));
97         add_action ("center-edit_cursor", mem_fun(*this, &Editor::center_edit_cursor));
98         add_action ("playhead-forward", mem_fun(*this, &Editor::playhead_forward));
99         add_action ("playhead-backward", mem_fun(*this, &Editor::playhead_backward));
100         add_action ("playhead-to-edit", bind (mem_fun(*this, &Editor::cursor_align), true));
101         add_action ("edit-to-playhead", bind (mem_fun(*this, &Editor::cursor_align), false));
102
103         add_action ("align-regions-start", bind (mem_fun(*this, &Editor::align), ARDOUR::Start));
104         add_action ("align-regions-start-relative", bind (mem_fun(*this, &Editor::align_relative), ARDOUR::Start));
105         add_action ("align-regions-end", bind (mem_fun(*this, &Editor::align), ARDOUR::End));
106         add_action ("align-regions-end-relative", bind (mem_fun(*this, &Editor::align_relative), ARDOUR::End));
107         add_action ("align-regions-sync", bind (mem_fun(*this, &Editor::align), ARDOUR::SyncPoint));
108         add_action ("align-regions-sync-relative", bind (mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint));
109         
110         add_action ("set-playhead", mem_fun(*this, &Editor::kbd_set_playhead_cursor));
111         add_action ("set-edit-cursor", mem_fun(*this, &Editor::kbd_set_edit_cursor));
112
113         add_action ("set-mouse-mode-object", bind (mem_fun(*this, &Editor::set_mouse_mode), Editing::MouseObject, false));
114         add_action ("set-mouse-mode-range", bind (mem_fun(*this, &Editor::set_mouse_mode), Editing::MouseRange, false));
115         add_action ("set-mouse-mode-gain", bind (mem_fun(*this, &Editor::set_mouse_mode), Editing::MouseGain, false));
116         add_action ("set-mouse-mode-zoom", bind (mem_fun(*this, &Editor::set_mouse_mode), Editing::MouseZoom, false));
117         add_action ("set-mouse-mode-timefx", bind (mem_fun(*this, &Editor::set_mouse_mode), Editing::MouseTimeFX, false));
118
119         add_action ("set-undo", bind (mem_fun(*this, &Editor::undo), 1U));
120         add_action ("set-redo", bind (mem_fun(*this, &Editor::redo), 1U));
121
122         add_action ("export-session", mem_fun(*this, &Editor::export_session));
123         add_action ("export-range", mem_fun(*this, &Editor::export_selection));
124
125         add_action ("editor-cut", mem_fun(*this, &Editor::cut));
126         add_action ("editor-copy", mem_fun(*this, &Editor::copy));
127         add_action ("editor-paste", mem_fun(*this, &Editor::keyboard_paste));
128         add_action ("duplicate-region", mem_fun(*this, &Editor::keyboard_duplicate_region));
129         add_action ("duplicate-range", mem_fun(*this, &Editor::keyboard_duplicate_selection));
130         add_action ("insert-region", mem_fun(*this, &Editor::keyboard_insert_region_list_selection));
131         add_action ("reverse-region", mem_fun(*this, &Editor::reverse_region));
132         add_action ("normalize-region", mem_fun(*this, &Editor::normalize_region));
133         add_action ("editor-crop", mem_fun(*this, &Editor::crop_region_to_selection));
134         add_action ("insert-chunk", bind (mem_fun(*this, &Editor::paste_named_selection), 1.0f));
135
136         add_action ("split-at-edit-cursor", mem_fun(*this, &Editor::split_region));
137         add_action ("split-at-mouse", mem_fun(*this, &Editor::kbd_split));
138
139         add_action ("brush-at-mouse", mem_fun(*this, &Editor::kbd_brush));
140         add_action ("audition-at-mouse", mem_fun(*this, &Editor::kbd_audition));
141
142         add_action ("start-range", mem_fun(*this, &Editor::keyboard_selection_begin));
143         add_action ("finish-range", bind (mem_fun(*this, &Editor::keyboard_selection_finish), false));
144         add_action ("finish-add-range", bind (mem_fun(*this, &Editor::keyboard_selection_finish), true));
145
146         add_action ("extend-range-to-end-of-region", bind (mem_fun(*this, &Editor::extend_selection_to_end_of_region), false));
147         add_action ("extend-range-to-start-of-region", bind (mem_fun(*this, &Editor::extend_selection_to_start_of_region), false));
148
149         add_action ("zoom-focus-left", bind (mem_fun(*this, &Editor::set_zoom_focus), Editing::ZoomFocusLeft));
150         add_action ("zoom-focus-right", bind (mem_fun(*this, &Editor::set_zoom_focus), Editing::ZoomFocusRight));
151         add_action ("zoom-focus-center", bind (mem_fun(*this, &Editor::set_zoom_focus), Editing::ZoomFocusCenter));
152         add_action ("zoom-focus-playhead", bind (mem_fun(*this, &Editor::set_zoom_focus), Editing::ZoomFocusPlayhead));
153         add_action ("zoom-focus-edit", bind (mem_fun(*this, &Editor::set_zoom_focus), Editing::ZoomFocusEdit));
154
155         add_action ("toggle-follow-playhead", (mem_fun(*this, &Editor::toggle_follow_playhead)));
156         add_action ("remove-last-capture", (mem_fun(*this, &Editor::remove_last_capture)));
157
158         add_action ("snap-to-frame", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToFrame)));
159         add_action ("snap-to-cd-frame", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToCDFrame)));
160         add_action ("snap-to-smpte-frame", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToSMPTEFrame)));
161         add_action ("snap-to-smpte-seconds", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToSMPTESeconds)));
162         add_action ("snap-to-smpte-minutes", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToSMPTEMinutes)));
163         add_action ("snap-to-seconds", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToSeconds)));
164         add_action ("snap-to-minutes", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToMinutes)));
165         add_action ("snap-to-thirtyseconds", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToAThirtysecondBeat)));
166         add_action ("snap-to-asixteenthbeat", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToASixteenthBeat)));
167         add_action ("snap-to-eighths", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToAEighthBeat)));
168         add_action ("snap-to-quarters", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToAQuarterBeat)));
169         add_action ("snap-to-thirds", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToAThirdBeat)));
170         add_action ("snap-to-beat", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToBeat)));
171         add_action ("snap-to-bar", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToBar)));
172         add_action ("snap-to-mark", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToMark)));
173         add_action ("snap-to-edit-cursor", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToEditCursor)));
174         add_action ("snap-to-region-start", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToRegionStart)));
175         add_action ("snap-to-region-end", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToRegionEnd)));
176         add_action ("snap-to-region-sync", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToRegionSync)));
177         add_action ("snap-to-region-boundary", (bind (mem_fun(*this, &Editor::set_snap_to), Editing::SnapToRegionBoundary)));
178 }
179
180 void
181 Editor::keyboard_selection_finish (bool add)
182 {
183         if (session && have_pending_keyboard_selection) {
184                 begin_reversible_command (_("keyboard selection"));
185                 if (!add) {
186                         selection->set (0, pending_keyboard_selection_start, session->audible_frame());
187                 } else {
188                         selection->add (pending_keyboard_selection_start, session->audible_frame());
189                 }
190                 commit_reversible_command ();
191                 have_pending_keyboard_selection = false;
192         }
193 }
194
195 void
196 Editor::keyboard_selection_begin ()
197 {
198         if (session) {
199                 pending_keyboard_selection_start = session->audible_frame();
200                 have_pending_keyboard_selection = true;
201         }
202 }
203
204 void
205 Editor::keyboard_duplicate_region ()
206 {
207         if (selection->audio_regions.empty()) {
208                 return;
209         }
210
211         float prefix;
212         bool was_floating;
213
214         if (get_prefix (prefix, was_floating) == 0) {
215                 duplicate_some_regions (selection->audio_regions, prefix);
216         } else {
217                 duplicate_some_regions (selection->audio_regions, 1);
218         }
219 }
220
221 void
222 Editor::keyboard_duplicate_selection ()
223 {
224         float prefix;
225         bool was_floating;
226
227         if (get_prefix (prefix, was_floating) == 0) {
228                 duplicate_selection (prefix);
229         } else {
230                 duplicate_selection (1);
231         }
232 }
233
234 void
235 Editor::keyboard_paste ()
236 {
237         float prefix;
238         bool was_floating;
239
240         if (get_prefix (prefix, was_floating) == 0) {
241                 paste (prefix);
242         } else {
243                 paste (1);
244         }
245 }
246
247 void
248 Editor::keyboard_insert_region_list_selection ()
249 {
250         float prefix;
251         bool was_floating;
252
253         if (get_prefix (prefix, was_floating) == 0) {
254                 insert_region_list_selection (prefix);
255         } else {
256                 insert_region_list_selection (1);
257         }
258 }
259
260 int
261 Editor::get_prefix (float& val, bool& was_floating)
262 {
263         return Keyboard::the_keyboard().get_prefix (val, was_floating);
264 }
265