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.

77 lines
2.1KB

  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 = -1;
  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. struct ProcessArgs {
  35. float sampleRate;
  36. float sampleTime;
  37. };
  38. /** Advances the module by one audio sample.
  39. Override this method to read Inputs and Params and to write Outputs and Lights.
  40. */
  41. virtual void process(const ProcessArgs &args) {
  42. #pragma GCC diagnostic push
  43. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  44. step();
  45. #pragma GCC diagnostic pop
  46. }
  47. /** Override process(const ProcessArgs &args) instead. */
  48. DEPRECATED virtual void step() {}
  49. /** Called when the engine sample rate is changed. */
  50. virtual void onSampleRateChange() {}
  51. /** Called when user clicks Initialize in the module context menu. */
  52. virtual void onReset() {}
  53. /** Called when user clicks Randomize in the module context menu. */
  54. virtual void onRandomize() {}
  55. /** Called when the Module is added to the Engine */
  56. virtual void onAdd() {}
  57. /** Called when the Module is removed from the Engine */
  58. virtual void onRemove() {}
  59. /** Override to store extra internal data in the "data" property of the module's JSON object. */
  60. virtual json_t *dataToJson() { return NULL; }
  61. virtual void dataFromJson(json_t *root) {}
  62. };
  63. } // namespace engine
  64. } // namespace rack