Use UTF8 instead of ASCII in CFString conversion.
[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 #include "gui_thread.h"
32
33 #include "i18n.h"
34
35 using namespace ARDOUR;
36 using namespace PBD;
37 using namespace sigc;
38 using namespace std;
39
40 AudioRegionEditor::AudioRegionEditor (Session&s, AudioRegion& r, AudioRegionView& rv)
41         : ArdourDialog ("audio region editor"),
42           _session (s),
43           _region (r),
44           _region_view (rv),
45           name_label (_("NAME:")),
46           lock_button (_("lock")),
47           mute_button (_("mute")),
48           opaque_button (_("opaque")),
49           envelope_active_button(_("active")),
50           envelope_view_button(_("visible")),
51           raise_arrow (Gtk::ARROW_UP, Gtk::SHADOW_OUT),
52           lower_arrow (Gtk::ARROW_DOWN, Gtk::SHADOW_OUT),
53           layer_label (_("Layer")),
54           audition_button (_("play")),
55           time_table (3, 2),
56           start_clock ("AudioRegionEditorClock", true),
57           end_clock ("AudioRegionEditorClock", true),
58           length_clock ("AudioRegionEditorClock", true, true),
59           sync_offset_clock ("AudioRegionEditorClock", true, true),
60           envelope_loop_table (1, 3),
61           envelope_label (_("ENVELOPE")),
62           fade_in_table (4, 3),
63           fade_in_length_adjustment (5.0, 0.0, 10000, 0.05, 1),
64           fade_in_length_spinner (fade_in_length_adjustment, 10),
65           fade_out_table (4, 3),
66           fade_out_length_adjustment (5.0, 0.0, 10000, 0.05, 1),
67           fade_out_length_spinner (fade_out_length_adjustment, 10)
68
69 {
70         start_clock.set_session (&_session);
71         end_clock.set_session (&_session);
72         length_clock.set_session (&_session);
73
74         name_entry.set_name ("AudioRegionEditorEntry");
75         name_label.set_name ("AudioRegionEditorLabel");
76
77         name_hbox.set_spacing (5);
78         name_hbox.pack_start (name_label, false, false);
79         name_hbox.pack_start (name_entry, false, false);
80
81         raise_button.add (raise_arrow);
82         lower_button.add (lower_arrow);
83         layer_frame.set_name ("BaseFrame");
84         layer_frame.set_shadow_type (Gtk::SHADOW_IN);
85         layer_frame.add (layer_value_label);
86         layer_label.set_name ("AudioRegionEditorLabel");
87         layer_value_label.set_name ("AudioRegionEditorLabel");
88         Gtkmm2ext::set_size_request_to_display_given_text (layer_value_label, "99", 5, 2);
89
90         layer_hbox.set_spacing (5);
91         layer_hbox.pack_start (layer_label, false, false);
92         layer_hbox.pack_start (layer_frame, false, false);
93 #if 0
94         layer_hbox.pack_start (raise_button, false, false);
95         layer_hbox.pack_start (lower_button, false, false);
96 #endif
97
98         mute_button.set_name ("AudioRegionEditorToggleButton");
99         opaque_button.set_name ("AudioRegionEditorToggleButton");
100         lock_button.set_name ("AudioRegionEditorToggleButton");
101         envelope_active_button.set_name ("AudioRegionEditorToggleButton");
102         envelope_view_button.set_name ("AudioRegionEditorToggleButton");
103         fade_in_active_button.set_name ("AudioRegionEditorToggleButton");
104         fade_out_active_button.set_name ("AudioRegionEditorToggleButton");
105         audition_button.set_name ("AudioRegionEditorToggleButton");
106
107         ARDOUR_UI::instance()->tooltips().set_tip (mute_button, _("mute this region"));
108         ARDOUR_UI::instance()->tooltips().set_tip (opaque_button, _("regions underneath this one cannot be heard"));
109         ARDOUR_UI::instance()->tooltips().set_tip (lock_button, _("prevent any changes to this region"));
110         ARDOUR_UI::instance()->tooltips().set_tip (envelope_active_button, _("use the gain envelope during playback"));
111         ARDOUR_UI::instance()->tooltips().set_tip (envelope_view_button, _("show the gain envelope"));
112         ARDOUR_UI::instance()->tooltips().set_tip (fade_in_active_button, _("use fade in curve during playback"));
113         ARDOUR_UI::instance()->tooltips().set_tip (fade_out_active_button, _("use fade out curve during playback"));
114         ARDOUR_UI::instance()->tooltips().set_tip (audition_button, _("audition this region"));
115
116         mute_button.unset_flags (Gtk::CAN_FOCUS);
117         opaque_button.unset_flags (Gtk::CAN_FOCUS);
118         lock_button.unset_flags (Gtk::CAN_FOCUS);
119         envelope_active_button.unset_flags (Gtk::CAN_FOCUS);
120         envelope_view_button.unset_flags (Gtk::CAN_FOCUS);
121         fade_in_active_button.unset_flags (Gtk::CAN_FOCUS);
122         fade_out_active_button.unset_flags (Gtk::CAN_FOCUS);
123         audition_button.unset_flags (Gtk::CAN_FOCUS);
124         
125         mute_button.set_events (mute_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
126         opaque_button.set_events (opaque_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
127         lock_button.set_events (lock_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
128         envelope_active_button.set_events (envelope_active_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
129         envelope_view_button.set_events (envelope_view_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
130         fade_in_active_button.set_events (fade_in_active_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
131         fade_out_active_button.set_events (fade_out_active_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
132         audition_button.set_events (audition_button.get_events() & ~(Gdk::ENTER_NOTIFY_MASK|Gdk::LEAVE_NOTIFY_MASK));
133
134         top_row_button_hbox.set_border_width (5);
135         top_row_button_hbox.set_spacing (5);
136         top_row_button_hbox.set_homogeneous (false);
137         top_row_button_hbox.pack_start (mute_button, false, false);
138         top_row_button_hbox.pack_start (opaque_button, false, false);
139         top_row_button_hbox.pack_start (lock_button, false, false);
140         top_row_button_hbox.pack_start (layer_hbox, false, false, 5);
141         top_row_button_hbox.pack_end (audition_button, false, false);
142         
143         top_row_hbox.pack_start (name_hbox, true, true);
144         top_row_hbox.pack_end (top_row_button_hbox, true, true);
145
146         start_label.set_name ("AudioRegionEditorLabel");
147         start_label.set_text (_("START:"));
148         end_label.set_name ("AudioRegionEditorLabel");
149         end_label.set_text (_("END:"));
150         length_label.set_name ("AudioRegionEditorLabel");
151         length_label.set_text (_("LENGTH:"));
152         
153         time_table.set_col_spacings (2);
154         time_table.set_row_spacings (5);
155         time_table.set_border_width (5);
156
157         start_alignment.set (1.0, 0.5);
158         end_alignment.set (1.0, 0.5);
159         length_alignment.set (1.0, 0.5);
160
161         start_alignment.add (start_label);
162         end_alignment.add (end_label);
163         length_alignment.add (length_label);
164
165         time_table.attach (start_alignment, 0, 1, 0, 1, Gtk::FILL, Gtk::FILL);
166         time_table.attach (start_clock, 1, 2, 0, 1, Gtk::FILL, Gtk::FILL);
167
168         time_table.attach (end_alignment, 0, 1, 1, 2, Gtk::FILL, Gtk::FILL);
169         time_table.attach (end_clock, 1, 2, 1, 2, Gtk::FILL, Gtk::FILL);
170
171         time_table.attach (length_alignment, 0, 1, 2, 3, Gtk::FILL, Gtk::FILL);
172         time_table.attach (length_clock, 1, 2, 2, 3, Gtk::FILL, Gtk::FILL);
173
174         envelope_label.set_name ("AudioRegionEditorLabel");
175
176         envelope_loop_table.set_border_width (5);
177         envelope_loop_table.set_row_spacings (2);
178         envelope_loop_table.attach (envelope_label, 0, 1, 0, 1, Gtk::FILL, Gtk::FILL);
179         envelope_loop_table.attach (envelope_active_button, 0, 1, 1, 2, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
180         envelope_loop_table.attach (envelope_view_button, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
181
182         /* fade in */
183
184         fade_in_table.set_border_width (5);
185         fade_in_table.set_homogeneous (false);
186
187         fade_in_label.set_name ("AudioRegionEditorLabel");
188         fade_in_active_button_label.set_name ("AudioRegionEditorSmallLabel");
189         fade_in_length_label.set_name ("AudioRegionEditorSmallLabel");
190
191         fade_in_label.set_text (_("FADE IN"));
192         fade_in_active_button_label.set_text (_("active"));
193         fade_in_length_label.set_text (_("msecs"));
194
195         fade_in_active_button.add (fade_in_active_button_label);
196
197         fade_in_length_spinner.set_name("GenericSpinner");
198
199         fade_in_length_spinner.set_digits (3);
200
201         // fade_in_length_spinner.signal_activate().connect (mem_fun(*this, &AudioRegionEditor::activation));
202
203         Gtkmm2ext::set_size_request_to_display_given_text (fade_in_length_spinner, "500g", 20, -1);
204
205         fade_in_label_align.add (fade_in_label);
206         fade_in_label_align.set (0.5);
207
208
209         fade_in_table.attach (fade_in_label_align,   0, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
210
211         fade_in_table.attach (fade_in_length_label,   0, 1, 1, 2, Gtk::EXPAND, Gtk::FILL);
212         fade_in_table.attach (fade_in_length_spinner, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
213
214         fade_in_table.attach (fade_in_active_button,        0, 2, 3, 5, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
215
216         /* fade out */
217
218         fade_out_table.set_border_width (5);
219         fade_out_table.set_homogeneous (false);
220
221         fade_out_label.set_name ("AudioRegionEditorLabel");
222         fade_out_active_button_label.set_name ("AudioRegionEditorSmallLabel");
223         fade_out_length_label.set_name ("AudioRegionEditorSmallLabel");
224
225         fade_out_label.set_text (_("FADE OUT"));
226         fade_out_active_button_label.set_text (_("active"));
227         fade_out_length_label.set_text (_("msecs"));
228
229         fade_out_active_button.add (fade_out_active_button_label);
230
231         fade_out_length_spinner.set_name("GenericSpinner");
232         
233         fade_out_length_spinner.set_digits (3);
234
235         fade_out_length_spinner.signal_activate().connect (mem_fun(*this, &AudioRegionEditor::activation));
236
237         Gtkmm2ext::set_size_request_to_display_given_text (fade_out_length_spinner, "500g", 20, -1);
238
239         fade_out_label_align.add (fade_out_label);
240         fade_out_label_align.set (0.5);
241
242         fade_out_table.attach (fade_out_label_align,   0, 2, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
243
244         fade_out_table.attach (fade_out_length_label,   0, 1, 1, 2, Gtk::EXPAND, Gtk::FILL);
245         fade_out_table.attach (fade_out_length_spinner, 0, 1, 2, 3, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
246
247         fade_out_table.attach (fade_out_active_button,        0, 2, 3, 5, Gtk::FILL|Gtk::EXPAND, Gtk::FILL);
248
249         lower_hbox.pack_start (time_table, true, true);
250         lower_hbox.pack_start (sep1, false, false);
251         lower_hbox.pack_start (envelope_loop_table, true, true);
252         lower_hbox.pack_start (sep2, false, false);
253         lower_hbox.pack_start (fade_in_table, true, true);
254         lower_hbox.pack_start (fade_out_table, true, true);
255
256         get_vbox()->pack_start (top_row_hbox, true, true);
257         get_vbox()->pack_start (sep3, false, false);
258         get_vbox()->pack_start (lower_hbox, true, true);
259
260         set_name ("AudioRegionEditorWindow");
261         add_events (Gdk::KEY_PRESS_MASK|Gdk::KEY_RELEASE_MASK);
262
263         signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), static_cast<Window *> (this)));
264
265         string title = _("ardour: region ");
266         title += _region.name();
267         set_title (title);
268
269         show_all();
270
271         name_changed ();
272         bounds_changed (Change (StartChanged|LengthChanged|PositionChanged));
273         envelope_active_changed ();
274         mute_changed ();
275         opacity_changed ();
276         lock_changed ();
277         layer_changed ();
278         fade_in_changed ();
279         fade_out_changed ();
280
281         XMLNode *node  = _region.extra_xml ("GUI");
282         XMLProperty *prop = 0;
283         bool showing_envelope = false;
284
285         if (node && (prop = node->property ("envelope-visible")) != 0) {
286                 if (prop->value() == "yes") {
287                         showing_envelope = true;
288                 } 
289         } 
290
291         if (showing_envelope) {
292                 envelope_view_button.set_active (true);
293         } else {
294                 envelope_view_button.set_active (false);
295         }
296
297         _region.StateChanged.connect (mem_fun(*this, &AudioRegionEditor::region_changed));
298         
299         spin_arrow_grab = false;
300         
301         connect_editor_events ();
302 }
303
304 AudioRegionEditor::~AudioRegionEditor ()
305 {
306 }
307
308 void
309 AudioRegionEditor::region_changed (Change what_changed)
310 {
311         if (what_changed & NameChanged) {
312                 name_changed ();
313         }
314         if (what_changed & BoundsChanged) {
315                 bounds_changed (what_changed);
316         }
317
318         if (what_changed & Region::OpacityChanged) {
319                 opacity_changed ();
320         }
321         if (what_changed & Region::MuteChanged) {
322                 mute_changed ();
323         }
324         if (what_changed & Region::LockChanged) {
325                 lock_changed ();
326         }
327         if (what_changed & Region::LayerChanged) {
328                 layer_changed ();
329         }
330
331         if (what_changed & AudioRegion::EnvelopeActiveChanged) {
332                 envelope_active_changed ();
333         }
334         if (what_changed & AudioRegion::FadeInChanged) {
335                 fade_in_changed ();
336         }
337         if (what_changed & AudioRegion::FadeOutChanged) {
338                 fade_out_changed ();
339         }
340         if (what_changed & AudioRegion::FadeInActiveChanged) {
341                 fade_in_active_changed ();
342         }
343         if (what_changed & AudioRegion::FadeOutActiveChanged) {
344                 fade_out_active_changed ();
345         }
346 }
347
348 void
349 AudioRegionEditor::fade_in_realized ()
350 {
351         fade_in_changed ();
352 }
353
354 void
355 AudioRegionEditor::fade_out_realized ()
356 {
357         fade_out_changed ();
358 }
359
360 gint 
361 AudioRegionEditor::bpressed (GdkEventButton* ev, Gtk::SpinButton* but, void (AudioRegionEditor::*pmf)())
362 {
363         switch (ev->button) {
364         case 1:
365         case 2:
366         case 3:
367                 if (ev->type == GDK_BUTTON_PRESS) { /* no double clicks here */
368                         if (!spin_arrow_grab) {
369                                 // GTK2FIX probably nuke the region editor
370                                 // if ((ev->window == but->gobj()->panel)) {
371                                 // spin_arrow_grab = true;
372                                 // (this->*pmf)();
373                                 // } 
374                         } 
375                 } 
376                 break;
377         default:
378                 break;
379         }
380         return FALSE;
381 }
382
383 gint 
384 AudioRegionEditor::breleased (GdkEventButton* ev, Gtk::SpinButton* but, void (AudioRegionEditor::*pmf)())
385 {
386         if (spin_arrow_grab) {
387                 (this->*pmf)();
388                 spin_arrow_grab = false;
389         }
390         return FALSE;
391 }
392
393 void
394 AudioRegionEditor::start_editing_fade_in ()
395 {
396         _region.freeze ();
397 }
398
399 void
400 AudioRegionEditor::stop_editing_fade_in ()
401 {
402         _region.thaw (_("fade in edit"));
403 }
404
405 void
406 AudioRegionEditor::start_editing_fade_out ()
407 {
408         _region.freeze ();
409 }
410
411 void
412 AudioRegionEditor::stop_editing_fade_out ()
413 {
414         _region.thaw (_("fade out edit"));
415 }
416
417 void
418 AudioRegionEditor::connect_editor_events ()
419 {
420   name_entry.signal_changed().connect (mem_fun(*this, &AudioRegionEditor::name_entry_changed));
421
422         start_clock.ValueChanged.connect (mem_fun(*this, &AudioRegionEditor::start_clock_changed));
423         end_clock.ValueChanged.connect (mem_fun(*this, &AudioRegionEditor::end_clock_changed));
424         length_clock.ValueChanged.connect (mem_fun(*this, &AudioRegionEditor::length_clock_changed));
425
426         fade_in_length_spinner.signal_button_press_event().connect (bind (mem_fun(*this, &AudioRegionEditor::bpressed), &fade_in_length_spinner, 
427                                                                  &AudioRegionEditor::start_editing_fade_in));
428         fade_in_length_spinner.signal_button_release_event().connect (bind (mem_fun (*this, &AudioRegionEditor::breleased), &fade_in_length_spinner, 
429                                                                    &AudioRegionEditor::stop_editing_fade_in));
430
431         fade_out_length_spinner.signal_button_press_event().connect (bind (mem_fun(*this, &AudioRegionEditor::bpressed), &fade_out_length_spinner, 
432                                                                  &AudioRegionEditor::start_editing_fade_out));
433         fade_out_length_spinner.signal_button_release_event().connect (bind (mem_fun (*this, &AudioRegionEditor::breleased), &fade_out_length_spinner, 
434                                                                    &AudioRegionEditor::stop_editing_fade_out));
435
436         fade_in_length_adjustment.signal_value_changed().connect (mem_fun(*this, &AudioRegionEditor::fade_in_length_adjustment_changed));
437         fade_out_length_adjustment.signal_value_changed().connect (mem_fun(*this, &AudioRegionEditor::fade_out_length_adjustment_changed));
438
439         fade_in_active_button.signal_toggled().connect (mem_fun(*this, &AudioRegionEditor::fade_in_active_toggled));
440         fade_out_active_button.signal_toggled().connect (mem_fun(*this, &AudioRegionEditor::fade_out_active_toggled));
441
442         envelope_active_button.signal_button_press_event().connect (mem_fun(*this, &AudioRegionEditor::envelope_active_button_press));
443         envelope_active_button.signal_button_release_event().connect (mem_fun(*this, &AudioRegionEditor::envelope_active_button_release));
444         audition_button.signal_toggled().connect (mem_fun(*this, &AudioRegionEditor::audition_button_toggled));
445         envelope_view_button.signal_toggled().connect (mem_fun(*this, &AudioRegionEditor::envelope_view_button_toggled));
446         lock_button.signal_clicked().connect (mem_fun(*this, &AudioRegionEditor::lock_button_clicked));
447         mute_button.signal_clicked().connect (mem_fun(*this, &AudioRegionEditor::mute_button_clicked));
448         opaque_button.signal_clicked().connect (mem_fun(*this, &AudioRegionEditor::opaque_button_clicked));
449         raise_button.signal_clicked().connect (mem_fun(*this, &AudioRegionEditor::raise_button_clicked));
450         lower_button.signal_clicked().connect (mem_fun(*this, &AudioRegionEditor::lower_button_clicked));
451         _session.AuditionActive.connect (mem_fun(*this, &AudioRegionEditor::audition_state_changed));
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         
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 }
722
723 void
724 AudioRegionEditor::audition_state_changed (bool yn)
725 {
726         ENSURE_GUI_THREAD (bind (mem_fun(*this, &AudioRegionEditor::audition_state_changed), yn));
727
728         if (!yn) {
729                 audition_button.set_active (false);
730         }
731 }
732