From 85e6ccd81f4f3e8000c51faeab69db189a7d41fb Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Tue, 17 Dec 2019 12:32:01 +0100 Subject: [PATCH] Moved to larger CC arrays This accodomates the extended sfz v2 CC --- src/sfizz/EGDescription.h | 14 +++++++------- src/sfizz/MidiState.cpp | 4 ++-- src/sfizz/MidiState.h | 12 ++++++------ src/sfizz/Region.cpp | 2 +- src/sfizz/Region.h | 2 +- src/sfizz/SfzHelpers.h | 4 ++-- tests/FilesT.cpp | 1 - 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/sfizz/EGDescription.h b/src/sfizz/EGDescription.h index bdec2e76..e7a93d15 100644 --- a/src/sfizz/EGDescription.h +++ b/src/sfizz/EGDescription.h @@ -77,7 +77,7 @@ struct EGDescription * @param velocity * @return float */ - float getAttack(const CCValueArray &ccValues, uint8_t velocity) const noexcept + float getAttack(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { return ccSwitchedValue(ccValues, ccAttack, attack) + normalizeCC(velocity)*vel2attack; } @@ -88,7 +88,7 @@ struct EGDescription * @param velocity * @return float */ - float getDecay(const CCValueArray &ccValues, uint8_t velocity) const noexcept + float getDecay(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { return ccSwitchedValue(ccValues, ccDecay, decay) + normalizeCC(velocity)*vel2decay; } @@ -99,7 +99,7 @@ struct EGDescription * @param velocity * @return float */ - float getDelay(const CCValueArray &ccValues, uint8_t velocity) const noexcept + float getDelay(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { return ccSwitchedValue(ccValues, ccDelay, delay) + normalizeCC(velocity)*vel2delay; } @@ -110,7 +110,7 @@ struct EGDescription * @param velocity * @return float */ - float getHold(const CCValueArray &ccValues, uint8_t velocity) const noexcept + float getHold(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { return ccSwitchedValue(ccValues, ccHold, hold) + normalizeCC(velocity)*vel2hold; } @@ -121,7 +121,7 @@ struct EGDescription * @param velocity * @return float */ - float getRelease(const CCValueArray &ccValues, uint8_t velocity) const noexcept + float getRelease(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { return ccSwitchedValue(ccValues, ccRelease, release) + normalizeCC(velocity)*vel2release; } @@ -132,7 +132,7 @@ struct EGDescription * @param velocity * @return float */ - float getStart(const CCValueArray &ccValues, uint8_t velocity [[maybe_unused]]) const noexcept + float getStart(const SfzCCArray &ccValues, uint8_t velocity [[maybe_unused]]) const noexcept { return ccSwitchedValue(ccValues, ccStart, start); } @@ -143,7 +143,7 @@ struct EGDescription * @param velocity * @return float */ - float getSustain(const CCValueArray &ccValues, uint8_t velocity) const noexcept + float getSustain(const SfzCCArray &ccValues, uint8_t velocity) const noexcept { return ccSwitchedValue(ccValues, ccSustain, sustain) + normalizeCC(velocity)*vel2sustain; } diff --git a/src/sfizz/MidiState.cpp b/src/sfizz/MidiState.cpp index 0766b5c5..1ee9bb35 100644 --- a/src/sfizz/MidiState.cpp +++ b/src/sfizz/MidiState.cpp @@ -58,7 +58,7 @@ int sfz::MidiState::getPitchBend(int channel) const noexcept void sfz::MidiState::ccEvent(int channel, int ccNumber, uint8_t ccValue) noexcept { ASSERT(channel >= 0 && channel < 16); - ASSERT(ccNumber >= 0 && ccNumber <= 127); + ASSERT(ccNumber >= 0 && ccNumber <= 142); ASSERT(ccValue >= 0 && ccValue <= 127); cc[channel][ccNumber] = ccValue; @@ -72,7 +72,7 @@ uint8_t sfz::MidiState::getCCValue(int channel, int ccNumber) const noexcept return cc[channel][ccNumber]; } -const sfz::CCValueArray& sfz::MidiState::getCCArray(int channel) const noexcept +const sfz::SfzCCArray& sfz::MidiState::getCCArray(int channel) const noexcept { ASSERT(channel >= 0 && channel < 16); diff --git a/src/sfizz/MidiState.h b/src/sfizz/MidiState.h index 949e0764..d1cfee06 100644 --- a/src/sfizz/MidiState.h +++ b/src/sfizz/MidiState.h @@ -80,9 +80,9 @@ public: * @brief Get the full CC status for a specific channel * * @param channel - * @return const CCValueArray& + * @return const SfzCCArray& */ - const CCValueArray& getCCArray(int channel) const noexcept; + const SfzCCArray& getCCArray(int channel) const noexcept; /** * @brief Reset the midi state (does not impact the last note on time) @@ -94,24 +94,24 @@ private: template using ChannelArray = std::array; template - using MidiArray = std::array; + using MidiNoteArray = std::array; using NoteOnTime = std::chrono::steady_clock::time_point; /** * @brief Stores the note on times. * */ - ChannelArray> noteOnTimes { }; + ChannelArray> noteOnTimes { }; /** * @brief Stores the velocity of the note ons for currently * depressed notes. * */ - ChannelArray> lastNoteVelocities { }; + ChannelArray> lastNoteVelocities { }; /** * @brief Current known values for the CCs. * */ - ChannelArray cc; + ChannelArray cc; /** * Pitch bend status */ diff --git a/src/sfizz/Region.cpp b/src/sfizz/Region.cpp index f5563fb8..77b61d17 100644 --- a/src/sfizz/Region.cpp +++ b/src/sfizz/Region.cpp @@ -749,7 +749,7 @@ float sfz::Region::getNoteGain(int noteNumber, uint8_t velocity) noexcept return baseGain; } -float sfz::Region::getCrossfadeGain(const sfz::CCValueArray& ccState) noexcept +float sfz::Region::getCrossfadeGain(const sfz::SfzCCArray& ccState) noexcept { float gain { 1.0f }; diff --git a/src/sfizz/Region.h b/src/sfizz/Region.h index 9b1fa044..9b6eb81e 100644 --- a/src/sfizz/Region.h +++ b/src/sfizz/Region.h @@ -172,7 +172,7 @@ struct Region { * @param ccState * @return float */ - float getCrossfadeGain(const CCValueArray& ccState) noexcept; + float getCrossfadeGain(const SfzCCArray& ccState) noexcept; /** * @brief Get the base volume of the region depending on which note has been * pressed to trigger the region. diff --git a/src/sfizz/SfzHelpers.h b/src/sfizz/SfzHelpers.h index f35333b3..5ea4262d 100644 --- a/src/sfizz/SfzHelpers.h +++ b/src/sfizz/SfzHelpers.h @@ -31,7 +31,7 @@ namespace sfz { -using CCValueArray = std::array; +using SfzCCArray = std::array; using CCValuePair = std::pair ; using CCNamePair = std::pair; @@ -109,7 +109,7 @@ constexpr float normalizeNegativePercents(T percentValue) * @param value * @return float */ -inline float ccSwitchedValue(const CCValueArray& ccValues, const absl::optional& ccSwitch, float value) noexcept +inline float ccSwitchedValue(const SfzCCArray& ccValues, const absl::optional& ccSwitch, float value) noexcept { if (ccSwitch) return value + ccSwitch->second * normalizeCC(ccValues[ccSwitch->first]); diff --git a/tests/FilesT.cpp b/tests/FilesT.cpp index 88c2f316..74308b3f 100644 --- a/tests/FilesT.cpp +++ b/tests/FilesT.cpp @@ -336,7 +336,6 @@ TEST_CASE("[Synth] Testing channel 1") REQUIRE( region->sample == "dummy1.wav" ); } - TEST_CASE("[Synth] Testing channel 2") { sfz::Synth synth;