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_window.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*);
75 void set_note (std::string const &);
78 void maybe_add_note (OptionEditorPage *, int);
83 /** A component which provides a subheading within the dialog */
84 class OptionEditorHeading : public OptionEditorComponent
87 OptionEditorHeading (std::string const &);
89 void parameter_changed (std::string const &) {}
90 void set_state_from_config () {}
91 void add_to_page (OptionEditorPage *);
94 Gtk::Label* _label; ///< the label used for the heading
97 /** A component which provides a box into which a subclass can put arbitrary widgets */
98 class OptionEditorBox : public OptionEditorComponent
102 /** Construct an OpenEditorBox */
105 _box = Gtk::manage (new Gtk::VBox);
106 _box->set_spacing (4);
109 void parameter_changed (std::string const &) = 0;
110 void set_state_from_config () = 0;
111 void add_to_page (OptionEditorPage *);
115 Gtk::VBox* _box; ///< constituent box for subclasses to add widgets to
118 /** Base class for components which provide UI to change an option */
119 class Option : public OptionEditorComponent
122 /** Construct an Option.
123 * @param i Option id (e.g. "plugins-stop-with-transport")
124 * @param n User-visible name (e.g. "Stop plugins when the transport is stopped")
126 Option (std::string const & i,
127 std::string const & n
133 void parameter_changed (std::string const & p)
136 set_state_from_config ();
140 virtual void set_state_from_config () = 0;
141 virtual void add_to_page (OptionEditorPage*) = 0;
143 std::string id () const {
153 /** Component which provides the UI to handle a boolean option using a GTK CheckButton */
154 class BoolOption : public Option
158 BoolOption (std::string const &, std::string const &, sigc::slot<bool>, sigc::slot<bool, bool>);
159 void set_state_from_config ();
160 void add_to_page (OptionEditorPage*);
162 void set_sensitive (bool yn) {
163 _button->set_sensitive (yn);
170 sigc::slot<bool> _get; ///< slot to get the configuration variable's value
171 sigc::slot<bool, bool> _set; ///< slot to set the configuration variable's value
172 Gtk::CheckButton* _button; ///< UI button
175 /** Component which provides the UI to handle a string option using a GTK Entry */
176 class EntryOption : public Option
180 EntryOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
181 void set_state_from_config ();
182 void add_to_page (OptionEditorPage*);
188 sigc::slot<std::string> _get; ///< slot to get the configuration variable's value
189 sigc::slot<bool, std::string> _set; ///< slot to set the configuration variable's value
190 Gtk::Label* _label; ///< UI label
191 Gtk::Entry* _entry; ///< UI entry
195 /** Component which provides the UI to handle an enumerated option using a GTK CheckButton.
196 * The template parameter is the enumeration.
199 class ComboOption : public Option
203 /** Construct an ComboOption.
205 * @param n User-visible name.
206 * @param g Slot to get the variable's value.
207 * @param s Slot to set the variable's value.
210 std::string const & i,
211 std::string const & n,
213 sigc::slot<bool, T> s
219 _label = manage (new Gtk::Label (n + ":"));
220 _label->set_alignment (0, 0.5);
221 _combo = manage (new Gtk::ComboBoxText);
222 _combo->signal_changed().connect (sigc::mem_fun (*this, &ComboOption::changed));
225 void set_state_from_config () {
227 while (r < _options.size() && _get () != _options[r]) {
231 if (r < _options.size()) {
232 _combo->set_active (r);
236 void add_to_page (OptionEditorPage* p)
238 add_widgets_to_page (p, _label, _combo);
241 /** Add an allowed value for this option.
242 * @param e Enumeration.
243 * @param o User-visible name for this value.
245 void add (T e, std::string const & o) {
246 _options.push_back (e);
247 _combo->append_text (o);
251 _combo->clear_items();
256 uint32_t const r = _combo->get_active_row_number ();
257 if (r < _options.size()) {
262 void set_sensitive (bool yn) {
263 _combo->set_sensitive (yn);
269 sigc::slot<bool, T> _set;
271 Gtk::ComboBoxText* _combo;
272 std::vector<T> _options;
276 /** Component which provides the UI to handle an numeric option using a GTK SpinButton */
278 class SpinOption : public Option
281 /** Construct an SpinOption.
283 * @param n User-visible name.
284 * @param g Slot to get the variable's value.
285 * @param s Slot to set the variable's value.
286 * @param min Variable minimum value.
287 * @param max Variable maximum value.
288 * @param step Step for the spin button.
289 * @param page Page step for the spin button.
290 * @param unit Unit name.
291 * @param scale Scaling factor (such that for a value x in the spinbutton, x * scale is written to the config)
294 std::string const & i,
295 std::string const & n,
297 sigc::slot<bool, T> s,
302 std::string const & unit = "",
310 _label = manage (new Gtk::Label (n + ":"));
311 _label->set_alignment (0, 0.5);
313 _spin = manage (new Gtk::SpinButton);
314 _spin->set_range (min, max);
315 _spin->set_increments (step, page);
317 _box = manage (new Gtk::HBox);
318 _box->pack_start (*_spin, true, true);
319 _box->set_spacing (4);
321 _box->pack_start (*manage (new Gtk::Label (unit)), false, false);
324 _spin->signal_value_changed().connect (sigc::mem_fun (*this, &SpinOption::changed));
327 void set_state_from_config ()
329 _spin->set_value (_get () / _scale);
332 void add_to_page (OptionEditorPage* p)
334 add_widgets_to_page (p, _label, _box);
339 _set (static_cast<T> (_spin->get_value ()) * _scale);
344 sigc::slot<bool, T> _set;
348 Gtk::SpinButton* _spin;
351 class FaderOption : public Option
355 FaderOption (std::string const &, std::string const &, sigc::slot<ARDOUR::gain_t> g, sigc::slot<bool, ARDOUR::gain_t> s);
356 void set_state_from_config ();
357 void add_to_page (OptionEditorPage *);
362 Gtk::Adjustment _db_adjustment;
363 Gtkmm2ext::HSliderController* _db_slider;
364 Glib::RefPtr<Gdk::Pixbuf> _pix;
365 Gtk::Entry _db_display;
368 Gtk::VBox _fader_centering_box;
369 sigc::slot<ARDOUR::gain_t> _get;
370 sigc::slot<bool, ARDOUR::gain_t> _set;
373 class ClockOption : public Option
376 ClockOption (std::string const &, std::string const &, sigc::slot<ARDOUR::framecnt_t>, sigc::slot<bool, ARDOUR::framecnt_t>);
377 void set_state_from_config ();
378 void add_to_page (OptionEditorPage *);
379 void set_session (ARDOUR::Session *);
384 sigc::slot<ARDOUR::framecnt_t> _get;
385 sigc::slot<bool, ARDOUR::framecnt_t> _set;
388 class DirectoryOption : public Option
391 DirectoryOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
393 void set_state_from_config ();
394 void add_to_page (OptionEditorPage *);
398 void current_folder_set ();
400 sigc::slot<std::string> _get; ///< slot to get the configuration variable's value
401 sigc::slot<bool, std::string> _set; ///< slot to set the configuration variable's value
402 Gtk::FileChooserButton _file_chooser;
405 /** Class to represent a single page in an OptionEditor's notebook.
406 * Pages are laid out using a 3-column table; the 1st column is used
407 * to indent non-headings, and the 2nd and 3rd for actual content.
409 class OptionEditorPage
412 OptionEditorPage (Gtk::Notebook&, std::string const &);
416 std::list<OptionEditorComponent*> components;
419 /** The OptionEditor dialog base class */
420 class OptionEditor : public ArdourWindow
423 OptionEditor (ARDOUR::Configuration *, std::string const &);
426 void add_option (std::string const &, OptionEditorComponent *);
428 void set_current_page (std::string const &);
432 virtual void parameter_changed (std::string const &);
434 ARDOUR::Configuration* _config;
438 PBD::ScopedConnection config_connection;
440 Gtk::Notebook _notebook;
441 std::map<std::string, OptionEditorPage*> _pages;
444 #endif /* __gtk_ardour_option_editor_h__ */