Page 1 of 1

Creating GUI without editor / XML

Posted: Sat Aug 05, 2017 1:44 pm
by .rhavin
My controller just needs 7 controls. I want to create them myself, without XML and editor. Lets say you just have a button:

Code: Select all

class FooController : public EditController
{
	// … //
protected:
	COnOffButton* m_pButton;
}
How would you set up the frame and create it in VSTGUI4 / VST3? All examples are for 2.x…

Re: Creating GUI without editor / XML

Posted: Fri Sep 15, 2017 6:35 pm
by .rhavin
well, *anyone* ?? :|

Re: Creating GUI without editor / XML

Posted: Mon Sep 18, 2017 9:04 am
by ray
Considering the basics, there's not much of a difference between VST2.x and VST3 editor wise imo.

One way would be to let FooController inherit from VSTGUIEditor and IControlListener:

Override open() to create a frame and place your controls. Something along the lines of

Code: Select all

virtual bool PLUGIN_API open(void* parent, const PlatformType& platformType = kDefaultNative)
{
	CRect size(rect.left, rect.top, rect.right, rect.bottom);

	auto old_frame = frame;
	frame = new CFrame(size, this);
	if(old_frame)
		old_frame->forget();

	if(frame && frame->open(parent, platformType))
	{
		// Create your controls here and add them via frame->addView(...)
		...
		return true;
	}
	return false;
}
Make sure to destroy your frame in your overrider of close(). Note that frame->close() will take care of forgetting your previously added controls and also forget() itself, so don't worry about leaking here...

Code: Select all

virtual void PLUGIN_API close()
{
	if(frame)
	{
		auto old_frame = frame;
		frame = 0;
		if(old_frame)
			old_frame->close();
	}
}
Then override valueChanged() to react to mouse/keyboard interaction performed by the user and forward them to your controller. Dispatching is typically handeled using tags (just use the IDs assigned to your parameters) and set the new values via

Code: Select all

controller->setParameterNormalized(control->getTag(), control->getValue());
Additionally, you'll need a machanism to make your GUI controls react to parameter changes imposed by the host (e.g. automation). You can do that by polling or you implement a custom synchronization protocol, e.g. take a look into the VST3Editor implementation to see how it's done - look out for the paramChangeListeners member.

Hope this helps.