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.

59 lines
1.6KB

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