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
This commit is contained in:
Paul Davis 2010-12-09 18:17:36 +00:00
parent 0a62044c2c
commit ebf3762fa9
8 changed files with 146 additions and 120 deletions

View file

@ -81,6 +81,11 @@ style "verbose_canvas_cursor"
font_name = "@FONT_BOLD_LARGER@" font_name = "@FONT_BOLD_LARGER@"
} }
style "silence_text"
{
font_name = "@FONT_BOLD_NORMAL@"
}
style "marker_text" style "marker_text"
{ {
font_name = "@FONT_SMALL@" font_name = "@FONT_SMALL@"
@ -1463,6 +1468,7 @@ class "GtkProgressBar" style:highest "ardour_progressbars"
widget "*PaddedButton" style:highest "padded_button" widget "*PaddedButton" style:highest "padded_button"
widget "*FirstActionMessage" style:highest "first_action_message" widget "*FirstActionMessage" style:highest "first_action_message"
widget "*VerboseCanvasCursor" style:highest "verbose_canvas_cursor" widget "*VerboseCanvasCursor" style:highest "verbose_canvas_cursor"
widget "*SilenceText" style:highest "silence_text"
widget "*MarkerText" style:highest "marker_text" widget "*MarkerText" style:highest "marker_text"
widget "*TimeAxisViewItemName*" style:highest "time_axis_view_item_name" widget "*TimeAxisViewItemName*" style:highest "time_axis_view_item_name"
widget "*EditModeSelector" style:highest "medium_bold_entry" widget "*EditModeSelector" style:highest "medium_bold_entry"

View file

@ -72,6 +72,11 @@ style "verbose_canvas_cursor"
font_name = "@FONT_BOLD_LARGER@" font_name = "@FONT_BOLD_LARGER@"
} }
style "silence_text"
{
font_name = "@FONT_BOLD_NORMAL@"
}
style "marker_text" style "marker_text"
{ {
font_name = "@FONT_NORMAL@" font_name = "@FONT_NORMAL@"
@ -1264,6 +1269,7 @@ class "GtkProgressBar" style:highest "ardour_progressbars"
widget "*PaddedButton" style:highest "padded_button" widget "*PaddedButton" style:highest "padded_button"
widget "*FirstActionMessage" style:highest "first_action_message" widget "*FirstActionMessage" style:highest "first_action_message"
widget "*VerboseCanvasCursor" style:highest "verbose_canvas_cursor" widget "*VerboseCanvasCursor" style:highest "verbose_canvas_cursor"
widget "*SilenceText" style:highest "silence_text"
widget "*MarkerText" style:highest "marker_text" widget "*MarkerText" style:highest "marker_text"
widget "*TimeAxisViewItemName*" style:highest "time_axis_view_item_name" widget "*TimeAxisViewItemName*" style:highest "time_axis_view_item_name"
#widget "*ExportProgress" style:highest "default_generic" #widget "*ExportProgress" style:highest "default_generic"

View file

@ -4559,7 +4559,9 @@ Editor::strip_region_silence ()
d.drop_rects (); d.drop_rects ();
if (r == Gtk::RESPONSE_OK) { 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); apply_filter (s, _("strip silence"), &d);
} }
} }

View file

