2005-09-25 14:42:24 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2006-2012 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2006-2015 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
* Copyright (C) 2006-2016 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2009-2011 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2014-2016 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2012-05-24 02:09:29 -04:00
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
#include <gtkmm2ext/utils.h>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/memento_command.h"
|
2010-03-02 13:05:26 -05:00
|
|
|
#include "pbd/stateful_diff_command.h"
|
2010-10-28 16:01:26 -04:00
|
|
|
#include "pbd/pthread_utils.h"
|
2006-11-12 19:50:28 -05:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/audioregion.h"
|
2012-05-24 02:09:29 -04:00
|
|
|
#include "ardour/session_event.h"
|
2009-10-23 19:21:55 -04:00
|
|
|
#include "ardour/dB.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2006-07-31 23:23:35 -04:00
|
|
|
#include "audio_region_editor.h"
|
|
|
|
#include "audio_region_view.h"
|
2006-01-03 09:16:27 -05:00
|
|
|
#include "gui_thread.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
using namespace ARDOUR;
|
2006-06-21 19:01:03 -04:00
|
|
|
using namespace PBD;
|
2005-09-25 14:42:24 -04:00
|
|
|
using namespace std;
|
2007-03-18 12:45:43 -04:00
|
|
|
using namespace Gtkmm2ext;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-10-28 16:01:26 -04:00
|
|
|
static void *
|
|
|
|
_peak_amplitude_thread (void* arg)
|
|
|
|
{
|
|
|
|
static_cast<AudioRegionEditor*>(arg)->peak_amplitude_thread ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-21 20:26:26 -04:00
|
|
|
AudioRegionEditor::AudioRegionEditor (Session* s, boost::shared_ptr<AudioRegion> r)
|
|
|
|
: RegionEditor (s, r)
|
|
|
|
, _audio_region (r)
|
2011-04-04 08:21:26 -04:00
|
|
|
, gain_adjustment(accurate_coefficient_to_dB(_audio_region->scale_amplitude()), -40.0, +40.0, 0.1, 1.0, 0)
|
|
|
|
, _peak_channel (false)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
|
2010-10-28 16:01:26 -04:00
|
|
|
Gtk::HBox* b = Gtk::manage (new Gtk::HBox);
|
|
|
|
b->set_spacing (6);
|
|
|
|
b->pack_start (gain_entry);
|
|
|
|
b->pack_start (*Gtk::manage (new Gtk::Label (_("dB"))), false, false);
|
2008-12-12 09:43:24 -05:00
|
|
|
|
2009-10-23 19:21:55 -04:00
|
|
|
gain_label.set_name ("AudioRegionEditorLabel");
|
2010-04-23 20:29:28 -04:00
|
|
|
gain_label.set_text (_("Region gain:"));
|
2010-10-28 16:01:26 -04:00
|
|
|
gain_label.set_alignment (1, 0.5);
|
2009-10-23 19:21:55 -04:00
|
|
|
gain_entry.configure (gain_adjustment, 0.0, 1);
|
2010-10-27 17:18:44 -04:00
|
|
|
_table.attach (gain_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
|
2010-10-28 16:01:26 -04:00
|
|
|
_table.attach (*b, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
|
|
|
|
++_table_row;
|
2010-02-19 13:09:08 -05:00
|
|
|
|
2010-10-28 16:01:26 -04:00
|
|
|
b = Gtk::manage (new Gtk::HBox);
|
|
|
|
b->set_spacing (6);
|
|
|
|
b->pack_start (_peak_amplitude);
|
|
|
|
b->pack_start (*Gtk::manage (new Gtk::Label (_("dBFS"))), false, false);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-10-28 16:01:26 -04:00
|
|
|
_peak_amplitude_label.set_name ("AudioRegionEditorLabel");
|
|
|
|
_peak_amplitude_label.set_text (_("Peak amplitude:"));
|
|
|
|
_peak_amplitude_label.set_alignment (1, 0.5);
|
|
|
|
_table.attach (_peak_amplitude_label, 0, 1, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
|
|
|
|
_table.attach (*b, 1, 2, _table_row, _table_row + 1, Gtk::FILL, Gtk::FILL);
|
|
|
|
++_table_row;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-10-23 19:21:55 -04:00
|
|
|
gain_changed ();
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-05-21 20:26:26 -04:00
|
|
|
gain_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &AudioRegionEditor::gain_adjustment_changed));
|
2010-10-28 16:01:26 -04:00
|
|
|
|
|
|
|
_peak_amplitude.property_editable() = false;
|
|
|
|
_peak_amplitude.set_text (_("Calculating..."));
|
|
|
|
|
|
|
|
PeakAmplitudeFound.connect (_peak_amplitude_connection, invalidator (*this), boost::bind (&AudioRegionEditor::peak_amplitude_found, this, _1), gui_context ());
|
2016-05-15 20:49:18 -04:00
|
|
|
|
|
|
|
char name[64];
|
|
|
|
snprintf (name, 64, "peak amplitude-%p", this);
|
|
|
|
pthread_create_and_store (name, &_peak_amplitude_thread_handle, _peak_amplitude_thread, this);
|
2013-07-13 08:27:56 -04:00
|
|
|
signal_peak_thread ();
|
2010-10-28 16:01:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioRegionEditor::~AudioRegionEditor ()
|
|
|
|
{
|
|
|
|
void* v;
|
2016-05-15 20:49:18 -04:00
|
|
|
_peak_channel.deliver ('t');
|
2011-09-30 13:55:14 -04:00
|
|
|
pthread_join (_peak_amplitude_thread_handle, &v);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-02-19 13:09:08 -05:00
|
|
|
AudioRegionEditor::region_changed (const PBD::PropertyChange& what_changed)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2010-05-21 20:26:26 -04:00
|
|
|
RegionEditor::region_changed (what_changed);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-02-19 13:09:08 -05:00
|
|
|
if (what_changed.contains (ARDOUR::Properties::scale_amplitude)) {
|
2009-10-23 19:21:55 -04:00
|
|
|
gain_changed ();
|
|
|
|
}
|
2011-04-04 08:21:26 -04:00
|
|
|
|
|
|
|
if (what_changed.contains (ARDOUR::Properties::start) || what_changed.contains (ARDOUR::Properties::length)) {
|
|
|
|
/* ask the peak thread to run again */
|
2013-07-13 08:27:56 -04:00
|
|
|
signal_peak_thread ();
|
2011-04-04 08:21:26 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2009-10-23 19:21:55 -04:00
|
|
|
void
|
|
|
|
AudioRegionEditor::gain_changed ()
|
|
|
|
{
|
2010-05-21 20:26:26 -04:00
|
|
|
float const region_gain_dB = accurate_coefficient_to_dB (_audio_region->scale_amplitude());
|
2009-10-23 19:21:55 -04:00
|
|
|
if (region_gain_dB != gain_adjustment.get_value()) {
|
|
|
|
gain_adjustment.set_value(region_gain_dB);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioRegionEditor::gain_adjustment_changed ()
|
|
|
|
{
|
|
|
|
float const gain = dB_to_coefficient (gain_adjustment.get_value());
|
2010-05-21 20:26:26 -04:00
|
|
|
if (_audio_region->scale_amplitude() != gain) {
|
|
|
|
_audio_region->set_scale_amplitude (gain);
|
2009-10-23 19:21:55 -04:00
|
|
|
}
|
|
|
|
}
|
2010-10-28 16:01:26 -04:00
|
|
|
|
2013-07-13 08:27:56 -04:00
|
|
|
void
|
|
|
|
AudioRegionEditor::signal_peak_thread ()
|
|
|
|
{
|
|
|
|
_peak_channel.deliver ('c');
|
|
|
|
}
|
|
|
|
|
2010-10-28 16:01:26 -04:00
|
|
|
void
|
|
|
|
AudioRegionEditor::peak_amplitude_thread ()
|
|
|
|
{
|
2011-04-04 08:21:26 -04:00
|
|
|
while (1) {
|
2016-05-15 20:49:18 -04:00
|
|
|
char msg;
|
2011-04-04 08:21:26 -04:00
|
|
|
/* await instructions to run */
|
2016-05-15 20:49:18 -04:00
|
|
|
_peak_channel.receive (msg);
|
|
|
|
|
|
|
|
if (msg == 't') {
|
|
|
|
break;
|
|
|
|
}
|
2011-04-04 08:21:26 -04:00
|
|
|
|
|
|
|
/* compute peak amplitude and signal the fact */
|
|
|
|
PeakAmplitudeFound (accurate_coefficient_to_dB (_audio_region->maximum_amplitude ())); /* EMIT SIGNAL */
|
|
|
|
}
|
2010-10-28 16:01:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioRegionEditor::peak_amplitude_found (double p)
|
|
|
|
{
|
2010-11-03 21:56:56 -04:00
|
|
|
stringstream s;
|
|
|
|
s.precision (2);
|
|
|
|
s.setf (ios::fixed, ios::floatfield);
|
|
|
|
s << p;
|
|
|
|
_peak_amplitude.set_text (s.str ());
|
2010-10-28 16:01:26 -04:00
|
|
|
}
|
|
|
|
|