editor window layout changes, and lots more
[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
23 #include "editor.h"
24 #include "regionview.h"
25 #include "selection.h"
26
27 void
28 Editor::kbd_driver (sigc::slot<void,GdkEvent*> theslot, bool use_track_canvas, bool use_time_canvas, bool can_select)
29 {
30         gint x, y;
31         double dx, dy;
32         GdkEvent ev;
33         Gdk::ModifierType mask;
34         Glib::RefPtr<Gdk::Window> evw = track_canvas.get_window()->get_pointer (x, y, mask);
35         bool doit = false;
36
37         cerr << "editor keyboard driver\n";
38
39         if (use_track_canvas && track_canvas_event_box.get_window()->get_pointer(x, y, mask) != 0) {
40                 cerr << "in track canvas\n";
41                 doit = true;
42
43         } else if (use_time_canvas && time_canvas_event_box.get_window()->get_pointer(x, y, mask)!= 0) {
44                 cerr << "in time canvas\n";
45                 doit = true;
46         }
47
48         if (doit) {
49
50                 if (entered_regionview && can_select) {
51                         selection->set (entered_regionview);
52                 }
53
54                 track_canvas.c2w(x, y, dx, dy);
55                 ev.type = GDK_BUTTON_PRESS;
56                 ev.button.x = dx;
57                 ev.button.y = dy;
58                 ev.button.state = 0;  /* XXX correct? */
59
60                 theslot (&ev);
61         }
62 }
63
64 void
65 Editor::kbd_set_playhead_cursor ()
66 {
67         kbd_driver (mem_fun(*this, &Editor::set_playhead_cursor), true, true, false);
68 }
69
70 void
71 Editor::kbd_set_edit_cursor ()
72 {
73         kbd_driver (mem_fun(*this, &Editor::set_edit_cursor), true, true, false);
74 }
75
76
77 void
78 Editor::kbd_do_split (GdkEvent* ev)
79 {
80         jack_nframes_t where = event_frame (ev);
81
82         if (entered_regionview) {
83                 if (selection->audio_regions.find (entered_regionview) != selection->audio_regions.end()) {
84                         split_regions_at (where, selection->audio_regions);
85                 } else {
86                         AudioRegionSelection s;
87                         s.add (entered_regionview);
88                         split_regions_at (where, s);
89                 }
90         }
91 }
92
93 void
94 Editor::kbd_split ()
95 {
96         kbd_driver (mem_fun(*this, &Editor::kbd_do_split), true, true, false);
97 }
98
99 void
100 Editor::kbd_do_align (GdkEvent* ev, ARDOUR::RegionPoint what)
101 {
102         align (what);
103 }
104
105 void
106 Editor::kbd_align (ARDOUR::RegionPoint what)
107 {
108         kbd_driver (bind (mem_fun(*this, &Editor::kbd_do_align), what));
109 }
110
111 void
112 Editor::kbd_do_align_relative (GdkEvent* ev, ARDOUR::RegionPoint what)
113 {
114         align (what);
115 }
116
117 void
118 Editor::kbd_align_relative (ARDOUR::RegionPoint what)
119 {
120         kbd_driver (bind (mem_fun(*this, &Editor::kbd_do_align), what), true, true, false);
121 }
122
123 void
124 Editor::kbd_do_brush (GdkEvent *ev)
125 {
126         brush (event_frame (ev, 0, 0));
127 }
128
129 void
130 Editor::kbd_brush ()
131 {
132         kbd_driver (mem_fun(*this, &Editor::kbd_do_brush), true, true, false);
133 }
134
135 void
136 Editor::kbd_do_audition (GdkEvent *ignored)
137 {
138         audition_selected_region ();
139 }
140
141 void
142 Editor::kbd_audition ()
143 {
144         kbd_driver (mem_fun(*this, &Editor::kbd_do_audition), true, false, true);
145 }