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