new keymouse action mute/unmute region (m)
[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 worldx, worldy;
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         if (use_track_canvas && track_canvas_event_box.get_window()->get_pointer(x, y, mask) != 0) {
38                 doit = true;
39         } else if (use_time_canvas && time_canvas_event_box.get_window()->get_pointer(x, y, mask)!= 0) {
40                 doit = true;
41         }
42
43         if (doit) {
44
45                 if (entered_regionview && can_select) {
46                         selection->set (entered_regionview);
47                 }
48
49                 track_canvas.window_to_world (x, y, worldx, worldy);
50                 worldx += horizontal_adjustment.get_value();
51                 worldy += vertical_adjustment.get_value();
52
53                 ev.type = GDK_BUTTON_PRESS;
54                 ev.button.x = worldx;
55                 ev.button.y = worldy;
56                 ev.button.state = 0;  /* XXX correct? */
57
58                 theslot (&ev);
59         }
60 }
61
62 void
63 Editor::kbd_set_playhead_cursor ()
64 {
65         kbd_driver (mem_fun(*this, &Editor::set_playhead_cursor), true, true, false);
66 }
67
68 void
69 Editor::kbd_set_edit_cursor ()
70 {
71         kbd_driver (mem_fun(*this, &Editor::set_edit_cursor), true, true, false);
72 }
73
74
75 void
76 Editor::kbd_do_split (GdkEvent* ev)
77 {
78         jack_nframes_t where = event_frame (ev);
79
80         if (entered_regionview) {
81                 if (selection->audio_regions.find (entered_regionview) != selection->audio_regions.end()) {
82                         split_regions_at (where, selection->audio_regions);
83                 } else {
84                         AudioRegionSelection s;
85                         s.add (entered_regionview);
86                         split_regions_at (where, s);
87                 }
88         }
89 }
90
91 void
92 Editor::kbd_split ()
93 {
94         kbd_driver (mem_fun(*this, &Editor::kbd_do_split), true, true, false);
95 }
96
97 void
98 Editor::kbd_mute_unmute_region ()
99 {
100         if (entered_regionview) {
101                entered_regionview->region.set_muted (!entered_regionview->region.muted());
102         }
103 }
104
105 void
106 Editor::kbd_set_sync_position ()
107 {
108         kbd_driver (mem_fun(*this, &Editor::kbd_do_set_sync_position), true, true, false);
109 }
110
111 void
112 Editor::kbd_do_set_sync_position (GdkEvent* ev)
113 {
114         jack_nframes_t where = event_frame (ev);
115         snap_to (where);
116
117         if (entered_regionview) {
118                 entered_regionview->region.set_sync_position (where);
119         }
120 }
121
122 void
123 Editor::kbd_do_align (GdkEvent* ev, ARDOUR::RegionPoint what)
124 {
125         align (what);
126 }
127
128 void
129 Editor::kbd_align (ARDOUR::RegionPoint what)
130 {
131         kbd_driver (bind (mem_fun(*this, &Editor::kbd_do_align), what));
132 }
133
134 void
135 Editor::kbd_do_align_relative (GdkEvent* ev, ARDOUR::RegionPoint what)
136 {
137         align (what);
138 }
139
140 void
141 Editor::kbd_align_relative (ARDOUR::RegionPoint what)
142 {
143         kbd_driver (bind (mem_fun(*this, &Editor::kbd_do_align), what), true, true, false);
144 }
145
146 void
147 Editor::kbd_do_brush (GdkEvent *ev)
148 {
149         brush (event_frame (ev, 0, 0));
150 }
151
152 void
153 Editor::kbd_brush ()
154 {
155         kbd_driver (mem_fun(*this, &Editor::kbd_do_brush), true, true, false);
156 }
157
158 void
159 Editor::kbd_do_audition (GdkEvent *ignored)
160 {
161         audition_selected_region ();
162 }
163
164 void
165 Editor::kbd_audition ()
166 {
167         kbd_driver (mem_fun(*this, &Editor::kbd_do_audition), true, false, true);
168 }