2009-04-29 13:05:42 -04:00
|
|
|
/*
|
2009-10-14 12:10:01 -04:00
|
|
|
Copyright (C) 2009 Paul Davis
|
2009-04-29 13:05:42 -04:00
|
|
|
|
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2010-03-03 18:38:42 -05:00
|
|
|
#include <iostream>
|
|
|
|
|
2009-04-29 13:05:42 -04:00
|
|
|
#include <gtkmm/table.h>
|
|
|
|
#include <gtkmm/label.h>
|
|
|
|
#include <gtkmm/stock.h>
|
2009-12-21 13:23:07 -05:00
|
|
|
|
2012-05-24 02:09:29 -04:00
|
|
|
#include "ardour/audioregion.h"
|
2009-04-30 13:07:57 -04:00
|
|
|
#include "ardour/dB.h"
|
|
|
|
#include "ardour_ui.h"
|
2010-03-04 21:05:20 -05:00
|
|
|
|
2011-06-02 13:50:37 -04:00
|
|
|
#include "audio_clock.h"
|
2009-12-21 13:23:07 -05:00
|
|
|
#include "gui_thread.h"
|
2009-04-29 13:05:42 -04:00
|
|
|
#include "strip_silence_dialog.h"
|
2009-04-30 13:07:57 -04:00
|
|
|
#include "canvas_impl.h"
|
2010-12-08 16:02:37 -05:00
|
|
|
#include "region_view.h"
|
2010-04-30 10:50:25 -04:00
|
|
|
#include "simpleline.h"
|
2009-04-30 13:07:57 -04:00
|
|
|
#include "waveview.h"
|
|
|
|
#include "simplerect.h"
|
|
|
|
#include "rgb_macros.h"
|
2009-04-29 13:05:42 -04:00
|
|
|
#include "i18n.h"
|
2010-04-30 10:50:25 -04:00
|
|
|
#include "logmeter.h"
|
2009-04-29 13:05:42 -04:00
|
|
|
|
2010-02-18 08:59:49 -05:00
|
|
|
using namespace ARDOUR;
|
2010-03-03 18:38:42 -05:00
|
|
|
using namespace std;
|
|
|
|
using namespace ArdourCanvas;
|
|
|
|
|
2009-04-29 13:05:42 -04:00
|
|
|
/** Construct Strip silence dialog box */
|
2010-12-08 16:02:37 -05:00
|
|
|
StripSilenceDialog::StripSilenceDialog (Session* s, list<RegionView*> const & v)
|
2010-03-03 18:38:42 -05:00
|
|
|
: ArdourDialog (_("Strip Silence"))
|
2010-09-19 20:58:25 -04:00
|
|
|
, ProgressReporter ()
|
2011-11-17 17:49:13 -05:00
|
|
|
, _minimum_length (new AudioClock (X_("silence duration"), true, "", true, false, true, false))
|
|
|
|
, _fade_length (new AudioClock (X_("silence duration"), true, "", true, false, true, false))
|
2010-04-21 21:40:33 -04:00
|
|
|
, _peaks_ready_connection (0)
|
2010-11-22 20:00:37 -05:00
|
|
|
, _destroying (false)
|
2009-04-29 13:05:42 -04:00
|
|
|
{
|
2010-03-04 21:05:20 -05:00
|
|
|
set_session (s);
|
|
|
|
|
2010-12-08 16:02:37 -05:00
|
|
|
for (list<RegionView*>::const_iterator r = v.begin(); r != v.end(); ++r) {
|
|
|
|
views.push_back (ViewInterval (*r));
|
|
|
|
}
|
|
|
|
|
2009-04-30 13:07:57 -04:00
|
|
|
Gtk::HBox* hbox = Gtk::manage (new Gtk::HBox);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-04-30 10:50:25 -04:00
|
|
|
Gtk::Table* table = Gtk::manage (new Gtk::Table (3, 3));
|
|
|
|
table->set_spacings (6);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-04-30 10:50:25 -04:00
|
|
|
int n = 0;
|
2009-04-29 13:05:42 -04:00
|
|
|
|
2010-04-30 10:50:25 -04:00
|
|
|
table->attach (*Gtk::manage (new Gtk::Label (_("Threshold"), 1, 0.5)), 0, 1, n, n + 1, Gtk::FILL);
|
|
|
|
table->attach (_threshold, 1, 2, n, n + 1, Gtk::FILL);
|
|
|
|
table->attach (*Gtk::manage (new Gtk::Label (_("dbFS"))), 2, 3, n, n + 1, Gtk::FILL);
|
|
|
|
++n;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2009-04-29 13:05:42 -04:00
|
|
|
_threshold.set_digits (1);
|
|
|
|
_threshold.set_increments (1, 10);
|
|
|
|
_threshold.set_range (-120, 0);
|
|
|
|
_threshold.set_value (-60);
|
2011-11-14 08:44:05 -05:00
|
|
|
_threshold.set_activates_default ();
|
2010-03-04 21:05:20 -05:00
|
|
|
|
2010-04-30 10:50:25 -04:00
|
|
|
table->attach (*Gtk::manage (new Gtk::Label (_("Minimum length"), 1, 0.5)), 0, 1, n, n + 1, Gtk::FILL);
|
2011-06-02 13:50:37 -04:00
|
|
|
table->attach (*_minimum_length, 1, 2, n, n + 1, Gtk::FILL);
|
2010-04-30 10:50:25 -04:00
|
|
|
++n;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-06-02 13:50:37 -04:00
|
|
|
_minimum_length->set_session (s);
|
|
|
|
_minimum_length->set_mode (AudioClock::Frames);
|
|
|
|
_minimum_length->set (1000, true);
|
2009-04-29 13:05:42 -04:00
|
|
|
|
2010-04-30 10:50:25 -04:00
|
|
|
table->attach (*Gtk::manage (new Gtk::Label (_("Fade length"), 1, 0.5)), 0, 1, n, n + 1, Gtk::FILL);
|
2011-06-02 13:50:37 -04:00
|
|
|
table->attach (*_fade_length, 1, 2, n, n + 1, Gtk::FILL);
|
2010-04-30 10:50:25 -04:00
|
|
|
++n;
|
2010-03-04 21:05:20 -05:00
|
|
|
|
2011-06-02 13:50:37 -04:00
|
|
|
_fade_length->set_session (s);
|
|
|
|
_fade_length->set_mode (AudioClock::Frames);
|
|
|
|
_fade_length->set (64, true);
|
2009-04-30 13:07:57 -04:00
|
|
|
|
2010-04-30 10:50:25 -04:00
|
|
|
hbox->pack_start (*table);
|
|
|
|
|
2010-03-03 18:38:42 -05:00
|
|
|
get_vbox()->pack_start (*hbox, false, false);
|
2009-04-29 13:05:42 -04:00
|
|
|
|
|
|
|
add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
|
|
|
add_button (Gtk::Stock::APPLY, Gtk::RESPONSE_OK);
|
2011-11-14 08:44:05 -05:00
|
|
|
set_default_response (Gtk::RESPONSE_OK);
|
2009-04-29 13:05:42 -04:00
|
|
|
|
2010-12-09 11:31:05 -05:00
|
|
|
get_vbox()->pack_start (_progress_bar, true, true, 12);
|
2010-09-19 20:58:25 -04:00
|
|
|
|
2009-04-29 13:05:42 -04:00
|
|
|
show_all ();
|
2009-04-30 13:07:57 -04:00
|
|
|
|
2010-04-30 10:50:25 -04:00
|
|
|
_threshold.get_adjustment()->signal_value_changed().connect (sigc::mem_fun (*this, &StripSilenceDialog::threshold_changed));
|
2011-06-02 13:50:37 -04:00
|
|
|
_minimum_length->ValueChanged.connect (sigc::mem_fun (*this, &StripSilenceDialog::restart_thread));
|
2010-03-03 18:38:42 -05:00
|
|
|
|
2009-04-30 13:07:57 -04:00
|
|
|
update_silence_rects ();
|
2010-04-30 10:50:25 -04:00
|
|
|
update_threshold_line ();
|
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
/* Create a thread which runs while the dialogue is open to compute the silence regions */
|
2012-04-25 08:58:19 -04:00
|
|
|
Completed.connect (_completed_connection, MISSING_INVALIDATOR, boost::bind (&StripSilenceDialog::update, this), gui_context ());
|
2010-11-22 12:15:32 -05:00
|
|
|
_thread_should_finish = false;
|
|
|
|
pthread_create (&_thread, 0, StripSilenceDialog::_detection_thread_work, this);
|
2009-04-30 13:07:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
StripSilenceDialog::~StripSilenceDialog ()
|
|
|
|
{
|
2010-11-22 20:00:37 -05:00
|
|
|
_destroying = true;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
/* Terminate our thread */
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
_lock.lock ();
|
|
|
|
_interthread_info.cancel = true;
|
|
|
|
_thread_should_finish = true;
|
|
|
|
_lock.unlock ();
|
2010-11-22 20:00:37 -05:00
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
_run_cond.signal ();
|
|
|
|
pthread_join (_thread, 0);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-06-02 13:50:37 -04:00
|
|
|
delete _minimum_length;
|
|
|
|
delete _fade_length;
|
|
|
|
|
2010-12-09 11:31:05 -05:00
|
|
|
delete _peaks_ready_connection;
|
|
|
|
}
|
|
|
|
|
2010-12-09 13:17:36 -05:00
|
|
|
void
|
|
|
|
StripSilenceDialog::silences (AudioIntervalMap& m)
|
2010-12-09 11:31:05 -05:00
|
|
|
{
|
|
|
|
for (list<ViewInterval>::iterator v = views.begin(); v != views.end(); ++v) {
|
2011-02-28 10:01:01 -05:00
|
|
|
pair<boost::shared_ptr<Region>,AudioIntervalResult> newpair (v->view->region(), v->intervals);
|
2010-12-09 11:31:05 -05:00
|
|
|
m.insert (newpair);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StripSilenceDialog::drop_rects ()
|
|
|
|
{
|
2010-12-08 16:02:37 -05:00
|
|
|
for (list<ViewInterval>::iterator v = views.begin(); v != views.end(); ++v) {
|
2011-02-28 10:01:01 -05:00
|
|
|
v->view->drop_silent_frames ();
|
2010-12-08 16:02:37 -05:00
|
|
|
}
|
2009-04-30 13:07:57 -04:00
|
|
|
}
|
|
|
|
|
2010-04-30 10:50:25 -04:00
|
|
|
void
|
|
|
|
StripSilenceDialog::update_threshold_line ()
|
|
|
|
{
|
2010-12-08 16:02:37 -05:00
|
|
|
#if 0
|
2010-04-30 10:50:25 -04:00
|
|
|
int n = 0;
|
2010-11-22 12:15:32 -05:00
|
|
|
|
|
|
|
/* Don't need to lock here as we're not reading the _waves silence details */
|
|
|
|
|
2010-04-30 10:50:25 -04:00
|
|
|
for (list<Wave*>::iterator i = _waves.begin(); i != _waves.end(); ++i) {
|
|
|
|
(*i)->threshold_line->property_x1() = 0;
|
|
|
|
(*i)->threshold_line->property_x2() = _wave_width;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-04-30 10:50:25 -04:00
|
|
|
double const y = alt_log_meter (_threshold.get_value());
|
|
|
|
|
|
|
|
(*i)->threshold_line->property_y1() = (n + 1 - y) * _wave_height;
|
|
|
|
(*i)->threshold_line->property_y2() = (n + 1 - y) * _wave_height;
|
|
|
|
}
|
|
|
|
|
|
|
|
++n;
|
2010-12-08 16:02:37 -05:00
|
|
|
#endif
|
2010-04-30 10:50:25 -04:00
|
|
|
}
|
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
void
|
|
|
|
StripSilenceDialog::update ()
|
|
|
|
{
|
|
|
|
update_threshold_line ();
|
2010-12-08 16:02:37 -05:00
|
|
|
update_silence_rects ();
|
2010-11-22 12:15:32 -05:00
|
|
|
}
|
|
|
|
|
2009-04-30 13:07:57 -04:00
|
|
|
void
|
|
|
|
StripSilenceDialog::update_silence_rects ()
|
|
|
|
{
|
2010-11-22 12:15:32 -05:00
|
|
|
/* Lock so that we don't contend with the detection thread for access to the silence regions */
|
|
|
|
Glib::Mutex::Lock lm (_lock);
|
2010-12-09 13:17:36 -05:00
|
|
|
double const y = _threshold.get_value();
|
|
|
|
|
2010-12-08 16:02:37 -05:00
|
|
|
for (list<ViewInterval>::iterator v = views.begin(); v != views.end(); ++v) {
|
2011-02-28 10:01:01 -05:00
|
|
|
v->view->set_silent_frames (v->intervals, y);
|
2009-04-30 13:07:57 -04:00
|
|
|
}
|
2010-03-03 18:38:42 -05:00
|
|
|
}
|
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
void *
|
2010-03-03 18:38:42 -05:00
|
|
|
StripSilenceDialog::_detection_thread_work (void* arg)
|
|
|
|
{
|
2010-11-22 12:15:32 -05:00
|
|
|
StripSilenceDialog* d = reinterpret_cast<StripSilenceDialog*> (arg);
|
|
|
|
return d->detection_thread_work ();
|
2010-03-03 18:38:42 -05:00
|
|
|
}
|
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
/** Body of our silence detection thread */
|
|
|
|
void *
|
2010-03-03 18:38:42 -05:00
|
|
|
StripSilenceDialog::detection_thread_work ()
|
|
|
|
{
|
|
|
|
ARDOUR_UI::instance()->register_thread ("gui", pthread_self(), "silence", 32);
|
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
/* Hold this lock when we are doing work */
|
|
|
|
_lock.lock ();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
while (1) {
|
2010-12-08 16:02:37 -05:00
|
|
|
for (list<ViewInterval>::iterator i = views.begin(); i != views.end(); ++i) {
|
|
|
|
boost::shared_ptr<AudioRegion> ar = boost::dynamic_pointer_cast<AudioRegion> ((*i).view->region());
|
|
|
|
|
|
|
|
if (ar) {
|
2011-02-28 10:01:01 -05:00
|
|
|
i->intervals = ar->find_silence (dB_to_coefficient (threshold ()), minimum_length (), _interthread_info);
|
2010-12-08 16:02:37 -05:00
|
|
|
}
|
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
if (_interthread_info.cancel) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2010-03-03 18:38:42 -05:00
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
if (!_interthread_info.cancel) {
|
|
|
|
Completed (); /* EMIT SIGNAL */
|
|
|
|
}
|
2010-03-03 18:38:42 -05:00
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
/* Our work is done; sleep until there is more to do.
|
|
|
|
* The lock is released while we are waiting.
|
|
|
|
*/
|
|
|
|
_run_cond.wait (_lock);
|
2010-03-03 18:38:42 -05:00
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
if (_thread_should_finish) {
|
|
|
|
_lock.unlock ();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2010-03-03 18:38:42 -05:00
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
return 0;
|
2010-04-30 10:50:25 -04:00
|
|
|
}
|
|
|
|
|
2010-03-03 18:38:42 -05:00
|
|
|
void
|
2010-11-22 12:15:32 -05:00
|
|
|
StripSilenceDialog::restart_thread ()
|
2010-03-03 18:38:42 -05:00
|
|
|
{
|
2010-11-22 20:00:37 -05:00
|
|
|
if (_destroying) {
|
|
|
|
/* I don't know how this happens, but it seems to be possible for this
|
|
|
|
method to be called after our destructor has finished executing.
|
|
|
|
If this happens, bad things follow; _lock cannot be locked and
|
|
|
|
Ardour hangs. So if we are destroying, just bail early.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
/* Cancel any current run */
|
|
|
|
_interthread_info.cancel = true;
|
2010-03-03 18:38:42 -05:00
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
/* Block until the thread waits() */
|
|
|
|
_lock.lock ();
|
|
|
|
/* Reset the flag */
|
|
|
|
_interthread_info.cancel = false;
|
|
|
|
_lock.unlock ();
|
2010-03-03 18:38:42 -05:00
|
|
|
|
2010-11-22 12:15:32 -05:00
|
|
|
/* And re-awake the thread */
|
|
|
|
_run_cond.signal ();
|
2010-03-03 18:38:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-11-22 12:15:32 -05:00
|
|
|
StripSilenceDialog::threshold_changed ()
|
2010-03-03 18:38:42 -05:00
|
|
|
{
|
2010-11-22 12:15:32 -05:00
|
|
|
update_threshold_line ();
|
|
|
|
restart_thread ();
|
2009-04-29 13:05:42 -04:00
|
|
|
}
|
2010-03-04 21:05:20 -05:00
|
|
|
|
2010-12-03 17:26:29 -05:00
|
|
|
framecnt_t
|
2010-03-04 21:05:20 -05:00
|
|
|
StripSilenceDialog::minimum_length () const
|
|
|
|
{
|
2011-06-02 13:50:37 -04:00
|
|
|
return _minimum_length->current_duration (views.front().view->region()->position());
|
2010-03-04 21:05:20 -05:00
|
|
|
}
|
|
|
|
|
2010-12-03 17:26:29 -05:00
|
|
|
framecnt_t
|
2010-03-04 21:05:20 -05:00
|
|
|
StripSilenceDialog::fade_length () const
|
|
|
|
{
|
2011-06-02 13:50:37 -04:00
|
|
|
return _fade_length->current_duration (views.front().view->region()->position());
|
2010-04-30 10:50:25 -04:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-09-19 20:58:25 -04:00
|
|
|
void
|
|
|
|
StripSilenceDialog::update_progress_gui (float p)
|
|
|
|
{
|
|
|
|
_progress_bar.set_fraction (p);
|
|
|
|
}
|