VST C++ Nested Classes - Construction and Inclusion

安稳与你 提交于 2019-12-24 23:35:04

问题


I need some help in Nested classes. This has sprung from a question I asked here

Essentially I have a class 'myPlugin'. This class is the bulk of my program and includes the 'processReplacing' function.

Within processReplacing I need to filter the signal using DSP, currently I am using 11 filters and that has led to 11 filters (and all buffers) being hard coded into processReplacing.

However, now I have decided to create a filter class, so I can create a new instance for each filter, call as necessary and improve my code efficiency.

So far I have had little success. But now I am using nested classes which, if I can get to work, should mean all else should follow suit.

Class definitions in the header are:

class myPlugin : public AudioEffectX

{

public: myPlugin (audioMasterCallback audioMaster); ~myPlugin ();

// Processing
virtual void processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames);
virtual void processDoubleReplacing (double** inputs, double** outputs, VstInt32 sampleFrames);
virtual void midiOutNoteOn (int iKey, int iVel);
virtual void midiOutNoteOff (int iKey, int iVel);

// Program
virtual void setProgramName (char* name);
virtual void getProgramName (char* name);

// Parameters
virtual void setParameter (VstInt32 index, float value);
virtual float getParameter (VstInt32 index);
virtual void getParameterLabel (VstInt32 index, char* label);
virtual void getParameterDisplay (VstInt32 index, char* text);
virtual void getParameterName (VstInt32 index, char* text);
virtual bool getEffectName (char* name);
virtual bool getVendorString (char* text);
virtual bool getProductString (char* text);
virtual VstInt32 getVendorVersion ();
virtual VstInt32 canDo (char* text);

        class aFilterL
    {
    friend class myPlugin;
    public:
        aFilterL ();
        ~aFilterL ();
        float fOut1_l;
        float filterOut1_l;
        float Out_1_l;
        float Out_2_l;
        float* buffer_Out_1_l;
        float* buffer_Out_2_l;

    virtual float aFilterMethodL (float a0, float a1, float a2, float b1, float b2, float inputL, float prevInput1L, float prevInput2L)
    {

        Out_1_l = buffer_Out_1_l[0];
        Out_2_l = buffer_Out_2_l[0];
        filterOut1_l = (a0 * inputL) + (a1 * prevInput1L) + (a2 * prevInput2L) - (b1 * Out_1_l) - (b2 * Out_2_l) + 1.0E-25;
        fOut1_l = filterOut1_l;
        buffer_Out_2_l[0] = buffer_Out_1_l[0];
        buffer_Out_1_l[0] = fOut1_l;  
        return fOut1_l;
    }
    };
    class aFilterR
    {
    friend class myPlugin;
    public:
        aFilterR ();
        ~aFilterR ();

        float fOut1_r;
        float filterOut1_r;
        float Out_1_r;
        float Out_2_r;
        float* buffer_Out_1_r;
        float* buffer_Out_2_r;

    virtual float aFilterMethodR (float a0, float a1, float a2, float b1, float b2, float inputR, float prevInput1R, float prevInput2R)
    {   
        Out_1_r = buffer_Out_1_r[0];
        Out_2_r = buffer_Out_2_r[0];
        filterOut1_r = (a0 * inputR) + (a1 * prevInput1R) + (a2 * prevInput2R) - (b1 * Out_1_r) - (b2 * Out_2_r) + 1.0E-25;
        fOut1_r = filterOut1_r;
        buffer_Out_2_r[0] = buffer_Out_1_r[0];
        buffer_Out_1_r[0] = fOut1_r;
        return fOut1_r;
    }
    };

};#endif

My issue then is that I can't initialize the filter class correctly. The constructor for 'myPlugin' looks like this (Please bear in mind that this is a very simplified version of the actual constructor)

myPlugin::myPlugin (audioMasterCallback audioMaster)

: AudioEffectX (audioMaster, 1, 1) // 1 program, 1 parameter only {

setNumInputs (2);       // stereo in
setNumOutputs (2);      // stereo out
setUniqueID ('Gain');   // identify
canProcessReplacing (); // supports replacing output
canDoubleReplacing ();  // supports double precision processing 

myPlugin *my_aFilter1L = new aFilterL();
myPlugin *my_aFilter1R = new aFilterR();

}

myPlugin::~myPlugin ()

{ }

When I then try and use my_aFilter1L etc in processReplacing it throws the error:"error C2065: 'my_aFilter1L' : undeclared identifier" and "error C2227: left of '->aFilterMethodL' must point to class/struct/union/generic type"

