Switching between different layouts

If you look at this code fron the AGain example:

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

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

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

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

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

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

<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

In the UI editor choose Edit->Template Settings…

No it does not make any difference whatsoever.

Yan

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

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

Line 572 from vst3editor.cpp (vstgui/vst3editor.cpp at 098cf0345014e35d53f3c8922f9f8d96f0f51354 · steinbergmedia/vstgui · GitHub)

which is being called from getFrame ()->setSize (width, height); (line 1522 => vstgui/vst3editor.cpp at 098cf0345014e35d53f3c8922f9f8d96f0f51354 · steinbergmedia/vstgui · GitHub)


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:

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;
}

As a side note, I tried to simply comment out the test entirely

//	if (editingEnabled || (width >= minSize.x * scaleFactor && width <= maxSize.x * scaleFactor && height >= minSize.y * scaleFactor && height <= maxSize.y * scaleFactor))

to force it to be executed no matter what and it changed the size of the window but did not paint the empty space… and when I switched back to a smaller size window, it did not shrink it…

So I am not entirely sure what is going on, but it is definitely broken…

Yan

1 Like