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.6KB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. namespace engine {
  11. struct Module {
  12. /** Automatically generated by the engine. */
  13. int id = 0;
  14. std::vector<Param> params;
  15. std::vector<Output> outputs;
  16. std::vector<Input> inputs;
  17. std::vector<Light> lights;
  18. /** For CPU meter. */
  19. float cpuTime = 0.f;
  20. bool bypass = false;
  21. /** Constructs a Module with no params, inputs, outputs, and lights. */
  22. Module();
  23. /** Use config() instead. */
  24. DEPRECATED Module(int numParams, int numInputs, int numOutputs, int numLights = 0) : Module() {
  25. config(numParams, numInputs, numOutputs, numLights);
  26. }
  27. virtual ~Module() {}
  28. /** Configures the number of Params, Outputs, Inputs, and Lights. */
  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 one audio sample.
  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 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 engine
  49. } // namespace rack