Use rectified log waveform in strip silence dialogue. Add threshold graphical indica...
[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 resize_silence_rects ();
53         void update_threshold_line ();
54         void threshold_changed ();
55
56         Gtk::SpinButton _threshold;
57         AudioClock      _minimum_length;
58         AudioClock      _fade_length;
59         Gtk::Label      _segment_count_label;
60         Gtk::Label      _shortest_silence_label;
61         Gtk::Label      _shortest_audible_label;
62         typedef std::list<std::pair<ARDOUR::frameoffset_t,ARDOUR::framecnt_t> > SilenceResult;
63
64         struct Wave {
65             boost::shared_ptr<ARDOUR::AudioRegion> region;
66             ArdourCanvas::WaveView* view;
67             std::list<ArdourCanvas::SimpleRect*> silence_rects;
68             ArdourCanvas::SimpleLine* threshold_line;
69             double samples_per_unit;
70             SilenceResult silence;
71           
72             Wave (ArdourCanvas::Group *, boost::shared_ptr<ARDOUR::AudioRegion>);
73             ~Wave ();
74         };
75
76         ArdourCanvas::Canvas* _canvas;
77         std::list<Wave*> _waves;
78         int _wave_width;
79         int _wave_height;
80         bool restart_queued;
81
82         static ARDOUR::InterThreadInfo itt;
83         static bool thread_should_exit;
84         static Glib::Cond *thread_run;
85         static Glib::Cond *thread_waiting;
86         static Glib::StaticMutex run_lock;
87         static StripSilenceDialog* current;
88
89         ARDOUR::framecnt_t max_audible;
90         ARDOUR::framecnt_t min_audible;
91         ARDOUR::framecnt_t max_silence;
92         ARDOUR::framecnt_t min_silence;
93
94         PBD::ScopedConnection* _peaks_ready_connection;
95     
96         static bool  _detection_done (void*);
97         static void* _detection_thread_work (void*);
98
99         bool  detection_done ();
100         void* detection_thread_work ();
101         bool  start_silence_detection ();
102         void  maybe_start_silence_detection ();
103
104         void update_stats (const SilenceResult&);
105 };