merged with 2.0-ongoing changes 2582-2605 (not thoroughly tested but it compiles...
[ardour.git] / gtk2_ardour / editor_actions.cc
1 /*
2     Copyright (C) 2000-2007 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 */
19
20 #include <ardour/ardour.h>
21
22 #include "utils.h"
23 #include "editor.h"
24 #include "editing.h"
25 #include "actions.h"
26 #include "ardour_ui.h"
27 #include "gui_thread.h"
28 #include "i18n.h"
29
30 using namespace Gtk;
31 using namespace Glib;
32 using namespace std;
33 using namespace sigc;
34 using namespace ARDOUR;
35 using namespace PBD;
36 using namespace Editing;
37
38 void
39 Editor::register_actions ()
40 {
41         RefPtr<Action> act;
42
43         editor_actions = ActionGroup::create (X_("Editor"));
44         
45         /* non-operative menu items for menu bar */
46
47         ActionManager::register_action (editor_actions, X_("Edit"), _("Edit"));
48         ActionManager::register_action (editor_actions, X_("EditSelectRegionOptions"), _("Select regions"));
49         ActionManager::register_action (editor_actions, X_("EditSelectRangeOptions"), _("Select range operations"));
50         ActionManager::register_action (editor_actions, X_("EditCursorMovementOptions"), _("Move edit cursor"));
51         ActionManager::register_action (editor_actions, X_("RegionEditOps"), _("Region operations"));
52         ActionManager::register_action (editor_actions, X_("Tools"), _("Tools"));
53         ActionManager::register_action (editor_actions, X_("View"), _("View"));
54         ActionManager::register_action (editor_actions, X_("ZoomFocus"), _("Zoom Focus"));
55         ActionManager::register_action (editor_actions, X_("MeterHold"), _("Meter hold"));
56         ActionManager::register_action (editor_actions, X_("MeterFalloff"), _("Meter falloff"));
57         ActionManager::register_action (editor_actions, X_("Solo"), _("Solo"));
58         ActionManager::register_action (editor_actions, X_("Crossfades"), _("Crossfades"));
59         ActionManager::register_action (editor_actions, X_("Monitoring"), _("Monitoring"));
60         ActionManager::register_action (editor_actions, X_("Autoconnect"), _("Autoconnect"));
61         ActionManager::register_action (editor_actions, X_("Layering"), _("Layering"));
62         ActionManager::register_action (editor_actions, X_("Timecode"), _("Timecode fps"));
63         ActionManager::register_action (editor_actions, X_("Pullup"), _("Pullup / Pulldown"));
64         ActionManager::register_action (editor_actions, X_("Subframes"), _("Subframes"));
65
66
67         /* add named actions for the editor */
68
69         act = ActionManager::register_toggle_action (editor_actions, "show-editor-mixer", _("Show Editor Mixer"), mem_fun (*this, &Editor::editor_mixer_button_toggled));
70         ActionManager::session_sensitive_actions.push_back (act);
71         act = ActionManager::register_toggle_action (editor_actions, "show-editor-list", _("Show Editor List"), mem_fun (*this, &Editor::editor_list_button_toggled));
72         ActionManager::session_sensitive_actions.push_back (act);
73
74         RadioAction::Group crossfade_model_group;
75
76         act = ActionManager::register_radio_action (editor_actions, crossfade_model_group, "CrossfadesFull", _("Span Entire Overlap"), bind (mem_fun(*this, &Editor::set_crossfade_model), FullCrossfade));
77         ActionManager::session_sensitive_actions.push_back (act);
78         act = ActionManager::register_radio_action (editor_actions, crossfade_model_group, "CrossfadesShort", _("Short"), bind (mem_fun(*this, &Editor::set_crossfade_model), ShortCrossfade));
79         ActionManager::session_sensitive_actions.push_back (act);
80
81         act = ActionManager::register_toggle_action (editor_actions, "toggle-xfades-active", _("Active"), mem_fun(*this, &Editor::toggle_xfades_active));
82         ActionManager::session_sensitive_actions.push_back (act);
83         act = ActionManager::register_toggle_action (editor_actions, "toggle-xfades-visible", _("Show"), mem_fun(*this, &Editor::toggle_xfade_visibility));
84         ActionManager::session_sensitive_actions.push_back (act);
85         act = ActionManager::register_toggle_action (editor_actions, "toggle-auto-xfades", _("Created Automatically"), mem_fun(*this, &Editor::toggle_auto_xfade));
86         ActionManager::session_sensitive_actions.push_back (act);
87
88         act = ActionManager::register_action (editor_actions, "playhead-to-next-region-start", _("Playhead to Next Region Start"), bind (mem_fun(*this, &Editor::cursor_to_next_region_point), playhead_cursor, RegionPoint (Start)));
89         ActionManager::session_sensitive_actions.push_back (act);
90         act = ActionManager::register_action (editor_actions, "playhead-to-next-region-end", _("Playhead to Next Region End"), bind (mem_fun(*this, &Editor::cursor_to_next_region_point), playhead_cursor, RegionPoint (End)));
91         ActionManager::session_sensitive_actions.push_back (act);
92         act = ActionManager::register_action (editor_actions, "playhead-to-next-region-sync", _("Playhead to Next Region Sync"), bind (mem_fun(*this, &Editor::cursor_to_next_region_point), playhead_cursor, RegionPoint (SyncPoint)));
93         ActionManager::session_sensitive_actions.push_back (act);
94
95         act = ActionManager::register_action (editor_actions, "playhead-to-previous-region-start", _("Playhead to Previous Region Start"), bind (mem_fun(*this, &Editor::cursor_to_previous_region_point), playhead_cursor, RegionPoint (Start)));
96         ActionManager::session_sensitive_actions.push_back (act);
97         act = ActionManager::register_action (editor_actions, "playhead-to-previous-region-end", _("Playhead to Previous Region End"), bind (mem_fun(*this, &Editor::cursor_to_previous_region_point), playhead_cursor, RegionPoint (End)));
98         ActionManager::session_sensitive_actions.push_back (act);
99         act = ActionManager::register_action (editor_actions, "playhead-to-previous-region-sync", _("Playhead to Previous Region Sync"), bind (mem_fun(*this, &Editor::cursor_to_previous_region_point), playhead_cursor, RegionPoint (SyncPoint)));
100         ActionManager::session_sensitive_actions.push_back (act);
101
102         act = ActionManager::register_action (editor_actions, "edit-cursor-to-next-region-start", _("Edit Cursor to Next Region Start"), bind (mem_fun(*this, &Editor::cursor_to_next_region_point), edit_cursor, RegionPoint (Start)));
103         ActionManager::session_sensitive_actions.push_back (act);
104         act = ActionManager::register_action (editor_actions, "edit-cursor-to-next-region-end", _("Edit Cursor to Next Region End"), bind (mem_fun(*this, &Editor::cursor_to_next_region_point), edit_cursor, RegionPoint (End)));
105         ActionManager::session_sensitive_actions.push_back (act);
106         act = ActionManager::register_action (editor_actions, "edit-cursor-to-next-region-sync", _("Edit Cursor to Next Region Sync"), bind (mem_fun(*this, &Editor::cursor_to_next_region_point), edit_cursor, RegionPoint (SyncPoint)));
107         ActionManager::session_sensitive_actions.push_back (act);
108
109         act = ActionManager::register_action (editor_actions, "edit-cursor-to-previous-region-start", _("Edit Cursor to Previous Region Start"), bind (mem_fun(*this, &Editor::cursor_to_previous_region_point), edit_cursor, RegionPoint (Start)));
110         ActionManager::session_sensitive_actions.push_back (act);
111         act = ActionManager::register_action (editor_actions, "edit-cursor-to-previous-region-end", _("Edit Cursor to Previous Region End"), bind (mem_fun(*this, &Editor::cursor_to_previous_region_point), edit_cursor, RegionPoint (End)));
112         ActionManager::session_sensitive_actions.push_back (act);
113         act = ActionManager::register_action (editor_actions, "edit-cursor-to-previous-region-sync", _("Edit Cursor to Previous Region Sync"), bind (mem_fun(*this, &Editor::cursor_to_previous_region_point), edit_cursor, RegionPoint (SyncPoint)));
114         ActionManager::session_sensitive_actions.push_back (act);
115
116         act = ActionManager::register_action (editor_actions, "playhead-to-range-start", _("Playhead to Range Start"), bind (mem_fun(*this, &Editor::cursor_to_selection_start), playhead_cursor));
117         ActionManager::session_sensitive_actions.push_back (act);
118         act = ActionManager::register_action (editor_actions, "playhead-to-range-end", _("Playhead to Range End"), bind (mem_fun(*this, &Editor::cursor_to_selection_end), playhead_cursor));
119         ActionManager::session_sensitive_actions.push_back (act);
120
121         act = ActionManager::register_action (editor_actions, "edit-cursor-to-range-start", _("Edit Cursor to Range Start"), bind (mem_fun(*this, &Editor::cursor_to_selection_start), edit_cursor));
122         ActionManager::session_sensitive_actions.push_back (act);
123         act = ActionManager::register_action (editor_actions, "edit-cursor-to-range-end", _("Edit Cursor to Range End"), bind (mem_fun(*this, &Editor::cursor_to_selection_end), edit_cursor));
124         ActionManager::session_sensitive_actions.push_back (act);
125
126         act = ActionManager::register_action (editor_actions, "select-all", _("Select All"), bind (mem_fun(*this, &Editor::select_all), Selection::Set));
127         ActionManager::session_sensitive_actions.push_back (act);
128         act = ActionManager::register_action (editor_actions, "select-all-after-edit-cursor", _("Select All After Edit Cursor"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), edit_cursor, true));
129         ActionManager::session_sensitive_actions.push_back (act);
130         act = ActionManager::register_action (editor_actions, "select-all-before-edit-cursor", _("Select All Before Edit Cursor"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), edit_cursor, false));
131         ActionManager::session_sensitive_actions.push_back (act);
132
133         act = ActionManager::register_action (editor_actions, "select-all-after-playhead", _("Select All After Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true));
134         ActionManager::session_sensitive_actions.push_back (act);
135         act = ActionManager::register_action (editor_actions, "select-all-before-playhead", _("Select All Before Playhead"), bind (mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false));
136         ActionManager::session_sensitive_actions.push_back (act);
137         act = ActionManager::register_action (editor_actions, "select-all-between-cursors", _("Select All Between Cursors"), bind (mem_fun(*this, &Editor::select_all_selectables_between_cursors), playhead_cursor, edit_cursor));
138         ActionManager::session_sensitive_actions.push_back (act);
139
140         act = ActionManager::register_action (editor_actions, "select-all-in-punch-range", _("Select All in Punch Range"), mem_fun(*this, &Editor::select_all_selectables_using_punch));
141         ActionManager::session_sensitive_actions.push_back (act);
142         act = ActionManager::register_action (editor_actions, "select-all-in-loop-range", _("Select All in Loop Range"), mem_fun(*this, &Editor::select_all_selectables_using_loop));
143         ActionManager::session_sensitive_actions.push_back (act);
144
145         act = ActionManager::register_action (editor_actions, "jump-forward-to-mark", _("Jump Forward to Mark"), mem_fun(*this, &Editor::jump_forward_to_mark));
146         ActionManager::session_sensitive_actions.push_back (act);
147         act = ActionManager::register_action (editor_actions, "jump-backward-to-mark", _("Jump Backward to Mark"), mem_fun(*this, &Editor::jump_backward_to_mark));
148         ActionManager::session_sensitive_actions.push_back (act);
149         act = ActionManager::register_action (editor_actions, "add-location-from-playhead", _("Add Mark from Playhead"), mem_fun(*this, &Editor::add_location_from_playhead_cursor));
150         ActionManager::session_sensitive_actions.push_back (act);
151
152         act = ActionManager::register_action (editor_actions, "nudge-forward", _("Nudge Forward"), bind (mem_fun(*this, &Editor::nudge_forward), false));
153         ActionManager::session_sensitive_actions.push_back (act);
154         act = ActionManager::register_action (editor_actions, "nudge-next-forward", _("Nudge Next Forward"), bind (mem_fun(*this, &Editor::nudge_forward), true));
155         ActionManager::session_sensitive_actions.push_back (act);
156         act = ActionManager::register_action (editor_actions, "nudge-backward", _("Nudge Backward"), bind (mem_fun(*this, &Editor::nudge_backward), false));
157         ActionManager::session_sensitive_actions.push_back (act);
158         act = ActionManager::register_action (editor_actions, "nudge-next-backward", _("Nudge Next Backward"), bind (mem_fun(*this, &Editor::nudge_backward), true));
159         ActionManager::session_sensitive_actions.push_back (act);
160
161         act = ActionManager::register_action (editor_actions, "temporal-zoom-out", _("Zoom Out"), bind (mem_fun(*this, &Editor::temporal_zoom_step), true));
162         ActionManager::session_sensitive_actions.push_back (act);
163         act = ActionManager::register_action (editor_actions, "temporal-zoom-in", _("Zoom In"), bind (mem_fun(*this, &Editor::temporal_zoom_step), false));
164         ActionManager::session_sensitive_actions.push_back (act);
165         act = ActionManager::register_action (editor_actions, "zoom-to-session", _("Zoom to Session"), mem_fun(*this, &Editor::temporal_zoom_session));
166         ActionManager::session_sensitive_actions.push_back (act);
167
168         act = ActionManager::register_action (editor_actions, "scroll-tracks-up", _("Scroll Tracks Up"), mem_fun(*this, &Editor::scroll_tracks_up));
169         ActionManager::session_sensitive_actions.push_back (act);
170         act = ActionManager::register_action (editor_actions, "scroll-tracks-down", _("Scroll Tracks Down"), mem_fun(*this, &Editor::scroll_tracks_down));
171         ActionManager::session_sensitive_actions.push_back (act);
172         act = ActionManager::register_action (editor_actions, "step-tracks-up", _("Step Tracks Up"), mem_fun(*this, &Editor::scroll_tracks_up_line));
173         ActionManager::session_sensitive_actions.push_back (act);
174         act = ActionManager::register_action (editor_actions, "step-tracks-down", _("Step Tracks Down"), mem_fun(*this, &Editor::scroll_tracks_down_line));
175         ActionManager::session_sensitive_actions.push_back (act);
176
177         act = ActionManager::register_action (editor_actions, "scroll-backward", _("Scroll Backward"), bind (mem_fun(*this, &Editor::scroll_backward), 0.8f));
178         ActionManager::session_sensitive_actions.push_back (act);
179         act = ActionManager::register_action (editor_actions, "scroll-forward", _("Scroll Forward"), bind (mem_fun(*this, &Editor::scroll_forward), 0.8f));
180         ActionManager::session_sensitive_actions.push_back (act);
181         act = ActionManager::register_action (editor_actions, "goto", _("goto"), mem_fun(*this, &Editor::goto_frame));
182         ActionManager::session_sensitive_actions.push_back (act);
183         act = ActionManager::register_action (editor_actions, "center-playhead", _("Center Playhead"), mem_fun(*this, &Editor::center_playhead));
184         ActionManager::session_sensitive_actions.push_back (act);
185         act = ActionManager::register_action (editor_actions, "center-edit-cursor", _("Center Edit Cursor"), mem_fun(*this, &Editor::center_edit_cursor));
186         ActionManager::session_sensitive_actions.push_back (act);
187
188         act = ActionManager::register_action (editor_actions, "scroll-playhead-forward", _("Playhead forward"), bind (mem_fun(*this, &Editor::scroll_playhead), true));;
189         ActionManager::session_sensitive_actions.push_back (act);
190         act = ActionManager::register_action (editor_actions, "scroll-playhead-backward", _("Playhead Backward"), bind (mem_fun(*this, &Editor::scroll_playhead), false));
191         ActionManager::session_sensitive_actions.push_back (act);
192
193         act = ActionManager::register_action (editor_actions, "playhead-to-edit", _("Playhead to Edit"), bind (mem_fun(*this, &Editor::cursor_align), true));
194         ActionManager::session_sensitive_actions.push_back (act);
195         act = ActionManager::register_action (editor_actions, "edit-to-playhead", _("Edit to Playhead"), bind (mem_fun(*this, &Editor::cursor_align), false));
196         ActionManager::session_sensitive_actions.push_back (act);
197
198         act = ActionManager::register_action (editor_actions, "align-regions-start", _("Align Regions Start"), bind (mem_fun(*this, &Editor::align), ARDOUR::Start));
199         ActionManager::session_sensitive_actions.push_back (act);
200         act = ActionManager::register_action (editor_actions, "align-regions-start-relative", _("Align Regions Start Relative"), bind (mem_fun(*this, &Editor::align_relative), ARDOUR::Start));
201         ActionManager::session_sensitive_actions.push_back (act);
202         act = ActionManager::register_action (editor_actions, "align-regions-end", _("Align Regions End"), bind (mem_fun(*this, &Editor::align), ARDOUR::End));
203         ActionManager::session_sensitive_actions.push_back (act);
204         act = ActionManager::register_action (editor_actions, "align-regions-end-relative", _("Align Regions End Relative"), bind (mem_fun(*this, &Editor::align_relative), ARDOUR::End));
205         ActionManager::session_sensitive_actions.push_back (act);
206
207         act = ActionManager::register_action (editor_actions, "align-regions-sync", _("Align Regions Sync"), bind (mem_fun(*this, &Editor::align), ARDOUR::SyncPoint));
208         ActionManager::session_sensitive_actions.push_back (act);
209         act = ActionManager::register_action (editor_actions, "align-regions-sync-relative", _("Align Regions Sync Relative"), bind (mem_fun(*this, &Editor::align_relative), ARDOUR::SyncPoint));
210         ActionManager::session_sensitive_actions.push_back (act);
211         
212         act = ActionManager::register_action (editor_actions, "audition-at-mouse", _("Audition at Mouse"), mem_fun(*this, &Editor::kbd_audition));
213         ActionManager::session_sensitive_actions.push_back (act);
214         act = ActionManager::register_action (editor_actions, "brush-at-mouse", _("Brush at Mouse"), mem_fun(*this, &Editor::kbd_brush));
215         ActionManager::session_sensitive_actions.push_back (act);
216         act = ActionManager::register_action (editor_actions, "set-edit-cursor", _("Set Edit Cursor"), mem_fun(*this, &Editor::kbd_set_edit_cursor));
217         ActionManager::session_sensitive_actions.push_back (act);
218         act = ActionManager::register_action (editor_actions, "mute-unmute-region", _("Mute/Unmute Region"), mem_fun(*this, &Editor::kbd_mute_unmute_region));
219         ActionManager::session_sensitive_actions.push_back (act);
220         act = ActionManager::register_action (editor_actions, "set-playhead", _("Set Playhead"), mem_fun(*this, &Editor::kbd_set_playhead_cursor));
221         ActionManager::session_sensitive_actions.push_back (act);
222         act = ActionManager::register_action (editor_actions, "split-region", _("Split Region"), mem_fun(*this, &Editor::kbd_split));
223         ActionManager::session_sensitive_actions.push_back (act);
224         act = ActionManager::register_action (editor_actions, "set-region-sync-position", _("Set Region Sync Position"), mem_fun(*this, &Editor::kbd_set_sync_position));
225         ActionManager::session_sensitive_actions.push_back (act);
226
227         undo_action = act = ActionManager::register_action (editor_actions, "undo", _("Undo"), bind (mem_fun(*this, &Editor::undo), 1U));
228         ActionManager::session_sensitive_actions.push_back (act);
229         redo_action = act = ActionManager::register_action (editor_actions, "redo", _("Redo"), bind (mem_fun(*this, &Editor::redo), 1U));
230         ActionManager::session_sensitive_actions.push_back (act);
231
232         act = ActionManager::register_action (editor_actions, "export-session", _("Export Session"), mem_fun(*this, &Editor::export_session));
233         ActionManager::session_sensitive_actions.push_back (act);
234         act = ActionManager::register_action (editor_actions, "export-range", _("Export Range"), mem_fun(*this, &Editor::export_selection));
235         ActionManager::session_sensitive_actions.push_back (act);
236
237         act = ActionManager::register_action (editor_actions, "editor-cut", _("Cut"), mem_fun(*this, &Editor::cut));
238         ActionManager::session_sensitive_actions.push_back (act);
239         /* Note: for now, editor-delete does the exact same thing as editor-cut */
240         act = ActionManager::register_action (editor_actions, "editor-delete", _("Delete"), mem_fun(*this, &Editor::cut));
241         ActionManager::session_sensitive_actions.push_back (act);
242         act = ActionManager::register_action (editor_actions, "editor-copy", _("Copy"), mem_fun(*this, &Editor::copy));
243         ActionManager::session_sensitive_actions.push_back (act);
244         act = ActionManager::register_action (editor_actions, "editor-paste", _("Paste"), mem_fun(*this, &Editor::keyboard_paste));
245         ActionManager::session_sensitive_actions.push_back (act);
246         act = ActionManager::register_action (editor_actions, "duplicate-region", _("Duplicate Region"), mem_fun(*this, &Editor::keyboard_duplicate_region));
247         ActionManager::session_sensitive_actions.push_back (act);
248         act = ActionManager::register_action (editor_actions, "duplicate-range", _("Duplicate Range"), mem_fun(*this, &Editor::keyboard_duplicate_selection));
249         ActionManager::session_sensitive_actions.push_back (act);
250         act = ActionManager::register_action (editor_actions, "insert-region", _("Insert Region"), mem_fun(*this, &Editor::keyboard_insert_region_list_selection));
251         ActionManager::session_sensitive_actions.push_back (act);
252         act = ActionManager::register_action (editor_actions, "reverse-region", _("Reverse Regions"), mem_fun(*this, &Editor::reverse_regions));
253         ActionManager::session_sensitive_actions.push_back (act);
254         act = ActionManager::register_action (editor_actions, "normalize-region", _("Normalize Regions"), mem_fun(*this, &Editor::normalize_regions));
255         ActionManager::session_sensitive_actions.push_back (act);
256         act = ActionManager::register_action (editor_actions, "quantize-region", _("Quantize Regions"), mem_fun(*this, &Editor::quantize_regions));
257         ActionManager::session_sensitive_actions.push_back (act);
258         act = ActionManager::register_action (editor_actions, "crop", _("Crop"), mem_fun(*this, &Editor::crop_region_to_selection));
259         ActionManager::session_sensitive_actions.push_back (act);
260         act = ActionManager::register_action (editor_actions, "insert-chunk", _("Insert Chunk"), bind (mem_fun(*this, &Editor::paste_named_selection), 1.0f));
261         ActionManager::session_sensitive_actions.push_back (act);
262
263         act = ActionManager::register_action (editor_actions, "split-at-edit-cursor", _("Split at edit cursor"), mem_fun(*this, &Editor::split_region));
264         ActionManager::edit_cursor_in_region_sensitive_actions.push_back (act);
265
266         act = ActionManager::register_action (editor_actions, "start-range", _("Start Range"), mem_fun(*this, &Editor::keyboard_selection_begin));
267         ActionManager::session_sensitive_actions.push_back (act);
268         act = ActionManager::register_action (editor_actions, "finish-range", _("Finish Range"), bind (mem_fun(*this, &Editor::keyboard_selection_finish), false));
269         ActionManager::session_sensitive_actions.push_back (act);
270         act = ActionManager::register_action (editor_actions, "finish-add-range", _("Finish add Range"), bind (mem_fun(*this, &Editor::keyboard_selection_finish), true));
271         ActionManager::session_sensitive_actions.push_back (act);
272
273         act = ActionManager::register_action (editor_actions, "extend-range-to-end-of-region", _("Extend Range to End of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_end_of_region), false));
274         ActionManager::session_sensitive_actions.push_back (act);
275         act = ActionManager::register_action (editor_actions, "extend-range-to-start-of-region", _("Extend Range to Start of Region"), bind (mem_fun(*this, &Editor::extend_selection_to_start_of_region), false));
276         ActionManager::session_sensitive_actions.push_back (act);
277
278         act = ActionManager::register_toggle_action (editor_actions, "toggle-follow-playhead", _("Follow Playhead"), (mem_fun(*this, &Editor::toggle_follow_playhead)));
279         ActionManager::session_sensitive_actions.push_back (act);
280         act = ActionManager::register_action (editor_actions, "remove-last-capture", _("Remove Last Capture"), (mem_fun(*this, &Editor::remove_last_capture)));
281         ActionManager::session_sensitive_actions.push_back (act);
282
283         Glib::RefPtr<ActionGroup> zoom_actions = ActionGroup::create (X_("Zoom"));
284         RadioAction::Group zoom_group;
285
286         ActionManager::register_radio_action (zoom_actions, zoom_group, "zoom-focus-left", _("Zoom Focus Left"), bind (mem_fun(*this, &Editor::zoom_focus_chosen), Editing::ZoomFocusLeft));
287         ActionManager::session_sensitive_actions.push_back (act);
288         ActionManager::register_radio_action (zoom_actions, zoom_group, "zoom-focus-right", _("Zoom Focus Right"), bind (mem_fun(*this, &Editor::zoom_focus_chosen), Editing::ZoomFocusRight));
289         ActionManager::session_sensitive_actions.push_back (act);
290         ActionManager::register_radio_action (zoom_actions, zoom_group, "zoom-focus-center", _("Zoom Focus Center"), bind (mem_fun(*this, &Editor::zoom_focus_chosen), Editing::ZoomFocusCenter));
291         ActionManager::session_sensitive_actions.push_back (act);
292         ActionManager::register_radio_action (zoom_actions, zoom_group, "zoom-focus-playhead", _("Zoom Focus Playhead"), bind (mem_fun(*this, &Editor::zoom_focus_chosen), Editing::ZoomFocusPlayhead));
293         ActionManager::session_sensitive_actions.push_back (act);
294         ActionManager::register_radio_action (zoom_actions, zoom_group, "zoom-focus-mouse", _("Zoom Focus Mouse"), bind (mem_fun(*this, &Editor::zoom_focus_chosen), Editing::ZoomFocusMouse));
295         ActionManager::session_sensitive_actions.push_back (act);
296         ActionManager::register_radio_action (zoom_actions, zoom_group, "zoom-focus-edit", _("Zoom Focus Edit"), bind (mem_fun(*this, &Editor::zoom_focus_chosen), Editing::ZoomFocusEdit));
297         ActionManager::session_sensitive_actions.push_back (act);
298
299         Glib::RefPtr<ActionGroup> mouse_mode_actions = ActionGroup::create (X_("MouseMode"));
300         RadioAction::Group mouse_mode_group;
301
302         ActionManager::register_radio_action (mouse_mode_actions, mouse_mode_group, "set-mouse-mode-object", _("Object Tool"), bind (mem_fun(*this, &Editor::set_mouse_mode), Editing::MouseObject, false));
303         ActionManager::register_radio_action (mouse_mode_actions, mouse_mode_group, "set-mouse-mode-range", _("Range Tool"), bind (mem_fun(*this, &Editor::set_mouse_mode), Editing::MouseRange, false));
304         ActionManager::register_radio_action (mouse_mode_actions, mouse_mode_group, "set-mouse-mode-gain", _("Gain Tool"), bind (mem_fun(*this, &Editor::set_mouse_mode), Editing::MouseGain, false));
305         ActionManager::register_radio_action (mouse_mode_actions, mouse_mode_group, "set-mouse-mode-zoom", _("Zoom Tool"), bind (mem_fun(*this, &Editor::set_mouse_mode), Editing::MouseZoom, false));
306         ActionManager::register_radio_action (mouse_mode_actions, mouse_mode_group, "set-mouse-mode-timefx", _("Timefx Tool"), bind (mem_fun(*this, &Editor::set_mouse_mode), Editing::MouseTimeFX, false));
307         ActionManager::register_radio_action (mouse_mode_actions, mouse_mode_group, "set-mouse-mode-note", _("Note Tool"), bind (mem_fun(*this, &Editor::set_mouse_mode), Editing::MouseNote, false));
308
309         RadioAction::Group edit_point_group;
310         ActionManager::register_radio_action (editor_actions, edit_point_group, X_("edit-at-playhead"), _("Playhead"), (bind (mem_fun(*this, &Editor::edit_point_chosen), Editing::EditAtPlayhead)));
311         ActionManager::register_radio_action (editor_actions, edit_point_group, X_("edit-at-mouse"), _("Mouse"), (bind (mem_fun(*this, &Editor::edit_point_chosen), Editing::EditAtPlayhead)));
312         ActionManager::register_radio_action (editor_actions, edit_point_group, X_("edit-at-selected-marker"), _("Marker"), (bind (mem_fun(*this, &Editor::edit_point_chosen), Editing::EditAtPlayhead)));
313
314         ActionManager::register_action (editor_actions, X_("SnapTo"), _("Snap To"));
315         ActionManager::register_action (editor_actions, X_("SnapMode"), _("Snap Mode"));
316
317         RadioAction::Group snap_mode_group;
318         ActionManager::register_radio_action (editor_actions, snap_mode_group, X_("snap-normal"), _("Normal"), (bind (mem_fun(*this, &Editor::snap_mode_chosen), Editing::SnapNormal)));
319         ActionManager::register_radio_action (editor_actions, snap_mode_group, X_("snap-magnetic"), _("Magnetic"), (bind (mem_fun(*this, &Editor::snap_mode_chosen), Editing::SnapMagnetic)));
320
321         Glib::RefPtr<ActionGroup> snap_actions = ActionGroup::create (X_("Snap"));
322         RadioAction::Group snap_choice_group;
323
324         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-frame"), _("Snap to frame"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToFrame)));
325         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-cd-frame"), _("Snap to cd frame"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToCDFrame)));
326         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-smpte-frame"), _("Snap to SMPTE frame"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToSMPTEFrame)));
327         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-smpte-seconds"), _("Snap to SMPTE seconds"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToSMPTESeconds)));
328         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-smpte-minutes"), _("Snap to SMPTE minutes"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToSMPTEMinutes)));
329         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-seconds"), _("Snap to seconds"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToSeconds)));
330         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-minutes"), _("Snap to minutes"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToMinutes)));
331         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-thirtyseconds"), _("Snap to thirtyseconds"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToAThirtysecondBeat)));
332         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-asixteenthbeat"), _("Snap to asixteenthbeat"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToASixteenthBeat)));
333         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-eighths"), _("Snap to eighths"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToAEighthBeat)));
334         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-quarters"), _("Snap to quarters"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToAQuarterBeat)));
335         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-thirds"), _("Snap to thirds"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToAThirdBeat)));
336         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-beat"), _("Snap to beat"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToBeat)));
337         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-bar"), _("Snap to bar"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToBar)));
338         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-mark"), _("Snap to mark"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToMark)));
339         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-edit-cursor"), _("Snap to edit cursor"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToEditCursor)));
340         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-region-start"), _("Snap to region start"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToRegionStart)));
341         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-region-end"), _("Snap to region end"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToRegionEnd)));
342         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-region-sync"), _("Snap to region sync"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToRegionSync)));
343         ActionManager::register_radio_action (snap_actions, snap_choice_group, X_("snap-to-region-boundary"), _("Snap to region boundary"), (bind (mem_fun(*this, &Editor::snap_type_chosen), Editing::SnapToRegionBoundary)));
344
345         /* REGION LIST */
346
347         Glib::RefPtr<ActionGroup> rl_actions = ActionGroup::create (X_("RegionList"));
348         RadioAction::Group sort_type_group;
349         RadioAction::Group sort_order_group;
350
351         /* the region list popup menu */
352         ActionManager::register_action (rl_actions, X_("RegionListSort"), _("Sort"));
353
354         act = ActionManager::register_action (rl_actions, X_("rlAudition"), _("Audition"), mem_fun(*this, &Editor::audition_region_from_region_list));
355         ActionManager::region_list_selection_sensitive_actions.push_back (act);
356         act = ActionManager::register_action (rl_actions, X_("rlHide"), _("Hide"), mem_fun(*this, &Editor::hide_region_from_region_list));
357         ActionManager::region_list_selection_sensitive_actions.push_back (act);
358         act = ActionManager::register_action (rl_actions, X_("rlRemove"), _("Remove"), mem_fun (*this, &Editor::remove_region_from_region_list));
359         ActionManager::region_list_selection_sensitive_actions.push_back (act);
360         ActionManager::register_toggle_action (rl_actions, X_("rlShowAll"), _("Show all"), mem_fun(*this, &Editor::toggle_full_region_list));
361         ActionManager::register_toggle_action (rl_actions, X_("rlShowAuto"), _("Show automatic regions"), mem_fun(*this, &Editor::toggle_show_auto_regions));
362
363         ActionManager::register_radio_action (rl_actions, sort_order_group, X_("SortAscending"),  _("Ascending"),
364                                bind (mem_fun(*this, &Editor::reset_region_list_sort_direction), true));
365         ActionManager::register_radio_action (rl_actions, sort_order_group, X_("SortDescending"),   _("Descending"),
366                                bind (mem_fun(*this, &Editor::reset_region_list_sort_direction), false));
367         
368         ActionManager::register_radio_action (rl_actions, sort_type_group, X_("SortByRegionName"),  _("By Region Name"),
369                                bind (mem_fun(*this, &Editor::reset_region_list_sort_type), ByName));
370         ActionManager::register_radio_action (rl_actions, sort_type_group, X_("SortByRegionLength"),  _("By Region Length"),
371                                bind (mem_fun(*this, &Editor::reset_region_list_sort_type), ByLength));
372         ActionManager::register_radio_action (rl_actions, sort_type_group, X_("SortByRegionPosition"),  _("By Region Position"),
373                                bind (mem_fun(*this, &Editor::reset_region_list_sort_type), ByPosition));
374         ActionManager::register_radio_action (rl_actions, sort_type_group, X_("SortByRegionTimestamp"),  _("By Region Timestamp"),
375                                bind (mem_fun(*this, &Editor::reset_region_list_sort_type), ByTimestamp));
376         ActionManager::register_radio_action (rl_actions, sort_type_group, X_("SortByRegionStartinFile"),  _("By Region Start in File"),
377                                bind (mem_fun(*this, &Editor::reset_region_list_sort_type), ByStartInFile));
378         ActionManager::register_radio_action (rl_actions, sort_type_group, X_("SortByRegionEndinFile"),  _("By Region End in File"),
379                                bind (mem_fun(*this, &Editor::reset_region_list_sort_type), ByEndInFile));
380         ActionManager::register_radio_action (rl_actions, sort_type_group, X_("SortBySourceFileName"),  _("By Source File Name"),
381                                bind (mem_fun(*this, &Editor::reset_region_list_sort_type), BySourceFileName));
382         ActionManager::register_radio_action (rl_actions, sort_type_group, X_("SortBySourceFileLength"),  _("By Source File Length"),
383                                bind (mem_fun(*this, &Editor::reset_region_list_sort_type), BySourceFileLength));
384         ActionManager::register_radio_action (rl_actions, sort_type_group, X_("SortBySourceFileCreationDate"),  _("By Source File Creation Date"),
385                                bind (mem_fun(*this, &Editor::reset_region_list_sort_type), BySourceFileCreationDate));
386         ActionManager::register_radio_action (rl_actions, sort_type_group, X_("SortBySourceFilesystem"),  _("By Source Filesystem"),
387                                bind (mem_fun(*this, &Editor::reset_region_list_sort_type), BySourceFileFS));
388
389
390         /* the next two are duplicate items with different names for use in two different contexts */
391
392         ActionManager::register_action (editor_actions, X_("addExistingAudioFiles"), _("Add Existing Audio"), mem_fun (*this, &Editor::external_audio_dialog));
393
394         act = ActionManager::register_action (editor_actions, X_("addExternalAudioToRegionList"), _("Add External Audio"), bind (mem_fun(*this, &Editor::add_external_audio_action), ImportAsRegion));
395         ActionManager::session_sensitive_actions.push_back (act);
396
397         ActionManager::register_toggle_action (editor_actions, X_("ToggleWaveformVisibility"), _("Show Waveforms"), mem_fun (*this, &Editor::toggle_waveform_visibility));
398         ActionManager::register_toggle_action (editor_actions, X_("ToggleWaveformsWhileRecording"), _("Show Waveforms While Recording"), mem_fun (*this, &Editor::toggle_waveforms_while_recording));
399         act = ActionManager::register_toggle_action (editor_actions, X_("ToggleMeasureVisibility"), _("Show Measures"), mem_fun (*this, &Editor::toggle_measure_visibility));
400         
401         /* if there is a logo in the editor canvas, its always visible at startup */
402
403         act = ActionManager::register_toggle_action (editor_actions, X_("ToggleLogoVisibility"), _("Show Logo"), mem_fun (*this, &Editor::toggle_logo_visibility));
404         Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
405         tact->set_active (true);
406
407         RadioAction::Group layer_model_group;
408
409         ActionManager::register_radio_action (editor_actions, layer_model_group,  X_("LayerLaterHigher"), _("Later is Higher"), bind (mem_fun (*this, &Editor::set_layer_model), LaterHigher));
410         ActionManager::register_radio_action (editor_actions, layer_model_group,  X_("LayerMoveAddHigher"), _("Most Recently Moved/Added is Higher"), bind (mem_fun (*this, &Editor::set_layer_model), MoveAddHigher));
411         ActionManager::register_radio_action (editor_actions, layer_model_group,  X_("LayerAddHigher"), _("Most Recently Added is Higher"), bind (mem_fun (*this, &Editor::set_layer_model), AddHigher));
412
413         RadioAction::Group smpte_group;
414
415         ActionManager::register_radio_action (editor_actions, smpte_group,  X_("Smpte23976"), _("23.976"), bind (mem_fun (*this, &Editor::smpte_fps_chosen), smpte_23976));
416         ActionManager::register_radio_action (editor_actions, smpte_group,  X_("Smpte24"), _("24"), bind (mem_fun (*this, &Editor::smpte_fps_chosen), smpte_24));
417         ActionManager::register_radio_action (editor_actions, smpte_group,  X_("Smpte24976"), _("24.976"), bind (mem_fun (*this, &Editor::smpte_fps_chosen), smpte_24976));
418         ActionManager::register_radio_action (editor_actions, smpte_group,  X_("Smpte25"), _("25"), bind (mem_fun (*this, &Editor::smpte_fps_chosen), smpte_25));
419         ActionManager::register_radio_action (editor_actions, smpte_group,  X_("Smpte2997"), _("29.97"), bind (mem_fun (*this, &Editor::smpte_fps_chosen), smpte_2997));
420         ActionManager::register_radio_action (editor_actions, smpte_group,  X_("Smpte2997drop"), _("29.97 drop"), bind (mem_fun (*this, &Editor::smpte_fps_chosen), smpte_2997drop));
421         ActionManager::register_radio_action (editor_actions, smpte_group,  X_("Smpte30"), _("30"), bind (mem_fun (*this, &Editor::smpte_fps_chosen), smpte_30));
422         ActionManager::register_radio_action (editor_actions, smpte_group,  X_("Smpte30drop"), _("30 drop"), bind (mem_fun (*this, &Editor::smpte_fps_chosen), smpte_30drop));
423         ActionManager::register_radio_action (editor_actions, smpte_group,  X_("Smpte5994"), _("59.94"), bind (mem_fun (*this, &Editor::smpte_fps_chosen), smpte_5994));
424         ActionManager::register_radio_action (editor_actions, smpte_group,  X_("Smpte60"), _("60"), bind (mem_fun (*this, &Editor::smpte_fps_chosen), smpte_60));
425
426         RadioAction::Group pullup_group;
427
428         ActionManager::register_radio_action (editor_actions, pullup_group,  X_("PullupPlus4Plus1"), _("+4.1667% + 0.1%"), bind (mem_fun (*this, &Editor::video_pullup_chosen), Session::pullup_Plus4Plus1));
429         ActionManager::register_radio_action (editor_actions, pullup_group,  X_("PullupPlus4"), _("+4.1667%"), bind (mem_fun (*this, &Editor::video_pullup_chosen), Session::pullup_Plus4));
430         ActionManager::register_radio_action (editor_actions, pullup_group,  X_("PullupPlus4Minus1"), _("+4.1667% - 0.1%"), bind (mem_fun (*this, &Editor::video_pullup_chosen), Session::pullup_Plus4Minus1));
431         ActionManager::register_radio_action (editor_actions, pullup_group,  X_("PullupPlus1"), _("+ 0.1%"), bind (mem_fun (*this, &Editor::video_pullup_chosen), Session::pullup_Plus1));
432         ActionManager::register_radio_action (editor_actions, pullup_group,  X_("PullupNone"), _("None"), bind (mem_fun (*this, &Editor::video_pullup_chosen), Session::pullup_None));
433         ActionManager::register_radio_action (editor_actions, pullup_group,  X_("PullupMinus1"), _("- 0.1%"), bind (mem_fun (*this, &Editor::video_pullup_chosen), Session::pullup_Minus1));
434         ActionManager::register_radio_action (editor_actions, pullup_group,  X_("PullupMinus4Plus1"), _("-4.1667% + 0.1%"), bind (mem_fun (*this, &Editor::video_pullup_chosen), Session::pullup_Minus4Plus1));
435         ActionManager::register_radio_action (editor_actions, pullup_group,  X_("PullupMinus4"), _("-4.1667%"), bind (mem_fun (*this, &Editor::video_pullup_chosen), Session::pullup_Minus4));
436         ActionManager::register_radio_action (editor_actions, pullup_group,  X_("PullupMinus4Minus1"), _("-4.1667% - 0.1%"), bind (mem_fun (*this, &Editor::video_pullup_chosen), Session::pullup_Minus4Minus1));
437
438         RadioAction::Group subframe_group;
439
440         ActionManager::register_radio_action (editor_actions, subframe_group,  X_("Subframes80"), _("80 per frame"), bind (mem_fun (*this, 
441 &Editor::subframes_per_frame_chosen), 80));
442         ActionManager::register_radio_action (editor_actions, subframe_group,  X_("Subframes100"), _("100 per frame"), bind (mem_fun (*this, 
443 &Editor::subframes_per_frame_chosen), 100));
444
445         ActionManager::add_action_group (rl_actions);
446         ActionManager::add_action_group (zoom_actions);
447         ActionManager::add_action_group (mouse_mode_actions);
448         ActionManager::add_action_group (snap_actions);
449         ActionManager::add_action_group (editor_actions);
450 }
451
452 void
453 Editor::toggle_waveform_visibility ()
454 {
455         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformVisibility"));
456         if (act) {
457                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
458                 set_show_waveforms (tact->get_active());
459         }
460 }
461
462 void
463 Editor::toggle_waveforms_while_recording ()
464 {
465         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleWaveformsWhileRecording"));
466         if (act) {
467                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
468                 set_show_waveforms_recording (tact->get_active());
469         }
470 }
471
472 void
473 Editor::toggle_measure_visibility ()
474 {
475         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleMeasureVisibility"));
476         if (act) {
477                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
478                 set_show_measures (tact->get_active());
479         }
480 }
481
482 void
483 Editor::toggle_logo_visibility ()
484 {
485         Glib::RefPtr<Action> act = ActionManager::get_action (X_("Editor"), X_("ToggleLogoVisibility"));
486
487         if (act) {
488                 Glib::RefPtr<ToggleAction> tact = Glib::RefPtr<ToggleAction>::cast_dynamic(act);
489                 if (logo_item) {
490                         if (tact->get_active()) {
491                                 logo_item->show ();
492                         } else {
493                                 logo_item->hide ();
494                         }
495                 }
496         }
497 }
498
499 void
500 Editor::set_crossfade_model (CrossfadeModel model)
501 {
502         RefPtr<Action> act;
503
504         /* this is driven by a toggle on a radio group, and so is invoked twice,
505            once for the item that became inactive and once for the one that became
506            active.
507         */
508
509         switch (model) {
510         case FullCrossfade:
511                 act = ActionManager::get_action (X_("Editor"), X_("CrossfadesFull"));
512                 break;
513         case ShortCrossfade:
514                 act = ActionManager::get_action (X_("Editor"), X_("CrossfadesShort"));
515                 break;
516         }
517         
518         if (act) {
519                 RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
520                 if (ract && ract->get_active()) {
521                         Config->set_xfade_model (model);
522                 }
523         }
524 }
525
526 void
527 Editor::update_crossfade_model ()
528 {
529         RefPtr<Action> act;
530
531         switch (Config->get_xfade_model()) {
532         case FullCrossfade:
533                 act = ActionManager::get_action (X_("Editor"), X_("CrossfadesFull"));
534                 break;
535         case ShortCrossfade:
536                 act = ActionManager::get_action (X_("Editor"), X_("CrossfadesShort"));
537                 break;
538         }
539
540         if (act) {
541                 RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
542                 if (ract && !ract->get_active()) {
543                         ract->set_active (true);
544                 }
545         }
546 }
547
548 void
549 Editor::update_smpte_mode ()
550 {
551         ENSURE_GUI_THREAD(mem_fun(*this, &Editor::update_smpte_mode));
552
553         RefPtr<Action> act;
554         const char* action = 0;
555
556         switch (Config->get_smpte_format()) {
557         case smpte_23976:
558                 action = X_("Smpte23976");
559                 break;
560         case smpte_24:
561                 action = X_("Smpte24");
562                 break;
563         case smpte_24976:
564                 action = X_("Smpte24976");
565                 break;
566         case smpte_25:
567                 action = X_("Smpte25");
568                 break;
569         case smpte_2997:
570                 action = X_("Smpte2997");
571                 break;
572         case smpte_2997drop:
573                 action = X_("Smpte2997drop");
574                 break;
575         case smpte_30:
576                 action = X_("Smpte30");
577                 break;
578         case smpte_30drop:
579                 action = X_("Smpte30drop");
580                 break;
581         case smpte_5994:
582                 action = X_("Smpte5994");
583                 break;
584         case smpte_60:
585                 action = X_("Smpte60");
586                 break;
587         }
588
589         act = ActionManager::get_action (X_("Editor"), action);
590
591         if (act) {
592                 RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
593                 if (ract && !ract->get_active()) {
594                         ract->set_active (true);
595                 }
596         }
597 }
598
599 void
600 Editor::update_video_pullup ()
601 {
602         ENSURE_GUI_THREAD (mem_fun(*this, &Editor::update_video_pullup));
603
604         RefPtr<Action> act;
605         const char* action = 0;
606
607         float pullup = Config->get_video_pullup();
608
609         if ( pullup < (-4.1667 - 0.1) * 0.99) {
610                 action = X_("PullupMinus4Minus1");
611         } else if ( pullup < (-4.1667) * 0.99 ) {
612                 action = X_("PullupMinus4");
613         } else if ( pullup < (-4.1667 + 0.1) * 0.99 ) {
614                 action = X_("PullupMinus4Plus1");
615         } else if ( pullup < (-0.1) * 0.99 ) {
616                 action = X_("PullupMinus1");
617         } else if (pullup > (4.1667 + 0.1) * 0.99 ) {
618                 action = X_("PullupPlus4Plus1");
619         } else if ( pullup > (4.1667) * 0.99 ) {
620                 action = X_("PullupPlus4");
621         } else if ( pullup > (4.1667 - 0.1) * 0.99) {
622                 action = X_("PullupPlus4Minus1");
623         } else if ( pullup > (0.1) * 0.99 ) {
624                 action = X_("PullupPlus1");
625         } else {
626                 action = X_("PullupNone");
627         }
628
629         act = ActionManager::get_action (X_("Editor"), action);
630
631         if (act) {
632                 RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
633                 if (ract && !ract->get_active()) {
634                         ract->set_active (true);
635                 }
636         }
637 }
638
639 void
640 Editor::update_layering_model ()
641 {
642         RefPtr<Action> act;
643
644         switch (Config->get_layer_model()) {
645         case LaterHigher:
646                 act = ActionManager::get_action (X_("Editor"), X_("LayerLaterHigher"));
647                 break;
648         case MoveAddHigher:
649                 act = ActionManager::get_action (X_("Editor"), X_("LayerMoveAddHigher"));
650                 break;
651         case AddHigher:
652                 act = ActionManager::get_action (X_("Editor"), X_("LayerAddHigher"));
653                 break;
654         }
655
656         if (act) {
657                 RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
658                 if (ract && !ract->get_active()) {
659                         ract->set_active (true);
660                 }
661         }
662 }
663
664 void
665 Editor::set_layer_model (LayerModel model)
666 {
667         /* this is driven by a toggle on a radio group, and so is invoked twice,
668            once for the item that became inactive and once for the one that became
669            active.
670         */
671
672         RefPtr<Action> act;
673
674         switch (model) {
675         case LaterHigher:
676                 act = ActionManager::get_action (X_("Editor"), X_("LayerLaterHigher"));
677                 break;
678         case MoveAddHigher:
679                 act = ActionManager::get_action (X_("Editor"), X_("LayerMoveAddHigher"));
680                 break;
681         case AddHigher:
682                 act = ActionManager::get_action (X_("Editor"), X_("LayerAddHigher"));
683                 break;
684         }
685         
686         if (act) {
687                 RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
688                 if (ract && ract->get_active() && Config->get_layer_model() != model) {
689                         Config->set_layer_model (model);
690                 }
691         }
692 }
693
694 RefPtr<RadioAction>
695 Editor::snap_type_action (SnapType type)
696 {
697
698         const char* action = 0;
699         RefPtr<Action> act;
700         
701         switch (type) {
702         case Editing::SnapToFrame:
703                 action = "snap-to-frame";
704                 break;
705         case Editing::SnapToCDFrame:
706                 action = "snap-to-cd-frame";
707                 break;
708         case Editing::SnapToSMPTEFrame:
709                 action = "snap-to-smpte-frame";
710                 break;
711         case Editing::SnapToSMPTESeconds:
712                 action = "snap-to-smpte-seconds";
713                 break;
714         case Editing::SnapToSMPTEMinutes:
715                 action = "snap-to-smpte-minutes";
716                 break;
717         case Editing::SnapToSeconds:
718                 action = "snap-to-seconds";
719                 break;
720         case Editing::SnapToMinutes:
721                 action = "snap-to-minutes";
722                 break;
723         case Editing::SnapToAThirtysecondBeat:
724                 action = "snap-to-thirtyseconds";
725                 break;
726         case Editing::SnapToASixteenthBeat:
727                 action = "snap-to-asixteenthbeat";
728                 break;
729         case Editing::SnapToAEighthBeat:
730                 action = "snap-to-eighths";
731                 break;
732         case Editing::SnapToAQuarterBeat:
733                 action = "snap-to-quarters";
734                 break;
735         case Editing::SnapToAThirdBeat:
736                 action = "snap-to-thirds";
737                 break;
738         case Editing::SnapToBeat:
739                 action = "snap-to-beat";
740                 break;
741         case Editing::SnapToBar:
742                 action = "snap-to-bar";
743                 break;
744         case Editing::SnapToMark:
745                 action = "snap-to-mark";
746                 break;
747         case Editing::SnapToEditCursor:
748                 action = "snap-to-edit-cursor";
749                 break;
750         case Editing::SnapToRegionStart:
751                 action = "snap-to-region-start";
752                 break;
753         case Editing::SnapToRegionEnd:
754                 action = "snap-to-region-end";
755                 break;
756         case Editing::SnapToRegionSync:
757                 action = "snap-to-region-sync";
758                 break;
759         case Editing::SnapToRegionBoundary:
760                 action = "snap-to-region-boundary";
761                 break;
762         default:
763                 fatal << string_compose (_("programming error: %1: %2"), "Editor: impossible snap-to type", (int) type) << endmsg;
764                 /*NOTREACHED*/
765         }
766
767         act = ActionManager::get_action (X_("Snap"), action);
768
769         if (act) {
770                 RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
771                 return ract;
772
773         } else  {
774                 error << string_compose (_("programming error: %1"), "Editor::snap_type_chosen could not find action to match type.") << endmsg;
775                 return RefPtr<RadioAction>();
776         }
777 }
778
779 void
780 Editor::snap_type_chosen (SnapType type)
781 {
782         /* this is driven by a toggle on a radio group, and so is invoked twice,
783            once for the item that became inactive and once for the one that became
784            active.
785         */
786
787         RefPtr<RadioAction> ract = snap_type_action (type);
788
789         if (ract && ract->get_active()) {
790                 set_snap_to (type);
791         }
792 }
793
794 RefPtr<RadioAction>
795 Editor::snap_mode_action (SnapMode mode)
796 {
797         const char* action = 0;
798         RefPtr<Action> act;
799         
800         switch (mode) {
801         case Editing::SnapNormal:
802                 action = X_("snap-normal");
803                 break;
804         case Editing::SnapMagnetic:
805                 action = X_("snap-magnetic");
806                 break;
807         default:
808                 fatal << string_compose (_("programming error: %1: %2"), "Editor: impossible snap mode type", (int) mode) << endmsg;
809                 /*NOTREACHED*/
810         }
811         
812         act = ActionManager::get_action (X_("Editor"), action);
813         
814         if (act) {
815                 RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
816                 return ract;
817                 
818         } else  {
819                 error << string_compose (_("programming error: %1: %2"), "Editor::snap_mode_chosen could not find action to match mode.", action) << endmsg;
820                 return RefPtr<RadioAction> ();
821         }
822 }
823
824 void
825 Editor::snap_mode_chosen (SnapMode mode)
826 {
827         /* this is driven by a toggle on a radio group, and so is invoked twice,
828            once for the item that became inactive and once for the one that became
829            active.
830         */
831
832         RefPtr<RadioAction> ract = snap_mode_action (mode);
833
834         if (ract && ract->get_active()) {
835                 set_snap_mode (mode);
836         }
837 }
838
839 RefPtr<RadioAction>
840 Editor::edit_point_action (EditPoint ep)
841 {
842         const char* action = 0;
843         RefPtr<Action> act;
844         
845         switch (ep) {
846         case Editing::EditAtPlayhead:
847                 action = X_("edit-at-playhead");
848                 break;
849         case Editing::EditAtSelectedMarker:
850                 action = X_("edit-at-selected-marker");
851                 break;
852         case Editing::EditAtMouse:
853                 action = X_("edit-at-mouse");
854                 break;
855         default:
856                 fatal << string_compose (_("programming error: %1: %2"), "Editor: impossible edit point type", (int) ep) << endmsg;
857                 /*NOTREACHED*/
858         }
859         
860         act = ActionManager::get_action (X_("Editor"), action);
861         
862         if (act) {
863                 RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
864                 return ract;
865                 
866         } else  {
867                 error << string_compose (_("programming error: %1: %2"), "Editor::edit_point_action could not find action to match edit point.", action) << endmsg;
868                 return RefPtr<RadioAction> ();
869         }
870 }
871
872 void
873 Editor::edit_point_chosen (EditPoint ep)
874 {
875         /* this is driven by a toggle on a radio group, and so is invoked twice,
876            once for the item that became inactive and once for the one that became
877            active.
878         */
879
880         RefPtr<RadioAction> ract = edit_point_action (ep);
881
882         if (ract && ract->get_active()) {
883                 set_edit_point (ep);
884         }
885 }
886
887
888 RefPtr<RadioAction>
889 Editor::zoom_focus_action (ZoomFocus focus)
890 {
891         const char* action = 0;
892         RefPtr<Action> act;
893         
894         switch (focus) {
895         case ZoomFocusLeft:
896                 action = X_("zoom-focus-left");
897                 break;
898         case ZoomFocusRight:
899                 action = X_("zoom-focus-right");
900                 break;
901         case ZoomFocusCenter:
902                 action = X_("zoom-focus-center");
903                 break;
904         case ZoomFocusPlayhead:
905                 action = X_("zoom-focus-playhead");
906                 break;
907         case ZoomFocusMouse:
908                 action = X_("zoom-focus-mouse");
909                 break;
910         case ZoomFocusEdit:
911                 action = X_("zoom-focus-edit");
912                 break;
913         default:
914                 fatal << string_compose (_("programming error: %1: %2"), "Editor: impossible focus type", (int) focus) << endmsg;
915                 /*NOTREACHED*/
916         }
917         
918         act = ActionManager::get_action (X_("Zoom"), action);
919         
920         if (act) {
921                 RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
922                 return ract;
923         } else {
924                 error << string_compose (_("programming error: %1: %2"), "Editor::zoom_focus_action could not find action to match focus.", action) << endmsg;
925         }
926
927         return RefPtr<RadioAction> ();
928 }
929
930 void
931 Editor::zoom_focus_chosen (ZoomFocus focus)
932 {
933         /* this is driven by a toggle on a radio group, and so is invoked twice,
934            once for the item that became inactive and once for the one that became
935            active.
936         */
937
938         RefPtr<RadioAction> ract = zoom_focus_action (focus);
939
940         if (ract && ract->get_active()) {
941                 set_zoom_focus (focus);
942         }
943 }
944
945 void
946 Editor::smpte_fps_chosen (SmpteFormat format)
947 {
948         /* this is driven by a toggle on a radio group, and so is invoked twice,
949            once for the item that became inactive and once for the one that became
950            active.
951         */
952
953         if (session) {
954
955                 RefPtr<Action> act;
956
957                 switch (format) {
958                         case smpte_23976: 
959                                 act = ActionManager::get_action (X_("Editor"), X_("Smpte23976"));
960                          break;
961                         case smpte_24: 
962                                 act = ActionManager::get_action (X_("Editor"), X_("Smpte24"));
963                          break;
964                         case smpte_24976: 
965                                 act = ActionManager::get_action (X_("Editor"), X_("Smpte24976"));
966                          break;
967                         case smpte_25: 
968                                 act = ActionManager::get_action (X_("Editor"), X_("Smpte25"));
969                          break;
970                         case smpte_2997: 
971                                 act = ActionManager::get_action (X_("Editor"), X_("Smpte2997"));
972                          break;
973                         case smpte_2997drop: 
974                                 act = ActionManager::get_action (X_("Editor"), X_("Smpte2997drop"));
975                          break;
976                         case smpte_30: 
977                                 act = ActionManager::get_action (X_("Editor"), X_("Smpte30"));
978                          break;
979                         case smpte_30drop: 
980                                 act = ActionManager::get_action (X_("Editor"), X_("Smpte30drop"));
981                          break;
982                         case smpte_5994: 
983                                 act = ActionManager::get_action (X_("Editor"), X_("Smpte5994"));
984                          break;
985                         case smpte_60: 
986                                 act = ActionManager::get_action (X_("Editor"), X_("Smpte60"));
987                          break;
988                         default:
989                                 cerr << "Editor received unexpected smpte type" << endl;
990                 }
991
992                 if (act) {
993                         RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
994                         if (ract && ract->get_active()) {
995                                 session->set_smpte_format (format);
996                         }
997                 }
998         }
999 }
1000
1001 void
1002 Editor::video_pullup_chosen (Session::PullupFormat pullup)
1003 {
1004         /* this is driven by a toggle on a radio group, and so is invoked twice,
1005            once for the item that became inactive and once for the one that became
1006            active.
1007         */
1008
1009         const char* action = 0;
1010
1011         RefPtr<Action> act;
1012         
1013         float pull = 0.0;
1014         
1015         switch (pullup) {
1016         case Session::pullup_Plus4Plus1:
1017                 pull = 4.1667 + 0.1;
1018                 action = X_("PullupPlus4Plus1");
1019                 break;
1020         case Session::pullup_Plus4:
1021                 pull = 4.1667;
1022                 action = X_("PullupPlus4");
1023                 break;
1024         case Session::pullup_Plus4Minus1:
1025                 pull = 4.1667 - 0.1;
1026                 action = X_("PullupPlus4Minus1");
1027                 break;
1028         case Session::pullup_Plus1:
1029                 pull = 0.1;
1030                 action = X_("PullupPlus1");
1031                 break;
1032         case Session::pullup_None:
1033                 pull = 0.0;
1034                 action = X_("PullupNone");
1035                 break;
1036         case Session::pullup_Minus1:
1037                 pull = -0.1;
1038                 action = X_("PullupMinus1");
1039                 break;
1040         case Session::pullup_Minus4Plus1:
1041                 pull = -4.1667 + 0.1;
1042                 action = X_("PullupMinus4Plus1");
1043                 break;
1044         case Session::pullup_Minus4:
1045                 pull = -4.1667;
1046                 action = X_("PullupMinus4");
1047                 break;
1048         case Session::pullup_Minus4Minus1:
1049                 pull = -4.1667 - 0.1;
1050                 action = X_("PullupMinus4Minus1");
1051                 break;
1052         default:
1053                 fatal << string_compose (_("programming error: %1"), "Session received unexpected pullup type") << endmsg;
1054                 /*NOTREACHED*/
1055         }
1056         
1057         act = ActionManager::get_action (X_("Editor"), action);
1058         
1059         if (act) {
1060                 RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
1061                 if (ract && ract->get_active()) {
1062                         Config->set_video_pullup ( pull );
1063                 }
1064                 
1065         } else  {
1066                 error << string_compose (_("programming error: %1"), "Editor::video_pullup_chosen could not find action to match pullup.") << endmsg;
1067         }
1068 }
1069
1070 void
1071 Editor::update_subframes_per_frame ()
1072 {
1073         ENSURE_GUI_THREAD (mem_fun(*this, &Editor::update_subframes_per_frame));
1074
1075         RefPtr<Action> act;
1076         const char* action = 0;
1077
1078         uint32_t sfpf = Config->get_subframes_per_frame();
1079
1080         if (sfpf == 80) {
1081                 action = X_("Subframes80");
1082         } else if (sfpf == 100) {
1083                 action = X_("Subframes100");
1084         } else {
1085                 warning << string_compose (_("Configuraton is using unhandled subframes per frame value: %1"), sfpf) << endmsg;
1086                 /*NOTREACHED*/
1087                 return;
1088         }
1089
1090         act = ActionManager::get_action (X_("Editor"), action);
1091
1092         if (act) {
1093                 RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
1094                 if (ract && !ract->get_active()) {
1095                         ract->set_active (true);
1096                 }
1097         }
1098 }
1099
1100 void
1101 Editor::subframes_per_frame_chosen (uint32_t sfpf)
1102 {
1103         /* this is driven by a toggle on a radio group, and so is invoked twice,
1104            once for the item that became inactive and once for the one that became
1105            active.
1106         */
1107
1108         const char* action = 0;
1109
1110         RefPtr<Action> act;
1111         
1112         if (sfpf == 80) {
1113                 action = X_("Subframes80");
1114         } else if (sfpf == 100) {       
1115                 action = X_("Subframes100");
1116         } else {
1117                 fatal << string_compose (_("programming error: %1 %2"), "Session received unexpected subframes per frame value: ", sfpf) << endmsg;
1118                 /*NOTREACHED*/
1119         }
1120         
1121         act = ActionManager::get_action (X_("Editor"), action);
1122         
1123         if (act) {
1124                 RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
1125                 if (ract && ract->get_active()) {
1126                         Config->set_subframes_per_frame ((uint32_t) rint (sfpf));
1127                 }
1128                 
1129         } else  {
1130                 error << string_compose (_("programming error: %1"), "Editor::subframes_per_frame_chosen could not find action to match value.") << endmsg;
1131         }
1132 }
1133
1134 void
1135 Editor::toggle_auto_xfade ()
1136 {
1137         ActionManager::toggle_config_state ("Editor", "toggle-auto-xfades", &Configuration::set_auto_xfade, &Configuration::get_auto_xfade);
1138 }
1139
1140 void
1141 Editor::toggle_xfades_active ()
1142 {
1143         ActionManager::toggle_config_state ("Editor", "toggle-xfades-active", &Configuration::set_xfades_active, &Configuration::get_xfades_active);
1144 }
1145
1146 void
1147 Editor::toggle_xfade_visibility ()
1148 {
1149         ActionManager::toggle_config_state ("Editor", "toggle-xfades-visible", &Configuration::set_xfades_visible, &Configuration::get_xfades_visible);
1150 }
1151
1152 /** A Configuration parameter has changed.
1153  * @param parameter_name Name of the changed parameter.
1154  */
1155 void
1156 Editor::parameter_changed (const char* parameter_name)
1157 {
1158 #define PARAM_IS(x) (!strcmp (parameter_name, (x)))
1159
1160         ENSURE_GUI_THREAD (bind (mem_fun (*this, &Editor::parameter_changed), parameter_name));
1161
1162         if (PARAM_IS ("auto-loop")) {
1163                 update_loop_range_view (true);
1164         } else if (PARAM_IS ("punch-in")) {
1165                 update_punch_range_view (true);
1166         } else if (PARAM_IS ("punch-out")) {
1167                 update_punch_range_view (true);
1168         } else if (PARAM_IS ("layer-model")) {
1169                 update_layering_model ();
1170         } else if (PARAM_IS ("smpte-format")) {
1171                 update_smpte_mode ();
1172                 update_just_smpte ();
1173         } else if (PARAM_IS ("video-pullup")) {
1174                 update_video_pullup ();
1175         } else if (PARAM_IS ("xfades-active")) {
1176                 ActionManager::map_some_state ("Editor", "toggle-xfades-active", &Configuration::get_xfades_active);
1177         } else if (PARAM_IS ("xfades-visible")) {
1178                 ActionManager::map_some_state ("Editor", "toggle-xfades-visible", &Configuration::get_xfades_visible);
1179                 update_xfade_visibility ();
1180         } else if (PARAM_IS ("auto-xfade")) {
1181                 ActionManager::map_some_state ("Editor", "toggle-auto-xfades", &Configuration::get_auto_xfade);
1182         } else if (PARAM_IS ("xfade-model")) {
1183                 update_crossfade_model ();
1184         } else if (PARAM_IS ("edit-mode")) {
1185                 edit_mode_selector.set_active_text (edit_mode_to_string (Config->get_edit_mode()));
1186         } else if (PARAM_IS ("subframes-per-frame")) {
1187                 update_subframes_per_frame ();
1188                 update_just_smpte ();
1189         }
1190
1191 #undef PARAM_IS
1192 }
1193
1194 void
1195 Editor::reset_focus ()
1196 {
1197         track_canvas.grab_focus();
1198 }