2 * Copyright (C) 2005-2009 Taybin Rutkin <taybin@taybin.com>
3 * Copyright (C) 2005-2018 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2005 Karsten Wiese <fzuuzf@googlemail.com>
5 * Copyright (C) 2008-2015 David Robillard <d@drobilla.net>
6 * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
7 * Copyright (C) 2012-2018 Robin Gareus <robin@gareus.org>
8 * Copyright (C) 2013-2015 John Emmas <john@creativepost.co.uk>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #ifndef __gtk_ardour_option_editor_h__
26 #define __gtk_ardour_option_editor_h__
28 #include <gtkmm/checkbutton.h>
29 #include <gtkmm/comboboxtext.h>
30 #include <gtkmm/filechooserbutton.h>
31 #include <gtkmm/label.h>
32 #include <gtkmm/notebook.h>
33 #include <gtkmm/scale.h>
34 #include <gtkmm/spinbutton.h>
35 #include <gtkmm/table.h>
36 #include <gtkmm/treestore.h>
37 #include <gtkmm/treeview.h>
38 #include <gtkmm/window.h>
40 #include "widgets/slider_controller.h"
43 #include "ardour_window.h"
44 #include "audio_clock.h"
45 #include "ardour/types.h"
47 /** @file option_editor.h
48 * @brief Base class for option editing dialog boxes.
50 * Code to provided the basis for dialogs which allow the user to edit options
51 * from an ARDOUR::Configuration class.
53 * The idea is that we have an OptionEditor class which is the dialog box.
54 * This is essentially a GTK Notebook. OptionEditorComponent objects can
55 * then be added to the OptionEditor, and these components are arranged on
56 * the pages of the Notebook. There is also an OptionEditorComponent hierarchy
57 * here, providing things like boolean and combobox option components.
59 * It is intended that OptionEditor be subclassed to implement a particular
67 class OptionEditorPage;
69 /** Base class for components of an OptionEditor dialog */
70 class OptionEditorComponent
73 virtual ~OptionEditorComponent() {}
75 /** Called when a configuration parameter's value has changed.
76 * @param p parameter name
78 virtual void parameter_changed (std::string const & p) = 0;
80 /** Called to instruct the object to set its UI state from the configuration */
81 virtual void set_state_from_config () = 0;
83 /** Called to instruct the object to add itself to an OptionEditorPage */
84 virtual void add_to_page (OptionEditorPage *) = 0;
86 void add_widget_to_page (OptionEditorPage*, Gtk::Widget*);
87 void add_widgets_to_page (OptionEditorPage*, Gtk::Widget*, Gtk::Widget*, bool expand = true);
89 void set_note (std::string const &);
91 virtual Gtk::Widget& tip_widget() = 0;
94 void maybe_add_note (OptionEditorPage *, int);
99 /** A component which provides a subheading within the dialog */
100 class OptionEditorHeading : public OptionEditorComponent
103 OptionEditorHeading (std::string const &);
105 void parameter_changed (std::string const &) {}
106 void set_state_from_config () {}
107 void add_to_page (OptionEditorPage *);
109 Gtk::Widget& tip_widget() { return *_label; }
112 Gtk::Label* _label; ///< the label used for the heading
115 /** Expanding layout helper to push elements to the left on a single column page */
116 class OptionEditorBlank : public OptionEditorComponent
119 OptionEditorBlank () {}
121 void parameter_changed (std::string const &) {}
122 void set_state_from_config () {}
123 void add_to_page (OptionEditorPage *);
125 Gtk::Widget& tip_widget() { return _dummy; }
128 Gtk::EventBox _dummy;
131 class RcConfigDisplay : public OptionEditorComponent
134 RcConfigDisplay (std::string const &, std::string const &, sigc::slot<std::string>, char s = '\0');
135 void add_to_page (OptionEditorPage *);
136 void parameter_changed (std::string const & p);
137 void set_state_from_config ();
138 Gtk::Widget& tip_widget() { return *_info; }
140 sigc::slot<std::string> _get;
147 class RcActionButton : public OptionEditorComponent
150 RcActionButton (std::string const & t, const Glib::SignalProxy0< void >::SlotType & slot, std::string const & l = "");
151 void add_to_page (OptionEditorPage *);
153 void parameter_changed (std::string const & p) {}
154 void set_state_from_config () {}
155 Gtk::Widget& tip_widget() { return *_button; }
158 Gtk::Button* _button;
163 /** Base class for components which provide UI to change an option */
164 class Option : public OptionEditorComponent
167 /** Construct an Option.
168 * @param i Option id (e.g. "plugins-stop-with-transport")
169 * @param n User-visible name (e.g. "Stop plugins when the transport is stopped")
171 Option (std::string const & i,
172 std::string const & n
178 void parameter_changed (std::string const & p)
181 set_state_from_config ();
185 virtual void set_state_from_config () = 0;
186 virtual void add_to_page (OptionEditorPage*) = 0;
188 std::string id () const {
197 /** Just a Gtk Checkbutton, masquerading as an option component */
198 class CheckOption : public OptionEditorComponent , public Gtkmm2ext::Activatable, public sigc::trackable
201 CheckOption (std::string const &, std::string const &, Glib::RefPtr<Gtk::Action> act );
202 void set_state_from_config () {}
203 void parameter_changed (std::string const &) {}
204 void add_to_page (OptionEditorPage*);
206 void set_sensitive (bool yn) {
207 _button->set_sensitive (yn);
210 Gtk::Widget& tip_widget() { return *_button; }
213 void action_toggled ();
214 void action_sensitivity_changed () {}
215 void action_visibility_changed () {}
217 virtual void toggled ();
219 Gtk::CheckButton* _button; ///< UI button
220 Gtk::Label* _label; ///< label for button, so we can use markup
223 /** Component which provides the UI to handle a boolean option using a GTK CheckButton */
224 class BoolOption : public Option
227 BoolOption (std::string const &, std::string const &, sigc::slot<bool>, sigc::slot<bool, bool>);
228 void set_state_from_config ();
229 void add_to_page (OptionEditorPage*);
231 void set_sensitive (bool yn) {
232 _button->set_sensitive (yn);
235 Gtk::Widget& tip_widget() { return *_button; }
238 virtual void toggled ();
240 sigc::slot<bool> _get; ///< slot to get the configuration variable's value
241 sigc::slot<bool, bool> _set; ///< slot to set the configuration variable's value
242 Gtk::CheckButton* _button; ///< UI button
243 Gtk::Label* _label; ///< label for button, so we can use markup
246 class RouteDisplayBoolOption : public BoolOption
249 RouteDisplayBoolOption (std::string const &, std::string const &, sigc::slot<bool>, sigc::slot<bool, bool>);
252 virtual void toggled ();
255 /** Component which allows to add any GTK Widget - intended for single buttons and custom stateless objects */
256 class FooOption : public OptionEditorComponent
259 FooOption (Gtk::Widget *w) : _w (w) {}
261 void add_to_page (OptionEditorPage* p) {
262 add_widget_to_page (p, _w);
265 Gtk::Widget& tip_widget() { return *_w; }
266 void set_state_from_config () {}
267 void parameter_changed (std::string const &) {}
272 /** Component which provides the UI to handle a string option using a GTK Entry */
273 class EntryOption : public Option
276 EntryOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
277 void set_state_from_config ();
278 void add_to_page (OptionEditorPage*);
279 void set_sensitive (bool);
280 void set_invalid_chars (std::string i) { _invalid = i; }
282 Gtk::Widget& tip_widget() { return *_entry; }
286 bool focus_out (GdkEventFocus*);
287 void filter_text (const Glib::ustring&, int*);
289 sigc::slot<std::string> _get; ///< slot to get the configuration variable's value
290 sigc::slot<bool, std::string> _set; ///< slot to set the configuration variable's value
291 Gtk::Label* _label; ///< UI label
292 Gtk::Entry* _entry; ///< UI entry
293 std::string _invalid;
297 /** Component which provides the UI to handle an enumerated option using a GTK ComboBox.
298 * The template parameter is the enumeration.
301 class ComboOption : public Option
304 /** Construct an ComboOption.
306 * @param n User-visible name.
307 * @param g Slot to get the variable's value.
308 * @param s Slot to set the variable's value.
311 std::string const & i,
312 std::string const & n,
314 sigc::slot<bool, T> s
320 _label = Gtk::manage (new Gtk::Label (n + ":"));
321 _label->set_alignment (0, 0.5);
322 _combo = Gtk::manage (new Gtk::ComboBoxText);
323 _combo->signal_changed().connect (sigc::mem_fun (*this, &ComboOption::changed));
326 void set_state_from_config ()
329 while (r < _options.size() && _get () != _options[r]) {
333 if (r < _options.size()) {
334 _combo->set_active (r);
338 void add_to_page (OptionEditorPage* p)
340 add_widgets_to_page (p, _label, _combo);
343 /** Add an allowed value for this option.
344 * @param e Enumeration.
345 * @param o User-visible name for this value.
347 void add (T e, std::string const & o)
349 _options.push_back (e);
350 _combo->append_text (o);
355 _combo->clear_items();
361 uint32_t const r = _combo->get_active_row_number ();
362 if (r < _options.size()) {
366 void set_sensitive (bool yn)
368 _combo->set_sensitive (yn);
371 Gtk::Widget& tip_widget() { return *_combo; }
375 sigc::slot<bool, T> _set;
377 Gtk::ComboBoxText* _combo;
378 std::vector<T> _options;
382 /** Component which provides the UI for a GTK HScale.
384 class HSliderOption : public Option
388 std::string const& i,
389 std::string const& n,
391 sigc::slot<bool, float> s,
392 double lower, double upper,
393 double step_increment = 1,
394 double page_increment = 10,
396 bool logarithmic = false
399 void set_state_from_config ();
400 virtual void changed ();
401 void add_to_page (OptionEditorPage* p);
402 void set_sensitive (bool yn);
404 Gtk::Widget& tip_widget() { return _hscale; }
405 Gtk::HScale& scale() { return _hscale; }
408 sigc::slot<float> _get;
409 sigc::slot<bool, float> _set;
410 Gtk::Adjustment _adj;
418 /** Component which provides the UI to handle an enumerated option using a GTK ComboBox.
419 * The template parameter is the enumeration.
421 class ComboStringOption : public Option
424 /** Construct an ComboOption.
426 * @param n User-visible name.
427 * @param g Slot to get the variable's value.
428 * @param s Slot to set the variable's value.
431 std::string const & i,
432 std::string const & n,
433 sigc::slot<std::string> g,
434 sigc::slot<bool, std::string> s
437 void set_state_from_config ();
438 void add_to_page (OptionEditorPage* p);
440 /** Set the allowed strings for this option
441 * @param strings a vector of allowed strings
443 void set_popdown_strings (const std::vector<std::string>& strings);
447 void set_sensitive (bool yn);
449 Gtk::Widget& tip_widget() { return *_combo; }
452 sigc::slot<std::string> _get;
453 sigc::slot<bool, std::string> _set;
455 Gtk::ComboBoxText* _combo;
459 /** Component which provides the UI to handle a boolean option which needs
460 * to be represented as a ComboBox to be clear to the user.
462 class BoolComboOption : public Option
471 sigc::slot<bool, bool>
474 void set_state_from_config ();
475 void add_to_page (OptionEditorPage *);
477 void set_sensitive (bool);
479 Gtk::Widget& tip_widget() { return *_combo; }
482 sigc::slot<bool> _get;
483 sigc::slot<bool, bool> _set;
485 Gtk::ComboBoxText* _combo;
489 /** Component which provides the UI to handle an numeric option using a GTK SpinButton */
491 class SpinOption : public Option
494 /** Construct an SpinOption.
496 * @param n User-visible name.
497 * @param g Slot to get the variable's value.
498 * @param s Slot to set the variable's value.
499 * @param min Variable minimum value.
500 * @param max Variable maximum value.
501 * @param step Step for the spin button.
502 * @param page Page step for the spin button.
503 * @param unit Unit name.
504 * @param scale Scaling factor (such that for a value x in the spinbutton, x * scale is written to the config)
505 * @param digits Number of decimal digits to show.
508 std::string const & i,
509 std::string const & n,
511 sigc::slot<bool, T> s,
516 std::string const & unit = "",
525 _label = Gtk::manage (new Gtk::Label (n + ":"));
526 _label->set_alignment (0, 0.5);
528 _spin = Gtk::manage (new Gtk::SpinButton);
529 _spin->set_range (min, max);
530 _spin->set_increments (step, page);
531 _spin->set_digits(digits);
533 _box = Gtk::manage (new Gtk::HBox);
534 _box->pack_start (*_spin, true, true);
535 _box->set_spacing (4);
537 _box->pack_start (*Gtk::manage (new Gtk::Label (unit)), false, false);
540 _spin->signal_value_changed().connect (sigc::mem_fun (*this, &SpinOption::changed));
543 void set_state_from_config ()
545 _spin->set_value (_get () / _scale);
548 void add_to_page (OptionEditorPage* p)
550 add_widgets_to_page (p, _label, _box, false);
555 _set (static_cast<T> (_spin->get_value ()) * _scale);
558 Gtk::Widget& tip_widget() { return *_spin; }
562 sigc::slot<bool, T> _set;
566 Gtk::SpinButton* _spin;
569 class FaderOption : public Option
573 FaderOption (std::string const &, std::string const &, sigc::slot<ARDOUR::gain_t> g, sigc::slot<bool, ARDOUR::gain_t> s);
574 void set_state_from_config ();
575 void add_to_page (OptionEditorPage *);
577 Gtk::Widget& tip_widget() { return *_db_slider; }
582 bool on_key_press (GdkEventKey* ev);
584 Gtk::Adjustment _db_adjustment;
585 ArdourWidgets::HSliderController* _db_slider;
586 Gtk::Entry _db_display;
589 Gtk::VBox _fader_centering_box;
590 sigc::slot<ARDOUR::gain_t> _get;
591 sigc::slot<bool, ARDOUR::gain_t> _set;
594 class WidgetOption : public Option
597 WidgetOption (std::string const & i, std::string const & n, Gtk::Widget& w);
599 void add_to_page (OptionEditorPage*);
600 void parameter_changed (std::string const &) {}
601 void set_state_from_config () {}
603 Gtk::Widget& tip_widget() { return *_widget; }
606 Gtk::Widget* _widget;
609 class ClockOption : public Option
612 ClockOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
613 void set_state_from_config ();
614 void add_to_page (OptionEditorPage *);
615 void set_session (ARDOUR::Session *);
617 Gtk::Widget& tip_widget() { return _clock; }
618 AudioClock& clock() { return _clock; }
621 void save_clock_time ();
624 sigc::slot<std::string> _get;
625 sigc::slot<bool, std::string> _set;
626 ARDOUR::Session *_session;
629 class DirectoryOption : public Option
632 DirectoryOption (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 *);
637 Gtk::Widget& tip_widget() { return _file_chooser; }
640 void selection_changed ();
642 sigc::slot<std::string> _get; ///< slot to get the configuration variable's value
643 sigc::slot<bool, std::string> _set; ///< slot to set the configuration variable's value
644 Gtk::FileChooserButton _file_chooser;
647 /** Class to represent a single page in an OptionEditor's notebook.
648 * Pages are laid out using a 3-column table; the 1st column is used
649 * to indent non-headings, and the 2nd and 3rd for actual content.
651 class OptionEditorPage
654 OptionEditorPage (Gtk::Notebook&, std::string const &);
659 std::list<OptionEditorComponent*> components;
665 class OptionEditorMiniPage : public OptionEditorComponent, public OptionEditorPage
668 OptionEditorMiniPage ()
670 box.pack_start (table, false, false);
671 box.set_border_width (0);
674 void parameter_changed (std::string const &) = 0;
675 void set_state_from_config () = 0;
676 virtual void add_to_page (OptionEditorPage*);
678 Gtk::Widget& tip_widget() { return *table.children().front().get_widget(); }
681 /** The OptionEditor dialog base class */
682 class OptionEditor : virtual public sigc::trackable
685 OptionEditor (PBD::Configuration *);
686 virtual ~OptionEditor ();
688 void add_option (std::string const &, OptionEditorComponent *);
689 void add_page (std::string const &, Gtk::Widget& page_widget);
691 void set_current_page (std::string const &);
694 virtual void parameter_changed (std::string const &);
696 PBD::Configuration* _config;
697 Gtk::Notebook& notebook() { return _notebook; }
698 Gtk::TreeView& treeview() { return option_treeview; }
700 class OptionColumns : public Gtk::TreeModel::ColumnRecord
703 Gtk::TreeModelColumn<std::string> name;
704 Gtk::TreeModelColumn<Gtk::Widget*> widget;
712 OptionColumns option_columns;
713 Glib::RefPtr<Gtk::TreeStore> option_tree;
716 PBD::ScopedConnection config_connection;
717 Gtk::Notebook _notebook;
718 Gtk::TreeView option_treeview;
719 std::map<std::string, OptionEditorPage*> _pages;
721 void add_path_to_treeview (std::string const &, Gtk::Widget&);
722 Gtk::TreeModel::iterator find_path_in_treemodel (std::string const & pn,
723 bool create_missing = false);
724 void treeview_row_selected ();
727 /** The OptionEditor dialog-as-container base class */
728 class OptionEditorContainer : public OptionEditor, public Gtk::VBox
731 OptionEditorContainer (PBD::Configuration *, std::string const &);
732 ~OptionEditorContainer() {}
737 /** The OptionEditor dialog-as-container base class */
738 class OptionEditorWindow : public OptionEditor, public ArdourWindow
741 OptionEditorWindow (PBD::Configuration *, std::string const &);
742 ~OptionEditorWindow() {}
748 #endif /* __gtk_ardour_option_editor_h__ */