Guitarix
gx_preset.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 
21 /* --------------------------------------------------------------------------
22 
23  This is the gx_head preset handling functions
24 
25  ---------------------------------------------------------------------------*/
26 
27 #include <sys/stat.h>
28 
29 #include "engine.h" // NOLINT
30 
31 #ifndef SCHED_IDLE
32 #define SCHED_IDLE SCHED_OTHER // non-linux systems
33 #endif
34 
35 namespace gx_preset {
36 
37 /****************************************************************
38  ** class PresetIO
39  */
40 
43  gx_engine::ParamMap& param_,
45  UnitRacks& rack_units_)
46  : gx_system::AbstractPresetIO(),
47  mctrl(mctrl_),
48  convolver(cvr_),
49  param(param_),
50  opt(opt_),
51  plist(),
52  m(0),
53  rack_units(rack_units_) {
54 }
55 
57  clear();
58 }
59 
60 void PresetIO::clear() {
61  plist.clear();
62  delete m;
63  m = 0;
64 }
65 
66 bool PresetIO::midi_in_preset() {
67  const char *i = "system.midi_in_preset";
68  if (param.hasId(i)) {
69  return param[i].getBool().get_value();
70  } else {
71  return false;
72  }
73 }
74 
76  clear();
77  for (gx_engine::ParamMap::iterator i = param.begin(); i != param.end(); ++i) {
78  if (i->second->isInPreset() && i->second->isSavable()) {
79  i->second->stdJSON_value();
80  plist.push_back(i->second);
81  }
82  }
83  read_intern(jp, 0, head);
84 }
85 
86 void PresetIO::fixup_parameters(const gx_system::SettingsFileHeader& head) {
87  assert(param.hasId("jconv.wet_dry"));
88  if (head.is_current()) {
89  return;
90  }
91  if (head.get_major() == 1 && head.get_minor() < 2) {
92  if (param.hasId("jconv.wet_dry")) {
93  gx_engine::Parameter& p = param["jconv.wet_dry"];
94  if (p.isFloat()) {
95  p.getFloat().convert_from_range(-1, 1);
96  }
97  }
98  }
99 }
100 
101 static std::string replaced_id(const std::string& s) {
102  const char *old_new[][2] = {
103  { "beat_detector.stepper", "midi_out.beat_detector.stepper" },
104  { "beat_detector.note_off", "midi_out.beat_detector.note_off" },
105  { "beat_detector.atack_gain", "midi_out.beat_detector.atack_gain" },
106  { "beat_detector.beat_gain", "midi_out.beat_detector.beat_gain" },
107  { "beat_detector.midi_gain", "midi_out.beat_detector.midi_gain" },
108  // begin ui.*
109  // ui.<name> -> ui.<id> (rack unit visible)
110  { "ui.3 Band EQ", "ui.tonemodul" },
111  { "ui.BiQuad Filter", "ui.biquad" },
112  { "ui.Cabinet", "ui.cab" },
113  { "ui.Preamp", "ui.pre" },
114  { "ui.Chorus", "ui.chorus" },
115  { "ui.Chorus Mono", "ui.chorus_mono" },
116  { "ui.Compressor", "ui.compressor" },
117  { "ui.Convolver", "ui.jconv" },
118  { "ui.Crybaby", "ui.crybaby" },
119  { "ui.Delay", "ui.delay" },
120  { "ui.Echo", "ui.echo" },
121  { "ui.Feedback", "ui.feedback" },
122  { "ui.Flanger", "ui.flanger" },
123  { "ui.Flanger Mono", "ui.flanger_mono" },
124  { "ui.Freeverb", "ui.freeverb" },
125  { "ui.ImpulseResponse", "ui.IR" },
126  { "ui.Midi Out", "ui.midi_out" },
127  { "ui.Moog Filter", "ui.moog" },
128  { "ui.Multi Band Distortion", "ui.gx_distortion" },
129  { "ui.Oscilloscope", "ui.oscilloscope" },
130  { "ui.Overdrive", "ui.overdrive" },
131  { "ui.Phaser", "ui.phaser" },
132  { "ui.Phaser Mono", "ui.phaser_mono" },
133  { "ui.Postamp", "ui.ampmodul" },
134  { "ui.Scaleable EQ", "ui.eqs" },
135  { "ui.Stereo Delay", "ui.stereodelay" },
136  { "ui.Stereo Echo", "ui.stereoecho" },
137  { "ui.Stereo Verb", "ui.stereoverb" },
138  { "ui.Tonestack", "ui.amp.tonestack" },
139  { "ui.Tremolo", "ui.tremolo" },
140  { "ui.Vibe", "ui.univibe" },
141  { "ui.Vibe Mono", "ui.univibe_mono" },
142  { "ui.Zita Rev1", "ui.zita_rev1" },
143  { "ui.abGate", "ui.abgate" },
144  { "ui.low high pass", "ui.low_highpass" },
145  { "Rev.Rocket.s_h", "rev_rocket.s_h"},
146  { "Rev.Rocket.position", "rev_rocket.position"},
147  { "Rev.Rocket.pp", "rev_rocket.pp"},
148  { "ui.Rev.Rocket", "ui.rev_rocket"},
149  {0}
150  };
151  for (const char *(*p)[2] = old_new; (*p)[0]; ++p) {
152  if (s == (*p)[0]) {
153  return (*p)[1];
154  }
155  }
156  return "";
157 }
158 
160 public:
161  std::string id;
162  int weight;
163  UnitPositionID(const string& id_, const UnitPosition& u);
164  bool operator<(const UnitPositionID& v) const { return weight < v.weight; }
165 };
166 
167 UnitPositionID::UnitPositionID(const string& id_, const UnitPosition& u)
168  : UnitPosition(u),
169  id(id_),
170  weight(position - 1000 * pp) {
171 }
172 
173 void UnitsCollector::get_list(std::vector<std::string>& l, bool stereo, gx_engine::ParamMap& param) {
174  std::vector<UnitPositionID> v;
175  for (std::map<std::string,UnitPosition>::iterator i = m.begin(); i != m.end(); ++i) {
176  if (i->first == "jconv" && i->second.position < 0) {
177  i->second.position = 99; // very old presets
179  jp.get_ostream() << i->second.position;
180  jp.start_parser();
181  param[i->first+".position"].readJSON_value(jp);
182  }
183  if (i->first == "cab") {
184  if (i->second.position < 0) {
185  i->second.position = 98; // very old presets
187  jp.get_ostream() << i->second.position;
188  jp.start_parser();
189  param[i->first+".position"].readJSON_value(jp);
190  }
191  if (i->second.pp < 0) {
192  i->second.pp = 0;
194  jp.get_ostream() << i->second.pp;
195  jp.start_parser();
196  param[i->first+".pp"].readJSON_value(jp);
197  }
198  }
199  if (i->second.position >= 0 && i->second.show) {
200  if ((stereo && i->second.pp < 0) || (!stereo && i->second.pp >= 0)) {
201  if (!i->second.visible) { // make sure ui.XX is set for old presets
202  i->second.visible = true;
204  jp.put('1');
205  jp.start_parser();
206  param["ui."+i->first].readJSON_value(jp);
207  }
208  v.push_back(UnitPositionID(i->first, i->second));
209  }
210  }
211  }
212  l.clear();
213  std::sort(v.begin(), v.end());
214  int pp = 1;
215  for (std::vector<UnitPositionID>::iterator j = v.begin(); j != v.end(); ++j) {
216  if (!stereo && j->pp != pp) {
217  pp = j->pp;
218  l.push_back("ampstack");
219  }
220  l.push_back(j->id);
221  }
222  if (!stereo && pp) {
223  l.push_back("ampstack");
224  }
225  /*
226  cerr << "SL";
227  for (std::vector<std::string>::iterator ii = l.begin(); ii != l.end(); ++ii) {
228  cerr << " '" << *ii << "'";
229  }
230  cerr << endl;
231  */
232 }
233 
234 bool PresetIO::convert_old(gx_system::JsonParser &jp) {
235  const std::string& s = jp.current_value();
236  if (s == "system.mainwin_x") {
238  opt.mainwin_x = jp.current_value_int();
239  return true;
240  }
241  if (s == "system.mainwin_y") {
243  opt.mainwin_y = jp.current_value_int();
244  return true;
245  }
246  if (s == "system.mainwin_height") {
248  opt.mainwin_height = jp.current_value_int();
249  return true;
250  }
251  if (s == "system.mainwin_rack_height") {
253  opt.window_height = jp.current_value_int();
254  return true;
255  }
256  if (s == "system.preset_window_height") {
258  opt.preset_window_height = jp.current_value_int();
259  return true;
260  }
261  if (s == "oscilloscope.bufferset") {
263  opt.mul_buffer = jp.current_value_int();
264  return true;
265  }
266  if (s == "ui.skin_name") {
268  opt.skin_name = jp.current_value();
269  return true;
270  }
271  if (s == "ui.latency_nowarn") {
273  opt.no_warn_latency = jp.current_value_int();
274  return true;
275  }
276  if (s == "system.order_rack_h") {
278  opt.system_order_rack_h = jp.current_value_int();
279  return true;
280  }
281  if (s == "system.show_value") {
283  opt.system_show_value = jp.current_value_int();
284  return true;
285  }
286  if (s == "system.show_tooltips") {
288  opt.system_show_tooltips = jp.current_value_int();
289  return true;
290  }
291  if (s == "system.animations") {
293  opt.system_animations = jp.current_value_int();
294  return true;
295  }
296  if (s == "system.show_presets") {
298  opt.system_show_presets = jp.current_value_int();
299  return true;
300  }
301  if (s == "system.show_toolbar") {
303  opt.system_show_toolbar = jp.current_value_int();
304  return true;
305  }
306  if (s == "system.show_rack") {
308  opt.system_show_rack = jp.current_value_int();
309  return true;
310  }
311 
312  return false;
313 }
314 
315 static inline bool endswith(const std::string& s, int n, const char *t) {
316  return s.compare(std::max<int>(0, s.size()-n), n, t) == 0;
317 }
318 
319 static inline bool startswith(const std::string& s, int n, const char *t) {
320  return s.compare(0, n, t) == 0;
321 }
322 
323 void PresetIO::collectRackOrder(gx_engine::Parameter *p, gx_system::JsonParser &jp, UnitsCollector& u) {
324  const std::string& s = p->id();
325  if (startswith(s, 3, "ui.")) {
326  if (jp.current_value_int()) {
327  std::string ss = s.substr(3);
328  u.set_visible(ss, true);
329  u.set_show(ss, true);
330  }
331  } else if (endswith(s, 7, ".on_off")) {
332  if (jp.current_value_int()) {
333  u.set_show(s.substr(0, s.size()-7), true);
334  }
335  } else if (endswith(s, 9, ".position")) {
336  u.set_position(s.substr(0, s.size()-9), jp.current_value_int());
337  } else if (endswith(s, 3, ".pp")) {
338  u.set_pp(s.substr(0, s.size()-3), (jp.current_value() == "pre" ? 1 : 0));
339  }
340 }
341 
342 void PresetIO::read_parameters(gx_system::JsonParser &jp, bool preset) {
343  UnitsCollector u;
345  do {
348  if (!param.hasId(jp.current_value())) {
349  if (convert_old(jp)) {
350  continue;
351  }
352  std::string s = replaced_id(jp.current_value());
353  if (s.empty()) {
355  _("recall settings"),
356  _("unknown parameter: ")+jp.current_value());
357  jp.skip_object();
358  continue;
359  }
360  p = &param[s];
361  } else {
362  p = &param[jp.current_value()];
363  }
364  if (!preset and p->isInPreset()) {
366  _("recall settings"),
367  _("preset-parameter ")+p->id()+_(" in settings"));
368  jp.skip_object();
369  continue;
370  } else if (preset and !p->isInPreset()) {
372  _("recall settings"),
373  _("non preset-parameter ")+p->id()+_(" in preset"));
374  jp.skip_object();
375  continue;
376  } else if (!p->isSavable()) {
378  _("recall settings"),
379  _("non saveable parameter ")+p->id()+_(" in settings"));
380  jp.skip_object();
381  continue;
382  }
383  p->readJSON_value(jp);
384  collectRackOrder(p, jp, u);
385  } while (jp.peek() == gx_system::JsonParser::value_key);
387  u.get_list(rack_units.mono, false, param);
388  u.get_list(rack_units.stereo, true, param);
389 }
390 
391 void PresetIO::write_parameters(gx_system::JsonWriter &w, bool preset) {
392  w.begin_object(true);
393 #if 0
394  int n = 0;
395  int pp = 1;
396  for (std::vector<std::string>::iterator j = mono_rack_units.begin(); j != mono_rack_units.end(); ++j) {
397  if (*j == "ampstack") {
398  n = 1;
399  pp = 0;
400  }
401  w.write_key("ui."+*j);
402  w.write(1);
403  w.write_key(*j+".pp");
404  w.write(pp);
405  w.write_key(*j+".position");
406  w.write(n);
407  n++;
408  }
409 #endif
410  for (gx_engine::ParamMap::iterator i = param.begin();
411  i != param.end(); ++i) {
412  gx_engine::Parameter *param = i->second;
413  if (!param->isSavable()) {
414  continue;
415  }
416  if ((preset and param->isInPreset()) or(!preset and !param->isInPreset())) {
417  param->writeJSON(w);
418  w.newline();
419  }
420  }
421  w.end_object(true);
422 }
423 
424 
426  std::string NAME_;
427  std::string FILE_;
428  std::string INFO_;
429  std::string AUTHOR_;
430  ifstream is(opt.get_online_config_filename().c_str());
431  ofstream os(opt.get_online_presets_filename().c_str());
432  if (!is.fail() && !os.fail()) {
433  gx_system::JsonParser jp(&is);
434  try {
436  do {
438  do {
440  if (jp.current_value() == "name") {
441  jp.read_kv("name", NAME_);
442  } else if (jp.current_value() == "description") {
443  jp.read_kv("description", INFO_);
444  } else if (jp.current_value() == "author") {
445  jp.read_kv("author", AUTHOR_);
446  } else if (jp.current_value() == "file") {
447  jp.read_kv("file", FILE_);
448  INFO_ += "Author : " + AUTHOR_;
449  // olp.push_back(std::tuple<std::string,std::string,std::string>(NAME_,FILE_,INFO_));
450  os << "\n<<NAME>> \n" << NAME_ << "\n<<FILE>> \n" << FILE_ << "\n<<INFO>> \n" << INFO_ << "\n<<END>> \n" << "\n";
451  } else {
452  //gx_print_warning("read_online", "unknown key: " + jp.current_value());
453  jp.skip_object();
454  }
455  } while (jp.peek() == gx_system::JsonParser::value_key);
457  } while (jp.peek() == gx_system::JsonParser::begin_object);
458  } catch (gx_system::JsonException& e) {
459  cerr << "JsonException: " << e.what() << ": '" << jp.current_value() << "'" << endl;
460  assert(false);
461  }
462  is.close();
463  os.close();
464  } else {
465  gx_print_warning(_("load online"),_("fail to open: "));
466  }
467 }
468 
469 void PresetIO::read_intern(gx_system::JsonParser &jp, bool *has_midi, const gx_system::SettingsFileHeader& head) {
470  bool use_midi = (has_midi != 0) || midi_in_preset();
471  if (has_midi) {
472  *has_midi = false;
473  }
475  do {
477  if (jp.current_value() == "engine") {
478  read_parameters(jp, true);
479  } else if (jp.current_value() == "jconv") { // for backwards compatibility
480  dynamic_cast<gx_engine::JConvParameter*>(&param["jconv.convolver"])->readJSON_value(jp);
481  } else if (jp.current_value() == "seq") {
482  dynamic_cast<gx_engine::SeqParameter*>(&param["seq.sequencer"])->readJSON_value(jp);
483  fprintf(stderr,"seq.sequencer found\n");
484  } else if (jp.current_value() == "midi_controller") {
485  if (use_midi) {
486  m = new gx_engine::ControllerArray();
487  m->readJSON(jp, param);
488  if (has_midi) {
489  *has_midi = true;
490  }
491  } else {
492  jp.skip_object();
493  }
494  } else {
496  _("recall settings"),
497  _("unknown preset section: ") + jp.current_value());
498  jp.skip_object();
499  }
500  } while (jp.peek() == gx_system::JsonParser::value_key);
502  fixup_parameters(head);
503 }
504 
506  for (gx_engine::paramlist::iterator i = plist.begin(); i != plist.end(); ++i) {
507  (*i)->setJSON_value();
508  }
509  if (m) {
510  mctrl.set_controller_array(*m);
511  }
512  clear();
513  mctrl.update_from_controllers();
514 }
515 
516 void PresetIO::write_intern(gx_system::JsonWriter &w, bool write_midi) {
517  w.begin_object(true);
518  w.write_key("engine");
519  write_parameters(w, true);
520  if (write_midi) {
521  w.write_key("midi_controller");
522  mctrl.writeJSON(w);
523  }
524  w.newline();
525  w.end_object(true);
526 }
527 
529  write_intern(jw, midi_in_preset());
530 }
531 
533  gx_system::JsonWriter &jw) {
534  param.set_init_values();
535  bool has_midi;
536  clear();
537  read_intern(jp, &has_midi, head);
538  commit_preset();
539  write_intern(jw, has_midi);
540 }
541 
542 
543 /****************************************************************
544  ** class StateIO
545  */
546 
549  gx_jack::GxJack& jack_, gx_system::CmdlineOptions& opt_, UnitRacks& rack_units)
550  : PresetIO(mctrl, cvr, param, opt_, rack_units),
551  midi_std_control(mstdctr),
552  jack(jack_) {
553 }
554 
556 }
557 
559  clear();
560  for (gx_engine::ParamMap::iterator i = param.begin(); i != param.end(); ++i) {
561  if (i->second->isSavable()) {
562  i->second->stdJSON_value();
563  plist.push_back(i->second);
564  }
565  }
566  do {
568  if (jp.current_value() == "settings") {
569  read_parameters(jp, false);
570  } else if (jp.current_value() == "current_preset") {
571  read_intern(jp, 0, head);
572  } else if (jp.current_value() == "midi_controller") {
573  m = new gx_engine::ControllerArray();
574  m->readJSON(jp, param);
575  } else if (jp.current_value() == "midi_ctrl_names") {
576  midi_std_control.readJSON(jp);
577  } else if (jp.current_value() == "jack_connections") {
578  jack.read_connections(jp);
579  } else {
581  _("recall settings"),
582  _("unknown section: ") + jp.current_value());
583  jp.skip_object();
584  }
585  } while (jp.peek() == gx_system::JsonParser::value_string);
586 }
587 
589  commit_preset();
590 }
591 
592 void StateIO::write_state(gx_system::JsonWriter &jw, bool no_preset) {
593  jw.write("settings");
594  write_parameters(jw, false);
595 
596  jw.write("midi_controller");
597  mctrl.writeJSON(jw);
598 
599  jw.write("midi_ctrl_names");
600  midi_std_control.writeJSON(jw);
601 
602  if (!no_preset) {
603  jw.write("current_preset");
604  write_intern(jw, false);
605  }
606 
607  jw.write("jack_connections");
608  jack.write_connections(jw);
609 
610  jw.newline();
611 }
612 
613 
614 /****************************************************************
615  ** class PluginPresetList
616  */
617 
620  : filename(fname), pmap(pmap_), mctrl(mctrl_), is(), jp(&is) {
621 }
622 
624  is.close();
625  is.open(filename.c_str());
626  jp.set_streampos(0);
627  if (is.fail()) {
628  return false;
629  }
630  try {
633  if (jp.current_value() != "gx_plugin_version") {
634  throw gx_system::JsonException("invalid gx_plugin file header");
635  }
637  } catch (gx_system::JsonException& e) {
638  gx_print_error(filename.c_str(), _("parse error"));
639  return false;
640  }
641  return true;
642 }
643 
644 bool PluginPresetList::next(Glib::ustring& name, bool *is_set) {
645  try {
647  name = "";
648  if (is_set) {
649  *is_set = false;
650  }
651  return false;
652  }
654  name = jp.current_value();
655  if (is_set) {
657  *is_set = true;
658  while (jp.peek() != gx_system::JsonParser::end_object) {
660  if (!pmap.hasId(jp.current_value())) {
662  _("recall plugin settings"),
663  _("unknown parameter: ")+jp.current_value());
664  jp.skip_object();
665  continue;
666  }
667  gx_engine::Parameter& p = pmap[jp.current_value()];
668  p.readJSON_value(jp);
669  if (!p.compareJSON_value()) {
670  *is_set = false;
671  }
672  }
674  } else {
675  jp.skip_object();
676  }
677  } catch (gx_system::JsonException& e) {
678  gx_print_error(filename.c_str(), _("parse error"));
679  return false;
680  }
681  return true;
682 }
683 
684 bool PluginPresetList::set(const Glib::ustring& name) {
685  gx_engine::paramlist plist;
686  if (!start()) {
687  return false;
688  }
689  bool ret = false;
690  try {
691  while (jp.peek() != gx_system::JsonParser::end_array) {
693  if (jp.current_value() != name) {
694  jp.skip_object();
695  } else {
696  ret = true;
698  while (jp.peek() != gx_system::JsonParser::end_object) {
700  if (pmap.hasId(jp.current_value())) {
701  gx_engine::Parameter& p = pmap[jp.current_value()];
702  p.readJSON_value(jp);
703  plist.push_back(&p);
704  }
705  }
707  }
708  }
711  } catch (gx_system::JsonException& e) {
712  gx_print_error(filename.c_str(), _("parse error"));
713  return false;
714  }
715  mctrl.remove_controlled_parameters(plist, 0);
716  for (gx_engine::paramlist::iterator i = plist.begin(); i != plist.end(); ++i) {
717  (*i)->setJSON_value();
718  }
719  return ret;
720 }
721 
722 static const int GX_PLUGIN_VERSION = 1;
723 
724 static inline bool compare_groups(const std::string& id, const char **groups) { //FIXME (is copy from gx_paramtable.cpp
725  if (!groups) {
726  return false;
727  }
728  for (const char **g = groups; *g; g += 2) {
729  const char *p = *g;
730  if ((*p) != '.') {
731  continue;
732  }
733  p++;
734  int n = strlen(p);
735  if (strncmp(id.c_str(), p, n) == 0 && id[n] == '.') {
736  return true;
737  }
738  }
739  return false;
740 }
741 
742 void PluginPresetList::write_values(gx_system::JsonWriter& jw, std::string id, const char **groups) {
743  id += ".";
744  string on_off = id + "on_off";
745  string pp = id + "pp";
746  std::string position = id + "position";
747  jw.begin_object(true);
748  for (gx_engine::ParamMap::iterator i = pmap.begin(); i != pmap.end(); ++i) {
749  if (i->first.compare(0, id.size(), id) == 0 || compare_groups(i->first, groups)) {
750  if (i->second->isInPreset() && i->second->isSavable()) {
751  if (i->first != on_off && i->first != pp && i->first != position) {
752  i->second->writeJSON(jw);
753  jw.newline();
754  }
755  }
756  }
757  }
758  jw.end_object(true);
759 }
760 
761 void PluginPresetList::save(const Glib::ustring& name, const std::string& id, const char **groups) {
762  try {
763  std::string tmpfile(filename + "_tmp");
764  ofstream os(tmpfile.c_str());
765  gx_system::JsonWriter jw(&os);
766  jw.begin_array();
767  jw.write("gx_plugin_version");
768  jw.write(GX_PLUGIN_VERSION, true);
769  bool found = false;
770  if (start()) {
771  while (jp.peek() != gx_system::JsonParser::end_array) {
773  jw.write(jp.current_value());
774  if (jp.current_value() == name) {
775  found = true;
776  write_values(jw, id, groups);
777  jp.skip_object();
778  } else {
779  jp.copy_object(jw);
780  }
781  }
782  }
783  if (!found) {
784  jw.write(name);
785  write_values(jw, id, groups);
786  }
787  jw.end_array(true);
788  jw.close();
789  os.close();
790  if (!os.good()) {
791  gx_print_error(_("save plugin preset"),
792  boost::format(_("couldn't write %1%")) % tmpfile);
793  return;
794  }
795  int rc = rename(tmpfile.c_str(), filename.c_str());
796  if (rc != 0) {
797  gx_print_error(_("save plugin preset"),
798  boost::format(_("couldn't rename %1% to %2%"))
799  % tmpfile % filename);
800  }
801  } catch (gx_system::JsonException& e) {
802  gx_print_error(filename.c_str(), _("parse error"));
803  }
804 }
805 
806 bool PluginPresetList::remove(const Glib::ustring& name) {
807  bool ret = false;
808  if (start()) {
809  try {
810  std::string tmpfile(filename + "_tmp");
811  ofstream os(tmpfile.c_str());
812  gx_system::JsonWriter jw(&os);
813  jw.begin_array();
814  jw.write("gx_plugin_version");
815  jw.write(GX_PLUGIN_VERSION, true);
816  while (jp.peek() != gx_system::JsonParser::end_array) {
818  if (jp.current_value() == name) {
819  jp.skip_object();
820  ret = true;
821  } else {
822  jw.write(jp.current_value());
823  jp.copy_object(jw);
824  }
825  }
828  jw.end_array(true);
829  jw.close();
830  os.close();
831  if (!os.good()) {
832  gx_print_error(_("remove plugin preset"),
833  boost::format(_("couldn't write %1%")) % tmpfile);
834  return false;
835  }
836  int rc = rename(tmpfile.c_str(), filename.c_str());
837  if (rc != 0) {
838  gx_print_error(_("remove plugin preset"),
839  boost::format(_("couldn't rename %1% to %2%"))
840  % tmpfile % filename);
841  return false;
842  }
843  } catch (gx_system::JsonException& e) {
844  gx_print_error(filename.c_str(), _("parse error"));
845  }
846  return ret;
847  } else {
848  return false;
849  }
850 }
851 
852 
853 /****************************************************************
854  ** GxSettings
855  */
856 
857 static const char *scratchpad_name = N_("Scratchpad");
858 static const char *scratchpad_file = "scratchpad.gx";
859 static const char *statename_postfix = "_rc";
860 static const char *bank_list = "banklist.js";
861 
865  : sigc::trackable(),
866  GxSettingsBase(seq_),
867  param(seq_.get_param()),
868  preset_io(mctrl_, cvr, param, opt, rack_units),
869  state_io(mctrl_, cvr, param, mstdctr, jack_, opt, rack_units),
870  state_loaded(false),
871  no_autosave(false),
872  jack(jack_),
873  mctrl(mctrl_),
874  options(opt),
875  preset_parameter(*param.reg_string("system.current_preset", "?", &current_name, "")),
876  bank_parameter(*param.reg_string("system.current_bank", "?", &current_bank, "")),
877  sync_name(""),
878  set_preset(),
879  get_sequencer_p(),
880  sequencer_max(24),
881  sequencer_pos(0) {
882  set_io(&state_io, &preset_io);
883  statefile.set_filename(make_default_state_filename());
884  banks.parse(opt.get_preset_filepath(bank_list), opt.get_preset_dir(), opt.get_factory_dir(),
885  scratchpad_name, scratchpad_file);
886  instance = this;
887  GxExit::get_instance().signal_exit().connect(
888  sigc::mem_fun(*this, &GxSettings::exit_handler));
889  jack.signal_client_change().connect(
890  sigc::mem_fun(*this, &GxSettings::jack_client_changed));
891  set_preset.connect(sigc::mem_fun(*this, &GxSettings::preset_sync_set));
892  get_sequencer_p.connect(sigc::mem_fun(*this, &GxSettings::on_get_sequencer_pos));
893 }
894 
895 GxSettings *GxSettings::instance = 0;
896 
898  instance = 0;
899  auto_save_state();
900 }
901 
903  if (state_loaded) {
904  if (setting_is_preset()) {
907  !pf->get_flags()) {
908  save(*pf, current_name);
909  }
910  }
911  if (!no_autosave) {
912  save_to_state();
913  }
914  }
915 }
916 
917 void GxSettings::exit_handler(bool otherthread) {
918  if (otherthread) {
919  return;
920  }
921  auto_save_state();
922 }
923 
924 void GxSettings::jack_client_changed() {
925  string fn = make_state_filename();
926  if (state_loaded && fn == statefile.get_filename()) {
928  return;
929  }
930  if (!state_loaded && access(fn.c_str(), R_OK|W_OK) != 0) {
931  string defname = make_default_state_filename();
932  if (access(defname.c_str(), R_OK) == 0) {
933  statefile.set_filename(defname);
934  loadsetting(0, "");
935  }
936  }
938  loadstate();
939 }
940 
941 string GxSettings::make_default_state_filename() {
942  if (!options.get_loadfile().empty()) {
943  return options.get_loadfile();
944  }
945  std::string s = options.get_jack_instancename();
946  if (!s.empty()) {
947  s = options.get_user_filepath(s + statename_postfix);
948  if (access(s.c_str(), R_OK|W_OK) == 0) {
949  return s;
950  }
951  }
952  return options.get_user_filepath(
953  jack.get_default_instancename() + statename_postfix);
954 }
955 
956 string GxSettings::make_state_filename() {
957  if (!options.get_loadfile().empty()) {
958  return options.get_loadfile();
959  }
960  return options.get_user_filepath(
961  jack.get_instancename() + statename_postfix);
962 }
963 
964 bool GxSettings::check_create_config_dir(const Glib::ustring& dir) {
965  if (access((Glib::build_filename(dir, ".")).c_str(), R_OK|W_OK|X_OK) != 0) {
966  if (errno != ENOENT) {
967  throw GxFatalError(
968  boost::format(_("no read/write access in guitarix config dir '%1%'"))
969  % dir);
970  }
971  if (mkdir(dir.c_str(), 0777) != 0) {
972  throw GxFatalError(
973  boost::format(_("can't create guitarix config dir '%1%'"))
974  % dir);
975  }
976  return true;
977  }
978  return false;
979 }
980 
982  save(*banks.get_file(scratchpad_name), "livebuffer1");
983 }
984 
985 static inline std::vector<std::string>::iterator find_unit(std::vector<std::string>& r, const std::string& unit) {
986  std::vector<std::string>::iterator i = r.begin();
987  for (; i != r.end(); ++i) {
988  if (unit == *i) {
989  break;
990  }
991  }
992  return i;
993 }
994 
995 bool GxSettings::remove_rack_unit(const std::string& unit, bool stereo) {
996  std::vector<std::string>& r = stereo ? rack_units.stereo : rack_units.mono;
997  std::vector<std::string>::iterator i = find_unit(r, unit);
998  if (i != r.end()) {
999  r.erase(i);
1000  return true;
1001  }
1002  return false;
1003 }
1004 
1005 void GxSettings::insert_rack_unit(const std::string& unit, const std::string& before, bool stereo) {
1006  std::vector<std::string>& r = stereo ? rack_units.stereo : rack_units.mono;
1007  remove_rack_unit(unit, stereo);
1008  if (before.empty()) {
1009  r.push_back(unit);
1010  } else {
1011  r.insert(find_unit(r, before), unit);
1012  }
1013 }
1014 
1015 Glib::RefPtr<Gio::File> GxSettings::uri_to_name_filename(const Glib::ustring& uri, Glib::ustring& name, std::string& filename) {
1016  Glib::RefPtr<Gio::File> rem = Gio::File::create_for_uri(uri);
1017  filename = rem->get_basename();
1018  banks.strip_preset_postfix(filename);
1019  name = gx_system::decode_filename(filename);
1020  banks.make_valid_utf8(name);
1021  banks.make_bank_unique(name, &filename);
1022  return rem;
1023 }
1024 
1025 gx_system::PresetFile* GxSettings::bank_insert_uri(const Glib::ustring& uri, bool move) {
1026  Glib::ustring name;
1027  std::string filename;
1028  Glib::RefPtr<Gio::File> rem = uri_to_name_filename(uri, name, filename);
1029  Glib::RefPtr<Gio::File> dest = Gio::File::create_for_path(filename);
1030  try {
1031  rem->copy(dest);
1032  } catch (Gio::Error& e) {
1033  gx_print_error(e.what().c_str(), _("can't copy to config dir"));
1034  return 0;
1035  }
1037  if (f->open_file(name, filename, gx_system::PresetFile::PRESET_FILE, 0)) {
1038  banks.insert(f);
1039  } else {
1040  delete f;
1041  try {
1042  dest->remove();
1043  } catch (Gio::Error& e) {
1044  gx_print_error(e.what().c_str(), _("can't remove copied file!?"));
1045  }
1046  return 0;
1047  }
1048  if (move) {
1049  try {
1050  rem->remove();
1051  } catch (Gio::Error& e) {
1052  gx_print_error(e.what().c_str(), _("can't move; file has been copied"));
1053  }
1054  }
1055  return f;
1056 }
1057 
1058 gx_system::PresetFile* GxSettings::bank_insert_content(const Glib::ustring& uri, const std::string content) {
1059  Glib::ustring name;
1060  std::string filename;
1061  uri_to_name_filename(uri, name, filename);
1062  Glib::RefPtr<Gio::File> dest = Gio::File::create_for_path(filename);
1063  try {
1064  Glib::RefPtr<Gio::FileOutputStream> s = dest->create_file();
1065  s->write(content);
1066  s->close();
1067  } catch (Gio::Error& e) {
1068  gx_print_error(e.what().c_str(), _("can't bank"));
1069  return 0;
1070  }
1072  if (f->open_file(name, filename, gx_system::PresetFile::PRESET_FILE, 0)) {
1073  banks.insert(f);
1074  } else {
1075  delete f;
1076  try {
1077  dest->remove();
1078  } catch (Gio::Error& e) {
1079  gx_print_error(e.what().c_str(), _("can't remove copied file!?"));
1080  }
1081  return 0;
1082  }
1083  return f;
1084 }
1085 
1087  Glib::ustring newname = name;
1088  std::string newfile;
1089  banks.make_bank_unique(newname, &newfile);
1091  if (f->create_file(newname, newfile, gx_system::PresetFile::PRESET_FILE, 0)) {
1092  banks.insert(f);
1093  return f;
1094  } else {
1095  delete f;
1096  return 0;
1097  }
1098 }
1099 
1100 bool GxSettings::rename_bank(const Glib::ustring& oldname, Glib::ustring& newname) {
1101  std::string newfile;
1102  banks.make_bank_unique(newname, &newfile);
1103  return GxSettingsBase::rename_bank(oldname, newname, newfile);
1104 }
1105 
1106 //static
1108  bool copied_from_old = false;
1109  std::string oldpreset;
1110  *need_new_preset = false;
1111  if (check_create_config_dir(opt.get_user_dir())) {
1112  check_create_config_dir(opt.get_preset_dir());
1113  check_create_config_dir(opt.get_plugin_dir());
1114  check_create_config_dir(opt.get_pluginpreset_dir());
1115  check_create_config_dir(opt.get_lv2_preset_dir());
1116  check_create_config_dir(opt.get_loop_dir());
1117  check_create_config_dir(opt.get_user_IR_dir());
1118  check_create_config_dir(opt.get_temp_dir());
1119  std::string fname = gx_jack::GxJack::get_default_instancename() + statename_postfix;
1120  if (access(Glib::build_filename(opt.get_old_user_dir(), fname).c_str(), R_OK) == 0) {
1121  copied_from_old = true;
1122  Glib::RefPtr<Gio::File> f = Gio::File::create_for_path(
1123  Glib::build_filename(opt.get_old_user_dir(), fname));
1124  try {
1125  f->copy(Gio::File::create_for_path(opt.get_user_filepath(fname)));
1126  } catch (Gio::Error& e) {
1127  gx_print_error(e.what().c_str(), _("can't copy to new config dir"));
1128  }
1129  }
1130  fname = Glib::build_filename(
1131  opt.get_old_user_dir(),
1133  if (access(fname.c_str(), R_OK) == 0) {
1134  Glib::RefPtr<Gio::File> f = Gio::File::create_for_path(fname);
1135  oldpreset = opt.get_preset_filepath("oldpresets.gx");
1136  try {
1137  f->copy(Gio::File::create_for_path(oldpreset));
1138  } catch (Gio::Error& e) {
1139  gx_print_error(e.what().c_str(), _("can't copy to new config preset dir"));
1140  oldpreset = "";
1141  }
1142  }
1143  } else {
1144  check_create_config_dir(opt.get_preset_dir());
1145  check_create_config_dir(opt.get_plugin_dir());
1146  check_create_config_dir(opt.get_pluginpreset_dir());
1147  check_create_config_dir(opt.get_lv2_preset_dir());
1148  check_create_config_dir(opt.get_loop_dir());
1149  check_create_config_dir(opt.get_user_IR_dir());
1150  check_create_config_dir(opt.get_temp_dir());
1151  }
1152  std::string fname = opt.get_preset_filepath(scratchpad_file);
1153  if (access(fname.c_str(), R_OK) != 0) {
1155  throw GxFatalError(
1156  boost::format(_("can't create file in '%1%' !!??")) % opt.get_preset_dir());
1157  }
1158  *need_new_preset = true;
1159  }
1160  fname = opt.get_preset_filepath(bank_list);
1161  if (access(fname.c_str(), R_OK) != 0) {
1162  ofstream f(fname.c_str());
1163  if (!f.good()) {
1164  throw GxFatalError(
1165  boost::format(_("can't create '%1%' in directory '%2%'"))
1166  % bank_list % opt.get_preset_dir());
1167  }
1169  pre.open_file(scratchpad_name, opt.get_preset_filepath(scratchpad_file), gx_system::PresetFile::PRESET_SCRATCH, 0);
1170  gx_system::JsonWriter jw(&f);
1171  jw.begin_array(true);
1172  pre.writeJSON(jw);
1173  if (!oldpreset.empty() && pre.open_file("copied presets", oldpreset, gx_system::PresetFile::PRESET_FILE, 0)) {
1174  pre.writeJSON(jw);
1175  }
1176  jw.end_array(true);
1177  jw.close();
1178  f.close();
1179  }
1180  return copied_from_old;
1181 }
1182 
1184  GxSettingsBase::loadstate();
1185 #if 0
1186  /* This following code is commented out because
1187  **
1188  ** o its debatable which of state file or scratch preset should have
1189  ** priority in case both differ because 2 different instantiations
1190  ** accessed the same scratch preset but different statefiles.
1191  **
1192  ** o if the scratch preset has priority, the autosave function would
1193  ** have to save to statefile *and* scratch preset (in case of the
1194  ** current preset being a scratch preset).
1195  **
1196  ** As an aside: load_preset() would have to be changed to not save
1197  ** to the scratch preset before loading in the case that this code
1198  ** is activated.
1199  */
1200  if (setting_is_preset()) {
1202  if (pf && pf->get_type() == gx_system::PresetFile::PRESET_SCRATCH) {
1203  /* make sure we see the content of the scratchpad,
1204  ** not the state file (in case someone changed the
1205  ** scratchpad while working with a different state file)
1206  */
1208  }
1209  }
1210 #endif
1211  state_loaded = true;
1212 }
1213 
1214 void GxSettings::add_plugin_preset_list(gx_preset::PluginPresetList& l,
1215  UnitPresetList &presetnames) {
1216  if (l.start()) {
1217  Glib::ustring name;
1218  bool is_set;
1219  while (l.next(name, &is_set)) {
1220  presetnames.push_back(PluginPresetEntry(name, is_set));
1221  }
1222  }
1223 }
1224 
1226  PluginPresetList lv2sets(options.get_lv2_preset_filepath(pdef->id), param, mctrl);
1227  add_plugin_preset_list(lv2sets, presetnames);
1228  PluginPresetList user(options.get_pluginpreset_filepath(pdef->id, false), param, mctrl);
1229  add_plugin_preset_list(user, presetnames);
1230  presetnames.push_back(PluginPresetEntry("", false));
1231  PluginPresetList factory(options.get_pluginpreset_filepath(pdef->id, true), param, mctrl);
1232  add_plugin_preset_list(factory, presetnames);
1233 }
1234 
1235 void GxSettings::preset_sync_set() {
1236  PluginPresetList(options.get_pluginpreset_filepath("seq", false), param, mctrl).set(sync_name);
1237 }
1238 
1239 void GxSettings::on_get_sequencer_pos() {
1240  gx_system::atomic_set(&sequencer_pos,(int)param["seq.step"].getFloat().get_value());
1241 }
1242 
1243 void *GxSettings::sync_run() {
1244  while (true) {
1245  get_sequencer_p();
1246  usleep(50000);
1247  if (gx_system::atomic_get(sequencer_pos) == 0) {
1248  set_preset();
1249  break;
1250  }
1251  }
1252  return NULL;
1253 }
1254 
1255 void *GxSettings::preset_sync_run(void *p) {
1256  struct sched_param spar;
1257  spar.sched_priority = 0;
1258  pthread_setschedparam(pthread_self(), SCHED_IDLE, &spar);
1259  (reinterpret_cast< GxSettings*>(p))->sync_run();
1260  pthread_exit(NULL);
1261  return NULL;
1262 }
1263 
1264 void GxSettings::plugin_preset_list_sync_set(const PluginDef *pdef, bool factory, const Glib::ustring& name) {
1265  if(strcmp(pdef->id,"seq")==0) {
1266  sync_name = name;
1267  pthread_t pthr;
1268  gx_system::atomic_set(&sequencer_max,(int)param["seq.asequences"].getFloat().get_value()-1);
1269  if (pthread_create(&pthr, NULL, preset_sync_run, reinterpret_cast<void*>(this))) {
1270  gx_print_error("GxSettings sync", _("can't create thread"));
1271  }
1272  }
1273 }
1274 
1275 void GxSettings::plugin_preset_list_set(const PluginDef *pdef, bool factory, const Glib::ustring& name) {
1276  if (!PluginPresetList(options.get_pluginpreset_filepath(pdef->id, factory), param, mctrl).set(name))
1277  PluginPresetList(options.get_lv2_preset_filepath(pdef->id), param, mctrl).set(name);
1278 }
1279 
1280 void GxSettings::plugin_preset_list_save(const PluginDef *pdef, const Glib::ustring& name) {
1281  PluginPresetList(options.get_pluginpreset_filepath(pdef->id, false), param, mctrl).save(name, pdef->id, pdef->groups);
1282 }
1283 
1284 void GxSettings::plugin_preset_list_remove(const PluginDef *pdef, const Glib::ustring& name) {
1285  // remove loop files when delete a plugin preset
1286  if(strcmp(pdef->id,"dubber")==0) {
1287  std::string pPath = options.get_loop_dir();
1288  pPath += name;
1289  std::remove((pPath + "1.wav").c_str());
1290  std::remove((pPath + "2.wav").c_str());
1291  std::remove((pPath + "3.wav").c_str());
1292  std::remove((pPath + "4.wav").c_str());
1293  }
1294  if (!PluginPresetList(options.get_pluginpreset_filepath(pdef->id, false), param, mctrl).remove(name))
1295  PluginPresetList(options.get_lv2_preset_filepath(pdef->id), param, mctrl).remove(name);
1296 }
1297 
1298 
1299 /* ----------------------------------------------------------------*/
1300 } /* end of gx_preset namespace */
void write_state(gx_system::JsonWriter &jw, bool preserve_preset)
Definition: gx_preset.cpp:592
void set_pp(const std::string &s, bool v)
Definition: gx_preset.h:60
gx_system::PresetFile * bank_insert_uri(const Glib::ustring &uri, bool move)
Definition: gx_preset.cpp:1025
void set_io(AbstractStateIO *st, AbstractPresetIO *pr)
Definition: gx_json.h:474
void begin_array(bool nl=false)
Definition: gx_json.cpp:184
Definition: gx_preset.h:128
void save(PresetFile &pf, const Glib::ustring &name)
Definition: gx_json.cpp:1891
PresetFile * get_current_bank_file()
Definition: gx_json.h:483
const std::string & get_preset_dir() const
Definition: gx_system.h:475
void set_show(const std::string &s, bool v)
Definition: gx_preset.h:57
void make_bank_unique(Glib::ustring &name, std::string *file=0)
Definition: gx_json.cpp:1458
bool remove_rack_unit(const std::string &unit, bool stereo)
Definition: gx_preset.cpp:995
std::ostream & get_ostream()
Definition: gx_json.h:208
std::string get_pluginpreset_filepath(const std::string &id, bool factory) const
Definition: gx_system.h:469
map< string, Parameter * >::const_iterator iterator
Definition: gx_parameter.h:533
#define SCHED_IDLE
Definition: gx_preset.cpp:32
list< Parameter * > paramlist
Definition: gx_parameter.h:221
void set_visible(const std::string &s, bool v)
Definition: gx_preset.h:58
void create_default_scratch_preset()
Definition: gx_preset.cpp:981
void insert(PresetFile *f)
Definition: gx_json.h:449
void end_array(bool nl=false)
Definition: gx_json.cpp:192
void set_streampos(streampos pos)
Definition: gx_json.cpp:571
const Glib::ustring & get_jack_instancename() const
Definition: gx_system.h:498
void read_connections(gx_system::JsonParser &jp)
Definition: gx_jack.cpp:159
void write_preset(gx_system::JsonWriter &jw)
Definition: gx_preset.cpp:528
void read_preset(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader &)
Definition: gx_preset.cpp:75
std::vector< PluginPresetEntry > UnitPresetList
Definition: gx_preset.h:135
#define N_(String)
PresetIO(gx_engine::MidiControllerList &mctrl, gx_engine::ConvolverAdapter &cvr, gx_engine::ParamMap &param, gx_system::CmdlineOptions &opt, UnitRacks &rack_units)
Definition: gx_preset.cpp:41
sigc::signal< void > selection_changed
Definition: gx_json.h:469
virtual void readJSON_value(gx_system::JsonParser &jp)=0
PresetFile * get_file(const Glib::ustring &bank) const
Definition: gx_json.cpp:1623
void read_state(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader &)
Definition: gx_preset.cpp:558
bool isSavable() const
Definition: gx_parameter.h:171
std::string get_lv2_preset_filepath(const std::string &id) const
Definition: gx_system.h:471
virtual void writeJSON(gx_system::JsonWriter &jw) const =0
bool rename_bank(const Glib::ustring &oldname, Glib::ustring &newname)
Definition: gx_preset.cpp:1100
std::vector< std::string > mono
Definition: gx_preset.h:38
iterator end() const
Definition: gx_parameter.h:535
int get_type() const
Definition: gx_json.h:361
const std::string & get_loop_dir() const
Definition: gx_system.h:478
void write_key(const char *p, bool nl=false)
Definition: gx_json.cpp:200
static bool check_settings_dir(gx_system::CmdlineOptions &opt, bool *need_new_preset)
Definition: gx_preset.cpp:1107
const char ** groups
Definition: gx_plugin.h:189
int atomic_get(volatile int &p)
Definition: gx_system.h:98
void save(const Glib::ustring &name, const std::string &id, const char **groups)
Definition: gx_preset.cpp:761
std::string decode_filename(const std::string &s)
Definition: gx_system.cpp:1048
virtual bool compareJSON_value()=0
void copy_preset(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader &, gx_system::JsonWriter &jw)
Definition: gx_preset.cpp:532
bool open_file(const Glib::ustring &name, const std::string &path, int tp, int flags)
Definition: gx_json.cpp:980
void parse(const std::string &bank_path, const std::string &preset_dir, const std::string &factory_path, const char *scratchpad_name, const char *scratchpad_file)
Definition: gx_json.cpp:1424
void gx_print_error(const char *, const std::string &)
Definition: gx_logging.cpp:166
bool read_kv(const char *key, float &v)
Definition: gx_json.cpp:511
static string get_default_instancename()
Definition: gx_jack.cpp:46
static bool make_empty_settingsfile(const string &name)
Definition: gx_json.cpp:684
gx_system::PresetFile * bank_insert_new(const Glib::ustring &name)
Definition: gx_preset.cpp:1086
static bool strip_preset_postfix(std::string &name)
Definition: gx_json.cpp:1450
void plugin_preset_list_load(const PluginDef *pdef, UnitPresetList &presetnames)
Definition: gx_preset.cpp:1225
bool remove(const Glib::ustring &name)
Definition: gx_preset.cpp:806
StateIO(gx_engine::MidiControllerList &mctrl, gx_engine::ConvolverAdapter &cvr, gx_engine::ParamMap &param, gx_engine::MidiStandardControllers &mstdctr, gx_jack::GxJack &jack, gx_system::CmdlineOptions &opt, UnitRacks &rack_units)
Definition: gx_preset.cpp:547
const char * id
Definition: gx_plugin.h:187
bool isFloat() const
Definition: gx_parameter.h:163
bool hasId(const string &id) const
Definition: gx_parameter.h:536
void plugin_preset_list_save(const PluginDef *pdef, const Glib::ustring &name)
Definition: gx_preset.cpp:1280
void set_filename(const string &fn)
Definition: gx_json.cpp:746
virtual void close()
Definition: gx_json.cpp:68
void insert_rack_unit(const std::string &unit, const std::string &before, bool stereo)
Definition: gx_preset.cpp:1005
void write_connections(gx_system::JsonWriter &w)
Definition: gx_jack.cpp:219
std::vector< std::string > stereo
Definition: gx_preset.h:39
void begin_object(bool nl=false)
Definition: gx_json.cpp:168
void plugin_preset_list_sync_set(const PluginDef *pdef, bool factory, const Glib::ustring &name)
Definition: gx_preset.cpp:1264
const std::string & get_pluginpreset_dir() const
Definition: gx_system.h:476
string get_filename() const
Definition: gx_json.h:268
bool next(Glib::ustring &name, bool *is_set=0)
Definition: gx_preset.cpp:644
static GxExit & get_instance()
Definition: gx_logging.cpp:205
bool isInPreset() const
Definition: gx_parameter.h:170
void load_preset(PresetFile *pf, const Glib::ustring &name)
Definition: gx_json.cpp:1770
void read_online(gx_system::JsonParser &jp)
Definition: gx_preset.cpp:425
void copy_object(JsonWriter &jw)
Definition: gx_json.cpp:580
virtual const char * what() const
Definition: gx_json.h:46
UnitPositionID(const string &id_, const UnitPosition &u)
Definition: gx_preset.cpp:167
const std::string & get_factory_dir() const
Definition: gx_system.h:480
FloatParameter & getFloat()
Definition: gx_parameter.h:453
void gx_print_warning(const char *, const std::string &)
Definition: gx_logging.cpp:161
void set_position(const std::string &s, int v)
Definition: gx_preset.h:59
const std::string & get_temp_dir() const
Definition: gx_system.h:479
const std::string & get_old_user_dir() const
Definition: gx_system.h:473
sigc::signal< void, bool > & signal_exit()
Definition: gx_logging.h:116
const string & get_instancename()
Definition: gx_jack.h:202
void writeJSON(gx_system::JsonWriter &jw) const
std::string get_user_filepath(const std::string &basename) const
Definition: gx_system.h:371
void atomic_set(volatile int *p, int v)
Definition: gx_system.h:90
Glib::ustring current_name
Definition: gx_json.h:467
string current_value() const
Definition: gx_json.h:143
iterator begin() const
Definition: gx_parameter.h:534
sigc::signal< void > & signal_client_change()
Definition: gx_jack.h:211
bool set(const Glib::ustring &name)
Definition: gx_preset.cpp:684
void readJSON(gx_system::JsonParser &jp)
Glib::ustring current_bank
Definition: gx_json.h:466
const std::string & get_lv2_preset_dir() const
Definition: gx_system.h:477
void plugin_preset_list_remove(const PluginDef *pdef, const Glib::ustring &name)
Definition: gx_preset.cpp:1284
GxSettings(gx_system::CmdlineOptions &opt, gx_jack::GxJack &jack, gx_engine::ConvolverAdapter &cvr, gx_engine::MidiStandardControllers &mstdctr, gx_engine::MidiControllerList &mctrl, gx_engine::ModuleSequencer &seq)
Definition: gx_preset.cpp:862
int get_flags() const
Definition: gx_json.h:358
const std::string & get_loadfile() const
Definition: gx_system.h:497
std::string get_preset_filepath(const std::string &basename) const
Definition: gx_system.h:465
const std::string & get_user_dir() const
Definition: gx_system.h:374
token next(token expect=no_token)
Definition: gx_json.cpp:496
PluginPresetList(const std::string &fname, gx_engine::ParamMap &pmap, gx_engine::MidiControllerList &mctrl_)
Definition: gx_preset.cpp:618
void write(float v, bool nl=false)
Definition: gx_json.cpp:116
const string & id() const
Definition: gx_parameter.h:173
bool operator<(const UnitPositionID &v) const
Definition: gx_preset.cpp:164
static void make_valid_utf8(Glib::ustring &s)
Definition: gx_json.cpp:1435
void get_list(std::vector< std::string > &l, bool stereo, gx_engine::ParamMap &param)
Definition: gx_preset.cpp:173
Glib::RefPtr< Gio::File > uri_to_name_filename(const Glib::ustring &uri, Glib::ustring &name, std::string &filename)
Definition: gx_preset.cpp:1015
const std::string & get_plugin_dir() const
Definition: gx_system.h:474
bool create_file(const Glib::ustring &name, const std::string &path, int tp, int flags)
Definition: gx_json.cpp:994
bool loadsetting(PresetFile *p, const Glib::ustring &name)
Definition: gx_json.cpp:1719
gx_system::PresetFile * bank_insert_content(const Glib::ustring &uri, const std::string content)
Definition: gx_preset.cpp:1058
void convert_from_range(float low, float up)
void remove_controlled_parameters(paramlist &plist, const ControllerArray *m)
void end_object(bool nl=false)
Definition: gx_json.cpp:176
void save_to_state(bool preserve_preset=false)
Definition: gx_json.cpp:1830
void plugin_preset_list_set(const PluginDef *pdef, bool factory, const Glib::ustring &name)
Definition: gx_preset.cpp:1275
const std::string & get_user_IR_dir() const
Definition: gx_system.h:375