move display of silence for strip-silence into regionviews, along with text to descri...
[ardour.git] / gtk2_ardour / strip_silence_dialog.h
1 /*
2     Copyright (C) 2009 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <gtkmm/spinbutton.h>
21 #include <glibmm/thread.h>
22
23 #include "ardour/types.h"
24 #include "ardour_dialog.h"
25 #include "canvas.h"
26 #include "progress_reporter.h"
27
28 namespace ARDOUR {
29         class Session;
30 }
31
32 class RegionView;
33
34 /// Dialog box to set options for the `strip silence' filter
35 class StripSilenceDialog : public ArdourDialog, public ProgressReporter
36 {
37 public:
38         StripSilenceDialog (ARDOUR::Session*, std::list<RegionView*> const &);
39         ~StripSilenceDialog ();
40
41         double threshold () const {
42                 return _threshold.get_value ();
43         }
44
45         ARDOUR::framecnt_t minimum_length () const;
46         ARDOUR::framecnt_t fade_length () const;
47
48 private:
49         void create_waves ();
50         void peaks_ready ();
51         void canvas_allocation (Gtk::Allocation &);
52         void update_silence_rects ();
53         void resize_silence_rects ();
54         void update ();
55         void update_threshold_line ();
56         void update_stats (ARDOUR::AudioIntervalResult const &);
57         void threshold_changed ();
58         void update_progress_gui (float);
59         void restart_thread ();
60
61         Gtk::SpinButton _threshold;
62         AudioClock      _minimum_length;
63         AudioClock      _fade_length;
64         Gtk::Label      _segment_count_label;
65         Gtk::Label      _shortest_silence_label;
66         Gtk::Label      _shortest_audible_label;
67         Gtk::ProgressBar _progress_bar;
68
69         struct ViewInterval {
70             RegionView* view;
71             ARDOUR::AudioIntervalResult intervals;
72
73             ViewInterval (RegionView* rv) : view (rv) {}
74         };
75
76         std::list<ViewInterval> views;
77
78         ARDOUR::framecnt_t max_audible;
79         ARDOUR::framecnt_t min_audible;
80         ARDOUR::framecnt_t max_silence;
81         ARDOUR::framecnt_t min_silence;
82
83         PBD::ScopedConnection* _peaks_ready_connection;
84
85         bool _destroying;
86
87         pthread_t _thread; ///< thread to compute silence in the background
88         static void * _detection_thread_work (void *);
89         void * detection_thread_work ();
90         Glib::Mutex _lock; ///< lock held while the thread is doing work
91         Glib::Cond _run_cond; ///< condition to wake the thread
92         bool _thread_should_finish; ///< true if the thread should terminate
93         PBD::Signal0<void> Completed; ///< emitted when a silence detection has completed
94         PBD::ScopedConnection _completed_connection;
95         ARDOUR::InterThreadInfo _interthread_info;
96 };