Make region properties dialogue work for MIDI regions too.
[ardour.git] / gtk2_ardour / audio_region_editor.cc
1 /*
2     Copyright (C) 2001 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "pbd/memento_command.h"
21 #include "pbd/stateful_diff_command.h"
22
23 #include "ardour/session.h"
24 #include "ardour/audioregion.h"
25 #include "ardour/playlist.h"
26 #include "ardour/utils.h"
27 #include "ardour/dB.h"
28 #include <gtkmm2ext/utils.h>
29 #include <gtkmm2ext/stop_signal.h>
30 #include <cmath>
31
32 #include "audio_region_editor.h"
33 #include "audio_region_view.h"
34 #include "ardour_ui.h"
35 #include "utils.h"
36 #include "gui_thread.h"
37
38 #include "i18n.h"
39
40 using namespace ARDOUR;
41 using namespace PBD;
42 using namespace std;
43 using namespace Gtkmm2ext;
44
45 AudioRegionEditor::AudioRegionEditor (Session* s, boost::shared_ptr<AudioRegion> r)
46         : RegionEditor (s, r)
47         , _audio_region (r)
48         , gain_adjustment(accurate_coefficient_to_dB(_audio_region->scale_amplitude()), -40.0, +40.0, 0.1, 1.0, 0)        
49
50 {
51         gain_label.set_alignment (1, 0.5);
52
53         Gtk::HBox* gb = Gtk::manage (new Gtk::HBox);
54         gb->set_spacing (6);
55         gb->pack_start (gain_entry);
56         gb->pack_start (*Gtk::manage (new Gtk::Label (_("dB"))), false, false);
57
58         gain_label.set_name ("AudioRegionEditorLabel");
59         gain_label.set_text (_("Region gain:"));
60         gain_entry.configure (gain_adjustment, 0.0, 1);
61         _table.attach (gain_label, 0, 1, 7, 8, Gtk::FILL, Gtk::FILL);
62         _table.attach (*gb, 1, 2, 7, 8, Gtk::FILL, Gtk::FILL);
63
64         gain_changed ();
65
66         gain_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &AudioRegionEditor::gain_adjustment_changed));
67 }
68
69 void
70 AudioRegionEditor::region_changed (const PBD::PropertyChange& what_changed)
71 {
72         RegionEditor::region_changed (what_changed);
73         
74         if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
75                 gain_changed ();
76         }
77 }
78 void
79 AudioRegionEditor::gain_changed ()
80 {
81         float const region_gain_dB = accurate_coefficient_to_dB (_audio_region->scale_amplitude());
82         if (region_gain_dB != gain_adjustment.get_value()) {
83                 gain_adjustment.set_value(region_gain_dB);
84         }
85 }
86
87 void
88 AudioRegionEditor::gain_adjustment_changed ()
89 {
90         float const gain = dB_to_coefficient (gain_adjustment.get_value());
91         if (_audio_region->scale_amplitude() != gain) {
92                 _audio_region->set_scale_amplitude (gain);
93         }
94 }