Fix processor box for no crash on click
[ardour.git] / gtk2_ardour / strip_silence_dialog.h
1 /*
2  * Copyright (C) 2009-2010 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2009-2011 David Robillard <d@drobilla.net>
4  * Copyright (C) 2009-2017 Paul Davis <paul@linuxaudiosystems.com>
5  * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include <gtkmm/spinbutton.h>
23 #include <glibmm/threads.h>
24
25 #include "ardour/types.h"
26 #include "ardour_dialog.h"
27 #include "progress_reporter.h"
28
29 namespace ARDOUR {
30         class Session;
31 }
32
33 class AudioClock;
34 class RegionView;
35
36 /// Dialog box to set options for the `strip silence' filter
37 class StripSilenceDialog : public ArdourDialog, public ProgressReporter
38 {
39 public:
40         StripSilenceDialog (ARDOUR::Session*, std::list<RegionView*> const &);
41         ~StripSilenceDialog ();
42
43         double threshold () const {
44                 return _threshold.get_value ();
45         }
46
47         void drop_rects ();
48
49         void silences (ARDOUR::AudioIntervalMap&);
50
51         ARDOUR::samplecnt_t minimum_length () const;
52         ARDOUR::samplecnt_t fade_length () const;
53
54         void on_response (int response_id) {
55                 Gtk::Dialog::on_response (response_id);
56         }
57
58 private:
59         void create_waves ();
60         void canvas_allocation (Gtk::Allocation &);
61         void update_silence_rects ();
62         void resize_silence_rects ();
63         void update ();
64         void update_threshold_line ();
65         void update_stats (ARDOUR::AudioIntervalResult const &);
66         void threshold_changed ();
67         void update_progress_gui (float);
68         void restart_thread ();
69
70         Gtk::SpinButton _threshold;
71         AudioClock*      _minimum_length;
72         AudioClock*      _fade_length;
73         Gtk::ProgressBar _progress_bar;
74
75         Gtk::Button* cancel_button;
76         Gtk::Button* apply_button;
77
78         struct ViewInterval {
79                 RegionView* view;
80                 ARDOUR::AudioIntervalResult intervals;
81
82                 ViewInterval (RegionView* rv) : view (rv) {}
83         };
84
85         std::list<ViewInterval> views;
86
87         bool _destroying;
88
89         pthread_t _thread; ///< thread to compute silence in the background
90         static void * _detection_thread_work (void *);
91         void * detection_thread_work ();
92         Glib::Threads::Mutex _lock; ///< lock held while the thread is doing work
93         Glib::Threads::Cond  _run_cond; ///< condition to wake the thread
94         bool _thread_should_finish; ///< true if the thread should terminate
95         PBD::Signal0<void> Completed; ///< emitted when a silence detection has completed
96         PBD::ScopedConnection _completed_connection;
97         ARDOUR::InterThreadInfo _interthread_info;
98
99         sigc::connection progress_idle_connection;
100         bool idle_update_progress(); ///< GUI-thread progress updates of background silence computation
101         int analysis_progress_cur;
102         int analysis_progress_max;
103 };