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