Merge branch 'windows' of git.ardour.org:ardour/ardour into windows
[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::Table basic_packer;
58     Gtk::HBox basic_hbox;
59     Gtk::VBox basic_vbox;
60
61     Gtk::ComboBoxText backend_combo;
62     Gtk::ComboBoxText driver_combo;
63     Gtk::ComboBoxText device_combo;
64     Gtk::ComboBoxText sample_rate_combo;
65     Gtk::ComboBoxText buffer_size_combo;
66     Gtk::Label        buffer_size_duration_label;
67     Gtk::Adjustment input_latency_adjustment;
68     Gtk::SpinButton input_latency;
69     Gtk::Adjustment output_latency_adjustment;
70     Gtk::SpinButton output_latency;
71     Gtk::Adjustment input_channels_adjustment;
72     Gtk::SpinButton input_channels;
73     Gtk::Adjustment output_channels_adjustment;
74     Gtk::SpinButton output_channels;
75     Gtk::Adjustment ports_adjustment;
76     Gtk::SpinButton ports_spinner;
77
78     Gtk::Button     control_app_button;
79
80     /* latency measurement */
81
82     Gtk::ComboBoxText lm_output_channel_combo;
83     Gtk::ComboBoxText lm_input_channel_combo;
84     Gtk::Label        lm_start_stop_label;
85     Gtk::ToggleButton lm_measure_button;
86     Gtk::Button       lm_use_button;
87     Gtk::Label        lm_title;
88     Gtk::Label        lm_results;
89     Gtk::Table        lm_table;
90     Gtk::VBox         lm_vbox;
91     bool              have_lm_results;
92
93     Gtk::Button* cancel_button;
94     Gtk::Button* ok_button;
95     Gtk::Button* apply_button;
96
97     /* MIDI Tab */
98
99     Gtk::VBox midi_vbox;
100     Gtk::Button midi_refresh_button;
101     Gtk::Table midi_device_table;
102
103     /* MIDI ... JACK */
104     
105     Gtk::CheckButton aj_button;
106     
107     uint32_t ignore_changes;
108     uint32_t _desired_sample_rate;
109     
110     static bool engine_running ();
111     
112     void driver_changed ();
113     void backend_changed ();
114     void sample_rate_changed ();
115     void buffer_size_changed ();
116     void parameter_changed ();
117
118     void setup_midi_tab_for_backend ();
119     void setup_midi_tab_for_jack ();
120     void refresh_midi_display ();
121     
122     std::string rate_as_string (float);
123     std::string bufsize_as_string (uint32_t);
124
125     float get_rate() const;
126     uint32_t get_buffer_size() const;
127     uint32_t get_input_channels() const;
128     uint32_t get_output_channels() const;
129     uint32_t get_input_latency() const;
130     uint32_t get_output_latency() const;
131     std::string get_device_name() const;
132     std::string get_driver() const;
133     std::string get_backend() const;
134
135     void device_changed ();
136     void list_devices ();
137     void show_buffer_duration ();
138
139     struct State {
140         std::string backend;
141         std::string driver;
142         std::string device;
143         float sample_rate;
144         uint32_t buffer_size;
145         uint32_t input_latency;
146         uint32_t output_latency;
147         uint32_t input_channels;
148         uint32_t output_channels;
149         bool active;
150
151         State() 
152                 : input_latency (0)
153                 , output_latency (0)
154                 , input_channels (0)
155                 , output_channels (0)
156                 , active (false) {}
157
158     };
159     
160     typedef std::list<State> StateList;
161
162     StateList states;
163
164     State* get_matching_state (const std::string& backend,
165                                const std::string& driver,
166                                const std::string& device);
167     State* get_saved_state_for_currently_displayed_backend_and_device ();
168     void maybe_display_saved_state ();
169     State* save_state ();
170     void store_state (State&);
171
172     bool  _have_control;
173
174     static bool print_channel_count (Gtk::SpinButton*);
175
176     void build_notebook ();
177
178     void on_response (int);
179     void control_app_button_clicked ();
180     void use_latency_button_clicked ();
181     void manage_control_app_sensitivity ();
182     int push_state_to_backend (bool start);
183     void post_push ();
184
185     /* latency measurement */
186     void latency_button_toggled ();
187     bool check_latency_measurement ();
188     sigc::connection latency_timeout;
189     void enable_latency_tab ();
190     void disable_latency_tab ();
191     void start_latency_detection ();
192     void end_latency_detection ();
193
194     void on_switch_page (GtkNotebookPage*, guint page_num);
195     bool on_delete_event (GdkEventAny*);
196 };
197
198 #endif /* __gtk2_ardour_engine_dialog_h__ */