Loading...
Searching...
No Matches
gx_preset.h
Go to the documentation of this file.
/*
* Copyright (C) 2009, 2010 Hermann Meyer, James Warden, Andreas Degert
* Copyright (C) 2011 Pete Shorthose
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* --------------------------------------------------------------------------
*/
/* ------- This is the preset namespace ------- */
#pragma once
#ifndef SRC_HEADERS_GX_PRESET_H_
#define SRC_HEADERS_GX_PRESET_H_
class PosixSignals;
#ifdef HAVE_LIBLO
class GxNsmHandler;
#endif
namespace gx_preset {
/****************************************************************
** class BasicIO, class PresetIO, class StateIO, class GxSettings
*/
class UnitRacks {
public:
std::vector<std::string> mono;
std::vector<std::string> stereo;
sigc::signal<void,bool> rack_unit_order_changed;
UnitRacks() { mono.push_back("ampstack"); }
};
class UnitPosition {
public:
bool show;
bool visible;
int position;
int pp;
UnitPosition(): show(false), visible(false), position(-1), pp(-1) {}
};
class UnitsCollector {
private:
std::map<std::string,UnitPosition> m;
public:
void set_show(const std::string& s, bool v) { m[s].show = v; }
void set_visible(const std::string& s, bool v) { m[s].visible = v; } // old preset handling
void set_position(const std::string& s, int v) { m[s].position = v; }
void set_pp(const std::string& s, bool v) { m[s].pp = v; }
void get_list(std::vector<std::string>& l, bool stereo, gx_engine::ParamMap& param);
bool empty() { return m.empty(); }
};
class PresetIO: public gx_system::AbstractPresetIO {
protected:
gx_engine::MidiControllerList& mctrl;
gx_engine::ParamMap& param;
gx_system::CmdlineOptions& opt;
gx_engine::paramlist plist;
gx_engine::ControllerArray *m;
UnitRacks& rack_units;
protected:
void read_parameters(gx_system::JsonParser &jp, bool preset);
void write_parameters(gx_system::JsonWriter &w, bool preset);
void clear();
bool midi_in_preset();
void read_intern(gx_system::JsonParser &jp, bool *has_midi, const gx_system::SettingsFileHeader& head);
void fixup_parameters(const gx_system::SettingsFileHeader& head);
void write_intern(gx_system::JsonWriter &w, bool write_midi);
bool convert_old(gx_system::JsonParser &jp);
void collectRackOrder(gx_engine::Parameter *p, gx_system::JsonParser &jp, UnitsCollector& u);
void commit_midi_feedback(gx_engine::Parameter *p);
friend class StateIO;
public:
PresetIO(gx_engine::MidiControllerList& mctrl, gx_engine::ParamMap& param,
gx_system::CmdlineOptions& opt, UnitRacks& rack_units);
~PresetIO();
void read_preset(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader&) override;
void commit_preset() override;
void write_preset(gx_system::JsonWriter& jw) override;
void copy_preset(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader&, gx_system::JsonWriter &jw) override;
static string try_replace_param_value(const std::string& id, const std::string& v_id, bool& found);
};
class StateIO: public gx_system::AbstractStateIO, private PresetIO {
private:
gx_engine::MidiStandardControllers& midi_std_control;
gx_jack::GxJack& jack;
public:
StateIO(gx_engine::MidiControllerList& mctrl, gx_engine::ParamMap& param,
gx_engine::MidiStandardControllers& mstdctr, gx_jack::GxJack& jack,
gx_system::CmdlineOptions& opt, UnitRacks& rack_units);
~StateIO();
void read_state(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader&) override;
void commit_state() override;
void write_state(gx_system::JsonWriter &jw, bool preserve_preset) override;
};
class PluginPresetList {
private:
std::string filename;
gx_engine::ParamMap& pmap;
gx_engine::MidiControllerList& mctrl;
ifstream is;
gx_system::JsonParser jp;
private:
void write_values(gx_system::JsonWriter& jw, std::string id, const char **groups);
public:
PluginPresetList(const std::string& fname, gx_engine::ParamMap& pmap, gx_engine::MidiControllerList& mctrl_);
bool start();
bool next(Glib::ustring& name, bool *is_set = 0);
bool set(const Glib::ustring& name);
void save(const Glib::ustring& name, const std::string& id, const char **groups);
bool remove(const Glib::ustring& name);
};
class PluginPresetEntry {
public:
Glib::ustring name;
bool is_set;
PluginPresetEntry(const Glib::ustring& name_, bool is_set_): name(name_), is_set(is_set_) {}
};
typedef std::vector<PluginPresetEntry> UnitPresetList;
class GxSettings: public sigc::trackable, public gx_system::GxSettingsBase {
private:
gx_engine::ParamMap& param;
gx_preset::PresetIO preset_io;
gx_preset::StateIO state_io;
bool state_loaded;
bool no_autosave;
bool no_save_on_exit;
gx_jack::GxJack& jack;
gx_engine::MidiControllerList& mctrl;
gx_system::CmdlineOptions& options;
gx_engine::StringParameter& preset_parameter;
gx_engine::StringParameter& bank_parameter;
UnitRacks rack_units;
void add_plugin_preset_list(PluginPresetList& l, UnitPresetList &presetnames);
void exit_handler(bool otherthread);
void jack_client_changed();
string make_state_filename();
string make_default_state_filename();
static bool check_create_config_dir(const Glib::ustring& dir);
static GxSettings *instance;
friend class ::PosixSignals;
#ifdef HAVE_LIBLO
friend class ::GxNsmHandler;
#endif
Glib::ustring sync_name;
void preset_sync_start();
static void *preset_sync_run(void *p);
void *sync_run();
void preset_sync_set();
void on_get_sequencer_pos();
Glib::Dispatcher set_preset;
Glib::Dispatcher get_sequencer_p;
volatile int sequencer_max;
volatile int sequencer_pos;
public:
using GxSettingsBase::banks;
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);
~GxSettings();
inline gx_engine::ParamMap& get_param() const { return param; }
inline gx_system::CmdlineOptions& get_options() const { return options; }
static void check_settings_dir(gx_system::CmdlineOptions& opt, bool *need_new_preset);
void loadstate();
bool get_auto_save_state() { return no_autosave;}
void disable_autosave(bool v) { no_autosave = v; }
void disable_save_on_exit(bool v) { no_save_on_exit = v; }
void auto_save_state();
void plugin_preset_list_load(const PluginDef *pdef, UnitPresetList &presetnames);
void plugin_preset_list_sync_set(const PluginDef *pdef, bool factory, const Glib::ustring& name);
void plugin_preset_list_set(const PluginDef *pdef, bool factory, const Glib::ustring& name);
void plugin_preset_list_save(const PluginDef *pdef, const Glib::ustring& name);
void plugin_preset_list_remove(const PluginDef *pdef, const Glib::ustring& name);
void create_default_scratch_preset();
std::vector<std::string>& get_rack_unit_order(bool stereo) { return stereo ? rack_units.stereo : rack_units.mono; }
sigc::signal<void,bool>& signal_rack_unit_order_changed() { return rack_units.rack_unit_order_changed; }
bool remove_rack_unit(const std::string& unit, bool stereo);
void insert_rack_unit(const std::string& unit, const std::string& before, bool stereo);
Glib::RefPtr<Gio::File> uri_to_name_filename(const Glib::ustring& uri, Glib::ustring& name, std::string& filename);
gx_system::PresetFile *bank_insert_uri(const Glib::ustring& uri, bool move, int position = 0);
gx_system::PresetFile* bank_insert_content(const Glib::ustring& uri, const std::string content, int position = 0);
gx_system::PresetFile *bank_insert_new(const Glib::ustring& name);
bool rename_bank(const Glib::ustring& oldname, Glib::ustring& newname);
};
/* --------------------------------------------------------------------- */
} /* end of gx_preset namespace */
#endif // SRC_HEADERS_GX_PRESET_H_
gx_engine::ControllerArray
Definition gx_parameter.h:757
gx_engine::ConvolverAdapter
Definition gx_internal_plugins.h:358
gx_engine::MidiControllerList
Definition gx_parameter.h:768
gx_engine::MidiStandardControllers
Definition gx_parameter.h:678
gx_engine::ModuleSequencer
Definition gx_modulesequencer.h:308
gx_engine::ParamMap
Definition gx_parameter.h:535
gx_engine::Parameter
Definition gx_parameter.h:107
gx_jack::GxJack
Definition gx_jack.h:168
gx_preset::GxSettings::preset_sync_set
void preset_sync_set()
gx_preset::GxSettings::bank_parameter
gx_engine::StringParameter & bank_parameter
Definition gx_preset.h:152
gx_preset::GxSettings::check_settings_dir
static void check_settings_dir(gx_system::CmdlineOptions &opt, bool *need_new_preset)
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)
gx_preset::GxSettings::signal_rack_unit_order_changed
sigc::signal< void, bool > & signal_rack_unit_order_changed()
Definition gx_preset.h:196
gx_preset::GxSettings::check_create_config_dir
static bool check_create_config_dir(const Glib::ustring &dir)
gx_preset::GxSettings::bank_insert_content
gx_system::PresetFile * bank_insert_content(const Glib::ustring &uri, const std::string content, int position=0)
gx_preset::GxSettings::disable_autosave
void disable_autosave(bool v)
Definition gx_preset.h:186
gx_preset::GxSettings::preset_sync_start
void preset_sync_start()
gx_preset::GxSettings::preset_parameter
gx_engine::StringParameter & preset_parameter
Definition gx_preset.h:151
gx_preset::GxSettings::make_state_filename
string make_state_filename()
gx_preset::GxSettings::no_autosave
bool no_autosave
Definition gx_preset.h:146
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)
gx_preset::GxSettings::get_options
gx_system::CmdlineOptions & get_options() const
Definition gx_preset.h:182
gx_preset::GxSettings::on_get_sequencer_pos
void on_get_sequencer_pos()
gx_preset::GxSettings::sequencer_max
volatile int sequencer_max
Definition gx_preset.h:173
gx_preset::GxSettings::no_save_on_exit
bool no_save_on_exit
Definition gx_preset.h:147
gx_preset::GxSettings::get_rack_unit_order
std::vector< std::string > & get_rack_unit_order(bool stereo)
Definition gx_preset.h:195
gx_preset::GxSettings::state_loaded
bool state_loaded
Definition gx_preset.h:145
gx_preset::GxSettings::param
gx_engine::ParamMap & param
Definition gx_preset.h:142
gx_preset::GxSettings::add_plugin_preset_list
void add_plugin_preset_list(PluginPresetList &l, UnitPresetList &presetnames)
gx_preset::GxSettings::bank_insert_uri
gx_system::PresetFile * bank_insert_uri(const Glib::ustring &uri, bool move, int position=0)
gx_preset::GxSettings::options
gx_system::CmdlineOptions & options
Definition gx_preset.h:150
gx_preset::GxSettings::sequencer_pos
volatile int sequencer_pos
Definition gx_preset.h:174
gx_preset::GxSettings::get_auto_save_state
bool get_auto_save_state()
Definition gx_preset.h:185
gx_preset::GxSettings::insert_rack_unit
void insert_rack_unit(const std::string &unit, const std::string &before, bool stereo)
gx_preset::GxSettings::preset_io
gx_preset::PresetIO preset_io
Definition gx_preset.h:143
gx_preset::GxSettings::plugin_preset_list_remove
void plugin_preset_list_remove(const PluginDef *pdef, const Glib::ustring &name)
gx_preset::GxSettings::plugin_preset_list_save
void plugin_preset_list_save(const PluginDef *pdef, const Glib::ustring &name)
gx_preset::GxSettings::create_default_scratch_preset
void create_default_scratch_preset()
gx_preset::GxSettings::auto_save_state
void auto_save_state()
gx_preset::GxSettings::jack_client_changed
void jack_client_changed()
gx_preset::GxSettings::set_preset
Glib::Dispatcher set_preset
Definition gx_preset.h:171
gx_preset::GxSettings::disable_save_on_exit
void disable_save_on_exit(bool v)
Definition gx_preset.h:187
gx_preset::GxSettings::bank_insert_new
gx_system::PresetFile * bank_insert_new(const Glib::ustring &name)
gx_preset::GxSettings::preset_sync_run
static void * preset_sync_run(void *p)
gx_preset::GxSettings::instance
static GxSettings * instance
Definition gx_preset.h:160
gx_preset::GxSettings::mctrl
gx_engine::MidiControllerList & mctrl
Definition gx_preset.h:149
gx_preset::GxSettings::plugin_preset_list_set
void plugin_preset_list_set(const PluginDef *pdef, bool factory, const Glib::ustring &name)
gx_preset::GxSettings::get_param
gx_engine::ParamMap & get_param() const
Definition gx_preset.h:181
gx_preset::GxSettings::remove_rack_unit
bool remove_rack_unit(const std::string &unit, bool stereo)
gx_preset::GxSettings::plugin_preset_list_sync_set
void plugin_preset_list_sync_set(const PluginDef *pdef, bool factory, const Glib::ustring &name)
gx_preset::GxSettings::state_io
gx_preset::StateIO state_io
Definition gx_preset.h:144
gx_preset::GxSettings::rack_units
UnitRacks rack_units
Definition gx_preset.h:153
gx_preset::GxSettings::exit_handler
void exit_handler(bool otherthread)
gx_preset::GxSettings::jack
gx_jack::GxJack & jack
Definition gx_preset.h:148
gx_preset::GxSettings::sync_run
void * sync_run()
gx_preset::GxSettings::sync_name
Glib::ustring sync_name
Definition gx_preset.h:165
gx_preset::GxSettings::make_default_state_filename
string make_default_state_filename()
gx_preset::GxSettings::rename_bank
bool rename_bank(const Glib::ustring &oldname, Glib::ustring &newname)
gx_preset::GxSettings::~GxSettings
~GxSettings()
gx_preset::GxSettings::get_sequencer_p
Glib::Dispatcher get_sequencer_p
Definition gx_preset.h:172
gx_preset::GxSettings::loadstate
void loadstate()
gx_preset::GxSettings::plugin_preset_list_load
void plugin_preset_list_load(const PluginDef *pdef, UnitPresetList &presetnames)
gx_preset::PluginPresetEntry::is_set
bool is_set
Definition gx_preset.h:134
gx_preset::PluginPresetEntry::PluginPresetEntry
PluginPresetEntry(const Glib::ustring &name_, bool is_set_)
Definition gx_preset.h:135
gx_preset::PluginPresetEntry::name
Glib::ustring name
Definition gx_preset.h:133
gx_preset::PluginPresetList
Definition gx_preset.h:113
gx_preset::PluginPresetList::save
void save(const Glib::ustring &name, const std::string &id, const char **groups)
gx_preset::PluginPresetList::write_values
void write_values(gx_system::JsonWriter &jw, std::string id, const char **groups)
gx_preset::PluginPresetList::filename
std::string filename
Definition gx_preset.h:115
gx_preset::PluginPresetList::PluginPresetList
PluginPresetList(const std::string &fname, gx_engine::ParamMap &pmap, gx_engine::MidiControllerList &mctrl_)
gx_preset::PluginPresetList::jp
gx_system::JsonParser jp
Definition gx_preset.h:119
gx_preset::PluginPresetList::set
bool set(const Glib::ustring &name)
gx_preset::PluginPresetList::pmap
gx_engine::ParamMap & pmap
Definition gx_preset.h:116
gx_preset::PluginPresetList::start
bool start()
gx_preset::PluginPresetList::is
ifstream is
Definition gx_preset.h:118
gx_preset::PluginPresetList::remove
bool remove(const Glib::ustring &name)
gx_preset::PluginPresetList::next
bool next(Glib::ustring &name, bool *is_set=0)
gx_preset::PluginPresetList::mctrl
gx_engine::MidiControllerList & mctrl
Definition gx_preset.h:117
gx_preset::PresetIO
Definition gx_preset.h:68
gx_preset::PresetIO::write_preset
void write_preset(gx_system::JsonWriter &jw) override
gx_preset::PresetIO::param
gx_engine::ParamMap & param
Definition gx_preset.h:71
gx_preset::PresetIO::fixup_parameters
void fixup_parameters(const gx_system::SettingsFileHeader &head)
gx_preset::PresetIO::plist
gx_engine::paramlist plist
Definition gx_preset.h:73
gx_preset::PresetIO::clear
void clear()
gx_preset::PresetIO::copy_preset
void copy_preset(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader &, gx_system::JsonWriter &jw) override
gx_preset::PresetIO::write_parameters
void write_parameters(gx_system::JsonWriter &w, bool preset)
gx_preset::PresetIO::midi_in_preset
bool midi_in_preset()
gx_preset::PresetIO::try_replace_param_value
static string try_replace_param_value(const std::string &id, const std::string &v_id, bool &found)
gx_preset::PresetIO::PresetIO
PresetIO(gx_engine::MidiControllerList &mctrl, gx_engine::ParamMap &param, gx_system::CmdlineOptions &opt, UnitRacks &rack_units)
gx_preset::PresetIO::commit_midi_feedback
void commit_midi_feedback(gx_engine::Parameter *p)
gx_preset::PresetIO::convert_old
bool convert_old(gx_system::JsonParser &jp)
gx_preset::PresetIO::StateIO
friend class StateIO
Definition gx_preset.h:87
gx_preset::PresetIO::rack_units
UnitRacks & rack_units
Definition gx_preset.h:75
gx_preset::PresetIO::mctrl
gx_engine::MidiControllerList & mctrl
Definition gx_preset.h:70
gx_preset::PresetIO::read_intern
void read_intern(gx_system::JsonParser &jp, bool *has_midi, const gx_system::SettingsFileHeader &head)
gx_preset::PresetIO::m
gx_engine::ControllerArray * m
Definition gx_preset.h:74
gx_preset::PresetIO::write_intern
void write_intern(gx_system::JsonWriter &w, bool write_midi)
gx_preset::PresetIO::commit_preset
void commit_preset() override
gx_preset::PresetIO::collectRackOrder
void collectRackOrder(gx_engine::Parameter *p, gx_system::JsonParser &jp, UnitsCollector &u)
gx_preset::PresetIO::opt
gx_system::CmdlineOptions & opt
Definition gx_preset.h:72
gx_preset::PresetIO::~PresetIO
~PresetIO()
gx_preset::PresetIO::read_parameters
void read_parameters(gx_system::JsonParser &jp, bool preset)
gx_preset::PresetIO::read_preset
void read_preset(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader &) override
gx_preset::StateIO
Definition gx_preset.h:99
gx_preset::StateIO::read_state
void read_state(gx_system::JsonParser &jp, const gx_system::SettingsFileHeader &) override
gx_preset::StateIO::commit_state
void commit_state() override
gx_preset::StateIO::StateIO
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_preset::StateIO::jack
gx_jack::GxJack & jack
Definition gx_preset.h:102
gx_preset::StateIO::midi_std_control
gx_engine::MidiStandardControllers & midi_std_control
Definition gx_preset.h:101
gx_preset::StateIO::write_state
void write_state(gx_system::JsonWriter &jw, bool preserve_preset) override
gx_preset::StateIO::~StateIO
~StateIO()
gx_preset::UnitPosition::visible
bool visible
Definition gx_preset.h:50
gx_preset::UnitPosition::show
bool show
Definition gx_preset.h:49
gx_preset::UnitPosition::pp
int pp
Definition gx_preset.h:52
gx_preset::UnitPosition::UnitPosition
UnitPosition()
Definition gx_preset.h:53
gx_preset::UnitPosition::position
int position
Definition gx_preset.h:51
gx_preset::UnitRacks
Definition gx_preset.h:39
gx_preset::UnitRacks::UnitRacks
UnitRacks()
Definition gx_preset.h:44
gx_preset::UnitRacks::rack_unit_order_changed
sigc::signal< void, bool > rack_unit_order_changed
Definition gx_preset.h:43
gx_preset::UnitRacks::mono
std::vector< std::string > mono
Definition gx_preset.h:41
gx_preset::UnitRacks::stereo
std::vector< std::string > stereo
Definition gx_preset.h:42
gx_preset::UnitsCollector
Definition gx_preset.h:56
gx_preset::UnitsCollector::set_pp
void set_pp(const std::string &s, bool v)
Definition gx_preset.h:63
gx_preset::UnitsCollector::set_show
void set_show(const std::string &s, bool v)
Definition gx_preset.h:60
gx_preset::UnitsCollector::empty
bool empty()
Definition gx_preset.h:65
gx_preset::UnitsCollector::m
std::map< std::string, UnitPosition > m
Definition gx_preset.h:58
gx_preset::UnitsCollector::set_position
void set_position(const std::string &s, int v)
Definition gx_preset.h:62
gx_preset::UnitsCollector::set_visible
void set_visible(const std::string &s, bool v)
Definition gx_preset.h:61
gx_preset::UnitsCollector::get_list
void get_list(std::vector< std::string > &l, bool stereo, gx_engine::ParamMap &param)
gx_system::AbstractPresetIO
Definition gx_json.h:406
gx_system::AbstractStateIO
Definition gx_json.h:398
gx_system::CmdlineOptions
Definition gx_system.h:395
gx_system::GxSettingsBase
Definition gx_json.h:463
gx_system::GxSettingsBase::seq
gx_engine::EngineControl & seq
Definition gx_json.h:471
gx_system::JsonParser
Definition gx_json.h:112
gx_system::JsonWriter
Definition gx_json.h:55
gx_system::PresetFile
Definition gx_json.h:299
gx_system::SettingsFileHeader
Definition gx_json.h:224
gx_engine::StringParameter
ParameterV< Glib::ustring > StringParameter
Definition gx_parameter.h:99
gx_engine::paramlist
list< Parameter * > paramlist
Definition gx_parameter.h:233
gx_preset
Definition gx_preset.h:33
gx_preset::UnitPresetList
std::vector< PluginPresetEntry > UnitPresetList
Definition gx_preset.h:138
PluginDef
Definition gx_plugin.h:195