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