「VSTe 操作するパラメータを管理するコードを覚える」の版間の差分

提供:yonewiki
13行目: 13行目:




<syntaxhighlight lang="cpp" line start="1">
<syntaxhighlight lang="cpp" line start="1" highlight="26-30,38-40,45-47,54-56">
#pragma once
#pragma once



2023年5月31日 (水) 23:18時点における版

概要

 音声処理の核心に触れることなく、パラメータだけを追加して管理するコードを覚えます。音声処理はかなり難しいので、後回しでいいと思います。パラメータの追加方法と管理方法というか制御方法を覚えれば、音声処理をしやすくなるので、先に覚えると楽です。


 ここでは、ユーザ定義の2つのクラスが登場します。好きな名前をつけられる部分です。いかにも勝手に名前つけやがったなという意味でCxxという接頭句をつけてみました。


  • CxxProc(AudioEffectクラスから派生)
  • CxxEdit(EditControllerクラスから派生)


ヘッダファイルではこんな風に定義されます。何も処理をしない基礎で既に習得済みの部分も多いですが、全部を記載します。追記した部分を後で示します。


#pragma once

//include headerfiles
#include "pluginterfaces\base\funknown.h"
#include "public.sdk/source/vst/vstaudioeffect.h"
#include "public.sdk/source/vst/vsteditcontroller.h"
#include "public.sdk/source/main/pluginfactory.h"
#include "pluginterfaces/vst/ivstparameterchanges.h"
#include "pluginterfaces/base/ibstream.h"
#include "vstgui/plugin-bindings/vst3editor.h"

namespace Steinberg{
namespace Vst {

#define xxVENDOR   "VENDOR"         
#define xxURL      "https://wiki.yo-net.jp/"
#define xxEMAIL    "mailto:__info@yo-net.jp"
#define xxVSTNAME  "UnknownVST"
#define xxVERSION  "1"
#define xxSUBCATEGORIES Vst::PlugType::kFx

static const FUID ProcessorUID(0x13E7D9FD, 0xE02B4003, 0xA2324A98, 0x45A53825);
//{13E7D9FD-E02B-4003-A232-4A9845A53825}
static const FUID ControllerUID(0xBFA33A3F, 0x06B34AEE, 0x83B53575, 0x0F947340);
//{BFA33A3F-06B3-4AEE-83B5-35750F947340}
enum ParaTag
{
	INT32_OPTION_MENU01 = 1,
	PARAMVALUE_KNOB01,
};

Class CxxProc : AudioEffect
{
public:
	CxxProc();

	tresult PLUGIN_API initialize(FUnknown* context) SMTG_OVERRIDE;
	tresult PLUGIN_API process(ProcessData& data) SMTG_OVERRIDE;
	tresult PLUGIN_API getState(IBStream* state) SMTG_OVERRIDE;
	tresult PLUGIN_API setState(IBStream* state) SMTG_OVERRIDE;
	static FUnknown* createInstance(void*) {
      return (IAudioProcessor*)new CxxProc(); 
    }

protected:
	int32      int32OptionMenu01  = 0;
	ParamValue ParamValue_Knob01 = 0.1;
};
 
Class CxxEdit : EditController
{
public:
	tresult PLUGIN_API initialize(FUnknown* context) SMTG_OVERRIDE;
	tresult PLUGIN_API getState(IBStream* state) SMTG_OVERRIDE;
	tresult PLUGIN_API setState(IBStream* state) SMTG_OVERRIDE;
	tresult PLUGIN_API setComponentState(IBStream* state) SMTG_OVERRIDE;
	IPlugView* PLUGIN_API createView(const char* name) SMTG_OVERRIDE;
	static FUnknown* createInstance(void*) { return (IEditController*)new CxxEdit(); }
};

}}//close namespace


ソースファイルはこんな感じ


#include "vst.h"
BEGIN_FACTORY_DEF(xxVENDOR, xxURL, xxEMAIL)

	DEF_CLASS2(INLINE_UID_FROM_FUID(Steinberg::Vst::ProcessorUID),
	PClassInfo::kManyInstances,
	kVstAudioEffectClass,
	xxVSTNAME,
	Vst::kDistributable,
	xxSUBCATEGORIES,
	xxVERSION,
	kVstVersionString,
	Steinberg::Vst::CxxProc::createInstance)

	DEF_CLASS2(INLINE_UID_FROM_FUID(Steinberg::Vst::ControllerUID),
	PClassInfo::kManyInstances,
	kVstComponentControllerClass,
	xxVSTNAME " Controller",
	0,                          
	"",                         
	xxVERSION,
	kVstVersionString,
	Steinberg::Vst::CxxEdit::createInstance)

END_FACTORY

