summaryrefslogtreecommitdiff
path: root/gtk2_ardour
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2010-12-09 16:31:05 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2010-12-09 16:31:05 +0000
commit0a62044c2c51b38c900ed75d4037e6093901f387 (patch)
tree280b47be28b61f79e8988619ca7026962bd3f457 /gtk2_ardour
parentd28ecb2b93540e64a7c8dc820dcb6dcedc17a550 (diff)
make strip silence work (again?)
git-svn-id: svn://localhost/ardour2/branches/3.0@8226 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'gtk2_ardour')
-rw-r--r--gtk2_ardour/editor_ops.cc8
-rw-r--r--gtk2_ardour/region_view.cc74
-rw-r--r--gtk2_ardour/strip_silence_dialog.cc176
-rw-r--r--gtk2_ardour/strip_silence_dialog.h12
4 files changed, 92 insertions, 178 deletions
diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc
index 4ad205c425..798496af74 100644
--- a/gtk2_ardour/editor_ops.cc
+++ b/gtk2_ardour/editor_ops.cc
@@ -4556,10 +4556,12 @@ Editor::strip_region_silence ()
StripSilenceDialog d (_session, audio_only);
int const r = d.run ();
- if (r == Gtk::RESPONSE_OK) {
- StripSilence s (*_session, d.threshold (), d.minimum_length (), d.fade_length ());
+ d.drop_rects ();
+
+ if (r == Gtk::RESPONSE_OK) {
+ StripSilence s (*_session, d.silences(), d.fade_length());
apply_filter (s, _("strip silence"), &d);
- }
+ }
}
Command*
diff --git a/gtk2_ardour/region_view.cc b/gtk2_ardour/region_view.cc
index 76fa158f9d..85770d731e 100644
--- a/gtk2_ardour/region_view.cc
+++ b/gtk2_ardour/region_view.cc
@@ -24,7 +24,6 @@
#include <gtkmm.h>
#include <gtkmm2ext/gtk_ui.h>
-#include "pbd/stacktrace.h"
#include "ardour/playlist.h"
#include "ardour/audioregion.h"
@@ -224,43 +223,77 @@ void
RegionView::set_silent_frames (const AudioIntervalResult& silences)
{
framecnt_t shortest = max_framecnt;
+ framecnt_t shortest_audible = max_framecnt;
+ bool seen_audible = false;
/* remove old silent frames */
drop_silent_frames ();
if (!silences.empty()) {
+
uint32_t const color = ARDOUR_UI::config()->canvasvar_Silence.get();
+ framecnt_t last_end;
+
+ if (silences.front().first != 0) {
+ /* use initial non-silent segment as shortest */
+ shortest_audible = silences.front().first;
+ seen_audible = true;
+ }
for (AudioIntervalResult::const_iterator i = silences.begin(); i != silences.end(); ++i) {
-
+
+ if ((*i).first > last_end) {
+ /* (audible) gap between the end of the last interval and this one */
+ shortest_audible = min (shortest_audible, (*i).first - last_end);
+ seen_audible = true;
+ }
+
ArdourCanvas::SimpleRect* cr = new ArdourCanvas::SimpleRect (*group);
_silent_frames.push_back (cr);
- cr->property_x1() = trackview.editor().frame_to_pixel ((*i).first);
+
+ /* coordinates for the rect are relative to the regionview origin */
+
+ cr->property_x1() = trackview.editor().frame_to_pixel ((*i).first - _region->start());
cr->property_y1() = 1;
cr->property_y2() = _height - 2;
cr->property_outline_pixels() = 0;
cr->property_fill_color_rgba () = color;
- cr->property_x2() = trackview.editor().frame_to_pixel ((*i).first + (*i).second);
- if ((*i).second < shortest) {
+ last_end = (*i).second;
+
+ cr->property_x2() = trackview.editor().frame_to_pixel ((*i).second - _region->start());
+
+ if (((*i).second - (*i).first) < shortest) {
shortest= (*i).second;
}
}
+ if (last_end != _region->length()) {
+ shortest_audible = min (shortest_audible, _region->last_frame() - last_end);
+ seen_audible = true;
+ }
+
_silence_text = new ArdourCanvas::NoEventText (*group);
_silence_text->property_font_desc() = *(get_font_for_style (N_("VerboseCanvasCusor")));
_silence_text->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SilenceText.get();
_silence_text->property_anchor() = ANCHOR_NW;
- /* both positions are relative to the RV start */
+ /* both positions are relative to the region start offset in source */
- _silence_text->property_x() = trackview.editor().frame_to_pixel (silences.front().first) + 10.0;
+ _silence_text->property_x() = trackview.editor().frame_to_pixel (silences.front().first - _region->start()) + 10.0;
_silence_text->property_y() = 20.0;
double ms;
char const * sunits;
+ char const * noun;
+ if (silences.size() > 1) {
+ noun = _("silent segments");
+ } else {
+ noun = _("silent segment");
+ }
+
ms = (float) shortest/_region->session().frame_rate();
/* ms are now in seconds */
@@ -275,11 +308,29 @@ RegionView::set_silent_frames (const AudioIntervalResult& silences)
sunits = _("secs");
}
+ if (seen_audible) {
+ /* ms are now in seconds */
+ double ma = shortest_audible / _region->session().frame_rate();
+ char const * aunits;
+
+ if (ma >= 60.0) {
+ aunits = _("minutes");
+ ma /= 60.0;
+ } else if (ma < 1.0) {
+ aunits = _("msecs");
+ ma *= 1000.0;
+ } else {
+ aunits = _("secs");
+ }
-
- _silence_text->property_text() = string_compose (_("%1 silent segments, shortest = %2 %3"),
- silences.size(), ms, sunits).c_str();
- }
+ _silence_text->property_text() = string_compose (_("%1 %2, shortest = %3 %4\n (shortest audible segment = %5 %6)"),
+ silences.size(), noun,
+ ms, sunits, ma, aunits).c_str();
+ } else {
+ _silence_text->property_text() = string_compose (_("%1 %2, shortest = %3 %4"),
+ silences.size(), noun, ms, sunits).c_str();
+ }
+ }
}
void
@@ -298,6 +349,7 @@ RegionView::drop_silent_frames ()
delete *i;
}
_silent_frames.clear ();
+
delete _silence_text;
_silence_text = 0;
}
diff --git a/gtk2_ardour/strip_silence_dialog.cc b/gtk2_ardour/strip_silence_dialog.cc
index da01387ffd..3e62e4247a 100644
--- a/gtk2_ardour/strip_silence_dialog.cc
+++ b/gtk2_ardour/strip_silence_dialog.cc
@@ -94,37 +94,12 @@ StripSilenceDialog::StripSilenceDialog (Session* s, list<RegionView*> const & v)
hbox->pack_start (*table);
- table = Gtk::manage (new Gtk::Table (3, 2));
- table->set_spacings (6);
-
- n = 0;
-
- table->attach (*Gtk::manage (new Gtk::Label (_("Silent segments:"), 1, 0.5)), 3, 4, n, n + 1, Gtk::FILL);
- table->attach (_segment_count_label, 5, 6, n, n + 1, Gtk::FILL);
- _segment_count_label.set_alignment (0, 0.5);
- ++n;
-
- table->attach (*Gtk::manage (new Gtk::Label (_("Shortest silence:"), 1, 0.5)), 3, 4, n, n + 1, Gtk::FILL);
- table->attach (_shortest_silence_label, 5, 6, n, n + 1, Gtk::FILL);
- _shortest_silence_label.set_alignment (0, 0.5);
- ++n;
-
- table->attach (*Gtk::manage (new Gtk::Label (_("Shortest audible:"), 1, 0.5)), 3, 4, n, n + 1, Gtk::FILL);
- table->attach (_shortest_audible_label, 5, 6, n, n + 1, Gtk::FILL);
- _shortest_audible_label.set_alignment (0, 0.5);
- ++n;
-
- hbox->pack_start (*table);
-
- /* dummy label for padding */
- hbox->pack_start (*Gtk::manage (new Gtk::Label ("")), true, true);
-
get_vbox()->pack_start (*hbox, false, false);
add_button (Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
add_button (Gtk::Stock::APPLY, Gtk::RESPONSE_OK);
- get_vbox()->pack_start (_progress_bar, true, true);
+ get_vbox()->pack_start (_progress_bar, true, true, 12);
show_all ();
@@ -155,11 +130,28 @@ StripSilenceDialog::~StripSilenceDialog ()
_run_cond.signal ();
pthread_join (_thread, 0);
+ delete _peaks_ready_connection;
+}
+
+AudioIntervalMap
+StripSilenceDialog::silences ()
+{
+ AudioIntervalMap m;
+
+ for (list<ViewInterval>::iterator v = views.begin(); v != views.end(); ++v) {
+ pair<boost::shared_ptr<Region>,AudioIntervalResult> newpair ((*v).view->region(), (*v).intervals);
+ m.insert (newpair);
+ }
+
+ return m;
+}
+
+void
+StripSilenceDialog::drop_rects ()
+{
for (list<ViewInterval>::iterator v = views.begin(); v != views.end(); ++v) {
(*v).view->drop_silent_frames ();
}
-
- delete _peaks_ready_connection;
}
void
@@ -187,75 +179,18 @@ StripSilenceDialog::update_threshold_line ()
void
StripSilenceDialog::update ()
{
- cerr << "UPDATE!\n";
update_threshold_line ();
- /* XXX: first one only?! */
- // update_stats (_waves.front()->silence);
-
update_silence_rects ();
- cerr << "UPDATE done\n";
}
void
StripSilenceDialog::update_silence_rects ()
{
- uint32_t max_segments = 0;
-
/* Lock so that we don't contend with the detection thread for access to the silence regions */
Glib::Mutex::Lock lm (_lock);
-
for (list<ViewInterval>::iterator v = views.begin(); v != views.end(); ++v) {
(*v).view->set_silent_frames ((*v).intervals);
- max_segments = max (max_segments, (uint32_t) (*v).intervals.size());
}
-
-#if 0
- cerr << "minaudible in update " << min_audible << " minsilence = " << min_silence << endl;
-
- if (min_audible > 0) {
- float ms, ma;
- char const * aunits;
- char const * sunits;
-
- ma = (float) min_audible/_session->frame_rate();
- ms = (float) min_silence/_session->frame_rate();
-
- /* ma and ms are now in seconds */
-
- if (ma >= 60.0) {
- aunits = _("minutes");
- //ma /= 60.0;
- } else if (min_audible < _session->frame_rate()) {
- aunits = _("msecs");
- ma *= 1000.0;
- } else {
- aunits = _("seconds");
- }
-
- if (ms >= 60.0) {
- sunits = _("minutes");
- //ms /= 60.0;
- } else if (min_silence < _session->frame_rate()) {
- sunits = _("ms");
- ms *= 1000.0;
- } else {
- sunits = _("s");
- }
-
- _segment_count_label.set_text (string_compose ("%1", max_segments));
- if (max_segments > 0) {
- _shortest_silence_label.set_text (string_compose ("%1 %2", ms, sunits));
- _shortest_audible_label.set_text (string_compose ("%1 %2", ma, aunits));
- } else {
- _shortest_silence_label.set_text ("");
- _shortest_audible_label.set_text ("");
- }
- } else {
- _segment_count_label.set_text (_("Full silence"));
- _shortest_silence_label.set_text ("");
- _shortest_audible_label.set_text ("");
- }
-#endif
}
void *
@@ -337,77 +272,6 @@ StripSilenceDialog::threshold_changed ()
restart_thread ();
}
-void
-StripSilenceDialog::update_stats (const AudioIntervalResult& res)
-{
- if (res.empty()) {
- return;
- }
-
- max_silence = 0;
- min_silence = max_framepos;
- max_audible = 0;
- min_audible = max_framepos;
-
- AudioIntervalResult::const_iterator cur;
- bool saw_silence = false;
- bool saw_audible = false;
-
- cur = res.begin();
-
- framepos_t start = 0;
- framepos_t end;
- bool in_silence;
-
- if (cur->first == 0) {
- /* initial segment, starting at zero, is silent */
- end = cur->second;
- in_silence = true;
- } else {
- /* initial segment, starting at zero, is audible */
- end = cur->first;
- in_silence = false;
- }
-
- while (cur != res.end()) {
-
- framecnt_t interval_duration;
-
- interval_duration = end - start;
-
- if (in_silence) {
- saw_silence = true;
- cerr << "Silent duration: " << interval_duration << endl;
-
- max_silence = max (max_silence, interval_duration);
- min_silence = min (min_silence, interval_duration);
- } else {
- saw_audible = true;
- cerr << "Audible duration: " << interval_duration << endl;
-
- max_audible = max (max_audible, interval_duration);
- min_audible = min (min_audible, interval_duration);
- }
-
- start = end;
- ++cur;
- end = cur->first;
- in_silence = !in_silence;
- }
-
- if (!saw_silence) {
- min_silence = 0;
- max_silence = 0;
- }
-
- if (!saw_audible) {
- min_audible = 0;
- max_audible = 0;
- }
-
- cerr << "max aud: " << max_audible << " min aud: " << min_audible << " max sil: " << max_silence << " min sil: " << min_silence << endl;
-}
-
framecnt_t
StripSilenceDialog::minimum_length () const
{
diff --git a/gtk2_ardour/strip_silence_dialog.h b/gtk2_ardour/strip_silence_dialog.h
index 62e58e7db5..9ac32b25f6 100644
--- a/gtk2_ardour/strip_silence_dialog.h
+++ b/gtk2_ardour/strip_silence_dialog.h
@@ -42,6 +42,10 @@ public:
return _threshold.get_value ();
}
+ void drop_rects ();
+
+ ARDOUR::AudioIntervalMap silences ();
+
ARDOUR::framecnt_t minimum_length () const;
ARDOUR::framecnt_t fade_length () const;
@@ -61,9 +65,6 @@ private:
Gtk::SpinButton _threshold;
AudioClock _minimum_length;
AudioClock _fade_length;
- Gtk::Label _segment_count_label;
- Gtk::Label _shortest_silence_label;
- Gtk::Label _shortest_audible_label;
Gtk::ProgressBar _progress_bar;
struct ViewInterval {
@@ -75,11 +76,6 @@ private:
std::list<ViewInterval> views;
- ARDOUR::framecnt_t max_audible;
- ARDOUR::framecnt_t min_audible;
- ARDOUR::framecnt_t max_silence;
- ARDOUR::framecnt_t min_silence;
-
PBD::ScopedConnection* _peaks_ready_connection;
bool _destroying;