2900e28c2a48a5fc1235aebc4a1a45f0b4ed86d2
[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_transport_speed ( 1.0 );
103
104                 //if join playhead, locate to the newly selected start
105 //              if ( !_session->transport_rolling() && Config->get_join_play_range() )
106 //                      _session->request_cancel_play_range();
107         }
108 }
109
110 /*
111 void
112 Editor::keyboard_selection_finish (bool add)
113 {
114         if (_session && have_pending_keyboard_selection) {
115
116                 framepos_t end;
117                 bool ignored;
118
119                 if (_session->transport_rolling()) {
120                         end = _session->audible_frame();
121                 } else {
122                         if (!mouse_frame (end, ignored)) {
123                                 return;
124                         }
125                 }
126
127                 if (add) {
128                         selection->add (pending_keyboard_selection_start, end);
129                 } else {
130                         selection->set (pending_keyboard_selection_start, end);
131                 }
132
133                 have_pending_keyboard_selection = false;
134         }
135 }
136
137 void
138 Editor::keyboard_selection_begin ()
139 {
140         if (_session) {
141                 if (_session->transport_rolling()) {
142                         pending_keyboard_selection_start = _session->audible_frame();
143                         have_pending_keyboard_selection = true;
144                 } else {
145                         bool ignored;
146                         framepos_t where; // XXX fix me
147
148                         if (mouse_frame (where, ignored)) {
149                                 pending_keyboard_selection_start = where;
150                                 have_pending_keyboard_selection = true;
151                         }
152
153                 }
154         }
155 }*/
156
157 void
158 Editor::keyboard_paste ()
159 {
160         paste (1);
161 }