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.

61 lines
1.4KB

  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. virtual ~Module() {}
  16. /** Advances the module by 1 audio frame with duration 1.0 / gSampleRate */
  17. virtual void step() {}
  18. /** Override these to store extra internal data in the "data" property */
  19. virtual json_t *toJson() { return NULL; }
  20. virtual void fromJson(json_t *root) {}
  21. virtual void initialize() {}
  22. virtual void randomize() {}
  23. };
  24. struct Wire {
  25. Module *outputModule = NULL;
  26. int outputId;
  27. Module *inputModule = NULL;
  28. int inputId;
  29. /** The voltage connected to input ports */
  30. float inputValue = 0.0;
  31. /** The voltage connected to output ports */
  32. float outputValue = 0.0;
  33. };
  34. void engineInit();
  35. void engineDestroy();
  36. /** Launches engine thread */
  37. void engineStart();
  38. void engineStop();
  39. /** Does not transfer pointer ownership */
  40. void engineAddModule(Module *module);
  41. void engineRemoveModule(Module *module);
  42. /** Does not transfer pointer ownership */
  43. void engineAddWire(Wire *wire);
  44. void engineRemoveWire(Wire *wire);
  45. void engineSetParamSmooth(Module *module, int paramId, float value);
  46. extern float gSampleRate;
  47. } // namespace rack