end latency detection if AMS window closed while running detection (plus some non...
[ardour.git] / gtk2_ardour / engine_dialog.h
1 /*
2     Copyright (C) 2010 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 #ifndef __gtk2_ardour_engine_dialog_h__
21 #define __gtk2_ardour_engine_dialog_h__
22
23 #include <map>
24 #include <vector>
25 #include <string>
26
27 #include <gtkmm/checkbutton.h>
28 #include <gtkmm/spinbutton.h>
29 #include <gtkmm/comboboxtext.h>
30 #include <gtkmm/table.h>
31 #include <gtkmm/expander.h>
32 #include <gtkmm/box.h>
33 #include <gtkmm/buttonbox.h>
34 #include <gtkmm/button.h>
35
36 #include "pbd/signals.h"
37
38 #include "ardour_dialog.h"
39
40 class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
41   public:
42     EngineControl ();
43     ~EngineControl ();
44     
45     static bool need_setup ();
46     
47     XMLNode& get_state ();
48     void set_state (const XMLNode&);
49     
50     void set_desired_sample_rate (uint32_t);
51     
52   private:
53     Gtk::Notebook notebook;
54
55     /* core fields used by all backends */
56
57     Gtk::ComboBoxText backend_combo;
58     Gtk::ComboBoxText sample_rate_combo;
59     Gtk::ComboBoxText buffer_size_combo;
60     Gtk::Label        buffer_size_duration_label;
61     Gtk::Adjustment input_latency_adjustment;
62     Gtk::SpinButton input_latency;
63     Gtk::Adjustment output_latency_adjustment;
64     Gtk::SpinButton output_latency;
65     Gtk::Adjustment input_channels_adjustment;
66     Gtk::SpinButton input_channels;
67     Gtk::Adjustment output_channels_adjustment;
68     Gtk::SpinButton output_channels;
69     Gtk::Adjustment ports_adjustment;
70     Gtk::SpinButton ports_spinner;
71
72     Gtk::Button     control_app_button;
73
74     /* latency measurement */
75
76     Gtk::ComboBoxText lm_output_channel_combo;
77     Gtk::ComboBoxText lm_input_channel_combo;
78     Gtk::Label        lm_start_stop_label;
79     Gtk::ToggleButton lm_measure_button;
80     Gtk::Button       lm_use_button;
81     Gtk::Label        lm_title;
82     Gtk::Label        lm_results;
83     Gtk::Table        lm_table;
84     Gtk::VBox         lm_vbox;
85     bool              have_lm_results;
86
87     Gtk::Button* cancel_button;
88     Gtk::Button* ok_button;
89     Gtk::Button* apply_button;
90
91     /* JACK specific */
92     
93     Gtk::CheckButton realtime_button;
94     Gtk::CheckButton no_memory_lock_button;
95     Gtk::CheckButton unlock_memory_button;
96     Gtk::CheckButton soft_mode_button;
97     Gtk::CheckButton monitor_button;
98     Gtk::CheckButton force16bit_button;
99     Gtk::CheckButton hw_monitor_button;
100     Gtk::CheckButton hw_meter_button;
101     Gtk::CheckButton verbose_output_button;
102     
103     Gtk::ComboBoxText preset_combo;
104     Gtk::ComboBoxText serverpath_combo;
105     Gtk::ComboBoxText driver_combo;
106     Gtk::ComboBoxText device_combo;
107     Gtk::ComboBoxText timeout_combo;
108     Gtk::ComboBoxText dither_mode_combo;
109     Gtk::ComboBoxText audio_mode_combo;
110     Gtk::ComboBoxText midi_driver_combo;
111     
112     Gtk::Table basic_packer;
113     Gtk::Table midi_packer;
114     Gtk::HBox basic_hbox;
115     Gtk::VBox basic_vbox;
116     Gtk::HBox midi_hbox;
117
118     uint32_t ignore_changes;
119     
120     static bool engine_running ();
121     
122     void driver_changed ();
123     void backend_changed ();
124     void sample_rate_changed ();
125     void buffer_size_changed ();
126     void parameter_changed ();
127
128     uint32_t get_rate() const;
129     uint32_t get_buffer_size() const;
130     uint32_t get_input_channels() const;
131     uint32_t get_output_channels() const;
132     uint32_t get_input_latency() const;
133     uint32_t get_output_latency() const;
134     std::string get_device_name() const;
135     std::string get_driver() const;
136
137     void device_changed ();
138     void list_devices ();
139     void show_buffer_duration ();
140
141     struct State {
142         std::string backend;
143         std::string driver;
144         std::string device;
145         std::string sample_rate;
146         std::string buffer_size;
147         uint32_t input_latency;
148         uint32_t output_latency;
149         uint32_t input_channels;
150         uint32_t output_channels;
151         bool active;
152
153         State() : active (false) {};
154     };
155     
156     typedef std::list<State> StateList;
157
158     StateList states;
159
160     State* get_matching_state (const std::string& backend,
161                                const std::string& driver,
162                                const std::string& device);
163     State* get_saved_state_for_currently_displayed_backend_and_device ();
164     void maybe_display_saved_state ();
165     State* save_state ();
166
167     static bool print_channel_count (Gtk::SpinButton*);
168
169     void build_notebook ();
170
171     void on_response (int);
172     void control_app_button_clicked ();
173     void use_latency_button_clicked ();
174     void manage_control_app_sensitivity ();
175     int push_state_to_backend (bool start);
176     uint32_t _desired_sample_rate;
177
178     /* latency measurement */
179     void latency_button_toggled ();
180     bool check_latency_measurement ();
181     sigc::connection latency_timeout;
182     void enable_latency_tab ();
183     void disable_latency_tab ();
184     void start_latency_detection ();
185     void end_latency_detection ();
186
187     void on_switch_page (GtkNotebookPage*, guint page_num);
188     bool on_delete_event (GdkEventAny*);
189 };
190
191 #endif /* __gtk2_ardour_engine_dialog_h__ */