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 <gtkmm/box.h>
52 #include <gtkmm/alignment.h>
53 #include <gtkmm/checkmenuitem.h>
54 #include <gtkmm/radiomenuitem.h>
55 #include <gtkmm/builder.h>
56 
57 #include <iostream>
58 #include <map>
59 #include <string>
60 #include <vector>
61 
62 namespace gx_gui {
63 
64 /****************************************************************
65  **
66  */
67 
68 class CpBase {
69 public:
71  std::string id;
73  bool blocked;
75  void set_cp_value(float v, Gxw::ControlParameter& c);
76 public:
77  CpBase(gx_engine::GxMachineBase& machine, const std::string& id);
78  ~CpBase();
79  void init(Gxw::Regler& regler, bool show_value);
80 };
81 
82 class CpBaseCaption: public Gtk::VBox {
83 protected:
85  Gtk::Label m_label;
86 public:
87  CpBaseCaption(gx_engine::GxMachineBase& machine, const std::string& id);
88  ~CpBaseCaption();
89  void init(Gxw::Regler& regler, bool show_value);
90  void set_effect_label(const char *label);
91  void set_rack_label(const char *label);
92  void set_rack_label_inverse(const char *label);
93 };
94 
95 class CpMasterCaption: public Gtk::HBox {
96 protected:
98  Gtk::Label m_label;
99 public:
100  CpMasterCaption(gx_engine::GxMachineBase& machine, const std::string& id);
101  ~CpMasterCaption();
102  void init(Gxw::Regler& regler);
103  void set_label(const char *label);
104 };
105 
106 class CpBaseCaptionBoxed: public Gtk::VBox {
107 protected:
109  Gtk::HBox h_box;
110  Gtk::Label m_label;
111 public:
112  CpBaseCaptionBoxed(gx_engine::GxMachineBase& machine, const std::string& id);
114  void init(Gxw::Regler& regler, bool show_value);
115  void set_rack_label(const char *label);
116  void set_rack_label_inverse(const char *label);
117 };
118 
119 template <class T>
120 class UiRegler: public T {
121 protected:
123 public:
124  UiRegler(gx_engine::GxMachineBase& machine, const std::string& id, bool show_value = true)
125  : T(), base(machine, id) { base.init(*this, show_value); }
126 };
127 
128 template <class T>
130 protected:
132 public:
134  : CpBaseCaption(machine, id), regler() { init(regler, true); }
135  void set_label(const Glib::ustring& label);
136  T *get_regler() { return &regler; }
137 };
138 
139 template <class T>
141 protected:
143 public:
145  : CpMasterCaption(machine, id), regler() { init(regler); }
146  T *get_regler() { return &regler; }
147 };
148 
149 template<class T>
151 protected:
153 public:
155  : CpBaseCaptionBoxed(machine, id), regler() { init(regler, true); }
156  T *get_regler() { return &regler; }
157 };
158 
159 
160 /****************************************************************/
161 
163 public:
165  const std::string id;
166 public:
167  CpSelectorBase(Gxw::Selector& selector, gx_engine::GxMachineBase& machine, const std::string& id);
168 };
169 
170 template <class T>
171 class UiSelector: public Gxw::Selector {
172 private:
173  CpSelectorBase base;
174  void set_selector_value(T v);
175  void on_value_changed();
176 public:
177  UiSelector(gx_engine::GxMachineBase& machine, const std::string& id);
178  ~UiSelector();
179  void set_name(const Glib::ustring& n) { set_name(n); }
180 };
181 
182 template <class T>
184 }
185 
186 template <class T>
187 class UiSelectorWithCaption: public Gtk::VBox {
188 private:
189  UiSelector<T> m_selector;
190  Gtk::Label m_label;
191 public:
192  UiSelectorWithCaption(gx_engine::GxMachineBase& machine, const std::string& id, const char *label);
194  void set_name(const Glib::ustring& n) { m_selector.set_name(n); }
195  void set_rack_label_inverse() {m_label.set_name("rack_label_inverse"); }
196 };
197 
198 template <class T>
200  : Gtk::VBox(), m_selector(machine, id), m_label() {
201  if (label) {
202  m_label.set_text(label);
203  } else {
204  m_label.set_text(machine.get_parameter(id).l_name());
205  }
206  m_label.set_name("rack_label");
207  m_label.set_justify(Gtk::JUSTIFY_CENTER);
208  Gtk::VBox::set_name(id);
209  pack_start(m_label, Gtk::PACK_SHRINK);
210  pack_start(m_selector, Gtk::PACK_EXPAND_PADDING);
211  set_accessible(m_selector, m_label);
212  show_all();
213 }
214 
215 template <class T>
217 }
218 
219 /****************************************************************/
220 
221 struct uiAdjustment: public uiElement {
223  const std::string id;
224  Gtk::Adjustment* fAdj;
225  bool blocked;
226  uiAdjustment(gx_engine::GxMachineBase& machine_, const std::string& id_, Gtk::Adjustment* adj)
227  : uiElement(), machine(machine_), id(id_), fAdj(adj), blocked(false) {
228  fAdj->set_value(machine.get_parameter_value<float>(id));
229  machine.signal_parameter_value<float>(id).connect(sigc::mem_fun(this, &uiAdjustment::on_parameter_changed));
230  }
231  void changed() {
232  if (!blocked) {
233  machine.set_parameter_value(id, fAdj->get_value());
234  }
235  }
236  void on_parameter_changed(float v) {
237  blocked = true;
238  fAdj->set_value(v);
239  blocked = false;
240  }
241 };
242 
243 /****************************************************************/
244 
245 extern const char *pb_gx_rack_amp_expose;
246 extern const char *pb_rectangle_skin_color_expose;
247 extern const char *pb_zac_expose;
248 extern const char *pb_gxhead_expose;
249 extern const char *pb_RackBox_expose;
250 extern const char *pb_gxrack_expose;
251 extern const char *pb_level_meter_expose;
252 
253 bool button_press_cb(GdkEventButton *event, gx_engine::GxMachineBase& machine, const std::string& id);
254 int precision(double n);
255 std::string fformat(float value, float step);
256 
257 /****************************************************************/
258 
259 #ifndef NDEBUG
260 // debug_check
261 inline void check_id(Gtk::Widget *w, const std::string& id, gx_engine::GxMachineBase& machine) {
262  if (!machine.parameter_hasId(id)) {
263  Glib::ustring pt, ptr;
264  w->path(pt, ptr);
265  cerr << "id '" << id << "' not found in definition of widget: "
266  << pt << endl;
267  assert(false);
268  }
269  //gx_engine::parameter_map[zone].setUsed();
270 }
271 #endif
272 
273 /****************************************************************/
274 
275 inline void connect_midi_controller(Gtk::Widget *w, const std::string& id, gx_engine::GxMachineBase& machine) {
276  debug_check(check_id, w, id, machine);
277  w->signal_button_press_event().connect(
278  sigc::bind(sigc::ptr_fun(button_press_cb), sigc::ref(machine), id), false);
279 }
280 
281 /****************************************************************/
282 
283 /* -------------------------------------------------------------------------- */
284 } /* end of gx_gui namespace */
285 
286 #endif // SRC_HEADERS_GX_MAIN_INTERFACE_H_
287 
void check_id(Gtk::Widget *w, const std::string &id, gx_engine::GxMachineBase &machine)
const char * pb_gxhead_expose
const char * pb_zac_expose
virtual Parameter & get_parameter(const std::string &id)=0
void set_accessible(Gtk::Widget &widget, Gtk::Label &label)
gx_engine::GxMachineBase & machine
UiMasterReglerWithCaption(gx_engine::GxMachineBase &machine, const std::string &id)
uiAdjustment(gx_engine::GxMachineBase &machine_, const std::string &id_, Gtk::Adjustment *adj)
const char * pb_gx_rack_amp_expose
int precision(double n)
UiRegler(gx_engine::GxMachineBase &machine, const std::string &id, bool show_value=true)
#define debug_check(func,...)
Definition: gx_parameter.h:36
UiDisplayWithCaption(gx_engine::GxMachineBase &machine, const std::string &id)
UiSelectorWithCaption(gx_engine::GxMachineBase &machine, const std::string &id, const char *label)
T get_parameter_value(const std::string &id)
const char * pb_RackBox_expose
Gtk::Adjustment * fAdj
void set_name(const Glib::ustring &n)
virtual bool parameter_hasId(const char *p)=0
virtual void set_parameter_value(const std::string &id, int value)=0
const char * pb_level_meter_expose
void connect_midi_controller(Gtk::Widget *w, const std::string &id, gx_engine::GxMachineBase &machine)
string l_name() const
Definition: gx_parameter.h:175
void set_cp_value(float v, Gxw::ControlParameter &c)
UiReglerWithCaption(gx_engine::GxMachineBase &machine, const std::string &id)
bool button_press_cb(GdkEventButton *event, gx_engine::GxMachineBase &machine, const std::string &id)
void on_cp_value_changed(Gxw::ControlParameter &c)
const char * pb_rectangle_skin_color_expose
gx_engine::GxMachineBase & machine
const std::string id
void set_name(const Glib::ustring &n)
const char * pb_gxrack_expose
sigc::signal< void, T > & signal_parameter_value(const std::string &id)
std::string fformat(float value, float step)
void init(Gxw::Regler &regler, bool show_value)
gx_engine::GxMachineBase & machine
CpBase(gx_engine::GxMachineBase &machine, const std::string &id)
void on_parameter_changed(float v)