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
195 CheckOption (std::string const &, std::string const &, Glib::RefPtr<Gtk::Action> act );
196 virtual ~CheckOption ();
197 void set_state_from_config () {}
198 void parameter_changed (std::string const &) {}
199 void add_to_page (OptionEditorPage*);
201 void set_sensitive (bool yn) {
202 _button->set_sensitive (yn);
205 Gtk::Widget& tip_widget() { return *_button; }
208 void action_toggled ();
209 void action_sensitivity_changed () {}
210 void action_visibility_changed () {}
212 virtual void toggled ();
214 Gtk::CheckButton* _button; ///< UI button
215 Gtk::Label* _label; ///< label for button, so we can use markup
218 sigc::connection _callback_connection;
221 /** Component which provides the UI to handle a boolean option using a GTK CheckButton */
222 class BoolOption : public Option
225 BoolOption (std::string const &, std::string const &, sigc::slot<bool>, sigc::slot<bool, bool>);
226 void set_state_from_config ();
227 void add_to_page (OptionEditorPage*);
229 void set_sensitive (bool yn) {
230 _button->set_sensitive (yn);
233 Gtk::Widget& tip_widget() { return *_button; }
236 virtual void toggled ();
238 sigc::slot<bool> _get; ///< slot to get the configuration variable's value
239 sigc::slot<bool, bool> _set; ///< slot to set the configuration variable's value
240 Gtk::CheckButton* _button; ///< UI button
241 Gtk::Label* _label; ///< label for button, so we can use markup
244 class RouteDisplayBoolOption : public BoolOption
247 RouteDisplayBoolOption (std::string const &, std::string const &, sigc::slot<bool>, sigc::slot<bool, bool>);
250 virtual void toggled ();
253 /** Component which allows to add any GTK Widget - intended for single buttons and custom stateless objects */
254 class FooOption : public OptionEditorComponent
257 FooOption (Gtk::Widget *w) : _w (w) {}
259 void add_to_page (OptionEditorPage* p) {
260 add_widget_to_page (p, _w);
263 Gtk::Widget& tip_widget() { return *_w; }
264 void set_state_from_config () {}
265 void parameter_changed (std::string const &) {}
270 /** Component which provides the UI to handle a string option using a GTK Entry */
271 class EntryOption : public Option
274 EntryOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
275 void set_state_from_config ();
276 void add_to_page (OptionEditorPage*);
277 void set_sensitive (bool);
278 void set_invalid_chars (std::string i) { _invalid = i; }
280 Gtk::Widget& tip_widget() { return *_entry; }
284 bool focus_out (GdkEventFocus*);
285 void filter_text (const Glib::ustring&, int*);
287 sigc::slot<std::string> _get; ///< slot to get the configuration variable's value
288 sigc::slot<bool, std::string> _set; ///< slot to set the configuration variable's value
289 Gtk::Label* _label; ///< UI label
290 Gtk::Entry* _entry; ///< UI entry
291 std::string _invalid;
295 /** Component which provides the UI to handle an enumerated option using a GTK ComboBox.
296 * The template parameter is the enumeration.
299 class ComboOption : public Option
302 /** Construct an ComboOption.
304 * @param n User-visible name.
305 * @param g Slot to get the variable's value.
306 * @param s Slot to set the variable's value.
309 std::string const & i,
310 std::string const & n,
312 sigc::slot<bool, T> s
318 _label = Gtk::manage (new Gtk::Label (n + ":"));
319 _label->set_alignment (0, 0.5);
320 _combo = Gtk::manage (new Gtk::ComboBoxText);
321 _combo->signal_changed().connect (sigc::mem_fun (*this, &ComboOption::changed));
324 void set_state_from_config ()
327 while (r < _options.size() && _get () != _options[r]) {
331 if (r < _options.size()) {
332 _combo->set_active (r);
336 void add_to_page (OptionEditorPage* p)
338 add_widgets_to_page (p, _label, _combo);
341 /** Add an allowed value for this option.
342 * @param e Enumeration.
343 * @param o User-visible name for this value.
345 void add (T e, std::string const & o)
347 _options.push_back (e);
348 _combo->append_text (o);
353 _combo->clear_items();
359 uint32_t const r = _combo->get_active_row_number ();
360 if (r < _options.size()) {
364 void set_sensitive (bool yn)
366 _combo->set_sensitive (yn);
369 Gtk::Widget& tip_widget() { return *_combo; }
373 sigc::slot<bool, T> _set;
375 Gtk::ComboBoxText* _combo;
376 std::vector<T> _options;
380 /** Component which provides the UI for a GTK HScale.
382 class HSliderOption : public Option
386 std::string const& i,
387 std::string const& n,
389 sigc::slot<bool, float> s,
390 double lower, double upper,
391 double step_increment = 1,
392 double page_increment = 10,
394 bool logarithmic = false
397 void set_state_from_config ();
398 virtual void changed ();
399 void add_to_page (OptionEditorPage* p);
400 void set_sensitive (bool yn);
402 Gtk::Widget& tip_widget() { return _hscale; }
403 Gtk::HScale& scale() { return _hscale; }
406 sigc::slot<float> _get;
407 sigc::slot<bool, float> _set;
408 Gtk::Adjustment _adj;
416 /** Component which provides the UI to handle an enumerated option using a GTK ComboBox.
417 * The template parameter is the enumeration.
419 class ComboStringOption : public Option
422 /** Construct an ComboOption.
424 * @param n User-visible name.
425 * @param g Slot to get the variable's value.
426 * @param s Slot to set the variable's value.
429 std::string const & i,
430 std::string const & n,
431 sigc::slot<std::string> g,
432 sigc::slot<bool, std::string> s
435 void set_state_from_config ();
436 void add_to_page (OptionEditorPage* p);
438 /** Set the allowed strings for this option
439 * @param strings a vector of allowed strings
441 void set_popdown_strings (const std::vector<std::string>& strings);
445 void set_sensitive (bool yn);
447 Gtk::Widget& tip_widget() { return *_combo; }
450 sigc::slot<std::string> _get;
451 sigc::slot<bool, std::string> _set;
453 Gtk::ComboBoxText* _combo;
457 /** Component which provides the UI to handle a boolean option which needs
458 * to be represented as a ComboBox to be clear to the user.
460 class BoolComboOption : public Option
469 sigc::slot<bool, bool>
472 void set_state_from_config ();
473 void add_to_page (OptionEditorPage *);
475 void set_sensitive (bool);
477 Gtk::Widget& tip_widget() { return *_combo; }
480 sigc::slot<bool> _get;
481 sigc::slot<bool, bool> _set;
483 Gtk::ComboBoxText* _combo;
487 /** Component which provides the UI to handle an numeric option using a GTK SpinButton */
489 class SpinOption : public Option
492 /** Construct an SpinOption.
494 * @param n User-visible name.
495 * @param g Slot to get the variable's value.
496 * @param s Slot to set the variable's value.
497 * @param min Variable minimum value.
498 * @param max Variable maximum value.
499 * @param step Step for the spin button.
500 * @param page Page step for the spin button.
501 * @param unit Unit name.
502 * @param scale Scaling factor (such that for a value x in the spinbutton, x * scale is written to the config)
503 * @param digits Number of decimal digits to show.
506 std::string const & i,
507 std::string const & n,
509 sigc::slot<bool, T> s,
514 std::string const & unit = "",
523 _label = Gtk::manage (new Gtk::Label (n + ":"));
524 _label->set_alignment (0, 0.5);
526 _spin = Gtk::manage (new Gtk::SpinButton);
527 _spin->set_range (min, max);
528 _spin->set_increments (step, page);
529 _spin->set_digits(digits);
531 _box = Gtk::manage (new Gtk::HBox);
532 _box->pack_start (*_spin, true, true);
533 _box->set_spacing (4);
535 _box->pack_start (*Gtk::manage (new Gtk::Label (unit)), false, false);
538 _spin->signal_value_changed().connect (sigc::mem_fun (*this, &SpinOption::changed));
541 void set_state_from_config ()
543 _spin->set_value (_get () / _scale);
546 void add_to_page (OptionEditorPage* p)
548 add_widgets_to_page (p, _label, _box, false);
553 _set (static_cast<T> (_spin->get_value ()) * _scale);
556 Gtk::Widget& tip_widget() { return *_spin; }
560 sigc::slot<bool, T> _set;
564 Gtk::SpinButton* _spin;
567 class FaderOption : public Option
571 FaderOption (std::string const &, std::string const &, sigc::slot<ARDOUR::gain_t> g, sigc::slot<bool, ARDOUR::gain_t> s);
572 void set_state_from_config ();
573 void add_to_page (OptionEditorPage *);
575 Gtk::Widget& tip_widget() { return *_db_slider; }
580 bool on_key_press (GdkEventKey* ev);
582 Gtk::Adjustment _db_adjustment;
583 ArdourWidgets::HSliderController* _db_slider;
584 Gtk::Entry _db_display;
587 Gtk::VBox _fader_centering_box;
588 sigc::slot<ARDOUR::gain_t> _get;
589 sigc::slot<bool, ARDOUR::gain_t> _set;
592 class WidgetOption : public Option
595 WidgetOption (std::string const & i, std::string const & n, Gtk::Widget& w);
597 void add_to_page (OptionEditorPage*);
598 void parameter_changed (std::string const &) {}
599 void set_state_from_config () {}
601 Gtk::Widget& tip_widget() { return *_widget; }
604 Gtk::Widget* _widget;
607 class ClockOption : public Option
610 ClockOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
611 void set_state_from_config ();
612 void add_to_page (OptionEditorPage *);
613 void set_session (ARDOUR::Session *);
615 Gtk::Widget& tip_widget() { return _clock; }
616 AudioClock& clock() { return _clock; }
619 void save_clock_time ();
622 sigc::slot<std::string> _get;
623 sigc::slot<bool, std::string> _set;
624 ARDOUR::Session *_session;
627 class DirectoryOption : public Option
630 DirectoryOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
632 void set_state_from_config ();
633 void add_to_page (OptionEditorPage *);
635 Gtk::Widget& tip_widget() { return _file_chooser; }
638 void selection_changed ();
640 sigc::slot<std::string> _get; ///< slot to get the configuration variable's value
641 sigc::slot<bool, std::string> _set; ///< slot to set the configuration variable's value
642 Gtk::FileChooserButton _file_chooser;
645 /** Class to represent a single page in an OptionEditor's notebook.
646 * Pages are laid out using a 3-column table; the 1st column is used
647 * to indent non-headings, and the 2nd and 3rd for actual content.
649 class OptionEditorPage
652 OptionEditorPage (Gtk::Notebook&, std::string const &);
657 std::list<OptionEditorComponent*> components;
663 class OptionEditorMiniPage : public OptionEditorComponent, public OptionEditorPage
666 OptionEditorMiniPage ()
668 box.pack_start (table, false, false);
669 box.set_border_width (0);
672 void parameter_changed (std::string const &) = 0;
673 void set_state_from_config () = 0;
674 virtual void add_to_page (OptionEditorPage*);
676 Gtk::Widget& tip_widget() { return *table.children().front().get_widget(); }
679 /** The OptionEditor dialog base class */
680 class OptionEditor : virtual public sigc::trackable
683 OptionEditor (PBD::Configuration *);
684 virtual ~OptionEditor ();
686 void add_option (std::string const &, OptionEditorComponent *);
687 void add_page (std::string const &, Gtk::Widget& page_widget);
689 void set_current_page (std::string const &);
692 virtual void parameter_changed (std::string const &);
694 PBD::Configuration* _config;
695 Gtk::Notebook& notebook() { return _notebook; }
696 Gtk::TreeView& treeview() { return option_treeview; }
698 class OptionColumns : public Gtk::TreeModel::ColumnRecord
701 Gtk::TreeModelColumn<std::string> name;
702 Gtk::TreeModelColumn<Gtk::Widget*> widget;
710 OptionColumns option_columns;
711 Glib::RefPtr<Gtk::TreeStore> option_tree;
714 PBD::ScopedConnection config_connection;
715 Gtk::Notebook _notebook;
716 Gtk::TreeView option_treeview;
717 std::map<std::string, OptionEditorPage*> _pages;
719 void add_path_to_treeview (std::string const &, Gtk::Widget&);
720 Gtk::TreeModel::iterator find_path_in_treemodel (std::string const & pn,
721 bool create_missing = false);
722 void treeview_row_selected ();
725 /** The OptionEditor dialog-as-container base class */
726 class OptionEditorContainer : public OptionEditor, public Gtk::VBox
729 OptionEditorContainer (PBD::Configuration *, std::string const &);
730 ~OptionEditorContainer() {}
735 /** The OptionEditor dialog-as-container base class */
736 class OptionEditorWindow : public OptionEditor, public ArdourWindow
739 OptionEditorWindow (PBD::Configuration *, std::string const &);
740 ~OptionEditorWindow() {}
746 #endif /* __gtk_ardour_option_editor_h__ */