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.

57 lines
1.5KB

  1. #pragma once
  2. #include "common.hpp"
  3. #include "string.hpp"
  4. #include "engine/Param.hpp"
  5. #include "engine/Port.hpp"
  6. #include "engine/Light.hpp"
  7. #include <vector>
  8. #include <jansson.h>
  9. namespace rack {
  10. struct Module {
  11. int id = 0;
  12. std::vector<Param> params;
  13. std::vector<Output> outputs;
  14. std::vector<Input> inputs;
  15. std::vector<Light> lights;
  16. /** For power meter */
  17. float cpuTime = 0.f;
  18. bool bypass = false;
  19. /** Constructs a Module with no params, inputs, outputs, and lights */
  20. Module();
  21. /** Deprecated. Use config() instead. */
  22. DEPRECATED Module(int numParams, int numInputs, int numOutputs, int numLights = 0) : Module() {
  23. config(numParams, numInputs, numOutputs, numLights);
  24. }
  25. virtual ~Module() {}
  26. void config(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