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.

73 lines
2.1KB

  1. #pragma once
  2. #include "common.hpp"
  3. #include "engine/Module.hpp"
  4. #include "engine/Cable.hpp"
  5. #include "engine/ParamHandle.hpp"
  6. #include <vector>
  7. namespace rack {
  8. namespace engine {
  9. struct Engine {
  10. struct Internal;
  11. Internal *internal;
  12. Engine();
  13. ~Engine();
  14. /** Starts engine thread. */
  15. void start();
  16. /** Stops engine thread. */
  17. void stop();
  18. void setPaused(bool paused);
  19. bool isPaused();
  20. float getSampleRate();
  21. /** Returns the inverse of the current sample rate. */
  22. float getSampleTime();
  23. /** Causes worker threads to block on a mutex instead of spinlock.
  24. Call this in your Module::step() method to hint that the operation will take more than ~0.1 ms.
  25. */
  26. void yieldWorkers();
  27. // Modules
  28. /** Adds a module to the rack engine.
  29. The module ID must not be taken by another module.
  30. If the module ID is -1, an ID is automatically assigned.
  31. Does not transfer pointer ownership.
  32. */
  33. void addModule(Module *module);
  34. void removeModule(Module *module);
  35. Module *getModule(int moduleId);
  36. void resetModule(Module *module);
  37. void randomizeModule(Module *module);
  38. void bypassModule(Module *module, bool bypass);
  39. // Cables
  40. /** Adds a cable to the rack engine.
  41. The cable ID must not be taken by another cable.
  42. If the cable ID is -1, an ID is automatically assigned.
  43. Does not transfer pointer ownership.
  44. */
  45. void addCable(Cable *cable);
  46. void removeCable(Cable *cable);
  47. // Params
  48. void setParam(Module *module, int paramId, float value);
  49. float getParam(Module *module, int paramId);
  50. void setSmoothParam(Module *module, int paramId, float value);
  51. float getSmoothParam(Module *module, int paramId);
  52. void addParamHandle(ParamHandle *paramHandle);
  53. void removeParamHandle(ParamHandle *paramHandle);
  54. /** Returns the unique ParamHandle for the given paramId */
  55. ParamHandle *getParamHandle(Module *module, int paramId);
  56. /** Sets the ParamHandle IDs and module pointer.
  57. If the given ParamHandle is added to the engine and another ParamHandle points to the same param, unsets that one and replaces it with the given handle.
  58. */
  59. void updateParamHandle(ParamHandle *paramHandle, int moduleId, int paramId, bool overwrite = true);
  60. };
  61. } // namespace engine
  62. } // namespace rack