From 57e1c287509d9a6f1d8b3b64000625b68a8b997a Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 30 Apr 2009 17:07:57 +0000 Subject: [PATCH] Preview effect of strip silence within the dialog. git-svn-id: svn://localhost/ardour2/branches/3.0@5017 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/editor_ops.cc | 18 +++- gtk2_ardour/strip_silence_dialog.cc | 135 +++++++++++++++++++++++++++- gtk2_ardour/strip_silence_dialog.h | 27 +++++- 3 files changed, 175 insertions(+), 5 deletions(-) diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 66286b62f0..b1ad57f9cd 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -4669,7 +4669,23 @@ Editor::strip_region_silence () return; } - StripSilenceDialog d; + RegionSelection rs; + get_regions_for_action (rs); + + if (rs.empty()) { + return; + } + + std::list > ar; + + for (RegionSelection::iterator i = rs.begin(); i != rs.end(); ++i) { + AudioRegionView* const arv = dynamic_cast (*i); + if (arv) { + ar.push_back (arv->audio_region ()); + } + } + + StripSilenceDialog d (ar); int const r = d.run (); if (r == Gtk::RESPONSE_OK) { diff --git a/gtk2_ardour/strip_silence_dialog.cc b/gtk2_ardour/strip_silence_dialog.cc index cf1ef25461..2770d6b03d 100644 --- a/gtk2_ardour/strip_silence_dialog.cc +++ b/gtk2_ardour/strip_silence_dialog.cc @@ -20,13 +20,34 @@ #include #include #include +#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 > const & regions) + : ArdourDialog (_("Strip silence")), _wave_width (640), _wave_height (64) { + for (std::list >::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::iterator i = _waves.begin(); i != _waves.end(); ++i) { + delete i->view; + for (std::list::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::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(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::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::iterator i = _waves.begin(); i != _waves.end(); ++i) { + for (std::list::iterator j = i->silence_rects.begin(); j != i->silence_rects.end(); ++j) { + delete *j; + } + + i->silence_rects.clear (); + + std::list > const silence = + i->region->find_silence (dB_to_coefficient (threshold ()), minimum_length ()); + + for (std::list >::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; + } } diff --git a/gtk2_ardour/strip_silence_dialog.h b/gtk2_ardour/strip_silence_dialog.h index faf52c268a..351fffa005 100644 --- a/gtk2_ardour/strip_silence_dialog.h +++ b/gtk2_ardour/strip_silence_dialog.h @@ -19,12 +19,18 @@ #include #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 > 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 region; + ArdourCanvas::WaveView* view; + std::list silence_rects; + double samples_per_unit; + }; + + ArdourCanvas::Canvas* _canvas; + std::list _waves; + int _wave_width; + int _wave_height; + + sigc::connection _peaks_ready_connection; };