a few more header files fixes, plus cleanup from nick_m, and the start of Action...
[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     $Id$
19 */
20
21 #include <ardour/audioregion.h>
22 #include <ardour/utils.h>
23 #include <gtkmm2ext/utils.h>
24 #include <gtkmm2ext/stop_signal.h>
25 #include <cmath>
26
27 #include "region_editor.h"
28 #include "regionview.h"
29 #include "ardour_ui.h"
30 #include "utils.h"
31
32 #include "i18n.h"
33
34 using namespace ARDOUR;
35 using namespace sigc;
36 using namespace std;
37
38 AudioRegionEditor::AudioRegionEditor (Session&s, AudioRegion& r, AudioRegionView& rv)
39         : ArdourDialog ("audio region editor"),
40           _session (s),
41           _region (r),
42           _region_view (rv),
43           name_label (_("NAME:")),
44           lock_button (_("lock")),
45           mute_button (_("mute")),
46           opaque_button (_("opaque")),
47           raise_arrow (Gtk::ARROW_UP, Gtk::SHADOW_OUT),
48           lower_arrow (Gtk::ARROW_DOWN, Gtk::SHADOW_OUT),
49           layer_label (_("Layer")),
50           audition_label (_("play")),
51           time_table (3, 2),
52           start_clock ("AudioRegionEditorClock", true),
53           end_clock ("AudioRegionEditorClock", true),
54           length_clock ("AudioRegionEditorClock", true, true),
55           sync_offset_clock ("AudioRegionEditorClock", true, true),
56           envelope_loop_table (1, 3),
57           envelope_label (_("ENVELOPE")),
58           fade_in_table (4, 3),
59           fade_in_length_adjustment (5.0, 0.0, 10000, 0.05, 1),
60           fade_in_length_spinner (fade_in_length_adjustment, 10),
61           fade_out_table (4, 3),
62           fade_out_length_adjustment (5.0, 0.0, 10000, 0.05, 1),
63           fade_out_length_spinner (fade_out_length_adjustment, 10)
64
65 {
66         start_clock.set_session (&_session);
67         end_clock.set_session (&_session);
68         length_clock.set_session (&_session);
69
70         name_entry.set_name ("AudioRegionEditorEntry");
71         name_label.set_name ("AudioRegionEditorLabel");
72
73         name_entry.signal_focus_in_event().connect (mem_fun(*this, &AudioRegionEditor::focus_change));
74         name_entry.signal_focus_out_event().connect (mem_fun(*this, &AudioRegionEditor::focus_change));
75         
76         name_hbox.set_spacing (5);
77         name_hbox.pack_start (name_label, false, false);
78         name_hbox.pack_start (name_entry, false, false);
79
80         raise_button.add (raise_arrow);
81         lower_button.add (lower_arrow);
82         layer_frame.set_name ("BaseFrame");
83         layer_frame.set_shadow_type (Gtk::SHADOW_IN);
84         layer_frame.add (layer_value_label);
85         layer_label.set_name ("AudioRegionEditorLabel");
86         layer_value_label.set_name ("AudioRegionEditorLabel");
87         Gtkmm2ext::set_size_request_to_display_given_text (layer_value_label, "99", 5, 2);
88
89         layer_hbox.set_spacing (5);
90         layer_hbox.pack_start (layer_label, false, false);
91         layer_hbox.pack_start (layer_frame, false, false);
92 #if 0
93         layer_hbox.pack_start (raise_button, false, false);
94         layer_hbox.pack_start (lower_button, false, false);
95 #endif
96
97         audition_button.add (audition_label);
98
99         mute_button.set_name ("AudioRegionEditorToggleButton");
100         opaque_button.set_name ("AudioRegionEditorToggleButton");
101         lock_button.set_name ("AudioRegionEditorToggleButton");
102         envelope_active_button.set_name ("AudioRegionEditorToggleButton");
103         envelope_view_button.set_name ("AudioRegionEditorToggleButton");
104         fade_in_active_button.set_name ("AudioRegionEditorToggleButton");
105         fade_out_active_button.set_name ("AudioRegionEditorToggleButton");
106         audition_button.set_name ("AudioRegionEditorToggleButton");
107
108         ARDOUR_UI::instance()->tooltips().set_tip (mute_button, _("mute this region"));
109         ARDOUR_UI::instance()->tooltips().set_tip (opaque_button, _("regions underneath this one cannot be heard"));
110         ARDOUR_UI::instance()->tooltips().set_tip (lock_button, _("prevent any changes to this region"));
111         ARDOUR_UI::instance()->tooltips().set_tip (envelope_active_button, _("use the gain envelope during playback"));
112         ARDOUR_UI::instance()->tooltips().set_tip (envelope_view_button, _("show the gain envelope"));
113         ARDOUR_UI::instance()->tooltips().set_tip (fade_in_active_button, _("use fade in curve during playback"));
114         ARDOUR_UI::instance()->tooltips().set_tip (fade_out_active_button, _("use fade out curve during playback"));
115         ARDOUR_UI::instance()->tooltips().set_tip (audition_button, _("audition this region"));
116
117         mute_button.unset_flags (Gtk::CAN_FOCUS);
118         opaque_button.unset_flags (Gtk::CAN_FOCUS);
119         lock_button.unset_flags (Gtk::CAN_FOCUS);
120         envelope_active_button.unset_flags (Gtk::CAN_FOCUS);
121         envelope_view_button.unset_flags (Gtk::CAN_FOCUS);
122         fade_in_active_button.unset_flags (Gtk::CAN_FOCUS);
123         fade_out_active_button.unset_flags (Gtk::CAN_FOCUS);
124         audition_button.unset_flags (Gtk::CAN_FOCUS);
125         
126         mute_button.set_events (mute_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
127         opaque_button.set_events (opaque_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
128         lock_button.set_events (lock_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
129         envelope_active_button.set_events (envelope_active_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
130         envelope_view_button.set_events (envelope_view_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
131         fade_in_active_button.set_events (fade_in_active_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
132         fade_out_active_button.set_events (fade_out_active_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
133         audition_button.set_events (audition_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
134
135         top_row_button_hbox.set_border_width (5);
136         top_row_button_hbox.set_spacing (5);
137         top_row_button_hbox.set_homogeneous (false);
138         top_row_button_hbox.pack_start (mute_button, false, false);
139         top_row_button_hbox.pack_start (opaque_button, false, false);
140         top_row_button_hbox.pack_start (lock_button, false, false);
141         top_row_button_hbox.pack_start (layer_hbox, false, false, 5);
142         top_row_button_hbox.pack_end (audition_button, false, false);
143         
144         top_row_hbox.pack_start (name_hbox, true, true);
145         top_row_hbox.pack_end (top_row_button_hbox, true, true);
146
147         start_label.set_name ("AudioRegionEditorLabel");
148         start_label.set_text (_("START:"));
149         end_label.set_name ("AudioRegionEditorLabel");
150         end_label.set_text (_("END:"));
151         length_label.set_name ("AudioRegionEditorLabel");
152         length_label.set_text (_("LENGTH:"));
153         
154         time_table.set_col_spacings (2);
155         time_table.set_row_spacings (5);
156         time_table.set_border_width (5);
157
158         start_alignment.set (1.0, 0.5);
159         end_alignment.set (1.0, 0.5);
160         length_alignment.set (1.0, 0.5);
161
162         start_alignment.add (start_label);
163         end_alignment.add (end_label);
164         length_alignment.add (length_label);
165
166         time_table.attach (start_alignment, 0, 1, 0, 1, Gtk::FILL, Gtk::FILL);
167         time_table.attach (start_clock, 1, 2, 0, 1, Gtk::FILL, Gtk::FILL);
168
169         time_table.attach (end_alignment, 0, 1, 1, 2, Gtk::FILL, Gtk::FILL);
170         time_table.attach (end_clock, 1, 2, 1, 2, Gtk::FILL, Gtk::FILL);
171
172         time_table.attach (length_alignment, 0, 1, 2, 3, Gtk::FILL, Gtk::FILL);
173         time_table.attach (length_clock, 1, 2, 2, 3, Gtk::FILL, Gtk::FILL);
174
175         envelope_label.set_name ("AudioRegionEditorLabel");
176
177         envelope_active_button_label.set_text (_("active"));
178         envelope_active_button.add (envelope_active_button_label);
179         envelope_view_button_label.set_text (_("visible"));
180         envelope_view_button.add (envelope_view_button_label);
181
182         envelope_loop_table.set_border_width (5);
183         envelope_loop_table.set_row_spacings (2);
184         envelope_loop_table.attach (envelope_label, 0, 1, 0, 1, Gtk::FILL, Gtk::FILL);
185         envelope_loop_table.attach (envelope_active_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
186         envelope_loop_table.attach (envelope_view_button, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
187
188         /* fade in */
189
190         fade_in_table.set_border_width (5);
191         fade_in_table.set_homogeneous (false);
192
193         fade_in_label.set_name ("AudioRegionEditorLabel");
194         fade_in_active_button_label.set_name ("AudioRegionEditorSmallLabel");
195         fade_in_length_label.set_name ("AudioRegionEditorSmallLabel");
196
197         fade_in_label.set_text (_("FADE IN"));
198         fade_in_active_button_label.set_text (_("active"));
199         fade_in_length_label.set_text (_("msecs"));
200
201         fade_in_active_button.add (fade_in_active_button_label);
202
203         fade_in_length_spinner.set_name("GenericSpinner");
204
205         fade_in_length_spinner.set_digits (3);
206
207         fade_in_length_spinner.signal_focus_in_event().connect (mem_fun(*this, &AudioRegionEditor::focus_change));
208         fade_in_length_spinner.signal_focus_out_event().connect (mem_fun(*this, &AudioRegionEditor::focus_change));
209         fade_in_length_spinner.signal_activate().connect (mem_fun(*this, &AudioRegionEditor::activation));
210
211         Gtkmm2ext::set_size_request_to_display_given_text (fade_in_length_spinner, "500g", 20, -1);
212
213         fade_in_label_align.add (fade_in_label);
214         fade_in_label_align.set (0.5);
215
216
217         fade_in_table.attach (fade_in_label_align,   0, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
218
219         fade_in_table.attach (fade_in_length_label,   0, 1, 1, 2, Gtk::EXPAND, Gtk::FILL);
220         fade_in_table.attach (fade_in_length_spinner, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
221
222         fade_in_table.attach (fade_in_active_button,        0, 2, 3, 5, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
223
224         /* fade out */
225
226         fade_out_table.set_border_width (5);
227         fade_out_table.set_homogeneous (false);
228
229         fade_out_label.set_name ("AudioRegionEditorLabel");
230         fade_out_active_button_label.set_name ("AudioRegionEditorSmallLabel");
231         fade_out_length_label.set_name ("AudioRegionEditorSmallLabel");
232
233         fade_out_label.set_text (_("FADE OUT"));
234         fade_out_active_button_label.set_text (_("active"));
235         fade_out_length_label.set_text (_("msecs"));
236
237         fade_out_active_button.add (fade_out_active_button_label);
238
239         fade_out_length_spinner.set_name("GenericSpinner");
240         
241         fade_out_length_spinner.set_digits (3);
242
243         fade_out_length_spinner.signal_focus_in_event().connect (mem_fun(*this, &AudioRegionEditor::focus_change));
244         fade_out_length_spinner.signal_focus_out_event().connect (mem_fun(*this, &AudioRegionEditor::focus_change));
245         fade_out_length_spinner.signal_activate().connect (mem_fun(*this, &AudioRegionEditor::activation));
246
247         Gtkmm2ext::set_size_request_to_display_given_text (fade_out_length_spinner, "500g", 20, -1);
248
249         fade_out_label_align.add (fade_out_label);
250         fade_out_label_align.set (0.5);
251
252         fade_out_table.attach (fade_out_label_align,   0, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
253
254         fade_out_table.attach (fade_out_length_label,   0, 1, 1, 2, Gtk::EXPAND, Gtk::FILL);
255         fade_out_table.attach (fade_out_length_spinner, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
256
257         fade_out_table.attach (fade_out_active_button,        0, 2, 3, 5, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
258
259         lower_hbox.pack_start (time_table, true, true);
260         lower_hbox.pack_start (sep1, false, false);
261         lower_hbox.pack_start (envelope_loop_table, true, true);
262         lower_hbox.pack_start (sep2, false, false);
263         lower_hbox.pack_start (fade_in_table, true, true);
264         lower_hbox.pack_start (fade_out_table, true, true);
265
266         upper_vbox.pack_start (top_row_hbox, true, true);
267         upper_vbox.pack_start (sep3, false, false);
268         upper_vbox.pack_start (lower_hbox, true, true);
269
270         add (upper_vbox);
271         set_name ("AudioRegionEditorWindow");
272         add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
273
274         signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (this)));
275
276         string title = _("ardour: region ");
277         title += _region.name();
278         set_title (title);
279
280         name_changed ();
281         bounds_changed (Change (StartChanged|LengthChanged|PositionChanged));
282         envelope_active_changed ();
283         mute_changed ();
284         opacity_changed ();
285         lock_changed ();
286         layer_changed ();
287         fade_in_changed ();
288         fade_out_changed ();
289
290         XMLNode *node  = _region.extra_xml ("GUI");
291         XMLProperty *prop = 0;
292         bool showing_envelope = false;
293
294         if (node && (prop = node->property ("envelope-visible")) != 0) {
295                 if (prop->value() == "yes") {
296                         showing_envelope = true;
297                 } 
298         } 
299
300         if (showing_envelope) {
301                 envelope_view_button.set_active (true);
302         } else {
303                 envelope_view_button.set_active (false);
304         }
305
306         _region.StateChanged.connect (mem_fun(*this, &AudioRegionEditor::region_changed));
307         
308         spin_arrow_grab = false;
309         
310         connect_editor_events ();
311 }
312
313 AudioRegionEditor::~AudioRegionEditor ()
314 {
315 }
316
317 void
318 AudioRegionEditor::region_changed (Change what_changed)
319 {
320         if (what_changed & NameChanged) {
321                 name_changed ();
322         }
323         if (what_changed & BoundsChanged) {
324                 bounds_changed (what_changed);
325         }
326
327         if (what_changed & Region::OpacityChanged) {
328                 opacity_changed ();
329         }
330         if (what_changed & Region::MuteChanged) {
331                 mute_changed ();
332         }
333         if (what_changed & Region::LockChanged) {
334                 lock_changed ();
335         }
336         if (what_changed & Region::LayerChanged) {
337                 layer_changed ();
338         }
339
340         if (what_changed & AudioRegion::EnvelopeActiveChanged) {
341                 envelope_active_changed ();
342         }
343         if (what_changed & AudioRegion::FadeInChanged) {
344                 fade_in_changed ();
345         }
346         if (what_changed & AudioRegion::FadeOutChanged) {
347                 fade_out_changed ();
348         }
349         if (what_changed & AudioRegion::FadeInActiveChanged) {
350                 fade_in_active_changed ();
351         }
352         if (what_changed & AudioRegion::FadeOutActiveChanged) {
353                 fade_out_active_changed ();
354         }
355 }
356
357 void
358 AudioRegionEditor::fade_in_realized ()
359 {
360         fade_in_changed ();
361 }
362
363 void
364 AudioRegionEditor::fade_out_realized ()
365 {
366         fade_out_changed ();
367 }
368
369 gint 
370 AudioRegionEditor::bpressed (GdkEventButton* ev, Gtk::SpinButton* but, void (AudioRegionEditor::*pmf)())
371 {
372         switch (ev->button) {
373         case 1:
374         case 2:
375         case 3:
376                 if (ev->type == GDK_BUTTON_PRESS) { /* no double clicks here */
377                         if (!spin_arrow_grab) {
378                                 if ((ev->window == but->gobj()->panel)) {
379                                         spin_arrow_grab = true;
380                                         (this->*pmf)();
381                                 } 
382                         } 
383                 } 
384                 break;
385         default:
386                 break;
387         }
388         return FALSE;
389 }
390
391 gint 
392 AudioRegionEditor::breleased (GdkEventButton* ev, Gtk::SpinButton* but, void (AudioRegionEditor::*pmf)())
393 {
394         if (spin_arrow_grab) {
395                 (this->*pmf)();
396                 spin_arrow_grab = false;
397         }
398         return FALSE;
399 }
400
401 void
402 AudioRegionEditor::start_editing_fade_in ()
403 {
404         _region.freeze ();
405 }
406
407 void
408 AudioRegionEditor::stop_editing_fade_in ()
409 {
410         _region.thaw (_("fade in edit"));
411 }
412
413 void
414 AudioRegionEditor::start_editing_fade_out ()
415 {
416         _region.freeze ();
417 }
418
419 void
420 AudioRegionEditor::stop_editing_fade_out ()
421 {
422         _region.thaw (_("fade out edit"));
423 }
424
425 void
426 AudioRegionEditor::connect_editor_events ()
427 {
428   name_entry.signal_changed().connect (mem_fun(*this, &AudioRegionEditor::name_entry_changed));
429
430         start_clock.ValueChanged.connect (mem_fun(*this, &AudioRegionEditor::start_clock_changed));
431         end_clock.ValueChanged.connect (mem_fun(*this, &AudioRegionEditor::end_clock_changed));
432         length_clock.ValueChanged.connect (mem_fun(*this, &AudioRegionEditor::length_clock_changed));
433
434         fade_in_length_spinner.signal_button_press_event().connect (bind (mem_fun(*this, &AudioRegionEditor::bpressed), &fade_in_length_spinner, 
435                                                                  &AudioRegionEditor::start_editing_fade_in));
436         fade_in_length_spinner.signal_button_release_event().connect (bind (mem_fun (*this, &AudioRegionEditor::breleased), &fade_in_length_spinner, 
437                                                                    &AudioRegionEditor::stop_editing_fade_in));
438
439         fade_out_length_spinner.signal_button_press_event().connect (bind (mem_fun(*this, &AudioRegionEditor::bpressed), &fade_out_length_spinner, 
440                                                                  &AudioRegionEditor::start_editing_fade_out));
441         fade_out_length_spinner.signal_button_release_event().connect (bind (mem_fun (*this, &AudioRegionEditor::breleased), &fade_out_length_spinner, 
442                                                                    &AudioRegionEditor::stop_editing_fade_out));
443
444         fade_in_length_adjustment.signal_value_changed().connect (mem_fun(*this, &AudioRegionEditor::fade_in_length_adjustment_changed));
445         fade_out_length_adjustment.signal_value_changed().connect (mem_fun(*this, &AudioRegionEditor::fade_out_length_adjustment_changed));
446
447         fade_in_active_button.signal_toggled().connect (mem_fun(*this, &AudioRegionEditor::fade_in_active_toggled));
448         fade_out_active_button.signal_toggled().connect (mem_fun(*this, &AudioRegionEditor::fade_out_active_toggled));
449
450         envelope_active_button.signal_button_press_event().connect (mem_fun(*this, &AudioRegionEditor::envelope_active_button_press));
451         envelope_active_button.signal_button_release_event().connect (mem_fun(*this, &AudioRegionEditor::envelope_active_button_release));
452         audition_button.signal_toggled().connect (mem_fun(*this, &AudioRegionEditor::audition_button_toggled));
453         envelope_view_button.signal_toggled().connect (mem_fun(*this, &AudioRegionEditor::envelope_view_button_toggled));
454         lock_button.signal_clicked().connect (mem_fun(*this, &AudioRegionEditor::lock_button_clicked));
455         mute_button.signal_clicked().connect (mem_fun(*this, &AudioRegionEditor::mute_button_clicked));
456         opaque_button.signal_clicked().connect (mem_fun(*this, &AudioRegionEditor::opaque_button_clicked));
457         raise_button.signal_clicked().connect (mem_fun(*this, &AudioRegionEditor::raise_button_clicked));
458         lower_button.signal_clicked().connect (mem_fun(*this, &AudioRegionEditor::lower_button_clicked));
459 }
460
461 void
462 AudioRegionEditor::start_clock_changed ()
463 {
464         _region.set_position (start_clock.current_time(), this);
465 }
466
467 void
468 AudioRegionEditor::end_clock_changed ()
469 {
470         _region.trim_end (end_clock.current_time(), this);
471
472         end_clock.set (_region.position() + _region.length(), true);
473 }
474
475 void
476 AudioRegionEditor::length_clock_changed ()
477 {
478         jack_nframes_t frames = length_clock.current_time();
479         _region.trim_end (_region.position() + frames, this);
480
481         length_clock.set (_region.length());
482 }
483
484 gint
485 AudioRegionEditor::envelope_active_button_press(GdkEventButton *ev)
486 {
487         return stop_signal (envelope_active_button, "button_press_event");
488 }
489
490 gint
491 AudioRegionEditor::envelope_active_button_release (GdkEventButton *ev)
492 {
493         _region.set_envelope_active (!_region.envelope_active());
494         return stop_signal (envelope_active_button, "button_release_event");
495 }
496
497 void
498 AudioRegionEditor::envelope_view_button_toggled ()
499 {
500         bool visible = envelope_view_button.get_active ();
501
502         _region_view.set_envelope_visible (visible);
503 }
504
505 void
506 AudioRegionEditor::audition_button_toggled ()
507 {
508         if (audition_button.get_active()) {
509                 _session.audition_region (_region);
510         } else {
511                 _session.cancel_audition ();
512         }
513 }
514
515 void
516 AudioRegionEditor::raise_button_clicked ()
517 {
518         _region.raise ();
519 }
520
521 void
522 AudioRegionEditor::lower_button_clicked ()
523 {
524         _region.lower ();
525 }
526
527 void
528 AudioRegionEditor::opaque_button_clicked ()
529 {
530         bool ractive = _region.opaque();
531
532         if (opaque_button.get_active() != ractive) {
533                 _region.set_opaque (!ractive);
534         }
535 }
536
537 void
538 AudioRegionEditor::mute_button_clicked ()
539 {
540         bool ractive = _region.muted();
541
542         if (mute_button.get_active() != ractive) {
543                 _region.set_muted (!ractive);
544         }
545 }
546
547 void
548 AudioRegionEditor::lock_button_clicked ()
549 {
550         bool ractive = _region.locked();
551
552         if (lock_button.get_active() != ractive) {
553                 _region.set_locked (!ractive);
554         }
555 }
556
557 void
558 AudioRegionEditor::layer_changed ()
559 {
560         char buf[8];
561         snprintf (buf, sizeof(buf), "%d", (int) _region.layer() + 1);
562         layer_value_label.set_text (buf);
563 }
564
565 void
566 AudioRegionEditor::name_changed ()
567 {
568         if (name_entry.get_text() != _region.name()) {
569                 name_entry.set_text (_region.name());
570         }
571 }
572
573 void
574 AudioRegionEditor::lock_changed ()
575 {
576         bool yn;
577
578         if ((yn = _region.locked()) != lock_button.get_active()) {
579                 lock_button.set_active (yn);
580         }
581
582         start_clock.set_sensitive (!yn);
583         end_clock.set_sensitive (!yn);
584         length_clock.set_sensitive (!yn);
585 }
586
587 void
588 AudioRegionEditor::envelope_active_changed ()
589 {
590         bool yn;
591
592         if ((yn = _region.envelope_active()) != envelope_active_button.get_active()) {
593                 envelope_active_button.set_active (yn);
594         }
595 }
596
597 void
598 AudioRegionEditor::opacity_changed ()
599 {
600         bool yn;
601         if ((yn = _region.opaque()) != opaque_button.get_active()) {
602                 opaque_button.set_active (yn);
603         }
604 }
605
606 void
607 AudioRegionEditor::mute_changed ()
608 {
609         bool yn;
610         if ((yn = _region.muted()) != mute_button.get_active()) {
611                 mute_button.set_active (yn);
612         }
613 }
614
615 void
616 AudioRegionEditor::bounds_changed (Change what_changed)
617 {
618         if (what_changed & Change ((PositionChanged|LengthChanged))) {
619                 start_clock.set (_region.position(), true);
620                 end_clock.set (_region.position() + _region.length(), true);
621                 length_clock.set (_region.length(), true);
622         }
623 }
624
625 gint
626 AudioRegionEditor::focus_change (GdkEventFocus *ev)
627 {
628         if (ev->in) {
629                 ARDOUR_UI::instance()->allow_focus (true);
630         } else {
631                 ARDOUR_UI::instance()->allow_focus (false);
632         }
633         return TRUE;
634 }
635
636 void
637 AudioRegionEditor::activation ()
638 {
639         ARDOUR_UI::instance()->allow_focus (false);
640 }       
641
642 void
643 AudioRegionEditor::name_entry_changed ()
644 {
645         if (name_entry.get_text() != _region.name()) {
646                 _region.set_name (name_entry.get_text());
647         }
648 }
649
650 void
651 AudioRegionEditor::fade_in_changed ()
652 {
653         float msecs = fade_in_length_adjustment.get_value();
654         jack_nframes_t sr = _session.frame_rate();
655         jack_nframes_t adj_frames = (jack_nframes_t) floor (msecs * (sr/1000.0f));
656         jack_nframes_t frames;
657         bool x;
658
659         if (adj_frames != (frames = (jack_nframes_t) _region.fade_in().back()->when)) {
660                 fade_in_length_adjustment.set_value ((frames * 1000.0f) / sr);
661         }
662
663         if ((x = _region.fade_in_active()) != fade_in_active_button.get_active()) {
664                 fade_in_active_button.set_active (x);
665         }
666 }
667
668 void
669 AudioRegionEditor::fade_out_changed ()
670 {
671         float msecs = fade_out_length_adjustment.get_value();
672         jack_nframes_t sr = _session.frame_rate();
673         jack_nframes_t adj_frames = (jack_nframes_t) floor (msecs * (sr/1000.0f));
674         jack_nframes_t frames;
675         bool x;
676         if (adj_frames != (frames = (jack_nframes_t) _region.fade_out().back()->when)) {
677                 fade_out_length_adjustment.set_value ((frames * 1000.0f) / sr);
678         }
679
680         if ((x = _region.fade_out_active()) != fade_out_active_button.get_active()) {
681                 fade_out_active_button.set_active (x);
682         }
683 }
684
685 void
686 AudioRegionEditor::fade_in_length_adjustment_changed ()
687 {
688         jack_nframes_t fade_length = (jack_nframes_t) floor (fade_in_length_adjustment.get_value() * _session.frame_rate() * 0.001); 
689         fade_length = max (fade_length, (jack_nframes_t) 64);
690         fade_length = min (fade_length, _region.length());
691         
692         _region.set_fade_in_length (fade_length);
693         /* region is frozen, no worries */
694         fade_in_changed();
695 }
696
697 void
698 AudioRegionEditor::fade_out_length_adjustment_changed ()
699 {
700         jack_nframes_t fade_length = (jack_nframes_t) floor (fade_out_length_adjustment.get_value() * _session.frame_rate() * 0.001); 
701         fade_length = max (fade_length, (jack_nframes_t) 64);
702         fade_length = min (fade_length, _region.length());
703         
704         _region.set_fade_out_length (fade_length);      
705         /* region is frozen, no worries */
706         fade_out_changed();
707 }
708
709 void
710 AudioRegionEditor::fade_in_active_toggled ()
711 {
712         _region.set_fade_in_active (fade_in_active_button.get_active());
713 }
714
715 void
716 AudioRegionEditor::fade_out_active_toggled ()
717 {
718         _region.set_fade_out_active (fade_out_active_button.get_active());
719 }
720
721 void
722 AudioRegionEditor::fade_out_active_changed ()
723 {
724         bool x;
725
726         if ((x = _region.fade_out_active()) != fade_out_active_button.get_active()) {
727                 fade_out_active_button.set_active (x);
728         }
729 }
730
731 void
732 AudioRegionEditor::fade_in_active_changed ()
733 {
734         bool x;
735
736         if ((x = _region.fade_in_active()) != fade_in_active_button.get_active()) {
737                 fade_in_active_button.set_active (x);
738         }
739 }