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 &);
77 virtual Gtk::Widget& tip_widget() = 0;
80 void maybe_add_note (OptionEditorPage *, int);
85 /** A component which provides a subheading within the dialog */
86 class OptionEditorHeading : public OptionEditorComponent
89 OptionEditorHeading (std::string const &);
91 void parameter_changed (std::string const &) {}
92 void set_state_from_config () {}
93 void add_to_page (OptionEditorPage *);
95 Gtk::Widget& tip_widget() { return *_label; }
98 Gtk::Label* _label; ///< the label used for the heading
101 /** A component which provides a box into which a subclass can put arbitrary widgets */
102 class OptionEditorBox : public OptionEditorComponent
106 /** Construct an OpenEditorBox */
109 _box = Gtk::manage (new Gtk::VBox);
110 _box->set_spacing (4);
113 void parameter_changed (std::string const &) = 0;
114 void set_state_from_config () = 0;
115 void add_to_page (OptionEditorPage *);
117 Gtk::Widget& tip_widget() { return *_box->children().front().get_widget(); }
121 Gtk::VBox* _box; ///< constituent box for subclasses to add widgets to
124 class RcConfigDisplay : public OptionEditorComponent
127 RcConfigDisplay (std::string const &, std::string const &, sigc::slot<std::string>, char s = '\0');
128 void add_to_page (OptionEditorPage *);
129 void parameter_changed (std::string const & p);
130 void set_state_from_config ();
131 Gtk::Widget& tip_widget() { return *_info; }
133 sigc::slot<std::string> _get;
140 class RcActionButton : public OptionEditorComponent
143 RcActionButton (std::string const & t, const Glib::SignalProxy0< void >::SlotType & slot, std::string const & l = "");
144 void add_to_page (OptionEditorPage *);
146 void parameter_changed (std::string const & p) {}
147 void set_state_from_config () {}
148 Gtk::Widget& tip_widget() { return *_button; }
151 Gtk::Button* _button;
156 /** Base class for components which provide UI to change an option */
157 class Option : public OptionEditorComponent
160 /** Construct an Option.
161 * @param i Option id (e.g. "plugins-stop-with-transport")
162 * @param n User-visible name (e.g. "Stop plugins when the transport is stopped")
164 Option (std::string const & i,
165 std::string const & n
171 void parameter_changed (std::string const & p)
174 set_state_from_config ();
178 virtual void set_state_from_config () = 0;
179 virtual void add_to_page (OptionEditorPage*) = 0;
181 std::string id () const {
191 /** Component which provides the UI to handle a boolean option using a GTK CheckButton */
192 class BoolOption : public Option
196 BoolOption (std::string const &, std::string const &, sigc::slot<bool>, sigc::slot<bool, bool>);
197 void set_state_from_config ();
198 void add_to_page (OptionEditorPage*);
200 void set_sensitive (bool yn) {
201 _button->set_sensitive (yn);
204 Gtk::Widget& tip_widget() { return *_button; }
208 virtual void toggled ();
210 sigc::slot<bool> _get; ///< slot to get the configuration variable's value
211 sigc::slot<bool, bool> _set; ///< slot to set the configuration variable's value
212 Gtk::CheckButton* _button; ///< UI button
213 Gtk::Label* _label; ///< label for button, so we can use markup
216 class RouteDisplayBoolOption : public BoolOption
219 RouteDisplayBoolOption (std::string const &, std::string const &, sigc::slot<bool>, sigc::slot<bool, bool>);
221 virtual void toggled ();
224 /** Component which allows to add any GTK Widget - intended for single buttons and custom stateless objects */
225 class FooOption : public OptionEditorComponent
228 FooOption (Gtk::Widget *w) : _w (w) {}
230 void add_to_page (OptionEditorPage* p) {
231 add_widget_to_page (p, _w);
234 Gtk::Widget& tip_widget() { return *_w; }
235 void set_state_from_config () {}
236 void parameter_changed (std::string const &) {}
241 /** Component which provides the UI to handle a string option using a GTK Entry */
242 class EntryOption : public Option
246 EntryOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
247 void set_state_from_config ();
248 void add_to_page (OptionEditorPage*);
249 void set_sensitive (bool);
250 void set_invalid_chars (std::string i) { _invalid = i; }
252 Gtk::Widget& tip_widget() { return *_entry; }
257 bool focus_out (GdkEventFocus*);
258 void filter_text (const Glib::ustring&, int*);
260 sigc::slot<std::string> _get; ///< slot to get the configuration variable's value
261 sigc::slot<bool, std::string> _set; ///< slot to set the configuration variable's value
262 Gtk::Label* _label; ///< UI label
263 Gtk::Entry* _entry; ///< UI entry
264 std::string _invalid;
268 /** Component which provides the UI to handle an enumerated option using a GTK ComboBox.
269 * The template parameter is the enumeration.
272 class ComboOption : public Option
276 /** Construct an ComboOption.
278 * @param n User-visible name.
279 * @param g Slot to get the variable's value.
280 * @param s Slot to set the variable's value.
283 std::string const & i,
284 std::string const & n,
286 sigc::slot<bool, T> s
292 _label = Gtk::manage (new Gtk::Label (n + ":"));
293 _label->set_alignment (0, 0.5);
294 _combo = Gtk::manage (new Gtk::ComboBoxText);
295 _combo->signal_changed().connect (sigc::mem_fun (*this, &ComboOption::changed));
298 void set_state_from_config () {
300 while (r < _options.size() && _get () != _options[r]) {
304 if (r < _options.size()) {
305 _combo->set_active (r);
309 void add_to_page (OptionEditorPage* p)
311 add_widgets_to_page (p, _label, _combo);
314 /** Add an allowed value for this option.
315 * @param e Enumeration.
316 * @param o User-visible name for this value.
318 void add (T e, std::string const & o) {
319 _options.push_back (e);
320 _combo->append_text (o);
324 _combo->clear_items();
329 uint32_t const r = _combo->get_active_row_number ();
330 if (r < _options.size()) {
335 void set_sensitive (bool yn) {
336 _combo->set_sensitive (yn);
339 Gtk::Widget& tip_widget() { return *_combo; }
344 sigc::slot<bool, T> _set;
346 Gtk::ComboBoxText* _combo;
347 std::vector<T> _options;
351 /** Component which provides the UI for a GTK HScale.
353 class HSliderOption : public Option
357 /** Construct an ComboOption.
359 * @param n User-visible name.
360 * @param g Slot to get the variable's value.
361 * @param s Slot to set the variable's value.
364 std::string const & i,
365 std::string const & n,
370 _label = Gtk::manage (new Gtk::Label (n + ":"));
371 _label->set_alignment (0, 0.5);
372 _hscale = Gtk::manage (new Gtk::HScale(adj));
377 std::string const & i,
378 std::string const & n,
379 Gtk::Adjustment *adj,
381 sigc::slot<bool, float> s
388 _label = Gtk::manage (new Gtk::Label (n + ":"));
389 _label->set_alignment (0, 0.5);
390 _hscale = Gtk::manage (new Gtk::HScale(*_adj));
391 _adj->signal_value_changed().connect (sigc::mem_fun (*this, &HSliderOption::changed));
394 void set_state_from_config () {
395 if (_adj) _adj->set_value (_get());
399 if (_adj) _set (_adj->get_value ());
402 void add_to_page (OptionEditorPage* p)
404 add_widgets_to_page (p, _label, _hscale);
407 void set_sensitive (bool yn) {
408 _hscale->set_sensitive (yn);
411 Gtk::Widget& tip_widget() { return *_hscale; }
412 Gtk::HScale& scale() { return *_hscale; }
415 sigc::slot<float> _get;
416 sigc::slot<bool, float> _set;
418 Gtk::HScale* _hscale;
419 Gtk::Adjustment* _adj;
422 /** Component which provides the UI to handle an enumerated option using a GTK ComboBox.
423 * The template parameter is the enumeration.
425 class ComboStringOption : public Option
429 /** Construct an ComboOption.
431 * @param n User-visible name.
432 * @param g Slot to get the variable's value.
433 * @param s Slot to set the variable's value.
436 std::string const & i,
437 std::string const & n,
438 sigc::slot<std::string> g,
439 sigc::slot<bool, std::string> s
445 _label = Gtk::manage (new Gtk::Label (n + ":"));
446 _label->set_alignment (0, 0.5);
447 _combo = Gtk::manage (new Gtk::ComboBoxText);
448 _combo->signal_changed().connect (sigc::mem_fun (*this, &ComboStringOption::changed));
451 void set_state_from_config () {
452 _combo->set_active_text (_get());
455 void add_to_page (OptionEditorPage* p)
457 add_widgets_to_page (p, _label, _combo);
460 /** Set the allowed strings for this option
461 * @param strings a vector of allowed strings
463 void set_popdown_strings (const std::vector<std::string>& strings) {
464 _combo->clear_items ();
465 for (std::vector<std::string>::const_iterator i = strings.begin(); i != strings.end(); ++i) {
466 _combo->append_text (*i);
471 _combo->clear_items();
475 _set (_combo->get_active_text ());
478 void set_sensitive (bool yn) {
479 _combo->set_sensitive (yn);
482 Gtk::Widget& tip_widget() { return *_combo; }
485 sigc::slot<std::string> _get;
486 sigc::slot<bool, std::string> _set;
488 Gtk::ComboBoxText* _combo;
492 /** Component which provides the UI to handle a boolean option which needs
493 * to be represented as a ComboBox to be clear to the user.
495 class BoolComboOption : public Option
505 sigc::slot<bool, bool>
508 void set_state_from_config ();
509 void add_to_page (OptionEditorPage *);
511 void set_sensitive (bool);
513 Gtk::Widget& tip_widget() { return *_combo; }
517 sigc::slot<bool> _get;
518 sigc::slot<bool, bool> _set;
520 Gtk::ComboBoxText* _combo;
525 /** Component which provides the UI to handle an numeric option using a GTK SpinButton */
527 class SpinOption : public Option
530 /** Construct an SpinOption.
532 * @param n User-visible name.
533 * @param g Slot to get the variable's value.
534 * @param s Slot to set the variable's value.
535 * @param min Variable minimum value.
536 * @param max Variable maximum value.
537 * @param step Step for the spin button.
538 * @param page Page step for the spin button.
539 * @param unit Unit name.
540 * @param scale Scaling factor (such that for a value x in the spinbutton, x * scale is written to the config)
541 * @param digits Number of decimal digits to show.
544 std::string const & i,
545 std::string const & n,
547 sigc::slot<bool, T> s,
552 std::string const & unit = "",
561 _label = Gtk::manage (new Gtk::Label (n + ":"));
562 _label->set_alignment (0, 0.5);
564 _spin = Gtk::manage (new Gtk::SpinButton);
565 _spin->set_range (min, max);
566 _spin->set_increments (step, page);
567 _spin->set_digits(digits);
569 _box = Gtk::manage (new Gtk::HBox);
570 _box->pack_start (*_spin, true, true);
571 _box->set_spacing (4);
573 _box->pack_start (*Gtk::manage (new Gtk::Label (unit)), false, false);
576 _spin->signal_value_changed().connect (sigc::mem_fun (*this, &SpinOption::changed));
579 void set_state_from_config ()
581 _spin->set_value (_get () / _scale);
584 void add_to_page (OptionEditorPage* p)
586 add_widgets_to_page (p, _label, _box);
591 _set (static_cast<T> (_spin->get_value ()) * _scale);
594 Gtk::Widget& tip_widget() { return *_spin; }
598 sigc::slot<bool, T> _set;
602 Gtk::SpinButton* _spin;
605 class FaderOption : public Option
609 FaderOption (std::string const &, std::string const &, sigc::slot<ARDOUR::gain_t> g, sigc::slot<bool, ARDOUR::gain_t> s);
610 void set_state_from_config ();
611 void add_to_page (OptionEditorPage *);
613 Gtk::Widget& tip_widget() { return *_db_slider; }
618 bool on_key_press (GdkEventKey* ev);
620 Gtk::Adjustment _db_adjustment;
621 Gtkmm2ext::HSliderController* _db_slider;
622 Gtk::Entry _db_display;
625 Gtk::VBox _fader_centering_box;
626 sigc::slot<ARDOUR::gain_t> _get;
627 sigc::slot<bool, ARDOUR::gain_t> _set;
630 class ClockOption : public Option
633 ClockOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
634 void set_state_from_config ();
635 void add_to_page (OptionEditorPage *);
636 void set_session (ARDOUR::Session *);
638 Gtk::Widget& tip_widget() { return _clock; }
639 AudioClock& clock() { return _clock; }
642 void save_clock_time ();
645 sigc::slot<std::string> _get;
646 sigc::slot<bool, std::string> _set;
647 ARDOUR::Session *_session;
650 class DirectoryOption : public Option
653 DirectoryOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
655 void set_state_from_config ();
656 void add_to_page (OptionEditorPage *);
658 Gtk::Widget& tip_widget() { return _file_chooser; }
661 void selection_changed ();
663 sigc::slot<std::string> _get; ///< slot to get the configuration variable's value
664 sigc::slot<bool, std::string> _set; ///< slot to set the configuration variable's value
665 Gtk::FileChooserButton _file_chooser;
668 /** Class to represent a single page in an OptionEditor's notebook.
669 * Pages are laid out using a 3-column table; the 1st column is used
670 * to indent non-headings, and the 2nd and 3rd for actual content.
672 class OptionEditorPage
675 OptionEditorPage (Gtk::Notebook&, std::string const &);
679 std::list<OptionEditorComponent*> components;
682 /** The OptionEditor dialog base class */
683 class OptionEditor : public ArdourWindow
686 OptionEditor (PBD::Configuration *, std::string const &);
689 void add_option (std::string const &, OptionEditorComponent *);
690 void add_page (std::string const &, Gtk::Widget& page_widget);
692 void set_current_page (std::string const &);
696 virtual void parameter_changed (std::string const &);
698 PBD::Configuration* _config;
702 PBD::ScopedConnection config_connection;
704 Gtk::Notebook _notebook;
705 std::map<std::string, OptionEditorPage*> _pages;
708 #endif /* __gtk_ardour_option_editor_h__ */