mp4chaps Lua script: don't clutter global environment
[ardour.git] / gtk2_ardour / editor_keys.cc
1 /*
2     Copyright (C) 2000 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <cstdlib>
21 #include <cmath>
22 #include <string>
23
24 #include <gtkmm/treeview.h>
25
26 #include "pbd/error.h"
27
28 #include "ardour/session.h"
29
30 #include "editor.h"
31 #include "region_view.h"
32 #include "selection.h"
33 #include "time_axis_view.h"
34
35 #include "pbd/i18n.h"
36
37 using namespace ARDOUR;
38 using namespace PBD;
39 using namespace Editing;
40
41 void
42 Editor::keyboard_selection_finish (bool /*add*/, Editing::EditIgnoreOption ign)
43 {
44         if (_session) {
45
46                 MusicFrame start (selection->time.start(), 0);
47                 framepos_t end;
48                 if ((_edit_point == EditAtPlayhead) && _session->transport_rolling()) {
49                         end = _session->audible_frame();
50                 } else {
51                         end = get_preferred_edit_position(ign);
52                 }
53
54                 //snap the selection start/end
55                 snap_to (start);
56
57                 //if no tracks are selected and we're working from the keyboard, enable all tracks (_something_ has to be selected for any range selection)
58                 if ( (_edit_point == EditAtPlayhead) && selection->tracks.empty() )
59                         select_all_tracks();
60
61                 selection->set (start.frame, end);
62
63                 //if session is playing a range, cancel that
64                 if (_session->get_play_range())
65                         _session->request_cancel_play_range();
66
67         }
68 }
69
70 void
71 Editor::keyboard_selection_begin (Editing::EditIgnoreOption ign)
72 {
73         if (_session) {
74
75                 MusicFrame start (0, 0);
76                 MusicFrame end (selection->time.end_frame(), 0);
77                 if ((_edit_point == EditAtPlayhead) && _session->transport_rolling()) {
78                         start.frame = _session->audible_frame();
79                 } else {
80                         start.frame = get_preferred_edit_position(ign);
81                 }
82
83                 //snap the selection start/end
84                 snap_to(start);
85
86                 //if there's not already a sensible selection endpoint, go "forever"
87                 if (start.frame > end.frame) {
88 #ifdef MIXBUS
89                         // 4hours at most.
90                         // This works around a visual glitch in red-bordered selection rect.
91                         end.frame = start.frame + _session->nominal_frame_rate() * 60 * 60 * 4;
92 #else
93                         end.frame = max_framepos;
94 #endif
95                 }
96
97                 //if no tracks are selected and we're working from the keyboard, enable all tracks (_something_ has to be selected for any range selection)
98                 if ( selection->tracks.empty() )
99                         select_all_tracks();
100
101                 selection->set (start.frame, end.frame);
102
103                 //if session is playing a range, cancel that
104                 if (_session->get_play_range())
105                         _session->request_cancel_play_range();
106         }
107 }
108
109 void
110 Editor::keyboard_paste ()
111 {
112         paste (1, false);
113 }