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.

58 lines
1.6KB

  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. bool bypass = false;
  20. /** Constructs a Module with no params, inputs, outputs, and lights */
  21. Module();
  22. /** Deprecated. Use setup() instead. */
  23. Module(int numParams, int numInputs, int numOutputs, int numLights = 0) : Module() {
  24. setup(numParams, numInputs, numOutputs, numLights);
  25. }
  26. virtual ~Module() {}
  27. void setup(int numParams, int numInputs, int numOutputs, int numLights = 0);
  28. json_t *toJson();
  29. void fromJson(json_t *rootJ);
  30. void reset();
  31. void randomize();
  32. /** Advances the module by 1 audio frame with duration 1.0 / gSampleRate
  33. Override this method to read inputs and params, and to write outputs and lights.
  34. */
  35. virtual void step() {}
  36. /** Called when the engine sample rate is changed */
  37. virtual void onSampleRateChange() {}
  38. /** Called when user clicks Initialize in the module context menu */
  39. virtual void onReset() {}
  40. /** Called when user clicks Randomize in the module context menu */
  41. virtual void onRandomize() {}
  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