1 /*
2  * Copyright (C) 2005-2019 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2006-2007 Doug McLain <doug@nostar.net>
4  * Copyright (C) 2006-2007 Sampo Savolainen <v2@iki.fi>
5  * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
6  * Copyright (C) 2007-2014 David Robillard <d@drobilla.net>
7  * Copyright (C) 2012-2017 Tim Mayberry <mojofunk@gmail.com>
8  * Copyright (C) 2013-2015 Colin Fletcher <colin.m.fletcher@googlemail.com>
9  * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
10  * Copyright (C) 2014-2016 Nick Mainsbridge <mainsbridge@gmail.com>
11  * Copyright (C) 2014-2019 Ben Loftis <ben@harrisonconsoles.com>
12  * Copyright (C) 2015 André Nusser <andre.nusser@googlemail.com>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, write to the Free Software Foundation, Inc.,
26  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27  */
28 
29 #include <gio/gio.h>
30 #include <gtk/gtkiconfactory.h>
31 
32 #include "pbd/file_utils.h"
33 
34 #include "gtkmm2ext/bindings.h"
35 #include "gtkmm2ext/utils.h"
36 
37 #include "ardour/filesystem_paths.h"
38 #include "ardour/profile.h"
39 #include "ardour/session.h"
40 #include "ardour/types.h"
41 
42 #include "canvas/canvas.h"
43 #include "canvas/pixbuf.h"
44 
45 #include "LuaBridge/LuaBridge.h"
46 
47 #include "actions.h"
48 #include "ardour_ui.h"
49 #include "editing.h"
50 #include "editor.h"
51 #include "gui_thread.h"
52 #include "luainstance.h"
53 #include "main_clock.h"
54 #include "time_axis_view.h"
55 #include "ui_config.h"
56 #include "utils.h"
57 #include "pbd/i18n.h"
58 #include "audio_time_axis.h"
59 #include "editor_group_tabs.h"
60 #include "editor_routes.h"
61 #include "editor_regions.h"
62 #include "midi_region_view.h"
63 
64 using namespace Gtk;
65 using namespace Glib;
66 using namespace std;
67 using namespace ARDOUR;
68 using namespace ARDOUR_UI_UTILS;
69 using namespace PBD;
70 using namespace Editing;
71 
72 using Gtkmm2ext::Bindings;
73 
74 /* Convenience functions to slightly reduce verbosity below */
75 
76 
77 RefPtr<Action>
register_region_action(RefPtr<ActionGroup> group,RegionActionTarget tgt,char const * name,char const * label,sigc::slot<void> slot)78 Editor::register_region_action (RefPtr<ActionGroup> group, RegionActionTarget tgt, char const * name, char const * label, sigc::slot<void> slot)
79 {
80 	RefPtr<Action> act = ActionManager::register_action (group, name, label, slot);
81 	ActionManager::session_sensitive_actions.push_back (act);
82 	region_action_map.insert (make_pair<string,RegionAction> (name, RegionAction (act,tgt)));
83 	return act;
84 }
85 
86 void
register_toggle_region_action(RefPtr<ActionGroup> group,RegionActionTarget tgt,char const * name,char const * label,sigc::slot<void> slot)87 Editor::register_toggle_region_action (RefPtr<ActionGroup> group, RegionActionTarget tgt, char const * name, char const * label, sigc::slot<void> slot)
88 {
89 	RefPtr<Action> act = ActionManager::register_toggle_action (group, name, label, slot);
90 	ActionManager::session_sensitive_actions.push_back (act);
91 	region_action_map.insert (make_pair<string,RegionAction> (name, RegionAction (act,tgt)));
92 }
93 
94 RefPtr<Action>
reg_sens(RefPtr<ActionGroup> group,char const * name,char const * label,sigc::slot<void> slot)95 Editor::reg_sens (RefPtr<ActionGroup> group, char const * name, char const * label, sigc::slot<void> slot)
96 {
97 	RefPtr<Action> act = ActionManager::register_action (group, name, label, slot);
98 	ActionManager::session_sensitive_actions.push_back (act);
99 	return act;
100 }
101 
102 void
toggle_reg_sens(RefPtr<ActionGroup> group,char const * name,char const * label,sigc::slot<void> slot)103 Editor::toggle_reg_sens (RefPtr<ActionGroup> group, char const * name, char const * label, sigc::slot<void> slot)
104 {
105 	RefPtr<Action> act = ActionManager::register_toggle_action (group, name, label, slot);
106 	ActionManager::session_sensitive_actions.push_back (act);
107 }
108 
109 void
radio_reg_sens(RefPtr<ActionGroup> action_group,RadioAction::Group & radio_group,char const * name,char const * label,sigc::slot<void> slot)110 Editor::radio_reg_sens (RefPtr<ActionGroup> action_group, RadioAction::Group& radio_group, char const * name, char const * label, sigc::slot<void> slot)
111 {
112 	RefPtr<Action> act = ActionManager::register_radio_action (action_group, radio_group, name, label, slot);
113 	ActionManager::session_sensitive_actions.push_back (act);
114 }
115 
116 void
register_actions()117 Editor::register_actions ()
118 {
119 	RefPtr<Action> act;
120 
121 	editor_actions = ActionManager::create_action_group (bindings, X_("Editor"));
122 	editor_menu_actions = ActionManager::create_action_group (bindings, X_("EditorMenu"));
123 
124 	/* non-operative menu items for menu bar */
125 
126 	ActionManager::register_action (editor_menu_actions, X_("AlignMenu"), _("Align"));
127 	ActionManager::register_action (editor_menu_actions, X_("Autoconnect"), _("Autoconnect"));
128 	ActionManager::register_action (editor_menu_actions, X_("AutomationMenu"), _("Automation"));
129 	ActionManager::register_action (editor_menu_actions, X_("Crossfades"), _("Crossfades"));
130 	ActionManager::register_action (editor_menu_actions, X_("Edit"), _("Edit"));
131 	ActionManager::register_action (editor_menu_actions, X_("EditCursorMovementOptions"), _("Move Selected Marker"));
132 	ActionManager::register_action (editor_menu_actions, X_("EditSelectRangeOptions"), _("Select Range Operations"));
133 	ActionManager::register_action (editor_menu_actions, X_("EditSelectRegionOptions"), _("Select Regions"));
134 	ActionManager::register_action (editor_menu_actions, X_("EditPointMenu"), _("Edit Point"));
135 	ActionManager::register_action (editor_menu_actions, X_("FadeMenu"), _("Fade"));
136 	ActionManager::register_action (editor_menu_actions, X_("LatchMenu"), _("Latch"));
137 	ActionManager::register_action (editor_menu_actions, X_("RegionMenu"), _("Region"));
138 	ActionManager::register_action (editor_menu_actions, X_("RegionMenuLayering"), _("Layering"));
139 	ActionManager::register_action (editor_menu_actions, X_("RegionMenuPosition"), _("Position"));
140 	ActionManager::register_action (editor_menu_actions, X_("RegionMenuMarkers"), _("Markers"));
141 	ActionManager::register_action (editor_menu_actions, X_("RegionMenuEdit"), _("Edit"));
142 	ActionManager::register_action (editor_menu_actions, X_("RegionMenuTrim"), _("Trim"));
143 	ActionManager::register_action (editor_menu_actions, X_("RegionMenuGain"), _("Gain"));
144 	ActionManager::register_action (editor_menu_actions, X_("RegionMenuRanges"), _("Ranges"));
145 	ActionManager::register_action (editor_menu_actions, X_("RegionMenuFades"), _("Fades"));
146 	ActionManager::register_action (editor_menu_actions, X_("RegionMenuMIDI"), _("MIDI"));
147 	ActionManager::register_action (editor_menu_actions, X_("RegionMenuDuplicate"), _("Duplicate"));
148 	ActionManager::register_action (editor_menu_actions, X_("Link"), _("Link"));
149 	ActionManager::register_action (editor_menu_actions, X_("ZoomFocusMenu"), _("Zoom Focus"));
150 	ActionManager::register_action (editor_menu_actions, X_("LocateToMarker"), _("Locate to Markers"));
151 	ActionManager::register_action (editor_menu_actions, X_("MarkerMenu"), _("Markers"));
152 	ActionManager::register_action (editor_menu_actions, X_("MeterFalloff"), _("Meter falloff"));
153 	ActionManager::register_action (editor_menu_actions, X_("MeterHold"), _("Meter hold"));
154 	ActionManager::register_action (editor_menu_actions, X_("MIDI"), _("MIDI Options"));
155 	ActionManager::register_action (editor_menu_actions, X_("MiscOptions"), _("Misc Options"));
156 	ActionManager::register_action (editor_menu_actions, X_("Monitoring"), _("Monitoring"));
157 	ActionManager::register_action (editor_menu_actions, X_("MoveActiveMarkMenu"), _("Active Mark"));
158 	ActionManager::register_action (editor_menu_actions, X_("MovePlayHeadMenu"), _("Playhead"));
159 	ActionManager::register_action (editor_menu_actions, X_("PlayMenu"), _("Play"));
160 	ActionManager::register_action (editor_menu_actions, X_("PrimaryClockMenu"), _("Primary Clock"));
161 	ActionManager::register_action (editor_menu_actions, X_("Pullup"), _("Pullup / Pulldown"));
162 	ActionManager::register_action (editor_menu_actions, X_("RegionEditOps"), _("Region operations"));
163 	ActionManager::register_action (editor_menu_actions, X_("RegionGainMenu"), _("Gain"));
164 	ActionManager::register_action (editor_menu_actions, X_("RulerMenu"), _("Rulers"));
165 	ActionManager::register_action (editor_menu_actions, X_("SavedViewMenu"), _("Views"));
166 	ActionManager::register_action (editor_menu_actions, X_("ScrollMenu"), _("Scroll"));
167 	ActionManager::register_action (editor_menu_actions, X_("SecondaryClockMenu"), _("Secondary Clock"));
168 	ActionManager::register_action (editor_menu_actions, X_("Select"), _("Select"));
169 	ActionManager::register_action (editor_menu_actions, X_("SelectMenu"), _("Select"));
170 	ActionManager::register_action (editor_menu_actions, X_("SeparateMenu"), _("Separate"));
171 	ActionManager::register_action (editor_menu_actions, X_("SetLoopMenu"), _("Loop"));
172 	ActionManager::register_action (editor_menu_actions, X_("SetPunchMenu"), _("Punch"));
173 	ActionManager::register_action (editor_menu_actions, X_("Solo"), _("Solo"));
174 	ActionManager::register_action (editor_menu_actions, X_("Subframes"), _("Subframes"));
175 	ActionManager::register_action (editor_menu_actions, X_("SyncMenu"), _("Sync"));
176 	ActionManager::register_action (editor_menu_actions, X_("TempoMenu"), _("Tempo"));
177 	ActionManager::register_action (editor_menu_actions, X_("Timecode"), _("Timecode fps"));
178 
179 	act = ActionManager::register_action (editor_menu_actions, X_("TrackHeightMenu"), _("Height"));
180 	ActionManager::stripable_selection_sensitive_actions.push_back (act);
181 
182 	ActionManager::register_action (editor_menu_actions, X_("TrackMenu"), _("Track"));
183 	ActionManager::register_action (editor_menu_actions, X_("TrackPlaylistMenu"), _("Playlists"));
184 	ActionManager::register_action (editor_menu_actions, X_("Tools"), _("Tools"));
185 	ActionManager::register_action (editor_menu_actions, X_("View"), _("View"));
186 	ActionManager::register_action (editor_menu_actions, X_("ZoomFocus"), _("Zoom Focus"));
187 	ActionManager::register_action (editor_menu_actions, X_("ZoomMenu"), _("Zoom"));
188 	ActionManager::register_action (editor_menu_actions, X_("LuaScripts"), _("Lua Scripts"));
189 
190 	register_region_actions ();
191 
192 	/* add named actions for the editor */
193 
194 	/* We don't bother registering "unlock" because it would be insensitive
195 	   when required. Editor::unlock() must be invoked directly.
196 	*/
197 	ActionManager::register_action (editor_actions, "lock", S_("Session|Lock"), sigc::mem_fun (*this, &Editor::lock));
198 
199 	toggle_reg_sens (editor_actions, "show-editor-mixer", _("Show Editor Mixer"), sigc::mem_fun (*this, &Editor::editor_mixer_button_toggled));
200 	toggle_reg_sens (editor_actions, "show-editor-list", _("Show Editor List"), sigc::mem_fun (*this, &Editor::editor_list_button_toggled));
201 
202 	reg_sens (editor_actions, "playhead-to-next-region-boundary", _("Playhead to Next Region Boundary"), sigc::bind (sigc::mem_fun(*this, &Editor::cursor_to_next_region_boundary), true));
203 	reg_sens (editor_actions, "playhead-to-next-region-boundary-noselection", _("Playhead to Next Region Boundary (No Track Selection)"), sigc::bind (sigc::mem_fun(*this, &Editor::cursor_to_next_region_boundary), false));
204 	reg_sens (editor_actions, "playhead-to-previous-region-boundary", _("Playhead to Previous Region Boundary"), sigc::bind (sigc::mem_fun(*this, &Editor::cursor_to_previous_region_boundary), true));
205 	reg_sens (editor_actions, "playhead-to-previous-region-boundary-noselection", _("Playhead to Previous Region Boundary (No Track Selection)"), sigc::bind (sigc::mem_fun(*this, &Editor::cursor_to_previous_region_boundary), false));
206 
207 	reg_sens (editor_actions, "playhead-to-next-region-start", _("Playhead to Next Region Start"), sigc::bind (sigc::mem_fun(*this, &Editor::cursor_to_next_region_point), _playhead_cursor, RegionPoint (Start)));
208 	reg_sens (editor_actions, "playhead-to-next-region-end", _("Playhead to Next Region End"), sigc::bind (sigc::mem_fun(*this, &Editor::cursor_to_next_region_point), _playhead_cursor, RegionPoint (End)));
209 	reg_sens (editor_actions, "playhead-to-next-region-sync", _("Playhead to Next Region Sync"), sigc::bind (sigc::mem_fun(*this, &Editor::cursor_to_next_region_point), _playhead_cursor, RegionPoint (SyncPoint)));
210 
211 	reg_sens (editor_actions, "playhead-to-previous-region-start", _("Playhead to Previous Region Start"), sigc::bind (sigc::mem_fun(*this, &Editor::cursor_to_previous_region_point), _playhead_cursor, RegionPoint (Start)));
212 	reg_sens (editor_actions, "playhead-to-previous-region-end", _("Playhead to Previous Region End"), sigc::bind (sigc::mem_fun(*this, &Editor::cursor_to_previous_region_point), _playhead_cursor, RegionPoint (End)));
213 	reg_sens (editor_actions, "playhead-to-previous-region-sync", _("Playhead to Previous Region Sync"), sigc::bind (sigc::mem_fun(*this, &Editor::cursor_to_previous_region_point), _playhead_cursor, RegionPoint (SyncPoint)));
214 
215 	reg_sens (editor_actions, "selected-marker-to-next-region-boundary", _("To Next Region Boundary"), sigc::bind (sigc::mem_fun(*this, &Editor::selected_marker_to_next_region_boundary), true));
216 	reg_sens (editor_actions, "selected-marker-to-next-region-boundary-noselection", _("To Next Region Boundary (No Track Selection)"), sigc::bind (sigc::mem_fun(*this, &Editor::selected_marker_to_next_region_boundary), false));
217 	reg_sens (editor_actions, "selected-marker-to-previous-region-boundary", _("To Previous Region Boundary"), sigc::bind (sigc::mem_fun(*this, &Editor::selected_marker_to_previous_region_boundary), true));
218 	reg_sens (editor_actions, "selected-marker-to-previous-region-boundary-noselection", _("To Previous Region Boundary (No Track Selection)"), sigc::bind (sigc::mem_fun(*this, &Editor::selected_marker_to_previous_region_boundary), false));
219 
220 	reg_sens (editor_actions, "edit-cursor-to-next-region-start", _("To Next Region Start"), sigc::bind (sigc::mem_fun(*this, &Editor::selected_marker_to_next_region_point), RegionPoint (Start)));
221 	reg_sens (editor_actions, "edit-cursor-to-next-region-end", _("To Next Region End"), sigc::bind (sigc::mem_fun(*this, &Editor::selected_marker_to_next_region_point), RegionPoint (End)));
222 	reg_sens (editor_actions, "edit-cursor-to-next-region-sync", _("To Next Region Sync"), sigc::bind (sigc::mem_fun(*this, &Editor::selected_marker_to_next_region_point), RegionPoint (SyncPoint)));
223 
224 	reg_sens (editor_actions, "edit-cursor-to-previous-region-start", _("To Previous Region Start"), sigc::bind (sigc::mem_fun(*this, &Editor::selected_marker_to_previous_region_point), RegionPoint (Start)));
225 	reg_sens (editor_actions, "edit-cursor-to-previous-region-end", _("To Previous Region End"), sigc::bind (sigc::mem_fun(*this, &Editor::selected_marker_to_previous_region_point), RegionPoint (End)));
226 	reg_sens (editor_actions, "edit-cursor-to-previous-region-sync", _("To Previous Region Sync"), sigc::bind (sigc::mem_fun(*this, &Editor::selected_marker_to_previous_region_point), RegionPoint (SyncPoint)));
227 
228 	reg_sens (editor_actions, "edit-cursor-to-range-start", _("To Range Start"), sigc::mem_fun(*this, &Editor::selected_marker_to_selection_start));
229 	reg_sens (editor_actions, "edit-cursor-to-range-end", _("To Range End"), sigc::mem_fun(*this, &Editor::selected_marker_to_selection_end));
230 
231 	reg_sens (editor_actions, "playhead-to-range-start", _("Playhead to Range Start"), sigc::bind (sigc::mem_fun(*this, &Editor::cursor_to_selection_start), _playhead_cursor));
232 	reg_sens (editor_actions, "playhead-to-range-end", _("Playhead to Range End"), sigc::bind (sigc::mem_fun(*this, &Editor::cursor_to_selection_end), _playhead_cursor));
233 
234 	reg_sens (editor_actions, "select-all-objects", _("Select All Objects"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_objects), Selection::Set));
235 
236 	reg_sens (editor_actions, "select-loop-range", _("Set Range to Loop Range"), sigc::mem_fun(*this, &Editor::set_selection_from_loop));
237 	reg_sens (editor_actions, "select-punch-range", _("Set Range to Punch Range"), sigc::mem_fun(*this, &Editor::set_selection_from_punch));
238 	reg_sens (editor_actions, "select-from-regions", _("Set Range to Selected Regions"), sigc::mem_fun(*this, &Editor::set_selection_from_region));
239 
240 	reg_sens (editor_actions, "edit-current-tempo", _("Edit Current Tempo"), sigc::mem_fun(*this, &Editor::edit_current_tempo));
241 	reg_sens (editor_actions, "edit-current-meter", _("Edit Current Meter"), sigc::mem_fun(*this, &Editor::edit_current_meter));
242 
243 	reg_sens (editor_actions, "select-all-after-edit-cursor", _("Select All After Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true, false));
244 	reg_sens (editor_actions, "alternate-select-all-after-edit-cursor", _("Select All After Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true, false));
245 	reg_sens (editor_actions, "select-all-before-edit-cursor", _("Select All Before Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false, false));
246 	reg_sens (editor_actions, "alternate-select-all-before-edit-cursor", _("Select All Before Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false, false));
247 
248 	reg_sens (editor_actions, "select-all-between-cursors", _("Select All Overlapping Edit Range"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), false));
249 	reg_sens (editor_actions, "select-all-within-cursors", _("Select All Inside Edit Range"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), true));
250 
251 	reg_sens (editor_actions, "select-range-between-cursors", _("Select Edit Range"), sigc::mem_fun(*this, &Editor::select_range_between));
252 
253 	reg_sens (editor_actions, "select-all-in-punch-range", _("Select All in Punch Range"), sigc::mem_fun(*this, &Editor::select_all_selectables_using_punch));
254 	reg_sens (editor_actions, "select-all-in-loop-range", _("Select All in Loop Range"), sigc::mem_fun(*this, &Editor::select_all_selectables_using_loop));
255 
256 	reg_sens (editor_actions, "select-next-route", _("Select Next Track or Bus"), sigc::bind (sigc::mem_fun(*this, &Editor::select_next_stripable), true));
257 	reg_sens (editor_actions, "select-prev-route", _("Select Previous Track or Bus"), sigc::bind (sigc::mem_fun(*this, &Editor::select_prev_stripable), true));
258 
259 	reg_sens (editor_actions, "select-next-stripable", _("Select Next Strip"), sigc::bind (sigc::mem_fun(*this, &Editor::select_next_stripable), false));
260 	reg_sens (editor_actions, "select-prev-stripable", _("Select Previous Strip"), sigc::bind (sigc::mem_fun(*this, &Editor::select_prev_stripable), false));
261 
262 	reg_sens (editor_actions, "toggle-all-existing-automation", _("Toggle All Existing Automation"), sigc::mem_fun (*this, &Editor::toggle_all_existing_automation));
263 	reg_sens (editor_actions, "toggle-layer-display", _("Toggle Layer Display"), sigc::mem_fun (*this, &Editor::toggle_layer_display));
264 
265 	/* these "overlap" with Region/nudge-* and also Common/nudge-* but
266 	 * provide a single editor-related action that will nudge a region,
267 	 * selected marker or playhead
268 	 */
269 
270 	reg_sens (editor_actions, "nudge-forward", _("Nudge Later"), sigc::bind (sigc::mem_fun (*this, &Editor::nudge_forward), false, false));
271 	reg_sens (editor_actions, "alternate-nudge-forward", _("Nudge Later"), sigc::bind (sigc::mem_fun (*this, &Editor::nudge_forward), false, false));
272 	reg_sens (editor_actions, "nudge-backward", _("Nudge Earlier"), sigc::bind (sigc::mem_fun (*this, &Editor::nudge_backward), false, false));
273 	reg_sens (editor_actions, "alternate-nudge-backward", _("Nudge Earlier"), sigc::bind (sigc::mem_fun (*this, &Editor::nudge_backward), false, false));
274 
275 	act = reg_sens (editor_actions, "track-record-enable-toggle", _("Toggle Record Enable"), sigc::mem_fun(*this, &Editor::toggle_record_enable));
276 	ActionManager::track_selection_sensitive_actions.push_back (act);
277 	act = reg_sens (editor_actions, "track-solo-toggle", _("Toggle Solo"), sigc::mem_fun(*this, &Editor::toggle_solo));
278 	ActionManager::stripable_selection_sensitive_actions.push_back (act);
279 	act = reg_sens (editor_actions, "track-mute-toggle", _("Toggle Mute"), sigc::mem_fun(*this, &Editor::toggle_mute));
280 	ActionManager::stripable_selection_sensitive_actions.push_back (act);
281 	act = reg_sens (editor_actions, "track-solo-isolate-toggle", _("Toggle Solo Isolate"), sigc::mem_fun(*this, &Editor::toggle_solo_isolate));
282 	ActionManager::stripable_selection_sensitive_actions.push_back (act);
283 
284 	for (int i = 1; i <= 12; ++i) {
285 		string const a = string_compose (X_("save-visual-state-%1"), i);
286 		string const n = string_compose (_("Save View %1"), i);
287 		reg_sens (editor_actions, a.c_str(), n.c_str(), sigc::bind (sigc::mem_fun (*this, &Editor::start_visual_state_op), i - 1));
288 	}
289 
290 	for (int i = 1; i <= 12; ++i) {
291 		string const a = string_compose (X_("goto-visual-state-%1"), i);
292 		string const n = string_compose (_("Go to View %1"), i);
293 		reg_sens (editor_actions, a.c_str(), n.c_str(), sigc::bind (sigc::mem_fun (*this, &Editor::cancel_visual_state_op), i - 1));
294 	}
295 
296 	reg_sens (editor_actions, "temporal-zoom-out", _("Zoom Out"), sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), true));
297 	reg_sens (editor_actions, "temporal-zoom-in", _("Zoom In"), sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_step), false));
298 	reg_sens (editor_actions, "zoom-to-session", _("Zoom to Session"), sigc::mem_fun(*this, &Editor::temporal_zoom_session));
299 	reg_sens (editor_actions, "zoom-to-extents", _("Zoom to Extents"), sigc::mem_fun(*this, &Editor::temporal_zoom_extents));
300 	reg_sens (editor_actions, "zoom-to-selection", _("Zoom to Selection"), sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_selection), Both));
301 	reg_sens (editor_actions, "zoom-to-selection-horiz", _("Zoom to Selection (Horizontal)"), sigc::bind (sigc::mem_fun(*this, &Editor::temporal_zoom_selection), Horizontal));
302 	reg_sens (editor_actions, "toggle-zoom", _("Toggle Zoom State"), sigc::mem_fun(*this, &Editor::swap_visual_state));
303 
304 	reg_sens (editor_actions, "expand-tracks", _("Expand Track Height"), sigc::bind (sigc::mem_fun (*this, &Editor::tav_zoom_step), false));
305 	reg_sens (editor_actions, "shrink-tracks", _("Shrink Track Height"), sigc::bind (sigc::mem_fun (*this, &Editor::tav_zoom_step), true));
306 
307 	reg_sens (editor_actions, "fit_1_track", _("Fit 1 Track"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 1));
308 	reg_sens (editor_actions, "fit_2_tracks", _("Fit 2 Tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 2));
309 	reg_sens (editor_actions, "fit_4_tracks", _("Fit 4 Tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 4));
310 	reg_sens (editor_actions, "fit_8_tracks", _("Fit 8 Tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 8));
311 	reg_sens (editor_actions, "fit_16_tracks", _("Fit 16 Tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 16));
312 	reg_sens (editor_actions, "fit_32_tracks", _("Fit 32 Tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 32));
313 	reg_sens (editor_actions, "fit_all_tracks", _("Fit All Tracks"), sigc::bind (sigc::mem_fun(*this, &Editor::set_visible_track_count), 0));
314 
315 	reg_sens (editor_actions, "zoom_10_ms", _("Zoom to 10 ms"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 10));
316 	reg_sens (editor_actions, "zoom_100_ms", _("Zoom to 100 ms"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 100));
317 	reg_sens (editor_actions, "zoom_1_sec", _("Zoom to 1 sec"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 1000));
318 	reg_sens (editor_actions, "zoom_10_sec", _("Zoom to 10 sec"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 10 * 1000));
319 	reg_sens (editor_actions, "zoom_1_min", _("Zoom to 1 min"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 60 * 1000));
320 	reg_sens (editor_actions, "zoom_5_min", _("Zoom to 5 min"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 5 * 60 * 1000));
321 	reg_sens (editor_actions, "zoom_10_min", _("Zoom to 10 min"), sigc::bind (sigc::mem_fun(*this, &Editor::set_zoom_preset), 10 * 60 * 1000));
322 
323 	act = reg_sens (editor_actions, "move-selected-tracks-up", _("Move Selected Tracks Up"), sigc::bind (sigc::mem_fun(*_routes, &EditorRoutes::move_selected_tracks), true));
324 	ActionManager::stripable_selection_sensitive_actions.push_back (act);
325 	act = reg_sens (editor_actions, "move-selected-tracks-down", _("Move Selected Tracks Down"), sigc::bind (sigc::mem_fun(*_routes, &EditorRoutes::move_selected_tracks), false));
326 	ActionManager::stripable_selection_sensitive_actions.push_back (act);
327 
328 	act = reg_sens (editor_actions, "scroll-tracks-up", _("Scroll Tracks Up"), sigc::mem_fun(*this, &Editor::scroll_tracks_up));
329 	act = reg_sens (editor_actions, "scroll-tracks-down", _("Scroll Tracks Down"), sigc::mem_fun(*this, &Editor::scroll_tracks_down));
330 	act = reg_sens (editor_actions, "step-tracks-up", _("Step Tracks Up"), sigc::hide_return (sigc::bind (sigc::mem_fun(*this, &Editor::scroll_up_one_track), true)));
331 	act = reg_sens (editor_actions, "step-tracks-down", _("Step Tracks Down"), sigc::hide_return (sigc::bind (sigc::mem_fun(*this, &Editor::scroll_down_one_track), true)));
332 	act = reg_sens (editor_actions, "select-topmost", _("Select Topmost Track"), (sigc::mem_fun(*this, &Editor::select_topmost_track)));
333 
334 	reg_sens (editor_actions, "scroll-backward", _("Scroll Backward"), sigc::bind (sigc::mem_fun(*this, &Editor::scroll_backward), 0.8f));
335 	reg_sens (editor_actions, "scroll-forward", _("Scroll Forward"), sigc::bind (sigc::mem_fun(*this, &Editor::scroll_forward), 0.8f));
336 	reg_sens (editor_actions, "center-playhead", _("Center Playhead"), sigc::mem_fun(*this, &Editor::center_playhead));
337 	reg_sens (editor_actions, "center-edit-cursor", _("Center Edit Point"), sigc::mem_fun(*this, &Editor::center_edit_point));
338 
339 	reg_sens (editor_actions, "scroll-playhead-forward", _("Playhead Forward"), sigc::bind (sigc::mem_fun(*this, &Editor::scroll_playhead), true));;
340 	reg_sens (editor_actions, "scroll-playhead-backward", _("Playhead Backward"), sigc::bind (sigc::mem_fun(*this, &Editor::scroll_playhead), false));
341 
342 	reg_sens (editor_actions, "playhead-to-edit", _("Playhead to Active Mark"), sigc::bind (sigc::mem_fun(*this, &Editor::cursor_align), true));
343 	reg_sens (editor_actions, "edit-to-playhead", _("Active Mark to Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::cursor_align), false));
344 
345 	toggle_reg_sens (editor_actions, "toggle-skip-playback", _("Use Skip Ranges"), sigc::mem_fun(*this, &Editor::toggle_skip_playback));
346 
347 	reg_sens (editor_actions, "set-loop-from-edit-range", _("Set Loop from Selection"), sigc::bind (sigc::mem_fun(*this, &Editor::set_loop_from_selection), false));
348 	reg_sens (editor_actions, "set-punch-from-edit-range", _("Set Punch from Selection"), sigc::mem_fun(*this, &Editor::set_punch_from_selection));
349 	reg_sens (editor_actions, "set-session-from-edit-range", _("Set Session Start/End from Selection"), sigc::mem_fun(*this, &Editor::set_session_extents_from_selection));
350 
351 	/* this is a duplicated action so that the main menu can use a different label */
352 	reg_sens (editor_actions, "main-menu-play-selected-regions", _("Play Selected Regions"), sigc::mem_fun (*this, &Editor::play_selected_region));
353 	reg_sens (editor_actions, "main-menu-tag-selected-regions", _("Tag Selected Regions"), sigc::mem_fun (*this, &Editor::tag_selected_region));
354 
355 	reg_sens (editor_actions, "play-from-edit-point", _("Play from Edit Point"), sigc::mem_fun(*this, &Editor::play_from_edit_point));
356 	reg_sens (editor_actions, "play-from-edit-point-and-return", _("Play from Edit Point and Return"), sigc::mem_fun(*this, &Editor::play_from_edit_point_and_return));
357 
358 	reg_sens (editor_actions, "play-edit-range", _("Play Edit Range"), sigc::mem_fun(*this, &Editor::play_edit_range));
359 
360 	reg_sens (editor_actions, "set-playhead", _("Playhead to Mouse"), sigc::mem_fun(*this, &Editor::set_playhead_cursor));
361 	reg_sens (editor_actions, "set-edit-point", _("Active Marker to Mouse"), sigc::mem_fun(*this, &Editor::set_edit_point));
362 	reg_sens (editor_actions, "set-auto-punch-range", _("Set Auto Punch In/Out from Playhead"), sigc::mem_fun(*this, &Editor::set_auto_punch_range));
363 
364 	reg_sens (editor_actions, "duplicate", _("Duplicate"), sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_range), false));
365 
366 	/* Open the dialogue to duplicate selected regions multiple times */
367 	reg_sens (editor_actions, "multi-duplicate", _("Multi-Duplicate..."),
368 	          sigc::bind (sigc::mem_fun (*this, &Editor::duplicate_range), true));
369 
370 	undo_action = reg_sens (editor_actions, "undo", S_("Command|Undo"), sigc::bind (sigc::mem_fun(*this, &Editor::undo), 1U));
371 
372 	redo_action = reg_sens (editor_actions, "redo", _("Redo"), sigc::bind (sigc::mem_fun(*this, &Editor::redo), 1U));
373 	alternate_redo_action = reg_sens (editor_actions, "alternate-redo", _("Redo"), sigc::bind (sigc::mem_fun(*this, &Editor::redo), 1U));
374 	alternate_alternate_redo_action = reg_sens (editor_actions, "alternate-alternate-redo", _("Redo"), sigc::bind (sigc::mem_fun(*this, &Editor::redo), 1U));
375 
376 	selection_undo_action = reg_sens (editor_actions, "undo-last-selection-op", _("Undo Selection Change"), sigc::mem_fun(*this, &Editor::undo_selection_op));
377 	selection_redo_action = reg_sens (editor_actions, "redo-last-selection-op", _("Redo Selection Change"), sigc::mem_fun(*this, &Editor::redo_selection_op));
378 
379 	reg_sens (editor_actions, "export-audio", _("Export Audio"), sigc::mem_fun(*this, &Editor::export_audio));
380 	reg_sens (editor_actions, "export-range", _("Export Range"), sigc::mem_fun(*this, &Editor::export_range));
381 
382 	act = reg_sens (editor_actions, "editor-separate", _("Separate"), sigc::mem_fun(*this, &Editor::separate_region_from_selection));
383 	ActionManager::mouse_edit_point_requires_canvas_actions.push_back (act);
384 
385 	act = reg_sens (editor_actions, "separate-from-punch", _("Separate Using Punch Range"), sigc::mem_fun(*this, &Editor::separate_region_from_punch));
386 	act = reg_sens (editor_actions, "separate-from-loop", _("Separate Using Loop Range"), sigc::mem_fun(*this, &Editor::separate_region_from_loop));
387 
388 	act = reg_sens (editor_actions, "editor-crop", _("Crop"), sigc::mem_fun(*this, &Editor::crop_region_to_selection));
389 	ActionManager::time_selection_sensitive_actions.push_back (act);
390 
391 	reg_sens (editor_actions, "editor-cut", _("Cut"), sigc::mem_fun(*this, &Editor::cut));
392 	reg_sens (editor_actions, "editor-delete", _("Delete"), sigc::mem_fun(*this, &Editor::delete_));
393 	reg_sens (editor_actions, "alternate-editor-delete", _("Delete"), sigc::mem_fun(*this, &Editor::delete_));
394 
395 	reg_sens (editor_actions, "split-region", _("Split/Separate"), sigc::mem_fun (*this, &Editor::split_region));
396 
397 	reg_sens (editor_actions, "editor-copy", _("Copy"), sigc::mem_fun(*this, &Editor::copy));
398 	reg_sens (editor_actions, "editor-paste", _("Paste"), sigc::mem_fun(*this, &Editor::keyboard_paste));
399 
400 	reg_sens (editor_actions, "editor-fade-range", _("Fade Range Selection"), sigc::mem_fun(*this, &Editor::fade_range));
401 
402 	act = ActionManager::register_action (editor_actions, "set-tempo-from-edit-range", _("Set Tempo from Edit Range = Bar"), sigc::mem_fun(*this, &Editor::use_range_as_bar));
403 	ActionManager::time_selection_sensitive_actions.push_back (act);
404 
405 	toggle_reg_sens (editor_actions, "toggle-log-window", _("Log"),
406 			sigc::mem_fun (ARDOUR_UI::instance(), &ARDOUR_UI::toggle_errors));
407 
408 	reg_sens (editor_actions, "alternate-tab-to-transient-forwards", _("Move to Next Transient"), sigc::bind (sigc::mem_fun(*this, &Editor::tab_to_transient), true));
409 	reg_sens (editor_actions, "alternate-tab-to-transient-backwards", _("Move to Previous Transient"), sigc::bind (sigc::mem_fun(*this, &Editor::tab_to_transient), false));
410 	reg_sens (editor_actions, "tab-to-transient-forwards", _("Move to Next Transient"), sigc::bind (sigc::mem_fun(*this, &Editor::tab_to_transient), true));
411 	reg_sens (editor_actions, "tab-to-transient-backwards", _("Move to Previous Transient"), sigc::bind (sigc::mem_fun(*this, &Editor::tab_to_transient), false));
412 
413 	reg_sens (editor_actions, "crop", _("Crop"), sigc::mem_fun(*this, &Editor::crop_region_to_selection));
414 
415 //	reg_sens (editor_actions, "finish-add-range", _("Finish Add Range"), sigc::bind (sigc::mem_fun(*this, &Editor::keyboard_selection_finish), true));
416 
417 	reg_sens (
418 		editor_actions,
419 		"move-range-start-to-previous-region-boundary",
420 		_("Move Range Start to Previous Region Boundary"),
421 		sigc::bind (sigc::mem_fun (*this, &Editor::move_range_selection_start_or_end_to_region_boundary), false, false)
422 		);
423 
424 	reg_sens (
425 		editor_actions,
426 		"move-range-start-to-next-region-boundary",
427 		_("Move Range Start to Next Region Boundary"),
428 		sigc::bind (sigc::mem_fun (*this, &Editor::move_range_selection_start_or_end_to_region_boundary), false, true)
429 		);
430 
431 	reg_sens (
432 		editor_actions,
433 		"move-range-end-to-previous-region-boundary",
434 		_("Move Range End to Previous Region Boundary"),
435 		sigc::bind (sigc::mem_fun (*this, &Editor::move_range_selection_start_or_end_to_region_boundary), true, false)
436 		);
437 
438 	reg_sens (
439 		editor_actions,
440 		"move-range-end-to-next-region-boundary",
441 		_("Move Range End to Next Region Boundary"),
442 		sigc::bind (sigc::mem_fun (*this, &Editor::move_range_selection_start_or_end_to_region_boundary), true, true)
443 		);
444 
445 	toggle_reg_sens (editor_actions, "toggle-follow-playhead", _("Follow Playhead"), (sigc::mem_fun(*this, &Editor::toggle_follow_playhead)));
446 	act = reg_sens (editor_actions, "remove-last-capture", _("Remove Last Capture"), (sigc::mem_fun(*this, &Editor::remove_last_capture)));
447 	act = reg_sens (editor_actions, "tag-last-capture", _("Tag Last Capture"), (sigc::mem_fun(*this, &Editor::tag_last_capture)));
448 
449 	ActionManager::register_toggle_action (editor_actions, "toggle-stationary-playhead", _("Stationary Playhead"), (mem_fun(*this, &Editor::toggle_stationary_playhead)));
450 
451 	ActionManager::register_toggle_action (editor_actions, "show-touched-automation", _("Show Automation Lane on Touch"), (mem_fun(*this, &Editor::toggle_show_touched_automation)));
452 
453 	act = reg_sens (editor_actions, "insert-time", _("Insert Time"), (sigc::mem_fun(*this, &Editor::do_insert_time)));
454 	ActionManager::track_selection_sensitive_actions.push_back (act);
455 	act = ActionManager::register_action (editor_actions, "remove-time", _("Remove Time"), (mem_fun(*this, &Editor::do_remove_time)));
456 	ActionManager::session_sensitive_actions.push_back (act);
457 	ActionManager::track_selection_sensitive_actions.push_back (act);
458 
459 	act = reg_sens (editor_actions, "remove-gaps", _("Remove Gaps"), (sigc::mem_fun(*this, &Editor::do_remove_gaps)));
460 	ActionManager::track_selection_sensitive_actions.push_back (act);
461 	ActionManager::session_sensitive_actions.push_back (act);
462 
463 	/*global playlist actions */
464 	ActionManager::register_action (editor_actions, "new-playlists-for-armed-tracks", _("New Playlist For Rec-Armed Tracks"), sigc::bind (sigc::mem_fun (*this, &Editor::new_playlists_for_armed_tracks), false));
465 	ActionManager::register_action (editor_actions, "new-playlists-for-all-tracks", _("New Playlist For All Tracks"), sigc::bind (sigc::mem_fun (*this, &Editor::new_playlists_for_all_tracks), false));
466 	act = ActionManager::register_action (editor_actions, "new-playlists-for-selected-tracks", _("New Playlist For Selected Tracks"), sigc::bind (sigc::mem_fun (*this, &Editor::new_playlists_for_selected_tracks), false));
467 	ActionManager::stripable_selection_sensitive_actions.push_back (act);
468 
469 	ActionManager::register_action (editor_actions, "copy-playlists-for-armed-tracks", _("Copy Playlist For Rec-Armed Tracks"), sigc::bind (sigc::mem_fun (*this, &Editor::new_playlists_for_armed_tracks), true));
470 	ActionManager::register_action (editor_actions, "copy-playlists-for-all-tracks", _("Copy Playlist For All Tracks"), sigc::bind (sigc::mem_fun (*this, &Editor::new_playlists_for_all_tracks), true));
471 	act = ActionManager::register_action (editor_actions, "copy-playlists-for-selected-tracks", _("Copy Playlist For Selected Tracks"), sigc::bind (sigc::mem_fun (*this, &Editor::new_playlists_for_selected_tracks), true));
472 	ActionManager::stripable_selection_sensitive_actions.push_back (act);
473 
474 	act = reg_sens (editor_actions, "toggle-track-active", _("Toggle Active"), (sigc::mem_fun(*this, &Editor::toggle_tracks_active)));
475 	ActionManager::route_selection_sensitive_actions.push_back (act);
476 	act = reg_sens (editor_actions, "remove-track", _("Remove"), (sigc::mem_fun(*this, &Editor::remove_tracks)));
477 	ActionManager::stripable_selection_sensitive_actions.push_back (act);
478 
479 	act = reg_sens (editor_actions, "fit-selection", _("Fit Selection (Vertical)"), sigc::mem_fun(*this, &Editor::fit_selection));
480 	ActionManager::stripable_selection_sensitive_actions.push_back (act);
481 
482 	act = reg_sens (editor_actions, "track-height-largest", _("Largest"), sigc::bind (
483 				sigc::mem_fun(*this, &Editor::set_track_height), HeightLargest));
484 	ActionManager::stripable_selection_sensitive_actions.push_back (act);
485 	act = reg_sens (editor_actions, "track-height-larger", _("Larger"), sigc::bind (
486 				sigc::mem_fun(*this, &Editor::set_track_height), HeightLarger));
487 	ActionManager::stripable_selection_sensitive_actions.push_back (act);
488 	act = reg_sens (editor_actions, "track-height-large", _("Large"), sigc::bind (
489 				sigc::mem_fun(*this, &Editor::set_track_height), HeightLarge));
490 	ActionManager::stripable_selection_sensitive_actions.push_back (act);
491 	act = reg_sens (editor_actions, "track-height-normal", _("Normal"), sigc::bind (
492 				sigc::mem_fun(*this, &Editor::set_track_height), HeightNormal));
493 	ActionManager::stripable_selection_sensitive_actions.push_back (act);
494 	act = reg_sens (editor_actions, "track-height-small", _("Small"), sigc::bind (
495 				sigc::mem_fun(*this, &Editor::set_track_height), HeightSmall));
496 	ActionManager::stripable_selection_sensitive_actions.push_back (act);
497 
498 	toggle_reg_sens (editor_actions, "sound-midi-notes", _("Sound Selected MIDI Notes"), sigc::mem_fun (*this, &Editor::toggle_sound_midi_notes));
499 
500 	Glib::RefPtr<ActionGroup> zoom_actions = ActionManager::create_action_group (bindings, X_("Zoom"));
501 	RadioAction::Group zoom_group;
502 
503 	radio_reg_sens (zoom_actions, zoom_group, "zoom-focus-left", _("Zoom Focus Left"), sigc::bind (sigc::mem_fun(*this, &Editor::zoom_focus_chosen), Editing::ZoomFocusLeft));
504 	radio_reg_sens (zoom_actions, zoom_group, "zoom-focus-right", _("Zoom Focus Right"), sigc::bind (sigc::mem_fun(*this, &Editor::zoom_focus_chosen), Editing::ZoomFocusRight));
505 	radio_reg_sens (zoom_actions, zoom_group, "zoom-focus-center", _("Zoom Focus Center"), sigc::bind (sigc::mem_fun(*this, &Editor::zoom_focus_chosen), Editing::ZoomFocusCenter));
506 	radio_reg_sens (zoom_actions, zoom_group, "zoom-focus-playhead", _("Zoom Focus Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::zoom_focus_chosen), Editing::ZoomFocusPlayhead));
507 	radio_reg_sens (zoom_actions, zoom_group, "zoom-focus-mouse", _("Zoom Focus Mouse"), sigc::bind (sigc::mem_fun(*this, &Editor::zoom_focus_chosen), Editing::ZoomFocusMouse));
508 	radio_reg_sens (zoom_actions, zoom_group, "zoom-focus-edit", _("Zoom Focus Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::zoom_focus_chosen), Editing::ZoomFocusEdit));
509 
510 	ActionManager::register_action (editor_actions, X_("cycle-zoom-focus"), _("Next Zoom Focus"), sigc::mem_fun (*this, &Editor::cycle_zoom_focus));
511 
512 	Glib::RefPtr<ActionGroup> lua_script_actions = ActionManager::create_action_group (bindings, X_("LuaAction"));
513 
514 	for (int i = 1; i <= MAX_LUA_ACTION_SCRIPTS; ++i) {
515 		string const a = string_compose (X_("script-%1"), i);
516 		string const n = string_compose (_("Unset #%1"), i);
517 		act = ActionManager::register_action (lua_script_actions, a.c_str(), n.c_str(), sigc::bind (sigc::mem_fun (*this, &Editor::trigger_script), i - 1));
518 		act->set_tooltip (_("No action bound\nRight-click to assign"));
519 		act->set_sensitive (false);
520 	}
521 
522 	Glib::RefPtr<ActionGroup> mouse_mode_actions = ActionManager::create_action_group (bindings, X_("MouseMode"));
523 	RadioAction::Group mouse_mode_group;
524 
525 	act = ActionManager::register_toggle_action (mouse_mode_actions, "set-mouse-mode-object-range", _("Smart Mode"), sigc::mem_fun (*this, &Editor::mouse_mode_object_range_toggled));
526 	smart_mode_action = Glib::RefPtr<ToggleAction>::cast_static (act);
527 	smart_mode_button.set_related_action (smart_mode_action);
528 	smart_mode_button.set_text (_("Smart"));
529 	smart_mode_button.set_name ("mouse mode button");
530 
531 	act = ActionManager::register_radio_action (mouse_mode_actions, mouse_mode_group, "set-mouse-mode-object", _("Object Tool"), sigc::bind (sigc::mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseObject));
532 	mouse_move_button.set_related_action (act);
533 	mouse_move_button.set_icon (ArdourWidgets::ArdourIcon::ToolGrab);
534 	mouse_move_button.set_name ("mouse mode button");
535 
536 	act = ActionManager::register_radio_action (mouse_mode_actions, mouse_mode_group, "set-mouse-mode-range", _("Range Tool"), sigc::bind (sigc::mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseRange));
537 	mouse_select_button.set_related_action (act);
538 	mouse_select_button.set_icon (ArdourWidgets::ArdourIcon::ToolRange);
539 	mouse_select_button.set_name ("mouse mode button");
540 
541 	act = ActionManager::register_radio_action (mouse_mode_actions, mouse_mode_group, "set-mouse-mode-draw", _("Note Drawing Tool"), sigc::bind (sigc::mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseDraw));
542 	mouse_draw_button.set_related_action (act);
543 	mouse_draw_button.set_icon (ArdourWidgets::ArdourIcon::ToolDraw);
544 	mouse_draw_button.set_name ("mouse mode button");
545 
546 	act = ActionManager::register_radio_action (mouse_mode_actions, mouse_mode_group, "set-mouse-mode-audition", _("Audition Tool"), sigc::bind (sigc::mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseAudition));
547 	mouse_audition_button.set_related_action (act);
548 	mouse_audition_button.set_icon (ArdourWidgets::ArdourIcon::ToolAudition);
549 	mouse_audition_button.set_name ("mouse mode button");
550 
551 	act = ActionManager::register_radio_action (mouse_mode_actions, mouse_mode_group, "set-mouse-mode-timefx", _("Time FX Tool"), sigc::bind (sigc::mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseTimeFX));
552 	mouse_timefx_button.set_related_action (act);
553 	mouse_timefx_button.set_icon (ArdourWidgets::ArdourIcon::ToolStretch);
554 	mouse_timefx_button.set_name ("mouse mode button");
555 
556 	act = ActionManager::register_radio_action (mouse_mode_actions, mouse_mode_group, "set-mouse-mode-content", _("Content Tool"), sigc::bind (sigc::mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseContent));
557 	mouse_content_button.set_related_action (act);
558 	mouse_content_button.set_icon (ArdourWidgets::ArdourIcon::ToolContent);
559 	mouse_content_button.set_name ("mouse mode button");
560 
561 	act = ActionManager::register_radio_action (mouse_mode_actions, mouse_mode_group, "set-mouse-mode-cut", _("Cut Tool"), sigc::bind (sigc::mem_fun(*this, &Editor::mouse_mode_toggled), Editing::MouseCut));
562 	mouse_cut_button.set_related_action (act);
563 	mouse_cut_button.set_icon (ArdourWidgets::ArdourIcon::ToolCut);
564 	mouse_cut_button.set_name ("mouse mode button");
565 
566 	ActionManager::register_action (editor_actions, "step-mouse-mode", _("Step Mouse Mode"), sigc::bind (sigc::mem_fun(*this, &Editor::step_mouse_mode), true));
567 
568 	RadioAction::Group edit_point_group;
569 	ActionManager::register_radio_action (editor_actions, edit_point_group, X_("edit-at-playhead"), _("Playhead"), (sigc::bind (sigc::mem_fun(*this, &Editor::edit_point_chosen), Editing::EditAtPlayhead)));
570 	ActionManager::register_radio_action (editor_actions, edit_point_group, X_("edit-at-mouse"), _("Mouse"), (sigc::bind (sigc::mem_fun(*this, &Editor::edit_point_chosen), Editing::EditAtMouse)));
571 	ActionManager::register_radio_action (editor_actions, edit_point_group, X_("edit-at-selected-marker"), _("Marker"), (sigc::bind (sigc::mem_fun(*this, &Editor::edit_point_chosen), Editing::EditAtSelectedMarker)));
572 
573 	ActionManager::register_action (editor_actions, "cycle-edit-point", _("Change Edit Point"), sigc::bind (sigc::mem_fun (*this, &Editor::cycle_edit_point), false));
574 	ActionManager::register_action (editor_actions, "cycle-edit-point-with-marker", _("Change Edit Point Including Marker"), sigc::bind (sigc::mem_fun (*this, &Editor::cycle_edit_point), true));
575 
576 //	ActionManager::register_action (editor_actions, "set-edit-splice", _("Splice"), sigc::bind (sigc::mem_fun (*this, &Editor::set_edit_mode), Splice));
577 	ActionManager::register_action (editor_actions, "set-edit-ripple", _("Ripple"), bind (mem_fun (*this, &Editor::set_edit_mode), Ripple));
578 	ActionManager::register_action (editor_actions, "set-edit-slide", _("Slide"), sigc::bind (sigc::mem_fun (*this, &Editor::set_edit_mode), Slide));
579 	ActionManager::register_action (editor_actions, "set-edit-lock", S_("EditMode|Lock"), sigc::bind (sigc::mem_fun (*this, &Editor::set_edit_mode), Lock));
580 	ActionManager::register_action (editor_actions, "cycle-edit-mode", _("Cycle Edit Mode"), sigc::mem_fun (*this, &Editor::cycle_edit_mode));
581 
582 	ActionManager::register_action (editor_actions, X_("GridChoice"), _("Snap & Grid"));
583 
584 	RadioAction::Group snap_mode_group;
585 	/* deprecated */  ActionManager::register_radio_action (editor_actions, snap_mode_group, X_("snap-off"), _("No Grid"), (sigc::bind (sigc::mem_fun(*this, &Editor::snap_mode_chosen), Editing::SnapOff)));
586 	/* deprecated */  ActionManager::register_radio_action (editor_actions, snap_mode_group, X_("snap-normal"), _("Grid"), (sigc::bind (sigc::mem_fun(*this, &Editor::snap_mode_chosen), Editing::SnapNormal)));  //deprecated
587 	/* deprecated */  ActionManager::register_radio_action (editor_actions, snap_mode_group, X_("snap-magnetic"), _("Magnetic"), (sigc::bind (sigc::mem_fun(*this, &Editor::snap_mode_chosen), Editing::SnapMagnetic)));
588 
589 	snap_mode_button.set_text (_("Snap"));
590 	snap_mode_button.set_name ("mouse mode button");
591 	snap_mode_button.signal_button_press_event().connect (sigc::mem_fun (*this, &Editor::snap_mode_button_clicked), false);
592 
593 	ActionManager::register_action (editor_actions, X_("cycle-snap-mode"), _("Toggle Snap"), sigc::mem_fun (*this, &Editor::cycle_snap_mode));
594 	ActionManager::register_action (editor_actions, X_("next-grid-choice"), _("Next Quantize Grid Choice"), sigc::mem_fun (*this, &Editor::next_grid_choice));
595 	ActionManager::register_action (editor_actions, X_("prev-grid-choice"), _("Previous Quantize Grid Choice"), sigc::mem_fun (*this, &Editor::prev_grid_choice));
596 
597 	Glib::RefPtr<ActionGroup> snap_actions = ActionManager::create_action_group (bindings, X_("Snap"));
598 	RadioAction::Group grid_choice_group;
599 
600 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-thirtyseconds"),  grid_type_strings[(int)GridTypeBeatDiv32].c_str(), (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBeatDiv32)));
601 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-twentyeighths"),  grid_type_strings[(int)GridTypeBeatDiv28].c_str(), (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBeatDiv28)));
602 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-twentyfourths"),  grid_type_strings[(int)GridTypeBeatDiv24].c_str(), (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBeatDiv24)));
603 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-twentieths"),     grid_type_strings[(int)GridTypeBeatDiv20].c_str(), (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBeatDiv20)));
604 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-asixteenthbeat"), grid_type_strings[(int)GridTypeBeatDiv16].c_str(), (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBeatDiv16)));
605 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-fourteenths"),    grid_type_strings[(int)GridTypeBeatDiv14].c_str(), (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBeatDiv14)));
606 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-twelfths"),       grid_type_strings[(int)GridTypeBeatDiv12].c_str(), (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBeatDiv12)));
607 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-tenths"),         grid_type_strings[(int)GridTypeBeatDiv10].c_str(), (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBeatDiv10)));
608 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-eighths"),        grid_type_strings[(int)GridTypeBeatDiv8].c_str(),  (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBeatDiv8)));
609 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-sevenths"),       grid_type_strings[(int)GridTypeBeatDiv7].c_str(),  (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBeatDiv7)));
610 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-sixths"),         grid_type_strings[(int)GridTypeBeatDiv6].c_str(),  (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBeatDiv6)));
611 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-fifths"),         grid_type_strings[(int)GridTypeBeatDiv5].c_str(),  (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBeatDiv5)));
612 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-quarters"),       grid_type_strings[(int)GridTypeBeatDiv4].c_str(),  (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBeatDiv4)));
613 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-thirds"),         grid_type_strings[(int)GridTypeBeatDiv3].c_str(),  (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBeatDiv3)));
614 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-halves"),         grid_type_strings[(int)GridTypeBeatDiv2].c_str(),  (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBeatDiv2)));
615 
616 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-timecode"),       grid_type_strings[(int)GridTypeTimecode].c_str(),      (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeTimecode)));
617 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-minsec"),         grid_type_strings[(int)GridTypeMinSec].c_str(),    (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeMinSec)));
618 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-cdframe"),        grid_type_strings[(int)GridTypeCDFrame].c_str(), (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeCDFrame)));
619 
620 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-beat"),           grid_type_strings[(int)GridTypeBeat].c_str(),      (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBeat)));
621 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-bar"),            grid_type_strings[(int)GridTypeBar].c_str(),       (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeBar)));
622 
623 	ActionManager::register_radio_action (snap_actions, grid_choice_group, X_("grid-type-none"),           grid_type_strings[(int)GridTypeNone].c_str(),      (sigc::bind (sigc::mem_fun(*this, &Editor::grid_type_chosen), Editing::GridTypeNone)));
624 
625 	ActionManager::register_toggle_action (editor_actions, X_("show-marker-lines"), _("Show Marker Lines"), sigc::mem_fun (*this, &Editor::toggle_marker_lines));
626 
627 	/* RULERS */
628 
629 	Glib::RefPtr<ActionGroup> ruler_actions = ActionManager::create_action_group (bindings, X_("Rulers"));
630 	ruler_tempo_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (ruler_actions, X_("toggle-tempo-ruler"), _("Tempo"), sigc::mem_fun(*this, &Editor::toggle_ruler_visibility)));
631 	ruler_meter_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (ruler_actions, X_("toggle-meter-ruler"), _("Meter"), sigc::mem_fun(*this, &Editor::toggle_ruler_visibility)));
632 	ruler_range_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (ruler_actions, X_("toggle-range-ruler"), _("Ranges"), sigc::mem_fun(*this, &Editor::toggle_ruler_visibility)));
633 	ruler_marker_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (ruler_actions, X_("toggle-marker-ruler"), _("Markers"), sigc::mem_fun(*this, &Editor::toggle_ruler_visibility)));
634 	ruler_cd_marker_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (ruler_actions, X_("toggle-cd-marker-ruler"), _("CD Markers"), sigc::mem_fun(*this, &Editor::toggle_ruler_visibility)));
635 	ruler_loop_punch_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (ruler_actions, X_("toggle-loop-punch-ruler"), _("Loop/Punch"), sigc::mem_fun(*this, &Editor::toggle_ruler_visibility)));
636 	ruler_bbt_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (ruler_actions, X_("toggle-bbt-ruler"), _("Bars & Beats"), sigc::mem_fun(*this, &Editor::toggle_ruler_visibility)));
637 	ruler_samples_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (ruler_actions, X_("toggle-samples-ruler"), _("Samples"), sigc::mem_fun(*this, &Editor::toggle_ruler_visibility)));
638 	ruler_timecode_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (ruler_actions, X_("toggle-timecode-ruler"), _("Timecode"), sigc::mem_fun(*this, &Editor::toggle_ruler_visibility)));
639 	ruler_minsec_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (ruler_actions, X_("toggle-minsec-ruler"), _("Min:Sec"), sigc::mem_fun(*this, &Editor::toggle_ruler_visibility)));
640 
641 	ActionManager::register_action (editor_menu_actions, X_("VideoMonitorMenu"), _("Video Monitor"));
642 
643 	ruler_video_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (ruler_actions, X_("toggle-video-ruler"), _("Video"), sigc::mem_fun(*this, &Editor::toggle_ruler_visibility)));
644 	xjadeo_proc_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (editor_actions, X_("ToggleJadeo"), _("Video Monitor"), sigc::mem_fun (*this, &Editor::set_xjadeo_proc)));
645 
646 	xjadeo_ontop_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (editor_actions, X_("toggle-vmon-ontop"), _("Always on Top"), sigc::bind (sigc::mem_fun (*this, &Editor::set_xjadeo_viewoption), (int) 1)));
647 	xjadeo_timecode_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (editor_actions, X_("toggle-vmon-timecode"), _("Timecode"), sigc::bind (sigc::mem_fun (*this, &Editor::set_xjadeo_viewoption), (int) 2)));
648 	xjadeo_frame_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (editor_actions, X_("toggle-vmon-frame"), _("Frame number"), sigc::bind (sigc::mem_fun (*this, &Editor::set_xjadeo_viewoption), (int) 3)));
649 	xjadeo_osdbg_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (editor_actions, X_("toggle-vmon-osdbg"), _("Timecode Background"), sigc::bind (sigc::mem_fun (*this, &Editor::set_xjadeo_viewoption), (int) 4)));
650 	xjadeo_fullscreen_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (editor_actions, X_("toggle-vmon-fullscreen"), _("Fullscreen"), sigc::bind (sigc::mem_fun (*this, &Editor::set_xjadeo_viewoption), (int) 5)));
651 	xjadeo_letterbox_action = Glib::RefPtr<ToggleAction>::cast_static (ActionManager::register_toggle_action (editor_actions, X_("toggle-vmon-letterbox"), _("Letterbox"), sigc::bind (sigc::mem_fun (*this, &Editor::set_xjadeo_viewoption), (int) 6)));
652 	xjadeo_zoom_100 = reg_sens (editor_actions, "zoom-vmon-100", _("Original Size"), sigc::bind (sigc::mem_fun (*this, &Editor::set_xjadeo_viewoption), (int) 7));
653 
654 	/* set defaults here */
655 
656 	no_ruler_shown_update = true;
657 
658 	ruler_marker_action->set_active (true);
659 	ruler_meter_action->set_active (true);
660 	ruler_tempo_action->set_active (true);
661 	ruler_range_action->set_active (true);
662 	ruler_loop_punch_action->set_active (true);
663 	ruler_loop_punch_action->set_active (true);
664 	ruler_bbt_action->set_active (true);
665 	ruler_cd_marker_action->set_active (true);
666 	ruler_timecode_action->set_active (true);
667 	ruler_minsec_action->set_active (false);
668 
669 	ruler_video_action->set_active (false);
670 	xjadeo_proc_action->set_active (false);
671 	xjadeo_proc_action->set_sensitive (false);
672 	xjadeo_ontop_action->set_active (false);
673 	xjadeo_ontop_action->set_sensitive (false);
674 	xjadeo_timecode_action->set_active (false);
675 	xjadeo_timecode_action->set_sensitive (false);
676 	xjadeo_frame_action->set_active (false);
677 	xjadeo_frame_action->set_sensitive (false);
678 	xjadeo_osdbg_action->set_active (false);
679 	xjadeo_osdbg_action->set_sensitive (false);
680 	xjadeo_fullscreen_action->set_active (false);
681 	xjadeo_fullscreen_action->set_sensitive (false);
682 	xjadeo_letterbox_action->set_active (false);
683 	xjadeo_letterbox_action->set_sensitive (false);
684 	xjadeo_zoom_100->set_sensitive (false);
685 
686 	ruler_samples_action->set_active (false);
687 	no_ruler_shown_update = false;
688 
689 	/* REGION LIST */
690 
691 	Glib::RefPtr<ActionGroup> rl_actions = ActionManager::create_action_group (bindings, X_("RegionList"));
692 	RadioAction::Group sort_type_group;
693 	RadioAction::Group sort_order_group;
694 
695 	/* the region list popup menu */
696 	act = ActionManager::register_action (rl_actions, X_("rlAudition"), _("Audition"), sigc::mem_fun(*this, &Editor::audition_region_from_region_list));
697 	ActionManager::region_list_selection_sensitive_actions.push_back (act);
698 
699 	ActionManager::register_action (rl_actions, X_("removeUnusedRegions"), _("Remove Unused"), sigc::mem_fun (*_regions, &EditorRegions::remove_unused_regions));
700 
701 	act = reg_sens (editor_actions, X_("addExistingPTFiles"), _("Import PT session"), sigc::mem_fun (*this, &Editor::external_pt_dialog));
702 	ActionManager::write_sensitive_actions.push_back (act);
703 
704 	act = reg_sens (editor_actions, X_("LoudnessAssistant"), _("Loudness Assistant..."), sigc::bind (sigc::mem_fun (*this, &Editor::loudness_assistant), false));
705 	ActionManager::write_sensitive_actions.push_back (act);
706 
707 	/* the next two are duplicate items with different names for use in two different contexts */
708 
709 	act = reg_sens (editor_actions, X_("addExternalAudioToRegionList"), _("Import to Source List..."), sigc::bind (sigc::mem_fun(*this, &Editor::add_external_audio_action), ImportAsRegion));
710 	ActionManager::write_sensitive_actions.push_back (act);
711 
712 	act = ActionManager::register_action (editor_actions, X_("importFromSession"), _("Import from Session"), sigc::mem_fun(*this, &Editor::session_import_dialog));
713 	ActionManager::write_sensitive_actions.push_back (act);
714 
715 
716 	act = ActionManager::register_action (editor_actions, X_("bring-into-session"), _("Bring all media into session folder"), sigc::mem_fun(*this, &Editor::bring_all_sources_into_session));
717 	ActionManager::write_sensitive_actions.push_back (act);
718 
719 	ActionManager::register_toggle_action (editor_actions, X_("ToggleSummary"), _("Show Summary"), sigc::mem_fun (*this, &Editor::set_summary));
720 
721 	ActionManager::register_toggle_action (editor_actions, X_("ToggleGroupTabs"), _("Show Group Tabs"), sigc::mem_fun (*this, &Editor::set_group_tabs));
722 
723 	ActionManager::register_action (editor_actions, X_("toggle-midi-input-active"), _("Toggle MIDI Input Active for Editor-Selected Tracks/Busses"),
724 	                           sigc::bind (sigc::mem_fun (*this, &Editor::toggle_midi_input_active), false));
725 
726 
727 	/* MIDI stuff */
728 	reg_sens (editor_actions, "quantize", _("Quantize"), sigc::mem_fun (*this, &Editor::quantize_region));
729 }
730 
731 void
register_midi_actions(Bindings * midi_bindings)732 Editor::register_midi_actions (Bindings* midi_bindings)
733 {
734 	_midi_actions = ActionManager::create_action_group (midi_bindings, X_("Notes"));
735 
736 	/* two versions to allow same action for Delete and Backspace */
737 
738 	ActionManager::register_action (_midi_actions, X_("delete"), _("Delete Selection"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::delete_selection));
739 	ActionManager::register_action (_midi_actions, X_("alt-delete"), _("Delete Selection (alternate)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::delete_selection));
740 
741 	ActionManager::register_action (_midi_actions, X_("clear-selection"), _("Clear Note Selection"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::clear_note_selection));
742 	ActionManager::register_action (_midi_actions, X_("invert-selection"), _("Invert Note Selection"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::invert_selection));
743 	ActionManager::register_action (_midi_actions, X_("extend-selection"), _("Extend Note Selection"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::extend_selection));
744 	ActionManager::register_action (_midi_actions, X_("move-starts-earlier-fine"), _("Move Note Start Earlier (fine)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::move_note_starts_earlier_fine));
745 	ActionManager::register_action (_midi_actions, X_("move-starts-earlier"), _("Move Note Start Earlier"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::move_note_starts_earlier));
746 	ActionManager::register_action (_midi_actions, X_("move-ends-later-fine"), _("Move Note Ends Later (fine)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::move_note_ends_later_fine));
747 	ActionManager::register_action (_midi_actions, X_("move-ends-later"), _("Move Note Ends Later"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::move_note_ends_later));
748 
749 	/* Alt versions allow bindings for both Tab and ISO_Left_Tab, if desired */
750 
751 	ActionManager::register_action (_midi_actions, X_("select-next"), _("Select Next"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::select_next_note));
752 	ActionManager::register_action (_midi_actions, X_("alt-select-next"), _("Select Next (alternate)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::select_next_note));
753 	ActionManager::register_action (_midi_actions, X_("select-previous"), _("Select Previous"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::select_previous_note));
754 	ActionManager::register_action (_midi_actions, X_("alt-select-previous"), _("Select Previous (alternate)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::select_previous_note));
755 	ActionManager::register_action (_midi_actions, X_("add-select-next"), _("Add Next to Selection"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::add_select_next_note));
756 	ActionManager::register_action (_midi_actions, X_("alt-add-select-next"), _("Add Next to Selection (alternate)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::add_select_next_note));
757 	ActionManager::register_action (_midi_actions, X_("add-select-previous"), _("Add Previous to Selection"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::add_select_previous_note));
758 	ActionManager::register_action (_midi_actions, X_("alt-add-select-previous"), _("Add Previous to Selection (alternate)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::add_select_previous_note));
759 
760 	ActionManager::register_action (_midi_actions, X_("increase-velocity"), _("Increase Velocity"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::increase_note_velocity));
761 	ActionManager::register_action (_midi_actions, X_("increase-velocity-fine"), _("Increase Velocity (fine)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::increase_note_velocity_fine));
762 	ActionManager::register_action (_midi_actions, X_("increase-velocity-smush"), _("Increase Velocity (allow mush)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::increase_note_velocity_smush));
763 	ActionManager::register_action (_midi_actions, X_("increase-velocity-together"), _("Increase Velocity (non-relative)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::increase_note_velocity_together));
764 	ActionManager::register_action (_midi_actions, X_("increase-velocity-fine-smush"), _("Increase Velocity (fine, allow mush)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::increase_note_velocity_fine_smush));
765 	ActionManager::register_action (_midi_actions, X_("increase-velocity-fine-together"), _("Increase Velocity (fine, non-relative)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::increase_note_velocity_fine_together));
766 	ActionManager::register_action (_midi_actions, X_("increase-velocity-smush-together"), _("Increase Velocity (maintain ratios, allow mush)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::increase_note_velocity_smush_together));
767 	ActionManager::register_action (_midi_actions, X_("increase-velocity-fine-smush-together"), _("Increase Velocity (fine, allow mush, non-relative)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::increase_note_velocity_fine_smush_together));
768 
769 	ActionManager::register_action (_midi_actions, X_("decrease-velocity"), _("Decrease Velocity"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::decrease_note_velocity));
770 	ActionManager::register_action (_midi_actions, X_("decrease-velocity-fine"), _("Decrease Velocity (fine)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::decrease_note_velocity_fine));
771 	ActionManager::register_action (_midi_actions, X_("decrease-velocity-smush"), _("Decrease Velocity (allow mush)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::decrease_note_velocity_smush));
772 	ActionManager::register_action (_midi_actions, X_("decrease-velocity-together"), _("Decrease Velocity (non-relative)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::decrease_note_velocity_together));
773 	ActionManager::register_action (_midi_actions, X_("decrease-velocity-fine-smush"), _("Decrease Velocity (fine, allow mush)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::decrease_note_velocity_fine_smush));
774 	ActionManager::register_action (_midi_actions, X_("decrease-velocity-fine-together"), _("Decrease Velocity (fine, non-relative)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::decrease_note_velocity_fine_together));
775 	ActionManager::register_action (_midi_actions, X_("decrease-velocity-smush-together"), _("Decrease Velocity (maintain ratios, allow mush)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::decrease_note_velocity_smush_together));
776 	ActionManager::register_action (_midi_actions, X_("decrease-velocity-fine-smush-together"), _("Decrease Velocity (fine, allow mush, non-relative)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::decrease_note_velocity_fine_smush_together));
777 
778 	ActionManager::register_action (_midi_actions, X_("transpose-up-octave"), _("Transpose Up (octave)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::transpose_up_octave));
779 	ActionManager::register_action (_midi_actions, X_("transpose-up-octave-smush"), _("Transpose Up (octave, allow mush)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::transpose_up_octave_smush));
780 	ActionManager::register_action (_midi_actions, X_("transpose-up-semitone"), _("Transpose Up (semitone)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::transpose_up_tone));
781 	ActionManager::register_action (_midi_actions, X_("transpose-up-semitone-smush"), _("Transpose Up (semitone, allow mush)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::transpose_up_octave_smush));
782 
783 	ActionManager::register_action (_midi_actions, X_("transpose-down-octave"), _("Transpose Down (octave)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::transpose_down_octave));
784 	ActionManager::register_action (_midi_actions, X_("transpose-down-octave-smush"), _("Transpose Down (octave, allow mush)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::transpose_down_octave_smush));
785 	ActionManager::register_action (_midi_actions, X_("transpose-down-semitone"), _("Transpose Down (semitone)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::transpose_down_tone));
786 	ActionManager::register_action (_midi_actions, X_("transpose-down-semitone-smush"), _("Transpose Down (semitone, allow mush)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::transpose_down_octave_smush));
787 
788 	ActionManager::register_action (_midi_actions, X_("nudge-later"), _("Nudge Notes Later (grid)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::nudge_notes_later));
789 	ActionManager::register_action (_midi_actions, X_("nudge-later-fine"), _("Nudge Notes Later (1/4 grid)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::nudge_notes_later_fine));
790 	ActionManager::register_action (_midi_actions, X_("nudge-earlier"), _("Nudge Notes Earlier (grid)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::nudge_notes_earlier));
791 	ActionManager::register_action (_midi_actions, X_("nudge-earlier-fine"), _("Nudge Notes Earlier (1/4 grid)"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::nudge_notes_earlier_fine));
792 
793 	ActionManager::register_action (_midi_actions, X_("edit-channels"), _("Edit Note Channels"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::channel_edit));
794 	ActionManager::register_action (_midi_actions, X_("edit-velocities"), _("Edit Note Velocities"), sigc::bind (sigc::mem_fun (*this, &Editor::midi_action), &MidiRegionView::velocity_edit));
795 
796 	ActionManager::set_sensitive (_midi_actions, false);
797 }
798 
_lua_print(std::string s)799 static void _lua_print (std::string s) {
800 #ifndef NDEBUG
801 	std::cout << "LuaInstance: " << s << "\n";
802 #endif
803 	PBD::info << "LuaInstance: " << s << endmsg;
804 }
805 
806 void
trigger_script_by_name(const std::string script_name)807 Editor::trigger_script_by_name (const std::string script_name)
808 {
809 	string script_path;
810 	ARDOUR::LuaScriptList scr = LuaScripting::instance ().scripts(LuaScriptInfo::EditorAction);
811 	for (ARDOUR::LuaScriptList::const_iterator s = scr.begin(); s != scr.end(); ++s) {
812 
813 		if ((*s)->name == script_name) {
814 			script_path = (*s)->path;
815 
816 			if (!Glib::file_test (script_path, Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR)) {
817 #ifndef NDEBUG
818 				cerr << "Lua Script action: path to " << script_path << " does not appear to be valid" << endl;
819 #endif
820 				return;
821 			}
822 
823 			LuaState lua;
824 			lua.Print.connect (&_lua_print);
825 			lua.sandbox (false);
826 			lua_State* L = lua.getState();
827 			LuaInstance::register_classes (L);
828 			LuaBindings::set_session (L, _session);
829 			luabridge::push <PublicEditor *> (L, &PublicEditor::instance());
830 			lua_setglobal (L, "Editor");
831 			lua.do_command ("function ardour () end");
832 			lua.do_file (script_path);
833 			luabridge::LuaRef args (luabridge::newTable (L));
834 
835 			try {
836 				luabridge::LuaRef fn = luabridge::getGlobal (L, "factory");
837 				if (fn.isFunction()) {
838 					fn (args)();
839 				}
840 			} catch (luabridge::LuaException const& e) {
841 #ifndef NDEBUG
842 				cerr << "LuaException:" << e.what () << endl;
843 #endif
844 				PBD::warning << "LuaException: " << e.what () << endmsg;
845 			} catch (...) {
846 				cerr << "Lua script failed: " << script_path << endl;
847 			}
848 			return;
849 		}
850 	}
851 #ifndef NDEBUG
852 	cerr << "Lua script was not found: " << script_name << endl;
853 #endif
854 }
855 
856 void
load_bindings()857 Editor::load_bindings ()
858 {
859 	bindings = Bindings::get_bindings (X_("Editor"));
860 	global_hpacker.set_data ("ardour-bindings", bindings);
861 
862 	/* This set of bindings may expand in the future to include things
863 	 * other than MIDI editing, but for now this is all we've got as far as
864 	 * bindings that need to be distinct from the Editors (because some of
865 	 * the keys may overlap.
866 	 */
867 
868 	Bindings* midi_bindings = Bindings::get_bindings (X_("MIDI"));
869 
870 	register_midi_actions (midi_bindings);
871 
872 	_track_canvas_viewport->canvas()->set_data ("ardour-bindings", midi_bindings);
873 }
874 
875 void
toggle_skip_playback()876 Editor::toggle_skip_playback ()
877 {
878 	Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), "toggle-skip-playback");
879 	bool s = Config->get_skip_playback ();
880 	if (tact->get_active() != s) {
881 		Config->set_skip_playback (tact->get_active());
882 	}
883 }
884 
885 void
toggle_ruler_visibility()886 Editor::toggle_ruler_visibility ()
887 {
888 	if (no_ruler_shown_update) {
889 		return;
890 	}
891 
892 	update_ruler_visibility ();
893 	store_ruler_visibility ();
894 }
895 
896 void
set_summary()897 Editor::set_summary ()
898 {
899 	Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("ToggleSummary"));
900 	_session->config.set_show_summary (tact->get_active ());
901 }
902 
903 void
set_group_tabs()904 Editor::set_group_tabs ()
905 {
906 	Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("ToggleGroupTabs"));
907 	_session->config.set_show_group_tabs (tact->get_active ());
908 }
909 
910 void
set_close_video_sensitive(bool onoff)911 Editor::set_close_video_sensitive (bool onoff)
912 {
913 	Glib::RefPtr<Action> act = ActionManager::get_action (X_("Main"), X_("CloseVideo"));
914 	act->set_sensitive (onoff);
915 }
916 
917 void
set_xjadeo_sensitive(bool onoff)918 Editor::set_xjadeo_sensitive (bool onoff)
919 {
920 	xjadeo_proc_action->set_sensitive(onoff);
921 }
922 
923 void
toggle_xjadeo_proc(int state)924 Editor::toggle_xjadeo_proc (int state)
925 {
926 	switch(state) {
927 		case 1:
928 			xjadeo_proc_action->set_active(true);
929 			break;
930 		case 0:
931 			xjadeo_proc_action->set_active(false);
932 			break;
933 		default:
934 			xjadeo_proc_action->set_active(!xjadeo_proc_action->get_active());
935 			break;
936 	}
937 	bool onoff = xjadeo_proc_action->get_active();
938 	xjadeo_ontop_action->set_sensitive(onoff);
939 	xjadeo_timecode_action->set_sensitive(onoff);
940 	xjadeo_frame_action->set_sensitive(onoff);
941 	xjadeo_osdbg_action->set_sensitive(onoff);
942 	xjadeo_fullscreen_action->set_sensitive(onoff);
943 	xjadeo_letterbox_action->set_sensitive(onoff);
944 	xjadeo_zoom_100->set_sensitive(onoff);
945 }
946 
947 void
set_xjadeo_proc()948 Editor::set_xjadeo_proc ()
949 {
950 	if (xjadeo_proc_action->get_active()) {
951 		ARDOUR_UI::instance()->video_timeline->open_video_monitor();
952 	} else {
953 		ARDOUR_UI::instance()->video_timeline->close_video_monitor();
954 	}
955 }
956 
957 void
toggle_xjadeo_viewoption(int what,int state)958 Editor::toggle_xjadeo_viewoption (int what, int state)
959 {
960 	Glib::RefPtr<Gtk::ToggleAction> action;
961 	switch (what) {
962 		case 1:
963 			action = xjadeo_ontop_action;
964 			break;
965 		case 2:
966 			action = xjadeo_timecode_action;
967 			break;
968 		case 3:
969 			action = xjadeo_frame_action;
970 			break;
971 		case 4:
972 			action = xjadeo_osdbg_action;
973 			break;
974 		case 5:
975 			action = xjadeo_fullscreen_action;
976 			break;
977 		case 6:
978 			action = xjadeo_letterbox_action;
979 			break;
980 		case 7:
981 			return;
982 		default:
983 			return;
984 	}
985 
986 	switch(state) {
987 		case 1:
988 			action->set_active(true);
989 			break;
990 		case 0:
991 			action->set_active(false);
992 			break;
993 		default:
994 			action->set_active(!action->get_active());
995 			break;
996 	}
997 }
998 
999 void
set_xjadeo_viewoption(int what)1000 Editor::set_xjadeo_viewoption (int what)
1001 {
1002 	Glib::RefPtr<Gtk::ToggleAction> action;
1003 	switch (what) {
1004 		case 1:
1005 			action = xjadeo_ontop_action;
1006 			break;
1007 		case 2:
1008 			action = xjadeo_timecode_action;
1009 			break;
1010 		case 3:
1011 			action = xjadeo_frame_action;
1012 			break;
1013 		case 4:
1014 			action = xjadeo_osdbg_action;
1015 			break;
1016 		case 5:
1017 			action = xjadeo_fullscreen_action;
1018 			break;
1019 		case 6:
1020 			action = xjadeo_letterbox_action;
1021 			break;
1022 		case 7:
1023 			ARDOUR_UI::instance()->video_timeline->control_video_monitor(what, 0);
1024 			return;
1025 		default:
1026 			return;
1027 	}
1028 	if (action->get_active()) {
1029 		ARDOUR_UI::instance()->video_timeline->control_video_monitor(what, 1);
1030 	} else {
1031 		ARDOUR_UI::instance()->video_timeline->control_video_monitor(what, 0);
1032 	}
1033 }
1034 
1035 void
edit_current_meter()1036 Editor::edit_current_meter ()
1037 {
1038 	ARDOUR::MeterSection* ms = const_cast<ARDOUR::MeterSection*>(&_session->tempo_map().meter_section_at_sample (ARDOUR_UI::instance()->primary_clock->absolute_time()));
1039 	edit_meter_section (ms);
1040 }
1041 
1042 void
edit_current_tempo()1043 Editor::edit_current_tempo ()
1044 {
1045 	ARDOUR::TempoSection* ts = const_cast<ARDOUR::TempoSection*>(&_session->tempo_map().tempo_section_at_sample (ARDOUR_UI::instance()->primary_clock->absolute_time()));
1046 	edit_tempo_section (ts);
1047 }
1048 
1049 RefPtr<RadioAction>
grid_type_action(GridType type)1050 Editor::grid_type_action (GridType type)
1051 {
1052 	const char* action = 0;
1053 	RefPtr<Action> act;
1054 
1055 	switch (type) {
1056 	case Editing::GridTypeBeatDiv32:
1057 		action = "grid-type-thirtyseconds";
1058 		break;
1059 	case Editing::GridTypeBeatDiv28:
1060 		action = "grid-type-twentyeighths";
1061 		break;
1062 	case Editing::GridTypeBeatDiv24:
1063 		action = "grid-type-twentyfourths";
1064 		break;
1065 	case Editing::GridTypeBeatDiv20:
1066 		action = "grid-type-twentieths";
1067 		break;
1068 	case Editing::GridTypeBeatDiv16:
1069 		action = "grid-type-asixteenthbeat";
1070 		break;
1071 	case Editing::GridTypeBeatDiv14:
1072 		action = "grid-type-fourteenths";
1073 		break;
1074 	case Editing::GridTypeBeatDiv12:
1075 		action = "grid-type-twelfths";
1076 		break;
1077 	case Editing::GridTypeBeatDiv10:
1078 		action = "grid-type-tenths";
1079 		break;
1080 	case Editing::GridTypeBeatDiv8:
1081 		action = "grid-type-eighths";
1082 		break;
1083 	case Editing::GridTypeBeatDiv7:
1084 		action = "grid-type-sevenths";
1085 		break;
1086 	case Editing::GridTypeBeatDiv6:
1087 		action = "grid-type-sixths";
1088 		break;
1089 	case Editing::GridTypeBeatDiv5:
1090 		action = "grid-type-fifths";
1091 		break;
1092 	case Editing::GridTypeBeatDiv4:
1093 		action = "grid-type-quarters";
1094 		break;
1095 	case Editing::GridTypeBeatDiv3:
1096 		action = "grid-type-thirds";
1097 		break;
1098 	case Editing::GridTypeBeatDiv2:
1099 		action = "grid-type-halves";
1100 		break;
1101 	case Editing::GridTypeBeat:
1102 		action = "grid-type-beat";
1103 		break;
1104 	case Editing::GridTypeBar:
1105 		action = "grid-type-bar";
1106 		break;
1107 	case Editing::GridTypeNone:
1108 		action = "grid-type-none";
1109 		break;
1110 	case Editing::GridTypeTimecode:
1111 		action = "grid-type-timecode";
1112 		break;
1113 	case Editing::GridTypeCDFrame:
1114 		action = "grid-type-cdframe";
1115 		break;
1116 	case Editing::GridTypeMinSec:
1117 		action = "grid-type-minsec";
1118 		break;
1119 	default:
1120 		fatal << string_compose (_("programming error: %1: %2"), "Editor: impossible snap-to type", (int) type) << endmsg;
1121 		abort(); /*NOTREACHED*/
1122 	}
1123 
1124 	act = ActionManager::get_action (X_("Snap"), action);
1125 
1126 	if (act) {
1127 		RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
1128 		return ract;
1129 
1130 	} else  {
1131 		error << string_compose (_("programming error: %1"), "Editor::grid_type_chosen could not find action to match type.") << endmsg;
1132 		return RefPtr<RadioAction>();
1133 	}
1134 }
1135 
1136 void
next_grid_choice()1137 Editor::next_grid_choice ()
1138 {
1139 	switch (_grid_type) {
1140 	case Editing::GridTypeBeatDiv32:
1141 		set_grid_to (Editing::GridTypeNone);
1142 		break;
1143 	case Editing::GridTypeBeatDiv16:
1144 		set_grid_to (Editing::GridTypeBeatDiv32);
1145 		break;
1146 	case Editing::GridTypeBeatDiv8:
1147 		set_grid_to (Editing::GridTypeBeatDiv16);
1148 		break;
1149 	case Editing::GridTypeBeatDiv4:
1150 		set_grid_to (Editing::GridTypeBeatDiv8);
1151 		break;
1152 	case Editing::GridTypeBeatDiv2:
1153 		set_grid_to (Editing::GridTypeBeatDiv4);
1154 		break;
1155 	case Editing::GridTypeBeat:
1156 		set_grid_to (Editing::GridTypeBeatDiv2);
1157 		break;
1158 	case Editing::GridTypeBar:
1159 		set_grid_to (Editing::GridTypeBeat);
1160 		break;
1161 	case Editing::GridTypeNone:
1162 		set_grid_to (Editing::GridTypeBar);
1163 		break;
1164 	case Editing::GridTypeBeatDiv3:
1165 	case Editing::GridTypeBeatDiv6:
1166 	case Editing::GridTypeBeatDiv12:
1167 	case Editing::GridTypeBeatDiv24:
1168 	case Editing::GridTypeBeatDiv5:
1169 	case Editing::GridTypeBeatDiv10:
1170 	case Editing::GridTypeBeatDiv20:
1171 	case Editing::GridTypeBeatDiv7:
1172 	case Editing::GridTypeBeatDiv14:
1173 	case Editing::GridTypeBeatDiv28:
1174 	case Editing::GridTypeTimecode:
1175 	case Editing::GridTypeMinSec:
1176 	case Editing::GridTypeCDFrame:
1177 		break;  //do nothing
1178 	}
1179 }
1180 
1181 void
prev_grid_choice()1182 Editor::prev_grid_choice ()
1183 {
1184 	switch (_grid_type) {
1185 	case Editing::GridTypeBeatDiv32:
1186 		set_grid_to (Editing::GridTypeBeatDiv16);
1187 		break;
1188 	case Editing::GridTypeBeatDiv16:
1189 		set_grid_to (Editing::GridTypeBeatDiv8);
1190 		break;
1191 	case Editing::GridTypeBeatDiv8:
1192 		set_grid_to (Editing::GridTypeBeatDiv4);
1193 		break;
1194 	case Editing::GridTypeBeatDiv4:
1195 		set_grid_to (Editing::GridTypeBeatDiv2);
1196 		break;
1197 	case Editing::GridTypeBeatDiv2:
1198 		set_grid_to (Editing::GridTypeBeat);
1199 		break;
1200 	case Editing::GridTypeBeat:
1201 		set_grid_to (Editing::GridTypeBar);
1202 		break;
1203 	case Editing::GridTypeBar:
1204 		set_grid_to (Editing::GridTypeNone);
1205 		break;
1206 	case Editing::GridTypeNone:
1207 		set_grid_to (Editing::GridTypeBeatDiv32);
1208 		break;
1209 	case Editing::GridTypeBeatDiv3:
1210 	case Editing::GridTypeBeatDiv6:
1211 	case Editing::GridTypeBeatDiv12:
1212 	case Editing::GridTypeBeatDiv24:
1213 	case Editing::GridTypeBeatDiv5:
1214 	case Editing::GridTypeBeatDiv10:
1215 	case Editing::GridTypeBeatDiv20:
1216 	case Editing::GridTypeBeatDiv7:
1217 	case Editing::GridTypeBeatDiv14:
1218 	case Editing::GridTypeBeatDiv28:
1219 	case Editing::GridTypeTimecode:
1220 	case Editing::GridTypeMinSec:
1221 	case Editing::GridTypeCDFrame:
1222 		break;  //do nothing
1223 	}
1224 }
1225 
1226 void
grid_type_chosen(GridType type)1227 Editor::grid_type_chosen (GridType type)
1228 {
1229 	/* this is driven by a toggle on a radio group, and so is invoked twice,
1230 	   once for the item that became inactive and once for the one that became
1231 	   active.
1232 	*/
1233 
1234 	RefPtr<RadioAction> ract = grid_type_action (type);
1235 
1236 	if (ract && ract->get_active()) {
1237 		set_grid_to (type);
1238 	}
1239 }
1240 
1241 RefPtr<RadioAction>
snap_mode_action(SnapMode mode)1242 Editor::snap_mode_action (SnapMode mode)
1243 {
1244 	const char* action = 0;
1245 	RefPtr<Action> act;
1246 
1247 	switch (mode) {
1248 	case Editing::SnapOff:
1249 		action = X_("snap-off");
1250 		break;
1251 	case Editing::SnapNormal:
1252 		action = X_("snap-normal");
1253 		break;
1254 	case Editing::SnapMagnetic:
1255 		action = X_("snap-magnetic");
1256 		break;
1257 	default:
1258 		fatal << string_compose (_("programming error: %1: %2"), "Editor: impossible snap mode type", (int) mode) << endmsg;
1259 		abort(); /*NOTREACHED*/
1260 	}
1261 
1262 	act = ActionManager::get_action (X_("Editor"), action);
1263 
1264 	if (act) {
1265 		RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
1266 		return ract;
1267 
1268 	} else  {
1269 		error << string_compose (_("programming error: %1: %2"), "Editor::snap_mode_chosen could not find action to match mode.", action) << endmsg;
1270 		return RefPtr<RadioAction> ();
1271 	}
1272 }
1273 
1274 void
cycle_snap_mode()1275 Editor::cycle_snap_mode ()
1276 {
1277 	switch (_snap_mode) {
1278 	case SnapOff:
1279 	case SnapNormal:
1280 		set_snap_mode (SnapMagnetic);
1281 		break;
1282 	case SnapMagnetic:
1283 		set_snap_mode (SnapOff);
1284 		break;
1285 	}
1286 }
1287 
1288 void
snap_mode_chosen(SnapMode mode)1289 Editor::snap_mode_chosen (SnapMode mode)
1290 {
1291 	/* this is driven by a toggle on a radio group, and so is invoked twice,
1292 	   once for the item that became inactive and once for the one that became
1293 	   active.
1294 	*/
1295 
1296 	if (mode == SnapNormal) {
1297 		mode = SnapMagnetic;
1298 	}
1299 
1300 	RefPtr<RadioAction> ract = snap_mode_action (mode);
1301 
1302 	if (ract && ract->get_active()) {
1303 		set_snap_mode (mode);
1304 	}
1305 }
1306 
1307 RefPtr<RadioAction>
edit_point_action(EditPoint ep)1308 Editor::edit_point_action (EditPoint ep)
1309 {
1310 	const char* action = 0;
1311 	RefPtr<Action> act;
1312 
1313 	switch (ep) {
1314 	case Editing::EditAtPlayhead:
1315 		action = X_("edit-at-playhead");
1316 		break;
1317 	case Editing::EditAtSelectedMarker:
1318 		action = X_("edit-at-selected-marker");
1319 		break;
1320 	case Editing::EditAtMouse:
1321 		action = X_("edit-at-mouse");
1322 		break;
1323 	default:
1324 		fatal << string_compose (_("programming error: %1: %2"), "Editor: impossible edit point type", (int) ep) << endmsg;
1325 		abort(); /*NOTREACHED*/
1326 	}
1327 
1328 	act = ActionManager::get_action (X_("Editor"), action);
1329 
1330 	if (act) {
1331 		RefPtr<RadioAction> ract = RefPtr<RadioAction>::cast_dynamic(act);
1332 		return ract;
1333 
1334 	} else  {
1335 		error << string_compose (_("programming error: %1: %2"), "Editor::edit_point_action could not find action to match edit point.", action) << endmsg;
1336 		return RefPtr<RadioAction> ();
1337 	}
1338 }
1339 
1340 void
edit_point_chosen(EditPoint ep)1341 Editor::edit_point_chosen (EditPoint ep)
1342 {
1343 	/* this is driven by a toggle on a radio group, and so is invoked twice,
1344 	   once for the item that became inactive and once for the one that became
1345 	   active.
1346 	*/
1347 
1348 	RefPtr<RadioAction> ract = edit_point_action (ep);
1349 
1350 	if (ract && ract->get_active()) {
1351 		set_edit_point_preference (ep);
1352 	}
1353 }
1354 
1355 
1356 RefPtr<RadioAction>
zoom_focus_action(ZoomFocus focus)1357 Editor::zoom_focus_action (ZoomFocus focus)
1358 {
1359 	const char* action = 0;
1360 	RefPtr<Action> act;
1361 
1362 	switch (focus) {
1363 	case ZoomFocusLeft:
1364 		action = X_("zoom-focus-left");
1365 		break;
1366 	case ZoomFocusRight:
1367 		action = X_("zoom-focus-right");
1368 		break;
1369 	case ZoomFocusCenter:
1370 		action = X_("zoom-focus-center");
1371 		break;
1372 	case ZoomFocusPlayhead:
1373 		action = X_("zoom-focus-playhead");
1374 		break;
1375 	case ZoomFocusMouse:
1376 		action = X_("zoom-focus-mouse");
1377 		break;
1378 	case ZoomFocusEdit:
1379 		action = X_("zoom-focus-edit");
1380 		break;
1381 	default:
1382 		fatal << string_compose (_("programming error: %1: %2"), "Editor: impossible focus type", (int) focus) << endmsg;
1383 		abort(); /*NOTREACHED*/
1384 	}
1385 
1386 	return ActionManager::get_radio_action (X_("Zoom"), action);
1387 }
1388 
1389 void
toggle_sound_midi_notes()1390 Editor::toggle_sound_midi_notes ()
1391 {
1392 	Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("sound-midi-notes"));
1393 	bool s = UIConfiguration::instance().get_sound_midi_notes();
1394 	if (tact->get_active () != s) {
1395 		UIConfiguration::instance().set_sound_midi_notes (tact->get_active());
1396 	}
1397 }
1398 
1399 void
zoom_focus_chosen(ZoomFocus focus)1400 Editor::zoom_focus_chosen (ZoomFocus focus)
1401 {
1402 	/* this is driven by a toggle on a radio group, and so is invoked twice,
1403 	   once for the item that became inactive and once for the one that became
1404 	   active.
1405 	*/
1406 
1407 	RefPtr<RadioAction> ract = zoom_focus_action (focus);
1408 
1409 	if (ract && ract->get_active()) {
1410 		set_zoom_focus (focus);
1411 	}
1412 }
1413 
1414 /** A Configuration parameter has changed.
1415  * @param parameter_name Name of the changed parameter.
1416  */
1417 void
parameter_changed(std::string p)1418 Editor::parameter_changed (std::string p)
1419 {
1420 	ENSURE_GUI_THREAD (*this, &Editor::parameter_changed, p)
1421 
1422 	if (p == "auto-loop") {
1423 		update_loop_range_view ();
1424 	} else if (p == "punch-in") {
1425 		update_punch_range_view ();
1426 	} else if (p == "punch-out") {
1427 		update_punch_range_view ();
1428 	} else if (p == "timecode-format") {
1429 		update_just_timecode ();
1430 	} else if (p == "show-region-fades") {
1431 		update_region_fade_visibility ();
1432 	} else if (p == "edit-mode") {
1433 		edit_mode_selector.set_text (edit_mode_to_string (Config->get_edit_mode()));
1434 	} else if (p == "show-track-meters") {
1435 		toggle_meter_updating();
1436 	} else if (p == "show-summary") {
1437 
1438 		bool const s = _session->config.get_show_summary ();
1439 		if (s) {
1440 			_summary_hbox.show ();
1441 		} else {
1442 			_summary_hbox.hide ();
1443 		}
1444 
1445 		Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("ToggleSummary"));
1446 		if (tact->get_active () != s) {
1447 			tact->set_active (s);
1448 		}
1449 	} else if (p == "show-group-tabs") {
1450 
1451 		bool const s = _session ? _session->config.get_show_group_tabs () : true;
1452 		if (s) {
1453 			_group_tabs->show ();
1454 		} else {
1455 			_group_tabs->hide ();
1456 		}
1457 
1458 		reset_controls_layout_width ();
1459 
1460 		Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("ToggleGroupTabs"));
1461 		if (tact->get_active () != s) {
1462 			tact->set_active (s);
1463 		}
1464 	} else if (p == "timecode-offset" || p == "timecode-offset-negative") {
1465 		update_just_timecode ();
1466 	} else if (p == "sound-midi-notes") {
1467 		Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("sound-midi-notes"));
1468 		bool s = UIConfiguration::instance().get_sound_midi_notes();
1469 		if (tact->get_active () != s) {
1470 			tact->set_active (s);
1471 		}
1472 	} else if (p == "show-region-gain") {
1473 		set_gain_envelope_visibility ();
1474 	} else if (p == "skip-playback") {
1475 		Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("toggle-skip-playback"));
1476 		bool s = Config->get_skip_playback ();
1477 		if (tact->get_active () != s) {
1478 			tact->set_active (s);
1479 		}
1480 	}
1481 }
1482 
1483 void
reset_canvas_action_sensitivity(bool onoff)1484 Editor::reset_canvas_action_sensitivity (bool onoff)
1485 {
1486 	if (_edit_point != EditAtMouse) {
1487 		onoff = true;
1488 	}
1489 
1490 	for (vector<Glib::RefPtr<Action> >::iterator x = ActionManager::mouse_edit_point_requires_canvas_actions.begin();
1491 	     x != ActionManager::mouse_edit_point_requires_canvas_actions.end(); ++x) {
1492 		(*x)->set_sensitive (onoff);
1493 	}
1494 }
1495 
1496 void
register_region_actions()1497 Editor::register_region_actions ()
1498 {
1499 	_region_actions = ActionManager::create_action_group (bindings, X_("Region"));
1500 
1501 	/* PART 1: actions that operate on the selection, and for which the edit point type and location is irrelevant */
1502 
1503 	/* Remove selected regions */
1504 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "remove-region", _("Remove"), sigc::mem_fun (*this, &Editor::remove_selected_regions));
1505 
1506 	/* Offer dialogue box to rename the first selected region */
1507 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "rename-region", _("Rename..."), sigc::mem_fun (*this, &Editor::rename_region));
1508 
1509 	/* Raise all selected regions by 1 layer */
1510 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions), "raise-region", _("Raise"), sigc::mem_fun (*this, &Editor::raise_region));
1511 
1512 	/* Raise all selected regions to the top */
1513 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions), "raise-region-to-top", _("Raise to Top"), sigc::mem_fun (*this, &Editor::raise_region_to_top));
1514 
1515 	/* Lower all selected regions by 1 layer */
1516 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions), "lower-region", _("Lower"), sigc::mem_fun (*this, &Editor::lower_region));
1517 
1518 	/* Lower all selected regions to the bottom */
1519 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions), "lower-region-to-bottom", _("Lower to Bottom"), sigc::mem_fun (*this, &Editor::lower_region_to_bottom));
1520 
1521 	/* Move selected regions to their original (`natural') position */
1522 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "naturalize-region", _("Move to Original Position"), sigc::mem_fun (*this, &Editor::naturalize_region));
1523 
1524 	/* Toggle `locked' status of selected regions */
1525 	register_toggle_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "toggle-region-lock", _("Lock"), sigc::mem_fun(*this, &Editor::toggle_region_lock));
1526 	register_toggle_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "toggle-region-video-lock", _("Lock to Video"), sigc::mem_fun(*this, &Editor::toggle_region_video_lock));
1527 	register_toggle_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "toggle-region-lock-style", _("Glue to Bars and Beats"), sigc::mem_fun (*this, &Editor::toggle_region_lock_style));
1528 
1529 	/* Remove sync points from selected regions */
1530 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "remove-region-sync", _("Remove Sync"), sigc::mem_fun(*this, &Editor::remove_region_sync));
1531 
1532 	/* Mute or unmute selected regions */
1533 	register_toggle_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "toggle-region-mute", _("Mute"), sigc::mem_fun(*this, &Editor::toggle_region_mute));
1534 
1535 	/* Open the normalize dialogue to operate on the selected regions */
1536 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "normalize-region", _("Normalize..."), sigc::mem_fun(*this, &Editor::normalize_region));
1537 
1538 	/* Reverse selected regions */
1539 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "reverse-region", _("Reverse"), sigc::mem_fun (*this, &Editor::reverse_region));
1540 
1541 	/* Split selected multi-channel regions into mono regions */
1542 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "split-multichannel-region", _("Make Mono Regions"), sigc::mem_fun (*this, &Editor::split_multichannel_region));
1543 
1544 	/* Boost selected region gain */
1545 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "boost-region-gain", _("Boost Gain"), sigc::bind (sigc::mem_fun(*this, &Editor::adjust_region_gain), true));
1546 
1547 	/* Cut selected region gain */
1548 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "cut-region-gain", _("Cut Gain"), sigc::bind (sigc::mem_fun(*this, &Editor::adjust_region_gain), false));
1549 
1550 	/* Reset selected region gain */
1551 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "reset-region-gain", _("Reset Gain"), sigc::mem_fun(*this, &Editor::reset_region_gain));
1552 
1553 	/* Open the pitch shift dialogue for any selected audio regions */
1554 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "pitch-shift-region", _("Pitch Shift..."), sigc::mem_fun (*this, &Editor::pitch_shift_region));
1555 
1556 	/* Open the transpose dialogue for any selected MIDI regions */
1557 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "transpose-region", _("Transpose..."), sigc::mem_fun (*this, &Editor::transpose_region));
1558 
1559 	/* Toggle selected region opacity */
1560 	register_toggle_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "toggle-opaque-region", _("Opaque"), sigc::mem_fun (*this, &Editor::toggle_opaque_region));
1561 
1562 	/* Toggle active status of selected regions' fade in */
1563 	register_toggle_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "toggle-region-fade-in", _("Fade In"), sigc::bind (sigc::mem_fun (*this, &Editor::toggle_region_fades), 1));
1564 
1565 	/* Toggle active status of selected regions' fade out */
1566 	register_toggle_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "toggle-region-fade-out", _("Fade Out"), sigc::bind (sigc::mem_fun(*this, &Editor::toggle_region_fades), -1));
1567 
1568 	/* Toggle active status of selected regions' fade in and out */
1569 	register_toggle_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "toggle-region-fades", _("Fades"), sigc::bind (sigc::mem_fun(*this, &Editor::toggle_region_fades), 0));
1570 
1571 	/* Duplicate selected regions */
1572 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "duplicate-region", _("Duplicate"), sigc::bind (sigc::mem_fun (*this, &Editor::duplicate_regions), 1));
1573 
1574 	/* Open the dialogue to duplicate selected regions multiple times */
1575 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "multi-duplicate-region", _("Multi-Duplicate..."), sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_range), true));
1576 
1577 	/* Fill tracks with selected regions */
1578 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "region-fill-track", _("Fill Track"), sigc::mem_fun (*this, &Editor::region_fill_track));
1579 
1580 	/* Set up the loop range from the selected regions */
1581 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "set-loop-from-region", _("Set Loop Range"), sigc::bind (sigc::mem_fun (*this, &Editor::set_loop_from_region), false));
1582 
1583 	/* Set up the loop range from the selected regions, and start playback of it */
1584 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "loop-region", _("Loop"), sigc::bind  (sigc::mem_fun(*this, &Editor::set_loop_from_region), true));
1585 
1586 	/* Set the punch range from the selected regions */
1587 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "set-punch-from-region", _("Set Punch"), sigc::mem_fun (*this, &Editor::set_punch_from_region));
1588 
1589 	/* Add a single range marker around all selected regions */
1590 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "add-range-marker-from-region", _("Add Single Range Marker"), sigc::mem_fun (*this, &Editor::add_location_from_region));
1591 
1592 	/* Add a range marker around each selected region */
1593 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "add-range-markers-from-region", _("Add Range Marker Per Region"), sigc::mem_fun (*this, &Editor::add_locations_from_region));
1594 
1595 	/* Snap selected regions to the grid */
1596 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "snap-regions-to-grid", _("Snap Position to Grid"), sigc::mem_fun (*this, &Editor::snap_regions_to_grid));
1597 
1598 	/* Close gaps in selected regions */
1599 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "close-region-gaps", _("Close Gaps"), sigc::mem_fun (*this, &Editor::close_region_gaps));
1600 
1601 	/* Open the Rhythm Ferret dialogue for the selected regions */
1602 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions), "show-rhythm-ferret", _("Rhythm Ferret..."), sigc::mem_fun (*this, &Editor::show_rhythm_ferret));
1603 
1604 	/* Export the first selected region */
1605 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions), "export-region", _("Export..."), sigc::mem_fun (*this, &Editor::export_region));
1606 
1607 	/* Separate under selected regions: XXX not sure what this does */
1608 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "separate-under-region", _("Separate Under"), sigc::mem_fun (*this, &Editor::separate_under_selected_regions));
1609 
1610 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "set-fade-in-length", _("Set Fade In Length"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_length), true));
1611 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "alternate-set-fade-in-length", _("Set Fade In Length"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_length), true));
1612 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "set-fade-out-length", _("Set Fade Out Length"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_length), false));
1613 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "alternate-set-fade-out-length", _("Set Fade Out Length"), sigc::bind (sigc::mem_fun (*this, &Editor::set_fade_length), false));
1614 
1615 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "set-tempo-from-region", _("Set Tempo from Region = Bar"), sigc::mem_fun (*this, &Editor::set_tempo_from_region));
1616 
1617 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "split-region-at-transients", _("Split at Percussion Onsets"), sigc::mem_fun(*this, &Editor::split_region_at_transients));
1618 
1619 	/* Open the list editor dialogue for the selected regions */
1620 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions), "show-region-list-editor", _("List Editor..."), sigc::mem_fun (*this, &Editor::show_midi_list_editor));
1621 
1622 	/* Open the region properties dialogue for the selected regions */
1623 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions), "show-region-properties", _("Properties..."), sigc::mem_fun (*this, &Editor::show_region_properties));
1624 
1625 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "play-selected-regions", _("Play Selected Regions"), sigc::mem_fun(*this, &Editor::play_selected_region));
1626 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "tag-selected-regions", _("Tag Selected Regions"), sigc::mem_fun(*this, &Editor::tag_selected_region));
1627 
1628 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions), "bounce-regions-processed", _("Bounce (with processing)"), (sigc::bind (sigc::mem_fun (*this, &Editor::bounce_region_selection), true)));
1629 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions), "bounce-regions-unprocessed", _("Bounce (without processing)"), (sigc::bind (sigc::mem_fun (*this, &Editor::bounce_region_selection), false)));
1630 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions), "combine-regions", _("Combine"), sigc::mem_fun (*this, &Editor::combine_regions));
1631 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions), "uncombine-regions", _("Uncombine"), sigc::mem_fun (*this, &Editor::uncombine_regions));
1632 
1633 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions), "loudness-analyze-region", _("Loudness Analysis..."), sigc::mem_fun (*this, &Editor::loudness_analyze_region_selection));
1634 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions), "spectral-analyze-region", _("Spectral Analysis..."), sigc::mem_fun (*this, &Editor::spectral_analyze_region_selection));
1635 
1636 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "reset-region-gain-envelopes", _("Reset Envelope"), sigc::mem_fun (*this, &Editor::reset_region_gain_envelopes));
1637 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "reset-region-scale-amplitude", _("Reset Gain"), sigc::mem_fun (*this, &Editor::reset_region_scale_amplitude));
1638 
1639 	register_toggle_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "toggle-region-gain-envelope-active", _("Envelope Active"), sigc::mem_fun (*this, &Editor::toggle_gain_envelope_active));
1640 
1641 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "quantize-region", _("Quantize..."), sigc::mem_fun (*this, &Editor::quantize_region));
1642 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "legatize-region", _("Legatize"), sigc::bind(sigc::mem_fun (*this, &Editor::legatize_region), false));
1643 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "transform-region", _("Transform..."), sigc::mem_fun (*this, &Editor::transform_region));
1644 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "remove-overlap", _("Remove Overlap"), sigc::bind(sigc::mem_fun (*this, &Editor::legatize_region), true));
1645 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "insert-patch-change", _("Insert Patch Change..."), sigc::bind (sigc::mem_fun (*this, &Editor::insert_patch_change), false));
1646 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "insert-patch-change-context", _("Insert Patch Change..."), sigc::bind (sigc::mem_fun (*this, &Editor::insert_patch_change), true));
1647 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "fork-region", _("Unlink from other copies"), sigc::mem_fun (*this, &Editor::fork_region));
1648 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "strip-region-silence", _("Strip Silence..."), sigc::mem_fun (*this, &Editor::strip_region_silence));
1649 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions), "set-selection-from-region", _("Set Range Selection"), sigc::mem_fun (*this, &Editor::set_selection_from_region));
1650 
1651 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "nudge-forward", _("Nudge Later"), sigc::bind (sigc::mem_fun (*this, &Editor::nudge_forward), false, false));
1652 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "alternate-nudge-forward", _("Nudge Later"), sigc::bind (sigc::mem_fun (*this, &Editor::nudge_forward), false, false));
1653 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "nudge-backward", _("Nudge Earlier"), sigc::bind (sigc::mem_fun (*this, &Editor::nudge_backward), false, false));
1654 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "alternate-nudge-backward", _("Nudge Earlier"), sigc::bind (sigc::mem_fun (*this, &Editor::nudge_backward), false, false));
1655 
1656 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "sequence-regions", _("Sequence Regions"), sigc::mem_fun (*this, &Editor::sequence_regions));
1657 
1658 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "nudge-forward-by-capture-offset", _("Nudge Later by Capture Offset"), sigc::mem_fun (*this, &Editor::nudge_forward_capture_offset));
1659 
1660 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "nudge-backward-by-capture-offset", _("Nudge Earlier by Capture Offset"), sigc::mem_fun (*this, &Editor::nudge_backward_capture_offset));
1661 
1662 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "trim-region-to-loop", _("Trim to Loop"), sigc::mem_fun (*this, &Editor::trim_region_to_loop));
1663 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "trim-region-to-punch", _("Trim to Punch"), sigc::mem_fun (*this, &Editor::trim_region_to_punch));
1664 
1665 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "trim-to-previous-region", _("Trim to Previous"), sigc::mem_fun(*this, &Editor::trim_region_to_previous_region_end));
1666 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EnteredRegions), "trim-to-next-region", _("Trim to Next"), sigc::mem_fun(*this, &Editor::trim_region_to_next_region_start));
1667 
1668 	/* PART 2: actions that are not related to the selection, but for which the edit point type and location is important */
1669 
1670 	register_region_action (_region_actions, RegionActionTarget (ListSelection), "insert-region-from-source-list", _("Insert Region from Source List"), sigc::bind (sigc::mem_fun (*this, &Editor::insert_source_list_selection), 1));
1671 
1672 	/* PART 3: actions that operate on the selection and also require the edit point location */
1673 
1674 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EditPointRegions), "make-region-markers-cd", _("Convert Region Cue Markers to CD Markers"), sigc::bind (sigc::mem_fun (*this, &Editor::make_region_markers_global), true));
1675 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EditPointRegions), "make-region-markers-global", _("Convert Region Cue Markers to Global Markers"), sigc::bind (sigc::mem_fun (*this, &Editor::make_region_markers_global), false));
1676 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EditPointRegions), "add-region-cue-marker", _("Add Region Cue Marker"), sigc::mem_fun (*this, &Editor::add_region_marker));
1677 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EditPointRegions), "clear-region-cue-markers", _("Clear Region Cue Markers"), sigc::mem_fun (*this, &Editor::clear_region_markers));
1678 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EditPointRegions), "set-region-sync-position", _("Set Sync Position"), sigc::mem_fun (*this, &Editor::set_region_sync_position));
1679 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EditPointRegions), "place-transient", _("Place Transient"), sigc::mem_fun (*this, &Editor::place_transient));
1680 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EditPointRegions), "trim-front", _("Trim Start at Edit Point"), sigc::mem_fun (*this, &Editor::trim_region_front));
1681 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EditPointRegions), "trim-back", _("Trim End at Edit Point"), sigc::mem_fun (*this, &Editor::trim_region_back));
1682 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EditPointRegions), "align-regions-start", _("Align Start"), sigc::bind (sigc::mem_fun(*this, &Editor::align_regions), ARDOUR::Start));
1683 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EditPointRegions), "align-regions-start-relative", _("Align Start Relative"), sigc::bind (sigc::mem_fun (*this, &Editor::align_regions_relative), ARDOUR::Start));
1684 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EditPointRegions), "align-regions-end", _("Align End"), sigc::bind (sigc::mem_fun (*this, &Editor::align_regions), ARDOUR::End));
1685 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EditPointRegions), "align-regions-end-relative", _("Align End Relative"), sigc::bind (sigc::mem_fun(*this, &Editor::align_regions_relative), ARDOUR::End));
1686 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EditPointRegions), "align-regions-sync", _("Align Sync"), sigc::bind (sigc::mem_fun(*this, &Editor::align_regions), ARDOUR::SyncPoint));
1687 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EditPointRegions), "align-regions-sync-relative", _("Align Sync Relative"), sigc::bind (sigc::mem_fun (*this, &Editor::align_regions_relative), ARDOUR::SyncPoint));
1688 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EditPointRegions), "choose-top-region", _("Choose Top..."), sigc::bind (sigc::mem_fun (*this, &Editor::change_region_layering_order), false));
1689 	register_region_action (_region_actions, RegionActionTarget (SelectedRegions|EditPointRegions), "choose-top-region-context-menu", _("Choose Top..."), sigc::bind (sigc::mem_fun (*this, &Editor::change_region_layering_order), true));
1690 
1691 	/* desensitize them all by default. region selection will change this */
1692 	sensitize_all_region_actions (false);
1693 }
1694