What to include in separate cpp/hpp file to be able to use "args.sampleRate"?

Hey :slight_smile:

Been working on moving some functions, to a separate cpp file and got a basic test working. So I know I got the basic setup right and how to implement the function for separate cpp file.

Then I wanted to implement the actual function I’d like to use, but when I use args.sampleRate in my functions.cpp file, it says " args. error undeclared identifier".

What do I need to include in either my functions.cpp or functions.hpp files, to make it work?

Thanks in advance!

args is an argument of the Module::process() method which you override in your Module subclass. The Rack plugin API likely already included in your source code as rack.hpp.

Thanks for responding :slight_smile:

Hmmm, okay. Strange its not working. Yes I have set up the development environment and been using it for a week or so, with no issues. And the code works when I use it directly in my modules.

In plugin.hpp I have this at the top: Screenshot 2024-02-12 at 23.09.42

In plugin.cpp: Screenshot 2024-02-12 at 23.20.57

In function.hpp, I declare the function, nothing else in there; Screenshot 2024-02-12 at 23.10.34

In functions.cpp I have code: Screenshot 2024-02-12 at 23.12.07

The error I get: error: use of undeclared identifier ‘args’

I did try to add #include <rack.hpp>, along with using namespace rack to both functions.cpp and functions.hpp, with no luck.

Not really sure whats wrong I tried a few things now and I am stuck.

Any help appreciated :wink:

args is an argument to the process() function. I do not think you are in your process() function in your code.l

Just a general suggestion, when I was first learning how to develop plugins and modules, I found it invaluable to download a number of open source plugins’ code from GitHub in order to see what functioning code looks like.

1 Like

I have made some modules a few years ago, just quit it for a while. I am not a programmer, but I have made a bunch of modules before :wink:

I do also have a bunch of modules to look at, but none of the ones I have has functions in separate cpp files. If you can recommend some, Ill gladly look at them. I did make a basic function that works, as I mentioned.

No I am in a separate cpp file. So that makes sense. Is there any way to use the args.sampleRate, or to get the sample rate outside of the process block?

I did also try to add the #include <samplerate.h> to the functions.cpp and functions.hpp files. That didn’t work either.

Anyway, it’s not something that can’t be done without the samplerate, but I just like to be able to use it for timing related stuff, like for a button, that I would like to turn on and off for 0,5 seconds. It just seemed rational to use the samplerate for that, so it’s consistent, no matter what samplerate you use.

float sr=APP->engine->getSampleRate();

1 Like

Thanks :slight_smile:

At least it builds now. I had to add #include <rack.hpp> to the functions.cpp file, though, then it worked.

But the function doesnt behave as it does when just made in process block. It uses a counter, which I don’t think works correctly after it has been moved out of process block…

Anyway, one more hurdle over come. Think I am going to leave it for a bit and just do it in the process block and then go on with other stuff and get back to it in a few days.

I appreciate the input!

I’d recommend propagating the sampleRate or sampleTime from your Module::process() method to your DSP classes and functions, instead of calling a Rack function from your DSP code. This makes your DSP code isolated from Rack functions and allows the compiler to better inline your code.


Thanks Andrew :slight_smile:

But how would I go about doing that?

The way I do this is to pass the args pointer to my DSP function as the first argument in the DSP function.

1 Like

Thats a good idea :wink:

Thank you for the suggestion, I will try that!