r269@gandalf: fugalh | 2006-08-03 20:18:05 -0600
[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     $Id$
19 */
20
21 #include <cstdlib>
22 #include <cmath>
23 #include <string>
24
25 #include <pbd/error.h>
26
27 #include <ardour/session.h>
28 #include <ardour/region.h>
29
30 #include "ardour_ui.h"
31 #include "editor.h"
32 #include "time_axis_view.h"
33 #include "region_view.h"
34 #include "selection.h"
35
36 #include "i18n.h"
37
38 using namespace ARDOUR;
39 using namespace PBD;
40 using namespace sigc;
41
42 void
43 Editor::keyboard_selection_finish (bool add)
44 {
45         if (session && have_pending_keyboard_selection) {
46                 begin_reversible_command (_("keyboard selection"));
47                 if (add) {
48                         selection->add (pending_keyboard_selection_start, session->audible_frame());
49                 } else {
50                         selection->set (0, pending_keyboard_selection_start, session->audible_frame());
51                 }
52                 commit_reversible_command ();
53                 have_pending_keyboard_selection = false;
54         }
55 }
56
57 void
58 Editor::keyboard_selection_begin ()
59 {
60         if (session) {
61                 pending_keyboard_selection_start = session->audible_frame();
62                 have_pending_keyboard_selection = true;
63         }
64 }
65
66 void
67 Editor::keyboard_duplicate_region ()
68 {
69         if (selection->regions.empty()) {
70                 return;
71         }
72
73         float prefix;
74         bool was_floating;
75
76         if (get_prefix (prefix, was_floating) == 0) {
77                 duplicate_some_regions (selection->regions, prefix);
78         } else {
79                 duplicate_some_regions (selection->regions, 1);
80         }
81 }
82
83 void
84 Editor::keyboard_duplicate_selection ()
85 {
86         float prefix;
87         bool was_floating;
88
89         if (get_prefix (prefix, was_floating) == 0) {
90                 duplicate_selection (prefix);
91         } else {
92                 duplicate_selection (1);
93         }
94 }
95
96 void
97 Editor::keyboard_paste ()
98 {
99         float prefix;
100         bool was_floating;
101
102         if (get_prefix (prefix, was_floating) == 0) {
103                 paste (prefix);
104         } else {
105                 paste (1);
106         }
107 }
108
109 void
110 Editor::keyboard_insert_region_list_selection ()
111 {
112         float prefix;
113         bool was_floating;
114
115         if (get_prefix (prefix, was_floating) == 0) {
116                 insert_region_list_selection (prefix);
117         } else {
118                 insert_region_list_selection (1);
119         }
120 }
121
122 int
123 Editor::get_prefix (float& val, bool& was_floating)
124 {
125         return Keyboard::the_keyboard().get_prefix (val, was_floating);
126 }
127