add a simple status indicator to the Engine Dialog
[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 #include "ardour_button.h"
40
41 class EngineControl : public ArdourDialog, public PBD::ScopedConnectionList {
42   public:
43     EngineControl ();
44     ~EngineControl ();
45
46     static bool need_setup ();
47
48     XMLNode& get_state ();
49     void set_state (const XMLNode&);
50
51     void set_desired_sample_rate (uint32_t);
52
53   private:
54     Gtk::Notebook notebook;
55
56     Gtk::Label engine_status;
57
58     /* core fields used by all backends */
59
60     Gtk::Table basic_packer;
61     Gtk::HBox basic_hbox;
62     Gtk::VBox basic_vbox;
63
64     Gtk::ComboBoxText backend_combo;
65     Gtk::ComboBoxText driver_combo;
66     Gtk::ComboBoxText device_combo;
67     Gtk::ComboBoxText sample_rate_combo;
68     Gtk::ComboBoxText midi_option_combo;
69     Gtk::ComboBoxText buffer_size_combo;
70     Gtk::Label        buffer_size_duration_label;
71     Gtk::Adjustment input_latency_adjustment;
72     Gtk::SpinButton input_latency;
73     Gtk::Adjustment output_latency_adjustment;
74     Gtk::SpinButton output_latency;
75     Gtk::Adjustment input_channels_adjustment;
76     Gtk::SpinButton input_channels;
77     Gtk::Adjustment output_channels_adjustment;
78     Gtk::SpinButton output_channels;
79     Gtk::Adjustment ports_adjustment;
80     Gtk::SpinButton ports_spinner;
81
82     Gtk::Label      have_control_text;
83     Gtk::Button     control_app_button;
84     ArdourButton    midi_devices_button;
85
86     Gtk::Button     connect_disconnect_button;
87
88     /* latency measurement */
89
90     Gtk::ComboBoxText lm_output_channel_combo;
91     Gtk::ComboBoxText lm_input_channel_combo;
92     Gtk::Label        lm_measure_label;
93     Gtk::Button       lm_measure_button;
94     Gtk::Button       lm_use_button;
95     Gtk::Button       lm_back_button;
96     ArdourButton      lm_button_audio;
97     Gtk::Label        lm_title;
98     Gtk::Label        lm_preamble;
99     Gtk::Label        lm_results;
100     Gtk::Table        lm_table;
101     Gtk::VBox         lm_vbox;
102     bool              have_lm_results;
103     bool              lm_running;
104
105     Gtk::Button* cancel_button;
106     Gtk::Button* ok_button;
107     Gtk::Button* apply_button;
108
109     /* MIDI Tab */
110
111     Gtk::VBox midi_vbox;
112     Gtk::Button midi_back_button;
113     Gtk::Table midi_device_table;
114
115     /* MIDI ... JACK */
116
117     Gtk::CheckButton aj_button;
118
119     uint32_t ignore_changes;
120     uint32_t _desired_sample_rate;
121     bool     started_at_least_once;
122
123     void driver_changed ();
124     void backend_changed ();
125     void sample_rate_changed ();
126     void buffer_size_changed ();
127     void parameter_changed ();
128     void midi_option_changed ();
129
130     void setup_midi_tab_for_backend ();
131     void setup_midi_tab_for_jack ();
132     void refresh_midi_display (std::string focus = "");
133
134     std::string bufsize_as_string (uint32_t);
135
136     float get_rate() const;
137     uint32_t get_buffer_size() const;
138     uint32_t get_input_channels() const;
139     uint32_t get_output_channels() const;
140     uint32_t get_input_latency() const;
141     uint32_t get_output_latency() const;
142     std::string get_device_name() const;
143     std::string get_driver() const;
144     std::string get_backend() const;
145     std::string get_midi_option () const;
146
147     void device_changed ();
148     void list_devices ();
149     void show_buffer_duration ();
150
151     void configure_midi_devices ();
152
153     struct MidiDeviceSetting {
154         std::string name;
155         bool enabled;
156         uint32_t input_latency;
157         uint32_t output_latency;
158
159         MidiDeviceSetting (std::string n, bool en = true, uint32_t inl = 0, uint32_t oul = 0)
160             : name (n)
161             , enabled (en)
162             , input_latency (inl)
163             , output_latency (oul)
164         {}
165     };
166
167     typedef boost::shared_ptr<MidiDeviceSetting> MidiDeviceSettings;
168     bool _can_set_midi_latencies;
169     std::vector<MidiDeviceSettings> _midi_devices;
170
171     MidiDeviceSettings find_midi_device(std::string devicename) const {
172         for (std::vector<MidiDeviceSettings>::const_iterator p = _midi_devices.begin(); p != _midi_devices.end(); ++p) {
173             if ((*p)->name == devicename) {
174                 return *p;
175             }
176         }
177         return MidiDeviceSettings();
178     }
179
180     struct StateStruct {
181         std::string backend;
182         std::string driver;
183         std::string device;
184         float sample_rate;
185         uint32_t buffer_size;
186         uint32_t input_latency;
187         uint32_t output_latency;
188         uint32_t input_channels;
189         uint32_t output_channels;
190         bool active;
191         std::string midi_option;
192         std::vector<MidiDeviceSettings> midi_devices;
193
194         StateStruct()
195                 : sample_rate (48000)
196                 , buffer_size (1024)
197                 , input_latency (0)
198                 , output_latency (0)
199                 , input_channels (0)
200                 , output_channels (0)
201                 , active (false) {}
202
203     };
204
205     typedef boost::shared_ptr<StateStruct> State;
206     typedef std::list<State> StateList;
207
208     StateList states;
209
210     State get_matching_state (const std::string& backend,
211                                const std::string& driver,
212                                const std::string& device);
213     State get_saved_state_for_currently_displayed_backend_and_device ();
214     void maybe_display_saved_state ();
215     State save_state ();
216     void store_state (State);
217
218     bool  _have_control;
219
220     static bool print_channel_count (Gtk::SpinButton*);
221
222     void build_notebook ();
223     void build_full_control_notebook ();
224     void build_no_control_notebook ();
225
226     void on_show ();
227     void on_response (int);
228     void control_app_button_clicked ();
229     void use_latency_button_clicked ();
230     void manage_control_app_sensitivity ();
231     int push_state_to_backend (bool start);
232     void post_push ();
233     void update_sensitivity ();
234
235     /* latency measurement */
236     void latency_button_clicked ();
237     bool check_audio_latency_measurement ();
238     bool check_midi_latency_measurement ();
239     sigc::connection latency_timeout;
240     void enable_latency_tab ();
241     void disable_latency_tab ();
242     void start_latency_detection ();
243     void end_latency_detection ();
244
245     void on_switch_page (GtkNotebookPage*, guint page_num);
246     bool on_delete_event (GdkEventAny*);
247
248     void engine_running ();
249     void engine_stopped ();
250     PBD::ScopedConnection running_connection;
251     PBD::ScopedConnectionList stopped_connection;
252
253     void connect_disconnect_click ();
254     void calibrate_audio_latency ();
255     void calibrate_midi_latency (MidiDeviceSettings);
256
257     MidiDeviceSettings _measure_midi;
258     void midi_latency_adjustment_changed(Gtk::Adjustment *, MidiDeviceSettings, bool);
259     void midi_device_enabled_toggled(ArdourButton *, MidiDeviceSettings);
260     sigc::connection lm_back_button_signal;
261 };
262
263 #endif /* __gtk2_ardour_engine_dialog_h__ */