69bfb3ba8af94bd395413ff016fd26ce0e30ae30
[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 */
19
20 #include "ardour/audioregion.h"
21 #include "ardour/playlist.h"
22 #include "ardour/location.h"
23
24 #include "pbd/memento_command.h"
25
26 #include "editor.h"
27 #include "region_view.h"
28 #include "selection.h"
29 #include "keyboard.h"
30 #include "editor_drag.h"
31
32 #include "i18n.h"
33
34 using namespace ARDOUR;
35
36 void
37 Editor::kbd_driver (sigc::slot<void,GdkEvent*> theslot, bool use_track_canvas, bool use_time_canvas, bool can_select)
38 {
39         gint x, y;
40         double worldx, worldy;
41         GdkEvent ev;
42         Gdk::ModifierType mask;
43         Glib::RefPtr<Gdk::Window> evw = track_canvas->get_window()->get_pointer (x, y, mask);
44         bool doit = false;
45
46         if (use_track_canvas && track_canvas_event_box.get_window()->get_pointer(x, y, mask) != 0) {
47                 doit = true;
48         } else if (use_time_canvas && time_canvas_event_box.get_window()->get_pointer(x, y, mask)!= 0) {
49                 doit = true;
50         }
51
52         /* any use of "keyboard mouse buttons" invalidates an existing grab
53         */
54         
55         if (_drag) {
56                 _drag->item()->ungrab (GDK_CURRENT_TIME);
57                 delete _drag;
58                 _drag = 0;
59         }
60
61         if (doit) {
62
63                 if (entered_regionview && can_select) {
64                         selection->set (entered_regionview);
65                 }
66
67                 track_canvas->window_to_world (x, y, worldx, worldy);
68                 worldx += horizontal_adjustment.get_value();
69                 worldy += vertical_adjustment.get_value();
70
71                 ev.type = GDK_BUTTON_PRESS;
72                 ev.button.x = worldx;
73                 ev.button.y = worldy;
74                 ev.button.state = 0;  /* XXX correct? */
75
76                 theslot (&ev);
77         }
78 }
79
80 void
81 Editor::kbd_mute_unmute_region ()
82 {
83         if (!selection->regions.empty ()) {
84
85                 if (selection->regions.size() > 1) {
86                         begin_reversible_command (_("mute regions"));
87                 } else {
88                         begin_reversible_command (_("mute region"));
89                 }
90
91                 for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
92
93                         XMLNode &before = (*i)->region()->playlist()->get_state ();
94                         (*i)->region()->set_muted (!(*i)->region()->muted ());
95                         XMLNode &after = (*i)->region()->playlist()->get_state ();
96
97                         session->add_command (new MementoCommand<ARDOUR::Playlist>(*((*i)->region()->playlist()), &before, &after));
98
99                 }
100
101                 commit_reversible_command ();
102
103         } else if (entered_regionview) {
104                 
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
117 void
118 Editor::kbd_do_brush (GdkEvent *ev)
119 {
120         brush (event_frame (ev, 0, 0));
121 }
122
123 void
124 Editor::kbd_brush ()
125 {
126         kbd_driver (mem_fun(*this, &Editor::kbd_do_brush), true, true, false);
127 }
128