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 
28 class PosixSignals;
29 #ifdef HAVE_LIBLO
30 class GxNsmHandler;
31 #endif
32 
33 namespace gx_preset {
34 
35 /****************************************************************
36  ** class BasicIO, class PresetIO, class StateIO, class GxSettings
37  */
38 
39 class UnitRacks {
40 public:
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 
47 class UnitPosition {
48 public:
49  bool show;
50  bool visible;
51  int position;
52  int pp;
53  UnitPosition(): show(false), visible(false), position(-1), pp(-1) {}
54 };
55 
57 private:
58  std::map<std::string,UnitPosition> m;
59 public:
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 
69 protected:
76 protected:
77  void read_parameters(gx_system::JsonParser &jp, bool preset);
78  void write_parameters(gx_system::JsonWriter &w, 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;
88 public:
93  void commit_preset() override;
94  void write_preset(gx_system::JsonWriter& jw) override;
96  static string try_replace_param_value(const std::string& id, const std::string& v_id, bool& found);
97 };
98 
100 private:
103 public:
109  void commit_state() override;
110  void write_state(gx_system::JsonWriter &jw, bool preserve_preset) override;
111 };
112 
114 private:
115  std::string filename;
118  ifstream is;
120 private:
121  void write_values(gx_system::JsonWriter& jw, std::string id, const char **groups);
122 public:
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 
132 public:
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 
138 typedef std::vector<PluginPresetEntry> UnitPresetList;
139 
140 class GxSettings: public sigc::trackable, public gx_system::GxSettingsBase {
141 private:
154  void exit_handler(bool otherthread);
158  static bool check_create_config_dir(const Glib::ustring& dir);
160  friend class ::PosixSignals;
161 #ifdef HAVE_LIBLO
162  friend class ::GxNsmHandler;
163 #endif
164  Glib::ustring sync_name;
166  static void *preset_sync_run(void *p);
167  void *sync_run();
170  Glib::Dispatcher set_preset;
171  Glib::Dispatcher get_sequencer_p;
172  volatile int sequencer_max;
173  volatile int sequencer_pos;
174 public:
175  using GxSettingsBase::banks;
180  inline gx_engine::ParamMap& get_param() const { return param; }
181  inline gx_system::CmdlineOptions& get_options() const { return options; }
182  static bool check_settings_dir(gx_system::CmdlineOptions& opt, bool *need_new_preset);
183  void loadstate();
185  void disable_autosave(bool v) { no_autosave = v; }
187  void plugin_preset_list_load(const PluginDef *pdef, UnitPresetList &presetnames);
188  void plugin_preset_list_sync_set(const PluginDef *pdef, bool factory, const Glib::ustring& name);
189  void plugin_preset_list_set(const PluginDef *pdef, bool factory, const Glib::ustring& name);
190  void plugin_preset_list_save(const PluginDef *pdef, const Glib::ustring& name);
191  void plugin_preset_list_remove(const PluginDef *pdef, const Glib::ustring& name);
193  std::vector<std::string>& get_rack_unit_order(bool stereo) { return stereo ? rack_units.stereo : rack_units.mono; }
195  bool remove_rack_unit(const std::string& unit, bool stereo);
196  void insert_rack_unit(const std::string& unit, const std::string& before, bool stereo);
197  Glib::RefPtr<Gio::File> uri_to_name_filename(const Glib::ustring& uri, Glib::ustring& name, std::string& filename);
198  gx_system::PresetFile *bank_insert_uri(const Glib::ustring& uri, bool move, int position = 0);
199  gx_system::PresetFile* bank_insert_content(const Glib::ustring& uri, const std::string content, int position = 0);
200  gx_system::PresetFile *bank_insert_new(const Glib::ustring& name);
201  bool rename_bank(const Glib::ustring& oldname, Glib::ustring& newname);
202 };
203 
204 /* --------------------------------------------------------------------- */
205 } /* end of gx_preset namespace */
206 #endif // SRC_HEADERS_GX_PRESET_H_
gx_engine::StringParameter & bank_parameter
Definition: gx_preset.h:151
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)
static bool check_create_config_dir(const Glib::ustring &dir)
static bool check_settings_dir(gx_system::CmdlineOptions &opt, bool *need_new_preset)
void disable_autosave(bool v)
Definition: gx_preset.h:185
gx_engine::StringParameter & preset_parameter
Definition: gx_preset.h:150
static void * preset_sync_run(void *p)
string make_state_filename()
std::vector< std::string > & get_rack_unit_order(bool stereo)
Definition: gx_preset.h:193
gx_engine::ParamMap & get_param() const
Definition: gx_preset.h:180
volatile int sequencer_max
Definition: gx_preset.h:172
gx_engine::ParamMap & param
Definition: gx_preset.h:142
gx_system::PresetFile * bank_insert_content(const Glib::ustring &uri, const std::string content, int position=0)
void add_plugin_preset_list(PluginPresetList &l, UnitPresetList &presetnames)
gx_system::CmdlineOptions & options
Definition: gx_preset.h:149
volatile int sequencer_pos
Definition: gx_preset.h:173
bool get_auto_save_state()
Definition: gx_preset.h:184
void insert_rack_unit(const std::string &unit, const std::string &before, bool stereo)
gx_preset::PresetIO preset_io
Definition: gx_preset.h:143
gx_system::PresetFile * bank_insert_new(const Glib::ustring &name)
void plugin_preset_list_remove(const PluginDef *pdef, const Glib::ustring &name)
void plugin_preset_list_save(const PluginDef *pdef, const Glib::ustring &name)
Glib::RefPtr< Gio::File > uri_to_name_filename(const Glib::ustring &uri, Glib::ustring &name, std::string &filename)
void create_default_scratch_preset()
Glib::Dispatcher set_preset
Definition: gx_preset.h:170
static GxSettings * instance
Definition: gx_preset.h:159
gx_engine::MidiControllerList & mctrl
Definition: gx_preset.h:148
gx_system::PresetFile * bank_insert_uri(const Glib::ustring &uri, bool move, int position=0)
void plugin_preset_list_set(const PluginDef *pdef, bool factory, const Glib::ustring &name)
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:152
void exit_handler(bool otherthread)
gx_jack::GxJack & jack
Definition: gx_preset.h:147
Glib::ustring sync_name
Definition: gx_preset.h:164
string make_default_state_filename()
bool rename_bank(const Glib::ustring &oldname, Glib::ustring &newname)
Glib::Dispatcher get_sequencer_p
Definition: gx_preset.h:171
sigc::signal< void, bool > & signal_rack_unit_order_changed()
Definition: gx_preset.h:194
gx_system::CmdlineOptions & get_options() const
Definition: gx_preset.h:181
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