Skip to content

Commit

Permalink
Merge pull request #49 from olilarkin/mDefaultTextsForFloatParams
Browse files Browse the repository at this point in the history
Approve
  • Loading branch information
b-vesco committed May 13, 2011
2 parents a71bfd1 + 9dfaf73 commit 91f81b6
Showing 3 changed files with 20 additions and 8 deletions.
12 changes: 12 additions & 0 deletions WDL/IPlug/Containers.h
Original file line number Diff line number Diff line change
@@ -34,6 +34,18 @@
#define AMP_DB 8.685889638065036553
#define IAMP_DB 0.11512925464970

#define IPLUG_EPSILON 0.000001

inline bool doubleIsZero(double value)
{
return (-IPLUG_EPSILON < value) && (value < IPLUG_EPSILON);
}

inline bool doubleIsEqual(double a, double b)
{
return doubleIsZero(a - b);
}

inline double DBToAmp(double dB)
{
return exp(IAMP_DB * dB);
10 changes: 5 additions & 5 deletions WDL/IPlug/IParam.cpp
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ void IParam::SetShape(double shape)
}
}

void IParam::SetDisplayText(int value, const char* text)
void IParam::SetDisplayText(double value, const char* text)
{
int n = mDisplayTexts.GetSize();
mDisplayTexts.Resize(n + 1);
@@ -109,7 +109,7 @@ void IParam::GetDisplayForHost(double value, bool normalized, char* rDisplay)
value = FromNormalizedParam(value, mMin, mMax, mShape);
}

const char* displayText = GetDisplayText((int) value);
const char* displayText = GetDisplayText(value);
if (CSTR_NOT_EMPTY(displayText)) {
strcpy(rDisplay, displayText);
return;
@@ -139,7 +139,7 @@ const char* IParam::GetNameForHost()

const char* IParam::GetLabelForHost()
{
const char* displayText = GetDisplayText((int) mValue);
const char* displayText = GetDisplayText( mValue);
return (CSTR_NOT_EMPTY(displayText)) ? "" : mLabel;
}

@@ -148,13 +148,13 @@ int IParam::GetNDisplayTexts()
return mDisplayTexts.GetSize();
}

const char* IParam::GetDisplayText(int value)
const char* IParam::GetDisplayText(double value)
{
int n = mDisplayTexts.GetSize();
if (n) {
DisplayText* pDT = mDisplayTexts.Get();
for (int i = 0; i < n; ++i, ++pDT) {
if (value == pDT->mValue) {
if (doubleIsEqual(value, pDT->mValue)){
return pDT->mText;
}
}
6 changes: 3 additions & 3 deletions WDL/IPlug/IParam.h
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ class IParam
void InitDouble(const char* name, double defaultVal, double minVal, double maxVal, double step, const char* label = "");

void Set(double value) { mValue = BOUNDED(value, mMin, mMax); }
void SetDisplayText(int value, const char* text);
void SetDisplayText(double value, const char* text);

// The higher the shape, the more resolution around host value zero.
void SetShape(double shape);
@@ -58,7 +58,7 @@ class IParam
const char* GetLabelForHost();

int GetNDisplayTexts();
const char* GetDisplayText(int value);
const char* GetDisplayText(double value);
bool MapDisplayText(char* str, int* pValue); // Reverse map back to value.
void GetBounds(double* pMin, double* pMax);

@@ -73,7 +73,7 @@ class IParam
bool mNegateDisplay;

struct DisplayText {
int mValue;
double mValue;
char mText[MAX_PARAM_NAME_LEN];
};
WDL_TypedBuf<DisplayText> mDisplayTexts;

0 comments on commit 91f81b6

Please sign in to comment.