Skip to content

Commit

Permalink
use size_t for TempoRateTable indices
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiapoirier committed Oct 3, 2022
1 parent 2b88862 commit 928e674
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 32 deletions.
10 changes: 5 additions & 5 deletions bufferoverride/bufferoverrideformalities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ BufferOverride::BufferOverride(TARGET_API_BASE_INSTANCE_TYPE inInstance)
setparametervaluestring(kBufferLFOShape, i, shapeName);
}
// set the value strings for the sync rate parameters
for (long i = 0; i < mTempoRateTable.getNumRates(); i++)
for (size_t i = 0; i < numTempoRates; i++)
{
auto const& tempoRateName = mTempoRateTable.getDisplay(i);
setparametervaluestring(kBufferSize_Sync, i, tempoRateName);
Expand Down Expand Up @@ -339,16 +339,16 @@ void BufferOverride::processparameters()
{
mDivisor = getparameter_f(kDivisor);
mBufferSizeMS = getparameter_f(kBufferSize_MS);
mBufferSizeSync = mTempoRateTable.getScalar(getparameter_i(kBufferSize_Sync));
mBufferSizeSync = mTempoRateTable.getScalar(getparameter_index(kBufferSize_Sync));
mBufferTempoSync = getparameter_b(kBufferTempoSync);
mBufferInterrupt = getparameter_b(kBufferInterrupt);
mDivisorLFORateHz = getparameter_f(kDivisorLFORate_Hz);
mDivisorLFOTempoRate = mTempoRateTable.getScalar(getparameter_i(kDivisorLFORate_Sync));
mDivisorLFOTempoRate = mTempoRateTable.getScalar(getparameter_index(kDivisorLFORate_Sync));
mDivisorLFO.setDepth(getparameter_scalar(kDivisorLFODepth));
mDivisorLFO.setShape(getparameter_i(kDivisorLFOShape));
mDivisorLFOTempoSync = getparameter_b(kDivisorLFOTempoSync);
mBufferLFORateHz = getparameter_f(kBufferLFORate_Hz);
mBufferLFOTempoRate = mTempoRateTable.getScalar(getparameter_i(kBufferLFORate_Sync));
mBufferLFOTempoRate = mTempoRateTable.getScalar(getparameter_index(kBufferLFORate_Sync));
mBufferLFO.setDepth(getparameter_scalar(kBufferLFODepth));
mBufferLFO.setShape(getparameter_i(kBufferLFOShape));
mBufferLFOTempoSync = getparameter_b(kBufferLFOTempoSync);
Expand Down Expand Up @@ -424,7 +424,7 @@ void BufferOverride::updateViewDataCache()

if (getparameter_b(kBufferTempoSync) && (tempoBPS > 0.))
{
viewData.mPreLFO.mForcedBufferSeconds = 1. / (tempoBPS * mTempoRateTable.getScalar(getparameter_i(kBufferSize_Sync)));
viewData.mPreLFO.mForcedBufferSeconds = 1. / (tempoBPS * mTempoRateTable.getScalar(getparameter_index(kBufferSize_Sync)));
}
else
{
Expand Down
7 changes: 7 additions & 0 deletions dfx-library/dfxplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,13 @@ DfxParam::Value DfxPlugin::getparameter(dfx::ParameterID inParameterID) const
return {};
}

size_t DfxPlugin::getparameter_index(dfx::ParameterID inParameterID) const
{
auto const value = getparameter_i(inParameterID);
assert(value >= 0);
return dfx::math::ToIndex(value);
}

//-----------------------------------------------------------------------------
// return a (hopefully) 0 to 1 scalar version of the parameter's current value
double DfxPlugin::getparameter_scalar(dfx::ParameterID inParameterID) const
Expand Down
1 change: 1 addition & 0 deletions dfx-library/dfxplugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ class DfxPlugin : public TARGET_API_BASE_CLASS
{
return parameterisvalid(inParameterID) ? mParameters[inParameterID].get_gen() : 0.0;
}
size_t getparameter_index(dfx::ParameterID inParameterID) const;
// return a (hopefully) 0 to 1 scalar version of the parameter's current value
double getparameter_scalar(dfx::ParameterID inParameterID) const;
std::optional<double> getparameterifchanged_f(dfx::ParameterID inParameterID) const;
Expand Down
8 changes: 4 additions & 4 deletions dfx-library/temporatetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Destroy FX Library. If not, see <http:https://www.gnu.org/licenses/>.
To contact the author, use the contact form at http:https://destroyfx.org/
To contact the author, use the contact form at http:https://destroyfx.org
Destroy FX is a sovereign entity comprised of Sophia Poirier and Tom Murphy 7.
Welcome to our tempo rate table.
Expand Down Expand Up @@ -91,11 +91,11 @@ dfx::TempoRateTable::TempoRateTable(Rates inRates)
//-----------------------------------------------------------------------------
// given a tempo rate value, return the index of the tempo rate
// that is closest to that requested value
long dfx::TempoRateTable::getNearestTempoRateIndex(double inTempoRateValue) const
size_t dfx::TempoRateTable::getNearestTempoRateIndex(double inTempoRateValue) const
{
auto bestDiff = mScalars.back();
long bestIndex = 0;
for (long i = 0; i < getNumRates(); i++)
size_t bestIndex = 0;
for (size_t i = 0; i < getNumRates(); i++)
{
auto const diff = std::fabs(inTempoRateValue - mScalars[i]);
if (diff < bestDiff)
Expand Down
20 changes: 10 additions & 10 deletions dfx-library/temporatetable.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Destroy FX Library. If not, see <http:https://www.gnu.org/licenses/>.
To contact the author, use the contact form at http:https://destroyfx.org/
To contact the author, use the contact form at http:https://destroyfx.org
Destroy FX is a sovereign entity comprised of Sophia Poirier and Tom Murphy 7.
Welcome to our tempo rate table.
Expand Down Expand Up @@ -50,24 +50,24 @@ class TempoRateTable

explicit TempoRateTable(Rates inRates = Rates::Normal);

double getScalar(long inIndex) const
double getScalar(size_t inIndex) const
{
return mScalars[safeIndex(inIndex)];
return mScalars[boundedIndex(inIndex)];
}
std::string const& getDisplay(long inIndex) const
std::string const& getDisplay(size_t inIndex) const
{
return mDisplays[safeIndex(inIndex)];
return mDisplays[boundedIndex(inIndex)];
}
long getNumRates() const noexcept
auto getNumRates() const noexcept
{
return static_cast<long>(mScalars.size());
return mScalars.size();
}
long getNearestTempoRateIndex(double inTempoRateValue) const;
size_t getNearestTempoRateIndex(double inTempoRateValue) const;

private:
size_t safeIndex(long inIndex) const noexcept
size_t boundedIndex(size_t inIndex) const noexcept
{
return static_cast<size_t>(std::clamp(inIndex, 0L, getNumRates() - 1));
return std::min(inIndex, getNumRates() - 1);
}

std::vector<double> mScalars;
Expand Down
4 changes: 2 additions & 2 deletions eqsync/eqsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ EQSync::EQSync(TARGET_API_BASE_INSTANCE_TYPE inInstance)
initparameter_f(kB2, {"b2"}, 0.5, 0.5, 0.0, 1.0, DfxParam::Unit::Generic);

// set the value strings for the sync rate parameters
for (long i = 0; i < numTempoRates; i++)
for (size_t i = 0; i < numTempoRates; i++)
{
setparametervaluestring(kRate_Sync, i, mTempoRateTable.getDisplay(i));
}
Expand Down Expand Up @@ -107,7 +107,7 @@ void EQSync::reset()
//-----------------------------------------------------------------------------
void EQSync::processparameters()
{
mRate = mTempoRateTable.getScalar(getparameter_i(kRate_Sync));
mRate = mTempoRateTable.getScalar(getparameter_index(kRate_Sync));
mSmooth = getparameter_scalar(kSmooth);
mUserTempo = getparameter_f(kTempo);
mUseHostTempo = getparameter_b(kTempoAuto);
Expand Down
2 changes: 1 addition & 1 deletion scrubby/scrubby.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Scrubby final : public DfxPlugin
// the parameters
double mSeekRangeSeconds = 0.0, mSeekDur = 0.0, mSeekDurRandMin = 0.0;
double mSeekRateHz = 0.0, mSeekRateSync = 0.0;
long mSeekRateIndex = 0, mSeekRateRandMinIndex = 0;
size_t mSeekRateIndex = 0, mSeekRateRandMinIndex = 0;
double mUserTempo = 0.0;
long mSpeedMode = kSpeedMode_Robot, mOctaveMin = 0, mOctaveMax = 0;
bool mFreeze = false, mSplitChannels = false, mPitchConstraint = false, mTempoSync = false, mUseHostTempo = false;
Expand Down
6 changes: 3 additions & 3 deletions scrubby/scrubbyformalities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Scrubby::Scrubby(TARGET_API_BASE_INSTANCE_TYPE inInstance)
setparameterenforcevaluelimits(kPredelay, true);

// set the value strings for the sync rate parameters
for (long i = 0; i < numTempoRates; i++)
for (size_t i = 0; i < numTempoRates; i++)
{
auto const& tempoRateName = mTempoRateTable.getDisplay(i);
setparametervaluestring(kSeekRate_Sync, i, tempoRateName);
Expand Down Expand Up @@ -401,10 +401,10 @@ void Scrubby::processparameters()
mSeekRangeSeconds = getparameter_f(kSeekRange) * 0.001;
mFreeze = getparameter_b(kFreeze);
mSeekRateHz = getparameter_f(kSeekRate_Hz);
mSeekRateIndex = getparameter_i(kSeekRate_Sync);
mSeekRateIndex = getparameter_index(kSeekRate_Sync);
mSeekRateSync = mTempoRateTable.getScalar(mSeekRateIndex);
auto const seekRateRandMinHz = getparameter_f(kSeekRateRandMin_Hz);
mSeekRateRandMinIndex = getparameter_i(kSeekRateRandMin_Sync);
mSeekRateRandMinIndex = getparameter_index(kSeekRateRandMin_Sync);
auto const seekRateRandMinSync = mTempoRateTable.getScalar(mSeekRateRandMinIndex);
mTempoSync = getparameter_b(kTempoSync);
mSeekDur = getparameter_scalar(kSeekDur);
Expand Down
2 changes: 1 addition & 1 deletion skidder/skidder.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Skidder final : public DfxPlugin
// the parameters
double mRate_Hz = 1., mRate_Sync = 1.;
float mPulsewidth = 0.f, mPulsewidthRandMin = 0.f;
long mRateIndex = 0, mRateRandMinIndex = 0;
size_t mRateIndex = 0, mRateRandMinIndex = 0;
float mPanWidth = 0.0f, mFloor = 0.0f;
dfx::SmoothedValue<float> mNoise;
double mSlopeSeconds = 0., mUserTempo = 1.;
Expand Down
6 changes: 3 additions & 3 deletions skidder/skidderformalities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Skidder::Skidder(TARGET_API_BASE_INSTANCE_TYPE inInstance)
setparameterenforcevaluelimits(kCrossoverFrequency, true);

// set the value strings for the sync rate parameters
for (long i = 0; i < mTempoRateTable.getNumRates(); i++)
for (size_t i = 0; i < numTempoRates; i++)
{
auto const& tempoRateName = mTempoRateTable.getDisplay(i);
setparametervaluestring(kRate_Sync, i, tempoRateName);
Expand Down Expand Up @@ -152,10 +152,10 @@ void Skidder::reset()
void Skidder::processparameters()
{
mRate_Hz = getparameter_f(kRate_Hz);
mRateIndex = getparameter_i(kRate_Sync);
mRateIndex = getparameter_index(kRate_Sync);
mRate_Sync = mTempoRateTable.getScalar(mRateIndex);
auto const rateRandMin_Hz = getparameter_f(kRateRandMin_Hz);
mRateRandMinIndex = getparameter_i(kRateRandMin_Sync);
mRateRandMinIndex = getparameter_index(kRateRandMin_Sync);
auto const rateRandMin_Sync = mTempoRateTable.getScalar(mRateRandMinIndex);
mTempoSync = getparameter_b(kTempoSync);
mPulsewidth = getparameter_f(kPulsewidth);
Expand Down
6 changes: 3 additions & 3 deletions thrush/thrush.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Thrush::Thrush(TARGET_API_BASE_INSTANCE_TYPE inInstance)
setparametervaluestring(kLFO2Shape2, i, shapeName);
}
// set the value strings for the sync rate parameters
for (long i = 0; i < mTempoRateTable.getNumRates(); i++)
for (size_t i = 0; i < numTempoRates; i++)
{
auto const& tempoRateName = mTempoRateTable.getDisplay(i);
setparametervaluestring(kLFO1Rate_Sync, i, tempoRateName);
Expand Down Expand Up @@ -284,7 +284,7 @@ void Thrush::processparameters()

mDelay2_gen = getparameter_gen(kDelay2);
mLFO1_2.mRateHz = getparameter_f(kLFO1Rate2_Hz);
mLFO1_2.mTempoRateScalar = mTempoRateTable.getScalar(getparameter_i(kLFO1Rate2_Sync));
mLFO1_2.mTempoRateScalar = mTempoRateTable.getScalar(getparameter_index(kLFO1Rate2_Sync));

if (auto const value = getparameterifchanged_b(kLFO1TempoSync2))
{
Expand All @@ -296,7 +296,7 @@ void Thrush::processparameters()
mLFO1_2.setDepth(getparameter_scalar(kLFO1Depth2));
mLFO1_2.setShape(getparameter_i(kLFO1Shape2));
mLFO2_2.mRateHz = getparameter_f(kLFO2Rate2_Hz);
mLFO2_2.mTempoRateScalar = mTempoRateTable.getScalar(getparameter_i(kLFO2Rate2_Sync));
mLFO2_2.mTempoRateScalar = mTempoRateTable.getScalar(getparameter_index(kLFO2Rate2_Sync));

if (auto const value = getparameterifchanged_b(kLFO2TempoSync2))
{
Expand Down

0 comments on commit 928e674

Please sign in to comment.