# Plugin setSize issue in Cubase

**URL:** <https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656>\
**Category:** General JUCE discussion\
**Created:** [April 22, 2021, 2:07pm UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656 "2021-04-22T14:07:59Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [April 22, 2021, 2:07pm UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/1 "2021-04-22T14:07:59Z")

</div>

Hi,

Since moving my plugin to the juce wrapper instead of my own, I have a report of an issue in the VST2 version in Cubase on OSX.  
When changing in the UI the actual plugin size, the user got this.  
This works fine in Reaper and Live.  
In my code I only call setSize with the new size.  
I don’t call setResizable as the only size changes come from my plugin itself. (no resize corner)

Does this ring a bell to someone ? (using juce develop trunk)

Thanks !

 ![CubaseIssue](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/c/c88059705cfb3e4f1cf851151829bce0ff7d9b02.jpeg)

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [April 27, 2021, 10:10am UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/2 "2021-04-27T10:10:47Z")

</div>

The issue can be reproduce with the Juce Gain Plugin example just by adding those lines

```
class GainProcessorEditor: public AudioProcessorEditor, public Button::Listener
{
public:
  GainProcessorEditor(AudioProcessor &processor) : AudioProcessorEditor(processor), mBig("Push"), mLabel("Text", "Text Label") {
    mBig.setClickingTogglesState(true);
    mBig.addListener(this);
    addAndMakeVisible(&mBig);
    addAndMakeVisible(&mLabel);
    mLabel.setColour(Label::textColourId, Colours::white);
    setSize(200, 200);
  }
  
  void buttonClicked (Button * button) override
  {
    if (button->getToggleState())
      setSize(200, 400);
    else
      setSize(200, 200);
  }
  
  void resized() override
  {
    mBig.setBounds(0, 0, 100, 50);
    mLabel.setBounds(0, getHeight() - 50, getWidth(), 50);
  }
  
  TextButton mBig;
  Label mLabel;
};

```

and this

> ```
> AudioProcessorEditor* createEditor() override { return new GainProcessorEditor (*this); }
> 
> ```

![JuceBugCubase](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/6/61071f7aafdf82501b12fe3f2eb4bc543511525f.gif)

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [April 27, 2021, 8:06pm UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/3 "2021-04-27T20:06:30Z")

</div>

Thanks for putting together a code example, that’s really helpful. I’ve put together a patch which should fix this issue, which I’ll push once it has been reviewed and tested a bit more thoroughly.

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [April 28, 2021, 5:19pm UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/4 "2021-04-28T17:19:30Z")

</div>

I’ve just pushed this change, which appears to resolve the issue:

> <https://github.com/juce-framework/JUCE/commit/f73f8ee8497d2ec7f158226ecc0266e30cdb1ea3>

Please try it out and let us know if you encounter any further problems.

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [April 29, 2021, 9:02am UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/5 "2021-04-29T09:02:26Z")

</div>

It fixes the main plugin issue, but it looks like something else has been broken in the meantime.  
The menu is called like that  
`m.showAt(componentToAttachTo, 1, 100, 1, 20);`

 ![Screenshot 2021-04-29 at 10.54.32](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/c/c8e0a22d7bf6e0b137eecb73c3986c6f19d8b42b.jpeg) ![Screenshot 2021-04-29 at 10.53.52](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/9/9617d6771c06914b2d09d080203f5d091ecb4f7b.png)

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [April 29, 2021, 12:01pm UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/6 "2021-04-29T12:01:52Z")

</div>

Thanks for reporting. I can reproduce the issue, and am currently investigating a solution.

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [April 29, 2021, 6:39pm UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/7 "2021-04-29T18:39:37Z")

</div>

This patch should fix the issue:

> <https://github.com/juce-framework/JUCE/commit/e9b26887ddde90b5a62d020504f14cf859c56b9e>
>
> When drawing a popup menu for a target component with a non-unity scale,
> the co…ntents of the component were being drawn with an unwanted vertical
> offset.

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [April 30, 2021, 9:54am UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/8 "2021-04-30T09:54:52Z")

</div>

So far, so good.

Thanks !

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [April 30, 2021, 1:04pm UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/9 "2021-04-30T13:04:27Z")

</div>

Looks like it has broken Protools AAX build

 ![Screenshot 2021-04-30 at 15.01.40](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/7/76804c580e414a5ca352125aeb05b858fdb443b1.jpeg)

The offset is inverted here.

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [April 30, 2021, 1:30pm UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/11 "2021-04-30T13:30:35Z")

</div>

Maybe something related

![Screen Recording 2021-04-30 at 15.11.37](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/2/2bd354e1e019c6d3f88885b159249656e0f64db3.gif)

scale increase the audio processor editor size by the ratio and add a transform scale into the main widget (not the audio processor editor itself)

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [April 30, 2021, 3:00pm UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/12 "2021-04-30T15:00:31Z")

</div>

> [@otristan](#):
>
> Looks like it has broken Protools AAX build

Can you provide some more details, please? It’d be useful to know how this editor is configured. Do you see the same issue in any of the JUCE demo plugins?

> [@otristan](#):
>
> scale increase the audio processor editor size by the ratio and add a transform scale into the main widget (not the audio processor editor itself)

Is the behaviour you’re seeing in that gif definitely new, or was it also present before the NSViewComponentPeer changes (e.g. in commit ec43c7f61c)?

I tried modifying the DSPModulePluginDemo with a similar setup and it seems to work fine, for the most part. Jumping from 10x scaling down to 1x scaling sometimes fails to refresh the view properly, but I’m seeing the same behaviour on `ec43c7f61c`. Other than that, the window size and scale update appropriately.

```auto
diff --git a/examples/Plugins/DSPModulePluginDemo.h b/examples/Plugins/DSPModulePluginDemo.h
index 4dd0f8d870..d931cbf315 100644
--- a/examples/Plugins/DSPModulePluginDemo.h
+++ b/examples/Plugins/DSPModulePluginDemo.h
@@ -1477,12 +1477,11 @@ private:
 };
 
 //==============================================================================
-class DspModulePluginDemoEditor : public AudioProcessorEditor
+class DspModulePluginDemoEditor : public Component
 {
 public:
     explicit DspModulePluginDemoEditor (DspModulePluginDemo& p)
- : AudioProcessorEditor (&p),
- proc (p)
+ : proc (p)
     {
         comboEffect.addSectionHeading ("Main");
         comboEffect.addItem ("Distortion", TabDistortion);
@@ -1529,9 +1528,6 @@ public:
         labelEffect.attachToComponent (&comboEffect, true);
 
         updateVisibility();
-
- setSize (800, 430);
- setResizable (false, false);
     }
 
     //==============================================================================
@@ -2027,11 +2023,46 @@ private:
     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (DspModulePluginDemoEditor)
 };
 
+struct Editor : AudioProcessorEditor
+{
+ explicit Editor (DspModulePluginDemo& proc)
+ : AudioProcessorEditor (proc),
+ widget (proc)
+ {
+ addAndMakeVisible (widget);
+ addAndMakeVisible (textEditor);
+ updateScale();
+ setResizable (false, false);
+
+ textEditor.onReturnKey = [this]
+ {
+ scale = textEditor.getText().getFloatValue();
+ updateScale();
+ };
+ }
+
+ void resized() override
+ {
+ widget.setBounds (getLocalBounds() / scale);
+ textEditor.setSize (80, 24);
+ }
+
+ void updateScale()
+ {
+ widget.setTransform (AffineTransform::scale (scale));
+ setSize (scale * 800, scale * 430);
+ }
+
+ DspModulePluginDemoEditor widget;
+ TextEditor textEditor;
+ float scale = 1.0f;
+};
+
 struct DspModulePluginDemoAudioProcessor : public DspModulePluginDemo
 {
     AudioProcessorEditor* createEditor() override
     {
- return new DspModulePluginDemoEditor (*this);
+ return new Editor (*this);
     }
 
     bool hasEditor() const override { return true; }

```

![trimmed](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/9/93b6292fecfb00c5c54dd166bac7a608bac3b703.gif)

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [April 30, 2021, 3:36pm UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/13 "2021-04-30T15:36:54Z")

</div>

It seems to happen only for 200% scale in my case so maybe something that happen only if Juce window is bigger than the screen size

I don’t have any setResizeLimits in my code  
and don’t call setResizable

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [April 30, 2021, 3:39pm UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/14 "2021-04-30T15:39:40Z")

</div>

I compute the original width and height in my code given the actual width and height with the previous scale.  
Looks like getWidth and getHeight is in that case limited by the screen size, so maybe you cannot have a plugin size bigger than the original one. hence my issue when getting back to smaller scaling

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [April 30, 2021, 3:46pm UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/15 "2021-04-30T15:46:16Z")

</div>

```
void UVIWorkstationUI::SetScaling(float scaling)
{
  float previousScaling = UIResourceManager::LocalScaleFactor;
  UIResourceManager::LocalScaleFactor = scaling;

  mpWrapper->setTransform(juce::AffineTransform::scale(scaling));

  // default size
  float w = getWidth() / previousScaling;
  float h = getHeight() / previousScaling;
  setSize(w * scaling, h * scaling);
}

```

I can fix my code but it should have worked no ?

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [April 30, 2021, 3:48pm UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/16 "2021-04-30T15:48:22Z")

</div>

Is there any way you can test whether this was an issue before the recent NSViewComponentPeer changes? If it was, then I’d be inclined to say that this is a bug in your code. If this is a new regression, then I’ll attempt to fix it in JUCE.

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [April 30, 2021, 3:51pm UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/17 "2021-04-30T15:51:10Z")

</div>

just add

`float previousScale = 1.0f;`

`setSize(800, 430)`

```
previousScale = scale
scale = textEditor.getText().getFloatValue();
updateScale();

```

and

```
void updateScale()
 {
  widget.setTransform (AffineTransform::scale (scale));
  setSize (scale * getWidth() / previousScale, scale * getHeight() / previousScale);
}

```

I can fix my code in UVIWorkstation case but this will means this will break Falcon which has a resizable GUI with scaling on top of that

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [April 30, 2021, 4:17pm UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/18 "2021-04-30T16:17:10Z")

</div>

Alright, I’m seeing the same behaviour before the NSViewComponentPeer changes, so this is not a new regression.

It looks like in the AAX wrapper, resize requests to the host may fail. In this case, the editor is reset to the last known-good size. We don’t have a dedicated way to signal this failure in the JUCE API at the moment, but it’s quite easy to check whether the size actually changed to the expected value after calling `setSize`:

```cpp
    void updateScale (float newScale)
    {
        const auto oldScale = std::exchange (scale, newScale);
        const auto oldBounds = getLocalBounds();
        setSize (scale * getWidth() / oldScale, scale * getHeight() / oldScale);

        // Check if the resize succeeded
        if (getLocalBounds() == oldBounds)
        {
            // The resize failed, revert to the previous scale
            scale = oldScale;
            resized();
        }
        else
        {
            widget.setTransform (AffineTransform::scale (scale));
        }
    }

```

To be clear, the AAX wrapper is refusing to accept the requested size. There’s nothing we can do in JUCE to force the requested editor size. If there’s a chance that you’ll request a very large editor size, you should add some checks in your code to ensure that the new size is what you expect.

---

<div class="post-metadata">

**Author:** ![otristan](https://avatars.discourse-cdn.com/v4/letter/o/f0a364/32.png) [@otristan](https://forum.juce.com/u/otristan)\
**Post date:** [April 30, 2021, 4:53pm UTC](https://forum.juce.com/t/plugin-setsize-issue-in-cubase/45656/19 "2021-04-30T16:53:08Z")

</div>

ok good to know.

Thanks !
