It appears you don’t know much about C++ yet. Here’s a more complete outline of how the timer could be declared in your class and used:
#include <rack.hpp>
using namespace ::rack;
struct MyModule : Module
{
// my_timer is a member of the MyModule struct (which can also be referred to as a class).
// Timer is a typedef (alias) for the TTimer<> template class, which defaults to a float accumulator.
// This could also be written as `rack::dsp::TTimer<float> my_timer;` if you wanted to be explicit.
rack::dsp::Timer my_timer;
void process(const ProcesssArgs& args) override; // declares the process override of the Module base class's process virtual function.
};
// Define the process function for MyModule.
// This could also be written in-line with the struct definition.
void MyModule::process(const ProcesssArgs& args)
{
...
if (vIn > Ref) {
my_timer.reset(); // reset the timer to zero
} else {
float dt = my_timer.process(args.SampleTime); // get the elapsed time since the last timer reset.
...
}
}
Efectively i came from arduino and i have a slight knowledge in java, and i have met problem in how to declare and initialize the timer functions because i have understand .process() and other functions but not nderstand how tu invocke the TTimer class correctly now i hope i can do this.
in any case I tried to insist on clarifications also to be able to construct a useful post for posterity.
many thanks.
p.s. MyModule::process(... is a process extern to Void process (...)override; ? so can i write it betwen process and the Widget ?
am ask because i see element who can be used inside process but in your example looks like their was be outside it.
In C++ you can do it both ways. You can define the methods inline in the class/struct declaration, or implement the methods separately from the class declaration, as I showed in this example. A common pattern in C++ is that the class declaration is in a header (.hpp) file, and the implementations of methods are in a separate source (.cpp) file. Most of Rack is structured this way. I recommend cloning other Rack plugins such as Fundamental and Rack itself, or at least reading their code to learn how they’re structured.
Many modules are simple enough that they’re done all together in one file. Many of my modules are complex enough that I have one header file, and split the Module and ModuleWidget method implementations into separate source files, or even more files separated by areas of concern. If my plugin has several modules, each module is put in a separate folder.
However, the beauty of this whole story is that, I tried hard to obtain an exponential curve to imitate an analogue response as much as possible, and as a result I obtained a derivative response… if I had known it before