Guitarix
gxw_mm_controllers.cpp
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 gx_head GUI main class
21  *
22  * ----------------------------------------------------------------------------
23  */
24 
25 #include <glibmm/i18n.h>
26 #include <atkmm/relationset.h>
27 #include <string>
28 
29 #include "guitarix.h"
30 #include <gtkmm/menu.h>
31 
32 namespace gx_gui
33 {
34 // -------------------------- gxwmm library controlers -----------------------------------
35 
36 void set_accessible(Gtk::Widget& widget,Gtk::Label& label) {
37  Glib::RefPtr<Atk::Object> atk_widget, atk_label;
38  Glib::RefPtr<Atk::RelationSet> relation_set;
39  Glib::RefPtr<Atk::Relation> relation;
40  std::vector<Glib::RefPtr<Atk::Object> > targets(1);
41 
42  atk_widget = widget.get_accessible();
43  atk_label = label.get_accessible();
44 
45  relation_set = atk_label->get_relation_set();
46  targets[0] = atk_widget;
47 
48  relation = Atk::Relation::create(targets, Atk::RELATION_LABEL_FOR);
49  relation_set->set_add(relation);
50 
51  relation_set = atk_widget->get_relation_set();
52  targets[0] = atk_label;
53 
54  relation = Atk::Relation::create(targets, Atk::RELATION_LABELLED_BY);
55  relation_set->set_add(relation);
56 }
57 
58 
59 /****************************************************************
60  ** class CpBaseXX
61  */
62 
64  if (blocked) {
65  return;
66  }
67  if (log_display) {
68  machine.set_parameter_value(id, pow(10.0,c.cp_get_value()));
69  } else {
71  }
72 }
73 
75  blocked = true;
76  if (log_display) {
77  c.cp_set_value(log10(v));
78  } else {
79  c.cp_set_value(v);
80  }
81  blocked = false;
82 }
83 
84 CpBase::CpBase(gx_engine::GxMachineBase& machine_, const std::string& id_)
85  : machine(machine_),
86  id(id_),
87  log_display(),
88  blocked(false) {
89 }
90 
91 void CpBase::init(Gxw::Regler& regler, bool show_value) {
92  regler.set_show_value(show_value);
93  regler.set_name("regler");
94  regler.cp_set_var(id);
95  if (!machine.parameter_hasId(id)) {
96  printf("not found: %s\n", id.c_str());
97  regler.set_sensitive(false);
98  return;
99  }
101  log_display = param.is_log_display();
102  if (log_display) {
103  double up = log10(param.getUpperAsFloat());
104  double step = log10(param.getStepAsFloat());
105  regler.cp_configure(param.group(), param.name(), log10(param.getLowerAsFloat()), up, step);
106  int prec = 0;
107  float d = log10((param.getStepAsFloat()-1)*param.getUpperAsFloat());
108  if (up > 0) {
109  prec = up;
110  if (d < 0) {
111  prec -= floor(d);
112  }
113  } else if (d < 0) {
114  prec = -floor(d);
115  }
116  regler.signal_format_value().connect(
117  sigc::bind(
118  sigc::ptr_fun(logarithmic_format_value),
119  prec));
120  regler.signal_input_value().connect(
121  sigc::ptr_fun(logarithmic_input_value));
122  } else {
123  regler.cp_configure(param.group(), param.name(), param.getLowerAsFloat(), param.getUpperAsFloat(), param.getStepAsFloat());
124  }
125  regler.set_has_tooltip();
126  string tip = param.desc();
127  if (param.desc().empty()) {
128  tip = id.substr(id.find_last_of(".")+1);
129  }
130  regler.set_tooltip_text(tip);
131  set_cp_value(machine.get_parameter_value<float>(id), regler);
132  machine.signal_parameter_value<float>(id).connect(
133  sigc::bind(sigc::mem_fun(this, &CpBase::set_cp_value), sigc::ref(regler)));
134  regler.get_adjustment()->signal_value_changed().connect(
135  sigc::bind(sigc::mem_fun(this, &CpBase::on_cp_value_changed), sigc::ref(regler)));
136  regler.show();
137  regler.get_accessible()->set_description (id);
138  regler.get_accessible()->set_name(id.substr(id.find_last_of(".")+1));
139  connect_midi_controller(&regler, id, machine);
140 }
141 
143 }
144 
146  gx_engine::GxMachineBase& machine_, const std::string& id_)
147  : Gtk::VBox(),
148  base( machine_, id_),
149  m_label() {
150 }
151 
153 }
154 
155 void CpBaseCaption::init(Gxw::Regler& regler, bool show_value) {
156  regler.set_label_ref(&m_label);
157  base.init(regler, show_value);
158  set_name(base.id);
159  pack_start(m_label, Gtk::PACK_SHRINK);
160  pack_start(regler, Gtk::PACK_EXPAND_WIDGET);
161  set_accessible(regler, m_label);
162  show_all();
163 }
164 
165 void CpBaseCaption::set_effect_label(const char *label) {
166  if (label) {
167  m_label.set_text(label);
168  }
169  m_label.set_name("effekt_label");
170 }
171 
172 void CpBaseCaption::set_rack_label(const char *label) {
173  if (label) {
174  m_label.set_text(label);
175  }
176  m_label.set_name("rack_label");
177  m_label.set_justify(Gtk::JUSTIFY_CENTER);
178 }
179 
180 void CpBaseCaption::set_rack_label_inverse(const char *label) {
181  if (label) {
182  m_label.set_text(label);
183  }
184  m_label.set_name("rack_label_inverse");
185  m_label.set_justify(Gtk::JUSTIFY_CENTER);
186 }
187 
189  gx_engine::GxMachineBase& machine_, const std::string& id_)
190  : Gtk::HBox(),
191  base(machine_, id_),
192  m_label() {
193 }
194 
196 }
197 
199  regler.set_label_ref(&m_label);
200  base.init(regler, false);
201  m_label.set_name("rack_label");
202  m_label.set_size_request(-1,12);
203  set_spacing(4);
204  set_name(base.id);
205  set_spacing(4);
206  pack_start(regler, Gtk::PACK_SHRINK);
207  pack_start(m_label, Gtk::PACK_SHRINK);
208  set_accessible(regler, m_label);
209  show_all();
210 }
211 
212 void CpMasterCaption::set_label(const char *label) {
213  if (label) {
214  Glib::ustring s = label;
215  m_label.set_text(s+" "); //FIXME: font bug, add space to avoid cut off on the right
216  }
217 }
218 
220  gx_engine::GxMachineBase& machine_, const std::string& id_)
221  : Gtk::VBox(),
222  base(machine_, id_),
223  h_box(),
224  m_label() {
225 }
226 
228 }
229 
230 void CpBaseCaptionBoxed::init(Gxw::Regler& regler, bool show_value) {
231  regler.set_label_ref(&m_label);
232  base.init(regler, show_value);
233  m_label.set_justify(Gtk::JUSTIFY_CENTER);
234  set_name(base.id);
235  pack_start(m_label, Gtk::PACK_SHRINK);
236  h_box.pack_start(regler, Gtk::PACK_EXPAND_PADDING);
237  pack_start(h_box, Gtk::PACK_EXPAND_PADDING);
238  set_accessible(regler, m_label);
239  show_all();
240 }
241 
242 void CpBaseCaptionBoxed::set_rack_label(const char *label) {
243  if (label) {
244  m_label.set_name("rack_label");
245  m_label.set_text(label);
246  }
247 }
248 
250  if (label) {
251  m_label.set_name("rack_label_inverse");
252  m_label.set_text(label);
253  }
254 }
255 
256 
257 /****************************************************************
258  ** class UiSelectorXX
259  */
260 
261 CpSelectorBase::CpSelectorBase(Gxw::Selector& selector, gx_engine::GxMachineBase& machine_, const std::string& id_)
262  : machine(machine_), id(id_) {
263  selector.show();
264  selector.cp_set_var(id);
265  Gtk::TreeModelColumn<Glib::ustring> label;
266  Gtk::TreeModelColumnRecord rec;
267  rec.add(label);
268  Glib::RefPtr<Gtk::ListStore> ls = Gtk::ListStore::create(rec);
270  for (const value_pair *p = param.getValueNames(); p->value_id; ++p) {
271  ls->append()->set_value(0, Glib::ustring(param.value_label(*p)));
272  }
273  selector.set_model(ls);
274  selector.set_has_tooltip();
275  string tip = param.desc();
276  if (param.desc().empty()) {
277  tip = id.substr(id.find_last_of(".")+1);
278  }
279  selector.set_tooltip_text(tip);
280  selector.get_accessible()->set_description(id);
281  selector.get_accessible()->set_name(id.substr(id.find_last_of(".")+1));
282 }
283 
284 template <>
285 UiSelector<float>::UiSelector(gx_engine::GxMachineBase& machine_, const std::string& id_)
286  : Gxw::Selector(),
287  base(*this, machine_, id_) {
289  cp_configure(param.group(), param.name(), param.getLowerAsFloat(), param.getUpperAsFloat(), param.getStepAsFloat());
290  cp_set_value(base.machine.get_parameter_value<float>(base.id));
291  base.machine.signal_parameter_value<float>(base.id).connect(
292  sigc::mem_fun(this, &UiSelector<float>::cp_set_value));
293  connect_midi_controller(this, base.id, base.machine);
294 }
295 
296 template <class T>
298  cp_set_value(v);
299 }
300 
301 template <class T>
303  base.machine.set_parameter_value(base.id, get_value());
304 }
305 
306 template <>
308  base.machine.set_parameter_value(base.id, static_cast<int>(get_value()));
309 }
310 
311 template <>
312 UiSelector<int>::UiSelector(gx_engine::GxMachineBase& machine, const std::string& id_)
313  : Gxw::Selector(),
314  base(*this, machine, id_) {
315  gx_engine::IntParameter& param = machine.get_parameter(base.id).getInt();
316  cp_configure(param.group(), param.name(), param.getLowerAsFloat(), param.getUpperAsFloat(), 1);
317  cp_set_value(machine.get_parameter_value<int>(base.id));
318  get_adjustment()->signal_value_changed().connect(
319  sigc::mem_fun(this, &UiSelector::on_value_changed));
320  base.machine.signal_parameter_value<int>(base.id).connect(
321  sigc::mem_fun(this, &UiSelector<int>::set_selector_value));
322  connect_midi_controller(this, base.id, base.machine);
323 }
324 
325 
326 /****************************************************************
327  ** class UiSwitchXX
328  */
329 
330 UiSwitch::UiSwitch(const char *sw_type):
331  Switch(sw_type) {
332 }
333 
335  if (param.isFloat()) {
336  return new UiSwitchFloat(machine, sw_type, param.getFloat());
337  } else {
338  return new UiSwitchBool(machine, sw_type, param.getBool());
339  }
340 }
341 
343  machine.set_parameter_value(param.id(), static_cast<float>(get_active()));
344 }
345 
347  set_active(v != 0.0);
348 }
349 
351  : UiSwitch(sw_type),
352  machine(machine_),
353  param(param_) {
355  cp_set_var(param.id());
356  machine.signal_parameter_value<float>(param.id()).connect(
357  sigc::mem_fun(this, &UiSwitchFloat::set_value));
358  set_has_tooltip();
359  string tip = param.desc();
360  if (param.desc().empty()) {
361  tip = param.id().substr(param.id().find_last_of(".")+1);
362  }
363  set_tooltip_text(tip);
364  get_accessible()->set_description (param.id());
365  get_accessible()->set_name (param.id().substr(
366  param.id().find_last_of(".")+1));
368  show();
369 }
370 
372  machine.set_parameter_value(param.id(), get_active());
373 }
374 
376  set_active(v);
377 }
378 
380  : UiSwitch(sw_type),
381  machine(machine_),
382  param(param_) {
383  set_active(machine.get_parameter_value<bool>(param.id()));
384  cp_set_var(param.id());
385  machine.signal_parameter_value<bool>(param.id()).connect(
386  sigc::mem_fun(this, &UiSwitchBool::set_value));
387  set_has_tooltip();
388  string tip = param.desc();
389  if (param.desc().empty()) {
390  tip = param.id().substr(param.id().find_last_of(".")+1);
391  }
392  set_tooltip_text(tip);
393  get_accessible()->set_description (param.id());
394  get_accessible()->set_name
395  (param.id().substr( param.id().find_last_of(".")+1));
397  show();
398 }
399 
400 static bool hasId(gx_engine::GxMachineBase& machine, string id) {
401  if (!machine.parameter_hasId(id)) {
402  printf("not found: %s\n", id.c_str());
403  return false;
404  }
405  return true;
406 }
407 
409  gx_engine::GxMachineBase& machine, const char *sw_type, const std::string& id,
410  const char *label) {
411  if (!hasId(machine, id)) {
412  return 0;
413  }
414  return new UiHSwitchWithCaption(machine, sw_type, machine.get_parameter(id), label);
415 }
416 
418  gx_engine::GxMachineBase& machine, const char *sw_type,
419  gx_engine::Parameter &param, const char *label)
420  : Gtk::HBox(),
421  m_label(label ? label : param.l_name()),
422  m_switch(UiSwitch::create(machine, sw_type, param)) {
423  m_label.set_name("rack_label");
424  pack_start(m_label, Gtk::PACK_SHRINK);
425  pack_start(*m_switch, Gtk::PACK_EXPAND_PADDING);
426  set_name(param.id());
427  set_accessible(*m_switch, m_label);
428  show_all();
429 }
430 
432  gx_engine::GxMachineBase& machine, const char *sw_type, const std::string& id,
433  const char *label) {
434  if (!hasId(machine, id)) {
435  return 0;
436  }
437  return new UiVSwitchWithCaption(machine, sw_type, machine.get_parameter(id), label);
438 }
439 
441  gx_engine::GxMachineBase& machine, const char *sw_type,
442  gx_engine::Parameter &param, const char *label)
443  : Gtk::VBox(),
444  m_hbox(),
445  m_hbox1(),
446  m_hbox2(),
447  m_label(label ? label : param.l_name()),
448  m_switch(UiSwitch::create(machine, sw_type, param)) {
449  m_label.set_name("rack_label");
450  m_label.set_justify(Gtk::JUSTIFY_CENTER);
451  pack_start(m_label, Gtk::PACK_SHRINK);
452  pack_start(m_hbox, Gtk::PACK_EXPAND_PADDING);
453  m_hbox.pack_start(m_hbox1, Gtk::PACK_EXPAND_PADDING);
454  m_hbox.pack_start(*m_switch, Gtk::PACK_SHRINK);
455  m_hbox.pack_start(m_hbox2, Gtk::PACK_EXPAND_PADDING);
456  set_name(param.id());
457  set_accessible(*m_switch, m_label);
458  show_all();
459 }
460 
462  delete m_switch;
463 }
464 
466  delete m_switch;
467 }
468 
469 }/* end of gx_gui namespace */
static Gtk::Widget * create(gx_engine::GxMachineBase &machine, const char *sw_type, const std::string &id, const char *label)
Glib::ustring logarithmic_format_value(double v, int prec)
static Gtk::Widget * create(gx_engine::GxMachineBase &machine, const char *sw_type, const std::string &id, const char *label)
gx_engine::FloatParameter & param
Definition: gx_main_boxes.h:68
UiSelector(gx_engine::GxMachineBase &machine, const std::string &id)
virtual float getUpperAsFloat() const
virtual float getLowerAsFloat() const
UiSwitchFloat(gx_engine::GxMachineBase &machine, const char *sw_type, gx_engine::FloatParameter &param)
const string & name() const
Definition: gx_parameter.h:175
int logarithmic_input_value(gpointer obj, gpointer nv)
const char * value_id
Definition: gx_plugin.h:118
virtual Parameter & get_parameter(const std::string &id)=0
void set_accessible(Gtk::Widget &widget, Gtk::Label &label)
Glib::SignalProxy2< int, void *, void *> signal_input_value()
Definition: regler.cc:504
static UiSwitch * create(gx_engine::GxMachineBase &machine, const char *sw_type, gx_engine::Parameter &param)
const string & group() const
Definition: gx_parameter.h:173
void init(Gxw::Regler &regler)
gx_engine::GxMachineBase & machine
virtual float getUpperAsFloat() const
CpMasterCaption(gx_engine::GxMachineBase &machine, const std::string &id)
virtual float getLowerAsFloat() const
void set_show_value(bool p1)
Definition: regler.cc:467
void set_label(const char *label)
void cp_configure(Glib::ustring group, Glib::ustring name, double lower, double upper, double step)
gx_engine::GxMachineBase & machine
Definition: gx_main_boxes.h:67
CpBaseCaptionBoxed(gx_engine::GxMachineBase &machine, const std::string &id)
void cp_set_value(double value)
CpSelectorBase(Gxw::Selector &selector, gx_engine::GxMachineBase &machine, const std::string &id)
void set_rack_label_inverse(const char *label)
void set_rack_label(const char *label)
T get_parameter_value(const std::string &id)
void init(Gxw::Regler &regler, bool show_value)
bool isFloat() const
Definition: gx_parameter.h:162
CpBaseCaption(gx_engine::GxMachineBase &machine, const std::string &id)
UiSwitchBool(gx_engine::GxMachineBase &machine, const char *sw_type, gx_engine::BoolParameter &param)
UiSwitch(const char *sw_type)
void set_label_ref(Gtk::Label *p1)
Definition: regler.cc:457
virtual bool parameter_hasId(const char *p)=0
Definition: bigknob.cc:51
void cp_set_var(Glib::ustring p1)
virtual void set_parameter_value(const std::string &id, int value)=0
UiVSwitchWithCaption(gx_engine::GxMachineBase &machine, const char *sw_type, gx_engine::Parameter &param, const char *label)
void connect_midi_controller(Gtk::Widget *w, const std::string &id, gx_engine::GxMachineBase &machine)
void set_model(Glib::RefPtr< Gtk::TreeModel > p1)
Definition: selector.cc:132
void set_rack_label_inverse(const char *label)
Glib::SignalProxy1< Glib::ustring, double > signal_format_value()
Definition: regler.cc:510
void set_cp_value(float v, Gxw::ControlParameter &c)
FloatParameter & getFloat()
Definition: gx_parameter.h:452
const string & desc() const
Definition: gx_parameter.h:177
virtual float getStepAsFloat() const
gx_engine::BoolParameter & param
Definition: gx_main_boxes.h:80
UiHSwitchWithCaption(gx_engine::GxMachineBase &machine, const char *sw_type, gx_engine::Parameter &param, const char *label)
void set_rack_label(const char *label)
void on_cp_value_changed(Gxw::ControlParameter &c)
IntParameter & getInt()
Definition: gx_parameter.h:457
void init(Gxw::Regler &regler, bool show_value)
gx_engine::GxMachineBase & machine
static const char * value_label(const value_pair &vp)
Definition: gx_parameter.h:198
sigc::signal< void, T > & signal_parameter_value(const std::string &id)
BoolParameter & getBool()
Definition: gx_parameter.h:468
const string & id() const
Definition: gx_parameter.h:172
void init(Gxw::Regler &regler, bool show_value)
void set_effect_label(const char *label)
CpBase(gx_engine::GxMachineBase &machine, const std::string &id)
virtual const value_pair * getValueNames() const
gx_engine::GxMachineBase & machine
Definition: gx_main_boxes.h:79