fix a variety of unused argument errors noted by gcc 4.3.2 on x86
[ardour.git] / gtk2_ardour / region_editor.cc
1 /*
2     Copyright (C) 2001 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/session.h"
24 #include "ardour/region.h"
25 #include "ardour/playlist.h"
26 #include "ardour/utils.h"
27 #include "ardour/dB.h"
28 #include <gtkmm2ext/utils.h>
29 #include <cmath>
30
31 #include "region_editor.h"
32 #include "ardour_ui.h"
33 #include "utils.h"
34 #include "gui_thread.h"
35
36 #include "i18n.h"
37
38 using namespace ARDOUR;
39 using namespace PBD;
40 using namespace std;
41 using namespace Gtkmm2ext;
42
43 RegionEditor::RegionEditor (Session* s, boost::shared_ptr<Region> r)
44         : ArdourDialog (_("Region")),
45           _table (8, 2),
46           _region (r),
47           name_label (_("Name:")),
48           audition_button (_("Play")),
49           position_clock (X_("regionposition"), true, X_("RegionEditorClock"), true, false),
50           end_clock (X_("regionend"), true, X_("RegionEditorClock"), true, false),
51           length_clock (X_("regionlength"), true, X_("RegionEditorClock"), true, false, true),
52           sync_offset_relative_clock (X_("regionsyncoffsetrelative"), true, X_("RegionEditorClock"), true, false),
53           sync_offset_absolute_clock (X_("regionsyncoffsetabsolute"), true, X_("RegionEditorClock"), true, false),
54           /* XXX cannot file start yet */
55           start_clock (X_("regionstart"), true, X_("RegionEditorClock"), false, false)
56 {
57         set_session (s);
58         
59         position_clock.set_session (_session);
60         end_clock.set_session (_session);
61         length_clock.set_session (_session);
62         sync_offset_relative_clock.set_session (_session);
63         sync_offset_absolute_clock.set_session (_session);
64         start_clock.set_session (_session);
65
66         ARDOUR_UI::instance()->set_tip (audition_button, _("audition this region"));
67
68         audition_button.unset_flags (Gtk::CAN_FOCUS);
69
70         audition_button.set_events (audition_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
71
72         name_entry.set_name ("RegionEditorEntry");
73         name_label.set_name ("RegionEditorLabel");
74         position_label.set_name ("RegionEditorLabel");
75         position_label.set_text (_("Position:"));
76         end_label.set_name ("RegionEditorLabel");
77         end_label.set_text (_("End:"));
78         length_label.set_name ("RegionEditorLabel");
79         length_label.set_text (_("Length:"));
80         sync_relative_label.set_name ("RegionEditorLabel");
81         sync_relative_label.set_text (_("Sync point (relative to region):"));
82         sync_absolute_label.set_name ("RegionEditorLabel");
83         sync_absolute_label.set_text (_("Sync point (absolute):"));
84         start_label.set_name ("RegionEditorLabel");
85         start_label.set_text (_("File start:"));
86
87         _table.set_col_spacings (12);
88         _table.set_row_spacings (6);
89         _table.set_border_width (12);
90
91         name_label.set_alignment (1, 0.5);
92         position_label.set_alignment (1, 0.5);
93         end_label.set_alignment (1, 0.5);
94         length_label.set_alignment (1, 0.5);
95         sync_relative_label.set_alignment (1, 0.5);
96         sync_absolute_label.set_alignment (1, 0.5);
97         start_label.set_alignment (1, 0.5);
98
99         Gtk::HBox* nb = Gtk::manage (new Gtk::HBox);
100         nb->set_spacing (6);
101         nb->pack_start (name_entry);
102         nb->pack_start (audition_button);
103
104         _table.attach (name_label, 0, 1, 0, 1, Gtk::FILL, Gtk::FILL);
105         _table.attach (*nb, 1, 2, 0, 1, Gtk::FILL, Gtk::FILL);
106
107         _table.attach (position_label, 0, 1, 1, 2, Gtk::FILL, Gtk::FILL);
108         _table.attach (position_clock, 1, 2, 1, 2, Gtk::FILL, Gtk::FILL);
109
110         _table.attach (end_label, 0, 1, 2, 3, Gtk::FILL, Gtk::FILL);
111         _table.attach (end_clock, 1, 2, 2, 3, Gtk::FILL, Gtk::FILL);
112         
113         _table.attach (length_label, 0, 1, 3, 4, Gtk::FILL, Gtk::FILL);
114         _table.attach (length_clock, 1, 2, 3, 4, Gtk::FILL, Gtk::FILL);
115         
116         _table.attach (sync_relative_label, 0, 1, 4, 5, Gtk::FILL, Gtk::FILL);
117         _table.attach (sync_offset_relative_clock, 1, 2, 4, 5, Gtk::FILL, Gtk::FILL);
118  
119         _table.attach (sync_absolute_label, 0, 1, 5, 6, Gtk::FILL, Gtk::FILL);
120         _table.attach (sync_offset_absolute_clock, 1, 2, 5, 6, Gtk::FILL, Gtk::FILL);
121
122         _table.attach (start_label, 0, 1, 6, 7, Gtk::FILL, Gtk::FILL);
123         _table.attach (start_clock, 1, 2, 6, 7, Gtk::FILL, Gtk::FILL);
124
125         get_vbox()->pack_start (_table, true, true);
126
127         add_button (Gtk::Stock::CLOSE, Gtk::RESPONSE_ACCEPT);
128
129         set_name ("RegionEditorWindow");
130         add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
131
132         signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (this)));
133         signal_response().connect (sigc::mem_fun (*this, &RegionEditor::handle_response));
134
135         set_title (string_compose (_("Region '%1'"), _region->name()));
136
137         show_all();
138
139         name_changed ();
140
141         PropertyChange change;
142
143         change.add (ARDOUR::Properties::start);
144         change.add (ARDOUR::Properties::length);
145         change.add (ARDOUR::Properties::position);
146         change.add (ARDOUR::Properties::sync_position);
147
148         bounds_changed (change);
149
150         _region->PropertyChanged.connect (state_connection, invalidator (*this), ui_bind (&RegionEditor::region_changed, this, _1), gui_context());
151
152         spin_arrow_grab = false;
153
154         connect_editor_events ();
155 }
156
157 void
158 RegionEditor::region_changed (const PBD::PropertyChange& what_changed)
159 {
160         if (what_changed.contains (ARDOUR::Properties::name)) {
161                 name_changed ();
162         }
163
164         PropertyChange interesting_stuff;
165
166         interesting_stuff.add (ARDOUR::Properties::position);
167         interesting_stuff.add (ARDOUR::Properties::length);
168         interesting_stuff.add (ARDOUR::Properties::start);
169         interesting_stuff.add (ARDOUR::Properties::sync_position);
170
171         if (what_changed.contains (interesting_stuff)) {
172                 bounds_changed (what_changed);
173         }
174 }
175
176 gint
177 RegionEditor::bpressed (GdkEventButton* ev, Gtk::SpinButton* /*but*/, void (RegionEditor::*/*pmf*/)())
178 {
179         switch (ev->button) {
180         case 1:
181         case 2:
182         case 3:
183                 if (ev->type == GDK_BUTTON_PRESS) { /* no double clicks here */
184                         if (!spin_arrow_grab) {
185                                 // GTK2FIX probably nuke the region editor
186                                 // if ((ev->window == but->gobj()->panel)) {
187                                 // spin_arrow_grab = true;
188                                 // (this->*pmf)();
189                                 // }
190                         }
191                 }
192                 break;
193         default:
194                 break;
195         }
196         return FALSE;
197 }
198
199 gint
200 RegionEditor::breleased (GdkEventButton* /*ev*/, Gtk::SpinButton* /*but*/, void (RegionEditor::*pmf)())
201 {
202         if (spin_arrow_grab) {
203                 (this->*pmf)();
204                 spin_arrow_grab = false;
205         }
206         return FALSE;
207 }
208
209 void
210 RegionEditor::connect_editor_events ()
211 {
212         name_entry.signal_changed().connect (sigc::mem_fun(*this, &RegionEditor::name_entry_changed));
213
214         position_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::position_clock_changed));
215         end_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::end_clock_changed));
216         length_clock.ValueChanged.connect (sigc::mem_fun(*this, &RegionEditor::length_clock_changed));
217         sync_offset_absolute_clock.ValueChanged.connect (sigc::mem_fun (*this, &RegionEditor::sync_offset_absolute_clock_changed));
218         sync_offset_relative_clock.ValueChanged.connect (sigc::mem_fun (*this, &RegionEditor::sync_offset_relative_clock_changed));
219
220         audition_button.signal_toggled().connect (sigc::mem_fun(*this, &RegionEditor::audition_button_toggled));
221
222         _session->AuditionActive.connect (audition_connection, invalidator (*this), ui_bind (&RegionEditor::audition_state_changed, this, _1), gui_context());
223 }
224
225 void
226 RegionEditor::position_clock_changed ()
227 {
228         _session->begin_reversible_command (_("change region start position"));
229
230         boost::shared_ptr<Playlist> pl = _region->playlist();
231
232         if (pl) {
233                 _region->clear_changes ();
234                 _region->set_position (position_clock.current_time(), this);
235                 _session->add_command(new StatefulDiffCommand (_region));
236         }
237
238         _session->commit_reversible_command ();
239 }
240
241 void
242 RegionEditor::end_clock_changed ()
243 {
244         _session->begin_reversible_command (_("change region end position"));
245
246         boost::shared_ptr<Playlist> pl = _region->playlist();
247
248         if (pl) {
249                 _region->clear_changes ();
250                 _region->trim_end (end_clock.current_time(), this);
251                 _session->add_command(new StatefulDiffCommand (_region));
252         }
253
254         _session->commit_reversible_command ();
255
256         end_clock.set (_region->position() + _region->length() - 1, true);
257 }
258
259 void
260 RegionEditor::length_clock_changed ()
261 {
262         nframes_t frames = length_clock.current_time();
263
264         _session->begin_reversible_command (_("change region length"));
265
266         boost::shared_ptr<Playlist> pl = _region->playlist();
267
268         if (pl) {
269                 _region->clear_changes ();
270                 _region->trim_end (_region->position() + frames - 1, this);
271                 _session->add_command(new StatefulDiffCommand (_region));
272         }
273
274         _session->commit_reversible_command ();
275
276         length_clock.set (_region->length());
277 }
278
279 void
280 RegionEditor::audition_button_toggled ()
281 {
282         if (audition_button.get_active()) {
283                 _session->audition_region (_region);
284         } else {
285                 _session->cancel_audition ();
286         }
287 }
288
289 void
290 RegionEditor::name_changed ()
291 {
292         if (name_entry.get_text() != _region->name()) {
293                 name_entry.set_text (_region->name());
294         }
295 }
296
297 void
298 RegionEditor::bounds_changed (const PropertyChange& what_changed)
299 {
300         if (what_changed.contains (ARDOUR::Properties::position) && what_changed.contains (ARDOUR::Properties::length)) {
301                 position_clock.set (_region->position(), true);
302                 end_clock.set (_region->position() + _region->length() - 1, true);
303                 length_clock.set (_region->length(), true);
304         } else if (what_changed.contains (ARDOUR::Properties::position)) {
305                 position_clock.set (_region->position(), true);
306                 end_clock.set (_region->position() + _region->length() - 1, true);
307         } else if (what_changed.contains (ARDOUR::Properties::length)) {
308                 end_clock.set (_region->position() + _region->length() - 1, true);
309                 length_clock.set (_region->length(), true);
310         }
311
312         if (what_changed.contains (ARDOUR::Properties::sync_position) || what_changed.contains (ARDOUR::Properties::position)) {
313                 int dir;
314                 nframes_t off = _region->sync_offset (dir);
315                 if (dir == -1) {
316                         off = -off;
317                 }
318
319                 if (what_changed.contains (ARDOUR::Properties::sync_position)) {
320                         sync_offset_relative_clock.set (off, true);
321                 }
322
323                 sync_offset_absolute_clock.set (off + _region->position (), true);
324         }
325
326         if (what_changed.contains (ARDOUR::Properties::start)) {
327                 start_clock.set (_region->start(), true);
328         }
329 }
330
331 void
332 RegionEditor::activation ()
333 {
334
335 }
336
337 void
338 RegionEditor::name_entry_changed ()
339 {
340         if (name_entry.get_text() != _region->name()) {
341                 _region->set_name (name_entry.get_text());
342         }
343 }
344
345 void
346 RegionEditor::audition_state_changed (bool yn)
347 {
348         ENSURE_GUI_THREAD (*this, &RegionEditor::audition_state_changed, yn)
349
350         if (!yn) {
351                 audition_button.set_active (false);
352         }
353 }
354
355 void
356 RegionEditor::sync_offset_absolute_clock_changed ()
357 {
358         _session->begin_reversible_command (_("change region sync point"));
359
360         _region->clear_changes ();
361         _region->set_sync_position (sync_offset_absolute_clock.current_time());
362         _session->add_command (new StatefulDiffCommand (_region));
363         
364         _session->commit_reversible_command ();
365 }
366
367 void
368 RegionEditor::sync_offset_relative_clock_changed ()
369 {
370         _session->begin_reversible_command (_("change region sync point"));
371
372         _region->clear_changes ();
373         _region->set_sync_position (sync_offset_relative_clock.current_time() + _region->position ());
374         _session->add_command (new StatefulDiffCommand (_region));
375         
376         _session->commit_reversible_command ();
377 }
378
379 bool
380 RegionEditor::on_delete_event (GdkEventAny*)
381 {
382         PropertyChange change;
383
384         change.add (ARDOUR::Properties::start);
385         change.add (ARDOUR::Properties::length);
386         change.add (ARDOUR::Properties::position);
387         change.add (ARDOUR::Properties::sync_position);
388
389         bounds_changed (change);
390
391         return true;
392 }
393
394 void
395 RegionEditor::handle_response (int)
396 {
397         hide ();
398 }