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.

56 lines
1.2KB

  1. #pragma once
  2. #include <vector>
  3. #include <jansson.h>
  4. #include "util.hpp"
  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. virtual json_t *toJsonData() { return NULL; }
  19. virtual void fromJsonData(json_t *root) {}
  20. };
  21. struct Wire {
  22. Module *outputModule = NULL;
  23. int outputId;
  24. Module *inputModule = NULL;
  25. int inputId;
  26. /** The voltage connected to input ports */
  27. float inputValue = 0.0;
  28. /** The voltage connected to output ports */
  29. float outputValue = 0.0;
  30. };
  31. void engineInit();
  32. void engineDestroy();
  33. /** Launches engine thread */
  34. void engineStart();
  35. void engineStop();
  36. /** Does not transfer pointer ownership */
  37. void engineAddModule(Module *module);
  38. void engineRemoveModule(Module *module);
  39. /** Does not transfer pointer ownership */
  40. void engineAddWire(Wire *wire);
  41. void engineRemoveWire(Wire *wire);
  42. void engineSetParamSmooth(Module *module, int paramId, float value);
  43. extern float gSampleRate;
  44. } // namespace rack