Note that there are some explanatory texts on larger screens.

plurals
  1. POVST C++ Nested Classes - Construction and Inclusion
    text
    copied!<p>I need some help in Nested classes. This has sprung from a question I asked <a href="https://stackoverflow.com/questions/4876253/storing-values-in-buffer-within-class-function-method">here</a></p> <p>Essentially I have a class 'myPlugin'. This class is the bulk of my program and includes the 'processReplacing' function.</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>Class definitions in the header are:</p> <pre><code>class myPlugin : public AudioEffectX </code></pre> <p>{</p> <p>public: myPlugin (audioMasterCallback audioMaster); ~myPlugin ();</p> <pre><code>// 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; } }; </code></pre> <p>};#endif</p> <p><strong>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)</strong></p> <pre><code>myPlugin::myPlugin (audioMasterCallback audioMaster) </code></pre> <p>: AudioEffectX (audioMaster, 1, 1) // 1 program, 1 parameter only {</p> <pre><code>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(); </code></pre> <p>}</p> <p>myPlugin::~myPlugin ()</p> <p>{ }</p> <p>When I then try and use my_aFilter1L etc in processReplacing it throws the error:"error C2065: 'my_aFilter1L' : undeclared identifier" <strong>and</strong> "error C2227: left of '->aFilterMethodL' must point to class/struct/union/generic type" </p> <p>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() <strong>OR</strong> aFilter1L::aFilter1L() but these have caused more errors.</p> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload