diff options
author | Carl Hetherington <carl@carlh.net> | 2009-04-29 17:05:42 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2009-04-29 17:05:42 +0000 |
commit | 9e776feac62e7a9609a29fa233f21d5278475a9d (patch) | |
tree | 388f298b35807462380f2115acd289e67a5e0f70 | |
parent | 459c43951238fd771231f840733468b84079dcdc (diff) |
Add files missing from previous commit.
git-svn-id: svn://localhost/ardour2/branches/3.0@5011 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r-- | gtk2_ardour/strip_silence_dialog.cc | 73 | ||||
-rw-r--r-- | gtk2_ardour/strip_silence_dialog.h | 45 | ||||
-rw-r--r-- | libs/ardour/ardour/strip_silence.h | 38 | ||||
-rw-r--r-- | libs/ardour/strip_silence.cc | 125 |
4 files changed, 281 insertions, 0 deletions
diff --git a/gtk2_ardour/strip_silence_dialog.cc b/gtk2_ardour/strip_silence_dialog.cc new file mode 100644 index 0000000000..cf1ef25461 --- /dev/null +++ b/gtk2_ardour/strip_silence_dialog.cc @@ -0,0 +1,73 @@ +/* + Copyright (C) 2009 Paul Davis + + 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. + +*/ + +#include <gtkmm/table.h> +#include <gtkmm/label.h> +#include <gtkmm/stock.h> +#include "strip_silence_dialog.h" +#include "i18n.h" + +/** Construct Strip silence dialog box */ +StripSilenceDialog::StripSilenceDialog () + : ArdourDialog (_("Strip silence")) +{ + Gtk::Table* table = Gtk::manage (new Gtk::Table (4, 3)); + table->set_spacings (4); + + Gtk::Label* l = Gtk::manage (new Gtk::Label (_("Threshold:"))); + l->set_alignment (1, 0.5); + table->attach (*l, 0, 1, 0, 1, Gtk::FILL, Gtk::FILL); + _threshold.set_digits (1); + _threshold.set_increments (1, 10); + _threshold.set_range (-120, 0); + _threshold.set_value (-60); + table->attach (_threshold, 1, 2, 0, 1, Gtk::FILL, Gtk::FILL); + l = Gtk::manage (new Gtk::Label (_("dBFS"))); + l->set_alignment (0, 0.5); + table->attach (*l, 2, 3, 0, 1, Gtk::FILL, Gtk::FILL); + + l = Gtk::manage (new Gtk::Label (_("Minimum length:"))); + l->set_alignment (1, 0.5); + table->attach (*l, 0, 1, 1, 2, Gtk::FILL, Gtk::FILL); + _minimum_length.set_digits (0); + _minimum_length.set_increments (1, 10); + _minimum_length.set_range (0, 65536); + _minimum_length.set_value (256); + table->attach (_minimum_length, 1, 2, 1, 2, Gtk::FILL, Gtk::FILL); + l = Gtk::manage (new Gtk::Label (_("samples"))); + table->attach (*l, 2, 3, 1, 2, Gtk::FILL, Gtk::FILL); + + l = Gtk::manage (new Gtk::Label (_("Fade length:"))); + l->set_alignment (1, 0.5); + table->attach (*l, 0, 1, 2, 3, Gtk::FILL, Gtk::FILL); + _fade_length.set_digits (0); + _fade_length.set_increments (1, 10); + _fade_length.set_range (0, 1024); + _fade_length.set_value (64); + table->attach (_fade_length, 1, 2, 2, 3, Gtk::FILL, Gtk::FILL); + l = Gtk::manage (new Gtk::Label (_("samples"))); + table->attach (*l, 2, 3, 2, 3, Gtk::FILL, Gtk::FILL); + + get_vbox()->add (*table); + + add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + add_button (Gtk::Stock::APPLY, Gtk::RESPONSE_OK); + + show_all (); +} diff --git a/gtk2_ardour/strip_silence_dialog.h b/gtk2_ardour/strip_silence_dialog.h new file mode 100644 index 0000000000..faf52c268a --- /dev/null +++ b/gtk2_ardour/strip_silence_dialog.h @@ -0,0 +1,45 @@ +/* + Copyright (C) 2009 Paul Davis + + 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. + +*/ + +#include <gtkmm/spinbutton.h> +#include "ardour_dialog.h" + +/// Dialog box to set options for the `strip silence' filter +class StripSilenceDialog : public ArdourDialog +{ +public: + StripSilenceDialog (); + + double threshold () const { + return _threshold.get_value (); + } + + nframes_t minimum_length () const { + return _minimum_length.get_value_as_int (); + } + + nframes_t fade_length () const { + return _fade_length.get_value_as_int (); + } + +private: + Gtk::SpinButton _threshold; + Gtk::SpinButton _minimum_length; + Gtk::SpinButton _fade_length; +}; diff --git a/libs/ardour/ardour/strip_silence.h b/libs/ardour/ardour/strip_silence.h new file mode 100644 index 0000000000..dab3ddd3d5 --- /dev/null +++ b/libs/ardour/ardour/strip_silence.h @@ -0,0 +1,38 @@ +/* + Copyright (C) 2009 Paul Davis + + 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. + +*/ + +#include "ardour/filter.h" + +namespace ARDOUR { + +/// A filter to strip silence from regions +class StripSilence : public Filter { + +public: + StripSilence (Session &, double, nframes_t, nframes_t); + + int run (boost::shared_ptr<ARDOUR::Region>); + +private: + double _threshold; ///< silence threshold, in dBFS + nframes_t _minimum_length; ///< minimum length to be considered silence, in samples + nframes_t _fade_length; ///< fade in/out to use on trimmed regions, in samples +}; + +} diff --git a/libs/ardour/strip_silence.cc b/libs/ardour/strip_silence.cc new file mode 100644 index 0000000000..dbb36735dd --- /dev/null +++ b/libs/ardour/strip_silence.cc @@ -0,0 +1,125 @@ +/* + Copyright (C) 2009 Paul Davis + + 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. + +*/ + +#include "ardour/strip_silence.h" +#include "ardour/audioregion.h" +#include "ardour/region_factory.h" +#include "ardour/session.h" +#include "ardour/dB.h" + +using namespace ARDOUR; + +/** Construct a StripSilence filter. + * @param s Session. + * @param threshold Threshold below which audio is considered silence, in dBFS. + * @param minimum_length Minimum length of silence period to recognise, in samples. + * @param fade_length Length of fade in/out to apply to trimmed regions, in samples. + */ + +StripSilence::StripSilence (Session & s, double threshold, nframes_t minimum_length, nframes_t fade_length) + : Filter (s), _threshold (threshold), _minimum_length (minimum_length), _fade_length (fade_length) +{ + +} + +int +StripSilence::run (boost::shared_ptr<Region> r) +{ + results.clear (); + + /* we only operate on AudioRegions, for now, though this could be adapted to MIDI + as well I guess */ + boost::shared_ptr<AudioRegion> region = boost::dynamic_pointer_cast<AudioRegion> (r); + if (!region) { + results.push_back (r); + return -1; + } + + /* find periods of silence in the region */ + std::list<std::pair<nframes_t, nframes_t> > const silence = + region->find_silence (dB_to_coefficient (_threshold), _minimum_length); + + if (silence.size () == 1 && silence.front().first == 0 && silence.front().second == region->length() - 1) { + /* the region is all silence, so just return with nothing */ + return 0; + } + + if (silence.empty()) { + /* no silence in this region */ + results.push_back (region); + return 0; + } + + std::list<std::pair<nframes_t, nframes_t > >::const_iterator s = silence.begin (); + nframes_t const pos = region->position (); + nframes_t const end = region->start () + region->length() - 1; + nframes_t const start = region->start (); + + region = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (region)); + region->set_name (session.new_region_name (region->name ())); + boost::shared_ptr<AudioRegion> last_region = region; + results.push_back (region); + + if (s->first == 0) { + /* the region starts with some silence */ + + /* we must set length to an intermediate value here, otherwise the call + ** to set_start will fail */ + region->set_length (region->length() - s->second + _fade_length, 0); + region->set_start (start + s->second - _fade_length, 0); + region->set_position (pos + s->second - _fade_length, 0); + region->set_fade_in_active (true); + region->set_fade_in (AudioRegion::Linear, _fade_length); + s++; + } + + while (s != silence.end()) { + + /* trim the end of this region */ + region->trim_end (pos + s->first + _fade_length, 0); + region->set_fade_out_active (true); + region->set_fade_out (AudioRegion::Linear, _fade_length); + + /* make a new region and trim its start */ + region = boost::dynamic_pointer_cast<AudioRegion> (RegionFactory::create (region)); + region->set_name (session.new_region_name (region->name ())); + last_region = region; + assert (region); + results.push_back (region); + + /* set length here for the same reasons as above */ + region->set_length (region->length() - s->second + _fade_length, 0); + region->set_start (start + s->second - _fade_length, 0); + region->set_position (pos + s->second - _fade_length, 0); + region->set_fade_in_active (true); + region->set_fade_in (AudioRegion::Linear, _fade_length); + + s++; + } + + if (silence.back().second == end) { + /* the last region we created is zero-sized, so just remove it */ + results.pop_back (); + } else { + /* finish off the last region */ + last_region->trim_end (end, 0); + } + + return 0; +} |