basic functionality for hardware latency measurement
[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 input_device_combo;
59     Gtk::ComboBoxText output_device_combo;
60     Gtk::ComboBoxText sample_rate_combo;
61     Gtk::ComboBoxText buffer_size_combo;
62     Gtk::Label        buffer_size_duration_label;
63     Gtk::Adjustment input_latency_adjustment;
64     Gtk::SpinButton input_latency;
65     Gtk::Adjustment output_latency_adjustment;
66     Gtk::SpinButton output_latency;
67     Gtk::Adjustment input_channels_adjustment;
68     Gtk::SpinButton input_channels;
69     Gtk::Adjustment output_channels_adjustment;
70     Gtk::SpinButton output_channels;
71     Gtk::Adjustment ports_adjustment;
72     Gtk::SpinButton ports_spinner;
73
74     Gtk::Button     control_app_button;
75
76     /* latency measurement */
77
78     Gtk::ComboBoxText lm_output_channel_combo;
79     Gtk::ComboBoxText lm_input_channel_combo;
80     Gtk::ToggleButton lm_measure_button;
81     Gtk::Button       lm_use_button;
82     Gtk::Label        lm_title;
83     Gtk::Label        lm_preamble;
84     Gtk::Label        lm_results;
85     Gtk::Table        lm_table;
86     Gtk::VBox         lm_vbox;
87
88     /* JACK specific */
89     
90     Gtk::CheckButton realtime_button;
91     Gtk::CheckButton no_memory_lock_button;
92     Gtk::CheckButton unlock_memory_button;
93     Gtk::CheckButton soft_mode_button;
94     Gtk::CheckButton monitor_button;
95     Gtk::CheckButton force16bit_button;
96     Gtk::CheckButton hw_monitor_button;
97     Gtk::CheckButton hw_meter_button;
98     Gtk::CheckButton verbose_output_button;
99     
100     Gtk::ComboBoxText preset_combo;
101     Gtk::ComboBoxText serverpath_combo;
102     Gtk::ComboBoxText driver_combo;
103     Gtk::ComboBoxText device_combo;
104     Gtk::ComboBoxText timeout_combo;
105     Gtk::ComboBoxText dither_mode_combo;
106     Gtk::ComboBoxText audio_mode_combo;
107     Gtk::ComboBoxText midi_driver_combo;
108     
109     Gtk::Table basic_packer;
110     Gtk::Table midi_packer;
111     Gtk::HBox basic_hbox;
112     Gtk::VBox basic_vbox;
113     Gtk::HBox midi_hbox;
114
115     uint32_t ignore_changes;
116     
117     static bool engine_running ();
118     
119     void driver_changed ();
120     void backend_changed ();
121     void sample_rate_changed ();
122     void buffer_size_changed ();
123
124     uint32_t get_rate() const;
125     uint32_t get_buffer_size() const;
126     uint32_t get_input_channels() const;
127     uint32_t get_output_channels() const;
128     uint32_t get_input_latency() const;
129     uint32_t get_output_latency() const;
130     std::string get_device_name() const;
131     std::string get_driver() const;
132
133     void audio_mode_changed ();
134     void device_changed ();
135     void list_devices ();
136     void show_buffer_duration ();
137
138     struct State {
139         std::string backend;
140         std::string driver;
141         std::string device;
142         std::string sample_rate;
143         std::string buffer_size;
144         uint32_t input_latency;
145         uint32_t output_latency;
146         uint32_t input_channels;
147         uint32_t output_channels;
148         bool active;
149
150         State() : active (false) {};
151     };
152     
153     typedef std::list<State> StateList;
154
155     StateList states;
156
157     State* get_matching_state (const std::string& backend,
158                                const std::string& driver,
159                                const std::string& device);
160     State* get_current_state ();
161     void maybe_display_saved_state ();
162     void save_state ();
163
164     static bool print_channel_count (Gtk::SpinButton*);
165
166     void build_notebook ();
167
168     void on_response (int);
169     void control_app_button_clicked ();
170     void manage_control_app_sensitivity ();
171     int push_state_to_backend (bool start);
172     uint32_t _desired_sample_rate;
173
174     /* latency measurement */
175     void latency_button_toggled ();
176     bool check_latency_measurement ();
177     void update_latency_display ();
178     sigc::connection latency_timeout;
179     void enable_latency_tab ();
180     void disable_latency_tab ();
181 };
182
183 #endif /* __gtk2_ardour_engine_dialog_h__ */