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.

68 lines
1.8KB

  1. #pragma once
  2. #include <rack.hpp>
  3. static const int NUM_ROWS = 6;
  4. static const int MAX_BUFFER_SIZE = 4096;
  5. struct Prototype;
  6. struct ProcessBlock {
  7. float sampleRate = 0.f;
  8. float sampleTime = 0.f;
  9. int bufferSize = 1;
  10. float inputs[NUM_ROWS][MAX_BUFFER_SIZE] = {};
  11. float outputs[NUM_ROWS][MAX_BUFFER_SIZE] = {};
  12. float knobs[NUM_ROWS] = {};
  13. bool switches[NUM_ROWS] = {};
  14. float lights[NUM_ROWS][3] = {};
  15. float switchLights[NUM_ROWS][3] = {};
  16. };
  17. struct ScriptEngine {
  18. // Virtual methods for subclasses
  19. virtual ~ScriptEngine() {}
  20. virtual std::string getEngineName() {return "";}
  21. /** Executes the script.
  22. Return nonzero if failure, and set error message with setMessage().
  23. Called only once per instance.
  24. */
  25. virtual int run(const std::string& path, const std::string& script) {return 0;}
  26. /** Calls the script's process() method.
  27. Return nonzero if failure, and set error message with setMessage().
  28. */
  29. virtual int process() {return 0;}
  30. // Communication with Prototype module.
  31. // These cannot be called from your constructor, so initialize your engine in the run() method.
  32. void display(const std::string& message);
  33. void setFrameDivider(int frameDivider);
  34. void setBufferSize(int bufferSize);
  35. ProcessBlock* getProcessBlock();
  36. // private
  37. Prototype* module = NULL;
  38. };
  39. struct ScriptEngineFactory {
  40. virtual ScriptEngine* createScriptEngine() = 0;
  41. };
  42. extern std::map<std::string, ScriptEngineFactory*> scriptEngineFactories;
  43. /** Called from functions with
  44. __attribute__((constructor(1000)))
  45. */
  46. template<typename TScriptEngine>
  47. void addScriptEngine(std::string extension) {
  48. struct TScriptEngineFactory : ScriptEngineFactory {
  49. ScriptEngine* createScriptEngine() override {
  50. return new TScriptEngine;
  51. }
  52. };
  53. scriptEngineFactories[extension] = new TScriptEngineFactory;
  54. }