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