summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugin/drumgizmo_plugin.cc126
-rw-r--r--plugin/drumgizmo_plugin.h12
-rw-r--r--src/drumgizmo.cc110
-rw-r--r--src/drumgizmo.h5
4 files changed, 136 insertions, 117 deletions
diff --git a/plugin/drumgizmo_plugin.cc b/plugin/drumgizmo_plugin.cc
index 68a7a91..5e4ebeb 100644
--- a/plugin/drumgizmo_plugin.cc
+++ b/plugin/drumgizmo_plugin.cc
@@ -36,6 +36,11 @@
#include <midievent.h>
+#include <hugin.hpp>
+
+#include "configparser.h"
+#include "nolocale.h"
+
#ifdef LV2
// Entry point for lv2 plugin instantiation.
PluginLV2* createEffectInstance()
@@ -52,10 +57,12 @@ AudioEffect* createEffectInstance(audioMasterCallback audioMaster)
}
DrumGizmoPlugin::DrumGizmoPlugin(audioMasterCallback audioMaster)
- : PluginVST(audioMaster)
+ : PluginVST(audioMaster),
#else
DrumGizmoPlugin::DrumGizmoPlugin()
+ :
#endif
+ config_string_io(settings)
{
init();
@@ -82,12 +89,12 @@ void DrumGizmoPlugin::onActiveChange(bool active)
std::string DrumGizmoPlugin::onStateSave()
{
- return drumgizmo->configString();
+ return config_string_io.get();
}
void DrumGizmoPlugin::onStateRestore(const std::string& config)
{
- drumgizmo->setConfigString(config);
+ config_string_io.set(config);
}
size_t DrumGizmoPlugin::getNumberOfMidiInputs()
@@ -336,3 +343,116 @@ bool DrumGizmoPlugin::Output::isFreewheeling() const
{
return plugin.getFreeWheel();
}
+
+//
+// ConfigStringIO
+//
+
+// anonymous namespace for helper furnctions of ConfigStringIO
+namespace
+{
+
+std::string float2str(float a)
+{
+ char buf[256];
+ snprintf_nol(buf, sizeof(buf) - 1, "%f", a);
+ return buf;
+}
+
+std::string bool2str(bool a)
+{
+ return a?"true":"false";
+}
+
+float str2float(std::string a)
+{
+ if(a == "")
+ {
+ return 0.0;
+ }
+
+ return atof_nol(a.c_str());
+}
+
+} // end anonymous namespace
+
+DrumGizmoPlugin::ConfigStringIO::ConfigStringIO(Settings& settings)
+ : settings(settings)
+{
+
+}
+
+std::string DrumGizmoPlugin::ConfigStringIO::get()
+{
+ return
+ "<config>\n"
+ " <value name=\"drumkitfile\">" + settings.drumkit_file.load() + "</value>\n"
+ " <value name=\"midimapfile\">" + settings.midimap_file.load() + "</value>\n"
+ " <value name=\"enable_velocity_modifier\">" +
+ bool2str(settings.enable_velocity_modifier.load()) + "</value>\n"
+ " <value name=\"velocity_modifier_falloff\">" +
+ float2str(settings.velocity_modifier_falloff.load()) + "</value>\n"
+ " <value name=\"velocity_modifier_weight\">" +
+ float2str(settings.velocity_modifier_weight.load()) + "</value>\n"
+ " <value name=\"enable_velocity_randomiser\">" +
+ bool2str(settings.enable_velocity_randomiser.load()) + "</value>\n"
+ " <value name=\"velocity_randomiser_weight\">" +
+ float2str(settings.velocity_randomiser_weight.load()) + "</value>\n"
+ "</config>";
+}
+
+bool DrumGizmoPlugin::ConfigStringIO::set(std::string config_string)
+{
+ DEBUG(config, "Load config: %s\n", config_string.c_str());
+
+ ConfigParser p;
+ if(p.parseString(config_string))
+ {
+ ERR(config, "Config parse error.\n");
+ return false;
+ }
+
+ if(p.value("enable_velocity_modifier") != "")
+ {
+ settings.enable_velocity_modifier.store(p.value("enable_velocity_modifier") == "true");
+ }
+
+ if(p.value("velocity_modifier_falloff") != "")
+ {
+ settings.velocity_modifier_falloff.store(str2float(p.value("velocity_modifier_falloff")));
+ }
+
+ if(p.value("velocity_modifier_weight") != "")
+ {
+ settings.velocity_modifier_weight.store(str2float(p.value("velocity_modifier_weight")));
+ }
+
+ if(p.value("enable_velocity_randomiser") != "")
+ {
+ settings.enable_velocity_randomiser.store(p.value("enable_velocity_randomiser") == "true");
+ }
+
+ if(p.value("velocity_randomiser_weight") != "")
+ {
+ settings.velocity_randomiser_weight.store(str2float(p.value("velocity_randomiser_weight")));
+ }
+
+ if(p.value("enable_resampling") != "")
+ {
+ settings.enable_resampling.store(p.value("enable_resampling") == "true");
+ }
+
+ std::string newkit = p.value("drumkitfile");
+ if(newkit != "")
+ {
+ settings.drumkit_file.store(newkit);
+ }
+
+ std::string newmidimap = p.value("midimapfile");
+ if(newmidimap != "")
+ {
+ settings.midimap_file.store(newmidimap);
+ }
+
+ return true;
+}
diff --git a/plugin/drumgizmo_plugin.h b/plugin/drumgizmo_plugin.h
index be9663f..2e3da26 100644
--- a/plugin/drumgizmo_plugin.h
+++ b/plugin/drumgizmo_plugin.h
@@ -155,6 +155,17 @@ private:
DrumGizmoPlugin& plugin;
};
+ class ConfigStringIO
+ {
+ public:
+ ConfigStringIO(Settings& settings);
+
+ std::string get();
+ bool set(std::string config_string);
+ private:
+ Settings& settings;
+ };
+
Input input{*this};
const std::vector<MidiEvent>* input_events{nullptr};
@@ -162,6 +173,7 @@ private:
const std::vector<float*>* output_samples{nullptr};
Settings settings;
+ ConfigStringIO config_string_io;
std::shared_ptr<GUI::PluginGUI> plugin_gui;
std::shared_ptr<DrumGizmo> drumgizmo;
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc
index b6d464f..fa601e6 100644
--- a/src/drumgizmo.cc
+++ b/src/drumgizmo.cc
@@ -37,16 +37,13 @@
#include <hugin.hpp>
-#include <config.h>
#include <memory>
+#include <config.h>
#include <iostream>
#include "drumkitparser.h"
#include "audioinputenginemidi.h"
-#include "configparser.h"
-
-#include "nolocale.h"
DrumGizmo::DrumGizmo(Settings& settings,
AudioOutputEngine& o, AudioInputEngine& i)
@@ -411,108 +408,3 @@ void DrumGizmo::setSamplerate(int samplerate)
}
#endif/*WITH_RESAMPLER*/
}
-
-std::string float2str(float a)
-{
- char buf[256];
- snprintf_nol(buf, sizeof(buf) - 1, "%f", a);
- return buf;
-}
-
-std::string bool2str(bool a)
-{
- return a?"true":"false";
-}
-
-float str2float(std::string a)
-{
- if(a == "")
- {
- return 0.0;
- }
-
- return atof_nol(a.c_str());
-}
-
-std::string DrumGizmo::configString()
-{
- std::string mmapfile;
- auto midiEngine = dynamic_cast<AudioInputEngineMidi*>(&ie);
- if(midiEngine)
- {
- mmapfile = midiEngine->getMidimapFile();
- }
-
- return
- "<config>\n"
- " <value name=\"drumkitfile\">" + kit.getFile() + "</value>\n"
- " <value name=\"midimapfile\">" + mmapfile + "</value>\n"
- " <value name=\"enable_velocity_modifier\">" +
- bool2str(settings.enable_velocity_modifier.load()) + "</value>\n"
- " <value name=\"velocity_modifier_falloff\">" +
- float2str(settings.velocity_modifier_falloff.load()) + "</value>\n"
- " <value name=\"velocity_modifier_weight\">" +
- float2str(settings.velocity_modifier_weight.load()) + "</value>\n"
- " <value name=\"enable_velocity_randomiser\">" +
- bool2str(settings.enable_velocity_randomiser.load()) + "</value>\n"
- " <value name=\"velocity_randomiser_weight\">" +
- float2str(settings.velocity_randomiser_weight.load()) + "</value>\n"
- "</config>";
-}
-
-bool DrumGizmo::setConfigString(std::string cfg)
-{
- DEBUG(config, "Load config: %s\n", cfg.c_str());
-
- std::string dkf;
- ConfigParser p;
- if(p.parseString(cfg))
- {
- ERR(drumgizmo, "Config parse error.\n");
- return false;
- }
-
- if(p.value("enable_velocity_modifier") != "")
- {
- settings.enable_velocity_modifier.store(p.value("enable_velocity_modifier") == "true");
- }
-
- if(p.value("velocity_modifier_falloff") != "")
- {
- settings.velocity_modifier_falloff.store(str2float(p.value("velocity_modifier_falloff")));
- }
-
- if(p.value("velocity_modifier_weight") != "")
- {
- settings.velocity_modifier_weight.store(str2float(p.value("velocity_modifier_weight")));
- }
-
- if(p.value("enable_velocity_randomiser") != "")
- {
- settings.enable_velocity_randomiser.store(p.value("enable_velocity_randomiser") == "true");
- }
-
- if(p.value("velocity_randomiser_weight") != "")
- {
- settings.velocity_randomiser_weight.store(str2float(p.value("velocity_randomiser_weight")));
- }
-
- if(p.value("enable_resampling") != "")
- {
- settings.enable_resampling.store(p.value("enable_resampling") == "true");
- }
-
- std::string newkit = p.value("drumkitfile");
- if(newkit != "")
- {
- settings.drumkit_file.store(newkit);
- }
-
- std::string newmidimap = p.value("midimapfile");
- if(newmidimap != "")
- {
- settings.midimap_file.store(newmidimap);
- }
-
- return true;
-}
diff --git a/src/drumgizmo.h b/src/drumgizmo.h
index 8ad77d3..b104772 100644
--- a/src/drumgizmo.h
+++ b/src/drumgizmo.h
@@ -39,7 +39,6 @@
#include "audiocache.h"
#include "mutex.h"
#include "chresampler.h"
-#include "configfile.h"
#include "settings.h"
#include "inputprocessor.h"
@@ -60,9 +59,6 @@ public:
void getSamples(int ch, int pos, sample_t *s, size_t sz);
- std::string configString();
- bool setConfigString(std::string cfg);
-
//! Get the current engine latency in samples.
std::size_t getLatency() const;
@@ -105,6 +101,5 @@ protected:
std::vector<event_t> events;
Settings& settings;
- SettingsGetter getter{settings};
Random rand;
};