String128 -> UTF8String conversion

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

String128 -> UTF8String conversion

Post by pongasoft » Mon Sep 02, 2019 1:11 pm

The VST SDK api deal with char16 (through TChar), for example

Code: Select all

IEditController::getParamStringByValue (ParamID id, ParamValue valueNormalized /*in*/, String128 string /*out*/)
where String128 is a TChar[128] array.

VSTGUI defines the UTF8String and uses it in throughout (like CTextLabel).

Is there a convenient way in the SDK to convert a String128 (which is an array of char16) to a UTF8String (which is essentially a wrapper around std::string which is an array of char, but that are properly utf8 encoded)? If not, what would you recommend?

Thanks
Yan

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

Re: String128 -> UTF8String conversion

Post by pongasoft » Mon Sep 02, 2019 3:00 pm

I think I found an answer in the code: https://github.com/steinbergmedia/vstgu ... r.cpp#L213

Code: Select all

	bool convertValueToString (float value, char utf8String[256])
	{
		if (parameter)
		{
			Steinberg::Vst::String128 utf16Str;
			if (parameter && parameter->getInfo ().stepCount)
			{
				// convert back to normalized value
				value = (float)editController->plainParamToNormalized (getParameterID (), (Steinberg::Vst::ParamValue)value);
			}
			editController->getParamStringByValue (getParameterID (), value, utf16Str);
			Steinberg::String utf8Str (utf16Str);
			utf8Str.toMultiByte (Steinberg::kCP_Utf8);
			utf8Str.copyTo8 (utf8String, 0, 256);
			return true;
		}
		return false;
	}
Is this the correct way?

Thanks for confirming
Yan

Post Reply