2 Copyright (C) 2001 Paul Davis
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.
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.
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.
20 #include <boost/lexical_cast.hpp>
22 #include "pbd/memento_command.h"
23 #include "pbd/stateful_diff_command.h"
24 #include "pbd/pthread_utils.h"
26 #include "ardour/session.h"
27 #include "ardour/audioregion.h"
28 #include "ardour/playlist.h"
29 #include "ardour/utils.h"
30 #include "ardour/dB.h"
31 #include <gtkmm2ext/utils.h>
34 #include "audio_region_editor.h"
35 #include "audio_region_view.h"
36 #include "ardour_ui.h"
38 #include "gui_thread.h"
42 using namespace ARDOUR;
45 using namespace Gtkmm2ext;
48 _peak_amplitude_thread (void* arg)
50 SessionEvent::create_per_thread_pool ("peak amplitude events", 64);
51 static_cast<AudioRegionEditor*>(arg)->peak_amplitude_thread ();
55 AudioRegionEditor::AudioRegionEditor (Session* s, boost::shared_ptr<AudioRegion> r)
58 , gain_adjustment(accurate_coefficient_to_dB(_audio_region->scale_amplitude()), -40.0, +40.0, 0.1, 1.0, 0)
59 , _peak_amplitude_found (false)
62 Gtk::HBox* b = Gtk::manage (new Gtk::HBox);
64 b->pack_start (gain_entry);
65 b->pack_start (*Gtk::manage (new Gtk::Label (_("dB"))), false, false);
67 gain_label.set_name ("AudioRegionEditorLabel");
68 gain_label.set_text (_("Region gain:"));
69 gain_label.set_alignment (1, 0.5);
70 gain_entry.configure (gain_adjustment, 0.0, 1);
71 _table.attach (gain_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
72 _table.attach (*b, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
75 b = Gtk::manage (new Gtk::HBox);
77 b->pack_start (_peak_amplitude);
78 b->pack_start (*Gtk::manage (new Gtk::Label (_("dBFS"))), false, false);
80 _peak_amplitude_label.set_name ("AudioRegionEditorLabel");
81 _peak_amplitude_label.set_text (_("Peak amplitude:"));
82 _peak_amplitude_label.set_alignment (1, 0.5);
83 _table.attach (_peak_amplitude_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
84 _table.attach (*b, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
89 gain_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &AudioRegionEditor::gain_adjustment_changed));
91 _peak_amplitude.property_editable() = false;
92 _peak_amplitude.set_text (_("Calculating..."));
94 PeakAmplitudeFound.connect (_peak_amplitude_connection, invalidator (*this), boost::bind (&AudioRegionEditor::peak_amplitude_found, this, _1), gui_context ());
95 pthread_create_and_store (X_("peak-amplitude"), &_peak_amplitude_thread_handle, _peak_amplitude_thread, this);
98 AudioRegionEditor::~AudioRegionEditor ()
100 pthread_cancel_one (_peak_amplitude_thread_handle);
102 int const r = pthread_join (_peak_amplitude_thread_handle, &v);
107 AudioRegionEditor::region_changed (const PBD::PropertyChange& what_changed)
109 RegionEditor::region_changed (what_changed);
111 if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
116 AudioRegionEditor::gain_changed ()
118 float const region_gain_dB = accurate_coefficient_to_dB (_audio_region->scale_amplitude());
119 if (region_gain_dB != gain_adjustment.get_value()) {
120 gain_adjustment.set_value(region_gain_dB);
125 AudioRegionEditor::gain_adjustment_changed ()
127 float const gain = dB_to_coefficient (gain_adjustment.get_value());
128 if (_audio_region->scale_amplitude() != gain) {
129 _audio_region->set_scale_amplitude (gain);
134 AudioRegionEditor::peak_amplitude_thread ()
136 PeakAmplitudeFound (accurate_coefficient_to_dB (_audio_region->maximum_amplitude ())); /* EMIT SIGNAL */
140 AudioRegionEditor::peak_amplitude_found (double p)
142 _peak_amplitude.set_text (boost::lexical_cast<string> (p));