Problems with setValue from a Slider


#1

Hey,

So what happens: The visual rendering from Ableton goes laggy if i run a automation.

What my code is doing:

void MyAudioProcessor::setParameter(int index, float newValue)
{
   globalDatabase->SetValueFromProc(index, newValue); // Set the value
   globalDatabase->ToggleValueFromProc(index);   // Set the specific flag which Knob has a new value
   globalDatabase->ToggleNewValueFromProc();   // Global flag that the Editor knows there is a new value on a knob
}

In my Editor the code looks like that:

void MyAudioEditor::timerCallback()
{
   if (globalDatabase->getToggleNewValueFromProc())
   {
      for (int i = 0; i < 8; i++)
      {
         if(globalDatabase->getToggleValueFromProc(i));
         {
            poti[i]->setValue(globalDatabase->GetValueFromProc(i), dontSendNotification);
         }
      }
   }
}

That is my poti class

Knob::Knob()
{
    frameWidth = 0;
    frameHeight = 0;
    isHorizontal = false;
    dragging = false;
}

Knob::~Knob()
{
}

void Knob::SetProcValue(float val)
{
    value = val;
}

float Knob::GetProcValue()
{
    return value;
}

void Knob::SetImage(Image image, int numFrames_, bool isHorizontal_)
{
    filmStripImage = image;
    if (filmStripImage.isValid())
    {
        numFrames = numFrames_;
        isHorizontal = isHorizontal_;

        if (isHorizontal)
        {
            frameHeight = filmStripImage.getHeight();
            frameWidth = filmStripImage.getWidth() / numFrames;
        }
        else
        {
            frameHeight = filmStripImage.getHeight() / numFrames;
            frameWidth = filmStripImage.getWidth();
        }
    }
    else
    {
        numFrames = 0;
    }
    repaint();
}

bool Knob::isDragging()
{
    return dragging;
}

void Knob::startedDragging()
{
    dragging = true;
}
void Knob::stoppedDragging()
{
    dragging = false;
}

void Knob::paint(Graphics& g)
{
    if (filmStripImage.isValid())
    {
        int value = (int)((getValue() - getMinimum()) / (getMaximum() - getMinimum()) * (numFrames - 1));

        int imageHeight;
        int imageWidth;

        if (getTextBoxPosition() == TextBoxBelow)
        {
            imageWidth = getWidth() - getTextBoxHeight();
            imageHeight = getHeight() - getTextBoxHeight();
        }
        else
        {
            imageWidth = getWidth();
            imageHeight = getHeight();
        }

        if (isHorizontal)
        {
            g.drawImage(filmStripImage, (getWidth() - imageWidth) * 0.5, 0, imageWidth, imageHeight,
                value * frameWidth, 0, frameWidth, frameHeight);
        }
        else
        {
            g.drawImage(filmStripImage, 0, 0, imageWidth, imageHeight,
                0, value * frameHeight, frameWidth, frameHeight);
        }
    }
}

and thats the header from the slider
class Knob : public juce::Slider
{
public:
Knob();
~Knob();

    void startedDragging(); 
    void stoppedDragging(); 
    void SetProcValue(float val);
    float GetProcValue();
    void SetImage(Image image, int numFrames, bool isHorizontal = false);
    int SetFrameWidth() const { return frameWidth; }
    int GetFrameWidth() const { return frameHeight; }
    bool isDragging();
    void paint(Graphics&g);
private:
    Image filmStripImage;
    float value;
    int numFrames, frameWidth, frameHeight;
    bool dragging;
    bool isHorizontal;
};

That’s it.
If i delete the setValue line, everything is fine.
It doesn’t help if i turnOff “setImage” from the poti that it has no picture to show.
If i set the value to a fix value everything is fine… something like that : globalDatabase->SetValueFromProc(index, 1);

Ah, the sound engine from Ableton works fine, now “knacks” or something like that.
My CPU Usage is with an Automation 8% higher then normaly.
It’s only the rendering engine which is “laggy”…

Hopefully some of u know where i have to look for…


#2

Is one of these lines calling a repaint? If so, then you get repaint from the audio thread and from the timer i.e. message thread. This happened to me once, so that even the daw’s repaint got laggy.

Just an idea…


#3

No it doesn’t but thanks for the idea.


#4

Quick look at your code and I think it looks ok. What rate is your timer running at? Are you on the latest commit on the develop branch? We’ve recently fixed a bug that sounds similar to the one you are reporting?


#5

Timer is on 20ms, playing a little bit around with it, with 40-50ms it looks good for the first 10 minutes in Ableton live, after that im getting in “lags again”. Is 20ms to hard?

Does someone knows a good tool to check the fps in a program and not in a game? I want to check that I’m not missing something.

No I’m not on a actual commit. I will update soon.

Thanks for you help.


#6

Please try the latest tip on the develop branch. The commits that fixed similar issues are 8b1b855 and 328652c.


#7

That fixed it, thanks