Compiles, but doesn't link. The link errors are mostly expected and are
[ardour.git] / gtk2_ardour / editor_keyboard.cc
1 /*
2     Copyright (C) 2004 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 <ardour/audioregion.h>
22 #include <ardour/playlist.h>
23 #include <pbd/memento_command.h>
24
25 #include "editor.h"
26 #include "regionview.h"
27 #include "selection.h"
28
29 #include "i18n.h"
30
31 void
32 Editor::kbd_driver (sigc::slot<void,GdkEvent*> theslot, bool use_track_canvas, bool use_time_canvas, bool can_select)
33 {
34         gint x, y;
35         double worldx, worldy;
36         GdkEvent ev;
37         Gdk::ModifierType mask;
38         Glib::RefPtr<Gdk::Window> evw = track_canvas.get_window()->get_pointer (x, y, mask);
39         bool doit = false;
40
41         if (use_track_canvas && track_canvas_event_box.get_window()->get_pointer(x, y, mask) != 0) {
42                 doit = true;
43         } else if (use_time_canvas && time_canvas_event_box.get_window()->get_pointer(x, y, mask)!= 0) {
44                 doit = true;
45         }
46
47         if (doit) {
48
49                 if (entered_regionview && can_select) {
50                         selection->set (entered_regionview);
51                 }
52
53                 track_canvas.window_to_world (x, y, worldx, worldy);
54                 worldx += horizontal_adjustment.get_value();
55                 worldy += vertical_adjustment.get_value();
56
57                 ev.type = GDK_BUTTON_PRESS;
58                 ev.button.x = worldx;
59                 ev.button.y = worldy;
60                 ev.button.state = 0;  /* XXX correct? */
61
62                 theslot (&ev);
63         }
64 }
65
66 void
67 Editor::kbd_set_playhead_cursor ()
68 {
69         kbd_driver (mem_fun(*this, &Editor::set_playhead_cursor), true, true, false);
70 }
71
72 void
73 Editor::kbd_set_edit_cursor ()
74 {
75         kbd_driver (mem_fun(*this, &Editor::set_edit_cursor), true, true, false);
76 }
77
78
79 void
80 Editor::kbd_do_split (GdkEvent* ev)
81 {
82         jack_nframes_t where = event_frame (ev);
83
84         if (entered_regionview) {
85                 if (selection->audio_regions.find (entered_regionview) != selection->audio_regions.end()) {
86                         split_regions_at (where, selection->audio_regions);
87                 } else {
88                         AudioRegionSelection s;
89                         s.add (entered_regionview);
90                         split_regions_at (where, s);
91                 }
92         }
93 }
94
95 void
96 Editor::kbd_split ()
97 {
98         kbd_driver (mem_fun(*this, &Editor::kbd_do_split), true, true, false);
99 }
100
101 void
102 Editor::kbd_mute_unmute_region ()
103 {
104         if (entered_regionview) {
105                 begin_reversible_command (_("mute region"));
106                 XMLNode &before = entered_regionview->region.playlist()->get_state();
107                 
108             entered_regionview->region.set_muted (!entered_regionview->region.muted());
109                 
110                 XMLNode &after = entered_regionview->region.playlist()->get_state();
111                 session->add_command (new MementoCommand<ARDOUR::Playlist>(*(entered_regionview->region.playlist()), before, after));
112                 commit_reversible_command();
113         }
114 }
115
116 void
117 Editor::kbd_set_sync_position ()
118 {
119         kbd_driver (mem_fun(*this, &Editor::kbd_do_set_sync_position), true, true, false);
120 }
121
122 void
123 Editor::kbd_do_set_sync_position (GdkEvent* ev)
124 {
125     jack_nframes_t where = event_frame (ev);
126         snap_to (where);
127
128         if (entered_regionview) {
129           set_a_regions_sync_position (entered_regionview->region, where);
130         }
131 }
132
133 void
134 Editor::kbd_do_align (GdkEvent* ev, ARDOUR::RegionPoint what)
135 {
136         align (what);
137 }
138
139 void
140 Editor::kbd_align (ARDOUR::RegionPoint what)
141 {
142         kbd_driver (bind (mem_fun(*this, &Editor::kbd_do_align), what));
143 }
144
145 void
146 Editor::kbd_do_align_relative (GdkEvent* ev, ARDOUR::RegionPoint what)
147 {
148         align (what);
149 }
150
151 void
152 Editor::kbd_align_relative (ARDOUR::RegionPoint what)
153 {
154         kbd_driver (bind (mem_fun(*this, &Editor::kbd_do_align), what), true, true, false);
155 }
156
157 void
158 Editor::kbd_do_brush (GdkEvent *ev)
159 {
160         brush (event_frame (ev, 0, 0));
161 }
162
163 void
164 Editor::kbd_brush ()
165 {
166         kbd_driver (mem_fun(*this, &Editor::kbd_do_brush), true, true, false);
167 }
168
169 void
170 Editor::kbd_do_audition (GdkEvent *ignored)
171 {
172         audition_selected_region ();
173 }
174
175 void
176 Editor::kbd_audition ()
177 {
178         kbd_driver (mem_fun(*this, &Editor::kbd_do_audition), true, false, true);
179 }