compiles and runs, but crashes ... duh
[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                                 // GTK2FIX probably nuke the region editor
372                                 // if ((ev->window == but->gobj()->panel)) {
373                                 // spin_arrow_grab = true;
374                                 // (this->*pmf)();
375                                 // } 
376                         } 
377                 } 
378                 break;
379         default:
380                 break;
381         }
382         return FALSE;
383 }
384
385 gint 
386 AudioRegionEditor::breleased (GdkEventButton* ev, Gtk::SpinButton* but, void (AudioRegionEditor::*pmf)())
387 {
388         if (spin_arrow_grab) {
389                 (this->*pmf)();
390                 spin_arrow_grab = false;
391         }
392         return FALSE;
393 }
394
395 void
396 AudioRegionEditor::start_editing_fade_in ()
397 {
398         _region.freeze ();
399 }
400
401 void
402 AudioRegionEditor::stop_editing_fade_in ()
403 {
404         _region.thaw (_("fade in edit"));
405 }
406
407 void
408 AudioRegionEditor::start_editing_fade_out ()
409 {
410         _region.freeze ();
411 }
412
413 void
414 AudioRegionEditor::stop_editing_fade_out ()
415 {
416         _region.thaw (_("fade out edit"));
417 }
418
419 void
420 AudioRegionEditor::connect_editor_events ()
421 {
422   name_entry.signal_changed().connect (mem_fun(*this, &AudioRegionEditor::name_entry_changed));
423
424         start_clock.ValueChanged.connect (mem_fun(*this, &AudioRegionEditor::start_clock_changed));
425         end_clock.ValueChanged.connect (mem_fun(*this, &AudioRegionEditor::end_clock_changed));
426         length_clock.ValueChanged.connect (mem_fun(*this, &AudioRegionEditor::length_clock_changed));
427
428         fade_in_length_spinner.signal_button_press_event().connect (bind (mem_fun(*this, &AudioRegionEditor::bpressed), &fade_in_length_spinner, 
429                                                                  &AudioRegionEditor::start_editing_fade_in));
430         fade_in_length_spinner.signal_button_release_event().connect (bind (mem_fun (*this, &AudioRegionEditor::breleased), &fade_in_length_spinner, 
431                                                                    &AudioRegionEditor::stop_editing_fade_in));
432
433         fade_out_length_spinner.signal_button_press_event().connect (bind (mem_fun(*this, &AudioRegionEditor::bpressed), &fade_out_length_spinner, 
434                                                                  &AudioRegionEditor::start_editing_fade_out));
435         fade_out_length_spinner.signal_button_release_event().connect (bind (mem_fun (*this, &AudioRegionEditor::breleased), &fade_out_length_spinner, 
436                                                                    &AudioRegionEditor::stop_editing_fade_out));
437
438         fade_in_length_adjustment.signal_value_changed().connect (mem_fun(*this, &AudioRegionEditor::fade_in_length_adjustment_changed));
439         fade_out_length_adjustment.signal_value_changed().connect (mem_fun(*this, &AudioRegionEditor::fade_out_length_adjustment_changed));
440
441         fade_in_active_button.signal_toggled().connect (mem_fun(*this, &AudioRegionEditor::fade_in_active_toggled));
442         fade_out_active_button.signal_toggled().connect (mem_fun(*this, &AudioRegionEditor::fade_out_active_toggled));
443
444         envelope_active_button.signal_button_press_event().connect (mem_fun(*this, &AudioRegionEditor::envelope_active_button_press));
445         envelope_active_button.signal_button_release_event().connect (mem_fun(*this, &AudioRegionEditor::envelope_active_button_release));
446         audition_button.signal_toggled().connect (mem_fun(*this, &AudioRegionEditor::audition_button_toggled));
447         envelope_view_button.signal_toggled().connect (mem_fun(*this, &AudioRegionEditor::envelope_view_button_toggled));
448         lock_button.signal_clicked().connect (mem_fun(*this, &AudioRegionEditor::lock_button_clicked));
449         mute_button.signal_clicked().connect (mem_fun(*this, &AudioRegionEditor::mute_button_clicked));
450         opaque_button.signal_clicked().connect (mem_fun(*this, &AudioRegionEditor::opaque_button_clicked));
451         raise_button.signal_clicked().connect (mem_fun(*this, &AudioRegionEditor::raise_button_clicked));
452         lower_button.signal_clicked().connect (mem_fun(*this, &AudioRegionEditor::lower_button_clicked));
453 }
454
455 void
456 AudioRegionEditor::start_clock_changed ()
457 {
458         _region.set_position (start_clock.current_time(), this);
459 }
460
461 void
462 AudioRegionEditor::end_clock_changed ()
463 {
464         _region.trim_end (end_clock.current_time(), this);
465
466         end_clock.set (_region.position() + _region.length(), true);
467 }
468
469 void
470 AudioRegionEditor::length_clock_changed ()
471 {
472         jack_nframes_t frames = length_clock.current_time();
473         _region.trim_end (_region.position() + frames, this);
474
475         length_clock.set (_region.length());
476 }
477
478 gint
479 AudioRegionEditor::envelope_active_button_press(GdkEventButton *ev)
480 {
481         return stop_signal (envelope_active_button, "button_press_event");
482 }
483
484 gint
485 AudioRegionEditor::envelope_active_button_release (GdkEventButton *ev)
486 {
487         _region.set_envelope_active (!_region.envelope_active());
488         return stop_signal (envelope_active_button, "button_release_event");
489 }
490
491 void
492 AudioRegionEditor::envelope_view_button_toggled ()
493 {
494         bool visible = envelope_view_button.get_active ();
495
496         _region_view.set_envelope_visible (visible);
497 }
498
499 void
500 AudioRegionEditor::audition_button_toggled ()
501 {
502         if (audition_button.get_active()) {
503                 _session.audition_region (_region);
504         } else {
505                 _session.cancel_audition ();
506         }
507 }
508
509 void
510 AudioRegionEditor::raise_button_clicked ()
511 {
512         _region.raise ();
513 }
514
515 void
516 AudioRegionEditor::lower_button_clicked ()
517 {
518         _region.lower ();
519 }
520
521 void
522 AudioRegionEditor::opaque_button_clicked ()
523 {
524         bool ractive = _region.opaque();
525
526         if (opaque_button.get_active() != ractive) {
527                 _region.set_opaque (!ractive);
528         }
529 }
530
531 void
532 AudioRegionEditor::mute_button_clicked ()
533 {
534         bool ractive = _region.muted();
535
536         if (mute_button.get_active() != ractive) {
537                 _region.set_muted (!ractive);
538         }
539 }
540
541 void
542 AudioRegionEditor::lock_button_clicked ()
543 {
544         bool ractive = _region.locked();
545
546         if (lock_button.get_active() != ractive) {
547                 _region.set_locked (!ractive);
548         }
549 }
550
551 void
552 AudioRegionEditor::layer_changed ()
553 {
554         char buf[8];
555         snprintf (buf, sizeof(buf), "%d", (int) _region.layer() + 1);
556         layer_value_label.set_text (buf);
557 }
558
559 void
560 AudioRegionEditor::name_changed ()
561 {
562         if (name_entry.get_text() != _region.name()) {
563                 name_entry.set_text (_region.name());
564         }
565 }
566
567 void
568 AudioRegionEditor::lock_changed ()
569 {
570         bool yn;
571
572         if ((yn = _region.locked()) != lock_button.get_active()) {
573                 lock_button.set_active (yn);
574         }
575
576         start_clock.set_sensitive (!yn);
577         end_clock.set_sensitive (!yn);
578         length_clock.set_sensitive (!yn);
579 }
580
581 void
582 AudioRegionEditor::envelope_active_changed ()
583 {
584         bool yn;
585
586         if ((yn = _region.envelope_active()) != envelope_active_button.get_active()) {
587                 envelope_active_button.set_active (yn);
588         }
589 }
590
591 void
592 AudioRegionEditor::opacity_changed ()
593 {
594         bool yn;
595         if ((yn = _region.opaque()) != opaque_button.get_active()) {
596                 opaque_button.set_active (yn);
597         }
598 }
599
600 void
601 AudioRegionEditor::mute_changed ()
602 {
603         bool yn;
604         if ((yn = _region.muted()) != mute_button.get_active()) {
605                 mute_button.set_active (yn);
606         }
607 }
608
609 void
610 AudioRegionEditor::bounds_changed (Change what_changed)
611 {
612         if (what_changed & Change ((PositionChanged|LengthChanged))) {
613                 start_clock.set (_region.position(), true);
614                 end_clock.set (_region.position() + _region.length(), true);
615                 length_clock.set (_region.length(), true);
616         }
617 }
618
619 void
620 AudioRegionEditor::activation ()
621 {
622         
623 }       
624
625 void
626 AudioRegionEditor::name_entry_changed ()
627 {
628         if (name_entry.get_text() != _region.name()) {
629                 _region.set_name (name_entry.get_text());
630         }
631 }
632
633 void
634 AudioRegionEditor::fade_in_changed ()
635 {
636         float msecs = fade_in_length_adjustment.get_value();
637         jack_nframes_t sr = _session.frame_rate();
638         jack_nframes_t adj_frames = (jack_nframes_t) floor (msecs * (sr/1000.0f));
639         jack_nframes_t frames;
640         bool x;
641
642         if (adj_frames != (frames = (jack_nframes_t) _region.fade_in().back()->when)) {
643                 fade_in_length_adjustment.set_value ((frames * 1000.0f) / sr);
644         }
645
646         if ((x = _region.fade_in_active()) != fade_in_active_button.get_active()) {
647                 fade_in_active_button.set_active (x);
648         }
649 }
650
651 void
652 AudioRegionEditor::fade_out_changed ()
653 {
654         float msecs = fade_out_length_adjustment.get_value();
655         jack_nframes_t sr = _session.frame_rate();
656         jack_nframes_t adj_frames = (jack_nframes_t) floor (msecs * (sr/1000.0f));
657         jack_nframes_t frames;
658         bool x;
659         if (adj_frames != (frames = (jack_nframes_t) _region.fade_out().back()->when)) {
660                 fade_out_length_adjustment.set_value ((frames * 1000.0f) / sr);
661         }
662
663         if ((x = _region.fade_out_active()) != fade_out_active_button.get_active()) {
664                 fade_out_active_button.set_active (x);
665         }
666 }
667
668 void
669 AudioRegionEditor::fade_in_length_adjustment_changed ()
670 {
671         jack_nframes_t fade_length = (jack_nframes_t) floor (fade_in_length_adjustment.get_value() * _session.frame_rate() * 0.001); 
672         fade_length = max (fade_length, (jack_nframes_t) 64);
673         fade_length = min (fade_length, _region.length());
674         
675         _region.set_fade_in_length (fade_length);
676         /* region is frozen, no worries */
677         fade_in_changed();
678 }
679
680 void
681 AudioRegionEditor::fade_out_length_adjustment_changed ()
682 {
683         jack_nframes_t fade_length = (jack_nframes_t) floor (fade_out_length_adjustment.get_value() * _session.frame_rate() * 0.001); 
684         fade_length = max (fade_length, (jack_nframes_t) 64);
685         fade_length = min (fade_length, _region.length());
686         
687         _region.set_fade_out_length (fade_length);      
688         /* region is frozen, no worries */
689         fade_out_changed();
690 }
691
692 void
693 AudioRegionEditor::fade_in_active_toggled ()
694 {
695         _region.set_fade_in_active (fade_in_active_button.get_active());
696 }
697
698 void
699 AudioRegionEditor::fade_out_active_toggled ()
700 {
701         _region.set_fade_out_active (fade_out_active_button.get_active());
702 }
703
704 void
705 AudioRegionEditor::fade_out_active_changed ()
706 {
707         bool x;
708
709         if ((x = _region.fade_out_active()) != fade_out_active_button.get_active()) {
710                 fade_out_active_button.set_active (x);
711         }
712 }
713
714 void
715 AudioRegionEditor::fade_in_active_changed ()
716 {
717         bool x;
718
719         if ((x = _region.fade_in_active()) != fade_in_active_button.get_active()) {
720                 fade_in_active_button.set_active (x);
721         }
722 }