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.

70 lines
1.7KB

  1. #pragma once
  2. #include <vector>
  3. #include "util.hpp"
  4. #include <jansson.h>
  5. namespace rack {
  6. struct Module {
  7. std::vector<float> params;
  8. /** Pointers to voltage values at each port
  9. If value is NULL, the input/output is disconnected
  10. */
  11. std::vector<float*> inputs;
  12. std::vector<float*> outputs;
  13. /** For CPU usage */
  14. float cpuTime = 0.0;
  15. /** Deprecated, use constructor below this one */
  16. Module() {}
  17. /** Constructs Module with a fixed number of params, inputs, and outputs */
  18. Module(int numParams, int numInputs, int numOutputs) {
  19. params.resize(numParams);
  20. inputs.resize(numInputs);
  21. outputs.resize(numOutputs);
  22. }
  23. virtual ~Module() {}
  24. /** Advances the module by 1 audio frame with duration 1.0 / gSampleRate */
  25. virtual void step() {}
  26. /** Override these to store extra internal data in the "data" property */
  27. virtual json_t *toJson() { return NULL; }
  28. virtual void fromJson(json_t *root) {}
  29. virtual void initialize() {}
  30. virtual void randomize() {}
  31. };
  32. struct Wire {
  33. Module *outputModule = NULL;
  34. int outputId;
  35. Module *inputModule = NULL;
  36. int inputId;
  37. /** The voltage connected to input ports */
  38. float inputValue = 0.0;
  39. /** The voltage connected to output ports */
  40. float outputValue = 0.0;
  41. };
  42. void engineInit();
  43. void engineDestroy();
  44. /** Launches engine thread */
  45. void engineStart();
  46. void engineStop();
  47. /** Does not transfer pointer ownership */
  48. void engineAddModule(Module *module);
  49. void engineRemoveModule(Module *module);
  50. /** Does not transfer pointer ownership */
  51. void engineAddWire(Wire *wire);
  52. void engineRemoveWire(Wire *wire);
  53. void engineSetParamSmooth(Module *module, int paramId, float value);
  54. extern float gSampleRate;
  55. extern bool gPaused;
  56. } // namespace rack