Preview effect of strip silence within the dialog.
git-svn-id: svn://localhost/ardour2/branches/3.0@5017 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
9ec3728796
commit
57e1c28750
@ -4669,7 +4669,23 @@ Editor::strip_region_silence ()
|
||||
return;
|
||||
}
|
||||
|
||||
StripSilenceDialog d;
|
||||
RegionSelection rs;
|
||||
get_regions_for_action (rs);
|
||||
|
||||
if (rs.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::list<boost::shared_ptr<AudioRegion> > ar;
|
||||
|
||||
for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) {
|
||||
AudioRegionView* const arv = dynamic_cast<AudioRegionView*> (*i);
|
||||
if (arv) {
|
||||
ar.push_back (arv->audio_region ());
|
||||
}
|
||||
}
|
||||
|
||||
StripSilenceDialog d (ar);
|
||||
int const r = d.run ();
|
||||
|
||||
if (r == Gtk::RESPONSE_OK) {
|
||||
|
@ -20,13 +20,34 @@
|
||||
#include <gtkmm/table.h>
|
||||
#include <gtkmm/label.h>
|
||||
#include <gtkmm/stock.h>
|
||||
#include "ardour/audioregion.h"
|
||||
#include "ardour/audiosource.h"
|
||||
#include "ardour/dB.h"
|
||||
#include "ardour_ui.h"
|
||||
#include "strip_silence_dialog.h"
|
||||
#include "canvas_impl.h"
|
||||
#include "waveview.h"
|
||||
#include "simplerect.h"
|
||||
#include "rgb_macros.h"
|
||||
#include "i18n.h"
|
||||
|
||||
/** Construct Strip silence dialog box */
|
||||
StripSilenceDialog::StripSilenceDialog ()
|
||||
: ArdourDialog (_("Strip silence"))
|
||||
StripSilenceDialog::StripSilenceDialog (std::list<boost::shared_ptr<ARDOUR::AudioRegion> > const & regions)
|
||||
: ArdourDialog (_("Strip silence")), _wave_width (640), _wave_height (64)
|
||||
{
|
||||
for (std::list<boost::shared_ptr<ARDOUR::AudioRegion> >::const_iterator i = regions.begin(); i != regions.end(); ++i) {
|
||||
|
||||
Wave w;
|
||||
w.region = *i;
|
||||
w.view = 0;
|
||||
w.samples_per_unit = 1;
|
||||
_waves.push_back (w);
|
||||
|
||||
}
|
||||
|
||||
Gtk::HBox* hbox = Gtk::manage (new Gtk::HBox);
|
||||
hbox->set_spacing (16);
|
||||
|
||||
Gtk::Table* table = Gtk::manage (new Gtk::Table (4, 3));
|
||||
table->set_spacings (4);
|
||||
|
||||
@ -64,10 +85,118 @@ StripSilenceDialog::StripSilenceDialog ()
|
||||
l = Gtk::manage (new Gtk::Label (_("samples")));
|
||||
table->attach (*l, 2, 3, 2, 3, Gtk::FILL, Gtk::FILL);
|
||||
|
||||
get_vbox()->add (*table);
|
||||
hbox->pack_start (*table, false, false);
|
||||
|
||||
Gtk::VBox* v = Gtk::manage (new Gtk::VBox);
|
||||
Gtk::Button* b = Gtk::manage (new Gtk::Button (_("Update display")));
|
||||
b->signal_clicked().connect (mem_fun (*this, &StripSilenceDialog::update_silence_rects));
|
||||
v->pack_start (*b, false, false);
|
||||
hbox->pack_start (*v, false, false);
|
||||
|
||||
get_vbox()->add (*hbox);
|
||||
|
||||
add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
|
||||
add_button (Gtk::Stock::APPLY, Gtk::RESPONSE_OK);
|
||||
|
||||
_canvas = new ArdourCanvas::CanvasAA ();
|
||||
_canvas->signal_size_allocate().connect (mem_fun (*this, &StripSilenceDialog::canvas_allocation));
|
||||
_canvas->set_size_request (_wave_width, _wave_height * _waves.size ());
|
||||
|
||||
get_vbox()->pack_start (*_canvas, true, true);
|
||||
|
||||
show_all ();
|
||||
|
||||
create_waves ();
|
||||
update_silence_rects ();
|
||||
}
|
||||
|
||||
|
||||
StripSilenceDialog::~StripSilenceDialog ()
|
||||
{
|
||||
for (std::list<Wave>::iterator i = _waves.begin(); i != _waves.end(); ++i) {
|
||||
delete i->view;
|
||||
for (std::list<ArdourCanvas::SimpleRect*>::iterator j = i->silence_rects.begin(); j != i->silence_rects.end(); ++j) {
|
||||
delete *j;
|
||||
}
|
||||
}
|
||||
|
||||
delete _canvas;
|
||||
}
|
||||
|
||||
void
|
||||
StripSilenceDialog::create_waves ()
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
for (std::list<Wave>::iterator i = _waves.begin(); i != _waves.end(); ++i) {
|
||||
if (i->region->audio_source(0)->peaks_ready (mem_fun (*this, &StripSilenceDialog::peaks_ready), _peaks_ready_connection)) {
|
||||
i->view = new WaveView (*(_canvas->root()));
|
||||
i->view->property_data_src() = static_cast<gpointer>(i->region.get());
|
||||
i->view->property_cache() = WaveView::create_cache ();
|
||||
i->view->property_cache_updater() = true;
|
||||
i->view->property_channel() = 0;
|
||||
i->view->property_length_function() = (void *) region_length_from_c;
|
||||
i->view->property_sourcefile_length_function() = (void *) sourcefile_length_from_c;
|
||||
i->view->property_peak_function() = (void *) region_read_peaks_from_c;
|
||||
i->view->property_x() = 0;
|
||||
i->view->property_y() = n * _wave_height;
|
||||
i->view->property_height() = _wave_height;
|
||||
i->view->property_samples_per_unit() = i->samples_per_unit;
|
||||
i->view->property_region_start() = i->region->start();
|
||||
i->view->property_wave_color() = ARDOUR_UI::config()->canvasvar_WaveForm.get();
|
||||
i->view->property_fill_color() = ARDOUR_UI::config()->canvasvar_WaveFormFill.get();
|
||||
}
|
||||
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
StripSilenceDialog::peaks_ready ()
|
||||
{
|
||||
_peaks_ready_connection.disconnect ();
|
||||
create_waves ();
|
||||
}
|
||||
|
||||
void
|
||||
StripSilenceDialog::canvas_allocation (Gtk::Allocation& alloc)
|
||||
{
|
||||
_canvas->set_scroll_region (0.0, 0.0, alloc.get_width(), alloc.get_height());
|
||||
_wave_width = alloc.get_width ();
|
||||
|
||||
for (std::list<Wave>::iterator i = _waves.begin(); i != _waves.end(); ++i) {
|
||||
i->samples_per_unit = ((double) i->region->length() / _wave_width);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
StripSilenceDialog::update_silence_rects ()
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
for (std::list<Wave>::iterator i = _waves.begin(); i != _waves.end(); ++i) {
|
||||
for (std::list<ArdourCanvas::SimpleRect*>::iterator j = i->silence_rects.begin(); j != i->silence_rects.end(); ++j) {
|
||||
delete *j;
|
||||
}
|
||||
|
||||
i->silence_rects.clear ();
|
||||
|
||||
std::list<std::pair<nframes_t, nframes_t> > const silence =
|
||||
i->region->find_silence (dB_to_coefficient (threshold ()), minimum_length ());
|
||||
|
||||
for (std::list<std::pair<nframes_t, nframes_t> >::const_iterator j = silence.begin(); j != silence.end(); ++j) {
|
||||
|
||||
ArdourCanvas::SimpleRect* r = new ArdourCanvas::SimpleRect (*(_canvas->root()));
|
||||
r->property_x1() = j->first / i->samples_per_unit;
|
||||
r->property_x2() = j->second / i->samples_per_unit;
|
||||
r->property_y1() = n * _wave_height;
|
||||
r->property_y2() = (n + 1) * _wave_height;
|
||||
r->property_outline_pixels() = 0;
|
||||
r->property_fill_color_rgba() = RGBA_TO_UINT (128, 128, 128, 128);
|
||||
i->silence_rects.push_back (r);
|
||||
|
||||
}
|
||||
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,18 @@
|
||||
|
||||
#include <gtkmm/spinbutton.h>
|
||||
#include "ardour_dialog.h"
|
||||
#include "canvas.h"
|
||||
|
||||
namespace ARDOUR {
|
||||
class AudioRegion;
|
||||
}
|
||||
|
||||
/// Dialog box to set options for the `strip silence' filter
|
||||
class StripSilenceDialog : public ArdourDialog
|
||||
{
|
||||
public:
|
||||
StripSilenceDialog ();
|
||||
StripSilenceDialog (std::list<boost::shared_ptr<ARDOUR::AudioRegion> > const &);
|
||||
~StripSilenceDialog ();
|
||||
|
||||
double threshold () const {
|
||||
return _threshold.get_value ();
|
||||
@ -39,7 +45,26 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void create_waves ();
|
||||
void peaks_ready ();
|
||||
void canvas_allocation (Gtk::Allocation &);
|
||||
void update_silence_rects ();
|
||||
|
||||
Gtk::SpinButton _threshold;
|
||||
Gtk::SpinButton _minimum_length;
|
||||
Gtk::SpinButton _fade_length;
|
||||
|
||||
struct Wave {
|
||||
boost::shared_ptr<ARDOUR::AudioRegion> region;
|
||||
ArdourCanvas::WaveView* view;
|
||||
std::list<ArdourCanvas::SimpleRect*> silence_rects;
|
||||
double samples_per_unit;
|
||||
};
|
||||
|
||||
ArdourCanvas::Canvas* _canvas;
|
||||
std::list<Wave> _waves;
|
||||
int _wave_width;
|
||||
int _wave_height;
|
||||
|
||||
sigc::connection _peaks_ready_connection;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user