more strip silence dialog changes, to use audio clocks, show smallest silence/audible...
[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
27 namespace ARDOUR {
28         class AudioRegion;
29         class Session;
30 }
31
32 /// Dialog box to set options for the `strip silence' filter
33 class StripSilenceDialog : public ArdourDialog
34 {
35 public:
36         StripSilenceDialog (ARDOUR::Session*, std::list<boost::shared_ptr<ARDOUR::AudioRegion> > const &);
37         ~StripSilenceDialog ();
38
39         double threshold () const {
40                 return _threshold.get_value ();
41         }
42
43         nframes_t minimum_length () const;
44         nframes_t fade_length () const;
45         static void stop_thread ();
46
47 private:
48         void create_waves ();
49         void peaks_ready ();
50         void canvas_allocation (Gtk::Allocation &);
51         void update_silence_rects ();
52         void redraw_silence_rects ();
53
54         Gtk::SpinButton _threshold;
55         AudioClock      _minimum_length;
56         AudioClock      _fade_length;
57         Gtk::Label      _segment_count_label;
58         typedef std::list<std::pair<ARDOUR::frameoffset_t,ARDOUR::framecnt_t> > SilenceResult;
59
60         struct Wave {
61             boost::shared_ptr<ARDOUR::AudioRegion> region;
62             ArdourCanvas::WaveView* view;
63             std::list<ArdourCanvas::SimpleRect*> silence_rects;
64             double samples_per_unit;
65             SilenceResult silence;
66           
67             Wave() : view (0), samples_per_unit (1) { }
68         };
69
70         ArdourCanvas::Canvas* _canvas;
71         std::list<Wave> _waves;
72         int _wave_width;
73         int _wave_height;
74         bool restart_queued;
75
76         static ARDOUR::InterThreadInfo itt;
77         static bool thread_should_exit;
78         static Glib::Cond *thread_run;
79         static Glib::Cond *thread_waiting;
80         static Glib::StaticMutex run_lock;
81         static StripSilenceDialog* current;
82
83         ARDOUR::framecnt_t max_audible;
84         ARDOUR::framecnt_t min_audible;
85         ARDOUR::framecnt_t max_silence;
86         ARDOUR::framecnt_t min_silence;
87
88         PBD::ScopedConnection _peaks_ready_connection;
89     
90         static bool  _detection_done (void*);
91         static void* _detection_thread_work (void*);
92
93         bool  detection_done ();
94         void* detection_thread_work ();
95         bool  start_silence_detection ();
96         void  maybe_start_silence_detection ();
97
98         void update_stats (const SilenceResult&);
99 };