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.

97 lines
2.9KB

  1. #pragma once
  2. #include <vector>
  3. #include <common.hpp>
  4. #include <engine/Module.hpp>
  5. #include <engine/Cable.hpp>
  6. #include <engine/ParamHandle.hpp>
  7. namespace rack {
  8. namespace engine {
  9. struct Engine {
  10. struct Internal;
  11. Internal* internal;
  12. Engine();
  13. ~Engine();
  14. void clear();
  15. /** Advances the engine by `frames` frames.
  16. Only call this method from the primary module.
  17. */
  18. void step(int frames);
  19. void setPrimaryModule(Module* module);
  20. Module* getPrimaryModule();
  21. float getSampleRate();
  22. /** Returns the inverse of the current sample rate.
  23. */
  24. float getSampleTime();
  25. /** Causes worker threads to block on a mutex instead of spinlock.
  26. Call this in your Module::step() method to hint that the operation will take more than ~0.1 ms.
  27. */
  28. void yieldWorkers();
  29. /** Returns the number of audio samples since the Engine's first sample.
  30. */
  31. int64_t getFrame();
  32. /** Returns the frame when step() was last called. */
  33. int64_t getStepFrame();
  34. /** Returns the timestamp in nanoseconds when step() was last called. */
  35. int64_t getStepTime();
  36. /** Returns the total number of frames in the current step() call. */
  37. int getStepFrames();
  38. // Modules
  39. /** Adds a module to the rack engine.
  40. The module ID must not be taken by another module.
  41. If the module ID is -1, an ID is automatically assigned.
  42. Does not transfer pointer ownership.
  43. */
  44. void addModule(Module* module);
  45. void removeModule(Module* module);
  46. Module* getModule(int moduleId);
  47. void resetModule(Module* module);
  48. void randomizeModule(Module* module);
  49. void bypassModule(Module* module, bool bypassed);
  50. // Cables
  51. /** Adds a cable to the rack engine.
  52. The cable ID must not be taken by another cable.
  53. If the cable ID is -1, an ID is automatically assigned.
  54. Does not transfer pointer ownership.
  55. */
  56. void addCable(Cable* cable);
  57. void removeCable(Cable* cable);
  58. Cable* getCable(int cableId);
  59. // Params
  60. void setParam(Module* module, int paramId, float value);
  61. float getParam(Module* module, int paramId);
  62. /** Requests the parameter to smoothly change toward `value`. */
  63. void setSmoothParam(Module* module, int paramId, float value);
  64. /** Returns the target value before smoothing. */
  65. float getSmoothParam(Module* module, int paramId);
  66. // ParamHandles
  67. void addParamHandle(ParamHandle* paramHandle);
  68. void removeParamHandle(ParamHandle* paramHandle);
  69. /** Returns the unique ParamHandle for the given paramId */
  70. ParamHandle* getParamHandle(int moduleId, int paramId);
  71. /** Use getParamHandle(int, int) instead. */
  72. DEPRECATED ParamHandle* getParamHandle(Module* module, int paramId);
  73. /** Sets the ParamHandle IDs and module pointer.
  74. If `overwrite` is true and another ParamHandle points to the same param, unsets that one and replaces it with the given handle.
  75. */
  76. void updateParamHandle(ParamHandle* paramHandle, int moduleId, int paramId, bool overwrite = true);
  77. json_t* toJson();
  78. void fromJson(json_t* rootJ);
  79. };
  80. } // namespace engine
  81. } // namespace rack