Browse Source

SC: protect against failure conditions

tags/v1.3.0
Brian Heim 5 years ago
parent
commit
e930fcd561
2 changed files with 17 additions and 4 deletions
  1. +2
    -0
      examples/gain.scd
  2. +15
    -4
      src/SuperColliderEngine.cpp

+ 2
- 0
examples/gain.scd View File

@@ -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")}

+ 15
- 4
src/SuperColliderEngine.cpp View File

@@ -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


Loading…
Cancel
Save