From e930fcd5610e52697a2c979471bd4a097ff2aa79 Mon Sep 17 00:00:00 2001 From: Brian Heim Date: Sun, 15 Dec 2019 12:21:47 -0600 Subject: [PATCH] SC: protect against failure conditions --- examples/gain.scd | 2 ++ src/SuperColliderEngine.cpp | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/examples/gain.scd b/examples/gain.scd index 0da9f2c..2bf8c91 100644 --- a/examples/gain.scd +++ b/examples/gain.scd @@ -4,4 +4,6 @@ ~i = 0; a = 0; // ~process = {|x| a = max(a, bench { 12.do { 256.do { |i| sin(i)} }; post(x); }); post(a) } +~vcv_bufferSize = 256; +~vcv_frameDivider = 1; ~vcv_process = {post("test")} diff --git a/src/SuperColliderEngine.cpp b/src/SuperColliderEngine.cpp index 801b2f8..6c7dbd1 100644 --- a/src/SuperColliderEngine.cpp +++ b/src/SuperColliderEngine.cpp @@ -37,8 +37,10 @@ public: // These will invoke the interpreter void interpret(const char *) noexcept; void evaluateProcessBlock(ProcessBlock* block) noexcept; - int getFrameDivider() noexcept { return 1; } // getResultAsInt("^~vcv_frameDivider"); } - int getBufferSize() noexcept { return 256; } // getResultAsInt("^~vcv_bufferSize"); } + int getFrameDivider() noexcept { return getResultAsInt("^~vcv_frameDivider"); } + int getBufferSize() noexcept { return getResultAsInt("^~vcv_bufferSize"); } + + bool isOk() const noexcept { return _ok; } void postText(const char* str, size_t len) override; @@ -52,6 +54,7 @@ private: int getResultAsInt(const char* text) noexcept; SuperColliderEngine* _engine; + bool _ok = true; }; class SuperColliderEngine final : public ScriptEngine { @@ -78,6 +81,9 @@ public: if (waitingOnClient()) return 0; + if (clientHasError()) + return 1; + _client->evaluateProcessBlock(getProcessBlock()); return 0; } @@ -85,6 +91,9 @@ public: private: bool waitingOnClient() const noexcept { return !_clientRunning; } + // TODO + bool clientHasError() const noexcept { return !_client->isOk(); } + // TODO handle failure conditions void finishClientLoading() noexcept { _clientRunning = true; } @@ -94,7 +103,7 @@ private: }; // TODO -#define FAIL(_msg_) _engine->display(_msg_) +#define FAIL(_msg_) do { _engine->display(_msg_); _ok = false; } while (0) SC_VcvPrototypeClient::SC_VcvPrototypeClient(SuperColliderEngine* engine) : SC_LanguageClient("SC VCV-Prototype client") @@ -136,7 +145,9 @@ void SC_VcvPrototypeClient::interpret(const char* text) noexcept { } void SC_VcvPrototypeClient::postText(const char* str, size_t len) { - _engine->display(std::string(str, len)); + // Ensure the last message logged (presumably an error) stays onscreen. + if (_ok) + _engine->display(std::string(str, len)); } // TODO test code