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
53 class OptionEditorPage;
55 /** Base class for components of an OptionEditor dialog */
56 class OptionEditorComponent
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
80 OptionEditorHeading (std::string const &);
82 void parameter_changed (std::string const &) {}
83 void set_state_from_config () {}
84 void add_to_page (OptionEditorPage *);
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
95 /** Construct an OpenEditorBox */
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 *);
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
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
126 void parameter_changed (std::string const & p)
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 {
146 /** Component which provides the UI to handle a boolean option using a GTK CheckButton */
147 class BoolOption : public Option
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*);
159 sigc::slot<bool> _get; ///< slot to get the configuration variable's value
160 sigc::slot<bool, bool> _set; ///< slot to set the configuration variable's value
161 Gtk::CheckButton* _button; ///< UI button
164 /** Component which provides the UI to handle a string option using a GTK Entry */
165 class EntryOption : public Option
169 EntryOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
170 void set_state_from_config ();
171 void add_to_page (OptionEditorPage*);
177 sigc::slot<std::string> _get; ///< slot to get the configuration variable's value
178 sigc::slot<bool, std::string> _set; ///< slot to set the configuration variable's value
179 Gtk::Label* _label; ///< UI label
180 Gtk::Entry* _entry; ///< UI entry
184 /** Component which provides the UI to handle an enumerated option using a GTK CheckButton.
185 * The template parameter is the enumeration.
188 class ComboOption : public Option
192 /** Construct an ComboOption.
194 * @param n User-visible name.
195 * @param g Slot to get the variable's value.
196 * @param s Slot to set the variable's value.
199 std::string const & i,
200 std::string const & n,
202 sigc::slot<bool, T> s
208 _label = manage (new Gtk::Label (n + ":"));
209 _label->set_alignment (0, 0.5);
210 _combo = manage (new Gtk::ComboBoxText);
211 _combo->signal_changed().connect (sigc::mem_fun (*this, &ComboOption::changed));
214 void set_state_from_config () {
216 while (r < _options.size() && _get () != _options[r]) {
220 if (r < _options.size()) {
221 _combo->set_active (r);
225 void add_to_page (OptionEditorPage* p)
227 add_widgets_to_page (p, _label, _combo);
230 /** Add an allowed value for this option.
231 * @param e Enumeration.
232 * @param o User-visible name for this value.
234 void add (T e, std::string const & o) {
235 _options.push_back (e);
236 _combo->append_text (o);
240 _combo->clear_items();
245 uint32_t const r = _combo->get_active_row_number ();
246 if (r < _options.size()) {
251 void set_sensitive (bool yn) {
252 _combo->set_sensitive (yn);
258 sigc::slot<bool, T> _set;
260 Gtk::ComboBoxText* _combo;
261 std::vector<T> _options;
265 /** Component which provides the UI to handle an numeric option using a GTK SpinButton */
267 class SpinOption : public Option
270 /** Construct an SpinOption.
272 * @param n User-visible name.
273 * @param g Slot to get the variable's value.
274 * @param s Slot to set the variable's value.
275 * @param min Variable minimum value.
276 * @param max Variable maximum value.
277 * @param step Step for the spin button.
278 * @param page Page step for the spin button.
279 * @param unit Unit name.
280 * @param scale Scaling factor (such that for a value x in the spinbutton, x * scale is written to the config)
283 std::string const & i,
284 std::string const & n,
286 sigc::slot<bool, T> s,
291 std::string const & unit = "",
299 _label = manage (new Gtk::Label (n + ":"));
300 _label->set_alignment (0, 0.5);
302 _spin = manage (new Gtk::SpinButton);
303 _spin->set_range (min, max);
304 _spin->set_increments (step, page);
306 _box = manage (new Gtk::HBox);
307 _box->pack_start (*_spin, true, true);
308 _box->set_spacing (4);
310 _box->pack_start (*manage (new Gtk::Label (unit)), false, false);
313 _spin->signal_value_changed().connect (sigc::mem_fun (*this, &SpinOption::changed));
316 void set_state_from_config ()
318 _spin->set_value (_get () / _scale);
321 void add_to_page (OptionEditorPage* p)
323 add_widgets_to_page (p, _label, _box);
328 _set (static_cast<T> (_spin->get_value ()) * _scale);
333 sigc::slot<bool, T> _set;
337 Gtk::SpinButton* _spin;
340 class FaderOption : public Option
344 FaderOption (std::string const &, std::string const &, sigc::slot<ARDOUR::gain_t> g, sigc::slot<bool, ARDOUR::gain_t> s);
345 void set_state_from_config ();
346 void add_to_page (OptionEditorPage *);
351 Gtk::Adjustment _db_adjustment;
352 Gtkmm2ext::HSliderController* _db_slider;
353 Glib::RefPtr<Gdk::Pixbuf> _pix;
354 Gtk::Entry _db_display;
357 sigc::slot<ARDOUR::gain_t> _get;
358 sigc::slot<bool, ARDOUR::gain_t> _set;
361 class ClockOption : public Option
364 ClockOption (std::string const &, std::string const &, sigc::slot<ARDOUR::framecnt_t>, sigc::slot<bool, ARDOUR::framecnt_t>);
365 void set_state_from_config ();
366 void add_to_page (OptionEditorPage *);
367 void set_session (ARDOUR::Session *);
372 sigc::slot<ARDOUR::framecnt_t> _get;
373 sigc::slot<bool, ARDOUR::framecnt_t> _set;
376 /** Class to represent a single page in an OptionEditor's notebook.
377 * Pages are laid out using a 3-column table; the 1st column is used
378 * to indent non-headings, and the 2nd and 3rd for actual content.
380 class OptionEditorPage
383 OptionEditorPage (Gtk::Notebook&, std::string const &);
387 std::list<OptionEditorComponent*> components;
390 /** The OptionEditor dialog base class */
391 class OptionEditor : public ArdourDialog
394 OptionEditor (ARDOUR::Configuration *, std::string const &);
397 void add_option (std::string const &, OptionEditorComponent *);
401 ARDOUR::Configuration* _config;
405 void parameter_changed (std::string const &);
406 PBD::ScopedConnection config_connection;
408 Gtk::Notebook _notebook;
409 std::map<std::string, OptionEditorPage*> _pages;
412 #endif /* __gtk_ardour_option_editor_h__ */