Editing from a control surface must have the ability to ignore mouse location.
[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 "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                 framepos_t start = selection->time.start();
47                 framepos_t end;
48
49                 if ((_edit_point == EditAtPlayhead) && _session->transport_rolling()) {
50                         end = _session->audible_frame();
51                 } else {
52                         end = get_preferred_edit_position(ign);
53                 }
54
55                 //snap the selection start/end
56                 snap_to(start);
57
58                 //if no tracks are selected and we're working from the keyboard, enable all tracks (_something_ has to be selected for any range selection)
59                 if ( (_edit_point == EditAtPlayhead) && selection->tracks.empty() )
60                         select_all_tracks();
61
62                 selection->set (start, end);
63
64                 //if session is playing a range, cancel that
65                 if (_session->get_play_range())
66                         _session->request_cancel_play_range();
67
68         }
69 }
70
71 void
72 Editor::keyboard_selection_begin (Editing::EditIgnoreOption ign)
73 {
74         if (_session) {
75
76                 framepos_t start;
77                 framepos_t end = selection->time.end_frame();  //0 if no current selection
78
79                 if ((_edit_point == EditAtPlayhead) && _session->transport_rolling()) {
80 printf("if you don't wait a second, this wil be wrong");
81                         start = _session->audible_frame();
82                 } else {
83 printf("keyboard_selection_begin:: getting pref\n");
84                         start = get_preferred_edit_position(ign);
85                 }
86
87                 //snap the selection start/end
88                 snap_to(start);
89
90                 //if there's not already a sensible selection endpoint, go "forever"
91                 if ( start > end ) {
92                         end = max_framepos;
93                 }
94
95                 //if no tracks are selected and we're working from the keyboard, enable all tracks (_something_ has to be selected for any range selection)
96                 if ( selection->tracks.empty() )
97                         select_all_tracks();
98
99                 selection->set (start, end);
100
101                 //if session is playing a range, cancel that
102                 if (_session->get_play_range())
103                         _session->request_cancel_play_range();
104         }
105 }
106
107 void
108 Editor::keyboard_paste ()
109 {
110         paste (1);
111 }