Guitarix
gx_preset.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
21/* ------- This is the preset namespace ------- */
22
23#pragma once
24
25#ifndef SRC_HEADERS_GX_PRESET_H_
26#define SRC_HEADERS_GX_PRESET_H_
27
28class PosixSignals;
29#ifdef HAVE_LIBLO
30class GxNsmHandler;
31#endif
32
33namespace gx_preset {
34
35/****************************************************************
36 ** class BasicIO, class PresetIO, class StateIO, class GxSettings
37 */
38
39class UnitRacks {
40public:
41 std::vector<std::string> mono;
42 std::vector<std::string> stereo;
43 sigc::signal<void,bool> rack_unit_order_changed;
44 UnitRacks() { mono.push_back("ampstack"); }
45};
46
48public:
49 bool show;
50 bool visible;
52 int pp;
53 UnitPosition(): show(false), visible(false), position(-1), pp(-1) {}
54};
55
57private:
58 std::map<std::string,UnitPosition> m;
59public:
60 void set_show(const std::string& s, bool v) { m[s].show = v; }
61 void set_visible(const std::string& s, bool v) { m[s].visible = v; } // old preset handling
62 void set_position(const std::string& s, int v) { m[s].position = v; }
63 void set_pp(const std::string& s, bool v) { m[s].pp = v; }
64 void get_list(std::vector<std::string>& l, bool stereo, gx_engine::ParamMap& param);
65 bool empty() { return m.empty(); }
66};
67
69protected:
76protected:
77 void read_parameters(gx_system::JsonParser &jp, bool preset);
79 void clear();
81 void read_intern(gx_system::JsonParser &jp, bool *has_midi, const gx_system::SettingsFileHeader& head);
83 void write_intern(gx_system::JsonWriter &w, bool write_midi);
87 friend class StateIO;
88public:
93 void commit_preset() override;
96 static string try_replace_param_value(const std::string& id, const std::string& v_id, bool& found);
97};
98
100private:
103public:
109 void commit_state() override;
110 void write_state(gx_system::JsonWriter &jw, bool preserve_preset) override;
111};
112
114private:
115 std::string filename;
118 ifstream is;
120private:
121 void write_values(gx_system::JsonWriter& jw, std::string id, const char **groups);
122public:
124 bool start();
125 bool next(Glib::ustring& name, bool *is_set = 0);
126 bool set(const Glib::ustring& name);
127 void save(const Glib::ustring& name, const std::string& id, const char **groups);
128 bool remove(const Glib::ustring& name);
129};
130
132public:
133 Glib::ustring name;
134 bool is_set;
135 PluginPresetEntry(const Glib::ustring& name_, bool is_set_): name(name_), is_set(is_set_) {}
136};
137
138typedef std::vector<PluginPresetEntry> UnitPresetList;
139
140class GxSettings: public sigc::trackable, public gx_system::GxSettingsBase {
141private:
155 void exit_handler(bool otherthread);
159 static bool check_create_config_dir(const Glib::ustring& dir);
161 friend class ::PosixSignals;
162#ifdef HAVE_LIBLO
163 friend class ::GxNsmHandler;
164#endif
165 Glib::ustring sync_name;
167 static void *preset_sync_run(void *p);
168 void *sync_run();
171 Glib::Dispatcher set_preset;
172 Glib::Dispatcher get_sequencer_p;
173 volatile int sequencer_max;
174 volatile int sequencer_pos;
175public:
176 using GxSettingsBase::banks;
181 inline gx_engine::ParamMap& get_param() const { return param; }
183 static bool check_settings_dir(gx_system::CmdlineOptions& opt, bool *need_new_preset);
184 void loadstate();
186 void disable_autosave(bool v) { no_autosave = v; }
189 void plugin_preset_list_load(const PluginDef *pdef, UnitPresetList &presetnames);
190 void plugin_preset_list_sync_set(const PluginDef *pdef, bool factory, const Glib::ustring& name);
191 void plugin_preset_list_set(const PluginDef *pdef, bool factory, const Glib::ustring& name);
192 void plugin_preset_list_save(const PluginDef *pdef, const Glib::ustring& name);
193 void plugin_preset_list_remove(const PluginDef *pdef, const Glib::ustring& name);
195 std::vector<std::string>& get_rack_unit_order(bool stereo) { return stereo ? rack_units.stereo : rack_units.mono; }
197 bool remove_rack_unit(const std::string& unit, bool stereo);
198 void insert_rack_unit(const std::string& unit, const std::string& before, bool stereo);
199 Glib::RefPtr<Gio::File> uri_to_name_filename(const Glib::ustring& uri, Glib::ustring& name, std::string& filename);
200 gx_system::PresetFile *bank_insert_uri(const Glib::ustring& uri, bool move, int position = 0);
201 gx_system::PresetFile* bank_insert_content(const Glib::ustring& uri, const std::string content, int position = 0);
202 gx_system::PresetFile *bank_insert_new(const Glib::ustring& name);
203 bool rename_bank(const Glib::ustring& oldname, Glib::ustring& newname);
204};
205
206/* --------------------------------------------------------------------- */
207} /* end of gx_preset namespace */
208#endif // SRC_HEADERS_GX_PRESET_H_
gx_engine::StringParameter & bank_parameter
Definition: gx_preset.h:152
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)
sigc::signal< void, bool > & signal_rack_unit_order_changed()
Definition: gx_preset.h:196
static bool check_create_config_dir(const Glib::ustring &dir)
gx_system::PresetFile * bank_insert_content(const Glib::ustring &uri, const std::string content, int position=0)
static bool check_settings_dir(gx_system::CmdlineOptions &opt, bool *need_new_preset)
void disable_autosave(bool v)
Definition: gx_preset.h:186
gx_engine::StringParameter & preset_parameter
Definition: gx_preset.h:151
string make_state_filename()
Glib::RefPtr< Gio::File > uri_to_name_filename(const Glib::ustring &uri, Glib::ustring &name, std::string &filename)
gx_system::CmdlineOptions & get_options() const
Definition: gx_preset.h:182
volatile int sequencer_max
Definition: gx_preset.h:173
std::vector< std::string > & get_rack_unit_order(bool stereo)
Definition: gx_preset.h:195
gx_engine::ParamMap & param
Definition: gx_preset.h:142
void add_plugin_preset_list(PluginPresetList &l, UnitPresetList &presetnames)
gx_system::PresetFile * bank_insert_uri(const Glib::ustring &uri, bool move, int position=0)
gx_system::CmdlineOptions & options
Definition: gx_preset.h:150
volatile int sequencer_pos
Definition: gx_preset.h:174
bool get_auto_save_state()
Definition: gx_preset.h:185
void insert_rack_unit(const std::string &unit, const std::string &before, bool stereo)
gx_preset::PresetIO preset_io
Definition: gx_preset.h:143
void plugin_preset_list_remove(const PluginDef *pdef, const Glib::ustring &name)
void plugin_preset_list_save(const PluginDef *pdef, const Glib::ustring &name)
void create_default_scratch_preset()
Glib::Dispatcher set_preset
Definition: gx_preset.h:171
void disable_save_on_exit(bool v)
Definition: gx_preset.h:187
gx_system::PresetFile * bank_insert_new(const Glib::ustring &name)
static void * preset_sync_run(void *p)
static GxSettings * instance
Definition: gx_preset.h:160
gx_engine::MidiControllerList & mctrl
Definition: gx_preset.h:149
void plugin_preset_list_set(const PluginDef *pdef, bool factory, const Glib::ustring &name)
gx_engine::ParamMap & get_param() const
Definition: gx_preset.h:181
bool remove_rack_unit(const std::string &unit, bool stereo)
void plugin_preset_list_sync_set(const PluginDef *pdef, bool factory, const Glib::ustring &name)
gx_preset::StateIO state_io
Definition: gx_preset.h:144
UnitRacks rack_units
Definition: gx_preset.h:153
void exit_handler(bool otherthread)
gx_jack::GxJack & jack
Definition: gx_preset.h:148
Glib::ustring sync_name
Definition: gx_preset.h:165
string make_default_state_filename()
bool rename_bank(const Glib::ustring &oldname, Glib::ustring &newname)
Glib::Dispatcher get_sequencer_p
Definition: gx_preset.h:172
void plugin_preset_list_load(const PluginDef *pdef, UnitPresetList &presetnames)
Definition: gx_preset.h:131
bool is_set
Definition: gx_preset.h:134
PluginPresetEntry(const Glib::ustring &name_, bool is_set_)
Definition: gx_preset.h:135
Glib::ustring name
Definition: gx_preset.h:133
void save(const Glib::ustring &name, const std::string &id, const char **groups)
void write_values(gx_system::JsonWriter &jw, std::string id, const char **groups)
PluginPresetList(const std::string &fname, gx_engine::ParamMap &pmap, gx_engine::MidiControllerList &mctrl_)
gx_system::JsonParser jp
Definition: gx_preset.h:119
bool set(const Glib::ustring &name)
gx_engine::ParamMap & pmap
Definition: gx_preset.h:116
bool remove(const Glib::ustring &name)
bool next(Glib::ustring &name, bool *is_set=0)
gx_engine::MidiControllerList & mctrl
Definition: gx_preset.h:117
void write_preset(gx_system::JsonWriter &jw) override
gx_engine::ParamMap & param
Definition: gx_preset.h:71
void fixup_parameters(const gx_system::SettingsFileHeader &head)
gx_engine::paramlist plist
Definition: gx_preset.h:73
void copy_preset(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader &, gx_system::JsonWriter &jw) override
void write_parameters(gx_system::JsonWriter &w, bool preset)
static string try_replace_param_value(const std::string &id, const std::string &v_id, bool &found)
PresetIO(gx_engine::MidiControllerList &mctrl, gx_engine::ParamMap &param, gx_system::CmdlineOptions &opt, UnitRacks &rack_units)
void commit_midi_feedback(gx_engine::Parameter *p)
bool convert_old(gx_system::JsonParser &jp)
UnitRacks & rack_units
Definition: gx_preset.h:75
gx_engine::MidiControllerList & mctrl
Definition: gx_preset.h:70
void read_intern(gx_system::JsonParser &jp, bool *has_midi, const gx_system::SettingsFileHeader &head)
gx_engine::ControllerArray * m
Definition: gx_preset.h:74
void write_intern(gx_system::JsonWriter &w, bool write_midi)
void commit_preset() override
void collectRackOrder(gx_engine::Parameter *p, gx_system::JsonParser &jp, UnitsCollector &u)
gx_system::CmdlineOptions & opt
Definition: gx_preset.h:72
void read_parameters(gx_system::JsonParser &jp, bool preset)
void read_preset(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader &) override
void read_state(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader &) override
void commit_state() override
StateIO(gx_engine::MidiControllerList &mctrl, gx_engine::ParamMap &param, gx_engine::MidiStandardControllers &mstdctr, gx_jack::GxJack &jack, gx_system::CmdlineOptions &opt, UnitRacks &rack_units)
gx_jack::GxJack & jack
Definition: gx_preset.h:102
gx_engine::MidiStandardControllers & midi_std_control
Definition: gx_preset.h:101
void write_state(gx_system::JsonWriter &jw, bool preserve_preset) override
sigc::signal< void, bool > rack_unit_order_changed
Definition: gx_preset.h:43
std::vector< std::string > mono
Definition: gx_preset.h:41
std::vector< std::string > stereo
Definition: gx_preset.h:42
void set_pp(const std::string &s, bool v)
Definition: gx_preset.h:63
void set_show(const std::string &s, bool v)
Definition: gx_preset.h:60
std::map< std::string, UnitPosition > m
Definition: gx_preset.h:58
void set_position(const std::string &s, int v)
Definition: gx_preset.h:62
void set_visible(const std::string &s, bool v)
Definition: gx_preset.h:61
void get_list(std::vector< std::string > &l, bool stereo, gx_engine::ParamMap &param)
gx_engine::EngineControl & seq
Definition: gx_json.h:471
list< Parameter * > paramlist
Definition: gx_parameter.h:232
std::vector< PluginPresetEntry > UnitPresetList
Definition: gx_preset.h:138