Fix thinkos in cubasish theme
[ardour.git] / gtk2_ardour / editor_keys.cc
1 /*
2  * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
4  * Copyright (C) 2006-2012 David Robillard <d@drobilla.net>
5  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
6  * Copyright (C) 2014-2018 Ben Loftis <ben@harrisonconsoles.com>
7  * Copyright (C) 2015-2016 Robin Gareus <robin@gareus.org>
8  * Copyright (C) 2016-2017 Nick Mainsbridge <mainsbridge@gmail.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #include <cstdlib>
26 #include <cmath>
27 #include <string>
28
29 #include <gtkmm/treeview.h>
30
31 #include "pbd/error.h"
32
33 #include "ardour/session.h"
34
35 #include "editor.h"
36 #include "region_view.h"
37 #include "selection.h"
38 #include "time_axis_view.h"
39
40 #include "pbd/i18n.h"
41
42 using namespace ARDOUR;
43 using namespace PBD;
44 using namespace Editing;
45
46 void
47 Editor::keyboard_selection_finish (bool /*add*/, Editing::EditIgnoreOption ign)
48 {
49         if (_session) {
50
51                 MusicSample start (selection->time.start(), 0);
52                 samplepos_t end;
53                 if ((_edit_point == EditAtPlayhead) && _session->transport_rolling()) {
54                         end = _session->audible_sample();
55                 } else {
56                         end = get_preferred_edit_position(ign);
57                 }
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.sample, 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 (Editing::EditIgnoreOption ign)
74 {
75         if (_session) {
76
77                 MusicSample start (0, 0);
78                 MusicSample end (selection->time.end_sample(), 0);
79                 if ((_edit_point == EditAtPlayhead) && _session->transport_rolling()) {
80                         start.sample = _session->audible_sample();
81                 } else {
82                         start.sample = get_preferred_edit_position(ign);
83                 }
84
85                 //if there's not already a sensible selection endpoint, go "forever"
86                 if (start.sample > end.sample) {
87 #ifdef MIXBUS
88                         // 4hours at most.
89                         // This works around a visual glitch in red-bordered selection rect.
90                         end.sample = start.sample + _session->nominal_sample_rate() * 60 * 60 * 4;
91 #else
92                         end.sample = max_samplepos;
93 #endif
94                 }
95
96                 //if no tracks are selected and we're working from the keyboard, enable all tracks (_something_ has to be selected for any range selection)
97                 if ( selection->tracks.empty() )
98                         select_all_tracks();
99
100                 selection->set (start.sample, end.sample);
101
102                 //if session is playing a range, cancel that
103                 if (_session->get_play_range())
104                         _session->request_cancel_play_range();
105         }
106 }
107
108 void
109 Editor::keyboard_paste ()
110 {
111         paste (1, false);
112 }