COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :

Go Back   Cockos Incorporated Forums > Other Software Discussion > WDL users forum

Reply
 
Thread Tools Display Modes
Old 01-17-2010, 10:40 AM   #1
RRokkenAudio
Human being with feelings
 
RRokkenAudio's Avatar
 
Join Date: Jun 2009
Location: Buffalo, NY
Posts: 777
Default Where should my variables be declared?

I'm usually putting my variables here: Does that eat up cpu at all? I have only seen schwa's sample code with iplug, not sure what you guys are doing..

Code:
void SomePlug::ProcessDoubleReplacing(double** inputs, double** outputs, int nFrames)
{
	double* in1 = inputs[0];
	double* in2 = inputs[1];
	double* out1 = outputs[0];
	double* out2 = outputs[1];
	double SR = this->GetSampleRate(); 
	double inputgain = GetParam(finputgain)->DBToAmp();
	double hipass = GetParam(fhipass)->Value();
	double mixcntrl = GetParam(fmix)->Value();
	double outputgain = GetParam(foutputgain)->DBToAmp();
	int listenswitch = GetParam(flisten)->Value();
	int bypassswitch = GetParam(fbypass)->Value();
~Rob.
RRokkenAudio is offline   Reply With Quote
Old 01-17-2010, 02:24 PM   #2
Astralp
Human being with feelings
 
Join Date: Dec 2009
Posts: 73
Default

See my other post on onParamChange, do as much as you can in there.

Also something like setting the samplerate you can do in the constructor ie; where you have set up all your parameters and graphics etc... In the header of your project in the private: section you can define global variables that will be visible in the whole class so:

<yourprojectname>.h

....

private:

double samplerate;

The idea is to have as little as possible in the processing part, so anything that can be calculated outside of it, should be
Astralp is offline   Reply With Quote
Old 01-17-2010, 02:31 PM   #3
RRokkenAudio
Human being with feelings
 
RRokkenAudio's Avatar
 
Join Date: Jun 2009
Location: Buffalo, NY
Posts: 777
Default

Well, i just tried this:

Code:
	//Optional methods
		void Reset() {}
		void OnParamChange(int paramIdx) {
		
		
		
		
		double peakL = 0.0, peakR = 0.0;
		
		
		
		
		}
And it gives the error: undeclared identifier.... ?? It is public, i dont see why its not working... something i'm missing. That is in the .h file
RRokkenAudio is offline   Reply With Quote
Old 01-17-2010, 02:47 PM   #4
Astralp
Human being with feelings
 
Join Date: Dec 2009
Posts: 73
Default

You can't assign the value in the header, you would assign the value in the constructor, in the header it would just be:

double peakL;

Although with the peaks, they are ok in the main process, and probably more efficient too as they change at block or sample rate. The samplerate only needs setting once and so could use the above method.

double hipass = GetParam(fhipass)->Value();

This is an example of how this is being executed on every block, if you defined a private variable in the header:

double hipass;

Then

void onParamChange(int paramIdx)
{
if (paramIdx)
hipass = GetParam(fhipass)->Value();
.....

This would only be set when the fhipass parameter changes so that you can just use hipass variable in your processing function.

Incidentally, the samplerate is perhaps not the best example because the host could change it if the user changes samplerate, I am not 100% sure if the plug is re-initialized when that happens, perhaps adding it to the reset() function will be necesary. But the what i was trying to demonstrate is that any variable that only needs setting once, can be declared in the hearer and then set in the constructor.

hehe It is hard to describe all of this, hope I'm doing ok and not confusing you even more.
Astralp is offline   Reply With Quote
Old 01-17-2010, 04:19 PM   #5
RRokkenAudio
Human being with feelings
 
RRokkenAudio's Avatar
 
Join Date: Jun 2009
Location: Buffalo, NY
Posts: 777
Default

lol, i'll just keep doing it the way i was lol, I tried this way and got the error: error C3861: 'GetParam': identifier not found
RRokkenAudio is offline   Reply With Quote
Old 01-17-2010, 04:22 PM   #6
Astralp
Human being with feelings
 
Join Date: Dec 2009
Posts: 73
Default

In OnParamChange() Use:

IParam* val = GetParam(paramIdx); // get the current value

EDIT:

then:

hipass = val->Value();
Astralp is offline   Reply With Quote
Old 01-17-2010, 04:27 PM   #7
Astralp
Human being with feelings
 
Join Date: Dec 2009
Posts: 73
Default

Just edited the above just in case you didn't see, the Iparam val bit is generic and can be used at the top to get the value of any parameter, then either using switches or if statements you decide what param it is
Astralp is offline   Reply With Quote
Old 01-17-2010, 04:33 PM   #8
RRokkenAudio
Human being with feelings
 
RRokkenAudio's Avatar
 
Join Date: Jun 2009
Location: Buffalo, NY
Posts: 777
Default

i'll try to make some of this, i have no clue what any of that means.

"int paramIdx" ?? no clue

"IParam* val " ?? nope, still no clue

lol.

Using this: void onParamChange(int paramIdx)
{
IParam* val = GetParam(paramIdx); // get the current value
}

I get error : getparam identifier not found.
RRokkenAudio is offline   Reply With Quote
Old 01-17-2010, 04:46 PM   #9
Astralp
Human being with feelings
 
Join Date: Dec 2009
Posts: 73
Default

sorry that top bit was just to lazily show you where to put it, onParamChange should already be defined in your project you don't need to add it, you asked in the other thread what it was for.

So find the existing function:

void VSTproject::OnParamChange(int paramIdx)
{

// then add here:

Code:
IParam* val = GetParam(paramIdx); // get the current value

switch (paramIdx)
{
  case fhipass:
  {
    hipass = val->Value(); 
  } break;
}
Then you can simply add new cases for as many parameters as you need:

Code:
IParam* val = GetParam(paramIdx); // get the current value

switch (paramIdx)
{
  case fhipass: // declared parameter name
  {
    hipass = val->Value(); 
  } break;
  case anotherparam:
  {
    // do something with this one
    double newparam = val->Value();
  } break;
}
hopefully I didn't typo anything, but that should get you going i hope!
Astralp is offline   Reply With Quote
Old 01-17-2010, 05:17 PM   #10
RRokkenAudio
Human being with feelings
 
RRokkenAudio's Avatar
 
Join Date: Jun 2009
Location: Buffalo, NY
Posts: 777
Default

I thought I would see some cpu usage drop by changing to this structure, didn't drop any lol, oh well, at least its more structured.

BTW: when using IParam* inputgain = GetParam(paramIdx); that is almost like a direct replacement for :inputgain = GetParam(finputgain)->DBToAmp(); ??

~Rob.
RRokkenAudio is offline   Reply With Quote
Old 01-17-2010, 05:31 PM   #11
Astralp
Human being with feelings
 
Join Date: Dec 2009
Posts: 73
Default

yes, you would use the created val structure to access it like this:

Code:
IParam* val = GetParam(paramIdx); // get the current value

switch (paramIdx)
{
  case fhipass: // declared parameter name
  {
    hipass = val->Value(); 
  } break;
  case finputgain:
  {
    inputgain = val->DBToAmp(); // should work but untested!
  } break;
}
Astralp is offline   Reply With Quote
Old 01-17-2010, 11:51 PM   #12
RRokkenAudio
Human being with feelings
 
RRokkenAudio's Avatar
 
Join Date: Jun 2009
Location: Buffalo, NY
Posts: 777
Default

Thanks! Got it all squared away!

We need a wiki on this...

~Rob.
RRokkenAudio is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 02:48 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.