Guitarix
gx_parameter.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 depends on gx_system.h
22  *
23  * ----------------------------------------------------------------------------
24  */
25 
26 #pragma once
27 
28 #ifndef SRC_HEADERS_GX_PARAMETER_H_
29 #define SRC_HEADERS_GX_PARAMETER_H_
30 
31 namespace gx_system { class JsonWriter; class JsonParser; }
32 
33 namespace gx_engine {
34 
35 #ifndef NDEBUG
36 #define debug_check(func, ...) func(__VA_ARGS__)
37 #else
38 #define debug_check(...)
39 #endif
40 
41 /****************************************************************
42  **
43  ** Parameter
44  **
45  */
46 
48  private:
49  map<string, string> groups;
50 
51 #ifndef NDEBUG
52  map<string, bool> used;
53  void group_exists(const string& id);
54  void group_is_new(const string& id);
55  friend string param_group(const string& group_id, bool nowarn);
56 #endif
57 
58  public:
60  ~ParameterGroups();
61 
62  inline string get(const string& id) { return groups[id]; }
63  inline string operator[](const string& id) {
64  debug_check(group_exists, id);
65  return groups[id];
66  }
67  inline void insert(const string& id, const string& group) {
68  debug_check(group_is_new, id);
69  groups.insert(pair<string, string>(id, group));
70  }
71  inline void erase(const string& id) {
72 #ifndef NDEBUG // avoid unused variable warning in release mode
73  size_t n = groups.erase(id);
74  assert(n == 1);
75 #else
76  groups.erase(id);
77 #endif
78  }
79 #ifndef NDEBUG
80  void dump();
81 #endif
82 };
83 
84 
86 string param_group(const string& group_id, bool nowarn = false);
87 
88 /****************************************************************
89  ** Parameter
90  */
91 
92 template <class T> class ParameterV;
93 
98 
99 class FloatEnumParameter;
100 class EnumParameter;
101 class FileParameter;
102 
103 /****************************************************************/
104 
105 class Parameter: boost::noncopyable {
106 public:
107  enum ctrl_type { None, Continuous, Switch, Enum };
108 private:
109  virtual bool midi_set(float n, float high, float llimit, float ulimit); //RT
110  virtual bool midi_set_bpm(float n, float high, float llimit, float ulimit); //RT
111  virtual void trigger_changed();
112  friend class MidiController;
113 protected:
114  enum value_type { tp_float, tp_int, tp_bool, tp_file, tp_string, tp_special };
115  enum display_flags { dtp_normal, dtp_log = 1 };
116  string _id;
117  string _name, _group, _desc;
118  enum value_type v_type : 3;
119  enum ctrl_type c_type : 3;
120  unsigned int d_flags : 2;
121  bool save_in_preset : 1;
122  bool controllable : 1;
123  bool do_not_save : 1;
124  bool blocked : 1;
125  bool used : 1; // debug
126 protected:
127  void range_warning(float value, float lower, float upper);
128  static gx_system::JsonParser& jp_next(gx_system::JsonParser& jp, const char *key);
129 public:
130  inline std::string group_id() const { return _id.substr(0, _id.find_last_of(".")); }
131  Parameter(const string& id, const string& name, value_type vtp, ctrl_type ctp, bool preset,
132  bool ctrl):
133  boost::noncopyable(),
134  _id(id),
135  _name(name),
136  _group(param_group(group_id())),
137  _desc(),
138  v_type(vtp),
139  c_type(ctp),
140  d_flags(0),
141  save_in_preset(preset),
142  controllable(ctrl),
143  do_not_save(false),
144  blocked(false),
145  used(false) {}
147  virtual ~Parameter();
148  virtual void serializeJSON(gx_system::JsonWriter& jw);
149 
150 #ifndef NDEBUG
151  bool isUsed() const { return used; }
152  void setUsed() { used = true; }
153  friend void compare_parameter(const char* title, Parameter* p1,
154  Parameter* p2, bool all);
155  void dump(gx_system::JsonWriter *jw);
156 #endif
157 
158  const char *get_typename() const;
159  bool isFloat() const { return v_type == tp_float; }
160  bool isInt() const { return v_type == tp_int; }
161  bool isBool() const { return v_type == tp_bool; }
162  bool isFile() const { return v_type == tp_file; }
163  bool isString() const { return v_type == tp_string; }
164  ctrl_type getControlType() const { return c_type; }
165  bool isControllable() const { return controllable; }
166  bool isInPreset() const { return save_in_preset; }
167  bool isSavable() const { return !do_not_save; }
168  void setSavable(bool v) { do_not_save = !v; }
169  const string& id() const { return _id; }
170  const string& group() const { return _group; }
171  string l_group() const { return gettext(_group.c_str()); }
172  const string& name() const { return _name; }
173  string l_name() const { return gettext(_name.c_str()); }
174  const string& desc() const { return _desc; }
175  void set_desc(const string& desc) { _desc = desc; }
176  string l_desc() const { return gettext(_desc.c_str()); }
177  void set_log_display() { d_flags |= dtp_log; }
178  bool is_log_display() { return d_flags & dtp_log; }
179  void set_blocked(bool v) { blocked = v; }
180  bool get_blocked() { return blocked; }
181  bool operator==(const Parameter& p) const { return &p == this; }
182  virtual void stdJSON_value() = 0;
183  virtual bool on_off_value() = 0; //RT
184  virtual void writeJSON(gx_system::JsonWriter& jw) const = 0;
185  virtual void readJSON_value(gx_system::JsonParser& jp) = 0;
186  virtual void setJSON_value() = 0;
187  virtual bool compareJSON_value() = 0;
188  virtual bool hasRange() const;
189  virtual float getLowerAsFloat() const;
190  virtual float getUpperAsFloat() const;
191  virtual float getStepAsFloat() const;
192  virtual const value_pair *getValueNames() const;
193  static inline const char *value_label(const value_pair& vp) {
194  return gettext(vp.value_label ? vp.value_label : vp.value_id);
195  }
196  FloatParameter& getFloat();
197  IntParameter& getInt();
198  EnumParameter& getEnum();
199  BoolParameter& getBool();
200  FileParameter &getFile();
201  StringParameter &getString();
202  sigc::signal<void, float>& signal_changed_float();
203  sigc::signal<void, int>& signal_changed_int();
204  sigc::signal<void, bool>& signal_changed_bool();
205  sigc::signal<void, const Glib::ustring&>& signal_changed_string();
206 };
207 
208 #ifndef NDEBUG
209 void compare_parameter(const char* title, Parameter* p1,
210  Parameter* p2, bool all = false);
211 #endif
212 
213 /****************************************************************/
214 
215 typedef list<Parameter*> paramlist;
216 
217 /****************************************************************/
218 
219 template<class T>
220 class ParameterV: public Parameter {
221 };
222 
223 template<>
224 class ParameterV<float>: public Parameter {
225 private:
226  virtual bool midi_set(float n, float high, float llimit, float ulimit); //RT
227  virtual bool midi_set_bpm(float n, float high, float llimit, float ulimit); //RT
228  virtual void trigger_changed();
229 protected:
230  float json_value;
231  float *value;
232  float std_value;
233  float lower, upper, step;
234  sigc::signal<void, float> changed;
236  friend class ParamRegImpl;
237 public:
238  bool set(float val) const;
239  float get_value() const { return *value; }
240  void convert_from_range(float low, float up);
241  virtual void stdJSON_value();
242  virtual bool on_off_value();
243  virtual void writeJSON(gx_system::JsonWriter& jw) const;
244  virtual void readJSON_value(gx_system::JsonParser& jp);
245  virtual bool compareJSON_value();
246  virtual void setJSON_value();
247  virtual bool hasRange() const;
248  virtual float getLowerAsFloat() const;
249  virtual float getUpperAsFloat() const;
250  virtual float getStepAsFloat() const;
251  virtual float idx_from_id(string v_id);
252  ParameterV(const string& id, const string& name, ctrl_type ctp, bool preset,
253  float *v, float sv, float lv, float uv, float tv, bool ctrl, bool no_init):
254  Parameter(id, name, tp_float, ctp, preset, ctrl),
255  value(v ? v : &value_storage), std_value(sv),lower(lv),upper(uv),step(tv) {
256  set(no_init ? *value : sv);
257  }
258 #ifndef NDEBUG
259  friend void compare_parameter(const char* title, Parameter* p1,
260  Parameter* p2, bool all);
261 #endif
262  ~ParameterV();
264  virtual void serializeJSON(gx_system::JsonWriter& jw);
265  sigc::signal<void, float>& signal_changed() { return changed; }
266 };
267 
268 /****************************************************************/
269 
270 class FloatEnumParameter: public FloatParameter {
271 protected:
273  FloatEnumParameter(gx_system::JsonParser& jp): FloatParameter(jp_next(jp, "FloatParameter")), value_names(0) {}
274 public:
275  virtual void writeJSON(gx_system::JsonWriter& jw) const;
276  virtual void readJSON_value(gx_system::JsonParser& jp);
277  virtual const value_pair *getValueNames() const;
278  FloatEnumParameter(const string& id, const string& name, const value_pair* vn, bool preset, float *v,
279  int sv, int low, bool ctrl, bool no_init);
280  virtual void serializeJSON(gx_system::JsonWriter& jw);
281  virtual float idx_from_id(string v_id);
282 };
283 
284 /****************************************************************/
285 
286 template<>
287 class ParameterV<int>: public Parameter {
288 private:
289  virtual bool midi_set(float n, float high, float llimit, float ulimit); //RT
290  virtual void trigger_changed();
291 protected:
293  int *value;
295  int lower, upper;
296  sigc::signal<void, int> changed;
298 public:
299  bool set(int val) const;
300  int get_value() const { return *value; }
301  virtual void stdJSON_value();
302  virtual bool on_off_value();
303  virtual void writeJSON(gx_system::JsonWriter& jw) const;
304  virtual void readJSON_value(gx_system::JsonParser& jp);
305  virtual bool compareJSON_value();
306  virtual void setJSON_value();
307  virtual bool hasRange() const;
308  virtual float getLowerAsFloat() const;
309  virtual float getUpperAsFloat() const;
310  virtual int idx_from_id(string v_id);
311  ParameterV(const string& id, const string& name, ctrl_type ctp, bool preset,
312  int *v, int sv, int lv, int uv, bool ctrl):
313  Parameter(id, name, tp_int, ctp, preset, ctrl),
314  value(v ? v : &value_storage), std_value(sv), lower(lv), upper(uv) {
315  *value = sv;
316  }
317  ~ParameterV();
319  virtual void serializeJSON(gx_system::JsonWriter& jw);
320  sigc::signal<void, int>& signal_changed() { return changed; }
321 };
322 
323 /****************************************************************/
324 
325 class EnumParameter: public IntParameter {
326 protected:
328  EnumParameter(gx_system::JsonParser& jp): IntParameter(jp_next(jp, "IntParameter")), value_names(0) {}
329 public:
330  virtual void writeJSON(gx_system::JsonWriter& jw) const;
331  virtual void readJSON_value(gx_system::JsonParser& jp);
332  virtual const value_pair *getValueNames() const;
333  virtual int idx_from_id(string v_id);
334  const value_pair& get_pair() { return getValueNames()[get_value()]; }
335  EnumParameter(const string& id, const string& name, const value_pair* vn, bool preset, int *v,
336  int sv, bool ctrl);
337  virtual void serializeJSON(gx_system::JsonWriter& jw);
338 };
339 
340 /****************************************************************/
341 
342 template<>
343 class ParameterV<bool>: public Parameter {
344 private:
345  virtual bool midi_set(float n, float high, float llimit, float ulimit); //RT
346  virtual void trigger_changed();
347 protected:
349  bool *value;
350  bool std_value;
351  sigc::signal<void, bool> changed;
353 public:
354  bool set(bool val) const;
355  virtual void stdJSON_value();
356  bool get_value() const { return *value; }
357  virtual bool on_off_value();
358  virtual void writeJSON(gx_system::JsonWriter& jw) const;
359  virtual bool compareJSON_value();
360  virtual void setJSON_value();
361  virtual void readJSON_value(gx_system::JsonParser& jp);
362  ParameterV(const string& id, const string& name, ctrl_type ctp, bool preset,
363  bool *v, bool sv, bool ctrl):
364  Parameter(id, name, tp_bool, ctp, preset, ctrl),
365  value(v ? v : &value_storage), std_value(sv) {
366  *value = sv;
367  }
368  ~ParameterV();
370  virtual void serializeJSON(gx_system::JsonWriter& jw);
371  sigc::signal<void, bool>& signal_changed() { return changed; }
372 };
373 
374 /****************************************************************/
375 
376 /****************************************************************/
377 
378 class FileParameter: public Parameter {
379 protected:
380  Glib::RefPtr<Gio::File> value;
381  Glib::RefPtr<Gio::File> std_value;
382  Glib::RefPtr<Gio::File> json_value;
383  sigc::signal<void> changed;
384 public:
385  sigc::signal<void>& signal_changed() { return changed; }
386  bool set(const Glib::RefPtr<Gio::File>& val);
387  void set_path(const string& path);
388  const Glib::RefPtr<Gio::File>& get() const { return value; }
389  virtual void stdJSON_value();
390  virtual bool on_off_value();
391  virtual void writeJSON(gx_system::JsonWriter& jw) const;
392  virtual void readJSON_value(gx_system::JsonParser& jp);
393  virtual bool compareJSON_value();
394  virtual void setJSON_value();
395  FileParameter(const string& id, const string& filename, bool preset = false):
396  Parameter(id, "", tp_file, None, preset, false),
397  value(Gio::File::create_for_path(filename)),
398  std_value(value->dup()) {}
399  FileParameter(const string& id, bool preset = false):
400  Parameter(id, "", tp_file, None, preset, false),
401  value(0),
402  std_value(0) {}
404  virtual void serializeJSON(gx_system::JsonWriter& jw);
405  void set_standard(const string& filename);
406  bool is_equal(const Glib::RefPtr<Gio::File>& v) const;
407  bool is_standard() const { return is_equal(std_value); }
408  string get_path() const;
409  string get_directory_path() const;
410  string get_parse_name() const;
411  string get_display_name() const;
412  void copy(const string& destination) const;
413 };
414 
415 /****************************************************************/
416 
417 template<>
418 class ParameterV<Glib::ustring>: public Parameter {
419 protected:
420  Glib::ustring json_value;
421  Glib::ustring *value;
422  Glib::ustring std_value;
423  sigc::signal<void, const Glib::ustring&> changed;
424  Glib::ustring value_storage;
425 public:
426  bool set(const Glib::ustring& val) const;
427  const Glib::ustring& get_value() const { return *value; }
428  virtual void stdJSON_value();
429  virtual bool on_off_value();
430  virtual void writeJSON(gx_system::JsonWriter& jw) const;
431  virtual bool compareJSON_value();
432  virtual void setJSON_value();
433  virtual void readJSON_value(gx_system::JsonParser& jp);
434  ParameterV(const string& id, const string& name, Glib::ustring *v, const Glib::ustring& sv, bool preset = false)
435  : Parameter(id, name, tp_string, None, preset, false),
436  value(v ? v : &value_storage), std_value(sv) {
437  }
438  ~ParameterV();
440  virtual void serializeJSON(gx_system::JsonWriter& jw);
441  sigc::signal<void, const Glib::ustring&>& signal_changed() { return changed; }
442 };
443 
444 
445 /****************************************************************/
446 
447 inline FloatParameter &Parameter::getFloat() {
448  assert(isFloat());
449  return static_cast<FloatParameter&>(*this);
450 }
451 
452 inline IntParameter &Parameter::getInt() {
453  assert(isInt());
454  return static_cast<IntParameter&>(*this);
455 }
456 
457 inline EnumParameter &Parameter::getEnum() {
458  EnumParameter *p = dynamic_cast<EnumParameter*>(this);
459  assert(p);
460  return *p;
461 }
462 
463 inline BoolParameter &Parameter::getBool() {
464  assert(isBool());
465  return static_cast<BoolParameter&>(*this);
466 }
467 
468 inline FileParameter &Parameter::getFile() {
469  assert(isFile());
470  return static_cast<FileParameter&>(*this);
471 }
472 
473 inline StringParameter &Parameter::getString() {
474  assert(isString());
475  return static_cast<StringParameter&>(*this);
476 }
477 
478 inline sigc::signal<void, float>& Parameter::signal_changed_float() {
479  FloatParameter *p = dynamic_cast<FloatParameter*>(this);
480  assert(p);
481  return p->signal_changed();
482 }
483 
484 inline sigc::signal<void, int>& Parameter::signal_changed_int() {
485  IntParameter *p = dynamic_cast<IntParameter*>(this);
486  assert(p);
487  return p->signal_changed();
488 }
489 
490 inline sigc::signal<void, bool>& Parameter::signal_changed_bool() {
491  BoolParameter *p = dynamic_cast<BoolParameter*>(this);
492  assert(p);
493  return p->signal_changed();
494 }
495 
496 inline sigc::signal<void, const Glib::ustring&>& Parameter::signal_changed_string() {
497  StringParameter *p = dynamic_cast<StringParameter*>(this);
498  assert(p);
499  return p->signal_changed();
500 }
501 
502 
503 /****************************************************************
504  ** ParamMap
505  */
506 
507 class ParamMap: boost::noncopyable {
508  private:
509  map<string, Parameter*> id_map;
510  bool replace_mode;
511  sigc::signal<void,Parameter*,bool> insert_remove;
512 #ifndef NDEBUG
513  void unique_id(Parameter* param);
514  void check_id(const string& id);
515  void check_p(const char *p);
516 #endif
517  Parameter *insert(Parameter* param); // private so we can make sure parameters are owned
518 
519  public:
520  template<class T> friend class ParameterV;
521  ParamMap();
522  ~ParamMap();
523  void writeJSON(gx_system::JsonWriter& jw);
524  void readJSON(gx_system::JsonParser& jp);
525  Parameter *readJSON_one(gx_system::JsonParser& jp);
526  void writeJSON_one(gx_system::JsonWriter& jw, Parameter *p);
527  typedef map<string, Parameter*>::const_iterator iterator;
528  iterator begin() const { return id_map.begin(); }
529  iterator end() const { return id_map.end(); }
530  bool hasId(const string& id) const { return id_map.find(id) != id_map.end(); }
531  bool hasId(const char *p) const { return id_map.find(p) != id_map.end(); }
532  void set_replace_mode(bool mode) { replace_mode = mode; }
533  Parameter& operator[](const string& id) {
534  debug_check(check_id, id);
535  return *id_map[id];
536  }
537  Parameter& operator[](const char *p) {
538  debug_check(check_p, p);
539  return *id_map[p];
540  }
541  void set_init_values();
542  void reset_unit(const PluginDef *pdef) const;
543  bool unit_has_std_values(const PluginDef *pdef) const;
544  sigc::signal<void,Parameter*,bool> signal_insert_remove() { return insert_remove; }
545  void unregister(Parameter *p);
546  void unregister(const string& id);
547  inline FloatParameter *reg_par(const string& id, const string& name, float *var, float std,
548  float lower, float upper, float step) {
549  FloatParameter *p = new FloatParameter(id, name, Parameter::Continuous, true, var, std, lower, upper, step, true, replace_mode);
550  insert(p);
551  return p;
552  }
553  inline FloatParameter *reg_par_non_preset(
554  const string& id, const string& name, float *var, float std, float lower, float upper, float step) {
555  FloatParameter *p = new FloatParameter(id, name, Parameter::Continuous, false, var, std, lower, upper, step, false, replace_mode);
556  insert(p);
557  return p;
558  }
559  inline FloatParameter *reg_par(const string& id, const string& name, float *var, float std = 0) {
560  FloatParameter *p = new FloatParameter(id, name, Parameter::Switch, true, var, std, 0, 1, 1, true, replace_mode);
561  insert(p);
562  return p;
563  }
564  inline BoolParameter *reg_par(const string& id, const string& name, bool *var, bool std=false, bool preset=true) {
565  BoolParameter * p = new BoolParameter(id, name, Parameter::Switch, preset, var, std, true);
566  insert(p);
567  return p;
568  }
569  inline EnumParameter *reg_enum_par(const string& id, const string& name,
570  const value_pair *vl, int *var, int std = 0) {
571  EnumParameter *p = new EnumParameter(id, name, vl, true, var, std, true);
572  insert(p);
573  return p;
574  }
576  const string& id, const string& name, const value_pair *vl,
577  int *var, bool preset, int std = 0) {
578  EnumParameter *p = new EnumParameter(id, name, vl, preset, var, std, false);
579  insert(p);
580  return p;
581  }
582  inline FloatEnumParameter *reg_enum_par(const string& id, const string& name,
583  const value_pair *vl, float *var,
584  int std = 0, int low = 0) {
585  FloatEnumParameter *p = new FloatEnumParameter(id, name, vl, true, var, std, low, true, replace_mode);
586  insert(p);
587  return p;
588  }
589  inline BoolParameter *reg_non_midi_par(const string& id, bool *var, bool preset, bool std = false) {
590  BoolParameter *p = new BoolParameter(id, "", Parameter::Switch, preset, var, std, false);
591  insert(p);
592  return p;
593  }
594  inline IntParameter *reg_non_midi_par(const string& id, int *var, bool preset, int std, int lower, int upper) {
595  IntParameter *p = new IntParameter(id, "", Parameter::None, preset, var, std, lower, upper, false);
596  insert(p);
597  return p;
598  }
599  inline FloatParameter *reg_non_midi_par(const string& id, float *val, bool preset,
600  float std = 0, float lower = 0, float upper = 1, float step = 0) {
601  FloatParameter *p = new FloatParameter(id, "", Parameter::None, preset, val, std, lower, upper, step, false, replace_mode);
602  insert(p);
603  return p;
604  }
605  inline FileParameter *reg_filepar(const string& id, bool preset = false) {
606  FileParameter *p = new FileParameter(id, preset);
607  insert(p);
608  return p;
609  }
610  inline StringParameter *reg_string(const string& id, const string& name, Glib::ustring *var, const string& sv, bool preset=false) {
611  StringParameter *p = new StringParameter(id, name, var, sv, preset);
612  insert(p);
613  return p;
614  }
615  inline StringParameter *reg_preset_string(const string& id, const string& name, Glib::ustring *var, const string& sv, bool preset=true) {
616  StringParameter *p = new StringParameter(id, name, var, sv, preset);
617  insert(p);
618  return p;
619  }
620 
621 #ifndef NDEBUG
622  void dump(const string& fmt);
623 #endif
624 };
625 
626 /****************************************************************
627  **
628  ** Midi
629  **
630  */
631 
632 
633 /*
634 ** MidiStandardControllers
635 */
636 
637 /****************************************************************/
638 
640  private:
641  struct modstring {
642  string name;
643  bool modified;
644  const char *std;
645  modstring(const string& n, bool m, const char* s): name(n), modified(m), std(s) {}
646  explicit modstring(const char* n): name(n), modified(false), std(n) {}
647  modstring(): name(""), modified(false), std(0) {}
648  };
649  map<int, modstring> m;
650 
651  public:
653  const string operator[](int ctr) { return m[ctr].name; }
654  void replace(int ctr, const string& name);
655  void writeJSON(gx_system::JsonWriter& jw) const;
656  void readJSON(gx_system::JsonParser& jp);
657 };
658 
659 extern MidiStandardControllers midi_std_ctr; // map ctrl num -> standard name
660 
661 /****************************************************************
662 **
663 ** MidiController
664 **/
665 
667  private:
668  Parameter *param; //RT
669  float _lower, _upper; //RT
670  bool toggle; //RT
671  public:
672  MidiController(Parameter& p, float l, float u, bool t=false):
673  param(&p), _lower(l), _upper(u), toggle(t) {}
674  float lower() const { return _lower; }
675  float upper() const { return _upper; }
676  bool is_toggle() const { return toggle; }
677  bool hasParameter(const Parameter& p) const { return *param == p; }
678  Parameter& getParameter() const { return *param; }
679  static MidiController *readJSON(gx_system::JsonParser& jp, ParamMap& param);
680  bool set_midi(int n, int last_value); //RT
681  bool set_bpm(int n, int last_value); //RT
682  bool set_trans(int n, int last_value); //RT
683  void set(float v, float high) { param->midi_set(v, high, _lower, _upper); }
684  void trigger_changed() { param->trigger_changed(); }
685  void writeJSON(gx_system::JsonWriter& jw) const;
686 };
687 
688 typedef list<MidiController> midi_controller_list;
689 
690 /****************************************************************
691 **
692 ** MidiControllerList
693 **/
694 
695 
697 private:
698  double time1;
699  double time_diff;
700  int collect;
701  int collect_;
702  double bpm;
703  double bpm_new;
704  bool ret;
705 
706 public:
707  MidiClockToBpm();
709  unsigned int rounded(float f);
710  bool time_to_bpm(double time, unsigned int* bpm_);
711 };
712 
713 
714 class ControllerArray: public vector<midi_controller_list> {
715 public:
716  enum { array_size = 128 };
717  ControllerArray(): vector<midi_controller_list>(array_size) {}
719  void writeJSON(gx_system::JsonWriter& jw) const;
720  void readJSON(gx_system::JsonParser& jp, ParamMap& param);
721  int param2controller(Parameter& param, const MidiController** p);
722  bool deleteParameter(Parameter& p);
723 };
724 
725 class MidiControllerList: public sigc::trackable {
726 public:
727 private:
728  ControllerArray map; //RT
729  int last_midi_control_value[ControllerArray::array_size]; //RT
730  int last_midi_control; //RT
731  volatile gint program_change; //RT
732  volatile gint mute_change; //RT
733  volatile gint bank_change; //RT
734  timespec ts1;
735  double time0;
736  unsigned int bpm_;
737  MidiClockToBpm mp;
738  Glib::Dispatcher pgm_chg;
739  Glib::Dispatcher mute_chg;
740  Glib::Dispatcher bank_chg;
741  sigc::signal<void> changed;
742  sigc::signal<void,int> new_program;
743  sigc::signal<void,int> new_mute_state;
744  sigc::signal<void,int> new_bank;
745  sigc::signal<void, int, int> midi_value_changed;
746 private:
747  void on_pgm_chg();
748  void on_mute_chg();
749  void on_bank_chg();
750  bool check_midi_values();
751 public:
753  midi_controller_list& operator[](int n) { return map[n]; }
754  int size() { return map.size(); }
755  void set_config_mode(bool mode, int ctl=-1);
756  bool get_config_mode() { return last_midi_control != -2; }
757  int get_current_control() { return last_midi_control; }
758  void set_current_control(int ctl) { last_midi_control = ctl; }
759  void set_ctr_val(int ctr, int val); //RT
760  void set_bpm_val(unsigned int val); //RT
761  void deleteParameter(Parameter& param);
762  void modifyCurrent(Parameter& param, float lower, float upper, bool toggle);
763  int param2controller(Parameter& param, const MidiController** p) {
764  return map.param2controller(param, p); }
765  void writeJSON(gx_system::JsonWriter& jw) const { map.writeJSON(jw); }
766  int get_last_midi_control_value(unsigned int n) {
767  assert(n < ControllerArray::array_size); return last_midi_control_value[n]; } //RT
768  void set_last_midi_control_value(unsigned int n, int v) {
769  assert(n < ControllerArray::array_size); last_midi_control_value[n] = v; } //RT
770  void set_controller_array(const ControllerArray& m);
771  void remove_controlled_parameters(paramlist& plist, const ControllerArray *m);
772  sigc::signal<void>& signal_changed() { return changed; }
773  sigc::signal<void,int>& signal_new_program() { return new_program; }
774  sigc::signal<void,int>& signal_new_mute_state() { return new_mute_state; }
775  sigc::signal<void,int>& signal_new_bank() { return new_bank; }
776  void compute_midi_in(void* midi_input_port_buf, void *arg); //RT
777  void process_trans(int transport_state); //RT
778  void update_from_controller(int ctr);
779  void update_from_controllers();
780  sigc::signal<void, int, int>& signal_midi_value_changed() { return midi_value_changed; }
781  void request_midi_value_update();
782 };
783 
784 } // namespace gx_gui
785 
786 #endif // SRC_HEADERS_GX_PARAMETER_H_
787 
ParameterV< float > FloatParameter
Definition: gx_parameter.h:92
int get_last_midi_control_value(unsigned int n)
Definition: gx_parameter.h:766
FloatEnumParameter(gx_system::JsonParser &jp)
Definition: gx_parameter.h:273
FloatEnumParameter * reg_enum_par(const string &id, const string &name, const value_pair *vl, float *var, int std=0, int low=0)
Definition: gx_parameter.h:582
int param2controller(Parameter &param, const MidiController **p)
string operator[](const string &id)
Definition: gx_parameter.h:63
ParameterV(const string &id, const string &name, ctrl_type ctp, bool preset, int *v, int sv, int lv, int uv, bool ctrl)
Definition: gx_parameter.h:311
Parameter & getParameter() const
Definition: gx_parameter.h:678
midi_controller_list & operator[](int n)
Definition: gx_parameter.h:753
void check_id(Gtk::Widget *w, const std::string &id, gx_engine::GxMachineBase &machine)
MidiController(Parameter &p, float l, float u, bool t=false)
Definition: gx_parameter.h:672
string l_desc() const
Definition: gx_parameter.h:176
sigc::signal< void > & signal_changed()
Definition: gx_parameter.h:772
BoolParameter * reg_non_midi_par(const string &id, bool *var, bool preset, bool std=false)
Definition: gx_parameter.h:589
bool isUsed() const
Definition: gx_parameter.h:151
MidiStandardControllers midi_std_ctr
const string & group() const
Definition: gx_parameter.h:170
map< string, Parameter * >::const_iterator iterator
Definition: gx_parameter.h:527
void setSavable(bool v)
Definition: gx_parameter.h:168
Parameter(const string &id, const string &name, value_type vtp, ctrl_type ctp, bool preset, bool ctrl)
Definition: gx_parameter.h:131
list< Parameter * > paramlist
Definition: gx_parameter.h:215
string l_group() const
Definition: gx_parameter.h:171
FloatParameter * reg_par_non_preset(const string &id, const string &name, float *var, float std, float lower, float upper, float step)
Definition: gx_parameter.h:553
const char * value_id
Definition: gx_plugin.h:118
FloatParameter * reg_par(const string &id, const string &name, float *var, float std=0)
Definition: gx_parameter.h:559
STL namespace.
const string operator[](int ctr)
Definition: gx_parameter.h:653
string param_group(const string &group_id, bool nowarn=false)
int param2controller(Parameter &param, const MidiController **p)
Definition: gx_parameter.h:763
bool hasId(const string &id) const
Definition: gx_parameter.h:530
Parameter & operator[](const string &id)
Definition: gx_parameter.h:533
bool isFile() const
Definition: gx_parameter.h:162
void compare_parameter(const char *title, Parameter *p1, Parameter *p2, bool all=false)
sigc::signal< void, int > & signal_new_program()
Definition: gx_parameter.h:773
bool isFloat() const
Definition: gx_parameter.h:159
const string & id() const
Definition: gx_parameter.h:169
bool isControllable() const
Definition: gx_parameter.h:165
Glib::RefPtr< Gio::File > std_value
Definition: gx_parameter.h:381
EnumParameter(gx_system::JsonParser &jp)
Definition: gx_parameter.h:328
IntParameter * reg_non_midi_par(const string &id, int *var, bool preset, int std, int lower, int upper)
Definition: gx_parameter.h:594
ParameterV< int > IntParameter
Definition: gx_parameter.h:95
iterator begin() const
Definition: gx_parameter.h:528
sigc::signal< void, float > & signal_changed()
Definition: gx_parameter.h:265
sigc::signal< void > changed
Definition: gx_parameter.h:383
StringParameter * reg_string(const string &id, const string &name, Glib::ustring *var, const string &sv, bool preset=false)
Definition: gx_parameter.h:610
bool hasParameter(const Parameter &p) const
Definition: gx_parameter.h:677
ParameterV< bool > BoolParameter
Definition: gx_parameter.h:96
sigc::signal< void, int, int > & signal_midi_value_changed()
Definition: gx_parameter.h:780
#define debug_check(func,...)
Definition: gx_parameter.h:36
void insert(const string &id, const string &group)
Definition: gx_parameter.h:67
sigc::signal< void > & signal_changed()
Definition: gx_parameter.h:385
ParameterGroups & get_group_table()
const string & desc() const
Definition: gx_parameter.h:174
sigc::signal< void, bool > changed
Definition: gx_parameter.h:351
const value_pair * value_names
Definition: gx_parameter.h:272
bool isInPreset() const
Definition: gx_parameter.h:166
ctrl_type getControlType() const
Definition: gx_parameter.h:164
FileParameter(const string &id, bool preset=false)
Definition: gx_parameter.h:399
sigc::signal< void, bool > & signal_changed()
Definition: gx_parameter.h:371
void set_replace_mode(bool mode)
Definition: gx_parameter.h:532
const char * value_label
Definition: gx_plugin.h:119
Parameter & operator[](const char *p)
Definition: gx_parameter.h:537
const value_pair * value_names
Definition: gx_parameter.h:327
void erase(const string &id)
Definition: gx_parameter.h:71
std::string group_id() const
Definition: gx_parameter.h:130
void writeJSON(gx_system::JsonWriter &jw) const
Definition: gx_parameter.h:765
bool isBool() const
Definition: gx_parameter.h:161
sigc::signal< void, Parameter *, bool > signal_insert_remove()
Definition: gx_parameter.h:544
sigc::signal< void, int > & signal_new_bank()
Definition: gx_parameter.h:775
FloatParameter * reg_par(const string &id, const string &name, float *var, float std, float lower, float upper, float step)
Definition: gx_parameter.h:547
string l_name() const
Definition: gx_parameter.h:173
list< MidiController > midi_controller_list
Definition: gx_parameter.h:688
void writeJSON(gx_system::JsonWriter &jw) const
bool isInt() const
Definition: gx_parameter.h:160
FileParameter * reg_filepar(const string &id, bool preset=false)
Definition: gx_parameter.h:605
void set_blocked(bool v)
Definition: gx_parameter.h:179
const string & name() const
Definition: gx_parameter.h:172
Glib::RefPtr< Gio::File > value
Definition: gx_parameter.h:380
bool isSavable() const
Definition: gx_parameter.h:167
sigc::signal< void, int > changed
Definition: gx_parameter.h:296
const Glib::ustring & get_value() const
Definition: gx_parameter.h:427
BoolParameter * reg_par(const string &id, const string &name, bool *var, bool std=false, bool preset=true)
Definition: gx_parameter.h:564
bool isString() const
Definition: gx_parameter.h:163
bool is_standard() const
Definition: gx_parameter.h:407
sigc::signal< void, int > & signal_new_mute_state()
Definition: gx_parameter.h:774
sigc::signal< void, const Glib::ustring & > & signal_changed()
Definition: gx_parameter.h:441
void set_desc(const string &desc)
Definition: gx_parameter.h:175
FloatParameter * reg_non_midi_par(const string &id, float *val, bool preset, float std=0, float lower=0, float upper=1, float step=0)
Definition: gx_parameter.h:599
EnumParameter * reg_enum_par(const string &id, const string &name, const value_pair *vl, int *var, int std=0)
Definition: gx_parameter.h:569
sigc::signal< void, float > changed
Definition: gx_parameter.h:234
FileParameter(const string &id, const string &filename, bool preset=false)
Definition: gx_parameter.h:395
Definition: bigknob.cc:41
ParameterV(const string &id, const string &name, ctrl_type ctp, bool preset, float *v, float sv, float lv, float uv, float tv, bool ctrl, bool no_init)
Definition: gx_parameter.h:252
ParameterV(const string &id, const string &name, Glib::ustring *v, const Glib::ustring &sv, bool preset=false)
Definition: gx_parameter.h:434
bool hasId(const char *p) const
Definition: gx_parameter.h:531
static const char * value_label(const value_pair &vp)
Definition: gx_parameter.h:193
ParameterV(const string &id, const string &name, ctrl_type ctp, bool preset, bool *v, bool sv, bool ctrl)
Definition: gx_parameter.h:362
ParameterV< Glib::ustring > StringParameter
Definition: gx_parameter.h:97
Glib::RefPtr< Gio::File > json_value
Definition: gx_parameter.h:382
const value_pair & get_pair()
Definition: gx_parameter.h:334
sigc::signal< void, const Glib::ustring & > changed
Definition: gx_parameter.h:423
EnumParameter * reg_non_midi_enum_par(const string &id, const string &name, const value_pair *vl, int *var, bool preset, int std=0)
Definition: gx_parameter.h:575
bool operator==(const Parameter &p) const
Definition: gx_parameter.h:181
void set_last_midi_control_value(unsigned int n, int v)
Definition: gx_parameter.h:768
sigc::signal< void, int > & signal_changed()
Definition: gx_parameter.h:320
iterator end() const
Definition: gx_parameter.h:529
StringParameter * reg_preset_string(const string &id, const string &name, Glib::ustring *var, const string &sv, bool preset=true)
Definition: gx_parameter.h:615