Merge pull request #1039 from paulfd/sw-last-octave-offset

sw_last is affected by octave/note offsets
This commit is contained in:
Paul Ferrand 2021-11-21 00:07:37 +01:00 committed by GitHub
commit 2aab560f39
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 4 deletions

View file

@ -205,7 +205,7 @@ void Synth::Impl::buildRegion(const std::vector<Opcode>& regionOpcodes)
previousKeyswitchLists_.push_back(lastLayer);
if (lastRegion->defaultSwitch)
currentSwitch_ = *lastRegion->defaultSwitch;
setCurrentSwitch(*lastRegion->defaultSwitch);
// There was a combination of group= and polyphony= on a region, so set the group polyphony
if (lastRegion->group != Default::group && lastRegion->polyphony != config::maxVoices) {
@ -320,7 +320,7 @@ void Synth::Impl::handleMasterOpcodes(const std::vector<Opcode>& members)
currentSet_->setPolyphonyLimit(member.read(Default::polyphony));
break;
case hash("sw_default"):
currentSwitch_ = member.read(Default::key);
setCurrentSwitch(member.read(Default::key));
break;
}
}
@ -337,7 +337,7 @@ void Synth::Impl::handleGlobalOpcodes(const std::vector<Opcode>& members)
currentSet_->setPolyphonyLimit(member.read(Default::polyphony));
break;
case hash("sw_default"):
currentSwitch_ = member.read(Default::key);
setCurrentSwitch(member.read(Default::key));
break;
case hash("volume"):
// FIXME : Probably best not to mess with this and let the host control the volume
@ -363,7 +363,7 @@ void Synth::Impl::handleGroupOpcodes(const std::vector<Opcode>& members, const s
maxPolyphony = member.read(Default::polyphony);
break;
case hash("sw_default"):
currentSwitch_ = member.read(Default::key);
setCurrentSwitch(member.read(Default::key));
break;
}
};
@ -645,6 +645,11 @@ bool Synth::loadSfzString(const fs::path& path, absl::string_view text)
return true;
}
void Synth::Impl::setCurrentSwitch(uint8_t noteValue)
{
currentSwitch_ = noteValue + 12 * octaveOffset_ + noteOffset_;
}
void Synth::Impl::finalizeSfzLoad()
{
FilePool& filePool = resources_.getFilePool();

View file

@ -197,6 +197,13 @@ struct Synth::Impl final: public Parser::Listener {
*/
void finalizeSfzLoad();
/**
* @brief Set the current keyswitch, taking into account octave offsets and the like.
*
* @param noteValue
*/
void setCurrentSwitch(uint8_t noteValue);
template<class T>
static void collectUsedCCsFromCCMap(BitArray<config::numCCs>& usedCCs, const CCMap<T> map) noexcept
{

View file

@ -8,6 +8,7 @@
#include "sfizz/Region.h"
#include "sfizz/Synth.h"
#include "sfizz/SfzHelpers.h"
#include "TestHelpers.h"
#include "catch2/catch.hpp"
using namespace Catch::literals;
using namespace sfz::literals;
@ -655,3 +656,53 @@ TEST_CASE("[Region activation] Polyphonic aftertouch")
}
}
TEST_CASE("[Keyswitches] sw_default with octave_offset")
{
sfz::Synth synth;
std::vector<std::string> messageList;
sfz::Client client(&messageList);
client.setReceiveCallback(&simpleMessageReceiver);
sfz::AudioBuffer<float> buffer { 2, static_cast<unsigned>(synth.getSamplesPerBlock()) };
std::vector<std::string> expected {
"/sw/last/current,i : { 59 }",
};
SECTION("In <global>") {
synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_previous.sfz", R"(
<control> octave_offset=1 note_offset=-1
<global> sw_default=48
<region> sample=*sine
)");
synth.dispatchMessage(client, 0, "/sw/last/current", "", nullptr);
REQUIRE(messageList == expected);
}
SECTION("In <master>") {
synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_previous.sfz", R"(
<control> octave_offset=1 note_offset=-1
<master> sw_default=48
<region> sample=*sine
)");
synth.dispatchMessage(client, 0, "/sw/last/current", "", nullptr);
REQUIRE(messageList == expected);
}
SECTION("In <group>") {
synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_previous.sfz", R"(
<control> octave_offset=1 note_offset=-1
<group> sw_default=48
<region> sample=*sine
)");
synth.dispatchMessage(client, 0, "/sw/last/current", "", nullptr);
REQUIRE(messageList == expected);
}
SECTION("In <region>") {
synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_previous.sfz", R"(
<control> octave_offset=1 note_offset=-1
<region> sample=*sine sw_default=48
)");
synth.dispatchMessage(client, 0, "/sw/last/current", "", nullptr);
REQUIRE(messageList == expected);
}
}