I have tried initializing values stored in the filter classes within the myPlugin constructor. I have tried creating the filter constructor i.e. myPlugin::aFilter1L() OR aFilter1L::aFilter1L() but these have caused more errors.

Not quite sure what I can do. I have worked with classes/functions before, but never nested classes so a bit lost. I've seen lots of threads online and every answer doesn't quite apply; or I have tried the solutions I found and they haven't worked.


回答1:


you have to add them to an instance of your effect, like so (copy to your editor and search for LOOK HERE):

class myPlugin : public AudioEffectX {

public:
    myPlugin (audioMasterCallback audioMaster);
    ~myPlugin ();

// Processing
    virtual void processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames);
    virtual void processDoubleReplacing (double** inputs, double** outputs, VstInt32 sampleFrames);
    virtual void midiOutNoteOn (int iKey, int iVel);
    virtual void midiOutNoteOff (int iKey, int iVel);

// Program
    virtual void setProgramName (char* name);
    virtual void getProgramName (char* name);

// Parameters
    virtual void setParameter (VstInt32 index, float value);
    virtual float getParameter (VstInt32 index);
    virtual void getParameterLabel (VstInt32 index, char* label);
    virtual void getParameterDisplay (VstInt32 index, char* text);
    virtual void getParameterName (VstInt32 index, char* text);
    virtual bool getEffectName (char* name);
    virtual bool getVendorString (char* text);
    virtual bool getProductString (char* text);
    virtual VstInt32 getVendorVersion ();
    virtual VstInt32 canDo (char* text);

    class aFilterL
    {
        friend class myPlugin;
    public:
        aFilterL ();
        ~aFilterL ();
        float fOut1_l;
        float filterOut1_l;
        float Out_1_l;
        float Out_2_l;
        float* buffer_Out_1_l;
        float* buffer_Out_2_l;

        virtual float aFilterMethodL (float a0, float a1, float a2, float b1, float b2, float inputL, float prevInput1L, float prevInput2L)
        {

            Out_1_l = buffer_Out_1_l[0];
            Out_2_l = buffer_Out_2_l[0];
            filterOut1_l = (a0 * inputL) + (a1 * prevInput1L) + (a2 * prevInput2L) - (b1 * Out_1_l) - (b2 * Out_2_l) + 1.0E-25;
            fOut1_l = filterOut1_l;
            buffer_Out_2_l[0] = buffer_Out_1_l[0];
            buffer_Out_1_l[0] = fOut1_l;
            return fOut1_l;
        }
    };

    class aFilterR
    {
        friend class myPlugin;
    public:
        aFilterR ();
        ~aFilterR ();

        float fOut1_r;
        float filterOut1_r;
        float Out_1_r;
        float Out_2_r;
        float* buffer_Out_1_r;
        float* buffer_Out_2_r;

        virtual float aFilterMethodR (float a0, float a1, float a2, float b1, float b2, float inputR, float prevInput1R, float prevInput2R)
        {
            Out_1_r = buffer_Out_1_r[0];
            Out_2_r = buffer_Out_2_r[0];
            filterOut1_r = (a0 * inputR) + (a1 * prevInput1R) + (a2 * prevInput2R) - (b1 * Out_1_r) - (b2 * Out_2_r) + 1.0E-25;
            fOut1_r = filterOut1_r;
            buffer_Out_2_r[0] = buffer_Out_1_r[0];
            buffer_Out_1_r[0] = fOut1_r;
            return fOut1_r;
        }
    };
    /* LOOK HERE */
private:
    aFilterL filterL;
    aFilterR filterR;
};


myPlugin::myPlugin (audioMasterCallback audioMaster) : AudioEffectX (audioMaster, 1, 1), filterL(), /* LOOK HERE */ filterR() /* LOOK HERE */ {

    setNumInputs (2); // stereo in
    setNumOutputs (2); // stereo out
    setUniqueID ('Gain'); // identify
    canProcessReplacing (); // supports replacing output
    canDoubleReplacing (); // supports double precision processing

    /* LOOK HERE */
    //myPlugin *my_aFilter1L = new aFilterL();
    //myPlugin *my_aFilter1R = new aFilterR();
}

the nested class is only a declaration (sort of like a namespace, but you have a few additional options regarding visibility). declaring a class in this scope does not automatically add filters to the effect, you'll still have to declare them exactly as any static or instance variable of the class.



来源:https://stackoverflow.com/questions/4885161/vst-c-nested-classes-construction-and-inclusion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!