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.

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