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.
19 #ifndef __gtk_ardour_option_editor_h__
20 #define __gtk_ardour_option_editor_h__
22 #include <gtkmm/checkbutton.h>
23 #include <gtkmm/comboboxtext.h>
24 #include <gtkmm/filechooserbutton.h>
25 #include <gtkmm/label.h>
26 #include <gtkmm/notebook.h>
27 #include <gtkmm/scale.h>
28 #include <gtkmm/spinbutton.h>
29 #include <gtkmm/table.h>
30 #include <gtkmm/treestore.h>
31 #include <gtkmm/treeview.h>
32 #include <gtkmm/window.h>
34 #include "widgets/slider_controller.h"
37 #include "ardour_window.h"
38 #include "audio_clock.h"
39 #include "ardour/types.h"
41 /** @file option_editor.h
42 * @brief Base class for option editing dialog boxes.
44 * Code to provided the basis for dialogs which allow the user to edit options
45 * from an ARDOUR::Configuration class.
47 * The idea is that we have an OptionEditor class which is the dialog box.
48 * This is essentially a GTK Notebook. OptionEditorComponent objects can
49 * then be added to the OptionEditor, and these components are arranged on
50 * the pages of the Notebook. There is also an OptionEditorComponent hierarchy
51 * here, providing things like boolean and combobox option components.
53 * It is intended that OptionEditor be subclassed to implement a particular
61 class OptionEditorPage;
63 /** Base class for components of an OptionEditor dialog */
64 class OptionEditorComponent
67 virtual ~OptionEditorComponent() {}
69 /** Called when a configuration parameter's value has changed.
70 * @param p parameter name
72 virtual void parameter_changed (std::string const & p) = 0;
74 /** Called to instruct the object to set its UI state from the configuration */
75 virtual void set_state_from_config () = 0;
77 /** Called to instruct the object to add itself to an OptionEditorPage */
78 virtual void add_to_page (OptionEditorPage *) = 0;
80 void add_widget_to_page (OptionEditorPage*, Gtk::Widget*);
81 void add_widgets_to_page (OptionEditorPage*, Gtk::Widget*, Gtk::Widget*, bool expand = true);
83 void set_note (std::string const &);
85 virtual Gtk::Widget& tip_widget() = 0;
88 void maybe_add_note (OptionEditorPage *, int);
93 /** A component which provides a subheading within the dialog */
94 class OptionEditorHeading : public OptionEditorComponent
97 OptionEditorHeading (std::string const &);
99 void parameter_changed (std::string const &) {}
100 void set_state_from_config () {}
101 void add_to_page (OptionEditorPage *);
103 Gtk::Widget& tip_widget() { return *_label; }
106 Gtk::Label* _label; ///< the label used for the heading
109 /** Expanding layout helper to push elements to the left on a single column page */
110 class OptionEditorBlank : public OptionEditorComponent
113 OptionEditorBlank () {}
115 void parameter_changed (std::string const &) {}
116 void set_state_from_config () {}
117 void add_to_page (OptionEditorPage *);
119 Gtk::Widget& tip_widget() { return _dummy; }
122 Gtk::EventBox _dummy;
125 class RcConfigDisplay : public OptionEditorComponent
128 RcConfigDisplay (std::string const &, std::string const &, sigc::slot<std::string>, char s = '\0');
129 void add_to_page (OptionEditorPage *);
130 void parameter_changed (std::string const & p);
131 void set_state_from_config ();
132 Gtk::Widget& tip_widget() { return *_info; }
134 sigc::slot<std::string> _get;
141 class RcActionButton : public OptionEditorComponent
144 RcActionButton (std::string const & t, const Glib::SignalProxy0< void >::SlotType & slot, std::string const & l = "");
145 void add_to_page (OptionEditorPage *);
147 void parameter_changed (std::string const & p) {}
148 void set_state_from_config () {}
149 Gtk::Widget& tip_widget() { return *_button; }
152 Gtk::Button* _button;
157 /** Base class for components which provide UI to change an option */
158 class Option : public OptionEditorComponent
161 /** Construct an Option.
162 * @param i Option id (e.g. "plugins-stop-with-transport")
163 * @param n User-visible name (e.g. "Stop plugins when the transport is stopped")
165 Option (std::string const & i,
166 std::string const & n
172 void parameter_changed (std::string const & p)
175 set_state_from_config ();
179 virtual void set_state_from_config () = 0;
180 virtual void add_to_page (OptionEditorPage*) = 0;
182 std::string id () const {
191 /** Just a Gtk Checkbutton, masquerading as an option component */
192 class CheckOption : public OptionEditorComponent , public Gtkmm2ext::Activatable, public sigc::trackable
195 CheckOption (std::string const &, std::string const &, Glib::RefPtr<Gtk::Action> act );
196 void set_state_from_config () {}
197 void parameter_changed (std::string const &) {}
198 void add_to_page (OptionEditorPage*);
200 void set_sensitive (bool yn) {
201 _button->set_sensitive (yn);
204 Gtk::Widget& tip_widget() { return *_button; }
207 void action_toggled ();
208 void action_sensitivity_changed () {}
209 void action_visibility_changed () {}
211 virtual void toggled ();
213 Gtk::CheckButton* _button; ///< UI button
214 Gtk::Label* _label; ///< label for button, so we can use markup
217 /** Component which provides the UI to handle a boolean option using a GTK CheckButton */
218 class BoolOption : public Option
221 BoolOption (std::string const &, std::string const &, sigc::slot<bool>, sigc::slot<bool, bool>);
222 void set_state_from_config ();
223 void add_to_page (OptionEditorPage*);
225 void set_sensitive (bool yn) {
226 _button->set_sensitive (yn);
229 Gtk::Widget& tip_widget() { return *_button; }
232 virtual void toggled ();
234 sigc::slot<bool> _get; ///< slot to get the configuration variable's value
235 sigc::slot<bool, bool> _set; ///< slot to set the configuration variable's value
236 Gtk::CheckButton* _button; ///< UI button
237 Gtk::Label* _label; ///< label for button, so we can use markup
240 class RouteDisplayBoolOption : public BoolOption
243 RouteDisplayBoolOption (std::string const &, std::string const &, sigc::slot<bool>, sigc::slot<bool, bool>);
246 virtual void toggled ();
249 /** Component which allows to add any GTK Widget - intended for single buttons and custom stateless objects */
250 class FooOption : public OptionEditorComponent
253 FooOption (Gtk::Widget *w) : _w (w) {}
255 void add_to_page (OptionEditorPage* p) {
256 add_widget_to_page (p, _w);
259 Gtk::Widget& tip_widget() { return *_w; }
260 void set_state_from_config () {}
261 void parameter_changed (std::string const &) {}
266 /** Component which provides the UI to handle a string option using a GTK Entry */
267 class EntryOption : public Option
270 EntryOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
271 void set_state_from_config ();
272 void add_to_page (OptionEditorPage*);
273 void set_sensitive (bool);
274 void set_invalid_chars (std::string i) { _invalid = i; }
276 Gtk::Widget& tip_widget() { return *_entry; }
280 bool focus_out (GdkEventFocus*);
281 void filter_text (const Glib::ustring&, int*);
283 sigc::slot<std::string> _get; ///< slot to get the configuration variable's value
284 sigc::slot<bool, std::string> _set; ///< slot to set the configuration variable's value
285 Gtk::Label* _label; ///< UI label
286 Gtk::Entry* _entry; ///< UI entry
287 std::string _invalid;
291 /** Component which provides the UI to handle an enumerated option using a GTK ComboBox.
292 * The template parameter is the enumeration.
295 class ComboOption : public Option
298 /** Construct an ComboOption.
300 * @param n User-visible name.
301 * @param g Slot to get the variable's value.
302 * @param s Slot to set the variable's value.
305 std::string const & i,
306 std::string const & n,
308 sigc::slot<bool, T> s
314 _label = Gtk::manage (new Gtk::Label (n + ":"));
315 _label->set_alignment (0, 0.5);
316 _combo = Gtk::manage (new Gtk::ComboBoxText);
317 _combo->signal_changed().connect (sigc::mem_fun (*this, &ComboOption::changed));
320 void set_state_from_config ()
323 while (r < _options.size() && _get () != _options[r]) {
327 if (r < _options.size()) {
328 _combo->set_active (r);
332 void add_to_page (OptionEditorPage* p)
334 add_widgets_to_page (p, _label, _combo);
337 /** Add an allowed value for this option.
338 * @param e Enumeration.
339 * @param o User-visible name for this value.
341 void add (T e, std::string const & o)
343 _options.push_back (e);
344 _combo->append_text (o);
349 _combo->clear_items();
355 uint32_t const r = _combo->get_active_row_number ();
356 if (r < _options.size()) {
360 void set_sensitive (bool yn)
362 _combo->set_sensitive (yn);
365 Gtk::Widget& tip_widget() { return *_combo; }
369 sigc::slot<bool, T> _set;
371 Gtk::ComboBoxText* _combo;
372 std::vector<T> _options;
376 /** Component which provides the UI for a GTK HScale.
378 class HSliderOption : public Option
382 std::string const& i,
383 std::string const& n,
385 sigc::slot<bool, float> s,
386 double lower, double upper,
387 double step_increment = 1,
388 double page_increment = 10,
390 bool logarithmic = false
393 void set_state_from_config ();
394 virtual void changed ();
395 void add_to_page (OptionEditorPage* p);
396 void set_sensitive (bool yn);
398 Gtk::Widget& tip_widget() { return _hscale; }
399 Gtk::HScale& scale() { return _hscale; }
402 sigc::slot<float> _get;
403 sigc::slot<bool, float> _set;
404 Gtk::Adjustment _adj;
412 /** Component which provides the UI to handle an enumerated option using a GTK ComboBox.
413 * The template parameter is the enumeration.
415 class ComboStringOption : public Option
418 /** Construct an ComboOption.
420 * @param n User-visible name.
421 * @param g Slot to get the variable's value.
422 * @param s Slot to set the variable's value.
425 std::string const & i,
426 std::string const & n,
427 sigc::slot<std::string> g,
428 sigc::slot<bool, std::string> s
431 void set_state_from_config ();
432 void add_to_page (OptionEditorPage* p);
434 /** Set the allowed strings for this option
435 * @param strings a vector of allowed strings
437 void set_popdown_strings (const std::vector<std::string>& strings);
441 void set_sensitive (bool yn);
443 Gtk::Widget& tip_widget() { return *_combo; }
446 sigc::slot<std::string> _get;
447 sigc::slot<bool, std::string> _set;
449 Gtk::ComboBoxText* _combo;
453 /** Component which provides the UI to handle a boolean option which needs
454 * to be represented as a ComboBox to be clear to the user.
456 class BoolComboOption : public Option
465 sigc::slot<bool, bool>
468 void set_state_from_config ();
469 void add_to_page (OptionEditorPage *);
471 void set_sensitive (bool);
473 Gtk::Widget& tip_widget() { return *_combo; }
476 sigc::slot<bool> _get;
477 sigc::slot<bool, bool> _set;
479 Gtk::ComboBoxText* _combo;
483 /** Component which provides the UI to handle an numeric option using a GTK SpinButton */
485 class SpinOption : public Option
488 /** Construct an SpinOption.
490 * @param n User-visible name.
491 * @param g Slot to get the variable's value.
492 * @param s Slot to set the variable's value.
493 * @param min Variable minimum value.
494 * @param max Variable maximum value.
495 * @param step Step for the spin button.
496 * @param page Page step for the spin button.
497 * @param unit Unit name.
498 * @param scale Scaling factor (such that for a value x in the spinbutton, x * scale is written to the config)
499 * @param digits Number of decimal digits to show.
502 std::string const & i,
503 std::string const & n,
505 sigc::slot<bool, T> s,
510 std::string const & unit = "",
519 _label = Gtk::manage (new Gtk::Label (n + ":"));
520 _label->set_alignment (0, 0.5);
522 _spin = Gtk::manage (new Gtk::SpinButton);
523 _spin->set_range (min, max);
524 _spin->set_increments (step, page);
525 _spin->set_digits(digits);
527 _box = Gtk::manage (new Gtk::HBox);
528 _box->pack_start (*_spin, true, true);
529 _box->set_spacing (4);
531 _box->pack_start (*Gtk::manage (new Gtk::Label (unit)), false, false);
534 _spin->signal_value_changed().connect (sigc::mem_fun (*this, &SpinOption::changed));
537 void set_state_from_config ()
539 _spin->set_value (_get () / _scale);
542 void add_to_page (OptionEditorPage* p)
544 add_widgets_to_page (p, _label, _box, false);
549 _set (static_cast<T> (_spin->get_value ()) * _scale);
552 Gtk::Widget& tip_widget() { return *_spin; }
556 sigc::slot<bool, T> _set;
560 Gtk::SpinButton* _spin;
563 class FaderOption : public Option
567 FaderOption (std::string const &, std::string const &, sigc::slot<ARDOUR::gain_t> g, sigc::slot<bool, ARDOUR::gain_t> s);
568 void set_state_from_config ();
569 void add_to_page (OptionEditorPage *);
571 Gtk::Widget& tip_widget() { return *_db_slider; }
576 bool on_key_press (GdkEventKey* ev);
578 Gtk::Adjustment _db_adjustment;
579 ArdourWidgets::HSliderController* _db_slider;
580 Gtk::Entry _db_display;
583 Gtk::VBox _fader_centering_box;
584 sigc::slot<ARDOUR::gain_t> _get;
585 sigc::slot<bool, ARDOUR::gain_t> _set;
588 class WidgetOption : public Option
591 WidgetOption (std::string const & i, std::string const & n, Gtk::Widget& w);
593 void add_to_page (OptionEditorPage*);
594 void parameter_changed (std::string const &) {}
595 void set_state_from_config () {}
597 Gtk::Widget& tip_widget() { return *_widget; }
600 Gtk::Widget* _widget;
603 class ClockOption : public Option
606 ClockOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
607 void set_state_from_config ();
608 void add_to_page (OptionEditorPage *);
609 void set_session (ARDOUR::Session *);
611 Gtk::Widget& tip_widget() { return _clock; }
612 AudioClock& clock() { return _clock; }
615 void save_clock_time ();
618 sigc::slot<std::string> _get;
619 sigc::slot<bool, std::string> _set;
620 ARDOUR::Session *_session;
623 class DirectoryOption : public Option
626 DirectoryOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
628 void set_state_from_config ();
629 void add_to_page (OptionEditorPage *);
631 Gtk::Widget& tip_widget() { return _file_chooser; }
634 void selection_changed ();
636 sigc::slot<std::string> _get; ///< slot to get the configuration variable's value
637 sigc::slot<bool, std::string> _set; ///< slot to set the configuration variable's value
638 Gtk::FileChooserButton _file_chooser;
641 /** Class to represent a single page in an OptionEditor's notebook.
642 * Pages are laid out using a 3-column table; the 1st column is used
643 * to indent non-headings, and the 2nd and 3rd for actual content.
645 class OptionEditorPage
648 OptionEditorPage (Gtk::Notebook&, std::string const &);
653 std::list<OptionEditorComponent*> components;
659 class OptionEditorMiniPage : public OptionEditorComponent, public OptionEditorPage
662 OptionEditorMiniPage ()
664 box.pack_start (table, false, false);
665 box.set_border_width (0);
668 void parameter_changed (std::string const &) = 0;
669 void set_state_from_config () = 0;
670 virtual void add_to_page (OptionEditorPage*);
672 Gtk::Widget& tip_widget() { return *table.children().front().get_widget(); }
675 /** The OptionEditor dialog base class */
676 class OptionEditor : virtual public sigc::trackable
679 OptionEditor (PBD::Configuration *);
680 virtual ~OptionEditor ();
682 void add_option (std::string const &, OptionEditorComponent *);
683 void add_page (std::string const &, Gtk::Widget& page_widget);
685 void set_current_page (std::string const &);
688 virtual void parameter_changed (std::string const &);
690 PBD::Configuration* _config;
691 Gtk::Notebook& notebook() { return _notebook; }
692 Gtk::TreeView& treeview() { return option_treeview; }
694 class OptionColumns : public Gtk::TreeModel::ColumnRecord
697 Gtk::TreeModelColumn<std::string> name;
698 Gtk::TreeModelColumn<Gtk::Widget*> widget;
706 OptionColumns option_columns;
707 Glib::RefPtr<Gtk::TreeStore> option_tree;
710 PBD::ScopedConnection config_connection;
711 Gtk::Notebook _notebook;
712 Gtk::TreeView option_treeview;
713 std::map<std::string, OptionEditorPage*> _pages;
715 void add_path_to_treeview (std::string const &, Gtk::Widget&);
716 Gtk::TreeModel::iterator find_path_in_treemodel (std::string const & pn,
717 bool create_missing = false);
718 void treeview_row_selected ();
721 /** The OptionEditor dialog-as-container base class */
722 class OptionEditorContainer : public OptionEditor, public Gtk::VBox
725 OptionEditorContainer (PBD::Configuration *, std::string const &);
726 ~OptionEditorContainer() {}
731 /** The OptionEditor dialog-as-container base class */
732 class OptionEditorWindow : public OptionEditor, public ArdourWindow
735 OptionEditorWindow (PBD::Configuration *, std::string const &);
736 ~OptionEditorWindow() {}
742 #endif /* __gtk_ardour_option_editor_h__ */