Switching between different layouts

A user interface toolkit mainly for audio plug-ins (VST, AudioUnit, etc).
User avatar
pongasoft
Posts: 67
Joined: Sun Mar 11, 2018 5:57 pm
Location: Las Vegas, USA
Contact:

Switching between different layouts

Postby pongasoft » Tue Jul 17, 2018 3:03 pm

If you look at this code fron the AGain example:

Code: Select all

IPlugView* PLUGIN_API AGainController::createView (const char* name)
{
   // someone wants my editor
   if (name && strcmp (name, "editor") == 0)
   {
      auto* view = new VST3Editor (this, "view", "again.uidesc");
      return view;
   }
   return nullptr;
}


it is not hard to imagine having multiple uidesc for different kinds of layout. For example I could imagine having a "compact" view where the size of the entire window is much smaller than the "normal" one.

The code could then easily do

Code: Select all

IPlugView* PLUGIN_API AGainController::createView (const char* name)
{
   if (name && strcmp (name, "editor") == 0)
   {
      auto xmlFile = getParamNormalized(MyParamIDS::kLayout) == 1 ?
         "again.uidesc" :
         "again_compact.uidesc";
      auto* view = new VST3Editor (this, "view", xmlFile);
      return view;
   }
   return nullptr;
}


The part I am struggling with is how do I add a toggle button in the UI tied to the MyParamIDS::kLayout parameter that would essentially force the UI to close and reopen with the new layout.

Any idea on how to do this?

Thanks
Yan

Arne Scheffler
Posts: 241
Joined: Mon Jun 20, 2016 7:53 am

Re: Switching between different layouts

Postby Arne Scheffler » Mon Jul 23, 2018 10:33 am

Hi,
see VST3Editor::exchangeView (). This is the preferred way to do it. Just create another template in your uidesc file and switch between them with the exchangeView call.

Cheers,
Arne

User avatar
pongasoft
Posts: 67
Joined: Sun Mar 11, 2018 5:57 pm
Location: Las Vegas, USA
Contact:

Re: Switching between different layouts

Postby pongasoft » Tue Dec 04, 2018 6:01 pm

I am having an issue making this work. I defined another template as you described (for testing purposes, I defined an empty template with red background color AND different size).

Although it does switch (meaning I see the new template), the window does not get resized with the new size (I have tried with the editor and the VST3PluginTestHost app).

Any idea how to make it work?

Thanks
Yan

Arne Scheffler
Posts: 241
Joined: Mon Jun 20, 2016 7:53 am

Re: Switching between different layouts

Postby Arne Scheffler » Tue Dec 18, 2018 1:59 pm

Have you setup the min/max size of the templates ?

User avatar
pongasoft
Posts: 67
Joined: Sun Mar 11, 2018 5:57 pm
Location: Las Vegas, USA
Contact:

Re: Switching between different layouts

Postby pongasoft » Tue Dec 18, 2018 2:50 pm

Arne Scheffler wrote:Have you setup the min/max size of the templates ?


How do you specify min/max? This is what I have...

Code: Select all

<template background-color="~ GreyCColor" background-color-draw-style="filled and stroked" class="CViewContainer" mouse-enabled="true" name="sample_edit_view" opacity="1" origin="0, 0" size="600, 500" transparent="false" wants-focus="false">


Thanks
Yan

Arne Scheffler
Posts: 241
Joined: Mon Jun 20, 2016 7:53 am

Re: Switching between different layouts

Postby Arne Scheffler » Tue Dec 18, 2018 3:15 pm

In the UI editor choose Edit->Template Settings...

User avatar
pongasoft
Posts: 67
Joined: Sun Mar 11, 2018 5:57 pm
Location: Las Vegas, USA
Contact:

Re: Switching between different layouts

Postby pongasoft » Tue Dec 18, 2018 5:12 pm

No it does not make any difference whatsoever.

Yan

Arne Scheffler
Posts: 241
Joined: Mon Jun 20, 2016 7:53 am

Re: Switching between different layouts

Postby Arne Scheffler » Tue Dec 18, 2018 5:34 pm

This worked in the past. Please make a breakpoint in vst3editor.cpp line 1558 and step thru it and find the cause. Thanks.

User avatar
pongasoft
Posts: 67
Joined: Sun Mar 11, 2018 5:57 pm
Location: Las Vegas, USA
Contact:

Re: Switching between different layouts

Postby pongasoft » Wed Dec 19, 2018 1:51 pm

Arne Scheffler wrote:This worked in the past. Please make a breakpoint in vst3editor.cpp line 1558 and step thru it and find the cause. Thanks.


If you are telling me that using VST3Editor::exchangeView() with a view that has a different size should resize the window according to the size of the new view, then I can spent some time trying to debug it since it is not working...

I am in a middle of something at this moment and will report back when I am done.

Yan

User avatar
pongasoft
Posts: 67
Joined: Sun Mar 11, 2018 5:57 pm
Location: Las Vegas, USA
Contact:

Re: Switching between different layouts

Postby pongasoft » Sun Dec 30, 2018 4:39 pm

I think I tracked it down to what I think is the problem:

Line 572 from vst3editor.cpp (https://github.com/steinbergmedia/vstgu ... r.cpp#L572)

which is being called from getFrame ()->setSize (width, height); (line 1522 => https://github.com/steinbergmedia/vstgu ... .cpp#L1522)


Code: Select all

bool VST3Editor::requestResize (const CPoint& newSize)
{
   if (!plugFrame)
      return false;
   CCoord width = newSize.x;
   CCoord height = newSize.y;
   double scaleFactor = getAbsScaleFactor ();
   if (editingEnabled || (width >= minSize.x * scaleFactor && width <= maxSize.x * scaleFactor && height >= minSize.y * scaleFactor && height <= maxSize.y * scaleFactor))
   {
      Steinberg::ViewRect vr;
      vr.right = static_cast<Steinberg::int32> (width);
      vr.bottom = static_cast<Steinberg::int32> (height);
      return plugFrame->resizeView (this, &vr) == Steinberg::kResultTrue ? true : false;
   }
   return false;
}


When editingEnabled is false (which I believe is the case when you don't select "Open UIDescription Editor") then the block is ignored (hence plugFrame->resizeView(...) is not called) and because it returns false, the cframe.cpp code is also ignored:

Code: Select all

bool CFrame::setSize (CCoord width, CCoord height)
{
   if ((width == getViewSize ().getWidth ()) && (height == getViewSize ().getHeight ()))
      return false;

   CRect newSize (getViewSize ());
   newSize.setWidth (width);
   newSize.setHeight (height);

   if (getEditor ())
   {
      if (getEditor ()->beforeSizeChange (newSize, getViewSize ()) == false)
         return false;
   }

///// Yan's comment
///// The following code is ignored because    getEditor ()->beforeSizeChange returns false
///// End Yan's comment   

   if (pImpl->platformFrame)
   {
      if (pImpl->platformFrame->setSize (newSize))
      {
         CViewContainer::setViewSize (newSize);
         return true;
      }
      return false;
   }
   CViewContainer::setViewSize (newSize);
   return true;
}


Return to “VSTGUI”

Who is online

Users browsing this forum: No registered users and 1 guest