You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Module.hpp 1.5KB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #include "common.hpp"
  3. #include "string.hpp"
  4. #include "engine/Param.hpp"
  5. #include "engine/Input.hpp"
  6. #include "engine/Output.hpp"
  7. #include "engine/Light.hpp"
  8. #include <vector>
  9. #include <jansson.h>
  10. namespace rack {
  11. struct Module {
  12. int id = 0;
  13. std::vector<Param> params;
  14. std::vector<Input> inputs;
  15. std::vector<Output> outputs;
  16. std::vector<Light> lights;
  17. /** For power meter */
  18. float cpuTime = 0.f;
  19. /** Constructs a Module with no params, inputs, outputs, and lights */
  20. Module();
  21. /** Deprecated. Use setup() instead. */
  22. Module(int numParams, int numInputs, int numOutputs, int numLights = 0) : Module() {
  23. setup(numParams, numInputs, numOutputs, numLights);
  24. }
  25. virtual ~Module() {}
  26. void setup(int numParams, int numInputs, int numOutputs, int numLights = 0);
  27. json_t *toJson();
  28. void fromJson(json_t *rootJ);
  29. void reset();
  30. void randomize();
  31. /** Advances the module by 1 audio frame with duration 1.0 / gSampleRate
  32. Override this method to read inputs and params, and to write outputs and lights.
  33. */
  34. virtual void step() {}
  35. /** Called when the engine sample rate is changed */
  36. virtual void onSampleRateChange() {}
  37. /** Called when user clicks Initialize in the module context menu */
  38. virtual void onReset() {}
  39. /** Called when user clicks Randomize in the module context menu */
  40. virtual void onRandomize() {}
  41. /** Override these to store extra internal data in the "data" property of the module's JSON object */
  42. virtual json_t *dataToJson() { return NULL; }
  43. virtual void dataFromJson(json_t *root) {}
  44. };
  45. } // namespace rack