Merge branch 'cairocanvas'
[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 "ardour_ui.h"
31 #include "editor.h"
32 #include "region_view.h"
33 #include "selection.h"
34 #include "time_axis_view.h"
35
36 #include "i18n.h"
37
38 using namespace ARDOUR;
39 using namespace PBD;
40 using namespace Editing;
41
42 void
43 Editor::keyboard_selection_finish (bool /*add*/)
44 {
45         if (_session) {
46
47                 framepos_t start = selection->time.start();
48                 framepos_t end;
49                 
50                 if ((_edit_point == EditAtPlayhead) && _session->transport_rolling()) {
51                         end = _session->audible_frame();
52                 } else {
53                         end = get_preferred_edit_position();
54                 }
55
56                 //snap the selection start/end
57                 snap_to(start);
58                 
59                 //if no tracks are selected and we're working from the keyboard, enable all tracks (_something_ has to be selected for any range selection)
60                 if ( (_edit_point == EditAtPlayhead) && selection->tracks.empty() )
61                         select_all_tracks();
62
63                 selection->set (start, end);
64
65                 //if session is playing a range, cancel that
66                 if (_session->get_play_range())
67                         _session->request_cancel_play_range();
68
69         }
70 }
71
72 void
73 Editor::keyboard_selection_begin ()
74 {
75         if (_session) {
76
77                 framepos_t start;
78                 framepos_t end = selection->time.end_frame();  //0 if no current selection
79
80                 if ((_edit_point == EditAtPlayhead) && _session->transport_rolling()) {
81                         start = _session->audible_frame();
82                 } else {
83                         start = get_preferred_edit_position();
84                 }
85                 
86                 //snap the selection start/end
87                 snap_to(start);
88                 
89                 //if there's not already a sensible selection endpoint, go "forever"
90                 if ( start > end ) {
91                         end = max_framepos;
92                 }
93                 
94                 //if no tracks are selected and we're working from the keyboard, enable all tracks (_something_ has to be selected for any range selection)
95                 if ( selection->tracks.empty() )
96                         select_all_tracks();
97                                         
98                 selection->set (start, end);
99
100                 //if session is playing a range, cancel that
101                 if (_session->get_play_range())
102                         _session->request_cancel_play_range();
103         }
104 }
105
106 void
107 Editor::keyboard_paste ()
108 {
109         paste (1);
110 }