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 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #include "common.hpp"
  3. #include "string.hpp"
  4. #include "plugin/Model.hpp"
  5. #include "engine/Param.hpp"
  6. #include "engine/Port.hpp"
  7. #include "engine/Light.hpp"
  8. #include <vector>
  9. #include <jansson.h>
  10. namespace rack {
  11. namespace plugin {
  12. struct Model;
  13. }
  14. namespace engine {
  15. struct Module {
  16. plugin::Model *model = NULL;
  17. /** Automatically generated by the engine. */
  18. int id = -1;
  19. std::vector<Param> params;
  20. std::vector<Output> outputs;
  21. std::vector<Input> inputs;
  22. std::vector<Light> lights;
  23. /** For CPU meter. */
  24. float cpuTime = 0.f;
  25. bool bypass = false;
  26. /** Constructs a Module with no params, inputs, outputs, and lights. */
  27. Module();
  28. /** Use config() instead. */
  29. DEPRECATED Module(int numParams, int numInputs, int numOutputs, int numLights = 0) : Module() {
  30. config(numParams, numInputs, numOutputs, numLights);
  31. }
  32. virtual ~Module() {}
  33. /** Configures the number of Params, Outputs, Inputs, and Lights. */
  34. void config(int numParams, int numInputs, int numOutputs, int numLights = 0);
  35. json_t *toJson();
  36. void fromJson(json_t *rootJ);
  37. void reset();
  38. void randomize();
  39. struct ProcessArgs {
  40. float sampleRate;
  41. float sampleTime;
  42. };
  43. /** Advances the module by one audio sample.
  44. Override this method to read Inputs and Params and to write Outputs and Lights.
  45. */
  46. virtual void process(const ProcessArgs &args) {
  47. #pragma GCC diagnostic push
  48. #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
  49. step();
  50. #pragma GCC diagnostic pop
  51. }
  52. /** Override process(const ProcessArgs &args) instead. */
  53. DEPRECATED virtual void step() {}
  54. /** Called when the engine sample rate is changed. */
  55. virtual void onSampleRateChange() {}
  56. /** Called when user clicks Initialize in the module context menu. */
  57. virtual void onReset() {}
  58. /** Called when user clicks Randomize in the module context menu. */
  59. virtual void onRandomize() {}
  60. /** Called when the Module is added to the Engine */
  61. virtual void onAdd() {}
  62. /** Called when the Module is removed from the Engine */
  63. virtual void onRemove() {}
  64. /** Override to store extra internal data in the "data" property of the module's JSON object. */
  65. virtual json_t *dataToJson() { return NULL; }
  66. virtual void dataFromJson(json_t *root) {}
  67. };
  68. } // namespace engine
  69. } // namespace rack