fix computation of silence text, and its display. it is still not on top of the canva...
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 9 Dec 2010 18:17:36 +0000 (18:17 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Thu, 9 Dec 2010 18:17:36 +0000 (18:17 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@8227 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/ardour3_ui_dark.rc.in
gtk2_ardour/ardour3_ui_light.rc.in
gtk2_ardour/editor_ops.cc
gtk2_ardour/region_view.cc
gtk2_ardour/region_view.h
gtk2_ardour/strip_silence_dialog.cc
gtk2_ardour/strip_silence_dialog.h
libs/ardour/ardour/strip_silence.h

index a31080d4900629f314c6c8586b08530e2b9736c0..49e86e3d7b06f340334ca14e8f724519f9da21f2 100644 (file)
@@ -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"
index 8d6ca1656d3760369b4aba980d11aabc6c4f77b1..65f3f74fdab58d9fe5f966df42052661e71ab311 100644 (file)
@@ -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"
index 798496af743789ff3e7436244e0979434964adda..4bf5a70cd8ba3a9bd9c5dd406b478d3c9a0ac308 100644 (file)
@@ -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);
        } 
 }
index 85770d731eac8a32ab8f17deaec2098a65498a9c..e84d25c9f3a9f2385cd53b748d5fe7891c4f7d3c 100644 (file)
@@ -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<ArdourCanvas::SimpleRect*>::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)
 {
index c291d60cf6602da54eef8066c8d42f0da85a714a..a96862f08a304ad543942b2933cdbf961b8f72a1 100644 (file)
@@ -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<ArdourCanvas::SimpleRect*> _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<ArdourCanvas::SimpleRect*> _silent_frames;
+       /** a list of rectangles used to show the current silence threshold
+       */
+       std::list<ArdourCanvas::SimpleRect*> _silent_threshold_frames;
         /** a text item to display strip silence statistics
          */
         ArdourCanvas::NoEventText* _silence_text;
index 3e62e4247a9ee17fd910597d332f29c2cae0803f..daa540d0393ac5cbf08ba0551cb926b5c0819bbc 100644 (file)
@@ -84,9 +84,12 @@ StripSilenceDialog::StripSilenceDialog (Session* s, list<RegionView*> 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<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
@@ -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<ViewInterval>::iterator v = views.begin(); v != views.end(); ++v) {
-                (*v).view->set_silent_frames ((*v).intervals);
+                (*v).view->set_silent_frames ((*v).intervals, y);
        }
 }
 
index 9ac32b25f6083efa8a9e209eea0811d59cd5f3eb..886017ca8a855071ed4d88cd222bf8de9c98b7bb 100644 (file)
@@ -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;
index ff1d1b7f17c4c652b289a149a429ac87d821a99c..0a3846b179c1d7c2e4a436341ac4cd59a87169bb 100644 (file)
@@ -30,7 +30,7 @@ class StripSilence : public Filter
        int run (boost::shared_ptr<ARDOUR::Region>, Progress* progress = 0);
 
 private:
-        AudioIntervalMap _smap;
+        const AudioIntervalMap& _smap;
        framecnt_t _fade_length; ///< fade in/out to use on trimmed regions, in samples
 };