From ebf3762fa91d911af411f1b5c68e3c67f2c47170 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 9 Dec 2010 18:17:36 +0000 Subject: fix computation of silence text, and its display. it is still not on top of the canvas, which is a small problem git-svn-id: svn://localhost/ardour2/branches/3.0@8227 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/ardour3_ui_dark.rc.in | 6 + gtk2_ardour/ardour3_ui_light.rc.in | 6 + gtk2_ardour/editor_ops.cc | 4 +- gtk2_ardour/region_view.cc | 219 +++++++++++++++++++----------------- gtk2_ardour/region_view.h | 10 +- gtk2_ardour/strip_silence_dialog.cc | 15 +-- gtk2_ardour/strip_silence_dialog.h | 2 +- 7 files changed, 144 insertions(+), 118 deletions(-) (limited to 'gtk2_ardour') diff --git a/gtk2_ardour/ardour3_ui_dark.rc.in b/gtk2_ardour/ardour3_ui_dark.rc.in index a31080d490..49e86e3d7b 100644 --- a/gtk2_ardour/ardour3_ui_dark.rc.in +++ b/gtk2_ardour/ardour3_ui_dark.rc.in @@ -81,6 +81,11 @@ style "verbose_canvas_cursor" font_name = "@FONT_BOLD_LARGER@" } +style "silence_text" +{ + font_name = "@FONT_BOLD_NORMAL@" +} + style "marker_text" { font_name = "@FONT_SMALL@" @@ -1463,6 +1468,7 @@ class "GtkProgressBar" style:highest "ardour_progressbars" widget "*PaddedButton" style:highest "padded_button" widget "*FirstActionMessage" style:highest "first_action_message" widget "*VerboseCanvasCursor" style:highest "verbose_canvas_cursor" +widget "*SilenceText" style:highest "silence_text" widget "*MarkerText" style:highest "marker_text" widget "*TimeAxisViewItemName*" style:highest "time_axis_view_item_name" widget "*EditModeSelector" style:highest "medium_bold_entry" diff --git a/gtk2_ardour/ardour3_ui_light.rc.in b/gtk2_ardour/ardour3_ui_light.rc.in index 8d6ca1656d..65f3f74fda 100644 --- a/gtk2_ardour/ardour3_ui_light.rc.in +++ b/gtk2_ardour/ardour3_ui_light.rc.in @@ -72,6 +72,11 @@ style "verbose_canvas_cursor" font_name = "@FONT_BOLD_LARGER@" } +style "silence_text" +{ + font_name = "@FONT_BOLD_NORMAL@" +} + style "marker_text" { font_name = "@FONT_NORMAL@" @@ -1264,6 +1269,7 @@ class "GtkProgressBar" style:highest "ardour_progressbars" widget "*PaddedButton" style:highest "padded_button" widget "*FirstActionMessage" style:highest "first_action_message" widget "*VerboseCanvasCursor" style:highest "verbose_canvas_cursor" +widget "*SilenceText" style:highest "silence_text" widget "*MarkerText" style:highest "marker_text" widget "*TimeAxisViewItemName*" style:highest "time_axis_view_item_name" #widget "*ExportProgress" style:highest "default_generic" diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 798496af74..4bf5a70cd8 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -4559,7 +4559,9 @@ Editor::strip_region_silence () d.drop_rects (); if (r == Gtk::RESPONSE_OK) { - StripSilence s (*_session, d.silences(), d.fade_length()); + ARDOUR::AudioIntervalMap silences; + d.silences (silences); + StripSilence s (*_session, silences, d.fade_length()); apply_filter (s, _("strip silence"), &d); } } diff --git a/gtk2_ardour/region_view.cc b/gtk2_ardour/region_view.cc index 85770d731e..e84d25c9f3 100644 --- a/gtk2_ardour/region_view.cc +++ b/gtk2_ardour/region_view.cc @@ -220,118 +220,138 @@ RegionView::~RegionView () } void -RegionView::set_silent_frames (const AudioIntervalResult& silences) +RegionView::set_silent_frames (const AudioIntervalResult& silences, double threshold) { 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 (silences.empty()) { + return; + } - 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); + framepos_t start; + framepos_t end; + bool in_silence; + bool seen_audible = false; + AudioIntervalResult::const_iterator s; + uint32_t const color = ARDOUR_UI::config()->canvasvar_Silence.get(); + + start = _region->start(); + s = silences.begin(); + + if (s->first == start) { + /* segment starting at zero is silent */ + end = s->second; + in_silence = true; + } else { + /* segment starting at zero is audible, and begins at the start of the region in the source */ + end = s->first; + in_silence = false; + } + + while (start < _region->start() + _region->length()) { + + framecnt_t interval_duration = end - start; + + if (interval_duration > 0) { + if (in_silence) { + + ArdourCanvas::SimpleRect* cr = new ArdourCanvas::SimpleRect (*group); + _silent_frames.push_back (cr); + + /* coordinates for the rect are relative to the regionview origin */ + + cr->property_x1() = trackview.editor().frame_to_pixel (s->first - _region->start()); + cr->property_x2() = trackview.editor().frame_to_pixel (s->second - _region->start()); + cr->property_y1() = 1; + cr->property_y2() = _height - 2; + cr->property_outline_pixels() = 0; + cr->property_fill_color_rgba () = color; + + if (interval_duration < shortest) { + shortest = interval_duration; + } + + } else if (interval_duration > 0) { seen_audible = true; + if (interval_duration < shortest_audible) { + shortest_audible = interval_duration; + } } - - ArdourCanvas::SimpleRect* cr = new ArdourCanvas::SimpleRect (*group); - _silent_frames.push_back (cr); - - /* 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; - - 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; + start = end; + in_silence = !in_silence; + ++s; + + if (s == silences.end()) { + end = _region->start() + _region->length(); + } else { + end = s->first; } } + } + + + _silence_text = new ArdourCanvas::NoEventText (*group); + _silence_text->property_font_desc() = *(get_font_for_style (N_("SilenceText"))); + _silence_text->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_SilenceText.get(); + _silence_text->property_anchor() = ANCHOR_NW; + + /* both positions are relative to the region start offset in source */ + + _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 */ + + if (ms >= 60.0) { + sunits = _("minutes"); + ms /= 60.0; + } else if (ms < 1.0) { + sunits = _("msecs"); + ms *= 1000.0; + } else { + sunits = _("secs"); + } + + if (seen_audible) { + /* ms are now in seconds */ + double ma = shortest_audible / _region->session().frame_rate(); + char const * aunits; - 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 region start offset in source */ - - _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"); + if (ma >= 60.0) { + aunits = _("minutes"); + ma /= 60.0; + } else if (ma < 1.0) { + aunits = _("msecs"); + ma *= 1000.0; } else { - noun = _("silent segment"); + aunits = _("secs"); } - - ms = (float) shortest/_region->session().frame_rate(); - /* ms are now in seconds */ - - if (ms >= 60.0) { - sunits = _("minutes"); - ms /= 60.0; - } else if (ms < 1.0) { - sunits = _("msecs"); - ms *= 1000.0; - } else { - 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 %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(); - } - } -} + _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 RegionView::hide_silent_frames () @@ -354,15 +374,6 @@ RegionView::drop_silent_frames () _silence_text = 0; } -void -RegionView::show_silent_frames () -{ - for (list::iterator i = _silent_frames.begin (); i != _silent_frames.end (); ++i) { - (*i)->show (); - } - _silence_text->show (); -} - gint RegionView::_lock_toggle (ArdourCanvas::Item*, GdkEvent* ev, void* arg) { diff --git a/gtk2_ardour/region_view.h b/gtk2_ardour/region_view.h index c291d60cf6..a96862f08a 100644 --- a/gtk2_ardour/region_view.h +++ b/gtk2_ardour/region_view.h @@ -112,10 +112,9 @@ class RegionView : public TimeAxisViewItem void trim_contents (framepos_t, bool, bool); virtual void thaw_after_trim (); - void set_silent_frames (const ARDOUR::AudioIntervalResult&); + void set_silent_frames (const ARDOUR::AudioIntervalResult&, double threshold); void drop_silent_frames (); void hide_silent_frames (); - void show_silent_frames (); protected: @@ -173,11 +172,12 @@ class RegionView : public TimeAxisViewItem */ std::list _coverage_frames; - /** a list of rectangles which are used in stacked display mode to colour - different bits of regions according to whether or not they are the one - that will be played at any given time. + /** a list of rectangles used to show silent segments */ std::list _silent_frames; + /** a list of rectangles used to show the current silence threshold + */ + std::list _silent_threshold_frames; /** a text item to display strip silence statistics */ ArdourCanvas::NoEventText* _silence_text; diff --git a/gtk2_ardour/strip_silence_dialog.cc b/gtk2_ardour/strip_silence_dialog.cc index 3e62e4247a..daa540d039 100644 --- a/gtk2_ardour/strip_silence_dialog.cc +++ b/gtk2_ardour/strip_silence_dialog.cc @@ -84,9 +84,12 @@ StripSilenceDialog::StripSilenceDialog (Session* s, list const & v) _minimum_length.set_mode (AudioClock::Frames); _minimum_length.set (1000, true); + /* Add this back when we finally do something with it */ + /* table->attach (*Gtk::manage (new Gtk::Label (_("Fade length"), 1, 0.5)), 0, 1, n, n + 1, Gtk::FILL); table->attach (_fade_length, 1, 2, n, n + 1, Gtk::FILL); ++n; + */ _fade_length.set_session (s); _fade_length.set_mode (AudioClock::Frames); @@ -133,17 +136,13 @@ StripSilenceDialog::~StripSilenceDialog () delete _peaks_ready_connection; } -AudioIntervalMap -StripSilenceDialog::silences () +void +StripSilenceDialog::silences (AudioIntervalMap& m) { - AudioIntervalMap m; - for (list::iterator v = views.begin(); v != views.end(); ++v) { pair,AudioIntervalResult> newpair ((*v).view->region(), (*v).intervals); m.insert (newpair); } - - return m; } void @@ -188,8 +187,10 @@ StripSilenceDialog::update_silence_rects () { /* Lock so that we don't contend with the detection thread for access to the silence regions */ Glib::Mutex::Lock lm (_lock); + double const y = _threshold.get_value(); + for (list::iterator v = views.begin(); v != views.end(); ++v) { - (*v).view->set_silent_frames ((*v).intervals); + (*v).view->set_silent_frames ((*v).intervals, y); } } diff --git a/gtk2_ardour/strip_silence_dialog.h b/gtk2_ardour/strip_silence_dialog.h index 9ac32b25f6..886017ca8a 100644 --- a/gtk2_ardour/strip_silence_dialog.h +++ b/gtk2_ardour/strip_silence_dialog.h @@ -44,7 +44,7 @@ public: void drop_rects (); - ARDOUR::AudioIntervalMap silences (); + void silences (ARDOUR::AudioIntervalMap&); ARDOUR::framecnt_t minimum_length () const; ARDOUR::framecnt_t fade_length () const; -- cgit v1.2.3