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 
53 class UnitsCollector {
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();
91  void commit_preset();
94 };
95 
96 class StateIO: public gx_system::AbstractStateIO, private PresetIO {
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();
106  void commit_state();
107  void write_state(gx_system::JsonWriter &jw, bool preserve_preset);
108 };
109 
110 class PluginPresetList {
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 
128 class PluginPresetEntry {
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;
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);
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_
gx_preset::GxSettings::plugin_preset_list_set
void plugin_preset_list_set(const PluginDef *pdef, bool factory, const Glib::ustring &name)
Definition: gx_preset.cpp:1276
gx_preset::UnitsCollector::empty
bool empty()
Definition: gx_preset.h:61
gx_preset::GxSettings::insert_rack_unit
void insert_rack_unit(const std::string &unit, const std::string &before, bool stereo)
Definition: gx_preset.cpp:1006
gx_preset::PluginPresetList::remove
bool remove(const Glib::ustring &name)
Definition: gx_preset.cpp:808
gx_preset::UnitRacks::UnitRacks
UnitRacks()
Definition: gx_preset.h:41
gx_preset::GxSettings::uri_to_name_filename
Glib::RefPtr< Gio::File > uri_to_name_filename(const Glib::ustring &uri, Glib::ustring &name, std::string &filename)
Definition: gx_preset.cpp:1016
gx_preset::GxSettings::auto_save_state
void auto_save_state()
Definition: gx_preset.cpp:903
gx_preset::UnitsCollector::set_visible
void set_visible(const std::string &s, bool v)
Definition: gx_preset.h:57
gx_preset::UnitRacks::stereo
std::vector< std::string > stereo
Definition: gx_preset.h:39
gx_preset::StateIO::read_state
void read_state(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader &)
Definition: gx_preset.cpp:561
gx_preset::UnitsCollector::set_show
void set_show(const std::string &s, bool v)
Definition: gx_preset.h:56
gx_preset::UnitPosition::position
int position
Definition: gx_preset.h:47
gx_preset::UnitsCollector::set_pp
void set_pp(const std::string &s, bool v)
Definition: gx_preset.h:59
gx_preset::PresetIO::copy_preset
void copy_preset(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader &, gx_system::JsonWriter &jw)
Definition: gx_preset.cpp:536
gx_preset::PluginPresetEntry::is_set
bool is_set
Definition: gx_preset.h:130
gx_preset::PluginPresetList::next
bool next(Glib::ustring &name, bool *is_set=0)
Definition: gx_preset.cpp:646
gx_preset::UnitPosition::pp
int pp
Definition: gx_preset.h:48
gx_preset::GxSettings::GxSettings
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:863
gx_preset::PresetIO::commit_preset
void commit_preset()
Definition: gx_preset.cpp:509
gx_preset::GxSettings::plugin_preset_list_save
void plugin_preset_list_save(const PluginDef *pdef, const Glib::ustring &name)
Definition: gx_preset.cpp:1281
gx_preset::GxSettings::~GxSettings
~GxSettings()
Definition: gx_preset.cpp:898
gx_preset::GxSettings::plugin_preset_list_load
void plugin_preset_list_load(const PluginDef *pdef, UnitPresetList &presetnames)
Definition: gx_preset.cpp:1226
gx_preset::PluginPresetList
Definition: gx_preset.h:109
gx_preset::PluginPresetList::set
bool set(const Glib::ustring &name)
Definition: gx_preset.cpp:686
gx_preset::PresetIO::read_preset
void read_preset(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader &)
Definition: gx_preset.cpp:74
gx_preset::GxSettings::plugin_preset_list_remove
void plugin_preset_list_remove(const PluginDef *pdef, const Glib::ustring &name)
Definition: gx_preset.cpp:1285
gx_preset::GxSettings::get_param
gx_engine::ParamMap & get_param() const
Definition: gx_preset.h:173
gx_preset::UnitPresetList
std::vector< PluginPresetEntry > UnitPresetList
Definition: gx_preset.h:134
gx_system::PresetFile
Definition: gx_json.h:297
gx_system::AbstractStateIO
Definition: gx_json.h:393
gx_preset::GxSettings::loadstate
void loadstate()
Definition: gx_preset.cpp:1184
gx_preset::GxSettings::plugin_preset_list_sync_set
void plugin_preset_list_sync_set(const PluginDef *pdef, bool factory, const Glib::ustring &name)
Definition: gx_preset.cpp:1265
PluginDef
Definition: gx_plugin.h:183
gx_preset::GxSettings::bank_insert_uri
gx_system::PresetFile * bank_insert_uri(const Glib::ustring &uri, bool move)
Definition: gx_preset.cpp:1026
gx_preset::GxSettings::bank_insert_new
gx_system::PresetFile * bank_insert_new(const Glib::ustring &name)
Definition: gx_preset.cpp:1087
gx_preset::UnitPosition::show
bool show
Definition: gx_preset.h:45
gx_preset::GxSettings::bank_insert_content
gx_system::PresetFile * bank_insert_content(const Glib::ustring &uri, const std::string content)
Definition: gx_preset.cpp:1059
gx_preset::UnitsCollector
Definition: gx_preset.h:52
gx_preset::UnitsCollector::get_list
void get_list(std::vector< std::string > &l, bool stereo, gx_engine::ParamMap &param)
Definition: gx_preset.cpp:172
gx_preset::GxSettings::disable_autosave
void disable_autosave(bool v)
Definition: gx_preset.h:178
gx_preset::GxSettings::check_settings_dir
static bool check_settings_dir(gx_system::CmdlineOptions &opt, bool *need_new_preset)
Definition: gx_preset.cpp:1108
gx_preset::PluginPresetList::save
void save(const Glib::ustring &name, const std::string &id, const char **groups)
Definition: gx_preset.cpp:763
gx_preset::UnitPosition
Definition: gx_preset.h:43
gx_preset::PluginPresetList::start
bool start()
Definition: gx_preset.cpp:625
gx_jack::GxJack
Definition: gx_jack.h:109
gx_system::SettingsFileHeader
Definition: gx_json.h:222
gx_preset::PresetIO::read_online
void read_online(gx_system::JsonParser &jp)
Definition: gx_preset.cpp:429
gx_preset::GxSettings::rename_bank
bool rename_bank(const Glib::ustring &oldname, Glib::ustring &newname)
Definition: gx_preset.cpp:1101
gx_engine::MidiControllerList
Definition: gx_parameter.h:731
gx_system::JsonWriter
Definition: gx_json.h:54
gx_preset::StateIO::commit_state
void commit_state()
Definition: gx_preset.cpp:591
gx_preset::PresetIO::PresetIO
PresetIO(gx_engine::MidiControllerList &mctrl, gx_engine::ConvolverAdapter &cvr, gx_engine::ParamMap &param, gx_system::CmdlineOptions &opt, UnitRacks &rack_units)
Definition: gx_preset.cpp:40
gx_system::JsonParser
Definition: gx_json.h:111
gx_preset::UnitsCollector::set_position
void set_position(const std::string &s, int v)
Definition: gx_preset.h:58
gx_preset::PluginPresetEntry::name
Glib::ustring name
Definition: gx_preset.h:129
gx_preset::GxSettings::create_default_scratch_preset
void create_default_scratch_preset()
Definition: gx_preset.cpp:982
gx_engine::MidiStandardControllers
Definition: gx_parameter.h:643
gx_preset::StateIO::write_state
void write_state(gx_system::JsonWriter &jw, bool preserve_preset)
Definition: gx_preset.cpp:595
gx_system::GxSettingsBase
Definition: gx_json.h:458
PosixSignals
Definition: gx_main.cpp:45
gx_preset::GxSettings
Definition: gx_preset.h:136
gx_preset::UnitRacks::mono
std::vector< std::string > mono
Definition: gx_preset.h:38
gx_system::AbstractPresetIO
Definition: gx_json.h:401
gx_engine::ControllerArray
Definition: gx_parameter.h:720
gx_preset::UnitRacks
Definition: gx_preset.h:35
gx_preset::GxSettings::get_rack_unit_order
std::vector< std::string > & get_rack_unit_order(bool stereo)
Definition: gx_preset.h:186
gx_preset::GxSettings::get_options
gx_system::CmdlineOptions & get_options() const
Definition: gx_preset.h:174
gx_preset::GxSettings::get_auto_save_state
bool get_auto_save_state()
Definition: gx_preset.h:177
gx_preset::StateIO
Definition: gx_preset.h:95
gx_engine::ParamMap
Definition: gx_parameter.h:512
gx_system::CmdlineOptions
Definition: gx_system.h:377
gx_preset::UnitRacks::rack_unit_order_changed
sigc::signal< void, bool > rack_unit_order_changed
Definition: gx_preset.h:40
gx_engine::ModuleSequencer
Definition: gx_modulesequencer.h:290
gx_engine::paramlist
list< Parameter * > paramlist
Definition: gx_parameter.h:219
gx_preset::PresetIO::write_preset
void write_preset(gx_system::JsonWriter &jw)
Definition: gx_preset.cpp:532
gx_system::GxSettingsBase::seq
gx_engine::EngineControl & seq
Definition: gx_json.h:466
gx_preset::UnitPosition::visible
bool visible
Definition: gx_preset.h:46
gx_preset::GxSettings::remove_rack_unit
bool remove_rack_unit(const std::string &unit, bool stereo)
Definition: gx_preset.cpp:996
gx_preset::UnitPosition::UnitPosition
UnitPosition()
Definition: gx_preset.h:49
gx_preset::StateIO::~StateIO
~StateIO()
Definition: gx_preset.cpp:558
gx_preset::PresetIO
Definition: gx_preset.h:64
gx_engine::ConvolverAdapter
Definition: gx_internal_plugins.h:377
gx_engine::ParameterV< Glib::ustring >
Definition: gx_parameter.h:424
gx_preset::PresetIO::~PresetIO
~PresetIO()
Definition: gx_preset.cpp:55
gx_engine::Parameter
Definition: gx_parameter.h:104
gx_preset::PluginPresetEntry::PluginPresetEntry
PluginPresetEntry(const Glib::ustring &name_, bool is_set_)
Definition: gx_preset.h:131
gx_preset
Definition: gx_preset.h:30
gx_preset::StateIO::StateIO
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:550
gx_preset::PluginPresetEntry
Definition: gx_preset.h:127
gx_preset::GxSettings::signal_rack_unit_order_changed
sigc::signal< void, bool > & signal_rack_unit_order_changed()
Definition: gx_preset.h:187
gx_preset::PluginPresetList::PluginPresetList
PluginPresetList(const std::string &fname, gx_engine::ParamMap &pmap, gx_engine::MidiControllerList &mctrl_)
Definition: gx_preset.cpp:620