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
*);
155 void set_sensitive (bool yn
) {
156 _button
->set_sensitive (yn
);
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
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
*);
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.
192 class ComboOption
: public Option
196 /** Construct an ComboOption.
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.
203 std::string
const & i
,
204 std::string
const & n
,
206 sigc::slot
<bool, T
> 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 () {
220 while (r
< _options
.size() && _get () != _options
[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
);
244 _combo
->clear_items();
249 uint32_t const r
= _combo
->get_active_row_number ();
250 if (r
< _options
.size()) {
255 void set_sensitive (bool yn
) {
256 _combo
->set_sensitive (yn
);
262 sigc::slot
<bool, T
> _set
;
264 Gtk::ComboBoxText
* _combo
;
265 std::vector
<T
> _options
;
269 /** Component which provides the UI to handle an numeric option using a GTK SpinButton */
271 class SpinOption
: public Option
274 /** Construct an SpinOption.
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)
287 std::string
const & i
,
288 std::string
const & n
,
290 sigc::slot
<bool, T
> s
,
295 std::string
const & unit
= "",
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);
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
);
332 _set (static_cast<T
> (_spin
->get_value ()) * _scale
);
337 sigc::slot
<bool, T
> _set
;
341 Gtk::SpinButton
* _spin
;
344 class FaderOption
: public Option
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
*);
355 Gtk::Adjustment _db_adjustment
;
356 Gtkmm2ext::HSliderController
* _db_slider
;
357 Glib::RefPtr
<Gdk::Pixbuf
> _pix
;
358 Gtk::Entry _db_display
;
361 sigc::slot
<ARDOUR::gain_t
> _get
;
362 sigc::slot
<bool, ARDOUR::gain_t
> _set
;
365 class ClockOption
: public Option
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
*);
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
387 OptionEditorPage (Gtk::Notebook
&, std::string
const &);
391 std::list
<OptionEditorComponent
*> components
;
394 /** The OptionEditor dialog base class */
395 class OptionEditor
: public ArdourDialog
398 OptionEditor (ARDOUR::Configuration
*, std::string
const &);
401 void add_option (std::string
const &, OptionEditorComponent
*);
403 void set_current_page (std::string
const &);
407 virtual void parameter_changed (std::string
const &);
409 ARDOUR::Configuration
* _config
;
413 PBD::ScopedConnection config_connection
;
415 Gtk::Notebook _notebook
;
416 std::map
<std::string
, OptionEditorPage
*> _pages
;
419 #endif /* __gtk_ardour_option_editor_h__ */