From f8be5a6d8d0be47596e1d9e6050e6e134f1e4167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Thu, 21 Apr 2016 21:05:43 +0200 Subject: A little refactoring for drumgizmo.cc. Range based loops, static const member variables instead of #define, c++11 convert from and to strings. --- src/drumgizmo.cc | 46 ++++++++++++---------------------------------- 1 file changed, 12 insertions(+), 34 deletions(-) (limited to 'src/drumgizmo.cc') diff --git a/src/drumgizmo.cc b/src/drumgizmo.cc index aa6be23..46250f0 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(int i = 0; i < MAX_NUM_CHANNELS; ++i) + for(auto& chresampler: resampler) { - resampler[i].setup(kit.getSamplerate(), settings.samplerate.load()); + chresampler.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(int i = 0; i < MAX_NUM_CHANNELS; ++i) + for(auto& chresampler: resampler) { - resampler[i].setup(kit.getSamplerate(), settings.samplerate.load()); + chresampler.setup(kit.getSamplerate(), settings.samplerate.load()); } if(resampler[0].getRatio() != 1) { @@ -613,28 +613,6 @@ 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; @@ -649,15 +627,15 @@ std::string DrumGizmo::configString() " " + kit.getFile() + "\n" " " + mmapfile + "\n" " " + - bool2str(settings.enable_velocity_modifier.load()) + "\n" + std::to_string(settings.enable_velocity_modifier.load()) + "\n" " " + - float2str(settings.velocity_modifier_falloff.load()) + "\n" + std::to_string(settings.velocity_modifier_falloff.load()) + "\n" " " + - float2str(settings.velocity_modifier_weight.load()) + "\n" + std::to_string(settings.velocity_modifier_weight.load()) + "\n" " " + - bool2str(settings.enable_velocity_randomiser.load()) + "\n" + std::to_string(settings.enable_velocity_randomiser.load()) + "\n" " " + - float2str(settings.velocity_randomiser_weight.load()) + "\n" + std::to_string(settings.velocity_randomiser_weight.load()) + "\n" ""; } @@ -680,12 +658,12 @@ bool DrumGizmo::setConfigString(std::string cfg) if(p.value("velocity_modifier_falloff") != "") { - settings.velocity_modifier_falloff.store(str2float(p.value("velocity_modifier_falloff"))); + settings.velocity_modifier_falloff.store(std::stof(p.value("velocity_modifier_falloff"))); } if(p.value("velocity_modifier_weight") != "") { - settings.velocity_modifier_weight.store(str2float(p.value("velocity_modifier_weight"))); + settings.velocity_modifier_weight.store(std::stof(p.value("velocity_modifier_weight"))); } if(p.value("enable_velocity_randomiser") != "") @@ -695,7 +673,7 @@ bool DrumGizmo::setConfigString(std::string cfg) if(p.value("velocity_randomiser_weight") != "") { - settings.velocity_randomiser_weight.store(str2float(p.value("velocity_randomiser_weight"))); + settings.velocity_randomiser_weight.store(std::stof(p.value("velocity_randomiser_weight"))); } if(p.value("enable_resampling") != "") -- cgit v1.2.3