Const all the region getters

This commit is contained in:
Paul Ferrand 2020-03-28 20:23:14 +01:00
parent 5e6de480fb
commit b17f9eaf32
2 changed files with 20 additions and 25 deletions

View file

@ -52,14 +52,12 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
break;
case hash("delay_random"):
setValueFromOpcode(opcode, delayRandom, Default::delayRange);
delayDistribution.param(std::uniform_real_distribution<float>::param_type(0, delayRandom));
break;
case hash("offset"):
setValueFromOpcode(opcode, offset, Default::offsetRange);
break;
case hash("offset_random"):
setValueFromOpcode(opcode, offsetRandom, Default::offsetRange);
offsetDistribution.param(std::uniform_int_distribution<uint32_t>::param_type(0, offsetRandom));
break;
case hash("end"):
setValueFromOpcode(opcode, sampleEnd, Default::sampleEndRange);
@ -301,7 +299,6 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
break;
case hash("amp_random"):
setValueFromOpcode(opcode, ampRandom, Default::ampRandomRange);
volumeDistribution.param(std::uniform_real_distribution<float>::param_type(0, ampRandom));
break;
case hash("amp_velcurve_&"):
{
@ -643,7 +640,6 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
break;
case hash("pitch_random"):
setValueFromOpcode(opcode, pitchRandom, Default::pitchRandomRange);
pitchDistribution.param(std::uniform_int_distribution<int>::param_type(-pitchRandom, pitchRandom));
break;
case hash("transpose"):
setValueFromOpcode(opcode, transpose, Default::transposeRange);
@ -895,8 +891,9 @@ void sfz::Region::registerTempo(float secondsPerQuarter) noexcept
bpmSwitched = false;
}
float sfz::Region::getBasePitchVariation(int noteNumber, uint8_t velocity) noexcept
float sfz::Region::getBasePitchVariation(int noteNumber, uint8_t velocity) const noexcept
{
std::uniform_int_distribution<int> pitchDistribution { -pitchRandom, pitchRandom };
auto pitchVariationInCents = pitchKeytrack * (noteNumber - (int)pitchKeycenter); // note difference with pitch center
pitchVariationInCents += tune; // sample tuning
pitchVariationInCents += config::centPerSemitone * transpose; // sample transpose
@ -905,20 +902,21 @@ float sfz::Region::getBasePitchVariation(int noteNumber, uint8_t velocity) noexc
return centsFactor(pitchVariationInCents);
}
float sfz::Region::getBaseVolumedB(int noteNumber) noexcept
float sfz::Region::getBaseVolumedB(int noteNumber) const noexcept
{
std::uniform_real_distribution<float> volumeDistribution { -ampRandom, ampRandom };
auto baseVolumedB = volume + volumeDistribution(Random::randomGenerator);
if (trigger == SfzTrigger::release || trigger == SfzTrigger::release_key)
baseVolumedB -= rtDecay * midiState.getNoteDuration(noteNumber);
return baseVolumedB;
}
float sfz::Region::getBaseGain() noexcept
float sfz::Region::getBaseGain() const noexcept
{
return normalizePercents(amplitude);
}
float sfz::Region::getPhase() noexcept
float sfz::Region::getPhase() const noexcept
{
float phase;
if (oscillatorPhase >= 0) {
@ -931,13 +929,15 @@ float sfz::Region::getPhase() noexcept
return phase;
}
uint32_t sfz::Region::getOffset(Oversampling factor) noexcept
uint32_t sfz::Region::getOffset(Oversampling factor) const noexcept
{
std::uniform_int_distribution<uint32_t> offsetDistribution { 0, offsetRandom };
return (offset + offsetDistribution(Random::randomGenerator)) * static_cast<uint32_t>(factor);
}
float sfz::Region::getDelay() noexcept
float sfz::Region::getDelay() const noexcept
{
std::uniform_real_distribution<float> delayDistribution { 0, delayRandom };
return delay + delayDistribution(Random::randomGenerator);
}
@ -988,7 +988,7 @@ float crossfadeOut(const sfz::Range<T>& crossfadeRange, U value, SfzCrossfadeCur
return 1.0f;
}
float sfz::Region::getNoteGain(int noteNumber, uint8_t velocity) noexcept
float sfz::Region::getNoteGain(int noteNumber, uint8_t velocity) const noexcept
{
float baseGain { 1.0f };
@ -1009,7 +1009,7 @@ float sfz::Region::getNoteGain(int noteNumber, uint8_t velocity) noexcept
return baseGain;
}
float sfz::Region::getCrossfadeGain(const sfz::SfzCCArray& ccState) noexcept
float sfz::Region::getCrossfadeGain(const sfz::SfzCCArray& ccState) const noexcept
{
float gain { 1.0f };

View file

@ -135,7 +135,7 @@ struct Region {
* @param velocity
* @return float
*/
float getBasePitchVariation(int noteNumber, uint8_t velocity) noexcept;
float getBasePitchVariation(int noteNumber, uint8_t velocity) const noexcept;
/**
* @brief Get the note-related gain of the region depending on which note has been
* pressed and at which velocity.
@ -144,7 +144,7 @@ struct Region {
* @param velocity
* @return float
*/
float getNoteGain(int noteNumber, uint8_t velocity) noexcept;
float getNoteGain(int noteNumber, uint8_t velocity) const noexcept;
/**
* @brief Get the additional crossfade gain of the region depending on the
* CC values
@ -152,7 +152,7 @@ struct Region {
* @param ccState
* @return float
*/
float getCrossfadeGain(const SfzCCArray& ccState) noexcept;
float getCrossfadeGain(const SfzCCArray& ccState) const noexcept;
/**
* @brief Get the base volume of the region depending on which note has been
* pressed to trigger the region.
@ -160,19 +160,19 @@ struct Region {
* @param noteNumber
* @return float
*/
float getBaseVolumedB(int noteNumber) noexcept;
float getBaseVolumedB(int noteNumber) const noexcept;
/**
* @brief Get the base gain of the region.
*
* @return float
*/
float getBaseGain() noexcept;
float getBaseGain() const noexcept;
/**
* @brief Get the base gain of the region.
*
* @return float
*/
float getPhase() noexcept;
float getPhase() const noexcept;
/**
* @brief Computes the gain value related to the velocity of the note
*
@ -184,13 +184,13 @@ struct Region {
*
* @return uint32_t
*/
uint32_t getOffset(Oversampling factor = Oversampling::x1) noexcept;
uint32_t getOffset(Oversampling factor = Oversampling::x1) const noexcept;
/**
* @brief Get the region delay in seconds
*
* @return float
*/
float getDelay() noexcept;
float getDelay() const noexcept;
/**
* @brief Get the index of the sample end, either natural end or forced
* loop.
@ -333,11 +333,6 @@ private:
absl::string_view defaultPath { "" };
int sequenceCounter { 0 };
std::uniform_real_distribution<float> volumeDistribution { -sfz::Default::ampRandom, sfz::Default::ampRandom };
std::uniform_real_distribution<float> delayDistribution { 0, sfz::Default::delayRandom };
std::uniform_int_distribution<uint32_t> offsetDistribution { 0, sfz::Default::offsetRandom };
std::uniform_int_distribution<int> pitchDistribution { -sfz::Default::pitchRandom, sfz::Default::pitchRandom };
LEAK_DETECTOR(Region);
};