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.

Engine.hpp 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. uint64_t getFrame();
  28. // Modules
  29. /** Adds a module to the rack engine.
  30. The module ID must not be taken by another module.
  31. If the module ID is -1, an ID is automatically assigned.
  32. Does not transfer pointer ownership.
  33. */
  34. void addModule(Module *module);
  35. void removeModule(Module *module);
  36. Module *getModule(int moduleId);
  37. void resetModule(Module *module);
  38. void randomizeModule(Module *module);
  39. void bypassModule(Module *module, bool bypass);
  40. // Cables
  41. /** Adds a cable to the rack engine.
  42. The cable ID must not be taken by another cable.
  43. If the cable ID is -1, an ID is automatically assigned.
  44. Does not transfer pointer ownership.
  45. */
  46. void addCable(Cable *cable);
  47. void removeCable(Cable *cable);
  48. // Params
  49. void setParam(Module *module, int paramId, float value);
  50. float getParam(Module *module, int paramId);
  51. void setSmoothParam(Module *module, int paramId, float value);
  52. float getSmoothParam(Module *module, int paramId);
  53. // ParamHandles
  54. void addParamHandle(ParamHandle *paramHandle);
  55. void removeParamHandle(ParamHandle *paramHandle);
  56. /** Returns the unique ParamHandle for the given paramId */
  57. ParamHandle *getParamHandle(int moduleId, int paramId);
  58. /** Use getParamHandle(int, int) instead. */
  59. DEPRECATED ParamHandle *getParamHandle(Module *module, int paramId);
  60. /** Sets the ParamHandle IDs and module pointer.
  61. If `overwrite` is true and another ParamHandle points to the same param, unsets that one and replaces it with the given handle.
  62. */
  63. void updateParamHandle(ParamHandle *paramHandle, int moduleId, int paramId, bool overwrite = true);
  64. };
  65. } // namespace engine
  66. } // namespace rack