Add progress bar to strip silence dialogue. Fixes #3103.
[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 AudioRegion;
30         class Session;
31 }
32
33 /// Dialog box to set options for the `strip silence' filter
34 class StripSilenceDialog : public ArdourDialog, public ProgressReporter
35 {
36 public:
37         StripSilenceDialog (ARDOUR::Session*, std::list<boost::shared_ptr<ARDOUR::AudioRegion> > const &);
38         ~StripSilenceDialog ();
39
40         double threshold () const {
41                 return _threshold.get_value ();
42         }
43
44         nframes_t minimum_length () const;
45         nframes_t fade_length () const;
46         static void stop_thread ();
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_threshold_line ();
55         void threshold_changed ();
56         void update_progress_gui (float);
57
58         Gtk::SpinButton _threshold;
59         AudioClock      _minimum_length;
60         AudioClock      _fade_length;
61         Gtk::Label      _segment_count_label;
62         Gtk::Label      _shortest_silence_label;
63         Gtk::Label      _shortest_audible_label;
64         Gtk::ProgressBar _progress_bar;
65         typedef std::list<std::pair<ARDOUR::frameoffset_t,ARDOUR::framecnt_t> > SilenceResult;
66
67         struct Wave {
68             boost::shared_ptr<ARDOUR::AudioRegion> region;
69             ArdourCanvas::WaveView* view;
70             std::list<ArdourCanvas::SimpleRect*> silence_rects;
71             ArdourCanvas::SimpleLine* threshold_line;
72             double samples_per_unit;
73             SilenceResult silence;
74           
75             Wave (ArdourCanvas::Group *, boost::shared_ptr<ARDOUR::AudioRegion>);
76             ~Wave ();
77         };
78
79         ArdourCanvas::Canvas* _canvas;
80         std::list<Wave*> _waves;
81         int _wave_width;
82         int _wave_height;
83         bool restart_queued;
84
85         static ARDOUR::InterThreadInfo itt;
86         static bool thread_should_exit;
87         static Glib::Cond *thread_run;
88         static Glib::Cond *thread_waiting;
89         static Glib::StaticMutex run_lock;
90         static StripSilenceDialog* current;
91
92         ARDOUR::framecnt_t max_audible;
93         ARDOUR::framecnt_t min_audible;
94         ARDOUR::framecnt_t max_silence;
95         ARDOUR::framecnt_t min_silence;
96
97         PBD::ScopedConnection* _peaks_ready_connection;
98     
99         static bool  _detection_done (void*);
100         static void* _detection_thread_work (void*);
101
102         bool  detection_done ();
103         void* detection_thread_work ();
104         bool  start_silence_detection ();
105         void  maybe_start_silence_detection ();
106
107         void update_stats (const SilenceResult&);
108 };