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.

66 lines
1.7KB

  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 ScriptEngine {
  7. struct ProcessBlock {
  8. float sampleRate = 0.f;
  9. float sampleTime = 0.f;
  10. int bufferSize = 1;
  11. float inputs[NUM_ROWS][MAX_BUFFER_SIZE] = {};
  12. float outputs[NUM_ROWS][MAX_BUFFER_SIZE] = {};
  13. float knobs[NUM_ROWS] = {};
  14. bool switches[NUM_ROWS] = {};
  15. float lights[NUM_ROWS][3] = {};
  16. float switchLights[NUM_ROWS][3] = {};
  17. };
  18. /** Set by module */
  19. ProcessBlock* block = NULL;
  20. // Virtual methods for subclasses
  21. virtual ~ScriptEngine() {}
  22. virtual std::string getEngineName() {return "";}
  23. /** Executes the script.
  24. Return nonzero if failure, and set error message with setMessage().
  25. Called only once per instance.
  26. */
  27. virtual int run(const std::string& path, const std::string& script) {return 0;}
  28. /** Calls the script's process() method.
  29. Return nonzero if failure, and set error message with setMessage().
  30. */
  31. virtual int process() {return 0;}
  32. // Communication with Prototype module.
  33. // These cannot be called from your constructor, so initialize your engine in the run() method.
  34. void setMessage(const std::string& message);
  35. void setFrameDivider(int frameDivider);
  36. // private
  37. Prototype* module = NULL;
  38. };
  39. // List of ScriptEngines
  40. // Add your createMyEngine() function here.
  41. ScriptEngine* createDuktapeEngine();
  42. ScriptEngine* createQuickJSEngine();
  43. ScriptEngine* createPythonEngine();
  44. inline ScriptEngine* createScriptEngine(std::string ext) {
  45. ext = rack::string::lowercase(ext);
  46. if (ext == "js")
  47. return createQuickJSEngine();
  48. else if (ext == "py")
  49. return createPythonEngine();
  50. // Add your file extension check here.
  51. return NULL;
  52. }