49 rack_units(rack_units_) {
56 void PresetIO::clear() {
62 bool PresetIO::midi_in_preset() {
63 const char *i =
"system.midi_in_preset";
65 return param[i].getBool().get_value();
74 if (i->second->isInPreset() && i->second->isSavable()) {
75 i->second->stdJSON_value();
76 plist.push_back(i->second);
79 read_intern(jp, 0, head);
83 assert(param.
hasId(
"jconv.wet_dry"));
88 if (param.
hasId(
"jconv.wet_dry")) {
97 static std::string replaced_id(
const std::string& s) {
98 const char *old_new[][2] = {
99 {
"beat_detector.stepper",
"midi_out.beat_detector.stepper" },
100 {
"beat_detector.note_off",
"midi_out.beat_detector.note_off" },
101 {
"beat_detector.atack_gain",
"midi_out.beat_detector.atack_gain" },
102 {
"beat_detector.beat_gain",
"midi_out.beat_detector.beat_gain" },
103 {
"beat_detector.midi_gain",
"midi_out.beat_detector.midi_gain" },
106 {
"ui.3 Band EQ",
"ui.tonemodul" },
107 {
"ui.BiQuad Filter",
"ui.biquad" },
108 {
"ui.Cabinet",
"ui.cab" },
109 {
"ui.Preamp",
"ui.pre" },
110 {
"ui.Chorus",
"ui.chorus" },
111 {
"ui.Chorus Mono",
"ui.chorus_mono" },
112 {
"ui.Compressor",
"ui.compressor" },
113 {
"ui.Convolver",
"ui.jconv" },
114 {
"ui.Crybaby",
"ui.crybaby" },
115 {
"ui.Delay",
"ui.delay" },
116 {
"ui.Echo",
"ui.echo" },
117 {
"ui.Feedback",
"ui.feedback" },
118 {
"ui.Flanger",
"ui.flanger" },
119 {
"ui.Flanger Mono",
"ui.flanger_mono" },
120 {
"ui.Freeverb",
"ui.freeverb" },
121 {
"ui.ImpulseResponse",
"ui.IR" },
122 {
"ui.Midi Out",
"ui.midi_out" },
123 {
"ui.Moog Filter",
"ui.moog" },
124 {
"ui.Multi Band Distortion",
"ui.gx_distortion" },
125 {
"ui.Oscilloscope",
"ui.oscilloscope" },
126 {
"ui.Overdrive",
"ui.overdrive" },
127 {
"ui.Phaser",
"ui.phaser" },
128 {
"ui.Phaser Mono",
"ui.phaser_mono" },
129 {
"ui.Postamp",
"ui.ampmodul" },
130 {
"ui.Scaleable EQ",
"ui.eqs" },
131 {
"ui.Stereo Delay",
"ui.stereodelay" },
132 {
"ui.Stereo Echo",
"ui.stereoecho" },
133 {
"ui.Stereo Verb",
"ui.stereoverb" },
134 {
"ui.Tonestack",
"ui.amp.tonestack" },
135 {
"ui.Tremolo",
"ui.tremolo" },
136 {
"ui.Vibe",
"ui.univibe" },
137 {
"ui.Vibe Mono",
"ui.univibe_mono" },
138 {
"ui.Zita Rev1",
"ui.zita_rev1" },
139 {
"ui.abGate",
"ui.abgate" },
140 {
"ui.low high pass",
"ui.low_highpass" },
141 {
"Rev.Rocket.s_h",
"rev_rocket.s_h"},
142 {
"Rev.Rocket.position",
"rev_rocket.position"},
143 {
"Rev.Rocket.pp",
"rev_rocket.pp"},
144 {
"ui.Rev.Rocket",
"ui.rev_rocket"},
147 for (
const char *(*p)[2] = old_new; (*p)[0]; ++p) {
166 weight(position - 1000 * pp) {
170 std::vector<UnitPositionID> v;
171 for (std::map<std::string,UnitPosition>::iterator i = m.begin(); i != m.end(); ++i) {
172 if (i->first ==
"jconv" && i->second.position < 0) {
173 i->second.position = 99;
177 param[i->first+
".position"].readJSON_value(jp);
179 if (i->first ==
"cab") {
180 if (i->second.position < 0) {
181 i->second.position = 98;
185 param[i->first+
".position"].readJSON_value(jp);
187 if (i->second.pp < 0) {
192 param[i->first+
".pp"].readJSON_value(jp);
195 if (i->second.position >= 0 && i->second.show) {
196 if ((stereo && i->second.pp < 0) || (!stereo && i->second.pp >= 0)) {
197 if (!i->second.visible) {
198 i->second.visible =
true;
202 param[
"ui."+i->first].readJSON_value(jp);
209 std::sort(v.begin(), v.end());
211 for (std::vector<UnitPositionID>::iterator j = v.begin(); j != v.end(); ++j) {
212 if (!stereo && j->pp != pp) {
214 l.push_back(
"ampstack");
219 l.push_back(
"ampstack");
232 if (s ==
"system.mainwin_x") {
237 if (s ==
"system.mainwin_y") {
242 if (s ==
"system.mainwin_height") {
247 if (s ==
"system.mainwin_rack_height") {
252 if (s ==
"system.preset_window_height") {
257 if (s ==
"oscilloscope.bufferset") {
262 if (s ==
"ui.skin_name") {
267 if (s ==
"ui.latency_nowarn") {
272 if (s ==
"system.order_rack_h") {
277 if (s ==
"system.show_value") {
282 if (s ==
"system.show_tooltips") {
287 if (s ==
"system.animations") {
292 if (s ==
"system.show_presets") {
297 if (s ==
"system.show_toolbar") {
302 if (s ==
"system.show_rack") {
311 static inline bool endswith(
const std::string& s,
int n,
const char *t) {
312 return s.compare(std::max<int>(0, s.size()-n), n, t) == 0;
315 static inline bool startswith(
const std::string& s,
int n,
const char *t) {
316 return s.compare(0, n, t) == 0;
320 const std::string& s = p->
id();
321 if (startswith(s, 3,
"ui.")) {
323 std::string ss = s.substr(3);
327 }
else if (endswith(s, 7,
".on_off")) {
329 u.
set_show(s.substr(0, s.size()-7),
true);
331 }
else if (endswith(s, 9,
".position")) {
333 }
else if (endswith(s, 3,
".pp")) {
345 if (convert_old(jp)) {
351 _(
"recall settings"),
362 _(
"recall settings"),
363 _(
"preset-parameter ")+p->
id()+_(
" in settings"));
368 _(
"recall settings"),
369 _(
"non preset-parameter ")+p->
id()+_(
" in preset"));
374 _(
"recall settings"),
375 _(
"non saveable parameter ")+p->
id()+_(
" in settings"));
380 collectRackOrder(p, jp, u);
383 u.
get_list(rack_units.mono,
false, param);
384 u.
get_list(rack_units.stereo,
true, param);
392 for (std::vector<std::string>::iterator j = mono_rack_units.begin(); j != mono_rack_units.end(); ++j) {
393 if (*j ==
"ampstack") {
407 i != param.end(); ++i) {
421 bool use_midi = (has_midi != 0) || midi_in_preset();
429 read_parameters(jp,
true);
435 m->readJSON(jp, param);
444 _(
"recall settings"),
450 fixup_parameters(head);
454 for (gx_engine::paramlist::iterator i = plist.begin(); i != plist.end(); ++i) {
455 (*i)->setJSON_value();
458 mctrl.set_controller_array(*m);
461 mctrl.update_from_controllers();
467 write_parameters(w,
true);
477 write_intern(jw, midi_in_preset());
482 param.set_init_values();
485 read_intern(jp, &has_midi, head);
487 write_intern(jw, has_midi);
498 :
PresetIO(mctrl, cvr, param, opt_, rack_units),
499 midi_std_control(mstdctr),
509 if (i->second->isSavable()) {
510 i->second->stdJSON_value();
511 plist.push_back(i->second);
517 read_parameters(jp,
false);
519 read_intern(jp, 0, head);
522 m->readJSON(jp, param);
529 _(
"recall settings"),
541 jw.
write(
"settings");
542 write_parameters(jw,
false);
544 jw.
write(
"midi_controller");
547 jw.
write(
"midi_ctrl_names");
551 jw.
write(
"current_preset");
552 write_intern(jw,
false);
555 jw.
write(
"jack_connections");
568 : filename(fname), pmap(pmap_), mctrl(mctrl_), is(), jp(&is) {
573 is.open(filename.c_str());
610 _(
"recall plugin settings"),
664 for (gx_engine::paramlist::iterator i = plist.begin(); i != plist.end(); ++i) {
665 (*i)->setJSON_value();
670 static const int GX_PLUGIN_VERSION = 1;
672 static inline bool compare_groups(
const std::string&
id,
const char **groups) {
676 for (
const char **g = groups; *g; g += 2) {
683 if (strncmp(
id.c_str(), p, n) == 0 &&
id[n] ==
'.') {
690 void PluginPresetList::write_values(
gx_system::JsonWriter& jw, std::string
id,
const char **groups) {
692 string on_off =
id +
"on_off";
693 string pp =
id +
"pp";
694 std::string position =
id +
"position";
697 if (i->first.compare(0,
id.size(), id) == 0 || compare_groups(i->first, groups)) {
698 if (i->second->isInPreset()) {
699 if (i->first != on_off && i->first != pp && i->first != position) {
700 i->second->writeJSON(jw);
711 std::string tmpfile(filename +
"_tmp");
712 ofstream os(tmpfile.c_str());
715 jw.write(
"gx_plugin_version");
716 jw.write(GX_PLUGIN_VERSION,
true);
724 write_values(jw,
id, groups);
733 write_values(jw,
id, groups);
740 boost::format(_(
"couldn't write %1%")) % tmpfile);
743 int rc = rename(tmpfile.c_str(), filename.c_str());
746 boost::format(_(
"couldn't rename %1% to %2%"))
747 % tmpfile % filename);
758 std::string tmpfile(filename +
"_tmp");
759 ofstream os(tmpfile.c_str());
762 jw.write(
"gx_plugin_version");
763 jw.write(GX_PLUGIN_VERSION,
true);
781 boost::format(_(
"couldn't write %1%")) % tmpfile);
784 int rc = rename(tmpfile.c_str(), filename.c_str());
787 boost::format(_(
"couldn't rename %1% to %2%"))
788 % tmpfile % filename);
805 static const char *scratchpad_name =
N_(
"Scratchpad");
806 static const char *scratchpad_file =
"scratchpad.gx";
807 static const char *statename_postfix =
"_rc";
808 static const char *bank_list =
"banklist.js";
814 GxSettingsBase(seq_),
815 param(seq_.get_param()),
816 preset_io(mctrl_, cvr, param, opt, rack_units),
817 state_io(mctrl_, cvr, param, mstdctr, jack_, opt, rack_units),
823 preset_parameter(*param.reg_string(
"system.current_preset",
"?", ¤t_name,
"")),
824 bank_parameter(*param.reg_string(
"system.current_bank",
"?", ¤t_bank,
"")) {
825 set_io(&state_io, &preset_io);
828 scratchpad_name, scratchpad_file);
831 sigc::mem_fun(*
this, &GxSettings::exit_handler));
833 sigc::mem_fun(*
this, &GxSettings::jack_client_changed));
858 void GxSettings::exit_handler(
bool otherthread) {
865 void GxSettings::jack_client_changed() {
866 string fn = make_state_filename();
871 if (!state_loaded && access(fn.c_str(), R_OK|W_OK) != 0) {
872 string defname = make_default_state_filename();
873 if (access(defname.c_str(), R_OK) == 0) {
882 string GxSettings::make_default_state_filename() {
889 if (access(s.c_str(), R_OK|W_OK) == 0) {
897 string GxSettings::make_state_filename() {
905 bool GxSettings::check_create_config_dir(
const Glib::ustring& dir) {
906 if (access((Glib::build_filename(dir,
".")).c_str(), R_OK|W_OK|X_OK) != 0) {
907 if (errno != ENOENT) {
909 boost::format(_(
"no read/write access in guitarix config dir '%1%'"))
912 if (mkdir(dir.c_str(), 0777) != 0) {
914 boost::format(_(
"can't create guitarix config dir '%1%'"))
926 static inline std::vector<std::string>::iterator find_unit(std::vector<std::string>& r,
const std::string& unit) {
927 std::vector<std::string>::iterator i = r.begin();
928 for (; i != r.end(); ++i) {
937 std::vector<std::string>& r = stereo ? rack_units.
stereo : rack_units.
mono;
938 std::vector<std::string>::iterator i = find_unit(r, unit);
947 std::vector<std::string>& r = stereo ? rack_units.
stereo : rack_units.
mono;
949 if (before.empty()) {
952 r.insert(find_unit(r, before), unit);
957 Glib::RefPtr<Gio::File> rem = Gio::File::create_for_uri(uri);
958 filename = rem->get_basename();
968 std::string filename;
970 Glib::RefPtr<Gio::File> dest = Gio::File::create_for_path(filename);
973 }
catch (Gio::Error& e) {
984 }
catch (Gio::Error& e) {
985 gx_print_error(e.what().c_str(), _(
"can't remove copied file!?"));
992 }
catch (Gio::Error& e) {
993 gx_print_error(e.what().c_str(), _(
"can't move; file has been copied"));
1001 std::string filename;
1003 Glib::RefPtr<Gio::File> dest = Gio::File::create_for_path(filename);
1005 Glib::RefPtr<Gio::FileOutputStream> s = dest->create_file();
1008 }
catch (Gio::Error& e) {
1019 }
catch (Gio::Error& e) {
1020 gx_print_error(e.what().c_str(), _(
"can't remove copied file!?"));
1028 Glib::ustring newname = name;
1029 std::string newfile;
1042 std::string newfile;
1044 return GxSettingsBase::rename_bank(oldname, newname, newfile);
1049 bool copied_from_old =
false;
1050 std::string oldpreset;
1051 *need_new_preset =
false;
1061 if (access(Glib::build_filename(opt.
get_old_user_dir(), fname).c_str(), R_OK) == 0) {
1062 copied_from_old =
true;
1063 Glib::RefPtr<Gio::File> f = Gio::File::create_for_path(
1067 }
catch (Gio::Error& e) {
1068 gx_print_error(e.what().c_str(), _(
"can't copy to new config dir"));
1071 fname = Glib::build_filename(
1074 if (access(fname.c_str(), R_OK) == 0) {
1075 Glib::RefPtr<Gio::File> f = Gio::File::create_for_path(fname);
1078 f->copy(Gio::File::create_for_path(oldpreset));
1079 }
catch (Gio::Error& e) {
1080 gx_print_error(e.what().c_str(), _(
"can't copy to new config preset dir"));
1094 if (access(fname.c_str(), R_OK) != 0) {
1097 boost::format(_(
"can't create file in '%1%' !!??")) % opt.
get_preset_dir());
1099 *need_new_preset =
true;
1102 if (access(fname.c_str(), R_OK) != 0) {
1103 ofstream f(fname.c_str());
1106 boost::format(_(
"can't create '%1%' in directory '%2%'"))
1121 return copied_from_old;
1125 GxSettingsBase::loadstate();
1152 state_loaded =
true;
1160 while (l.
next(name, &is_set)) {
1168 add_plugin_preset_list(lv2sets, presetnames);
1170 add_plugin_preset_list(user, presetnames);
1173 add_plugin_preset_list(factory, presetnames);
1187 if(strcmp(pdef->
id,
"dubber")==0) {
1190 std::remove((pPath +
"1.wav").c_str());
1191 std::remove((pPath +
"2.wav").c_str());
1192 std::remove((pPath +
"3.wav").c_str());
1193 std::remove((pPath +
"4.wav").c_str());
void write_state(gx_system::JsonWriter &jw, bool preserve_preset)
void set_pp(const std::string &s, bool v)
gx_system::PresetFile * bank_insert_uri(const Glib::ustring &uri, bool move)
void set_io(AbstractStateIO *st, AbstractPresetIO *pr)
void begin_array(bool nl=false)
void save(PresetFile &pf, const Glib::ustring &name)
PresetFile * get_current_bank_file()
const std::string & get_preset_dir() const
void set_show(const std::string &s, bool v)
void make_bank_unique(Glib::ustring &name, std::string *file=0)
bool remove_rack_unit(const std::string &unit, bool stereo)
std::ostream & get_ostream()
std::string get_pluginpreset_filepath(const std::string &id, bool factory) const
map< string, Parameter * >::const_iterator iterator
list< Parameter * > paramlist
void set_visible(const std::string &s, bool v)
void create_default_scratch_preset()
void insert(PresetFile *f)
void end_array(bool nl=false)
void set_streampos(streampos pos)
const Glib::ustring & get_jack_instancename() const
void read_connections(gx_system::JsonParser &jp)
void write_preset(gx_system::JsonWriter &jw)
void read_preset(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader &)
std::vector< PluginPresetEntry > UnitPresetList
PresetIO(gx_engine::MidiControllerList &mctrl, gx_engine::ConvolverAdapter &cvr, gx_engine::ParamMap ¶m, gx_system::CmdlineOptions &opt, UnitRacks &rack_units)
sigc::signal< void > selection_changed
virtual void readJSON_value(gx_system::JsonParser &jp)=0
PresetFile * get_file(const Glib::ustring &bank) const
void read_state(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader &)
std::string get_lv2_preset_filepath(const std::string &id) const
virtual void writeJSON(gx_system::JsonWriter &jw) const =0
bool rename_bank(const Glib::ustring &oldname, Glib::ustring &newname)
std::vector< std::string > mono
const std::string & get_loop_dir() const
void write_key(const char *p, bool nl=false)
static bool check_settings_dir(gx_system::CmdlineOptions &opt, bool *need_new_preset)
void save(const Glib::ustring &name, const std::string &id, const char **groups)
std::string decode_filename(const std::string &s)
virtual bool compareJSON_value()=0
void copy_preset(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader &, gx_system::JsonWriter &jw)
bool open_file(const Glib::ustring &name, const std::string &path, int tp, int flags)
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)
void gx_print_error(const char *, const std::string &)
static string get_default_instancename()
gx_system::PresetFile * bank_insert_new(const Glib::ustring &name)
static bool strip_preset_postfix(std::string &name)
void plugin_preset_list_load(const PluginDef *pdef, UnitPresetList &presetnames)
bool remove(const Glib::ustring &name)
StateIO(gx_engine::MidiControllerList &mctrl, gx_engine::ConvolverAdapter &cvr, gx_engine::ParamMap ¶m, gx_engine::MidiStandardControllers &mstdctr, gx_jack::GxJack &jack, gx_system::CmdlineOptions &opt, UnitRacks &rack_units)
bool hasId(const string &id) const
void plugin_preset_list_save(const PluginDef *pdef, const Glib::ustring &name)
void set_filename(const string &fn)
void insert_rack_unit(const std::string &unit, const std::string &before, bool stereo)
void write_connections(gx_system::JsonWriter &w)
std::vector< std::string > stereo
void begin_object(bool nl=false)
const std::string & get_pluginpreset_dir() const
string get_filename() const
bool next(Glib::ustring &name, bool *is_set=0)
static GxExit & get_instance()
void load_preset(PresetFile *pf, const Glib::ustring &name)
void copy_object(JsonWriter &jw)
UnitPositionID(const string &id_, const UnitPosition &u)
const std::string & get_factory_dir() const
FloatParameter & getFloat()
void gx_print_warning(const char *, const std::string &)
void set_position(const std::string &s, int v)
const std::string & get_temp_dir() const
const std::string & get_old_user_dir() const
sigc::signal< void, bool > & signal_exit()
const string & get_instancename()
void writeJSON(gx_system::JsonWriter &jw) const
std::string get_user_filepath(const std::string &basename) const
Glib::ustring current_name
string current_value() const
sigc::signal< void > & signal_client_change()
bool set(const Glib::ustring &name)
void readJSON(gx_system::JsonParser &jp)
Glib::ustring current_bank
const std::string & get_lv2_preset_dir() const
void plugin_preset_list_remove(const PluginDef *pdef, const Glib::ustring &name)
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)
const std::string & get_loadfile() const
std::string get_preset_filepath(const std::string &basename) const
const std::string & get_user_dir() const
token next(token expect=no_token)
PluginPresetList(const std::string &fname, gx_engine::ParamMap &pmap, gx_engine::MidiControllerList &mctrl_)
void write(float v, bool nl=false)
const string & id() const
bool operator<(const UnitPositionID &v) const
static void make_valid_utf8(Glib::ustring &s)
void get_list(std::vector< std::string > &l, bool stereo, gx_engine::ParamMap ¶m)
Glib::RefPtr< Gio::File > uri_to_name_filename(const Glib::ustring &uri, Glib::ustring &name, std::string &filename)
const std::string & get_plugin_dir() const
bool create_file(const Glib::ustring &name, const std::string &path, int tp, int flags)
bool loadsetting(PresetFile *p, const Glib::ustring &name)
gx_system::PresetFile * bank_insert_content(const Glib::ustring &uri, const std::string content)
void convert_from_range(float low, float up)
void remove_controlled_parameters(paramlist &plist, const ControllerArray *m)
void end_object(bool nl=false)
void save_to_state(bool preserve_preset=false)
void plugin_preset_list_set(const PluginDef *pdef, bool factory, const Glib::ustring &name)
const std::string & get_user_IR_dir() const