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 
30 namespace gx_preset {
31 
32 /****************************************************************
33  ** class BasicIO, class PresetIO, class StateIO, class GxSettings
34  */
35 
36 class UnitRacks {
37 public:
38  std::vector<std::string> mono;
39  std::vector<std::string> stereo;
40  sigc::signal<void,bool> rack_unit_order_changed;
41  UnitRacks() { mono.push_back("ampstack"); }
42 };
43 
44 class UnitPosition {
45 public:
46  bool show;
47  bool visible;
48  int position;
49  int pp;
50  UnitPosition(): show(false), visible(false), position(-1), pp(-1) {}
51 };
52 
54 private:
55  std::map<std::string,UnitPosition> m;
56 public:
57  void set_show(const std::string& s, bool v) { m[s].show = v; }
58  void set_visible(const std::string& s, bool v) { m[s].visible = v; } // old preset handling
59  void set_position(const std::string& s, int v) { m[s].position = v; }
60  void set_pp(const std::string& s, bool v) { m[s].pp = v; }
61  void get_list(std::vector<std::string>& l, bool stereo, gx_engine::ParamMap& param);
62  bool empty() { return m.empty(); }
63 };
64 
66 private:
68  gx_engine::ConvolverAdapter& convolver;
69  gx_engine::ParamMap& param;
73  UnitRacks& rack_units;
74 private:
75  void read_parameters(gx_system::JsonParser &jp, bool preset);
76  void write_parameters(gx_system::JsonWriter &w, bool preset);
77  void clear();
78  bool midi_in_preset();
79  void read_intern(gx_system::JsonParser &jp, bool *has_midi, const gx_system::SettingsFileHeader& head);
80  void fixup_parameters(const gx_system::SettingsFileHeader& head);
81  void write_intern(gx_system::JsonWriter &w, bool write_midi);
82  bool convert_old(gx_system::JsonParser &jp);
83  void collectRackOrder(gx_engine::Parameter *p, gx_system::JsonParser &jp, UnitsCollector& u);
84  friend class StateIO;
85 public:
87  gx_engine::ParamMap& param, gx_system::CmdlineOptions& opt, UnitRacks& rack_units);
88  ~PresetIO();
89  void read_online(gx_system::JsonParser &jp);
90  void read_preset(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader&);
91  void commit_preset();
92  void write_preset(gx_system::JsonWriter& jw);
94 };
95 
97 private:
98  gx_engine::MidiStandardControllers& midi_std_control;
99  gx_jack::GxJack& jack;
100 public:
103  gx_jack::GxJack& jack, gx_system::CmdlineOptions& opt, UnitRacks& rack_units);
104  ~StateIO();
105  void read_state(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader&);
106  void commit_state();
107  void write_state(gx_system::JsonWriter &jw, bool preserve_preset);
108 };
109 
111 private:
112  std::string filename;
113  gx_engine::ParamMap& pmap;
115  ifstream is;
117 private:
118  void write_values(gx_system::JsonWriter& jw, std::string id, const char **groups);
119 public:
120  PluginPresetList(const std::string& fname, gx_engine::ParamMap& pmap, gx_engine::MidiControllerList& mctrl_);
121  bool start();
122  bool next(Glib::ustring& name, bool *is_set = 0);
123  bool set(const Glib::ustring& name);
124  void save(const Glib::ustring& name, const std::string& id, const char **groups);
125  bool remove(const Glib::ustring& name);
126 };
127 
129 public:
130  Glib::ustring name;
131  bool is_set;
132  PluginPresetEntry(const Glib::ustring& name_, bool is_set_): name(name_), is_set(is_set_) {}
133 };
134 
135 typedef std::vector<PluginPresetEntry> UnitPresetList;
136 
137 class GxSettings: public sigc::trackable, public gx_system::GxSettingsBase {
138 private:
139  gx_engine::ParamMap& param;
140  gx_preset::PresetIO preset_io;
141  gx_preset::StateIO state_io;
142  bool state_loaded;
143  bool no_autosave;
144  gx_jack::GxJack& jack;
146  gx_system::CmdlineOptions& options;
147  gx_engine::StringParameter& preset_parameter;
148  gx_engine::StringParameter& bank_parameter;
149  UnitRacks rack_units;
150  void add_plugin_preset_list(PluginPresetList& l, UnitPresetList &presetnames);
151  void exit_handler(bool otherthread);
152  void jack_client_changed();
153  string make_state_filename();
154  string make_default_state_filename();
155  static bool check_create_config_dir(const Glib::ustring& dir);
156  static GxSettings *instance;
157  friend class ::PosixSignals;
158  Glib::ustring sync_name;
159  void preset_sync_start();
160  static void *preset_sync_run(void *p);
161  void *sync_run();
162  void preset_sync_set();
163  void on_get_sequencer_pos();
164  Glib::Dispatcher set_preset;
165  Glib::Dispatcher get_sequencer_p;
166  volatile int sequencer_max;
167  volatile int sequencer_pos;
168 public:
169  using GxSettingsBase::banks;
173  ~GxSettings();
174  inline gx_engine::ParamMap& get_param() const { return param; }
175  inline gx_system::CmdlineOptions& get_options() const { return options; }
176  static bool check_settings_dir(gx_system::CmdlineOptions& opt, bool *need_new_preset);
177  void loadstate();
178  bool get_auto_save_state() { return no_autosave;}
179  void disable_autosave(bool v) { no_autosave = v; }
180  void auto_save_state();
181  void plugin_preset_list_load(const PluginDef *pdef, UnitPresetList &presetnames);
182  void plugin_preset_list_sync_set(const PluginDef *pdef, bool factory, const Glib::ustring& name);
183  void plugin_preset_list_set(const PluginDef *pdef, bool factory, const Glib::ustring& name);
184  void plugin_preset_list_save(const PluginDef *pdef, const Glib::ustring& name);
185  void plugin_preset_list_remove(const PluginDef *pdef, const Glib::ustring& name);
186  void create_default_scratch_preset();
187  std::vector<std::string>& get_rack_unit_order(bool stereo) { return stereo ? rack_units.stereo : rack_units.mono; }
188  sigc::signal<void,bool>& signal_rack_unit_order_changed() { return rack_units.rack_unit_order_changed; }
189  bool remove_rack_unit(const std::string& unit, bool stereo);
190  void insert_rack_unit(const std::string& unit, const std::string& before, bool stereo);
191  Glib::RefPtr<Gio::File> uri_to_name_filename(const Glib::ustring& uri, Glib::ustring& name, std::string& filename);
192  gx_system::PresetFile *bank_insert_uri(const Glib::ustring& uri, bool move);
193  gx_system::PresetFile* bank_insert_content(const Glib::ustring& uri, const std::string content);
194  gx_system::PresetFile *bank_insert_new(const Glib::ustring& name);
195  bool rename_bank(const Glib::ustring& oldname, Glib::ustring& newname);
196 };
197 
198 /* --------------------------------------------------------------------- */
199 } /* end of gx_preset namespace */
200 #endif // SRC_HEADERS_GX_PRESET_H_
void set_pp(const std::string &s, bool v)
Definition: gx_preset.h:60
CmdConnection::msg_type start
Definition: jsonrpc.cpp:257
Definition: gx_preset.h:128
void set_show(const std::string &s, bool v)
Definition: gx_preset.h:57
void disable_autosave(bool v)
Definition: gx_preset.h:179
list< Parameter * > paramlist
Definition: gx_parameter.h:221
void set_visible(const std::string &s, bool v)
Definition: gx_preset.h:58
std::vector< std::string > & get_rack_unit_order(bool stereo)
Definition: gx_preset.h:187
std::vector< PluginPresetEntry > UnitPresetList
Definition: gx_preset.h:135
Glib::ustring name
Definition: gx_preset.h:130
sigc::signal< void, bool > rack_unit_order_changed
Definition: gx_preset.h:40
std::vector< std::string > mono
Definition: gx_preset.h:38
PluginPresetEntry(const Glib::ustring &name_, bool is_set_)
Definition: gx_preset.h:132
gx_system::CmdlineOptions & get_options() const
Definition: gx_preset.h:175
std::vector< std::string > stereo
Definition: gx_preset.h:39
bool get_auto_save_state()
Definition: gx_preset.h:178
sigc::signal< void, bool > & signal_rack_unit_order_changed()
Definition: gx_preset.h:188
void set_position(const std::string &s, int v)
Definition: gx_preset.h:59
bool is_set
Definition: gx_preset.h:131
gx_engine::ParamMap & get_param() const
Definition: gx_preset.h:174