Support for the reset CC

This commit is contained in:
Paul Ferrand 2019-12-17 22:56:25 +01:00
parent b00103d342
commit f2c6ac95a7
4 changed files with 51 additions and 3 deletions

View file

@ -91,4 +91,14 @@ void sfz::MidiState::reset() noexcept
for (auto& bendValue: pitchBends)
bendValue = 0;
}
void sfz::MidiState::resetAllControllers(int channel) noexcept
{
ASSERT(channel >= 0 && channel < 16);
for (int idx = 0; idx < config::numCCs; idx++)
cc[channel][idx] = 0;
pitchBends[channel] = 0;
}

View file

@ -90,6 +90,13 @@ public:
*/
void reset() noexcept;
/**
* @brief Res
*
* @param channel
*/
void resetAllControllers(int channel) noexcept;
private:
template<class T>
using ChannelArray = std::array<T, 16>;

View file

@ -443,16 +443,19 @@ void sfz::Synth::cc(int delay, int channel, int ccNumber, uint8_t ccValue) noexc
ASSERT(ccNumber < config::numCCs);
ASSERT(ccNumber >= 0);
AtomicGuard callbackGuard { inCallback };
if (!canEnterCallback)
return;
midiState.ccEvent(channel, ccNumber, ccValue);
if (ccNumber == config::resetCC) {
resetAllControllers(delay, channel);
return;
}
midiState.ccEvent(channel, ccNumber, ccValue);
for (auto& voice : voices)
voice->registerCC(delay, channel, ccNumber, ccValue);
for (auto& region : ccActivationLists[ccNumber]) {
if (region->registerCC(channel, ccNumber, ccValue)) {
auto voice = findFreeVoice();
@ -607,3 +610,22 @@ void sfz::Synth::disableFreeWheeling() noexcept
DBG("Disabling freewheeling");
}
}
void sfz::Synth::resetAllControllers(int delay, int channel) noexcept
{
AtomicGuard callbackGuard { inCallback };
if (!canEnterCallback)
return;
midiState.resetAllControllers(channel);
for (auto& voice: voices) {
voice->registerPitchWheel(delay, channel, 0);
for (int cc = 0; cc < config::numCCs; ++cc)
voice->registerCC(delay, channel, cc, 0);
}
for (auto& region: regions) {
for (int cc = 0; cc < config::numCCs; ++cc)
region->registerCC(channel, cc, 0);
}
}

View file

@ -359,6 +359,15 @@ protected:
void callback(absl::string_view header, const std::vector<Opcode>& members) final;
private:
/**
* @brief Reset all CCs; to be used on CC 121
*
* @param delay the delay for the controller reset
* @param channel the channel on which to reset the controller
*
*/
void resetAllControllers(int delay, int channel) noexcept;
int numGroups { 0 };
int numMasters { 0 };
int numCurves { 0 };