Color StyleData::calculateColor(const ColorData& mColorData) const { Color color{mColorData.color}; if(mColorData.dynamic) { const auto& dynamicColor(getColorFromHue((currentHue + mColorData.hueShift) / 360.f)); if(!mColorData.main) { if(mColorData.dynamicOffset) { assert(mColorData.offset != 0); color.r += dynamicColor.r / mColorData.offset; color.g += dynamicColor.g / mColorData.offset; color.b += dynamicColor.b / mColorData.offset; color.a += dynamicColor.a; } else color = getColorDarkened(dynamicColor, mColorData.dynamicDarkness); } else color = dynamicColor; } const auto& pulse(mColorData.pulse); return Color(getClamped(color.r + pulse.r * pulseFactor, 0.f, 255.f), getClamped(color.g + pulse.g * pulseFactor, 0.f, 255.f), getClamped(color.b + pulse.b * pulseFactor, 0.f, 255.f), getClamped(color.a + pulse.a * pulseFactor, 0.f, 255.f)); }
/// <summary>Given input value warp-normalized (0.0 to 1.0), convert it back to given range based on midpoint. /// Example: Given decibel gain value where 0.5 equates to 0.0dB, map the value back to raw decibels FS.</summary> /// <param name="inValue"> The input value, normalized between 0.0 and 1.0 (Ex. 0.7)</param> /// <param name="minOfRange"> The minimum possible value of the input range (Ex. -96 decibels) </param> /// <param name="maxOfRange"> The maximum possible value of the input range (Ex. +12 decibels) </param> /// <param name="mappedMidpointOfRange">Value IN RANGE that should be tied to 0.5 NORMALIZED (Ex. 0.0 decibels)</param> /// <returns>Full range value of the input normalized value</returns> float ZenParamUtils::convertMidpointWarpedLinearNormalizedValueToRawRangeValue(float inValue, float minOfRange, float maxOfRange, float mappedMidpointOfRange) { //Account for float truncation errors jassert(inValue >= -0.00001f && inValue <= 1.00001f && mappedMidpointOfRange >= minOfRange && mappedMidpointOfRange <= maxOfRange); inValue = getClamped(inValue, 0.0f, 1.0f); float y, x0, x1, y0, y1; if (inValue <= 0.5) { x0 = 0.0; y0 = minOfRange; x1 = 0.5; y1 = mappedMidpointOfRange; } else if (inValue > 0.5) { x0 = 0.5; y0 = mappedMidpointOfRange; x1 = 1.0; y1 = maxOfRange; } else { jassertfalse; return -9000.0f; } if ((x1 - x0) == 0) return 0; //prevent divide by zero y = ((y1 - y0)*((inValue - x0) / (x1 - x0))) + y0; return y; }
void HexagonGame::updateFlash(FT mFT) { if(status.flashEffect > 0) status.flashEffect -= 3 * mFT; status.flashEffect = getClamped(status.flashEffect, 0.f, 255.f); for(auto i(0u); i < 4; ++i) flashPolygon[i].color.a = status.flashEffect; }
Vector<T, N> getNearestPoint(const LineSegment<T, N>& line, const Vector<T, N>& point) { double divisor = getLengthSquared(line.getVector()); double t = (point - line.getStart()) * line.getVector() / divisor; return line.getPointAtT(getClamped(t, 0.0, 1.0)); }
float ZenParamUtils::denormalizeValueLinear( float& normalized, const float& minValue, const float& maxValue) { jassert(normalized >= -0.00001f && normalized <= 1.00001f); jassert(maxValue > minValue); normalized = getClamped(normalized, 0, 1.0); return minValue + normalized * (maxValue - minValue); }
void ZenDecibelParameter::setValueFromGainNotifyingHost(float inGainValue) { float dbValue = getClamped(Decibels::gainToDecibels(inGainValue), range.start, range.end); float newNormValue = DecibelConversions::mapDecibelsToProperNormalizedValue( dbValue, range.start, range.end, midValue); //DBG("In ZenDecibelParameter::setValueFromGainNotifyingHost(inValue) of " << this->paramID << " with invalue: " << inGainValue << " and calling setValueNotifyingHost with value: " << newNormValue); setValueNotifyingHost(newNormValue); setGainValue(inGainValue); }
//inNormValue expected to be normalized void ZenDecibelParameter::setValueNotifyingHost(float inNormValue) { float clampedValue = getClamped(inNormValue, 0.0f, 1.0f); //clampedValue = DecibelConversions::mapDecibelsToProperNormalizedValue(clampedValue, range.start, range.end, midValue); //DBG("In ZenDecibelParameter::setValueNotifyingHost(inValue) of " << this->paramID << " with invalue: " << inNormValue << " and setParameterNotifyingHost with: " << clampedValue); processor->setParameterNotifyingHost(getParameterIndex(), clampedValue); if (shouldBeSmoothed) setTargetValue(clampedValue); listeners.call(&ZenAudioProcessorValueTreeState::Listener::parameterChanged, paramID, clampedValue); listenersNeedCalling = false; setValueInGainFromNormalised(value.load()); needsUpdate.set(1); }
void ZenDecibelParameter::setValueFromGain(float inGainValue) { float newValue = getClamped(Decibels::gainToDecibels(inGainValue), range.start, range.end); float newNormValue = DecibelConversions::mapDecibelsToProperNormalizedValue( newValue, range.start, range.end, midValue); //DBG("In ZenDecibelParameter::setValueFromGain(inValue) of " << this->paramID << " with inValue: " << inGainValue << " and storing value: " << newNormValue); value.store(newNormValue); if (shouldBeSmoothed) setTargetValue(newNormValue); listeners.call(&ZenAudioProcessorValueTreeState::Listener::parameterChanged, paramID, value.load()); listenersNeedCalling = false; setGainValue(inGainValue); needsUpdate.set(1); UIUpdate.store(true); }
void GTPopulation::selection() { matingPool.clear(); float maxFitness{getMaxFitness()}; //sort(begin(organisms), end(organisms), [](GTOrganism* a, GTOrganism* b){ return a->fitness < b->fitness; }); //matingPool.push_back(organisms[0]); //return; for(const auto& o : organisms) { float fitnessNormal{getMapped<float>(o->fitness, 0.f, getClamped(maxFitness, 0.f, 999.f), 0.f, 1.f)}; int n{static_cast<int>(pow((1 - fitnessNormal), bias) * (150 * (bias * 2)))}; n = max(1, n); for(int i{0}; i < n; ++i) matingPool.push_back(o); } }
void HexagonGame::updateFlash(float mFT) { if(status.flashEffect > 0) status.flashEffect -= 3 * mFT; status.flashEffect = getClamped(status.flashEffect, 0.f, 255.f); for(int i{0}; i < 4; ++i) flashPolygon[i].color.a = status.flashEffect; }