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 <gtkmm/window.h>
30 #include "gtkmm2ext/slider_controller.h"
32 #include "ardour_window.h"
33 #include "audio_clock.h"
34 #include "ardour/types.h"
36 /** @file option_editor.h
37 * @brief Base class for option editing dialog boxes.
39 * Code to provided the basis for dialogs which allow the user to edit options
40 * from an ARDOUR::Configuration class.
42 * The idea is that we have an OptionEditor class which is the dialog box.
43 * This is essentially a GTK Notebook. OptionEditorComponent objects can
44 * then be added to the OptionEditor, and these components are arranged on
45 * the pages of the Notebook. There is also an OptionEditorComponent hierarchy
46 * here, providing things like boolean and combobox option components.
48 * It is intended that OptionEditor be subclassed to implement a particular
56 class OptionEditorPage;
58 /** Base class for components of an OptionEditor dialog */
59 class OptionEditorComponent
62 virtual ~OptionEditorComponent() {}
64 /** Called when a configuration parameter's value has changed.
65 * @param p parameter name
67 virtual void parameter_changed (std::string const & p) = 0;
69 /** Called to instruct the object to set its UI state from the configuration */
70 virtual void set_state_from_config () = 0;
72 /** Called to instruct the object to add itself to an OptionEditorPage */
73 virtual void add_to_page (OptionEditorPage *) = 0;
75 void add_widget_to_page (OptionEditorPage*, Gtk::Widget*);
76 void add_widgets_to_page (OptionEditorPage*, Gtk::Widget*, Gtk::Widget*);
78 void set_note (std::string const &);
80 virtual Gtk::Widget& tip_widget() = 0;
83 void maybe_add_note (OptionEditorPage *, int);
88 /** A component which provides a subheading within the dialog */
89 class OptionEditorHeading : public OptionEditorComponent
92 OptionEditorHeading (std::string const &);
94 void parameter_changed (std::string const &) {}
95 void set_state_from_config () {}
96 void add_to_page (OptionEditorPage *);
98 Gtk::Widget& tip_widget() { return *_label; }
101 Gtk::Label* _label; ///< the label used for the heading
104 /** A component which provides a box into which a subclass can put arbitrary widgets */
105 class OptionEditorBox : public OptionEditorComponent
109 /** Construct an OpenEditorBox */
112 _box = Gtk::manage (new Gtk::VBox);
113 _box->set_spacing (4);
116 void parameter_changed (std::string const &) = 0;
117 void set_state_from_config () = 0;
118 void add_to_page (OptionEditorPage *);
120 Gtk::Widget& tip_widget() { return *_box->children().front().get_widget(); }
124 Gtk::VBox* _box; ///< constituent box for subclasses to add widgets to
127 class RcConfigDisplay : public OptionEditorComponent
130 RcConfigDisplay (std::string const &, std::string const &, sigc::slot<std::string>, char s = '\0');
131 void add_to_page (OptionEditorPage *);
132 void parameter_changed (std::string const & p);
133 void set_state_from_config ();
134 Gtk::Widget& tip_widget() { return *_info; }
136 sigc::slot<std::string> _get;
143 class RcActionButton : public OptionEditorComponent
146 RcActionButton (std::string const & t, const Glib::SignalProxy0< void >::SlotType & slot, std::string const & l = "");
147 void add_to_page (OptionEditorPage *);
149 void parameter_changed (std::string const & p) {}
150 void set_state_from_config () {}
151 Gtk::Widget& tip_widget() { return *_button; }
154 Gtk::Button* _button;
159 /** Base class for components which provide UI to change an option */
160 class Option : public OptionEditorComponent
163 /** Construct an Option.
164 * @param i Option id (e.g. "plugins-stop-with-transport")
165 * @param n User-visible name (e.g. "Stop plugins when the transport is stopped")
167 Option (std::string const & i,
168 std::string const & n
174 void parameter_changed (std::string const & p)
177 set_state_from_config ();
181 virtual void set_state_from_config () = 0;
182 virtual void add_to_page (OptionEditorPage*) = 0;
184 std::string id () const {
194 /** Component which provides the UI to handle a boolean option using a GTK CheckButton */
195 class BoolOption : public Option
199 BoolOption (std::string const &, std::string const &, sigc::slot<bool>, sigc::slot<bool, bool>);
200 void set_state_from_config ();
201 void add_to_page (OptionEditorPage*);
203 void set_sensitive (bool yn) {
204 _button->set_sensitive (yn);
207 Gtk::Widget& tip_widget() { return *_button; }
211 virtual void toggled ();
213 sigc::slot<bool> _get; ///< slot to get the configuration variable's value
214 sigc::slot<bool, bool> _set; ///< slot to set the configuration variable's value
215 Gtk::CheckButton* _button; ///< UI button
216 Gtk::Label* _label; ///< label for button, so we can use markup
219 class RouteDisplayBoolOption : public BoolOption
222 RouteDisplayBoolOption (std::string const &, std::string const &, sigc::slot<bool>, sigc::slot<bool, bool>);
224 virtual void toggled ();
227 /** Component which allows to add any GTK Widget - intended for single buttons and custom stateless objects */
228 class FooOption : public OptionEditorComponent
231 FooOption (Gtk::Widget *w) : _w (w) {}
233 void add_to_page (OptionEditorPage* p) {
234 add_widget_to_page (p, _w);
237 Gtk::Widget& tip_widget() { return *_w; }
238 void set_state_from_config () {}
239 void parameter_changed (std::string const &) {}
244 /** Component which provides the UI to handle a string option using a GTK Entry */
245 class EntryOption : public Option
249 EntryOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
250 void set_state_from_config ();
251 void add_to_page (OptionEditorPage*);
252 void set_sensitive (bool);
253 void set_invalid_chars (std::string i) { _invalid = i; }
255 Gtk::Widget& tip_widget() { return *_entry; }
260 bool focus_out (GdkEventFocus*);
261 void filter_text (const Glib::ustring&, int*);
263 sigc::slot<std::string> _get; ///< slot to get the configuration variable's value
264 sigc::slot<bool, std::string> _set; ///< slot to set the configuration variable's value
265 Gtk::Label* _label; ///< UI label
266 Gtk::Entry* _entry; ///< UI entry
267 std::string _invalid;
271 /** Component which provides the UI to handle an enumerated option using a GTK ComboBox.
272 * The template parameter is the enumeration.
275 class ComboOption : public Option
279 /** Construct an ComboOption.
281 * @param n User-visible name.
282 * @param g Slot to get the variable's value.
283 * @param s Slot to set the variable's value.
286 std::string const & i,
287 std::string const & n,
289 sigc::slot<bool, T> s
295 _label = Gtk::manage (new Gtk::Label (n + ":"));
296 _label->set_alignment (0, 0.5);
297 _combo = Gtk::manage (new Gtk::ComboBoxText);
298 _combo->signal_changed().connect (sigc::mem_fun (*this, &ComboOption::changed));
301 void set_state_from_config () {
303 while (r < _options.size() && _get () != _options[r]) {
307 if (r < _options.size()) {
308 _combo->set_active (r);
312 void add_to_page (OptionEditorPage* p)
314 add_widgets_to_page (p, _label, _combo);
317 /** Add an allowed value for this option.
318 * @param e Enumeration.
319 * @param o User-visible name for this value.
321 void add (T e, std::string const & o) {
322 _options.push_back (e);
323 _combo->append_text (o);
327 _combo->clear_items();
332 uint32_t const r = _combo->get_active_row_number ();
333 if (r < _options.size()) {
338 void set_sensitive (bool yn) {
339 _combo->set_sensitive (yn);
342 Gtk::Widget& tip_widget() { return *_combo; }
347 sigc::slot<bool, T> _set;
349 Gtk::ComboBoxText* _combo;
350 std::vector<T> _options;
354 /** Component which provides the UI for a GTK HScale.
356 class HSliderOption : public Option
360 /** Construct an ComboOption.
362 * @param n User-visible name.
363 * @param g Slot to get the variable's value.
364 * @param s Slot to set the variable's value.
367 std::string const & i,
368 std::string const & n,
373 _label = Gtk::manage (new Gtk::Label (n + ":"));
374 _label->set_alignment (0, 0.5);
375 _hscale = Gtk::manage (new Gtk::HScale(adj));
380 std::string const & i,
381 std::string const & n,
382 Gtk::Adjustment *adj,
384 sigc::slot<bool, float> s
391 _label = Gtk::manage (new Gtk::Label (n + ":"));
392 _label->set_alignment (0, 0.5);
393 _hscale = Gtk::manage (new Gtk::HScale(*_adj));
394 _adj->signal_value_changed().connect (sigc::mem_fun (*this, &HSliderOption::changed));
397 void set_state_from_config () {
398 if (_adj) _adj->set_value (_get());
402 if (_adj) _set (_adj->get_value ());
405 void add_to_page (OptionEditorPage* p)
407 add_widgets_to_page (p, _label, _hscale);
410 void set_sensitive (bool yn) {
411 _hscale->set_sensitive (yn);
414 Gtk::Widget& tip_widget() { return *_hscale; }
415 Gtk::HScale& scale() { return *_hscale; }
418 sigc::slot<float> _get;
419 sigc::slot<bool, float> _set;
421 Gtk::HScale* _hscale;
422 Gtk::Adjustment* _adj;
425 /** Component which provides the UI to handle an enumerated option using a GTK ComboBox.
426 * The template parameter is the enumeration.
428 class ComboStringOption : public Option
432 /** Construct an ComboOption.
434 * @param n User-visible name.
435 * @param g Slot to get the variable's value.
436 * @param s Slot to set the variable's value.
439 std::string const & i,
440 std::string const & n,
441 sigc::slot<std::string> g,
442 sigc::slot<bool, std::string> s
448 _label = Gtk::manage (new Gtk::Label (n + ":"));
449 _label->set_alignment (0, 0.5);
450 _combo = Gtk::manage (new Gtk::ComboBoxText);
451 _combo->signal_changed().connect (sigc::mem_fun (*this, &ComboStringOption::changed));
454 void set_state_from_config () {
455 _combo->set_active_text (_get());
458 void add_to_page (OptionEditorPage* p)
460 add_widgets_to_page (p, _label, _combo);
463 /** Set the allowed strings for this option
464 * @param strings a vector of allowed strings
466 void set_popdown_strings (const std::vector<std::string>& strings) {
467 _combo->clear_items ();
468 for (std::vector<std::string>::const_iterator i = strings.begin(); i != strings.end(); ++i) {
469 _combo->append_text (*i);
474 _combo->clear_items();
478 _set (_combo->get_active_text ());
481 void set_sensitive (bool yn) {
482 _combo->set_sensitive (yn);
485 Gtk::Widget& tip_widget() { return *_combo; }
488 sigc::slot<std::string> _get;
489 sigc::slot<bool, std::string> _set;
491 Gtk::ComboBoxText* _combo;
495 /** Component which provides the UI to handle a boolean option which needs
496 * to be represented as a ComboBox to be clear to the user.
498 class BoolComboOption : public Option
508 sigc::slot<bool, bool>
511 void set_state_from_config ();
512 void add_to_page (OptionEditorPage *);
514 void set_sensitive (bool);
516 Gtk::Widget& tip_widget() { return *_combo; }
520 sigc::slot<bool> _get;
521 sigc::slot<bool, bool> _set;
523 Gtk::ComboBoxText* _combo;
528 /** Component which provides the UI to handle an numeric option using a GTK SpinButton */
530 class SpinOption : public Option
533 /** Construct an SpinOption.
535 * @param n User-visible name.
536 * @param g Slot to get the variable's value.
537 * @param s Slot to set the variable's value.
538 * @param min Variable minimum value.
539 * @param max Variable maximum value.
540 * @param step Step for the spin button.
541 * @param page Page step for the spin button.
542 * @param unit Unit name.
543 * @param scale Scaling factor (such that for a value x in the spinbutton, x * scale is written to the config)
544 * @param digits Number of decimal digits to show.
547 std::string const & i,
548 std::string const & n,
550 sigc::slot<bool, T> s,
555 std::string const & unit = "",
564 _label = Gtk::manage (new Gtk::Label (n + ":"));
565 _label->set_alignment (0, 0.5);
567 _spin = Gtk::manage (new Gtk::SpinButton);
568 _spin->set_range (min, max);
569 _spin->set_increments (step, page);
570 _spin->set_digits(digits);
572 _box = Gtk::manage (new Gtk::HBox);
573 _box->pack_start (*_spin, true, true);
574 _box->set_spacing (4);
576 _box->pack_start (*Gtk::manage (new Gtk::Label (unit)), false, false);
579 _spin->signal_value_changed().connect (sigc::mem_fun (*this, &SpinOption::changed));
582 void set_state_from_config ()
584 _spin->set_value (_get () / _scale);
587 void add_to_page (OptionEditorPage* p)
589 add_widgets_to_page (p, _label, _box);
594 _set (static_cast<T> (_spin->get_value ()) * _scale);
597 Gtk::Widget& tip_widget() { return *_spin; }
601 sigc::slot<bool, T> _set;
605 Gtk::SpinButton* _spin;
608 class FaderOption : public Option
612 FaderOption (std::string const &, std::string const &, sigc::slot<ARDOUR::gain_t> g, sigc::slot<bool, ARDOUR::gain_t> s);
613 void set_state_from_config ();
614 void add_to_page (OptionEditorPage *);
616 Gtk::Widget& tip_widget() { return *_db_slider; }
621 bool on_key_press (GdkEventKey* ev);
623 Gtk::Adjustment _db_adjustment;
624 Gtkmm2ext::HSliderController* _db_slider;
625 Gtk::Entry _db_display;
628 Gtk::VBox _fader_centering_box;
629 sigc::slot<ARDOUR::gain_t> _get;
630 sigc::slot<bool, ARDOUR::gain_t> _set;
633 class ClockOption : public Option
636 ClockOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
637 void set_state_from_config ();
638 void add_to_page (OptionEditorPage *);
639 void set_session (ARDOUR::Session *);
641 Gtk::Widget& tip_widget() { return _clock; }
642 AudioClock& clock() { return _clock; }
645 void save_clock_time ();
648 sigc::slot<std::string> _get;
649 sigc::slot<bool, std::string> _set;
650 ARDOUR::Session *_session;
653 class DirectoryOption : public Option
656 DirectoryOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
658 void set_state_from_config ();
659 void add_to_page (OptionEditorPage *);
661 Gtk::Widget& tip_widget() { return _file_chooser; }
664 void selection_changed ();
666 sigc::slot<std::string> _get; ///< slot to get the configuration variable's value
667 sigc::slot<bool, std::string> _set; ///< slot to set the configuration variable's value
668 Gtk::FileChooserButton _file_chooser;
671 /** Class to represent a single page in an OptionEditor's notebook.
672 * Pages are laid out using a 3-column table; the 1st column is used
673 * to indent non-headings, and the 2nd and 3rd for actual content.
675 class OptionEditorPage
678 OptionEditorPage (Gtk::Notebook&, std::string const &);
682 std::list<OptionEditorComponent*> components;
685 /** The OptionEditor dialog base class */
686 class OptionEditor : virtual public sigc::trackable
689 OptionEditor (PBD::Configuration *);
690 virtual ~OptionEditor ();
692 void add_option (std::string const &, OptionEditorComponent *);
693 void add_page (std::string const &, Gtk::Widget& page_widget);
695 void set_current_page (std::string const &);
698 virtual void parameter_changed (std::string const &);
700 PBD::Configuration* _config;
701 Gtk::Notebook& notebook() { return _notebook; }
702 Gtk::TreeView& treeview() { return option_treeview; }
704 class OptionColumns : public Gtk::TreeModel::ColumnRecord
707 Gtk::TreeModelColumn<std::string> name;
708 Gtk::TreeModelColumn<Gtk::Widget*> widget;
716 OptionColumns option_columns;
717 Glib::RefPtr<Gtk::TreeStore> option_tree;
720 PBD::ScopedConnection config_connection;
721 Gtk::Notebook _notebook;
722 Gtk::TreeView option_treeview;
723 std::map<std::string, OptionEditorPage*> _pages;
725 void add_path_to_treeview (std::string const &, Gtk::Widget&);
726 void treeview_row_selected ();
729 /** The OptionEditor dialog-as-container base class */
730 class OptionEditorContainer : public OptionEditor, public Gtk::VBox
733 OptionEditorContainer (PBD::Configuration *, std::string const &);
734 ~OptionEditorContainer() {}
739 /** The OptionEditor dialog-as-container base class */
740 class OptionEditorWindow : public OptionEditor, public ArdourWindow
743 OptionEditorWindow (PBD::Configuration *, std::string const &);
744 ~OptionEditorWindow() {}
750 #endif /* __gtk_ardour_option_editor_h__ */