diff options
author | André Nusser <andre.nusser@googlemail.com> | 2016-04-22 10:17:22 +0200 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2016-04-22 10:17:22 +0200 |
commit | 0571c71aa9fb91adbd246a91a27dd607effad76b (patch) | |
tree | 09cf9a6dd9b27c3a4b48e339247484881bce3b72 /src | |
parent | f8be5a6d8d0be47596e1d9e6050e6e134f1e4167 (diff) |
Revert "A little refactoring for drumgizmo.cc."
This reverts commit f8be5a6d8d0be47596e1d9e6050e6e134f1e4167.
Stupid locale bug re-introduced, thus reverting.
Diffstat (limited to 'src')
-rw-r--r-- | src/drumgizmo.cc | 46 | ||||
-rw-r--r-- | src/drumgizmo.h | 9 |
2 files changed, 37 insertions, 18 deletions
diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index 46250f0..aa6be23 100644 --- a/src/drumgizmo.cc +++ b/src/drumgizmo.cc @@ -107,9 +107,9 @@ bool DrumGizmo::loadkit(std::string file) loader.loadKit(&kit); #ifdef WITH_RESAMPLER - for(auto& chresampler: resampler) + for(int i = 0; i < MAX_NUM_CHANNELS; ++i) { - chresampler.setup(kit.getSamplerate(), settings.samplerate.load()); + resampler[i].setup(kit.getSamplerate(), settings.samplerate.load()); } #endif/*WITH_RESAMPLER*/ @@ -602,9 +602,9 @@ void DrumGizmo::setSamplerate(int samplerate) DEBUG(dgeditor, "%s samplerate: %d\n", __PRETTY_FUNCTION__, samplerate); settings.samplerate.store(samplerate); #ifdef WITH_RESAMPLER - for(auto& chresampler: resampler) + for(int i = 0; i < MAX_NUM_CHANNELS; ++i) { - chresampler.setup(kit.getSamplerate(), settings.samplerate.load()); + resampler[i].setup(kit.getSamplerate(), settings.samplerate.load()); } if(resampler[0].getRatio() != 1) { @@ -613,6 +613,28 @@ 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; @@ -627,15 +649,15 @@ std::string DrumGizmo::configString() " <value name=\"drumkitfile\">" + kit.getFile() + "</value>\n" " <value name=\"midimapfile\">" + mmapfile + "</value>\n" " <value name=\"enable_velocity_modifier\">" + - std::to_string(settings.enable_velocity_modifier.load()) + "</value>\n" + bool2str(settings.enable_velocity_modifier.load()) + "</value>\n" " <value name=\"velocity_modifier_falloff\">" + - std::to_string(settings.velocity_modifier_falloff.load()) + "</value>\n" + float2str(settings.velocity_modifier_falloff.load()) + "</value>\n" " <value name=\"velocity_modifier_weight\">" + - std::to_string(settings.velocity_modifier_weight.load()) + "</value>\n" + float2str(settings.velocity_modifier_weight.load()) + "</value>\n" " <value name=\"enable_velocity_randomiser\">" + - std::to_string(settings.enable_velocity_randomiser.load()) + "</value>\n" + bool2str(settings.enable_velocity_randomiser.load()) + "</value>\n" " <value name=\"velocity_randomiser_weight\">" + - std::to_string(settings.velocity_randomiser_weight.load()) + "</value>\n" + float2str(settings.velocity_randomiser_weight.load()) + "</value>\n" "</config>"; } @@ -658,12 +680,12 @@ bool DrumGizmo::setConfigString(std::string cfg) if(p.value("velocity_modifier_falloff") != "") { - settings.velocity_modifier_falloff.store(std::stof(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(std::stof(p.value("velocity_modifier_weight"))); + settings.velocity_modifier_weight.store(str2float(p.value("velocity_modifier_weight"))); } if(p.value("enable_velocity_randomiser") != "") @@ -673,7 +695,7 @@ bool DrumGizmo::setConfigString(std::string cfg) if(p.value("velocity_randomiser_weight") != "") { - settings.velocity_randomiser_weight.store(std::stof(p.value("velocity_randomiser_weight"))); + settings.velocity_randomiser_weight.store(str2float(p.value("velocity_randomiser_weight"))); } if(p.value("enable_resampling") != "") diff --git a/src/drumgizmo.h b/src/drumgizmo.h index 13c657d..7af5dbb 100644 --- a/src/drumgizmo.h +++ b/src/drumgizmo.h @@ -42,7 +42,9 @@ #include "configfile.h" #include "settings.h" +#define MAX_NUM_CHANNELS 64 #define REFSFILE "refs.conf" +#define RESAMPLER_INPUT_BUFFER 64 class DrumGizmo { @@ -71,11 +73,6 @@ public: void setFreeWheel(bool freewheel); -private: - static const int MAX_NUM_CHANNELS = 64; - static const int RESAMPLER_OUTPUT_BUFFER = 4096; - static const int RESAMPLER_INPUT_BUFFER = 64; - protected: DrumKitLoader loader; @@ -88,7 +85,7 @@ protected: std::list< Event* > activeevents[MAX_NUM_CHANNELS]; CHResampler resampler[MAX_NUM_CHANNELS]; - sample_t resampler_output_buffer[MAX_NUM_CHANNELS][RESAMPLER_OUTPUT_BUFFER]; + sample_t resampler_output_buffer[MAX_NUM_CHANNELS][4096]; sample_t resampler_input_buffer[MAX_NUM_CHANNELS][RESAMPLER_INPUT_BUFFER]; std::map<std::string, AudioFile *> audiofiles; |