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.

77 lines
2.2KB

  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. // ParamHandles
  53. void addParamHandle(ParamHandle *paramHandle);
  54. void removeParamHandle(ParamHandle *paramHandle);
  55. /** Returns the unique ParamHandle for the given paramId */
  56. ParamHandle *getParamHandle(int moduleId, int paramId);
  57. /** Use getParamHandle(int, int) instead. */
  58. DEPRECATED ParamHandle *getParamHandle(Module *module, int paramId);
  59. /** Sets the ParamHandle IDs and module pointer.
  60. If `overwrite` is true and another ParamHandle points to the same param, unsets that one and replaces it with the given handle.
  61. */
  62. void updateParamHandle(ParamHandle *paramHandle, int moduleId, int paramId, bool overwrite = true);
  63. };
  64. } // namespace engine
  65. } // namespace rack