Zoom session when the mouse pointer is moved up and down during a playhead drag.
[ardour2.git] / gtk2_ardour / option_editor.h
blobb81672e094035b6651062ca7a5b4dd7695c74c0c
1 /*
2 Copyright (C) 2009 Paul Davis
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.
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.
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.
20 #ifndef __gtk_ardour_option_editor_h__
21 #define __gtk_ardour_option_editor_h__
23 #include <gtkmm/notebook.h>
24 #include <gtkmm/checkbutton.h>
25 #include <gtkmm/comboboxtext.h>
26 #include <gtkmm/spinbutton.h>
27 #include <gtkmm/table.h>
28 #include "gtkmm2ext/slider_controller.h"
29 #include "ardour_dialog.h"
30 #include "audio_clock.h"
31 #include "ardour/types.h"
33 /** @file option_editor.h
34 * @brief Base class for option editing dialog boxes.
36 * Code to provided the basis for dialogs which allow the user to edit options
37 * from an ARDOUR::Configuration class.
39 * The idea is that we have an OptionEditor class which is the dialog box.
40 * This is essentially a GTK Notebook. OptionEditorComponent objects can
41 * then be added to the OptionEditor, and these components are arranged on
42 * the pages of the Notebook. There is also an OptionEditorComponent hierarchy
43 * here, providing things like boolean and combobox option components.
45 * It is intended that OptionEditor be subclassed to implement a particular
46 * options dialog.
49 namespace ARDOUR {
50 class Configuration;
53 class OptionEditorPage;
55 /** Base class for components of an OptionEditor dialog */
56 class OptionEditorComponent
58 public:
59 virtual ~OptionEditorComponent() {}
61 /** Called when a configuration parameter's value has changed.
62 * @param p parameter name
64 virtual void parameter_changed (std::string const & p) = 0;
66 /** Called to instruct the object to set its UI state from the configuration */
67 virtual void set_state_from_config () = 0;
69 /** Called to instruct the object to add itself to an OptionEditorPage */
70 virtual void add_to_page (OptionEditorPage *) = 0;
72 void add_widget_to_page (OptionEditorPage*, Gtk::Widget*);
73 void add_widgets_to_page (OptionEditorPage*, Gtk::Widget*, Gtk::Widget*);
76 /** A component which provides a subheading within the dialog */
77 class OptionEditorHeading : public OptionEditorComponent
79 public:
80 OptionEditorHeading (std::string const &);
82 void parameter_changed (std::string const &) {}
83 void set_state_from_config () {}
84 void add_to_page (OptionEditorPage *);
86 private:
87 Gtk::Label* _label; ///< the label used for the heading
90 /** A component which provides a box into which a subclass can put arbitrary widgets */
91 class OptionEditorBox : public OptionEditorComponent
93 public:
95 /** Construct an OpenEditorBox */
96 OptionEditorBox ()
98 _box = Gtk::manage (new Gtk::VBox);
99 _box->set_spacing (4);
102 void parameter_changed (std::string const &) = 0;
103 void set_state_from_config () = 0;
104 void add_to_page (OptionEditorPage *);
106 protected:
108 Gtk::VBox* _box; ///< constituent box for subclasses to add widgets to
111 /** Base class for components which provide UI to change an option */
112 class Option : public OptionEditorComponent
114 public:
115 /** Construct an Option.
116 * @param i Option id (e.g. "plugins-stop-with-transport")
117 * @param n User-visible name (e.g. "Stop plugins when the transport is stopped")
119 Option (std::string const & i,
120 std::string const & n
122 : _id (i),
123 _name (n)
126 void parameter_changed (std::string const & p)
128 if (p == _id) {
129 set_state_from_config ();
133 virtual void set_state_from_config () = 0;
134 virtual void add_to_page (OptionEditorPage*) = 0;
136 std::string id () const {
137 return _id;
140 protected:
142 std::string _id;
143 std::string _name;
146 /** Component which provides the UI to handle a boolean option using a GTK CheckButton */
147 class BoolOption : public Option
149 public:
151 BoolOption (std::string const &, std::string const &, sigc::slot<bool>, sigc::slot<bool, bool>);
152 void set_state_from_config ();
153 void add_to_page (OptionEditorPage*);
155 void set_sensitive (bool yn) {
156 _button->set_sensitive (yn);
159 private:
161 void toggled ();
163 sigc::slot<bool> _get; ///< slot to get the configuration variable's value
164 sigc::slot<bool, bool> _set; ///< slot to set the configuration variable's value
165 Gtk::CheckButton* _button; ///< UI button
168 /** Component which provides the UI to handle a string option using a GTK Entry */
169 class EntryOption : public Option
171 public:
173 EntryOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
174 void set_state_from_config ();
175 void add_to_page (OptionEditorPage*);
177 private:
179 void activated ();
181 sigc::slot<std::string> _get; ///< slot to get the configuration variable's value
182 sigc::slot<bool, std::string> _set; ///< slot to set the configuration variable's value
183 Gtk::Label* _label; ///< UI label
184 Gtk::Entry* _entry; ///< UI entry
188 /** Component which provides the UI to handle an enumerated option using a GTK CheckButton.
189 * The template parameter is the enumeration.
191 template <class T>
192 class ComboOption : public Option
194 public:
196 /** Construct an ComboOption.
197 * @param i id
198 * @param n User-visible name.
199 * @param g Slot to get the variable's value.
200 * @param s Slot to set the variable's value.
202 ComboOption (
203 std::string const & i,
204 std::string const & n,
205 sigc::slot<T> g,
206 sigc::slot<bool, T> s
208 : Option (i, n),
209 _get (g),
210 _set (s)
212 _label = manage (new Gtk::Label (n + ":"));
213 _label->set_alignment (0, 0.5);
214 _combo = manage (new Gtk::ComboBoxText);
215 _combo->signal_changed().connect (sigc::mem_fun (*this, &ComboOption::changed));
218 void set_state_from_config () {
219 uint32_t r = 0;
220 while (r < _options.size() && _get () != _options[r]) {
221 ++r;
224 if (r < _options.size()) {
225 _combo->set_active (r);
229 void add_to_page (OptionEditorPage* p)
231 add_widgets_to_page (p, _label, _combo);
234 /** Add an allowed value for this option.
235 * @param e Enumeration.
236 * @param o User-visible name for this value.
238 void add (T e, std::string const & o) {
239 _options.push_back (e);
240 _combo->append_text (o);
243 void clear () {
244 _combo->clear_items();
245 _options.clear ();
248 void changed () {
249 uint32_t const r = _combo->get_active_row_number ();
250 if (r < _options.size()) {
251 _set (_options[r]);
255 void set_sensitive (bool yn) {
256 _combo->set_sensitive (yn);
259 private:
261 sigc::slot<T> _get;
262 sigc::slot<bool, T> _set;
263 Gtk::Label* _label;
264 Gtk::ComboBoxText* _combo;
265 std::vector<T> _options;
269 /** Component which provides the UI to handle an numeric option using a GTK SpinButton */
270 template <class T>
271 class SpinOption : public Option
273 public:
274 /** Construct an SpinOption.
275 * @param i id
276 * @param n User-visible name.
277 * @param g Slot to get the variable's value.
278 * @param s Slot to set the variable's value.
279 * @param min Variable minimum value.
280 * @param max Variable maximum value.
281 * @param step Step for the spin button.
282 * @param page Page step for the spin button.
283 * @param unit Unit name.
284 * @param scale Scaling factor (such that for a value x in the spinbutton, x * scale is written to the config)
286 SpinOption (
287 std::string const & i,
288 std::string const & n,
289 sigc::slot<T> g,
290 sigc::slot<bool, T> s,
291 T min,
292 T max,
293 T step,
294 T page,
295 std::string const & unit = "",
296 float scale = 1
298 : Option (i, n),
299 _get (g),
300 _set (s),
301 _scale (scale)
303 _label = manage (new Gtk::Label (n + ":"));
304 _label->set_alignment (0, 0.5);
306 _spin = manage (new Gtk::SpinButton);
307 _spin->set_range (min, max);
308 _spin->set_increments (step, page);
310 _box = manage (new Gtk::HBox);
311 _box->pack_start (*_spin, true, true);
312 _box->set_spacing (4);
313 if (unit.length()) {
314 _box->pack_start (*manage (new Gtk::Label (unit)), false, false);
317 _spin->signal_value_changed().connect (sigc::mem_fun (*this, &SpinOption::changed));
320 void set_state_from_config ()
322 _spin->set_value (_get () / _scale);
325 void add_to_page (OptionEditorPage* p)
327 add_widgets_to_page (p, _label, _box);
330 void changed ()
332 _set (static_cast<T> (_spin->get_value ()) * _scale);
335 private:
336 sigc::slot<T> _get;
337 sigc::slot<bool, T> _set;
338 float _scale;
339 Gtk::Label* _label;
340 Gtk::HBox* _box;
341 Gtk::SpinButton* _spin;
344 class FaderOption : public Option
346 public:
348 FaderOption (std::string const &, std::string const &, sigc::slot<ARDOUR::gain_t> g, sigc::slot<bool, ARDOUR::gain_t> s);
349 void set_state_from_config ();
350 void add_to_page (OptionEditorPage *);
352 private:
353 void db_changed ();
355 Gtk::Adjustment _db_adjustment;
356 Gtkmm2ext::HSliderController* _db_slider;
357 Glib::RefPtr<Gdk::Pixbuf> _pix;
358 Gtk::Entry _db_display;
359 Gtk::Label _label;
360 Gtk::HBox _box;
361 sigc::slot<ARDOUR::gain_t> _get;
362 sigc::slot<bool, ARDOUR::gain_t> _set;
365 class ClockOption : public Option
367 public:
368 ClockOption (std::string const &, std::string const &, sigc::slot<ARDOUR::framecnt_t>, sigc::slot<bool, ARDOUR::framecnt_t>);
369 void set_state_from_config ();
370 void add_to_page (OptionEditorPage *);
371 void set_session (ARDOUR::Session *);
373 private:
374 Gtk::Label _label;
375 AudioClock _clock;
376 sigc::slot<ARDOUR::framecnt_t> _get;
377 sigc::slot<bool, ARDOUR::framecnt_t> _set;
380 /** Class to represent a single page in an OptionEditor's notebook.
381 * Pages are laid out using a 3-column table; the 1st column is used
382 * to indent non-headings, and the 2nd and 3rd for actual content.
384 class OptionEditorPage
386 public:
387 OptionEditorPage (Gtk::Notebook&, std::string const &);
389 Gtk::VBox box;
390 Gtk::Table table;
391 std::list<OptionEditorComponent*> components;
394 /** The OptionEditor dialog base class */
395 class OptionEditor : public ArdourDialog
397 public:
398 OptionEditor (ARDOUR::Configuration *, std::string const &);
399 ~OptionEditor ();
401 void add_option (std::string const &, OptionEditorComponent *);
403 void set_current_page (std::string const &);
405 protected:
407 virtual void parameter_changed (std::string const &);
409 ARDOUR::Configuration* _config;
411 private:
413 PBD::ScopedConnection config_connection;
415 Gtk::Notebook _notebook;
416 std::map<std::string, OptionEditorPage*> _pages;
419 #endif /* __gtk_ardour_option_editor_h__ */