Guitarix
gx_main_interface.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, 2010 Hermann Meyer, James Warden, Andreas Degert
3  * Copyright (C) 2011 Pete Shorthose
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  * --------------------------------------------------------------------------
19  *
20  * This file is part of the guitarix GUI main class
21  * Note: this header file is the base for gx_main_boxes.h
22  *
23  * ----------------------------------------------------------------------------
24  */
25 
26 /* ------- This is the GUI namespace ------- */
27 
28 #pragma once
29 
30 #ifndef SRC_HEADERS_GX_MAIN_INTERFACE_H_
31 #define SRC_HEADERS_GX_MAIN_INTERFACE_H_
32 
33 #include <gxwmm/bigknob.h>
34 #include <gxwmm/midknob.h>
35 #include <gxwmm/smallknob.h>
36 #include <gxwmm/smallknobr.h>
37 #include <gxwmm/wheel.h>
38 #include <gxwmm/hslider.h>
39 #include <gxwmm/eqslider.h>
40 #include <gxwmm/levelslider.h>
41 #include <gxwmm/minislider.h>
42 #include <gxwmm/switch.h>
43 #include <gxwmm/selector.h>
44 #include <gxwmm/valuedisplay.h>
45 #include <gxwmm/simplevaluedisplay.h>
46 #include <gxwmm/fastmeter.h>
47 #include <gxwmm/tuner.h>
48 #include <gxwmm/racktuner.h>
49 #include <gxwmm/waveview.h>
50 #include <gxwmm/portdisplay.h>
51 #include <gxwmm/playhead.h>
52 #include <gtkmm/box.h>
53 #include <gtkmm/alignment.h>
54 #include <gtkmm/checkmenuitem.h>
55 #include <gtkmm/radiomenuitem.h>
56 #include <gtkmm/builder.h>
57 
58 #include <iostream>
59 #include <map>
60 #include <string>
61 #include <vector>
62 
63 namespace gx_gui {
64 
65 /****************************************************************
66  **
67  */
68 
69 class CpBase {
70 public:
72  std::string id;
74  bool blocked;
76  void set_cp_value(float v, Gxw::ControlParameter& c);
77 public:
78  CpBase(gx_engine::GxMachineBase& machine, const std::string& id);
79  ~CpBase();
80  void init(Gxw::Regler& regler, bool show_value);
81 };
82 
83 class CpBaseCaption: public Gtk::VBox {
84 protected:
86  Gtk::Label m_label;
87 public:
88  CpBaseCaption(gx_engine::GxMachineBase& machine, const std::string& id);
90  void init(Gxw::Regler& regler, bool show_value);
91  void set_effect_label(const char *label);
92  void set_rack_label(const char *label);
93  void set_rack_label_inverse(const char *label);
94 };
95 
96 class CpMasterCaption: public Gtk::HBox {
97 protected:
99  Gtk::Label m_label;
100 public:
101  CpMasterCaption(gx_engine::GxMachineBase& machine, const std::string& id);
103  void init(Gxw::Regler& regler);
104  void set_label(const char *label);
105 };
106 
107 class CpBaseCaptionBoxed: public Gtk::VBox {
108 protected:
110  Gtk::HBox h_box;
111  Gtk::Label m_label;
112 public:
113  CpBaseCaptionBoxed(gx_engine::GxMachineBase& machine, const std::string& id);
115  void init(Gxw::Regler& regler, bool show_value);
116  void set_rack_label(const char *label);
117  void set_rack_label_inverse(const char *label);
118 };
119 
120 template <class T>
121 class UiRegler: public T {
122 protected:
123  CpBase base;
124 public:
125  UiRegler(gx_engine::GxMachineBase& machine, const std::string& id, bool show_value = true)
126  : T(), base(machine, id) { base.init(*this, show_value); }
127 };
128 
129 template <class T>
130 class UiReglerWithCaption: public CpBaseCaption {
131 protected:
132  T regler;
133 public:
134  UiReglerWithCaption(gx_engine::GxMachineBase& machine, const std::string& id)
135  : CpBaseCaption(machine, id), regler() { init(regler, true); }
136  void set_label(const Glib::ustring& label);
137  T *get_regler() { return &regler; }
138 };
139 
140 template <class T>
142 protected:
143  T regler;
144 public:
145  UiMasterReglerWithCaption(gx_engine::GxMachineBase& machine, const std::string& id)
146  : CpMasterCaption(machine, id), regler() { init(regler); }
147  T *get_regler() { return &regler; }
148 };
149 
150 template<class T>
152 protected:
153  T regler;
154 public:
155  UiDisplayWithCaption(gx_engine::GxMachineBase& machine, const std::string& id)
156  : CpBaseCaptionBoxed(machine, id), regler() { init(regler, true); }
157  T *get_regler() { return &regler; }
158 };
159 
160 
161 /****************************************************************/
162 
163 class CpSelectorBase {
164 public:
166  const std::string id;
167 public:
168  CpSelectorBase(Gxw::Selector& selector, gx_engine::GxMachineBase& machine, const std::string& id);
169 };
170 
171 template <class T>
172 class UiSelector: public Gxw::Selector {
173 private:
174  CpSelectorBase base;
175  void set_selector_value(T v);
176  void on_value_changed();
177 public:
178  UiSelector(gx_engine::GxMachineBase& machine, const std::string& id);
180  void set_name(const Glib::ustring& n) { set_name(n); }
181 };
182 
183 template <class T>
185 }
186 
187 template <class T>
188 class UiSelectorWithCaption: public Gtk::VBox {
189 private:
190  UiSelector<T> m_selector;
191  Gtk::Label m_label;
192 public:
193  UiSelectorWithCaption(gx_engine::GxMachineBase& machine, const std::string& id, const char *label);
195  void set_name(const Glib::ustring& n) { m_selector.set_name(n); }
196  void set_rack_label_inverse() {m_label.set_name("rack_label_inverse"); }
197 };
198 
199 template <class T>
200 UiSelectorWithCaption<T>::UiSelectorWithCaption(gx_engine::GxMachineBase& machine, const std::string& id, const char *label)
201  : Gtk::VBox(), m_selector(machine, id), m_label() {
202  if (label) {
203  m_label.set_text(label);
204  } else {
205  m_label.set_text(machine.get_parameter(id).l_name());
206  }
207  m_label.set_name("rack_label");
208  m_label.set_justify(Gtk::JUSTIFY_CENTER);
209  Gtk::VBox::set_name(id);
210  pack_start(m_label, Gtk::PACK_SHRINK);
211  pack_start(m_selector, Gtk::PACK_EXPAND_PADDING);
212  set_accessible(m_selector, m_label);
213  show_all();
214 }
215 
216 template <class T>
218 }
219 
220 /****************************************************************/
221 
222 struct uiAdjustment: public uiElement {
224  const std::string id;
225  Gtk::Adjustment* fAdj;
226  bool blocked;
227  uiAdjustment(gx_engine::GxMachineBase& machine_, const std::string& id_, Gtk::Adjustment* adj)
228  : uiElement(), machine(machine_), id(id_), fAdj(adj), blocked(false) {
229  fAdj->set_value(machine.get_parameter_value<float>(id));
230  machine.signal_parameter_value<float>(id).connect(sigc::mem_fun(this, &uiAdjustment::on_parameter_changed));
231  }
232  void changed() {
233  if (!blocked) {
234  machine.set_parameter_value(id, fAdj->get_value());
235  }
236  }
237  void on_parameter_changed(float v) {
238  blocked = true;
239  fAdj->set_value(v);
240  blocked = false;
241  }
242 };
243 
244 /****************************************************************/
245 
246 extern const char *pb_gx_rack_amp_expose;
247 extern const char *pb_rectangle_skin_color_expose;
248 extern const char *pb_zac_expose;
249 extern const char *pb_gxhead_expose;
250 extern const char *pb_RackBox_expose;
251 extern const char *pb_gxrack_expose;
252 extern const char *pb_level_meter_expose;
253 
254 bool button_press_cb(GdkEventButton *event, gx_engine::GxMachineBase& machine, const std::string& id);
255 int precision(double n);
256 std::string fformat(float value, float step);
257 
258 /****************************************************************/
259 
260 #ifndef NDEBUG
261 // debug_check
262 inline void check_id(Gtk::Widget *w, const std::string& id, gx_engine::GxMachineBase& machine) {
263  if (!machine.parameter_hasId(id)) {
264  Glib::ustring pt, ptr;
265  w->path(pt, ptr);
266  cerr << "id '" << id << "' not found in definition of widget: "
267  << pt << endl;
268  assert(false);
269  }
270  //gx_engine::parameter_map[zone].setUsed();
271 }
272 #endif
273 
274 /****************************************************************/
275 
276 inline void connect_midi_controller(Gtk::Widget *w, const std::string& id, gx_engine::GxMachineBase& machine) {
277  debug_check(check_id, w, id, machine);
278  w->signal_button_press_event().connect(
279  sigc::bind(sigc::ptr_fun(button_press_cb), sigc::ref(machine), id), false);
280 }
281 
282 /****************************************************************/
283 
284 /* -------------------------------------------------------------------------- */
285 } /* end of gx_gui namespace */
286 
287 #endif // SRC_HEADERS_GX_MAIN_INTERFACE_H_
288 
gx_gui::uiAdjustment::on_parameter_changed
void on_parameter_changed(float v)
Definition: gx_main_interface.h:236
gx_engine::Parameter::l_name
string l_name() const
Definition: gx_parameter.h:175
gx_engine::GxMachineBase::parameter_hasId
virtual bool parameter_hasId(const char *p)=0
gx_gui::set_accessible
void set_accessible(Gtk::Widget &widget, Gtk::Label &label)
Definition: gxw_mm_controllers.cpp:36
gx_gui::UiMasterReglerWithCaption::UiMasterReglerWithCaption
UiMasterReglerWithCaption(gx_engine::GxMachineBase &machine, const std::string &id)
Definition: gx_main_interface.h:144
gx_gui::uiElement
Definition: gx_ui_builder.h:33
gx_engine::GxMachineBase::get_parameter_value
T get_parameter_value(const std::string &id)
gx_gui::UiSelectorWithCaption::UiSelectorWithCaption
UiSelectorWithCaption(gx_engine::GxMachineBase &machine, const std::string &id, const char *label)
Definition: gx_main_interface.h:199
gx_gui::UiSelectorWithCaption::~UiSelectorWithCaption
~UiSelectorWithCaption()
Definition: gx_main_interface.h:216
gx_gui::CpBaseCaption::~CpBaseCaption
~CpBaseCaption()
Definition: gxw_mm_controllers.cpp:151
gx_gui::UiSelector::UiSelector
UiSelector(gx_engine::GxMachineBase &machine, const std::string &id)
gx_engine::GxMachineBase
Definition: machine.h:53
gx_gui::CpSelectorBase::CpSelectorBase
CpSelectorBase(Gxw::Selector &selector, gx_engine::GxMachineBase &machine, const std::string &id)
Definition: gxw_mm_controllers.cpp:259
gx_gui::UiReglerWithCaption::regler
T regler
Definition: gx_main_interface.h:131
gx_gui::CpBaseCaption::init
void init(Gxw::Regler &regler, bool show_value)
Definition: gxw_mm_controllers.cpp:154
gx_gui::UiReglerWithCaption
Definition: gx_main_interface.h:129
gx_gui::CpBaseCaption::base
CpBase base
Definition: gx_main_interface.h:84
gx_gui::precision
int precision(double n)
Definition: gx_stackbox_builder.cpp:20
gx_gui::CpBaseCaption::set_rack_label_inverse
void set_rack_label_inverse(const char *label)
Definition: gxw_mm_controllers.cpp:179
gx_gui::UiDisplayWithCaption
Definition: gx_main_interface.h:150
gx_gui::CpMasterCaption::~CpMasterCaption
~CpMasterCaption()
Definition: gxw_mm_controllers.cpp:194
gx_gui::CpMasterCaption::base
CpBase base
Definition: gx_main_interface.h:97
gx_gui::CpMasterCaption::init
void init(Gxw::Regler &regler)
Definition: gxw_mm_controllers.cpp:197
gx_engine::GxMachineBase::signal_parameter_value
sigc::signal< void, T > & signal_parameter_value(const std::string &id)
gx_gui::CpBaseCaptionBoxed::m_label
Gtk::Label m_label
Definition: gx_main_interface.h:110
gx_gui::UiDisplayWithCaption::get_regler
T * get_regler()
Definition: gx_main_interface.h:156
gx_gui::pb_gxhead_expose
const char * pb_gxhead_expose
Definition: gx_stackbox_builder.cpp:14
gx_gui::UiSelectorWithCaption
Definition: gx_main_interface.h:187
gx_gui::CpSelectorBase::id
const std::string id
Definition: gx_main_interface.h:165
gx_gui::UiReglerWithCaption::get_regler
T * get_regler()
Definition: gx_main_interface.h:136
gx_gui::UiSelectorWithCaption::set_name
void set_name(const Glib::ustring &n)
Definition: gx_main_interface.h:194
gx_gui::CpBaseCaptionBoxed::base
CpBase base
Definition: gx_main_interface.h:108
gx_gui::CpBase::id
std::string id
Definition: gx_main_interface.h:72
gx_engine::GxMachineBase::set_parameter_value
virtual void set_parameter_value(const std::string &id, int value)=0
gx_gui::UiMasterReglerWithCaption::regler
T regler
Definition: gx_main_interface.h:142
gx_gui::uiAdjustment::fAdj
Gtk::Adjustment * fAdj
Definition: gx_main_interface.h:224
gx_gui::CpSelectorBase
Definition: gx_main_interface.h:162
gx_gui::UiMasterReglerWithCaption::get_regler
T * get_regler()
Definition: gx_main_interface.h:146
Gxw::ControlParameter
Definition: controlparameter.h:48
gx_gui::CpBaseCaptionBoxed::set_rack_label
void set_rack_label(const char *label)
Definition: gxw_mm_controllers.cpp:241
gx_gui::uiAdjustment::machine
gx_engine::GxMachineBase & machine
Definition: gx_main_interface.h:222
gx_gui::CpBase::init
void init(Gxw::Regler &regler, bool show_value)
Definition: gxw_mm_controllers.cpp:90
gx_gui::CpMasterCaption::set_label
void set_label(const char *label)
Definition: gxw_mm_controllers.cpp:211
gx_gui::CpMasterCaption::CpMasterCaption
CpMasterCaption(gx_engine::GxMachineBase &machine, const std::string &id)
Definition: gxw_mm_controllers.cpp:187
gx_gui::UiDisplayWithCaption::regler
T regler
Definition: gx_main_interface.h:152
gx_gui::UiRegler::base
CpBase base
Definition: gx_main_interface.h:122
gx_gui::uiAdjustment::uiAdjustment
uiAdjustment(gx_engine::GxMachineBase &machine_, const std::string &id_, Gtk::Adjustment *adj)
Definition: gx_main_interface.h:226
gx_gui::pb_gx_rack_amp_expose
const char * pb_gx_rack_amp_expose
Definition: gx_stackbox_builder.cpp:11
gx_gui::UiDisplayWithCaption::UiDisplayWithCaption
UiDisplayWithCaption(gx_engine::GxMachineBase &machine, const std::string &id)
Definition: gx_main_interface.h:154
debug_check
#define debug_check(func,...)
Definition: gx_parameter.h:36
gx_gui::pb_rectangle_skin_color_expose
const char * pb_rectangle_skin_color_expose
Definition: gx_stackbox_builder.cpp:12
gx_gui::CpMasterCaption
Definition: gx_main_interface.h:95
gx_gui::CpBaseCaptionBoxed
Definition: gx_main_interface.h:106
gx_gui::CpBaseCaption
Definition: gx_main_interface.h:82
Gxw::Selector
Definition: selector.h:43
gx_gui::UiMasterReglerWithCaption
Definition: gx_main_interface.h:140
gx_gui::CpBaseCaption::m_label
Gtk::Label m_label
Definition: gx_main_interface.h:85
gx_gui::uiAdjustment::changed
void changed()
Definition: gx_main_interface.h:231
gx_gui::UiSelectorWithCaption::set_rack_label_inverse
void set_rack_label_inverse()
Definition: gx_main_interface.h:195
gx_gui::CpBase::CpBase
CpBase(gx_engine::GxMachineBase &machine, const std::string &id)
Definition: gxw_mm_controllers.cpp:83
gx_engine::GxMachineBase::get_parameter
virtual Parameter & get_parameter(const std::string &id)=0
gx_gui::UiSelector
Definition: gx_main_interface.h:171
gx_gui::CpBase::set_cp_value
void set_cp_value(float v, Gxw::ControlParameter &c)
Definition: gxw_mm_controllers.cpp:73
gx_gui::CpBaseCaption::set_effect_label
void set_effect_label(const char *label)
Definition: gxw_mm_controllers.cpp:164
gx_gui::CpBaseCaptionBoxed::init
void init(Gxw::Regler &regler, bool show_value)
Definition: gxw_mm_controllers.cpp:229
gx_gui::uiAdjustment::id
const std::string id
Definition: gx_main_interface.h:223
gx_gui::pb_gxrack_expose
const char * pb_gxrack_expose
Definition: gx_stackbox_builder.cpp:16
gx_gui::CpBaseCaptionBoxed::CpBaseCaptionBoxed
CpBaseCaptionBoxed(gx_engine::GxMachineBase &machine, const std::string &id)
Definition: gxw_mm_controllers.cpp:218
gx_gui::CpBase
Definition: gx_main_interface.h:68
gx_gui::CpBase::~CpBase
~CpBase()
Definition: gxw_mm_controllers.cpp:141
gx_gui::fformat
std::string fformat(float value, float step)
Definition: gx_stackbox_builder.cpp:31
gx_gui::UiSelector::set_name
void set_name(const Glib::ustring &n)
Definition: gx_main_interface.h:179
gx_gui::CpMasterCaption::m_label
Gtk::Label m_label
Definition: gx_main_interface.h:98
gx_gui::UiSelector::~UiSelector
~UiSelector()
Definition: gx_main_interface.h:183
gx_gui::UiReglerWithCaption::UiReglerWithCaption
UiReglerWithCaption(gx_engine::GxMachineBase &machine, const std::string &id)
Definition: gx_main_interface.h:133
gx_gui
Definition: gx_gui_helpers.h:28
gx_gui::UiReglerWithCaption::set_label
void set_label(const Glib::ustring &label)
gx_gui::UiRegler::UiRegler
UiRegler(gx_engine::GxMachineBase &machine, const std::string &id, bool show_value=true)
Definition: gx_main_interface.h:124
gx_gui::CpBase::log_display
bool log_display
Definition: gx_main_interface.h:73
gx_gui::CpBase::on_cp_value_changed
void on_cp_value_changed(Gxw::ControlParameter &c)
Definition: gxw_mm_controllers.cpp:62
gx_gui::pb_RackBox_expose
const char * pb_RackBox_expose
Definition: gx_stackbox_builder.cpp:15
gx_gui::pb_level_meter_expose
const char * pb_level_meter_expose
Definition: gx_stackbox_builder.cpp:17
gx_gui::uiAdjustment
Definition: gx_main_interface.h:221
gx_gui::CpSelectorBase::machine
gx_engine::GxMachineBase & machine
Definition: gx_main_interface.h:164
gx_gui::CpBaseCaption::set_rack_label
void set_rack_label(const char *label)
Definition: gxw_mm_controllers.cpp:171
gx_gui::uiAdjustment::blocked
bool blocked
Definition: gx_main_interface.h:225
Gxw::Regler
Definition: regler.h:45
gx_gui::connect_midi_controller
void connect_midi_controller(Gtk::Widget *w, const std::string &id, gx_engine::GxMachineBase &machine)
Definition: gx_main_interface.h:275
gx_gui::CpBaseCaptionBoxed::h_box
Gtk::HBox h_box
Definition: gx_main_interface.h:109
gx_gui::CpBaseCaptionBoxed::set_rack_label_inverse
void set_rack_label_inverse(const char *label)
Definition: gxw_mm_controllers.cpp:248
gx_gui::CpBase::machine
gx_engine::GxMachineBase & machine
Definition: gx_main_interface.h:71
gx_gui::check_id
void check_id(Gtk::Widget *w, const std::string &id, gx_engine::GxMachineBase &machine)
Definition: gx_main_interface.h:261
gx_gui::UiRegler
Definition: gx_main_interface.h:120
gx_gui::pb_zac_expose
const char * pb_zac_expose
Definition: gx_stackbox_builder.cpp:13
gx_gui::CpBaseCaption::CpBaseCaption
CpBaseCaption(gx_engine::GxMachineBase &machine, const std::string &id)
Definition: gxw_mm_controllers.cpp:144
gx_gui::CpBase::blocked
bool blocked
Definition: gx_main_interface.h:74
gx_gui::button_press_cb
bool button_press_cb(GdkEventButton *event, gx_engine::GxMachineBase &machine, const std::string &id)
Definition: gx_stackbox_builder.cpp:37
gx_gui::CpBaseCaptionBoxed::~CpBaseCaptionBoxed
~CpBaseCaptionBoxed()
Definition: gxw_mm_controllers.cpp:226