Equation Composer

Documentation and Examples

Creating Modules

In this tutorial we're going to start by creating a module that outputs the value 4. Really simple stuff. Our new module will be called "ModuleJigglyPuff".

Step #1: Create a new file called ModuleJigglyPuff.h

#ifndef ModuleJigglyPuff_h
#define ModuleJigglyPuff_h

// Always include these three files
#include "Arduino.h"
#include "Module.h"
#include "ModuleOutput.h"
 
class ModuleJigglyPuff : public Module
{
  public:
    ModuleJigglyPuff();
    uint16_t compute();
};

#endif

I'm assuming that you're reasonably comfortable writing code in C++ and understand the above class definition. This isn't where you implement the code, but is rather a necessary "heads-up" that tells the C++ compiler which methods will be implemented in ModuleJigglyPuff.cpp.

Step #2: Create a new file called ModuleJigglyPuff.cpp

#include "Arduino.h"
#include "ModuleJigglyPuff.h"
#include "defines.h"

ModuleJigglyPuff::ModuleJigglyPuff()
{
  // no initialization code necessary for this example    
}

uint16_t ModuleJigglyPuff::compute()
{
	return(4);
}

That's it! Our first module is complete. In the next step, we need to tell the framework about it so we can use it in a synth.

Step #3: Update Modules.h

Modules.h is where every module is included. We'll need to add our new module to the list.

		
// Modules.h
...
#include "ModuleEquationLooper.h"
#include "ModuleExtClock.h"
#include "ModuleHighpassFilter.h"
#include "ModuleJigglyPuff.h"   -----  add our new module here
#include "ModuleLFO.h"
#include "ModuleLowpassFilter.h"
#include "ModuleMap.h"
...		

Step #4: Using ModuleJigglyPuff in a synth

And finally, we'd use our new module in a synth like this:

		
SynthExample::SynthExample(Inputs *inputs)
{
  ModuleWavetableOsc *osc = new ModuleWavetableOsc();
  ModuleJigglyPuff *jiggly_puff = new ModuleJigglyPuff();
  osc->wavetable_input = jiggly_puff;
  osc->frequency_input = inputs->sr;

  this->last_module = osc;
}