@ -220,117 +220,137 @@ RegionView::~RegionView ()
} }
void 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 = max_framecnt;
framecnt_t shortest_audible = max_framecnt; framecnt_t shortest_audible = max_framecnt;
bool seen_audible = false;
/* remove old silent frames */ /* remove old silent frames */
drop_silent_frames (); drop_silent_frames ();
if (!silences.empty()) { if (silences.empty()) {
return;
}
uint32_t const color = ARDOUR_UI::config()->canvasvar_Silence.get(); framepos_t start;
framecnt_t last_end; framepos_t end;
bool in_silence;
bool seen_audible = false;
AudioIntervalResult::const_iterator s;
uint32_t const color = ARDOUR_UI::config()->canvasvar_Silence.get();
if (silences.front().first != 0) { start = _region->start();
/* use initial non-silent segment as shortest */ s = silences.begin();
shortest_audible = silences.front().first;
seen_audible = true;
}
for (AudioIntervalResult::const_iterator i = silences.begin(); i != silences.end(); ++i) { 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;
}
if ((*i).first > last_end) { while (start < _region->start() + _region->length()) {
/* (audible) gap between the end of the last interval and this one */
shortest_audible = min (shortest_audible, (*i).first - last_end); 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; seen_audible = true;
if (interval_duration < shortest_audible) {
shortest_audible = interval_duration;
}
} }
start = end;
in_silence = !in_silence;
++s;
ArdourCanvas::SimpleRect* cr = new ArdourCanvas::SimpleRect (*group); if (s == silences.end()) {
_silent_frames.push_back (cr); end = _region->start() + _region->length();
/* 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;
}
}
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");
} 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 (ma >= 60.0) {
aunits = _("minutes");
ma /= 60.0;
} else if (ma < 1.0) {
aunits = _("msecs");
ma *= 1000.0;
} else { } else {
aunits = _("secs"); end = s->first;
} }
_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 = 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 (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();
}
} }
void void
@ -354,15 +374,6 @@ RegionView::drop_silent_frames ()
_silence_text = 0; _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 gint
RegionView::_lock_toggle (ArdourCanvas::Item*, GdkEvent* ev, void* arg) RegionView::_lock_toggle (ArdourCanvas::Item*, GdkEvent* ev, void* arg)
{ {

View file

@ -112,10 +112,9 @@ class RegionView : public TimeAxisViewItem
void trim_contents (framepos_t, bool, bool); void trim_contents (framepos_t, bool, bool);
virtual void thaw_after_trim (); 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 drop_silent_frames ();
void hide_silent_frames (); void hide_silent_frames ();
void show_silent_frames ();
protected: protected:
@ -173,11 +172,12 @@ class RegionView : public TimeAxisViewItem
*/ */
std::list<ArdourCanvas::SimpleRect*> _coverage_frames; std::list<ArdourCanvas::SimpleRect*> _coverage_frames;
/** a list of rectangles which are used in stacked display mode to colour /** a list of rectangles used to show silent segments
different bits of regions according to whether or not they are the one
that will be played at any given time.
*/ */
std::list<ArdourCanvas::SimpleRect*> _silent_frames; 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 /** a text item to display strip silence statistics
*/ */
ArdourCanvas::NoEventText* _silence_text; ArdourCanvas::NoEventText* _silence_text;

View file

@ -84,9 +84,12 @@ StripSilenceDialog::StripSilenceDialog (Session* s, list<RegionView*> const & v)
_minimum_length.set_mode (AudioClock::Frames); _minimum_length.set_mode (AudioClock::Frames);
_minimum_length.set (1000, true); _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 (*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); table->attach (_fade_length, 1, 2, n, n + 1, Gtk::FILL);
++n; ++n;
*/
_fade_length.set_session (s); _fade_length.set_session (s);
_fade_length.set_mode (AudioClock::Frames); _fade_length.set_mode (AudioClock::Frames);
@ -133,17 +136,13 @@ StripSilenceDialog::~StripSilenceDialog ()
delete _peaks_ready_connection; delete _peaks_ready_connection;
} }
AudioIntervalMap void
StripSilenceDialog::silences () StripSilenceDialog::silences (AudioIntervalMap& m)
{ {
AudioIntervalMap m;
for (list<ViewInterval>::iterator v = views.begin(); v != views.end(); ++v) { for (list<ViewInterval>::iterator v = views.begin(); v != views.end(); ++v) {
pair<boost::shared_ptr<Region>,AudioIntervalResult> newpair ((*v).view->region(), (*v).intervals); pair<boost::shared_ptr<Region>,AudioIntervalResult> newpair ((*v).view->region(), (*v).intervals);
m.insert (newpair); m.insert (newpair);
} }
return m;
} }
void 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 */ /* Lock so that we don't contend with the detection thread for access to the silence regions */
Glib::Mutex::Lock lm (_lock); Glib::Mutex::Lock lm (_lock);
double const y = _threshold.get_value();
for (list<ViewInterval>::iterator v = views.begin(); v != views.end(); ++v) { 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);
} }
} }

View file

@ -44,7 +44,7 @@ public:
void drop_rects (); void drop_rects ();
ARDOUR::AudioIntervalMap silences (); void silences (ARDOUR::AudioIntervalMap&);
ARDOUR::framecnt_t minimum_length () const; ARDOUR::framecnt_t minimum_length () const;
ARDOUR::framecnt_t fade_length () const; ARDOUR::framecnt_t fade_length () const;

View file

@ -30,7 +30,7 @@ class StripSilence : public Filter
int run (boost::shared_ptr<ARDOUR::Region>, Progress* progress = 0); int run (boost::shared_ptr<ARDOUR::Region>, Progress* progress = 0);
private: private:
AudioIntervalMap _smap; const AudioIntervalMap& _smap;
framecnt_t _fade_length; ///< fade in/out to use on trimmed regions, in samples framecnt_t _fade_length; ///< fade in/out to use on trimmed regions, in samples
}; };