ardour
option_editor.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Paul Davis
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #ifndef __gtk_ardour_option_editor_h__
21 #define __gtk_ardour_option_editor_h__
22 
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>
29 #include "ardour_window.h"
30 #include "audio_clock.h"
31 #include "ardour/types.h"
32 
49 namespace PBD {
50  class Configuration;
51 }
52 
53 class OptionEditorPage;
54 
57 {
58 public:
60 
64  virtual void parameter_changed (std::string const & p) = 0;
65 
67  virtual void set_state_from_config () = 0;
68 
70  virtual void add_to_page (OptionEditorPage *) = 0;
71 
72  void add_widget_to_page (OptionEditorPage*, Gtk::Widget*);
73  void add_widgets_to_page (OptionEditorPage*, Gtk::Widget*, Gtk::Widget*);
74 
75  void set_note (std::string const &);
76 
77  virtual Gtk::Widget& tip_widget() = 0;
78 
79 private:
80  void maybe_add_note (OptionEditorPage *, int);
81 
82  std::string _note;
83 };
84 
87 {
88 public:
89  OptionEditorHeading (std::string const &);
90 
91  void parameter_changed (std::string const &) {}
94 
95  Gtk::Widget& tip_widget() { return *_label; }
96 
97 private:
98  Gtk::Label* _label;
99 };
100 
103 {
104 public:
105 
108  {
109  _box = Gtk::manage (new Gtk::VBox);
110  _box->set_spacing (4);
111  }
112 
113  void parameter_changed (std::string const &) = 0;
114  void set_state_from_config () = 0;
115  void add_to_page (OptionEditorPage *);
116 
117  Gtk::Widget& tip_widget() { return *_box->children().front().get_widget(); }
118 
119 protected:
120 
121  Gtk::VBox* _box;
122 };
123 
126 {
127 public:
132  Option (std::string const & i,
133  std::string const & n
134  )
135  : _id (i),
136  _name (n)
137  {}
138 
139  void parameter_changed (std::string const & p)
140  {
141  if (p == _id) {
143  }
144  }
145 
146  virtual void set_state_from_config () = 0;
147  virtual void add_to_page (OptionEditorPage*) = 0;
148 
149  std::string id () const {
150  return _id;
151  }
152 
153 protected:
154 
155  std::string _id;
156  std::string _name;
157 };
158 
160 class BoolOption : public Option
161 {
162 public:
163 
164  BoolOption (std::string const &, std::string const &, sigc::slot<bool>, sigc::slot<bool, bool>);
165  void set_state_from_config ();
167 
168  void set_sensitive (bool yn) {
169  _button->set_sensitive (yn);
170  }
171 
172  Gtk::Widget& tip_widget() { return *_button; }
173 
174 protected:
175 
176  virtual void toggled ();
177 
178  sigc::slot<bool> _get;
179  sigc::slot<bool, bool> _set;
180  Gtk::CheckButton* _button;
181  Gtk::Label* _label;
182 };
183 
185 {
186 public:
187  RouteDisplayBoolOption (std::string const &, std::string const &, sigc::slot<bool>, sigc::slot<bool, bool>);
188 protected:
189  virtual void toggled ();
190 };
191 
194 {
195 public:
196  FooOption (Gtk::Widget *w) : _w (w) {}
197 
199  add_widget_to_page (p, _w);
200  }
201 
202  Gtk::Widget& tip_widget() { return *_w; }
204  void parameter_changed (std::string const &) {}
205 private:
206  Gtk::Widget *_w;
207 };
208 
210 class EntryOption : public Option
211 {
212 public:
213 
214  EntryOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
215  void set_state_from_config ();
217  void set_sensitive (bool);
218  void set_invalid_chars (std::string i) { _invalid = i; }
219 
220  Gtk::Widget& tip_widget() { return *_entry; }
221 
222 private:
223 
224  void activated ();
225  bool focus_out (GdkEventFocus*);
226  void filter_text (const Glib::ustring&, int*);
227 
228  sigc::slot<std::string> _get;
229  sigc::slot<bool, std::string> _set;
230  Gtk::Label* _label;
231  Gtk::Entry* _entry;
232  std::string _invalid;
233 };
234 
235 
239 template <class T>
240 class ComboOption : public Option
241 {
242 public:
243 
251  std::string const & i,
252  std::string const & n,
253  sigc::slot<T> g,
254  sigc::slot<bool, T> s
255  )
256  : Option (i, n),
257  _get (g),
258  _set (s)
259  {
260  _label = Gtk::manage (new Gtk::Label (n + ":"));
261  _label->set_alignment (0, 0.5);
262  _combo = Gtk::manage (new Gtk::ComboBoxText);
263  _combo->signal_changed().connect (sigc::mem_fun (*this, &ComboOption::changed));
264  }
265 
267  uint32_t r = 0;
268  while (r < _options.size() && _get () != _options[r]) {
269  ++r;
270  }
271 
272  if (r < _options.size()) {
273  _combo->set_active (r);
274  }
275  }
276 
278  {
280  }
281 
286  void add (T e, std::string const & o) {
287  _options.push_back (e);
288  _combo->append_text (o);
289  }
290 
291  void clear () {
292  _combo->clear_items();
293  _options.clear ();
294  }
295 
296  void changed () {
297  uint32_t const r = _combo->get_active_row_number ();
298  if (r < _options.size()) {
299  _set (_options[r]);
300  }
301  }
302 
303  void set_sensitive (bool yn) {
304  _combo->set_sensitive (yn);
305  }
306 
307  Gtk::Widget& tip_widget() { return *_combo; }
308 
309 private:
310 
311  sigc::slot<T> _get;
312  sigc::slot<bool, T> _set;
313  Gtk::Label* _label;
314  Gtk::ComboBoxText* _combo;
315  std::vector<T> _options;
316 };
317 
318 
321 class HSliderOption : public Option
322 {
323 public:
324 
332  std::string const & i,
333  std::string const & n,
334  Gtk::Adjustment &adj
335  )
336  : Option (i, n)
337  {
338  _label = Gtk::manage (new Gtk::Label (n + ":"));
339  _label->set_alignment (0, 0.5);
340  _hscale = Gtk::manage (new Gtk::HScale(adj));
341  _adj = NULL;
342  }
343 
345  std::string const & i,
346  std::string const & n,
347  Gtk::Adjustment *adj,
348  sigc::slot<float> g,
349  sigc::slot<bool, float> s
350  )
351  : Option (i, n)
352  , _get (g)
353  , _set (s)
354  , _adj (adj)
355  {
356  _label = Gtk::manage (new Gtk::Label (n + ":"));
357  _label->set_alignment (0, 0.5);
358  _hscale = Gtk::manage (new Gtk::HScale(*_adj));
359  _adj->signal_value_changed().connect (sigc::mem_fun (*this, &HSliderOption::changed));
360  }
361 
363  if (_adj) _adj->set_value (_get());
364  }
365 
366  void changed () {
367  if (_adj) _set (_adj->get_value ());
368  }
369 
371  {
373  }
374 
375  void set_sensitive (bool yn) {
376  _hscale->set_sensitive (yn);
377  }
378 
379  Gtk::Widget& tip_widget() { return *_hscale; }
380  Gtk::HScale& scale() { return *_hscale; }
381 
382 private:
383  sigc::slot<float> _get;
384  sigc::slot<bool, float> _set;
385  Gtk::Label* _label;
386  Gtk::HScale* _hscale;
387  Gtk::Adjustment* _adj;
388 };
389 
393 class ComboStringOption : public Option
394 {
395 public:
396 
404  std::string const & i,
405  std::string const & n,
406  sigc::slot<std::string> g,
407  sigc::slot<bool, std::string> s
408  )
409  : Option (i, n),
410  _get (g),
411  _set (s)
412  {
413  _label = Gtk::manage (new Gtk::Label (n + ":"));
414  _label->set_alignment (0, 0.5);
415  _combo = Gtk::manage (new Gtk::ComboBoxText);
416  _combo->signal_changed().connect (sigc::mem_fun (*this, &ComboStringOption::changed));
417  }
418 
420  _combo->set_active_text (_get());
421  }
422 
424  {
426  }
427 
431  void set_popdown_strings (const std::vector<std::string>& strings) {
432  _combo->clear_items ();
433  for (std::vector<std::string>::const_iterator i = strings.begin(); i != strings.end(); ++i) {
434  _combo->append_text (*i);
435  }
436  }
437 
438  void clear () {
439  _combo->clear_items();
440  }
441 
442  void changed () {
443  _set (_combo->get_active_text ());
444  }
445 
446  void set_sensitive (bool yn) {
447  _combo->set_sensitive (yn);
448  }
449 
450  Gtk::Widget& tip_widget() { return *_combo; }
451 
452 private:
453  sigc::slot<std::string> _get;
454  sigc::slot<bool, std::string> _set;
455  Gtk::Label* _label;
456  Gtk::ComboBoxText* _combo;
457 };
458 
459 
463 class BoolComboOption : public Option
464 {
465 public:
466 
468  std::string const &,
469  std::string const &,
470  std::string const &,
471  std::string const &,
472  sigc::slot<bool>,
473  sigc::slot<bool, bool>
474  );
475 
476  void set_state_from_config ();
477  void add_to_page (OptionEditorPage *);
478  void changed ();
479  void set_sensitive (bool);
480 
481  Gtk::Widget& tip_widget() { return *_combo; }
482 
483 private:
484 
485  sigc::slot<bool> _get;
486  sigc::slot<bool, bool> _set;
487  Gtk::Label* _label;
488  Gtk::ComboBoxText* _combo;
489 };
490 
491 
492 
494 template <class T>
495 class SpinOption : public Option
496 {
497 public:
512  std::string const & i,
513  std::string const & n,
514  sigc::slot<T> g,
515  sigc::slot<bool, T> s,
516  T min,
517  T max,
518  T step,
519  T page,
520  std::string const & unit = "",
521  float scale = 1,
522  unsigned digits = 0
523  )
524  : Option (i, n),
525  _get (g),
526  _set (s),
527  _scale (scale)
528  {
529  _label = Gtk::manage (new Gtk::Label (n + ":"));
530  _label->set_alignment (0, 0.5);
531 
532  _spin = Gtk::manage (new Gtk::SpinButton);
533  _spin->set_range (min, max);
534  _spin->set_increments (step, page);
535  _spin->set_digits(digits);
536 
537  _box = Gtk::manage (new Gtk::HBox);
538  _box->pack_start (*_spin, true, true);
539  _box->set_spacing (4);
540  if (unit.length()) {
541  _box->pack_start (*Gtk::manage (new Gtk::Label (unit)), false, false);
542  }
543 
544  _spin->signal_value_changed().connect (sigc::mem_fun (*this, &SpinOption::changed));
545  }
546 
548  {
549  _spin->set_value (_get () / _scale);
550  }
551 
553  {
555  }
556 
557  void changed ()
558  {
559  _set (static_cast<T> (_spin->get_value ()) * _scale);
560  }
561 
562  Gtk::Widget& tip_widget() { return *_spin; }
563 
564 private:
565  sigc::slot<T> _get;
566  sigc::slot<bool, T> _set;
567  float _scale;
568  Gtk::Label* _label;
569  Gtk::HBox* _box;
570  Gtk::SpinButton* _spin;
571 };
572 
573 class FaderOption : public Option
574 {
575 public:
576 
577  FaderOption (std::string const &, std::string const &, sigc::slot<ARDOUR::gain_t> g, sigc::slot<bool, ARDOUR::gain_t> s);
578  void set_state_from_config ();
579  void add_to_page (OptionEditorPage *);
580 
581  Gtk::Widget& tip_widget() { return *_db_slider; }
582 
583 private:
584  void db_changed ();
585 
586  Gtk::Adjustment _db_adjustment;
588  Gtk::Entry _db_display;
589  Gtk::Label _label;
590  Gtk::HBox _box;
592  sigc::slot<ARDOUR::gain_t> _get;
593  sigc::slot<bool, ARDOUR::gain_t> _set;
594 };
595 
596 class ClockOption : public Option
597 {
598 public:
599  ClockOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
600  void set_state_from_config ();
601  void add_to_page (OptionEditorPage *);
602  void set_session (ARDOUR::Session *);
603 
604  Gtk::Widget& tip_widget() { return _clock; }
605  AudioClock& clock() { return _clock; }
606 
607 private:
608  void save_clock_time ();
609  Gtk::Label _label;
611  sigc::slot<std::string> _get;
612  sigc::slot<bool, std::string> _set;
614 };
615 
616 class DirectoryOption : public Option
617 {
618 public:
619  DirectoryOption (std::string const &, std::string const &, sigc::slot<std::string>, sigc::slot<bool, std::string>);
620 
621  void set_state_from_config ();
622  void add_to_page (OptionEditorPage *);
623 
624  Gtk::Widget& tip_widget() { return _file_chooser; }
625 
626 private:
627  void selection_changed ();
628 
629  sigc::slot<std::string> _get;
630  sigc::slot<bool, std::string> _set;
631  Gtk::FileChooserButton _file_chooser;
632 };
633 
639 {
640 public:
641  OptionEditorPage (Gtk::Notebook&, std::string const &);
642 
643  Gtk::VBox box;
644  Gtk::Table table;
645  std::list<OptionEditorComponent*> components;
646 };
647 
650 {
651 public:
652  OptionEditor (PBD::Configuration *, std::string const &);
653  ~OptionEditor ();
654 
655  void add_option (std::string const &, OptionEditorComponent *);
656  void add_page (std::string const &, Gtk::Widget& page_widget);
657 
658  void set_current_page (std::string const &);
659 
660 protected:
661 
662  virtual void parameter_changed (std::string const &);
663 
665 
666 private:
667 
669 
670  Gtk::Notebook _notebook;
671  std::map<std::string, OptionEditorPage*> _pages;
672 };
673 
674 #endif /* __gtk_ardour_option_editor_h__ */
675 
676 
void set_note(std::string const &)
void db_changed()
void save_clock_time()
std::list< OptionEditorComponent * > components
void filter_text(const Glib::ustring &, int *)
virtual void parameter_changed(std::string const &p)=0
void set_popdown_strings(const std::vector< std::string > &strings)
Gtk::Widget & tip_widget()
SpinOption(std::string const &i, std::string const &n, sigc::slot< T > g, sigc::slot< bool, T > s, T min, T max, T step, T page, std::string const &unit="", float scale=1, unsigned digits=0)
void selection_changed()
virtual void toggled()
void set_state_from_config()=0
Gtk::Widget & tip_widget()
void set_current_page(std::string const &)
void set_sensitive(bool yn)
void add_page(std::string const &, Gtk::Widget &page_widget)
void parameter_changed(std::string const &)
Definition: option_editor.h:91
void parameter_changed(std::string const &)=0
Gtk::Widget & tip_widget()
void parameter_changed(std::string const &)
OptionEditorPage(Gtk::Notebook &, std::string const &)
Gtkmm2ext::HSliderController * _db_slider
void changed()
Gtk::Label _label
ComboStringOption(std::string const &i, std::string const &n, sigc::slot< std::string > g, sigc::slot< bool, std::string > s)
Gtk::Label * _label
void set_state_from_config()
Gtk::Label _label
DirectoryOption(std::string const &, std::string const &, sigc::slot< std::string >, sigc::slot< bool, std::string >)
Gtk::CheckButton * _button
UI button.
ClockOption(std::string const &, std::string const &, sigc::slot< std::string >, sigc::slot< bool, std::string >)
Gtk::Widget & tip_widget()
Definition: option_editor.h:95
void set_state_from_config()
HSliderOption(std::string const &i, std::string const &n, Gtk::Adjustment *adj, sigc::slot< float > g, sigc::slot< bool, float > s)
std::map< std::string, OptionEditorPage * > _pages
std::vector< T > _options
ComboOption(std::string const &i, std::string const &n, sigc::slot< T > g, sigc::slot< bool, T > s)
FooOption(Gtk::Widget *w)
Gtk::VBox * _box
constituent box for subclasses to add widgets to
Gtk::VBox _fader_centering_box
sigc::slot< bool, std::string > _set
slot to set the configuration variable's value
void add_to_page(OptionEditorPage *p)
sigc::slot< std::string > _get
slot to get the configuration variable's value
sigc::slot< std::string > _get
sigc::slot< bool, T > _set
AudioClock _clock
void set_state_from_config()
void set_sensitive(bool yn)
Gtk::Widget & tip_widget()
virtual void parameter_changed(std::string const &)
Gtk::HBox * _box
void set_sensitive(bool)
sigc::slot< bool, std::string > _set
slot to set the configuration variable's value
void add_to_page(OptionEditorPage *)
Gtk::Widget & tip_widget()
Gtk::Table table
Gtk::Label * _label
virtual Gtk::Widget & tip_widget()=0
void set_state_from_config()
Gtk::FileChooserButton _file_chooser
sigc::slot< bool, T > _set
void changed()
ARDOUR::Session * _session
void add_to_page(OptionEditorPage *p)
Gtk::Widget & tip_widget()
Gtk::HScale & scale()
Gtk::Widget & tip_widget()
sigc::slot< float > _get
virtual void toggled()
PBD::ScopedConnection config_connection
void add_to_page(OptionEditorPage *p)
void maybe_add_note(OptionEditorPage *, int)
std::string _invalid
sigc::slot< ARDOUR::gain_t > _get
Gtk::HScale * _hscale
Gtk::Notebook _notebook
std::string id() const
Gtk::Label * _label
the label used for the heading
Definition: option_editor.h:98
void set_invalid_chars(std::string i)
Gtk::Widget & tip_widget()
void add_option(std::string const &, OptionEditorComponent *)
LIBPBD_API uint64_t Configuration
Definition: debug.cc:53
Gtk::Widget * _w
Gtk::Entry _db_display
Gtk::Widget & tip_widget()
void add_to_page(OptionEditorPage *p)
void activated()
void add_widget_to_page(OptionEditorPage *, Gtk::Widget *)
Gtk::Entry * _entry
UI entry.
void add(T e, std::string const &o)
void set_state_from_config()
virtual ~OptionEditorComponent()
Definition: option_editor.h:59
Gtk::Label * _label
sigc::slot< std::string > _get
void set_state_from_config()
BoolComboOption(std::string const &, std::string const &, std::string const &, std::string const &, sigc::slot< bool >, sigc::slot< bool, bool >)
sigc::slot< bool > _get
void set_state_from_config()
void set_session(ARDOUR::Session *)
void add_to_page(OptionEditorPage *)
sigc::slot< bool, bool > _set
void set_state_from_config()
void set_sensitive(bool)
Gtk::Widget & tip_widget()
Gtk::ComboBoxText * _combo
virtual void add_to_page(OptionEditorPage *)=0
sigc::slot< bool, std::string > _set
void set_state_from_config()
BoolOption(std::string const &, std::string const &, sigc::slot< bool >, sigc::slot< bool, bool >)
void add_widgets_to_page(OptionEditorPage *, Gtk::Widget *, Gtk::Widget *)
RouteDisplayBoolOption(std::string const &, std::string const &, sigc::slot< bool >, sigc::slot< bool, bool >)
void set_sensitive(bool yn)
virtual void set_state_from_config()=0
void set_state_from_config()
virtual void add_to_page(OptionEditorPage *)=0
sigc::slot< bool, std::string > _set
void parameter_changed(std::string const &p)
Gtk::Label * _label
label for button, so we can use markup
EntryOption(std::string const &, std::string const &, sigc::slot< std::string >, sigc::slot< bool, std::string >)
void add_to_page(OptionEditorPage *)
Gtk::Adjustment _db_adjustment
Definition: debug.h:30
Gtk::Adjustment * _adj
void set_state_from_config()
AudioClock & clock()
void add_to_page(OptionEditorPage *p)
FaderOption(std::string const &, std::string const &, sigc::slot< ARDOUR::gain_t > g, sigc::slot< bool, ARDOUR::gain_t > s)
Gtk::ComboBoxText * _combo
sigc::slot< bool, ARDOUR::gain_t > _set
std::string _name
Gtk::Widget & tip_widget()
Gtk::ComboBoxText * _combo
sigc::slot< std::string > _get
slot to get the configuration variable's value
virtual void set_state_from_config()=0
std::string _id
void set_state_from_config()
Definition: option_editor.h:92
Gtk::Widget & tip_widget()
OptionEditor(PBD::Configuration *, std::string const &)
Gtk::Label * _label
UI label.
sigc::slot< T > _get
Gtk::Label * _label
OptionEditorHeading(std::string const &)
sigc::slot< T > _get
void add_to_page(OptionEditorPage *)
void set_sensitive(bool yn)
void add_to_page(OptionEditorPage *)
Gtk::HBox _box
void add_to_page(OptionEditorPage *)
void add_to_page(OptionEditorPage *)
bool focus_out(GdkEventFocus *)
sigc::slot< bool, bool > _set
slot to set the configuration variable's value
Option(std::string const &i, std::string const &n)
PBD::Configuration * _config
Gtk::SpinButton * _spin
sigc::slot< bool > _get
slot to get the configuration variable's value
sigc::slot< bool, float > _set
HSliderOption(std::string const &i, std::string const &n, Gtk::Adjustment &adj)
void add_to_page(OptionEditorPage *)
Gtk::Label * _label