Page 1 of 2

Switching between different layouts

Posted: Tue Jul 17, 2018 3:03 pm
by pongasoft
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

Re: Switching between different layouts

Posted: Mon Jul 23, 2018 10:33 am
by Arne Scheffler
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

Re: Switching between different layouts

Posted: Tue Dec 04, 2018 6:01 pm
by pongasoft
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

Re: Switching between different layouts

Posted: Tue Dec 18, 2018 1:59 pm
by Arne Scheffler
Have you setup the min/max size of the templates ?

Re: Switching between different layouts

Posted: Tue Dec 18, 2018 2:50 pm
by pongasoft
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

Re: Switching between different layouts

Posted: Tue Dec 18, 2018 3:15 pm
by Arne Scheffler
In the UI editor choose Edit->Template Settings...

Re: Switching between different layouts

Posted: Tue Dec 18, 2018 5:12 pm
by pongasoft
No it does not make any difference whatsoever.

Yan

Re: Switching between different layouts

Posted: Tue Dec 18, 2018 5:34 pm
by Arne Scheffler
This worked in the past. Please make a breakpoint in vst3editor.cpp line 1558 and step thru it and find the cause. Thanks.

Re: Switching between different layouts

Posted: Wed Dec 19, 2018 1:51 pm
by pongasoft
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

Re: Switching between different layouts

Posted: Sun Dec 30, 2018 4:39 pm
by pongasoft
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;
}