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.

65 lines
1.6KB

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