//==============================================================================
LoudnessHistory::LoudnessHistory (const Value & loudnessValueToReferTo,
                                  const Value & minLoudnessToReferTo,
                                  const Value & maxLoudnessToReferTo)
  : currentLevelValue (var(0.0f)),
//    timeRange (240),
    specifiedTimeRange (20), // seconds
    lineThickness (2.0f),
//    desiredNumberOfPixelsBetweenTwoPoints (3.0f),
    desiredNumberOfPixelsBetweenTwoPoints (6.0f),
    textBoxWidth (40),
    distanceBetweenLeftBorderAndText (3),
    mostRecentYPosition (circularBufferForYPositions.begin()),
    distanceBetweenGraphAndBottom (32)
{
    currentLevelValue.referTo (loudnessValueToReferTo);
    minLoudness.referTo (minLoudnessToReferTo);
    minLoudness.addListener(this);
    maxLoudness.referTo (maxLoudnessToReferTo);
    maxLoudness.addListener(this);

    DEB("minLoudness = " + minLoudness.getValue().toString())
    DEB("maxLoudness = " + maxLoudness.getValue().toString())
    
    determineStretchAndOffset();
    
    // Memory allocation for the circularLevelBuffer as well as starting
    // the timer will be done by this.
    resized();
}
示例#2
0
//==============================================================================
LoudnessBar::LoudnessBar (const Value & levelValueToReferTo,
                          const Value & minValueToReferTo,
                          const Value & maxValueToReferTo)
  : currentLevel (minValueToReferTo.getValue()),
    previousLevel (minValueToReferTo.getValue())
{
    levelValue.referTo(levelValueToReferTo);
    levelValue.addListener(this);
    
    minLoudness.referTo(minValueToReferTo);
    minLoudness.addListener(this);
    maxLoudness.referTo(maxValueToReferTo);
    maxLoudness.addListener(this);

    determineStretchAndOffset();
}
void LoudnessHistory::valueChanged (Value & value)
{
    const float oldStretch = stretch;
    const float oldOffset = offset;
    
    // minLoudness or maxLoudness has changed.
    // Therefore:
    determineStretchAndOffset();
    
    // And rescale
    for (std::vector<float>::iterator yPos = circularBufferForYPositions.begin();
         yPos != circularBufferForYPositions.end(); ++yPos)
    {
        // Derivation on 120817_loudness_history_min_max_value_changes.tif
        *yPos = (1.0 - (stretch/oldStretch * (1.0 - *yPos/getHeight() - oldOffset) + offset)) * getHeight();
    }
}
示例#4
0
void LoudnessBar::valueChanged (Value & value)
{
    if (value == levelValue)
    {
        
        currentLevel = value.getValue();
        
        // Ensure that the currentLevel is in the interval
        // [minimumLevel, maximumLevel].
        currentLevel = jmax(currentLevel, float(minLoudness.getValue()));
        currentLevel = jmin(currentLevel, float(maxLoudness.getValue()));
        
        if (currentLevel != previousLevel)
        {
            //        float topBorderInPercent = stretch*jmax(currentLevel,previousLevel) + offset;
            //        float bottomBorderInPercent = stretch*jmin(currentLevel,previousLevel) + offset;
            //        
            //        const int topLeftX = 0;
            //        const int topLeftY = floor((1-topBorderInPercent) * (float) getHeight()) -3;
            //        const int heightOfSectionToDraw = ceil((topBorderInPercent-bottomBorderInPercent) * (float) getHeight()) + 3;
            //        
            previousLevel = currentLevel;
            //    
            //        repaint(topLeftX, topLeftY, getWidth(), heightOfSectionToDraw);
            
            // Mesurements showed that it is more CPU efficient to draw the whole
            // bar and not only the section that has changed.
            repaint();
        }
    }
    else if (value == minLoudness || value == maxLoudness)
    {
        determineStretchAndOffset();
        repaint();
    }
}