如何在代码中实例化Vst3插件?对于vst3主机应用程序

问题描述 投票:-1回答:1

我试图从一个简单的主机应用程序创建一个Vst3插件。

这里我有一个简单的代码,只是从* .vst3文件创建一个Vst3插件的实例。

    auto proc = (GetFactoryProc)GetFunction(hmodule, "GetPluginFactory");
    Steinberg::IPluginFactory* rawFactory = proc();

    // Get factory info.
    Steinberg::PFactoryInfo factoryInfo;
    rawFactory->getFactoryInfo(&factoryInfo);

    // Get classes.
    for (size_t i = 0; i < rawFactory->countClasses(); i++)
    {
        Steinberg::PClassInfo info;
        rawFactory->getClassInfo(i, &info);

        // ------------------------------------
        // ----------HOW TO USE THIS IDs-------
        // ------------------------------------
        Steinberg::FIDString cid = info.cid; // Is this correct?
        Steinberg::FIDString iid = Steinberg::Vst::IComponent::iid; // I dont know what I am doing...

        // ------------------------------------
        // HOW TO USE THE createInstance FUNCTION?
        // ------------------------------------
        void* instance(nullptr);
        Steinberg::tresult result = rawFactory->createInstance(cid, iid, &instance);
    }

问题是:这个ID是什么?我猜可以说cid代表class-id。但是iid是什么以及如何才能创建插件类的实例呢?

我从任何类,IPluginFactory,IComponent等中获取的每个iid都得到了未解析的外部符号。

createInstance函数按顺序返回Steinberg :: kNoInterface,因此当我尝试插入空iid时没有找到类。

谁对Steinberg的Vst3一无所知?任何代码示例或文档如何使用Vst3进行插件托管?

谢谢// Alex。

c++ audio plugins signal-processing vst
1个回答
1
投票

About module initialization.

A * .vst3模块可能需要额外的初始化。

如果模块导出某些预定义函数,则应在获取IPluginFactory之前调用它。

导出的函数名称是Windows平台的“InitDll”和“ExitDll”。

    // after the module is loaded.
    auto initDll = (bool(*)())GetFunction(hmodule, "InitDll");
    if(initDll) { initDll(); }

    auto proc = (GetFactoryProc)GetFunction(hmodule, "GetPluginFactory");
    Steinberg::IPluginFactory* rawFactory = proc();
    // before the module is unloaded.
    auto exitDll = (bool(*)())GetFunction(hmodule, "ExitDll");
    if(exitDll) { exitDll(); }

您也可以使用VST3::Hosting::Module中定义的public.sdk/source/vst/hosting/module.h类来实现此目的。

About IDs.

CID是class-id(a.k.a. component-id),用于标识vst3模块文件中的实际插件组件类。

一个* .vst3模块文件可以包含多个插件,但是主机应用程序无法通过其实际的C ++类名来识别插件(因为主机永远不会知道它)。这就是为什么VST3 SDK提供了使用CID识别实际插件组件类的方法。

IID是interface-id,用于指定接口类。在插件加载上下文中,IID表示要获取创建的插件的接口类类型,通常它将是Vst :: IComponent。

VST3 SDK基于VST模块体系结构(VST-MA),它非常类似于Microsoft的组件对象模型(COM)。学习COM将帮助您了解VST-MA。

此外,* .vst3模块文件中的每个插件通常由两个组件组成:Processor组件和EditController组件。

  • Processor组件提供基本的插件API和DSP API。 Processor组件派生两个接口类:Vst :: IComponent类和Vst :: IAudioProcessor类。
  • EditController组件提供参数管理API和UI API。

基本概念VST 3音频效果或乐器基本上由两部分组成:处理部分和编辑控制器部分。相应的接口是:

处理器:Steinberg :: Vst :: IAudioProcessor + Steinberg :: Vst :: IComponent控制器:Steinberg :: Vst :: IEditController VST 3的设计通过实现两个组件建议完全分离处理器和编辑控制器。将效果分解为这两个部分需要一些额外的努力才能实现。但是这种分离使主机能够在不同的上下文中运行每个组件。它甚至可以在不同的计算机上运行它们。另一个好处是,在自动化方面,参数变化可以分开。虽然为了处理这些变化需要以样本精确的方式传输,但GUI部分可以用更低的频率进行更新,并且可以移动由任何延迟补偿或其他处理偏移产生的量。

支持这种分离的插件必须在处理器组件的类信息中设置Steinberg :: Vst :: kDistributable标志(Steinberg :: PClassInfo2 :: classFlags)。当然不是每个插件都可以支持这一点,例如,如果它非常依赖于无法轻易移动到另一台计算机的资源。因此,当未设置此标志时,主机不得尝试以任何方式分离组件。虽然不推荐,但可以在一个组件类中实现处理部分和控制器部分。在创建Steinberg :: Vst :: IAudioProcessor之后,主机尝试查询Steinberg :: Vst :: IEditController接口,并且成功时将其用作控制器。

- VST3 API文档(VST_SDK 3.6.13)

插件由两个组件组成,因此您将调用createInstance()两次。这是从* .vst3模块文件加载插件的步骤:

  1. 从模块文件创建插件的Processor组件,作为Vst :: IComponent类。
  2. 初始化Processor组件。
  3. 获取与Processor组件对应的EditController组件的CID。
  4. 使用CID从模块文件创建EditController组件。
  5. 也初始化EditController组件。
  6. 连接并设置它们。
    // Get classes.
    for (size_t i = 0; i < rawFactory->countClasses(); i++)
    {
        Steinberg::PClassInfo info;
        rawFactory->getClassInfo(i, &info);

        // info.category will be kVstAudioEffectClass for Processor component.
        // skip this component if not.
        if(info.category != kVstAudioEffectClass) {
            continue;
        }

        Vst::IComponent *comp(nullptr);
        Steinberg::tresult result
            = rawFactory->createInstance(info.cid, // tell factory which plugin to be created.
                                         Vst::IComponent::iid, // tell factory which type of interface you want.
                                         (void **)&comp // get the pointer to `comp`, and pass it as (void **)
                                         );
        if(result != kResultTrue) {
            // TODO: error handling
            return;
        }

        // now `comp` shall be valid pointer of Vst::IComponent.

        // initialize comp
        comp->setIoMode(Vst::IoModes::kAdvanced);

        // you should define host context object before and pass it here as `FUnknown *`.
        // the host context object is the class which normally derives Vst::IHostApplication,
        // Vst::IComponentHandler, Vst::IPluginInterfaceSupport, etc.
        comp->initialize(host_context);

        TUID edit_cid;
        comp->getControllerClassId(edit_cid);
        // (in detail, IEditController interface may be obtained from IComponent directly if the plugin
        //  derives SingleComponentEffect.
        //  For such plugins, do not use this method and obtain IEditController with `comp->queryInstance()`
        // )

        Vst::IEditController *edit(nullptr);        
        result = rawFactory->createInstance(edit_cid,
                                            Vst::IEditController::iid,
                                            (void **)&edit);
        if(result != kResultTrue) {
            // TODO: error handling
            return;
        }

        // initialize the EditController component too.
        edit->initialize(host_context);

        //...

        // now the two components are created.
        // connect and setup them.

        // use the plugin.

        // ...

        // don't forget destruction after using it.
        edit->terminate();
        comp->terminate();

        edit->release();
        comp->release();
    }

仅供参考,我开发了一个名为Terra的开源VST3主机应用程序。

https://github.com/hotwatermorning/Terra

它现在仍然是alpha版本。但它可能对你有所帮助。

谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.