diff --git a/sources/Synth.cpp b/sources/Synth.cpp index c29e86d2..38dc16eb 100644 --- a/sources/Synth.cpp +++ b/sources/Synth.cpp @@ -1,5 +1,6 @@ #include "Synth.h" #include "Helpers.h" +#include "absl/algorithm/container.h" #include #include #include @@ -124,6 +125,28 @@ void sfz::Synth::handleControlOpcodes(const std::vector& members) } } +void addEndpointsToVelocityCurve(sfz::Region& region) +{ + if (region.velocityPoints.size() > 0) + { + absl::c_sort(region.velocityPoints, [](auto& lhs, auto& rhs) { return lhs.first < rhs.first; }); + if (region.ampVeltrack > 0) + { + if (region.velocityPoints.back().first != sfz::Default::velocityRange.getEnd()) + region.velocityPoints.push_back(std::make_pair(127, 1.0f)); + if (region.velocityPoints.front().first != sfz::Default::velocityRange.getStart()) + region.velocityPoints.insert(region.velocityPoints.begin(), std::make_pair(0, 0.0f)); + } + else + { + if (region.velocityPoints.front().first != sfz::Default::velocityRange.getEnd()) + region.velocityPoints.insert(region.velocityPoints.begin(), std::make_pair(127, 0.0f)); + if (region.velocityPoints.back().first != sfz::Default::velocityRange.getStart()) + region.velocityPoints.push_back(std::make_pair(0, 1.0f)); + } + } +} + bool sfz::Synth::loadSfzFile(const std::filesystem::path& filename) { clear(); @@ -172,10 +195,7 @@ bool sfz::Synth::loadSfzFile(const std::filesystem::path& filename) region->registerNoteOff(region->channelRange.getStart(), *defaultSwitch, 0, 1.0); } - absl::c_sort(region->velocityPoints, [](const auto& lhs, const auto& rhs) { - return lhs.first < rhs.first; - }); - + addEndpointsToVelocityCurve(*region); region->registerPitchWheel(region->channelRange.getStart(), 0); region->registerAftertouch(region->channelRange.getStart(), 0); region->registerTempo(2.0f);