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);
89  ~CpBaseCaption();
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);
102  ~CpMasterCaption();
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:
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>
131 protected:
133 public:
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:
144 public:
146  : CpMasterCaption(machine, id), regler() { init(regler); }
147  T *get_regler() { return &regler; }
148 };
149 
150 template<class T>
152 protected:
154 public:
156  : CpBaseCaptionBoxed(machine, id), regler() { init(regler, true); }
157  T *get_regler() { return &regler; }
158 };
159 
160 
161 /****************************************************************/
162 
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);
179  ~UiSelector();
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>
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 
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)
string l_name() const
Definition: gx_parameter.h:177
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)
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)