namespace Steinberg{
namespace Vst {

CxxProc::CxxProc()
{
	setControllerClass(ControllerUID);
}

tresult PLUGIN_API CxxProc::initialize(FUnknown* pFUnknown_Context)
{
	tresult tresult_r = AudioEffect::initialize(pFUnknown_Context);
	if (tresult_r == kResultTrue)
	{
		addAudioInput(STR16("AudioInput"), SpeakerArr::kStereo);
		addAudioOutput(STR16("AudioOutput"), SpeakerArr::kStereo);
	}

	return tresult_r;
}


tresult PLUGIN_API CxxProc::process(ProcessData& refProcessDat_Data)
{
	if (refProcessDat_Data.inputParameterChanges != nullptr)
	{
		int32 int32ParamChangeCount = refProcessDat_Data.inputParameterChanges->getParameterCount();
		for (int32 int32i = 0; int32i < int32ParamChangeCount; int32i++)
		{
			IParamValueQueue* pIParamValueQueue_Q = refProcessDat_Data.inputParameterChanges->getParameterData(i);
			if (pIParamValueQueue_Q != nullptr)
			{
				int32 int32Tag = pIParamValueQueue_Q->getParameterId();

				int32 int32valueChangeCount = pIParamValueQueue_Q->getPointCount();

				ParamValue ParamValue_value;
				int32 int32SampleOffset;
				if (pIParamValueQueue_Q->getPoint(int32valueChangeCount - 1, int32SampleOffset, ParamValue_value) == kResultTrue)
				{
					switch (int32Tag)
					{
					case INT32_OPTION_MENU01:
						int32OptionMenu01 = (int32)(ParamValue_value * 2.0f);//3択は0, 0.5, 1 →x2.0→ 0, 1, 2 、2択は0, 1 →x1.0→ 0, 1 同様に4択ならx3
						break;
					case PARAMVALUE_KNOB01:
						ParamValue_Knob01 = ParamValue_value;
						break;
					}
				}
			}
		}
	}

	if (refProcessDat_Data.numInputs != 1 || refProcessDat_Data.numOutputs != 1)
	{
		return kResultTrue;
	}
	
	if (refProcessDat_Data.inputs[0].numChannels != 2 || refProcessDat_Data.outputs[0].numChannels != 2)
	{
		return kResultTrue;
	}

	Sample32* pSample32_inL = refProcessDat_Data.inputs[0].channelBuffers32[0];
	Sample32* pSample32_inR = refProcessDat_Data.inputs[0].channelBuffers32[1];
	Sample32* pSample32_outL = refProcessDat_Data.outputs[0].channelBuffers32[0];
	Sample32* pSample32_outR = refProcessDat_Data.outputs[0].channelBuffers32[1];

	for (int32 int32i = 0; int32i < refProcessDat_Data.numSamples; int32i++)
	{

		pSample32_outL[int32i] = pSample32_inL[int32i];
		pSample32_outR[int32i] = pSample32_inR[int32i];

	}

	return kResultTrue;
}

tresult PLUGIN_API CxxProc::getState(IBStream* pIBStream_State)
{
	pIBStream_State->write(&int32OptionMenu01, sizeof(int32));
	pIBStream_State->write(&ParamValue_Knob01, sizeof(ParamValue));
	return kResultOk;
}

tresult PLUGIN_API CxxProc::setState(IBStream* pIBStream_State)
{
	tresult tresult_r;
	tresult_r = pIBStream_State->read(&int32OptionMenu01, sizeof(int32));
	if (tresult_r != kResultOk) { return kResultFalse; }

	tresult_r = pIBStream_State->read(&ParamValue_Knob01, sizeof(ParamValue));
	if (tresult_r != kResultOk) { return kResultFalse; }

	return kResultOk;
}

tresult PLUGIN_API CxxEdit::initialize(FUnknown* pFUnknown_Context)
{
	tresult tresult_r = EditController::initialize(pFUnknown_Context);
	if (tresult_r == kResultTrue)
	{
		StringListParameter* param1 = new StringListParameter(STR16("OptionMenu_Para1"), INT32_OPTION_MENU);
		param1->appendString(STR16("TEXT1"));
		param1->appendString(STR16("TEXT2"));
		param1->appendString(STR16("TEXT3"));
		parameters.addParameter(param1);//SteinBerg::Vst::parameters.addParameter()

		RangeParameter* param2 = new RangeParameter(STR16("Knob_Para1"), PARAMVALUE_KNOB, STR16(""), 0.0, 1.0, 0.0);
		parameters.addParameter(param2);//SteinBerg::Vst::parameters.addParameter()
	}

	return tresult_r;
}

tresult PLUGIN_API CxxEdit::getState(IBStream* pIBStream_State)
{
	return kResultOk;
}

tresult PLUGIN_API CxxEdit::setState(IBStream* pIBStream_State)
{
	return kResultOk;
}


tresult PLUGIN_API CxxEdit::setComponentState(IBStream* pIBStream_State)
{
	tresult tresult_r;

	int32 int32TmpOptionMenu01;
	tresult_r = pIBStream_State->read(&int32TmpOptionMenu01, sizeof(int32));
	if (tresult_r != kResultOk) { return kResultFalse; }

	ParamValue ParamValue_TmpKnob01;
	tresult_r = pIBStream_State->read(&ParamValue_TmpKnob01, sizeof(ParamValue));
	if (tresult_r != kResultOk) { return kResultFalse; }


	ParamValue ParamValue_Normalvalue;
	ParamValue_Normalvalue = plainParamToNormalized(INT32_OPTION_MENU, (ParamValue)int32TmpOptionMenu01);
	setParamNormalized(INT32_OPTION_MENU01, ParamValue_Normalvalue);

	ParamValue_Normalvalue = plainParamToNormalized(PARAMVALUE_KNOB, ParamValue_TmpKnob01);
	setParamNormalized(PARAMVALUE_KNOB01, ParamValue_Normalvalue);

	return kResultOk;
}

IPlugView* PLUGIN_API CxxEdit::createView(FIDString FIDString_Name)
{
	if (strcmp(FIDString_Name, ViewType::kEditor) == 0)
	{
		return new VSTGUI::VST3Editor(this, "view", "myEditor.uidesc");
	}
	return nullptr;
}

} } // namespace SteinbergとVstの終わり