From 81eb47815ef615585443de296ca2a3f23da09df1 Mon Sep 17 00:00:00 2001 From: Leonardo Laguna Ruiz Date: Sun, 12 Apr 2020 12:44:04 +0300 Subject: [PATCH 01/27] Improves the LuaJIT performance by using luaL_openlibs to initialize the VM --- src/LuaJITEngine.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/LuaJITEngine.cpp b/src/LuaJITEngine.cpp index ee39157..5e87383 100644 --- a/src/LuaJITEngine.cpp +++ b/src/LuaJITEngine.cpp @@ -28,17 +28,16 @@ struct LuaJITEngine : ScriptEngine { return -1; } - // Import a subset of the standard library - luaopen_base(L); - luaopen_string(L); - luaopen_table(L); - luaopen_math(L); - luaopen_bit(L); - // Loads the JIT package otherwise it will be off - luaopen_jit(L); - // Disables access to the JIT package - lua_pushnil(L); - lua_setglobal(L,"jit"); + // Import the common Lua libraries + luaL_openlibs(L); + // Unloads the unsafe libraries + lua_pushinteger(L, 0); + lua_setglobal(L, "os"); + lua_pushinteger(L, 0); + lua_setglobal(L, "io"); + // Unloads 'require' so 'io' and 'os' cannot be reloaded + lua_pushinteger(L, 0); + lua_setglobal(L, "require"); // Set user pointer lua_pushlightuserdata(L, this); From c68b38aa6402aee02e9c4e2471d74b13f51d3502 Mon Sep 17 00:00:00 2001 From: Leonardo Laguna Ruiz Date: Sun, 12 Apr 2020 14:42:15 +0300 Subject: [PATCH 02/27] Revert "Improves the LuaJIT performance by using luaL_openlibs to initialize the VM" This reverts commit 1e8f89a8fa9fa965f398cccf3af4988aa91a9395. --- src/LuaJITEngine.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/LuaJITEngine.cpp b/src/LuaJITEngine.cpp index 5e87383..1d8d523 100644 --- a/src/LuaJITEngine.cpp +++ b/src/LuaJITEngine.cpp @@ -28,16 +28,12 @@ struct LuaJITEngine : ScriptEngine { return -1; } - // Import the common Lua libraries - luaL_openlibs(L); - // Unloads the unsafe libraries - lua_pushinteger(L, 0); - lua_setglobal(L, "os"); - lua_pushinteger(L, 0); - lua_setglobal(L, "io"); - // Unloads 'require' so 'io' and 'os' cannot be reloaded - lua_pushinteger(L, 0); - lua_setglobal(L, "require"); + // Import a subset of the standard library + luaopen_base(L); + luaopen_string(L); + luaopen_table(L); + luaopen_math(L); + luaopen_bit(L); // Set user pointer lua_pushlightuserdata(L, this); From 95348ffaee8cbcc600bd7719712c41f2ff6833da Mon Sep 17 00:00:00 2001 From: Leonardo Laguna Ruiz Date: Sun, 12 Apr 2020 14:59:10 +0300 Subject: [PATCH 03/27] Loads the JIT library that way the JIT engine is enabled --- src/LuaJITEngine.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/LuaJITEngine.cpp b/src/LuaJITEngine.cpp index 1d8d523..099a062 100644 --- a/src/LuaJITEngine.cpp +++ b/src/LuaJITEngine.cpp @@ -34,6 +34,11 @@ struct LuaJITEngine : ScriptEngine { luaopen_table(L); luaopen_math(L); luaopen_bit(L); + // Loads the JIT package otherwise it will be off + luaopen_jit(L); + // Diables access to the JIT package + lua_pushnil(L); + lua_setglobal(L,"jit"); // Set user pointer lua_pushlightuserdata(L, this); From 4004bc4e96fce7bfd5933f95ee7d5398ace85885 Mon Sep 17 00:00:00 2001 From: Leonardo Laguna Ruiz Date: Sun, 12 Apr 2020 15:05:19 +0300 Subject: [PATCH 04/27] Fixes typo in comment --- src/LuaJITEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LuaJITEngine.cpp b/src/LuaJITEngine.cpp index 099a062..ee39157 100644 --- a/src/LuaJITEngine.cpp +++ b/src/LuaJITEngine.cpp @@ -36,7 +36,7 @@ struct LuaJITEngine : ScriptEngine { luaopen_bit(L); // Loads the JIT package otherwise it will be off luaopen_jit(L); - // Diables access to the JIT package + // Disables access to the JIT package lua_pushnil(L); lua_setglobal(L,"jit"); From 9dcb0f4445cc82c04e04085cad913c5e8652adc5 Mon Sep 17 00:00:00 2001 From: Leonardo Laguna Ruiz Date: Mon, 13 Apr 2020 07:56:17 +0300 Subject: [PATCH 05/27] Example on how to use the FFI in LuaJIT to increase the performance --- examples/gain.lua | 10 +- examples/rainbow.lua | 6 +- examples/vco.lua | 8 +- src/LuaJITEngine.cpp | 246 ++++++++++++------------------------------- 4 files changed, 78 insertions(+), 192 deletions(-) diff --git a/examples/gain.lua b/examples/gain.lua index 45e8d95..01aae12 100644 --- a/examples/gain.lua +++ b/examples/gain.lua @@ -6,23 +6,23 @@ config.bufferSize = 32 function process(block) -- Loop through each column - for i=1,6 do + for i=0,5 do -- Get gain knob gain = block.knobs[i] -- Set gain light (red = 1) - block.lights[i][1] = gain + block.lights[i][0] = gain -- Check mute switch if block.switches[i] then -- Mute output gain = 0 -- Enable mute light (red = 1) - block.switchLights[i][1] = 1 + block.switchLights[i][0] = 1 else -- Disable mute light - block.switchLights[i][1] = 0 + block.switchLights[i][0] = 0 end -- Iterate input/output buffer - for j=1,block.bufferSize do + for j=0,block.bufferSize-1 do -- Get input x = block.inputs[i][j] -- Apply gain to input diff --git a/examples/rainbow.lua b/examples/rainbow.lua index db8eadd..341447f 100644 --- a/examples/rainbow.lua +++ b/examples/rainbow.lua @@ -34,10 +34,10 @@ function process(block) h = (1 - i / 6 + phase) % 1 rgb = hsvToRgb(h, 1, 1) for c=1,3 do - block.lights[i][c] = rgb[c] - block.switchLights[i][c] = rgb[c] + block.lights[i-1][c-1] = rgb[c] + block.switchLights[i-1][c-1] = rgb[c] end - block.outputs[i][1] = math.sin(2 * math.pi * h) * 5 + 5 + block.outputs[i-1][0] = math.sin(2 * math.pi * h) * 5 + 5 end end diff --git a/examples/vco.lua b/examples/vco.lua index 5a274f6..e39252b 100644 --- a/examples/vco.lua +++ b/examples/vco.lua @@ -9,10 +9,10 @@ config.bufferSize = 16 phase = 0 function process(block) -- Knob ranges from -5 to 5 octaves - pitch = block.knobs[1] * 10 - 5 + pitch = block.knobs[0] * 10 - 5 -- Input follows 1V/oct standard -- Take the first input's first buffer value - pitch = pitch + block.inputs[1][1] + pitch = pitch + block.inputs[0][0] -- The relationship between 1V/oct pitch and frequency is `freq = 2^pitch`. -- Default frequency is middle C (C4) in Hz. @@ -22,13 +22,13 @@ function process(block) -- Set all samples in output buffer deltaPhase = config.frameDivider * block.sampleTime * freq - for i=1,block.bufferSize do + for i=0,block.bufferSize-1 do -- Accumulate phase phase = phase + deltaPhase -- Wrap phase around range [0, 1] phase = phase % 1 -- Convert phase to sine output - block.outputs[1][i] = math.sin(2 * math.pi * phase) * 5 + block.outputs[0][i] = math.sin(2 * math.pi * phase) * 5 end end \ No newline at end of file diff --git a/src/LuaJITEngine.cpp b/src/LuaJITEngine.cpp index ee39157..28c6fcb 100644 --- a/src/LuaJITEngine.cpp +++ b/src/LuaJITEngine.cpp @@ -1,6 +1,28 @@ #include "ScriptEngine.hpp" #include +static const luaL_Reg lj_lib_load[] = { + { "", luaopen_base }, + { LUA_LOADLIBNAME, luaopen_package }, + { LUA_TABLIBNAME, luaopen_table }, + { LUA_STRLIBNAME, luaopen_string }, + { LUA_MATHLIBNAME, luaopen_math }, + { LUA_BITLIBNAME, luaopen_bit }, + { LUA_JITLIBNAME, luaopen_jit }, + { LUA_FFILIBNAME, luaopen_ffi }, + { NULL, NULL } +}; + +LUALIB_API void custom_openlibs(lua_State *L) +{ + const luaL_Reg *lib; + for (lib = lj_lib_load; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_pushstring(L, lib->name); + lua_call(L, 1, 0); + } + lua_pop(L, 1); +} struct LuaJITEngine : ScriptEngine { lua_State* L = NULL; @@ -29,16 +51,7 @@ struct LuaJITEngine : ScriptEngine { } // Import a subset of the standard library - luaopen_base(L); - luaopen_string(L); - luaopen_table(L); - luaopen_math(L); - luaopen_bit(L); - // Loads the JIT package otherwise it will be off - luaopen_jit(L); - // Disables access to the JIT package - lua_pushnil(L); - lua_setglobal(L,"jit"); + custom_openlibs(L); // Set user pointer lua_pushlightuserdata(L, this); @@ -63,7 +76,45 @@ struct LuaJITEngine : ScriptEngine { } lua_setglobal(L, "config"); - // Compile script + // Loads the FFI auxiliary functions. + std::stringstream ffi_stream; + ffi_stream + << "local ffi = require('ffi')" << std::endl + // Describes the struct 'ProcessBlock' that way LuaJIT knows how to access the data + << "ffi.cdef[[" << std::endl + << "struct ProcessBlock {" << std::endl + << "float sampleRate;" << std::endl + << "float sampleTime;" << std::endl + << "int bufferSize;" << std::endl + << "float inputs[" << NUM_ROWS << "][" << MAX_BUFFER_SIZE << "];" << std::endl + << "float outputs[" << NUM_ROWS << "][" << MAX_BUFFER_SIZE << "];" << std::endl + << "float knobs[" << NUM_ROWS << "];" << std::endl + << "bool switches[" << NUM_ROWS << "];" << std::endl + << "float lights[" << NUM_ROWS << "][3];" << std::endl + << "float switchLights[" << NUM_ROWS << "][3];};]]" << std::endl + // Declares the function 'castBlock' used to transform the 'block' pointer into a LuaJIT cdata + << "function castBlock(b) return ffi.cast('struct ProcessBlock*', b) end"; + std::string ffi_script = ffi_stream.str(); + + // Compile the ffi script + if (luaL_loadbuffer(L, ffi_script.c_str(), ffi_script.size(), "ffi_script.lua")) { + const char* s = lua_tostring(L, -1); + WARN("LuaJIT: %s", s); + display(s); + lua_pop(L, 1); + return -1; + } + + // Run the ffi script + if (lua_pcall(L, 0, 0, 0)) { + const char* s = lua_tostring(L, -1); + WARN("LuaJIT: %s", s); + display(s); + lua_pop(L, 1); + return -1; + } + + // Compile user script if (luaL_loadbuffer(L, script.c_str(), script.size(), path.c_str())) { const char* s = lua_tostring(L, -1); WARN("LuaJIT: %s", s); @@ -104,125 +155,16 @@ struct LuaJITEngine : ScriptEngine { return -1; } - // FloatArray metatable - lua_newtable(L); - { - // __index - lua_pushcfunction(L, native_FloatArray_index); - lua_setfield(L, -2, "__index"); - // __newindex - lua_pushcfunction(L, native_FloatArray_newindex); - lua_setfield(L, -2, "__newindex"); - // __len - lua_pushcfunction(L, native_FloatArray_len); - lua_setfield(L, -2, "__len"); - } - lua_setglobal(L, "FloatArray"); - - // BoolArray metatable - lua_newtable(L); - { - // __index - lua_pushcfunction(L, native_BoolArray_index); - lua_setfield(L, -2, "__index"); - // __newindex - lua_pushcfunction(L, native_BoolArray_newindex); - lua_setfield(L, -2, "__newindex"); - // __len - lua_pushcfunction(L, native_BoolArray_len); - lua_setfield(L, -2, "__len"); - } - lua_setglobal(L, "BoolArray"); - // Create block object - lua_newtable(L); - { - // inputs - lua_newtable(L); - for (int i = 0; i < NUM_ROWS; i++) { - SafeArray* input = (SafeArray*) lua_newuserdata(L, sizeof(SafeArray)); - input->p = &block->inputs[i]; - input->len = block->bufferSize; - lua_getglobal(L, "FloatArray"); - lua_setmetatable(L, -2); - lua_rawseti(L, -2, i + 1); - } - lua_setfield(L, -2, "inputs"); - - // outputs - lua_newtable(L); - for (int i = 0; i < NUM_ROWS; i++) { - SafeArray* output = (SafeArray*) lua_newuserdata(L, sizeof(SafeArray)); - output->p = &block->outputs[i]; - output->len = block->bufferSize; - lua_getglobal(L, "FloatArray"); - lua_setmetatable(L, -2); - lua_rawseti(L, -2, i + 1); - } - lua_setfield(L, -2, "outputs"); - - // knobs - SafeArray* knobs = (SafeArray*) lua_newuserdata(L, sizeof(SafeArray)); - knobs->p = &block->knobs; - knobs->len = 6; - lua_getglobal(L, "FloatArray"); - lua_setmetatable(L, -2); - lua_setfield(L, -2, "knobs"); - - // switches - SafeArray* switches = (SafeArray*) lua_newuserdata(L, sizeof(SafeArray)); - switches->p = &block->switches; - switches->len = 6; - lua_getglobal(L, "BoolArray"); - lua_setmetatable(L, -2); - lua_setfield(L, -2, "switches"); - - // lights - lua_newtable(L); - for (int i = 0; i < NUM_ROWS; i++) { - SafeArray* light = (SafeArray*) lua_newuserdata(L, sizeof(SafeArray)); - light->p = &block->lights[i]; - light->len = 3; - lua_getglobal(L, "FloatArray"); - lua_setmetatable(L, -2); - lua_rawseti(L, -2, i + 1); - } - lua_setfield(L, -2, "lights"); - - // switchLights - lua_newtable(L); - for (int i = 0; i < NUM_ROWS; i++) { - SafeArray* switchLight = (SafeArray*) lua_newuserdata(L, sizeof(SafeArray)); - switchLight->p = &block->switchLights[i]; - switchLight->len = 3; - lua_getglobal(L, "FloatArray"); - lua_setmetatable(L, -2); - lua_rawseti(L, -2, i + 1); - } - lua_setfield(L, -2, "switchLights"); - } + lua_getglobal(L, "castBlock"); + lua_pushlightuserdata(L, (void *)block); + if (lua_pcall(L, 1, 1, 0) != 0) + printf("error running function 'castBlock': %s", lua_tostring(L, -1)); return 0; } int process() override { - ProcessBlock* block = getProcessBlock(); - - // Set block - { - // sampleRate - lua_pushnumber(L, block->sampleRate); - lua_setfield(L, -2, "sampleRate"); - - // sampleTime - lua_pushnumber(L, block->sampleTime); - lua_setfield(L, -2, "sampleTime"); - - // bufferSize - lua_pushinteger(L, block->bufferSize); - lua_setfield(L, -2, "bufferSize"); - } - // Duplicate process function lua_pushvalue(L, -2); // Duplicate block @@ -264,62 +206,6 @@ struct LuaJITEngine : ScriptEngine { getEngine(L)->display(s); return 0; } - - static int native_FloatArray_index(lua_State* L) { - SafeArray* a = (SafeArray*) lua_touserdata(L, 1); - float* data = (float*) a->p; - size_t index = lua_tointeger(L, 2) - 1; - if (index >= a->len) { - lua_pushstring(L, "Array out of bounds"); - lua_error(L); - } - lua_pushnumber(L, data[index]); - return 1; - } - static int native_FloatArray_newindex(lua_State* L) { - SafeArray* a = (SafeArray*) lua_touserdata(L, 1); - float* data = (float*) a->p; - size_t index = lua_tointeger(L, 2) - 1; - if (index >= a->len) { - lua_pushstring(L, "Array out of bounds"); - lua_error(L); - } - data[index] = lua_tonumber(L, 3); - return 0; - } - static int native_FloatArray_len(lua_State* L) { - SafeArray* a = (SafeArray*) lua_touserdata(L, 1); - lua_pushinteger(L, a->len); - return 1; - } - - static int native_BoolArray_index(lua_State* L) { - SafeArray* a = (SafeArray*) lua_touserdata(L, 1); - bool* data = (bool*) a->p; - size_t index = lua_tointeger(L, 2) - 1; - if (index >= a->len) { - lua_pushstring(L, "Array out of bounds"); - lua_error(L); - } - lua_pushboolean(L, data[index]); - return 1; - } - static int native_BoolArray_newindex(lua_State* L) { - SafeArray* a = (SafeArray*) lua_touserdata(L, 1); - bool* data = (bool*) a->p; - size_t index = lua_tointeger(L, 2) - 1; - if (index >= a->len) { - lua_pushstring(L, "Array out of bounds"); - lua_error(L); - } - data[index] = lua_toboolean(L, 3); - return 0; - } - static int native_BoolArray_len(lua_State* L) { - SafeArray* a = (SafeArray*) lua_touserdata(L, 1); - lua_pushinteger(L, a->len); - return 1; - } }; From 4caf611d2d5ed99769de6479b3ee3d85c0903018 Mon Sep 17 00:00:00 2001 From: Leonardo Laguna Ruiz Date: Mon, 13 Apr 2020 18:42:36 +0300 Subject: [PATCH 06/27] Reverts changes in the Lua examples to use the original 1-based index --- examples/gain.lua | 10 +++++----- examples/rainbow.lua | 6 +++--- examples/vco.lua | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/gain.lua b/examples/gain.lua index 01aae12..45e8d95 100644 --- a/examples/gain.lua +++ b/examples/gain.lua @@ -6,23 +6,23 @@ config.bufferSize = 32 function process(block) -- Loop through each column - for i=0,5 do + for i=1,6 do -- Get gain knob gain = block.knobs[i] -- Set gain light (red = 1) - block.lights[i][0] = gain + block.lights[i][1] = gain -- Check mute switch if block.switches[i] then -- Mute output gain = 0 -- Enable mute light (red = 1) - block.switchLights[i][0] = 1 + block.switchLights[i][1] = 1 else -- Disable mute light - block.switchLights[i][0] = 0 + block.switchLights[i][1] = 0 end -- Iterate input/output buffer - for j=0,block.bufferSize-1 do + for j=1,block.bufferSize do -- Get input x = block.inputs[i][j] -- Apply gain to input diff --git a/examples/rainbow.lua b/examples/rainbow.lua index 341447f..db8eadd 100644 --- a/examples/rainbow.lua +++ b/examples/rainbow.lua @@ -34,10 +34,10 @@ function process(block) h = (1 - i / 6 + phase) % 1 rgb = hsvToRgb(h, 1, 1) for c=1,3 do - block.lights[i-1][c-1] = rgb[c] - block.switchLights[i-1][c-1] = rgb[c] + block.lights[i][c] = rgb[c] + block.switchLights[i][c] = rgb[c] end - block.outputs[i-1][0] = math.sin(2 * math.pi * h) * 5 + 5 + block.outputs[i][1] = math.sin(2 * math.pi * h) * 5 + 5 end end diff --git a/examples/vco.lua b/examples/vco.lua index e39252b..5a274f6 100644 --- a/examples/vco.lua +++ b/examples/vco.lua @@ -9,10 +9,10 @@ config.bufferSize = 16 phase = 0 function process(block) -- Knob ranges from -5 to 5 octaves - pitch = block.knobs[0] * 10 - 5 + pitch = block.knobs[1] * 10 - 5 -- Input follows 1V/oct standard -- Take the first input's first buffer value - pitch = pitch + block.inputs[0][0] + pitch = pitch + block.inputs[1][1] -- The relationship between 1V/oct pitch and frequency is `freq = 2^pitch`. -- Default frequency is middle C (C4) in Hz. @@ -22,13 +22,13 @@ function process(block) -- Set all samples in output buffer deltaPhase = config.frameDivider * block.sampleTime * freq - for i=0,block.bufferSize-1 do + for i=1,block.bufferSize do -- Accumulate phase phase = phase + deltaPhase -- Wrap phase around range [0, 1] phase = phase % 1 -- Convert phase to sine output - block.outputs[0][i] = math.sin(2 * math.pi * phase) * 5 + block.outputs[1][i] = math.sin(2 * math.pi * phase) * 5 end end \ No newline at end of file From 909d5d72414630e39f7034521c5b49ae29df974c Mon Sep 17 00:00:00 2001 From: Leonardo Laguna Ruiz Date: Mon, 13 Apr 2020 18:46:47 +0300 Subject: [PATCH 07/27] Implements a copy of the ProccessBlock that is used to provide 1-based indices in the Lua VM and keep the speed of the FFI --- src/LuaJITEngine.cpp | 62 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/src/LuaJITEngine.cpp b/src/LuaJITEngine.cpp index 28c6fcb..dee7d99 100644 --- a/src/LuaJITEngine.cpp +++ b/src/LuaJITEngine.cpp @@ -27,11 +27,22 @@ LUALIB_API void custom_openlibs(lua_State *L) struct LuaJITEngine : ScriptEngine { lua_State* L = NULL; - struct SafeArray { - void* p; - size_t len; + // This is a mirror of ProcessBlock that we are going to use + // to provide 1-based indices within the Lua VM + struct LuaProcessBlock { + float sampleRate; + float sampleTime; + int bufferSize; + float* inputs[NUM_ROWS+1]; + float* outputs[NUM_ROWS+1]; + float* knobs; + bool* switches; + float* lights[NUM_ROWS+1]; + float* switchLights[NUM_ROWS+1]; }; + LuaProcessBlock block; + ~LuaJITEngine() { if (L) lua_close(L); @@ -42,7 +53,22 @@ struct LuaJITEngine : ScriptEngine { } int run(const std::string& path, const std::string& script) override { - ProcessBlock* block = getProcessBlock(); + ProcessBlock* original_block = getProcessBlock(); + + block.sampleRate = original_block->sampleRate; + block.sampleTime = original_block->sampleTime; + block.bufferSize = original_block->bufferSize; + + // Initialize all the pointers with an offset of -1 + block.knobs = (float*)&(original_block->knobs[-1]); + block.switches = (bool*)&(original_block->switches[-1]); + + for(int i = 1; i < NUM_ROWS + 1; i++) { + block.inputs[i] = (float*)&(original_block->inputs[i-1][-1]); + block.outputs[i] = (float*)&(original_block->outputs[i-1][-1]); + block.lights[i] = (float*)&(original_block->lights[i-1][-1]); + block.switchLights[i] = (float*)&(original_block->switchLights[i-1][-1]); + } L = luaL_newstate(); if (!L) { @@ -80,20 +106,21 @@ struct LuaJITEngine : ScriptEngine { std::stringstream ffi_stream; ffi_stream << "local ffi = require('ffi')" << std::endl - // Describes the struct 'ProcessBlock' that way LuaJIT knows how to access the data + // Describes the struct 'LuaProcessBlock' that way LuaJIT knows how to access the data << "ffi.cdef[[" << std::endl - << "struct ProcessBlock {" << std::endl + << "struct LuaProcessBlock {" << std::endl << "float sampleRate;" << std::endl << "float sampleTime;" << std::endl << "int bufferSize;" << std::endl - << "float inputs[" << NUM_ROWS << "][" << MAX_BUFFER_SIZE << "];" << std::endl - << "float outputs[" << NUM_ROWS << "][" << MAX_BUFFER_SIZE << "];" << std::endl - << "float knobs[" << NUM_ROWS << "];" << std::endl - << "bool switches[" << NUM_ROWS << "];" << std::endl - << "float lights[" << NUM_ROWS << "][3];" << std::endl - << "float switchLights[" << NUM_ROWS << "][3];};]]" << std::endl + << "float *inputs[" << NUM_ROWS + 1 << "];" << std::endl + << "float *outputs[" << NUM_ROWS + 1 << "];" << std::endl + << "float *knobs;" << std::endl + << "bool *switches;" << std::endl + << "float *lights[" << NUM_ROWS + 1 << "];" << std::endl + << "float *switchLights[" << NUM_ROWS + 1 << "];" << std::endl + <<"};]]" << std::endl // Declares the function 'castBlock' used to transform the 'block' pointer into a LuaJIT cdata - << "function castBlock(b) return ffi.cast('struct ProcessBlock*', b) end"; + << "function castBlock(b) return ffi.cast('struct LuaProcessBlock*', b) end"; std::string ffi_script = ffi_stream.str(); // Compile the ffi script @@ -157,7 +184,7 @@ struct LuaJITEngine : ScriptEngine { // Create block object lua_getglobal(L, "castBlock"); - lua_pushlightuserdata(L, (void *)block); + lua_pushlightuserdata(L, (void *)&block); if (lua_pcall(L, 1, 1, 0) != 0) printf("error running function 'castBlock': %s", lua_tostring(L, -1)); @@ -165,6 +192,13 @@ struct LuaJITEngine : ScriptEngine { } int process() override { + ProcessBlock* original_block = getProcessBlock(); + + // Update the values of the block (the pointers should not change) + block.sampleRate = original_block->sampleRate; + block.sampleTime = original_block->sampleTime; + block.bufferSize = original_block->bufferSize; + // Duplicate process function lua_pushvalue(L, -2); // Duplicate block From c823845e7abfab0a79a715e3cf5325e540ee1d94 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Thu, 25 Jun 2020 11:33:05 -0400 Subject: [PATCH 08/27] LuaJIT: Clean up code and organization. --- src/LuaJITEngine.cpp | 108 +++++++++++++++++++++---------------------- 1 file changed, 53 insertions(+), 55 deletions(-) diff --git a/src/LuaJITEngine.cpp b/src/LuaJITEngine.cpp index dee7d99..dc0dada 100644 --- a/src/LuaJITEngine.cpp +++ b/src/LuaJITEngine.cpp @@ -1,28 +1,6 @@ #include "ScriptEngine.hpp" #include -static const luaL_Reg lj_lib_load[] = { - { "", luaopen_base }, - { LUA_LOADLIBNAME, luaopen_package }, - { LUA_TABLIBNAME, luaopen_table }, - { LUA_STRLIBNAME, luaopen_string }, - { LUA_MATHLIBNAME, luaopen_math }, - { LUA_BITLIBNAME, luaopen_bit }, - { LUA_JITLIBNAME, luaopen_jit }, - { LUA_FFILIBNAME, luaopen_ffi }, - { NULL, NULL } -}; - -LUALIB_API void custom_openlibs(lua_State *L) -{ - const luaL_Reg *lib; - for (lib = lj_lib_load; lib->func; lib++) { - lua_pushcfunction(L, lib->func); - lua_pushstring(L, lib->name); - lua_call(L, 1, 0); - } - lua_pop(L, 1); -} struct LuaJITEngine : ScriptEngine { lua_State* L = NULL; @@ -33,15 +11,15 @@ struct LuaJITEngine : ScriptEngine { float sampleRate; float sampleTime; int bufferSize; - float* inputs[NUM_ROWS+1]; - float* outputs[NUM_ROWS+1]; + float* inputs[NUM_ROWS + 1]; + float* outputs[NUM_ROWS + 1]; float* knobs; bool* switches; - float* lights[NUM_ROWS+1]; - float* switchLights[NUM_ROWS+1]; + float* lights[NUM_ROWS + 1]; + float* switchLights[NUM_ROWS + 1]; }; - LuaProcessBlock block; + LuaProcessBlock luaBlock; ~LuaJITEngine() { if (L) @@ -53,22 +31,21 @@ struct LuaJITEngine : ScriptEngine { } int run(const std::string& path, const std::string& script) override { - ProcessBlock* original_block = getProcessBlock(); - - block.sampleRate = original_block->sampleRate; - block.sampleTime = original_block->sampleTime; - block.bufferSize = original_block->bufferSize; + ProcessBlock* block = getProcessBlock(); // Initialize all the pointers with an offset of -1 - block.knobs = (float*)&(original_block->knobs[-1]); - block.switches = (bool*)&(original_block->switches[-1]); - - for(int i = 1; i < NUM_ROWS + 1; i++) { - block.inputs[i] = (float*)&(original_block->inputs[i-1][-1]); - block.outputs[i] = (float*)&(original_block->outputs[i-1][-1]); - block.lights[i] = (float*)&(original_block->lights[i-1][-1]); - block.switchLights[i] = (float*)&(original_block->switchLights[i-1][-1]); +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Warray-bounds" + luaBlock.knobs = &block->knobs[-1]; + luaBlock.switches = &block->switches[-1]; + + for (int i = 0; i < NUM_ROWS; i++) { + luaBlock.inputs[i + 1] = &block->inputs[i][-1]; + luaBlock.outputs[i + 1] = &block->outputs[i][-1]; + luaBlock.lights[i + 1] = &block->lights[i][-1]; + luaBlock.switchLights[i + 1] = &block->switchLights[i][-1]; } +#pragma GCC diagnostic pop L = luaL_newstate(); if (!L) { @@ -77,7 +54,22 @@ struct LuaJITEngine : ScriptEngine { } // Import a subset of the standard library - custom_openlibs(L); + static const luaL_Reg lj_lib_load[] = { + {"", luaopen_base}, + {LUA_LOADLIBNAME, luaopen_package}, + {LUA_TABLIBNAME, luaopen_table}, + {LUA_STRLIBNAME, luaopen_string}, + {LUA_MATHLIBNAME, luaopen_math}, + {LUA_BITLIBNAME, luaopen_bit}, + {LUA_JITLIBNAME, luaopen_jit}, + {LUA_FFILIBNAME, luaopen_ffi}, + {NULL, NULL} + }; + for (const luaL_Reg* lib = lj_lib_load; lib->func; lib++) { + lua_pushcfunction(L, lib->func); + lua_pushstring(L, lib->name); + lua_call(L, 1, 0); + } // Set user pointer lua_pushlightuserdata(L, this); @@ -102,11 +94,11 @@ struct LuaJITEngine : ScriptEngine { } lua_setglobal(L, "config"); - // Loads the FFI auxiliary functions. + // Load the FFI auxiliary functions. std::stringstream ffi_stream; ffi_stream << "local ffi = require('ffi')" << std::endl - // Describes the struct 'LuaProcessBlock' that way LuaJIT knows how to access the data + // Describe the struct `LuaProcessBlock` so that LuaJIT knows how to access the data << "ffi.cdef[[" << std::endl << "struct LuaProcessBlock {" << std::endl << "float sampleRate;" << std::endl @@ -118,9 +110,9 @@ struct LuaJITEngine : ScriptEngine { << "bool *switches;" << std::endl << "float *lights[" << NUM_ROWS + 1 << "];" << std::endl << "float *switchLights[" << NUM_ROWS + 1 << "];" << std::endl - <<"};]]" << std::endl - // Declares the function 'castBlock' used to transform the 'block' pointer into a LuaJIT cdata - << "function castBlock(b) return ffi.cast('struct LuaProcessBlock*', b) end"; + << "};]]" << std::endl + // Declare the function `_castBlock` used to transform `luaBlock` pointer into a LuaJIT cdata + << "function _castBlock(b) return ffi.cast('struct LuaProcessBlock*', b) end"; std::string ffi_script = ffi_stream.str(); // Compile the ffi script @@ -183,21 +175,27 @@ struct LuaJITEngine : ScriptEngine { } // Create block object - lua_getglobal(L, "castBlock"); - lua_pushlightuserdata(L, (void *)&block); - if (lua_pcall(L, 1, 1, 0) != 0) - printf("error running function 'castBlock': %s", lua_tostring(L, -1)); + lua_getglobal(L, "_castBlock"); + lua_pushlightuserdata(L, (void*) &luaBlock); + if (lua_pcall(L, 1, 1, 0)) { + const char* s = lua_tostring(L, -1); + WARN("LuaJIT: Error casting block: %s", s); + display(s); + lua_pop(L, 1); + return -1; + } return 0; } int process() override { - ProcessBlock* original_block = getProcessBlock(); + ProcessBlock* block = getProcessBlock(); - // Update the values of the block (the pointers should not change) - block.sampleRate = original_block->sampleRate; - block.sampleTime = original_block->sampleTime; - block.bufferSize = original_block->bufferSize; + // Update the values of the block. + // The pointer values do not change. + luaBlock.sampleRate = block->sampleRate; + luaBlock.sampleTime = block->sampleTime; + luaBlock.bufferSize = block->bufferSize; // Duplicate process function lua_pushvalue(L, -2); From 165693b0dedbd6dbc4ddf4f37746ea992098b108 Mon Sep 17 00:00:00 2001 From: Leonardo Laguna Ruiz Date: Fri, 17 Apr 2020 22:11:12 +0300 Subject: [PATCH 09/27] Add support for Vult scripts --- Makefile | 18 ++++++ README.md | 5 ++ examples/basic.vult | 83 ++++++++++++++++++++++++ examples/synth.vult | 80 +++++++++++++++++++++++ examples/vco.vult | 45 +++++++++++++ src/VultEngine.cpp | 153 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 384 insertions(+) create mode 100644 examples/basic.vult create mode 100644 examples/synth.vult create mode 100644 examples/vco.vult create mode 100644 src/VultEngine.cpp diff --git a/Makefile b/Makefile index 8cd8e9f..d8646a5 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,13 @@ QUICKJS ?= 1 LUAJIT ?= 1 PYTHON ?= 0 SUPERCOLLIDER ?= 0 +VULT ?= 1 + +# Vult depends on both LuaJIT and QuickJS +ifeq ($(VULT), 1) +QUICKJS = 1 +LUAJIT = 1 +endif # Entropia File System Watcher efsw := dep/lib/libefsw-static-release.a @@ -186,5 +193,16 @@ endif # cd dep/llvm-8.0.1.src/build && $(MAKE) # cd dep/llvm-8.0.1.src/build && $(MAKE) install +# Vult +ifeq ($(VULT), 1) +SOURCES += src/VultEngine.cpp +vult := dep/vult/vultc.h +$(vult): + cd dep && mkdir -p vult + cd dep/vult && $(WGET) "https://github.com/modlfo/vult/releases/download/v0.4.9/vultc.h" + $(SHA256) $(vult) 73f53e7595d515ae87fe1c89925e17cd86c2ac75b73b48fa502a2fb0fd1d4847 +FLAGS += -Idep/vult +DEPS += $(vult) +endif include $(RACK_DIR)/plugin.mk diff --git a/README.md b/README.md index d206ef3..625daaf 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ Scripting language host for [VCV Rack](https://vcvrack.com/) containing: Supported scripting languages: - JavaScript (.js) +- Lua (.lua) +- [Vult](https://github.com/modlfo/vult) (.vult) - [Add your own below](#adding-a-script-engine) [Discussion thread](https://community.vcvrack.com/t/vcv-prototype/3271) @@ -89,6 +91,8 @@ function process(block) { } ``` +The Vult API is slightly different from the JavaScript version. Check the Vult examples included with the plugin to learn how to use the language with the VCV-Prototype plugin. + ## Build dependencies ### Windows @@ -125,4 +129,5 @@ sudo pacman -S premake - [Wes Milholen](https://grayscale.info/): panel design - [Andrew Belt](https://github.com/AndrewBelt): host code, Duktape (JavaScript, disabled), LuaJIT (Lua), Python (in development) - [Jerry Sievert](https://github.com/JerrySievert): QuickJS (JavaScript) +- [Leonardo Laguna Ruiz](https://github.com/modlfo): Vult - add your name here diff --git a/examples/basic.vult b/examples/basic.vult new file mode 100644 index 0000000..f77c865 --- /dev/null +++ b/examples/basic.vult @@ -0,0 +1,83 @@ +/* + Vult API documentation. + + Author: Leonardo Laguna Ruiz - leonardo@vult-dsp.com + + The main difference of the Vult API compared to the JavaScript and Lua is that all interactions + happen through functions rather than accessing to the block arrays. + + A Vult script requires the following two functions: + + fun process() { } + and update() { } + + The 'process' function is called every audio sample. As inputs, it will receive the values from + the input jacks but normalized to 1.0. This means that a value of 10.0 V in VCV Rack is received + as 1.0. Similarly, when you return a value of 1.0 it will be output by the prototype as 10.0V. + + You can use the input and output jacks by adding or removing arguments to the function. For example, + to pass all the inputs to the outputs you can declare the function as follows: + + fun process(i1, i2, i3, i4, i5, i6) { + return i1, i2, i3, i4, i5, i6; + } + + The 'update' function is called once every 32 samples. You can use this function to perform actions + that do not require audio rate speed e.g. setting light colors or displying characters in the screen. + The function 'update' do not takes or returns any value. + + Important: Notice that the 'update' function is declared with the keyword 'and'. In Vult language, + this means that they share context. At the moment, declaring them differently could have an undefined + behavior. + + To interact with knobs, switches, lights the following builtin functions are provided. + NOTE: the knobs, switches and lights are numbered from 1 to 6 + + getKnob(n:int) : real // value of the nth knob range: 0.0-1.0 + getSwitch(n:int) : bool // value of the nth switch: true/false + + setLight(n:int, r:real, g:real, b:real) // r, g, b range: 0.0-1.0 + setSwitchLight(n:int, r:real, g:real, b:real) // r, g, b range: 0.0-1.0 + + samplerate() : real // current sample rate + sampletime() : real // current time step (1.0 / samplerate()) + display(text:string) // display text in the screen + + */ + + +// Returns the r,g,b values for a given voltage +fun getRGB(v) { + if (v > 0.0) + return v, 0.0, 0.0; + else + return 0.0, -v, 0.0; +} + +// Takes two inputs and returns the result of different operations on them +fun process(in1, in2) { + // theses are declared as 'mem' so we can remember them and use them in 'update' + mem sum = clip(in1 + in2, -1.0, 1.0); // use 'clip' to keep the signals in the specified range + mem sub = clip(in1 - in2, -1.0, 1.0); + mem mul = clip(in1 * in2, -1.0, 1.0); + return sum, sub, mul; +} +and update() { + _ = display("Add two LFO to IN1 and IN2"); + val r, g, b; + // Set the light no 1 with the 'sum' value + r, g, b = getRGB(sum); + _ = setLight(1, r, g, b); + _ = setSwitchLight(1, r, g, b); + + // Set the light no 2 with the 'sub' value + r, g, b = getRGB(sub); + _ = setLight(2, r, g, b); + _ = setSwitchLight(2, r, g, b); + + // Set the light no 2 with the 'mul' value + r, g, b = getRGB(mul); + _ = setLight(3, r, g, b); + _ = setSwitchLight(3, r, g, b); + +} \ No newline at end of file diff --git a/examples/synth.vult b/examples/synth.vult new file mode 100644 index 0000000..0042632 --- /dev/null +++ b/examples/synth.vult @@ -0,0 +1,80 @@ +/* + +Simple synthesizer with one oscillator, LFO and envelope. + +Author: Leonardo Laguna Ruiz - leonardo@vult-dsp.com + +Check the API documentation in the basic.vult example + +*/ + +fun env(gate) { + mem x; + val k = if gate > x then 0.05 else 0.0002; + x = x + (gate - x) * k; + return x; +} + +fun edge(x):bool { + mem pre_x; + val v:bool = (pre_x <> x) && (pre_x == false); + pre_x = x; + return v; +} + +fun pitchToFreq(cv) { + return 261.6256 * exp(cv * 0.69314718056); +} + +fun phasor(pitch, reset){ + mem phase; + val rate = pitchToFreq(pitch) * sampletime(); + phase = phase + rate; + if(phase > 1.0) + phase = phase - 1.0; + if(reset) + phase = 0.0; + return phase; +} + +fun oscillator(pitch, mod) { + mem pre_phase1; + // Implements the resonant filter simulation as shown in + // http://en.wikipedia.org/wiki/Phase_distortion_synthesis + val phase1 = phasor(pitch, false); + val comp = 1.0 - phase1; + val reset = edge((pre_phase1 - phase1) > 0.5); + pre_phase1 = phase1; + val phase2 = phasor(pitch + mod, reset); + val sine = sin(2.0 * pi() * phase2); + return sine * comp; +} + +fun lfo(f, gate){ + mem phase; + val rate = f * 10.0 * sampletime(); + if(edge(gate > 0.0)) + phase = 0.0; + phase = phase + rate; + if(phase > 1.0) + phase = phase - 1.0; + return sin(phase * 2.0 * pi()) - 0.5; +} + +// Main processing function +fun process(cv, gate){ + // LFO + val lfo_rate = getKnob(3); + val lfo_amt = getKnob(4); + val lfo_val = lfo(lfo_rate, gate) * lfo_amt; + // Oscillator + val pitch = getKnob(1) + 10.0 * cv - 2.0; + val mod = getKnob(2) * 2.0 + lfo_val; + val o = oscillator(pitch, mod); + // Envelope + val e = env(gate); + return o * e; +} +and update() { + _ = display("IN1: CV, IN2: GATE"); +} \ No newline at end of file diff --git a/examples/vco.vult b/examples/vco.vult new file mode 100644 index 0000000..9b8155e --- /dev/null +++ b/examples/vco.vult @@ -0,0 +1,45 @@ + +/* + +Simple wave table VCO. + +Author: Leonardo Laguna Ruiz - leonardo@vult-dsp.com + +Check the API documentation in the basic.vult example + +*/ + +fun pitchToFreq(cv) @[table(size=128, min=-10.0, max=10.0)] { + return 261.6256 * exp(cv * 0.69314718056); +} + +// Generates (at compile time) a wave table based on the provided harmonics +// To change the wave table, change the 'harmonics' array +fun wavetable(phase) @[table(size=128, min=0.0, max=1.0)] { + val harmonics = [0.0, 1.0, 0.7, 0.5, 0.3]; + val n = size(harmonics); + val acc = 0.0; + val i = 0; + while(i < n) { + acc = acc + harmonics[i] * sin(2.0 * pi() * real(i) * phase); + i = i + 1; + } + return acc / sqrt(real(n)); +} + +fun process(input_cv:real) { + mem phase; + val knob_cv = getKnob(1) - 0.5; + val cv = 10.0 * (input_cv + knob_cv); + val freq = pitchToFreq(cv); + val delta = sampletime() * freq; + phase = phase + delta; + if(phase > 1.0) { + phase = phase - 1.0; + } + + return wavetable(phase); +} +and update() { + +} diff --git a/src/VultEngine.cpp b/src/VultEngine.cpp new file mode 100644 index 0000000..c454b0d --- /dev/null +++ b/src/VultEngine.cpp @@ -0,0 +1,153 @@ +#include "ScriptEngine.hpp" +#include "vultc.h" +#include + +/* The Vult engine relies on both QuickJS and LuaJIT. + * + * The compiler is written in OCaml but converted to JavaScript. The JavaScript + * code is embedded as a string and executed by the QuickJs engine. The Vult + * compiler generates Lua code that is executed by the LuaJIT engine. + */ + +extern std::map scriptEngineFactories; +// Special version of createScriptEngine that only creates Lua engines +ScriptEngine *createLuaEngine() { + auto it = scriptEngineFactories.find("lua"); + if (it == scriptEngineFactories.end()) + return NULL; + return it->second->createScriptEngine(); +} + +struct VultEngine : ScriptEngine { + + // used to run the lua generated code + ScriptEngine *luaEngine; + + // used to run the Vult compiler + JSRuntime *rt = NULL; + JSContext *ctx = NULL; + + VultEngine() { + rt = JS_NewRuntime(); + // Create QuickJS context + ctx = JS_NewContext(rt); + if (!ctx) { + display("Could not create QuickJS context"); + return; + } + + JSValue global_obj = JS_GetGlobalObject(ctx); + + // Load the Vult compiler code + JSValue val = + JS_Eval(ctx, (const char *)vultc_h, vultc_h_size, "vultc.js", 0); + if (JS_IsException(val)) { + display("Error loading the Vult compiler"); + JS_FreeValue(ctx, val); + JS_FreeValue(ctx, global_obj); + return; + } + } + + ~VultEngine() { + if (ctx) { + JS_FreeContext(ctx); + } + if (rt) { + JS_FreeRuntime(rt); + } + } + + std::string getEngineName() override { return "Vult"; } + + int run(const std::string &path, const std::string &script) override { + display("Loading..."); + + JSValue global_obj = JS_GetGlobalObject(ctx); + + // Put the script text in the 'code' variable + JSValue code = JS_NewString(ctx, script.c_str()); + JS_SetPropertyStr(ctx, global_obj, "code", code); + + // Put the script path in 'file' variable + JSValue file = JS_NewString(ctx, path.c_str()); + JS_SetPropertyStr(ctx, global_obj, "file", file); + + display("Compiling..."); + // Call the Vult compiler to generate Lua code + static const std::string testVult = R"( + var result = vult.generateLua([{ file:file, code:code}],{ output:'Engine', template:'vcv-prototype'});)"; + + JSValue compile = + JS_Eval(ctx, testVult.c_str(), testVult.size(), "Compile", 0); + + JS_FreeValue(ctx, code); + JS_FreeValue(ctx, file); + + // If there are any internal errors, the execution could fail + if (JS_IsException(compile)) { + display("Fatal error in the Vult compiler"); + JS_FreeValue(ctx, global_obj); + return -1; + } + + // Retrive the variable 'result' + JSValue result = JS_GetPropertyStr(ctx, global_obj, "result"); + // Get the first element of the 'result' array + JSValue first = JS_GetPropertyUint32(ctx, result, 0); + // Try to get the 'msg' field which is only present in error messages + JSValue msg = JS_GetPropertyStr(ctx, first, "msg"); + // Display the error if any + if (!JS_IsUndefined(msg)) { + const char *text = JS_ToCString(ctx, msg); + const char *row = + JS_ToCString(ctx, JS_GetPropertyStr(ctx, first, "line")); + const char *col = JS_ToCString(ctx, JS_GetPropertyStr(ctx, first, "col")); + // Compose the error message + std::stringstream error; + error << "line:" << row << ":" << col << ": " << text; + WARN("Vult Error: %s", error.str().c_str()); + display(error.str().c_str()); + + JS_FreeValue(ctx, result); + JS_FreeValue(ctx, first); + JS_FreeValue(ctx, msg); + return -1; + } + // In case of no error, retrieve the generated code + JSValue luacode = JS_GetPropertyStr(ctx, first, "code"); + std::string luacode_str(JS_ToCString(ctx, luacode)); + + //WARN("Generated Code: %s", luacode_str.c_str()); + + luaEngine = createLuaEngine(); + + if (!luaEngine) { + WARN("Could not create a Lua script engine"); + return -1; + } + + luaEngine->module = this->module; + + display("Running..."); + + JS_FreeValue(ctx, luacode); + JS_FreeValue(ctx, first); + JS_FreeValue(ctx, msg); + JS_FreeValue(ctx, msg); + JS_FreeValue(ctx, global_obj); + + return luaEngine->run(path, luacode_str); + } + + int process() override { + if (luaEngine) + return luaEngine->process(); + else + return 0; + } +}; + +__attribute__((constructor(1000))) static void constructor() { + addScriptEngine("vult"); +} From a4d9b387c37bcfd4e313b16eeedefdf527e2eb21 Mon Sep 17 00:00:00 2001 From: Leonardo Date: Mon, 20 Apr 2020 18:47:33 +0300 Subject: [PATCH 10/27] Fixes the vultc.h checksum --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d8646a5..8d01326 100644 --- a/Makefile +++ b/Makefile @@ -200,7 +200,7 @@ vult := dep/vult/vultc.h $(vult): cd dep && mkdir -p vult cd dep/vult && $(WGET) "https://github.com/modlfo/vult/releases/download/v0.4.9/vultc.h" - $(SHA256) $(vult) 73f53e7595d515ae87fe1c89925e17cd86c2ac75b73b48fa502a2fb0fd1d4847 + $(SHA256) $(vult) 91f575afd2913d0879df90ee666021065ad726372f0bd306198024dc771cce55 FLAGS += -Idep/vult DEPS += $(vult) endif From c6594800997016bc14bde7d193d69aa18aeba094 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Thu, 25 Jun 2020 13:03:05 -0400 Subject: [PATCH 11/27] Vult: Clean up code and auto-format. --- Makefile | 4 +- README.md | 9 +- examples/basic.vult | 83 -------------- src/VultEngine.cpp | 263 ++++++++++++++++++++++---------------------- 4 files changed, 139 insertions(+), 220 deletions(-) delete mode 100644 examples/basic.vult diff --git a/Makefile b/Makefile index 8d01326..0c0cc98 100644 --- a/Makefile +++ b/Makefile @@ -22,8 +22,8 @@ VULT ?= 1 # Vult depends on both LuaJIT and QuickJS ifeq ($(VULT), 1) -QUICKJS = 1 -LUAJIT = 1 +QUICKJS := 1 +LUAJIT := 1 endif # Entropia File System Watcher diff --git a/README.md b/README.md index 625daaf..268cc6c 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ Scripting language host for [VCV Rack](https://vcvrack.com/) containing: - 6 switches with RGB LEDs Supported scripting languages: -- JavaScript (.js) -- Lua (.lua) +- JavaScript (ES2020) (.js) +- [Lua](https://www.lua.org/) (.lua) - [Vult](https://github.com/modlfo/vult) (.vult) - [Add your own below](#adding-a-script-engine) @@ -91,7 +91,8 @@ function process(block) { } ``` -The Vult API is slightly different from the JavaScript version. Check the Vult examples included with the plugin to learn how to use the language with the VCV-Prototype plugin. +*The Vult API is slightly different than Prototype's scripting API. +See `examples/template.vult` for a reference of the Vult API.* ## Build dependencies @@ -127,7 +128,7 @@ sudo pacman -S premake ## Contributors - [Wes Milholen](https://grayscale.info/): panel design -- [Andrew Belt](https://github.com/AndrewBelt): host code, Duktape (JavaScript, disabled), LuaJIT (Lua), Python (in development) +- [Andrew Belt](https://github.com/AndrewBelt): host code, Duktape (JavaScript, not used), LuaJIT (Lua), Python (in development) - [Jerry Sievert](https://github.com/JerrySievert): QuickJS (JavaScript) - [Leonardo Laguna Ruiz](https://github.com/modlfo): Vult - add your name here diff --git a/examples/basic.vult b/examples/basic.vult deleted file mode 100644 index f77c865..0000000 --- a/examples/basic.vult +++ /dev/null @@ -1,83 +0,0 @@ -/* - Vult API documentation. - - Author: Leonardo Laguna Ruiz - leonardo@vult-dsp.com - - The main difference of the Vult API compared to the JavaScript and Lua is that all interactions - happen through functions rather than accessing to the block arrays. - - A Vult script requires the following two functions: - - fun process() { } - and update() { } - - The 'process' function is called every audio sample. As inputs, it will receive the values from - the input jacks but normalized to 1.0. This means that a value of 10.0 V in VCV Rack is received - as 1.0. Similarly, when you return a value of 1.0 it will be output by the prototype as 10.0V. - - You can use the input and output jacks by adding or removing arguments to the function. For example, - to pass all the inputs to the outputs you can declare the function as follows: - - fun process(i1, i2, i3, i4, i5, i6) { - return i1, i2, i3, i4, i5, i6; - } - - The 'update' function is called once every 32 samples. You can use this function to perform actions - that do not require audio rate speed e.g. setting light colors or displying characters in the screen. - The function 'update' do not takes or returns any value. - - Important: Notice that the 'update' function is declared with the keyword 'and'. In Vult language, - this means that they share context. At the moment, declaring them differently could have an undefined - behavior. - - To interact with knobs, switches, lights the following builtin functions are provided. - NOTE: the knobs, switches and lights are numbered from 1 to 6 - - getKnob(n:int) : real // value of the nth knob range: 0.0-1.0 - getSwitch(n:int) : bool // value of the nth switch: true/false - - setLight(n:int, r:real, g:real, b:real) // r, g, b range: 0.0-1.0 - setSwitchLight(n:int, r:real, g:real, b:real) // r, g, b range: 0.0-1.0 - - samplerate() : real // current sample rate - sampletime() : real // current time step (1.0 / samplerate()) - display(text:string) // display text in the screen - - */ - - -// Returns the r,g,b values for a given voltage -fun getRGB(v) { - if (v > 0.0) - return v, 0.0, 0.0; - else - return 0.0, -v, 0.0; -} - -// Takes two inputs and returns the result of different operations on them -fun process(in1, in2) { - // theses are declared as 'mem' so we can remember them and use them in 'update' - mem sum = clip(in1 + in2, -1.0, 1.0); // use 'clip' to keep the signals in the specified range - mem sub = clip(in1 - in2, -1.0, 1.0); - mem mul = clip(in1 * in2, -1.0, 1.0); - return sum, sub, mul; -} -and update() { - _ = display("Add two LFO to IN1 and IN2"); - val r, g, b; - // Set the light no 1 with the 'sum' value - r, g, b = getRGB(sum); - _ = setLight(1, r, g, b); - _ = setSwitchLight(1, r, g, b); - - // Set the light no 2 with the 'sub' value - r, g, b = getRGB(sub); - _ = setLight(2, r, g, b); - _ = setSwitchLight(2, r, g, b); - - // Set the light no 2 with the 'mul' value - r, g, b = getRGB(mul); - _ = setLight(3, r, g, b); - _ = setSwitchLight(3, r, g, b); - -} \ No newline at end of file diff --git a/src/VultEngine.cpp b/src/VultEngine.cpp index c454b0d..4370f53 100644 --- a/src/VultEngine.cpp +++ b/src/VultEngine.cpp @@ -9,145 +9,146 @@ * compiler generates Lua code that is executed by the LuaJIT engine. */ -extern std::map scriptEngineFactories; // Special version of createScriptEngine that only creates Lua engines -ScriptEngine *createLuaEngine() { - auto it = scriptEngineFactories.find("lua"); - if (it == scriptEngineFactories.end()) - return NULL; - return it->second->createScriptEngine(); +ScriptEngine* createLuaEngine() { + auto it = scriptEngineFactories.find("lua"); + if (it == scriptEngineFactories.end()) + return NULL; + return it->second->createScriptEngine(); } struct VultEngine : ScriptEngine { - // used to run the lua generated code - ScriptEngine *luaEngine; - - // used to run the Vult compiler - JSRuntime *rt = NULL; - JSContext *ctx = NULL; - - VultEngine() { - rt = JS_NewRuntime(); - // Create QuickJS context - ctx = JS_NewContext(rt); - if (!ctx) { - display("Could not create QuickJS context"); - return; - } - - JSValue global_obj = JS_GetGlobalObject(ctx); - - // Load the Vult compiler code - JSValue val = - JS_Eval(ctx, (const char *)vultc_h, vultc_h_size, "vultc.js", 0); - if (JS_IsException(val)) { - display("Error loading the Vult compiler"); - JS_FreeValue(ctx, val); - JS_FreeValue(ctx, global_obj); - return; - } - } - - ~VultEngine() { - if (ctx) { - JS_FreeContext(ctx); - } - if (rt) { - JS_FreeRuntime(rt); - } - } - - std::string getEngineName() override { return "Vult"; } - - int run(const std::string &path, const std::string &script) override { - display("Loading..."); - - JSValue global_obj = JS_GetGlobalObject(ctx); - - // Put the script text in the 'code' variable - JSValue code = JS_NewString(ctx, script.c_str()); - JS_SetPropertyStr(ctx, global_obj, "code", code); - - // Put the script path in 'file' variable - JSValue file = JS_NewString(ctx, path.c_str()); - JS_SetPropertyStr(ctx, global_obj, "file", file); - - display("Compiling..."); - // Call the Vult compiler to generate Lua code - static const std::string testVult = R"( + // used to run the lua generated code + ScriptEngine* luaEngine; + + // used to run the Vult compiler + JSRuntime* rt = NULL; + JSContext* ctx = NULL; + + VultEngine() { + rt = JS_NewRuntime(); + // Create QuickJS context + ctx = JS_NewContext(rt); + if (!ctx) { + display("Could not create QuickJS context"); + return; + } + + JSValue global_obj = JS_GetGlobalObject(ctx); + + // Load the Vult compiler code + JSValue val = + JS_Eval(ctx, (const char*)vultc_h, vultc_h_size, "vultc.js", 0); + if (JS_IsException(val)) { + display("Error loading the Vult compiler"); + JS_FreeValue(ctx, val); + JS_FreeValue(ctx, global_obj); + return; + } + } + + ~VultEngine() { + if (ctx) { + JS_FreeContext(ctx); + } + if (rt) { + JS_FreeRuntime(rt); + } + } + + std::string getEngineName() override { + return "Vult"; + } + + int run(const std::string& path, const std::string& script) override { + display("Loading..."); + + JSValue global_obj = JS_GetGlobalObject(ctx); + + // Put the script text in the 'code' variable + JSValue code = JS_NewString(ctx, script.c_str()); + JS_SetPropertyStr(ctx, global_obj, "code", code); + + // Put the script path in 'file' variable + JSValue file = JS_NewString(ctx, path.c_str()); + JS_SetPropertyStr(ctx, global_obj, "file", file); + + display("Compiling..."); + // Call the Vult compiler to generate Lua code + static const std::string testVult = R"( var result = vult.generateLua([{ file:file, code:code}],{ output:'Engine', template:'vcv-prototype'});)"; - JSValue compile = - JS_Eval(ctx, testVult.c_str(), testVult.size(), "Compile", 0); - - JS_FreeValue(ctx, code); - JS_FreeValue(ctx, file); - - // If there are any internal errors, the execution could fail - if (JS_IsException(compile)) { - display("Fatal error in the Vult compiler"); - JS_FreeValue(ctx, global_obj); - return -1; - } - - // Retrive the variable 'result' - JSValue result = JS_GetPropertyStr(ctx, global_obj, "result"); - // Get the first element of the 'result' array - JSValue first = JS_GetPropertyUint32(ctx, result, 0); - // Try to get the 'msg' field which is only present in error messages - JSValue msg = JS_GetPropertyStr(ctx, first, "msg"); - // Display the error if any - if (!JS_IsUndefined(msg)) { - const char *text = JS_ToCString(ctx, msg); - const char *row = - JS_ToCString(ctx, JS_GetPropertyStr(ctx, first, "line")); - const char *col = JS_ToCString(ctx, JS_GetPropertyStr(ctx, first, "col")); - // Compose the error message - std::stringstream error; - error << "line:" << row << ":" << col << ": " << text; - WARN("Vult Error: %s", error.str().c_str()); - display(error.str().c_str()); - - JS_FreeValue(ctx, result); - JS_FreeValue(ctx, first); - JS_FreeValue(ctx, msg); - return -1; - } - // In case of no error, retrieve the generated code - JSValue luacode = JS_GetPropertyStr(ctx, first, "code"); - std::string luacode_str(JS_ToCString(ctx, luacode)); - - //WARN("Generated Code: %s", luacode_str.c_str()); - - luaEngine = createLuaEngine(); - - if (!luaEngine) { - WARN("Could not create a Lua script engine"); + JSValue compile = + JS_Eval(ctx, testVult.c_str(), testVult.size(), "Compile", 0); + + JS_FreeValue(ctx, code); + JS_FreeValue(ctx, file); + + // If there are any internal errors, the execution could fail + if (JS_IsException(compile)) { + display("Fatal error in the Vult compiler"); + JS_FreeValue(ctx, global_obj); + return -1; + } + + // Retrive the variable 'result' + JSValue result = JS_GetPropertyStr(ctx, global_obj, "result"); + // Get the first element of the 'result' array + JSValue first = JS_GetPropertyUint32(ctx, result, 0); + // Try to get the 'msg' field which is only present in error messages + JSValue msg = JS_GetPropertyStr(ctx, first, "msg"); + // Display the error if any + if (!JS_IsUndefined(msg)) { + const char* text = JS_ToCString(ctx, msg); + const char* row = + JS_ToCString(ctx, JS_GetPropertyStr(ctx, first, "line")); + const char* col = JS_ToCString(ctx, JS_GetPropertyStr(ctx, first, "col")); + // Compose the error message + std::stringstream error; + error << "line:" << row << ":" << col << ": " << text; + WARN("Vult Error: %s", error.str().c_str()); + display(error.str().c_str()); + + JS_FreeValue(ctx, result); + JS_FreeValue(ctx, first); + JS_FreeValue(ctx, msg); + return -1; + } + // In case of no error, retrieve the generated code + JSValue luacode = JS_GetPropertyStr(ctx, first, "code"); + std::string luacode_str(JS_ToCString(ctx, luacode)); + + //WARN("Generated Code: %s", luacode_str.c_str()); + + luaEngine = createLuaEngine(); + + if (!luaEngine) { + WARN("Could not create a Lua script engine"); + return -1; + } + + luaEngine->module = this->module; + + display("Running..."); + + JS_FreeValue(ctx, luacode); + JS_FreeValue(ctx, first); + JS_FreeValue(ctx, msg); + JS_FreeValue(ctx, msg); + JS_FreeValue(ctx, global_obj); + + return luaEngine->run(path, luacode_str); + } + + int process() override { + if (!luaEngine) return -1; - } - - luaEngine->module = this->module; - - display("Running..."); - - JS_FreeValue(ctx, luacode); - JS_FreeValue(ctx, first); - JS_FreeValue(ctx, msg); - JS_FreeValue(ctx, msg); - JS_FreeValue(ctx, global_obj); - - return luaEngine->run(path, luacode_str); - } - - int process() override { - if (luaEngine) - return luaEngine->process(); - else - return 0; - } + return luaEngine->process(); + } }; -__attribute__((constructor(1000))) static void constructor() { - addScriptEngine("vult"); +__attribute__((constructor(1000))) +static void constructor() { + addScriptEngine("vult"); } From 713613f2c66cc0508976c9d285a34ce5f4dc40a9 Mon Sep 17 00:00:00 2001 From: clwe Date: Sun, 28 Jun 2020 22:05:05 +0200 Subject: [PATCH 12/27] implements Makefile build flow --- Makefile | 27 +++++++++- src/LibPDEngine.cpp | 118 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+), 2 deletions(-) create mode 100644 src/LibPDEngine.cpp diff --git a/Makefile b/Makefile index 0c0cc98..56e4eab 100644 --- a/Makefile +++ b/Makefile @@ -14,10 +14,11 @@ DISTRIBUTABLES += $(wildcard LICENSE*) include $(RACK_DIR)/arch.mk DUKTAPE ?= 0 -QUICKJS ?= 1 +QUICKJS ?= 0 LUAJIT ?= 1 PYTHON ?= 0 SUPERCOLLIDER ?= 0 +<<<<<<< HEAD VULT ?= 1 # Vult depends on both LuaJIT and QuickJS @@ -25,6 +26,9 @@ ifeq ($(VULT), 1) QUICKJS := 1 LUAJIT := 1 endif +======= +LIBPD ?= 1 +>>>>>>> implements Makefile build flow # Entropia File System Watcher efsw := dep/lib/libefsw-static-release.a @@ -37,6 +41,25 @@ $(efsw): cd efsw && cp lib/libefsw-static-release.a $(DEP_PATH)/lib/ cd efsw && cp -R include/efsw $(DEP_PATH)/include/ +# LibPD +ifeq ($(LIBPD), 1) +libpd := dep/lib/libpd.a +SOURCES += src/LibPDEngine.cpp +OBJECTS += $(libpd) +DEPS += $(libpd) +FLAGS += -Idep/include/libpd + +$(libpd): + $(WGET) "https://github.com/chairaudio/libpd/archive/master.tar.gz" + #$(SHA256) master.tar.gz f8dd2ea21f295badeae1b2ea8d00a91135b24710e67d437f7f18719d728e6e04 + cd dep && $(UNTAR) ../master.tar.gz + $(WGET) "https://github.com/pure-data/pure-data/archive/0.50-2.tar.gz" + #$(SHA256) 0.51-0.tar.gz 68b13342aaee70b8ef993eef11dc8d6837323dd6ea74a2f0705461d59f3ad2af + cd dep/libpd-master/pure-data && $(UNTAR) ../../../0.50-2.tar.gz --strip-components=1 + cd dep/libpd-master && make MULTI=true + cd dep/libpd-master && $(MAKE) install prefix="$(DEP_PATH)" +endif + # Duktape ifeq ($(DUKTAPE), 1) SOURCES += src/DuktapeEngine.cpp @@ -63,7 +86,7 @@ endif $(quickjs): cd dep && git clone "https://github.com/JerrySievert/QuickJS.git" cd dep/QuickJS && git checkout 807adc8ca9010502853d471bd8331cdc1d376b94 - cd dep/QuickJS && $(MAKE) $(QUICKJS_MAKE_FLAGS) + cd dep/QuickJS && $(MAKE) $(QUICKJS_MAKE_FLAGS) cd dep/QuickJS && $(MAKE) $(QUICKJS_MAKE_FLAGS) install endif diff --git a/src/LibPDEngine.cpp b/src/LibPDEngine.cpp new file mode 100644 index 0000000..7f4ee6e --- /dev/null +++ b/src/LibPDEngine.cpp @@ -0,0 +1,118 @@ +#include "ScriptEngine.hpp" +#include "z_libpd.h" +#include +#include +using namespace std; + +#define BUFFERSIZE 4096 + +void chair_write_patch_to_file(const string &patch, const string &path, const string &name ) +{ + + ofstream myfile; + cout << "file to write: " << path + "/" + name << endl; + myfile.open (path + "/" + name); + myfile << patch; + myfile.close(); +} + +void chair_load_patch(const string &patch, const string &name) +{ + + string path = "."; + chair_write_patch_to_file(patch, path, name); + + libpd_openfile(name.c_str(), path.c_str()); + + remove( (path + "/" + name).c_str() ); +} + + +struct LibPDEngine : ScriptEngine { + + ~LibPDEngine() { + } + // // variables for libpd + t_pdinstance *_lpd; + int _sampleRate = 0; + int _ticks = 0; + float _output[BUFFERSIZE]; + float _input[BUFFERSIZE];// = (float*)malloc(1024*2*sizeof(float)); + // end variables for libpd + + + std::string getEngineName() override { + return "Pure Data"; + } + + int run(const std::string& path, const std::string& script) override { + + ProcessBlock* block = getProcessBlock(); + + _sampleRate = block->sampleRate; + + libpd_init(); + _lpd = libpd_new_instance(); + + libpd_set_instance(_lpd); + libpd_init_audio(2, 2, _sampleRate); + //cout << "_lpd is initialized" << endl; + + //cout << "num od pd instances: " << libpd_num_instances() << endl; + + // compute audio [; pd dsp 1( + libpd_start_message(1); // one entry in list + libpd_add_float(1.0f); + libpd_finish_message("pd", "dsp"); + + std::string name = "test.pd"; + std::string patch = "#N canvas 333 425 105 153 10;\n" + "#X obj 32 79 dac~;\n" + "#X obj 32 27 adc~;\n" + "#X connect 1 0 0 0;\n" + "#X connect 1 1 0 1;"; + + //libpd_openfile(patch.c_str(), path.c_str()); + + chair_load_patch(patch, name); + + return 0; + } + + int process() override { + // block + ProcessBlock* block = getProcessBlock(); + int curr_bufSize = 256; + block->bufferSize = curr_bufSize; + display(std::to_string(curr_bufSize)); + + const int nChans = 2; + + // pass samples to/from libpd + _ticks = curr_bufSize / 64; + for (int s = 0; s < curr_bufSize; s++) { + for (int c = 0; c < nChans; c++) { + _input[s*nChans+c] = block->inputs[c][s]; + } + } + + libpd_set_instance(_lpd); + libpd_process_float(_ticks, _input, _output); + + for (int s = 0; s < curr_bufSize; s++) { + for (int c = 0; c < nChans; c++) { + block->outputs[c][s] = _output[s*nChans+c]; + } + } + + return 0; + } + + +}; + + +__attribute__((constructor(1000))) +static void constructor() { + addScriptEngine("pd"); +} From 3dadb3f3c10db11161c7e762c2b6eaac798f6b17 Mon Sep 17 00:00:00 2001 From: clwe Date: Sun, 28 Jun 2020 23:25:59 +0200 Subject: [PATCH 13/27] adds 6 in/out audio through pd patch, sets buffer size to 64 samples and sets frame divider to 1 --- examples/audio-trough.pd | 9 +++++++ src/LibPDEngine.cpp | 51 ++++++++++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 examples/audio-trough.pd diff --git a/examples/audio-trough.pd b/examples/audio-trough.pd new file mode 100644 index 0000000..529bd3e --- /dev/null +++ b/examples/audio-trough.pd @@ -0,0 +1,9 @@ +#N canvas 653 457 450 300 12; +#X obj 151 125 adc~ 1 2 3 4 5 6; +#X obj 152 184 dac~ 1 2 3 4 5 6; +#X connect 0 0 1 0; +#X connect 0 1 1 1; +#X connect 0 2 1 2; +#X connect 0 3 1 3; +#X connect 0 4 1 4; +#X connect 0 5 1 5; diff --git a/src/LibPDEngine.cpp b/src/LibPDEngine.cpp index 7f4ee6e..b04fae3 100644 --- a/src/LibPDEngine.cpp +++ b/src/LibPDEngine.cpp @@ -4,7 +4,7 @@ #include using namespace std; -#define BUFFERSIZE 4096 +#define BUFFERSIZE MAX_BUFFER_SIZE * NUM_ROWS void chair_write_patch_to_file(const string &patch, const string &path, const string &name ) { @@ -34,6 +34,7 @@ struct LibPDEngine : ScriptEngine { } // // variables for libpd t_pdinstance *_lpd; + int _pd_block_size = 64; int _sampleRate = 0; int _ticks = 0; float _output[BUFFERSIZE]; @@ -50,27 +51,43 @@ struct LibPDEngine : ScriptEngine { ProcessBlock* block = getProcessBlock(); _sampleRate = block->sampleRate; - + + setBufferSize(_pd_block_size); + setFrameDivider(1); libpd_init(); _lpd = libpd_new_instance(); libpd_set_instance(_lpd); - libpd_init_audio(2, 2, _sampleRate); + libpd_init_audio(NUM_ROWS, NUM_ROWS, _sampleRate); //cout << "_lpd is initialized" << endl; //cout << "num od pd instances: " << libpd_num_instances() << endl; // compute audio [; pd dsp 1( - libpd_start_message(1); // one entry in list + libpd_start_message(1); // one enstry in list libpd_add_float(1.0f); libpd_finish_message("pd", "dsp"); std::string name = "test.pd"; - std::string patch = "#N canvas 333 425 105 153 10;\n" + std::string patch = "#N canvas 653 457 450 300 12;\n" + "#X obj 151 125 adc~ 1 2 3 4 5 6;\n" + "#X obj 152 184 dac~ 1 2 3 4 5 6;\n" + "#X connect 0 0 1 0;\n" + "#X connect 0 1 1 1;\n" + "#X connect 0 2 1 2;\n" + "#X connect 0 3 1 3;\n" + "#X connect 0 4 1 4;\n" + "#X connect 0 5 1 5;"; + + + + + + /*"#N canvas 333 425 105 153 10;\n" "#X obj 32 79 dac~;\n" "#X obj 32 27 adc~;\n" "#X connect 1 0 0 0;\n" - "#X connect 1 1 0 1;"; + "#X connect 1 1 0 1;";*/ //libpd_openfile(patch.c_str(), path.c_str()); @@ -82,26 +99,24 @@ struct LibPDEngine : ScriptEngine { int process() override { // block ProcessBlock* block = getProcessBlock(); - int curr_bufSize = 256; - block->bufferSize = curr_bufSize; - display(std::to_string(curr_bufSize)); - const int nChans = 2; - + display(std::to_string(block->bufferSize)); + // pass samples to/from libpd - _ticks = curr_bufSize / 64; - for (int s = 0; s < curr_bufSize; s++) { - for (int c = 0; c < nChans; c++) { - _input[s*nChans+c] = block->inputs[c][s]; + _ticks = 1;//curr_bufSize / 64; + int rows = NUM_ROWS; + for (int s = 0; s < _pd_block_size; s++) { + for (int r = 0; r < rows; r++) { + _input[s*rows+r] = block->inputs[r][s]; } } libpd_set_instance(_lpd); libpd_process_float(_ticks, _input, _output); - for (int s = 0; s < curr_bufSize; s++) { - for (int c = 0; c < nChans; c++) { - block->outputs[c][s] = _output[s*nChans+c]; + for (int s = 0; s < _pd_block_size; s++) { + for (int r = 0; r < rows; r++) { + block->outputs[r][s] = _output[s*rows+r]; } } From dcad136882eef12f9aab04eb7162d45be8a02128 Mon Sep 17 00:00:00 2001 From: clwe Date: Tue, 30 Jun 2020 23:36:10 +0200 Subject: [PATCH 14/27] PD: revert to PD v.0.50-2, implements knob send, lights receive and audio through, displays multi instance warning --- examples/audio-trough.pd | 61 ++++++++++-- src/LibPDEngine.cpp | 195 +++++++++++++++++++++++++++------------ 2 files changed, 187 insertions(+), 69 deletions(-) diff --git a/examples/audio-trough.pd b/examples/audio-trough.pd index 529bd3e..29ce98b 100644 --- a/examples/audio-trough.pd +++ b/examples/audio-trough.pd @@ -1,9 +1,52 @@ -#N canvas 653 457 450 300 12; -#X obj 151 125 adc~ 1 2 3 4 5 6; -#X obj 152 184 dac~ 1 2 3 4 5 6; -#X connect 0 0 1 0; -#X connect 0 1 1 1; -#X connect 0 2 1 2; -#X connect 0 3 1 3; -#X connect 0 4 1 4; -#X connect 0 5 1 5; +#N canvas 2220 331 802 519 12; +#X obj 112 43 adc~ 1 2 3 4 5 6, f 47; +#X obj 113 199 dac~ 1 2 3 4 5 6, f 47; +#X obj 112 127 *~ 1; +#X obj 137 94 r K1; +#X obj 178 126 *~ 1; +#X obj 242 128 *~ 1; +#X obj 308 127 *~ 1; +#X obj 372 127 *~ 1; +#X obj 438 126 *~ 1; +#X obj 203 93 r K2; +#X obj 267 93 r K3; +#X obj 333 94 r K4; +#X obj 397 93 r K5; +#X obj 463 93 r K6; +#X obj 290 416 print toVCV; +#X msg 267 278 L3 \$1 0 0; +#X msg 333 310 L4 \$1 0 0; +#X msg 463 311 L6 \$1 0 0; +#X msg 136 277 L1 \$1 0 0; +#X msg 203 309 L2 \$1 0 0; +#X msg 397 280 L5 \$1 0 0; +#X connect 0 0 2 0; +#X connect 0 1 4 0; +#X connect 0 2 5 0; +#X connect 0 3 6 0; +#X connect 0 4 7 0; +#X connect 0 5 8 0; +#X connect 2 0 1 0; +#X connect 3 0 2 1; +#X connect 3 0 18 0; +#X connect 4 0 1 1; +#X connect 5 0 1 2; +#X connect 6 0 1 3; +#X connect 7 0 1 4; +#X connect 8 0 1 5; +#X connect 9 0 4 1; +#X connect 9 0 19 0; +#X connect 10 0 5 1; +#X connect 10 0 15 0; +#X connect 11 0 6 1; +#X connect 11 0 16 0; +#X connect 12 0 7 1; +#X connect 12 0 20 0; +#X connect 13 0 8 1; +#X connect 13 0 17 0; +#X connect 15 0 14 0; +#X connect 16 0 14 0; +#X connect 17 0 14 0; +#X connect 18 0 14 0; +#X connect 19 0 14 0; +#X connect 20 0 14 0; diff --git a/src/LibPDEngine.cpp b/src/LibPDEngine.cpp index b04fae3..212a37a 100644 --- a/src/LibPDEngine.cpp +++ b/src/LibPDEngine.cpp @@ -1,45 +1,54 @@ #include "ScriptEngine.hpp" #include "z_libpd.h" -#include -#include -using namespace std; +#include "util/z_print_util.h" +using namespace rack; #define BUFFERSIZE MAX_BUFFER_SIZE * NUM_ROWS -void chair_write_patch_to_file(const string &patch, const string &path, const string &name ) -{ - - ofstream myfile; - cout << "file to write: " << path + "/" + name << endl; - myfile.open (path + "/" + name); - myfile << patch; - myfile.close(); -} -void chair_load_patch(const string &patch, const string &name) -{ +// there is no multi-instance support for receiving messages from libpd +// for now, received values for the prototype gui will be stored in global variables + +float g_leds[NUM_ROWS][3]; + +std::vector split (const std::string &s, char delim) { + std::vector result; + std::stringstream ss (s); + std::string item; - string path = "."; - chair_write_patch_to_file(patch, path, name); - - libpd_openfile(name.c_str(), path.c_str()); - - remove( (path + "/" + name).c_str() ); + while (getline (ss, item, delim)) { + result.push_back (item); + } + + return result; } + + struct LibPDEngine : ScriptEngine { ~LibPDEngine() { + libpd_free_instance(_lpd); + } - // // variables for libpd + + static void receiveLEDs(const char *s); + + bool knobChanged(const float* knobs, int idx); + + bool switchChanged(const float* knobs, int idx); + t_pdinstance *_lpd; int _pd_block_size = 64; int _sampleRate = 0; int _ticks = 0; + + float _old_knobs[NUM_ROWS]; + bool _old_switches[NUM_ROWS]; float _output[BUFFERSIZE]; float _input[BUFFERSIZE];// = (float*)malloc(1024*2*sizeof(float)); - // end variables for libpd + const static std::map _led_map; std::string getEngineName() override { @@ -49,49 +58,37 @@ struct LibPDEngine : ScriptEngine { int run(const std::string& path, const std::string& script) override { ProcessBlock* block = getProcessBlock(); - _sampleRate = block->sampleRate; - setBufferSize(_pd_block_size); setFrameDivider(1); libpd_init(); _lpd = libpd_new_instance(); - libpd_set_instance(_lpd); + libpd_set_printhook((t_libpd_printhook)libpd_print_concatenator); + libpd_set_concatenated_printhook( receiveLEDs ); + //libpd_set_printhook(receiveLEDs); + //libpd_bind("L2"); + //libpd_bind("foo"); + //libpd_set_listhook(receiveList); + //libpd_set_messagehook(receiveMessage); + + if(libpd_num_instances()>2) + { + display("Sorry, multi instance support in libpd is under development!"); + return -1; + } + + //display(std::to_string(libpd_num_instances())); libpd_init_audio(NUM_ROWS, NUM_ROWS, _sampleRate); - //cout << "_lpd is initialized" << endl; - - //cout << "num od pd instances: " << libpd_num_instances() << endl; - - // compute audio [; pd dsp 1( + + // compute audio [; pd dsp 1( libpd_start_message(1); // one enstry in list libpd_add_float(1.0f); libpd_finish_message("pd", "dsp"); - std::string name = "test.pd"; - std::string patch = "#N canvas 653 457 450 300 12;\n" - "#X obj 151 125 adc~ 1 2 3 4 5 6;\n" - "#X obj 152 184 dac~ 1 2 3 4 5 6;\n" - "#X connect 0 0 1 0;\n" - "#X connect 0 1 1 1;\n" - "#X connect 0 2 1 2;\n" - "#X connect 0 3 1 3;\n" - "#X connect 0 4 1 4;\n" - "#X connect 0 5 1 5;"; - - - - - - /*"#N canvas 333 425 105 153 10;\n" - "#X obj 32 79 dac~;\n" - "#X obj 32 27 adc~;\n" - "#X connect 1 0 0 0;\n" - "#X connect 1 1 0 1;";*/ - - //libpd_openfile(patch.c_str(), path.c_str()); - - chair_load_patch(patch, name); + std::string name = string::filename(path); + std::string dir = string::directory(path); + libpd_openfile(name.c_str(), dir.c_str()); return 0; } @@ -100,10 +97,7 @@ struct LibPDEngine : ScriptEngine { // block ProcessBlock* block = getProcessBlock(); - display(std::to_string(block->bufferSize)); - - // pass samples to/from libpd - _ticks = 1;//curr_bufSize / 64; + // get samples prototype int rows = NUM_ROWS; for (int s = 0; s < _pd_block_size; s++) { for (int r = 0; r < rows; r++) { @@ -112,8 +106,33 @@ struct LibPDEngine : ScriptEngine { } libpd_set_instance(_lpd); + + // knobs + for (int i=0; iknobs, i) ){ + std::string knob = "K"+std::to_string(i+1); + libpd_float(knob.c_str(), block->knobs[i]); + } + } + // leds + //display(std::to_string(g_leds[0])); + for(int i=0; ilights[i][0] = g_leds[i][0]; + block->lights[i][1] = g_leds[i][1]; + block->lights[i][2] = g_leds[i][2]; + } + // switches + for(int i=0; iswitches, i) ){ + std::string sw = "S"+std::to_string(i+1); + libpd_float(sw.c_str(), block->switches[i]); + } + } + // process samples in libpd + _ticks = 1; libpd_process_float(_ticks, _input, _output); + //return samples to prototype for (int s = 0; s < _pd_block_size; s++) { for (int r = 0; r < rows; r++) { block->outputs[r][s] = _output[s*rows+r]; @@ -122,8 +141,6 @@ struct LibPDEngine : ScriptEngine { return 0; } - - }; @@ -131,3 +148,61 @@ __attribute__((constructor(1000))) static void constructor() { addScriptEngine("pd"); } + + +void LibPDEngine::receiveLEDs(const char *s) { + std::string str = std::string(s); + std::vector atoms = split (str, ' '); + + if(atoms[0]=="toVCV:"){ + // led list + bool led_is_valid = true; + int led_idx = -1; + try { + led_idx = _led_map.at(atoms[1]); // map::at throws an out-of-range + } + catch (const std::out_of_range& oor) { + led_is_valid = false; + //display("Warning:"+atoms[1]+" not found!"); + } + //std::cout << v[1] << ", " << g_led_map[v[1]] << std::endl; + if(led_is_valid && atoms.size()==5){ + g_leds[led_idx][0] = stof(atoms[2]); // red + g_leds[led_idx][1] = stof(atoms[3]); // green + g_leds[led_idx][2] = stof(atoms[4]); // blue + } + else { + + } + } + else { + // do nothing + } +} + +bool LibPDEngine::knobChanged(const float* knobs, int i){ + bool knob_changed = false; + if (_old_knobs[i] != knobs[i]){ + knob_changed = true; + _old_knobs[i] = knobs[i]; + } + return knob_changed; +} + +bool LibPDEngine::switchChanged(const float* switches, int i){ + bool switch_changed = false; + if (_old_switches[i] != switches[i]){ + switch_changed = true; + _old_switches[i] = switches[i]; + } + return switch_changed; +} + +const std::map LibPDEngine::_led_map{ + { "L1", 0 }, + { "L2", 1 }, + { "L3", 2 }, + { "L4", 3 }, + { "L5", 4 }, + { "L6", 5 } +}; \ No newline at end of file From b5816de8bd1a6348f3c26a08fec9b9784d6864a0 Mon Sep 17 00:00:00 2001 From: clwe Date: Wed, 1 Jul 2020 00:36:56 +0200 Subject: [PATCH 15/27] PD: adds switch send, switch lights receive, adds examples/gain.pd, initializes patch with sending messages --- examples/audio-trough.pd | 52 ---------------- examples/gain.pd | 106 +++++++++++++++++++++++++++++++ src/LibPDEngine.cpp | 131 +++++++++++++++++++++++++++------------ 3 files changed, 196 insertions(+), 93 deletions(-) delete mode 100644 examples/audio-trough.pd create mode 100644 examples/gain.pd diff --git a/examples/audio-trough.pd b/examples/audio-trough.pd deleted file mode 100644 index 29ce98b..0000000 --- a/examples/audio-trough.pd +++ /dev/null @@ -1,52 +0,0 @@ -#N canvas 2220 331 802 519 12; -#X obj 112 43 adc~ 1 2 3 4 5 6, f 47; -#X obj 113 199 dac~ 1 2 3 4 5 6, f 47; -#X obj 112 127 *~ 1; -#X obj 137 94 r K1; -#X obj 178 126 *~ 1; -#X obj 242 128 *~ 1; -#X obj 308 127 *~ 1; -#X obj 372 127 *~ 1; -#X obj 438 126 *~ 1; -#X obj 203 93 r K2; -#X obj 267 93 r K3; -#X obj 333 94 r K4; -#X obj 397 93 r K5; -#X obj 463 93 r K6; -#X obj 290 416 print toVCV; -#X msg 267 278 L3 \$1 0 0; -#X msg 333 310 L4 \$1 0 0; -#X msg 463 311 L6 \$1 0 0; -#X msg 136 277 L1 \$1 0 0; -#X msg 203 309 L2 \$1 0 0; -#X msg 397 280 L5 \$1 0 0; -#X connect 0 0 2 0; -#X connect 0 1 4 0; -#X connect 0 2 5 0; -#X connect 0 3 6 0; -#X connect 0 4 7 0; -#X connect 0 5 8 0; -#X connect 2 0 1 0; -#X connect 3 0 2 1; -#X connect 3 0 18 0; -#X connect 4 0 1 1; -#X connect 5 0 1 2; -#X connect 6 0 1 3; -#X connect 7 0 1 4; -#X connect 8 0 1 5; -#X connect 9 0 4 1; -#X connect 9 0 19 0; -#X connect 10 0 5 1; -#X connect 10 0 15 0; -#X connect 11 0 6 1; -#X connect 11 0 16 0; -#X connect 12 0 7 1; -#X connect 12 0 20 0; -#X connect 13 0 8 1; -#X connect 13 0 17 0; -#X connect 15 0 14 0; -#X connect 16 0 14 0; -#X connect 17 0 14 0; -#X connect 18 0 14 0; -#X connect 19 0 14 0; -#X connect 20 0 14 0; diff --git a/examples/gain.pd b/examples/gain.pd new file mode 100644 index 0000000..ab6906d --- /dev/null +++ b/examples/gain.pd @@ -0,0 +1,106 @@ +#N canvas 2220 331 805 580 12; +#X obj 112 43 adc~ 1 2 3 4 5 6, f 47; +#X obj 113 281 dac~ 1 2 3 4 5 6, f 47; +#X obj 112 127 *~ 1; +#X obj 137 94 r K1; +#X obj 178 126 *~ 1; +#X obj 242 128 *~ 1; +#X obj 308 127 *~ 1; +#X obj 372 127 *~ 1; +#X obj 438 126 *~ 1; +#X obj 203 93 r K2; +#X obj 267 93 r K3; +#X obj 333 94 r K4; +#X obj 397 93 r K5; +#X obj 463 93 r K6; +#X obj 290 502 print toVCV; +#X msg 267 315 L3 \$1 0 0; +#X msg 333 347 L4 \$1 0 0; +#X msg 463 348 L6 \$1 0 0; +#X msg 136 314 L1 \$1 0 0; +#X msg 203 346 L2 \$1 0 0; +#X msg 397 317 L5 \$1 0 0; +#X obj 112 230 *~ 1; +#X obj 178 229 *~ 1; +#X obj 242 231 *~ 1; +#X obj 308 230 *~ 1; +#X obj 372 230 *~ 1; +#X obj 438 229 *~ 1; +#X obj 147 158 r S1; +#X obj 213 157 r S2; +#X obj 277 157 r S3; +#X obj 343 158 r S4; +#X obj 407 157 r S5; +#X obj 473 158 r S6; +#X obj 473 197 - 1; +#X obj 407 196 - 1; +#X obj 343 194 - 1; +#X obj 277 195 - 1; +#X obj 213 196 - 1; +#X obj 147 195 - 1; +#X msg 146 404 S1 \$1 0 0; +#X msg 213 436 S2 \$1 0 0; +#X msg 277 405 S3 \$1 0 0; +#X msg 343 438 S4 \$1 0 0; +#X msg 407 407 S5 \$1 0 0; +#X msg 473 437 S6 \$1 0 0; +#X connect 0 0 2 0; +#X connect 0 1 4 0; +#X connect 0 2 5 0; +#X connect 0 3 6 0; +#X connect 0 4 7 0; +#X connect 0 5 8 0; +#X connect 2 0 21 0; +#X connect 3 0 2 1; +#X connect 3 0 18 0; +#X connect 4 0 22 0; +#X connect 5 0 23 0; +#X connect 6 0 24 0; +#X connect 7 0 25 0; +#X connect 8 0 26 0; +#X connect 9 0 4 1; +#X connect 9 0 19 0; +#X connect 10 0 5 1; +#X connect 10 0 15 0; +#X connect 11 0 6 1; +#X connect 11 0 16 0; +#X connect 12 0 7 1; +#X connect 12 0 20 0; +#X connect 13 0 8 1; +#X connect 13 0 17 0; +#X connect 15 0 14 0; +#X connect 16 0 14 0; +#X connect 17 0 14 0; +#X connect 18 0 14 0; +#X connect 19 0 14 0; +#X connect 20 0 14 0; +#X connect 21 0 1 0; +#X connect 22 0 1 1; +#X connect 23 0 1 2; +#X connect 24 0 1 3; +#X connect 25 0 1 4; +#X connect 26 0 1 5; +#X connect 27 0 38 0; +#X connect 27 0 39 0; +#X connect 28 0 37 0; +#X connect 28 0 40 0; +#X connect 29 0 36 0; +#X connect 29 0 41 0; +#X connect 30 0 35 0; +#X connect 30 0 42 0; +#X connect 31 0 34 0; +#X connect 31 0 43 0; +#X connect 32 0 33 0; +#X connect 32 0 44 0; +#X connect 33 0 26 1; +#X connect 34 0 25 1; +#X connect 35 0 24 1; +#X connect 36 0 23 1; +#X connect 37 0 22 1; +#X connect 38 0 21 1; +#X connect 39 0 14 0; +#X connect 40 0 14 0; +#X connect 41 0 14 0; +#X connect 42 0 14 0; +#X connect 43 0 14 0; +#X connect 44 0 14 0; diff --git a/src/LibPDEngine.cpp b/src/LibPDEngine.cpp index 212a37a..ec06e9b 100644 --- a/src/LibPDEngine.cpp +++ b/src/LibPDEngine.cpp @@ -9,7 +9,8 @@ using namespace rack; // there is no multi-instance support for receiving messages from libpd // for now, received values for the prototype gui will be stored in global variables -float g_leds[NUM_ROWS][3]; +float g_lights[NUM_ROWS][3] = {}; +float g_switchLights[NUM_ROWS][3] = {}; std::vector split (const std::string &s, char delim) { std::vector result; @@ -25,7 +26,6 @@ std::vector split (const std::string &s, char delim) { - struct LibPDEngine : ScriptEngine { ~LibPDEngine() { @@ -33,23 +33,25 @@ struct LibPDEngine : ScriptEngine { } - static void receiveLEDs(const char *s); - + void sendInitialStates(const ProcessBlock* block); + static void receiveLights(const char *s); bool knobChanged(const float* knobs, int idx); - - bool switchChanged(const float* knobs, int idx); + bool switchChanged(const bool* knobs, int idx); + void sendKnob(const int idx, const float value); + void sendSwitch(const int idx, const bool value); t_pdinstance *_lpd; int _pd_block_size = 64; int _sampleRate = 0; int _ticks = 0; + bool _init = true; - float _old_knobs[NUM_ROWS]; - bool _old_switches[NUM_ROWS]; - float _output[BUFFERSIZE]; - float _input[BUFFERSIZE];// = (float*)malloc(1024*2*sizeof(float)); - const static std::map _led_map; - + float _old_knobs[NUM_ROWS] = {}; + bool _old_switches[NUM_ROWS] = {}; + float _output[BUFFERSIZE] = {}; + float _input[BUFFERSIZE] = {};// = (float*)malloc(1024*2*sizeof(float)); + const static std::map _light_map; + const static std::map _switchLight_map; std::string getEngineName() override { return "Pure Data"; @@ -65,12 +67,8 @@ struct LibPDEngine : ScriptEngine { _lpd = libpd_new_instance(); libpd_set_printhook((t_libpd_printhook)libpd_print_concatenator); - libpd_set_concatenated_printhook( receiveLEDs ); - //libpd_set_printhook(receiveLEDs); - //libpd_bind("L2"); - //libpd_bind("foo"); - //libpd_set_listhook(receiveList); - //libpd_set_messagehook(receiveMessage); + libpd_set_concatenated_printhook( receiveLights ); + if(libpd_num_instances()>2) { @@ -89,6 +87,8 @@ struct LibPDEngine : ScriptEngine { std::string name = string::filename(path); std::string dir = string::directory(path); libpd_openfile(name.c_str(), dir.c_str()); + + sendInitialStates(block); return 0; } @@ -110,22 +110,25 @@ struct LibPDEngine : ScriptEngine { // knobs for (int i=0; iknobs, i) ){ - std::string knob = "K"+std::to_string(i+1); - libpd_float(knob.c_str(), block->knobs[i]); + sendKnob(i, block->knobs[i]); } } - // leds - //display(std::to_string(g_leds[0])); + // lights + for(int i=0; ilights[i][0] = g_lights[i][0]; + block->lights[i][1] = g_lights[i][1]; + block->lights[i][2] = g_lights[i][2]; + } + // switch lights for(int i=0; ilights[i][0] = g_leds[i][0]; - block->lights[i][1] = g_leds[i][1]; - block->lights[i][2] = g_leds[i][2]; + block->switchLights[i][0] = g_switchLights[i][0]; + block->switchLights[i][1] = g_switchLights[i][1]; + block->switchLights[i][2] = g_switchLights[i][2]; } // switches for(int i=0; iswitches, i) ){ - std::string sw = "S"+std::to_string(i+1); - libpd_float(sw.c_str(), block->switches[i]); + sendSwitch(i, block->switches[i]); } } // process samples in libpd @@ -150,29 +153,48 @@ static void constructor() { } -void LibPDEngine::receiveLEDs(const char *s) { +void LibPDEngine::receiveLights(const char *s) { std::string str = std::string(s); std::vector atoms = split (str, ' '); if(atoms[0]=="toVCV:"){ - // led list - bool led_is_valid = true; - int led_idx = -1; + // light list + bool light_is_valid = true; + int light_idx = -1; try { - led_idx = _led_map.at(atoms[1]); // map::at throws an out-of-range + light_idx = _light_map.at(atoms[1]); // map::at throws an out-of-range } catch (const std::out_of_range& oor) { - led_is_valid = false; + light_is_valid = false; //display("Warning:"+atoms[1]+" not found!"); } //std::cout << v[1] << ", " << g_led_map[v[1]] << std::endl; - if(led_is_valid && atoms.size()==5){ - g_leds[led_idx][0] = stof(atoms[2]); // red - g_leds[led_idx][1] = stof(atoms[3]); // green - g_leds[led_idx][2] = stof(atoms[4]); // blue + if(light_is_valid && atoms.size()==5){ + g_lights[light_idx][0] = stof(atoms[2]); // red + g_lights[light_idx][1] = stof(atoms[3]); // green + g_lights[light_idx][2] = stof(atoms[4]); // blue } else { - + // error + } + + bool switchLight_is_valid = true; + int switchLight_idx = -1; + try { + switchLight_idx = _switchLight_map.at(atoms[1]); // map::at throws an out-of-range + } + catch (const std::out_of_range& oor) { + switchLight_is_valid = false; + //display("Warning:"+atoms[1]+" not found!"); + } + //std::cout << v[1] << ", " << g_led_map[v[1]] << std::endl; + if(switchLight_is_valid && atoms.size()==5){ + g_switchLights[switchLight_idx][0] = stof(atoms[2]); // red + g_switchLights[switchLight_idx][1] = stof(atoms[3]); // green + g_switchLights[switchLight_idx][2] = stof(atoms[4]); // blue + } + else { + // error } } else { @@ -189,7 +211,7 @@ bool LibPDEngine::knobChanged(const float* knobs, int i){ return knob_changed; } -bool LibPDEngine::switchChanged(const float* switches, int i){ +bool LibPDEngine::switchChanged(const bool* switches, int i){ bool switch_changed = false; if (_old_switches[i] != switches[i]){ switch_changed = true; @@ -198,11 +220,38 @@ bool LibPDEngine::switchChanged(const float* switches, int i){ return switch_changed; } -const std::map LibPDEngine::_led_map{ +const std::map LibPDEngine::_light_map{ { "L1", 0 }, { "L2", 1 }, { "L3", 2 }, { "L4", 3 }, { "L5", 4 }, { "L6", 5 } -}; \ No newline at end of file +}; + +const std::map LibPDEngine::_switchLight_map{ + { "S1", 0 }, + { "S2", 1 }, + { "S3", 2 }, + { "S4", 3 }, + { "S5", 4 }, + { "S6", 5 } +}; + +void LibPDEngine::sendKnob(const int idx, const float value){ + std::string knob = "K"+std::to_string(idx+1); + libpd_float(knob.c_str(), value); +} + +void LibPDEngine::sendSwitch(const int idx, const bool value){ + std::string sw = "S"+std::to_string(idx+1); + libpd_float(sw.c_str(), value); +} + +void LibPDEngine::sendInitialStates(const ProcessBlock* block){ + // knobs + for (int i=0; iknobs[i]); + sendSwitch(i, block->knobs[i]); + } +} \ No newline at end of file From d439edd9755eb42d85917b5666487c3640dd3206 Mon Sep 17 00:00:00 2001 From: clwe Date: Wed, 1 Jul 2020 15:35:06 +0200 Subject: [PATCH 16/27] PD: implements display from pd patch and changes message sending method to lists --- examples/gain.pd | 210 ++++++++++++++++++++++---------------------- src/LibPDEngine.cpp | 52 +++++++++-- 2 files changed, 153 insertions(+), 109 deletions(-) diff --git a/examples/gain.pd b/examples/gain.pd index ab6906d..8d3b097 100644 --- a/examples/gain.pd +++ b/examples/gain.pd @@ -1,106 +1,108 @@ -#N canvas 2220 331 805 580 12; -#X obj 112 43 adc~ 1 2 3 4 5 6, f 47; -#X obj 113 281 dac~ 1 2 3 4 5 6, f 47; -#X obj 112 127 *~ 1; -#X obj 137 94 r K1; -#X obj 178 126 *~ 1; -#X obj 242 128 *~ 1; -#X obj 308 127 *~ 1; -#X obj 372 127 *~ 1; -#X obj 438 126 *~ 1; -#X obj 203 93 r K2; -#X obj 267 93 r K3; -#X obj 333 94 r K4; -#X obj 397 93 r K5; -#X obj 463 93 r K6; -#X obj 290 502 print toVCV; -#X msg 267 315 L3 \$1 0 0; -#X msg 333 347 L4 \$1 0 0; -#X msg 463 348 L6 \$1 0 0; -#X msg 136 314 L1 \$1 0 0; -#X msg 203 346 L2 \$1 0 0; -#X msg 397 317 L5 \$1 0 0; -#X obj 112 230 *~ 1; -#X obj 178 229 *~ 1; -#X obj 242 231 *~ 1; -#X obj 308 230 *~ 1; -#X obj 372 230 *~ 1; -#X obj 438 229 *~ 1; -#X obj 147 158 r S1; -#X obj 213 157 r S2; -#X obj 277 157 r S3; -#X obj 343 158 r S4; -#X obj 407 157 r S5; -#X obj 473 158 r S6; -#X obj 473 197 - 1; -#X obj 407 196 - 1; -#X obj 343 194 - 1; -#X obj 277 195 - 1; -#X obj 213 196 - 1; -#X obj 147 195 - 1; -#X msg 146 404 S1 \$1 0 0; -#X msg 213 436 S2 \$1 0 0; -#X msg 277 405 S3 \$1 0 0; -#X msg 343 438 S4 \$1 0 0; -#X msg 407 407 S5 \$1 0 0; -#X msg 473 437 S6 \$1 0 0; +#N canvas 1187 297 729 742 12; +#X obj 153 257 adc~ 1 2 3 4 5 6, f 47; +#X obj 153 427 dac~ 1 2 3 4 5 6, f 47; +#X obj 154 297 *~ 1; +#X obj 218 296 *~ 1; +#X obj 282 298 *~ 1; +#X obj 348 297 *~ 1; +#X obj 412 297 *~ 1; +#X obj 478 296 *~ 1; +#X obj 330 663 print toVCV; +#X msg 307 476 L3 \$1 0 0; +#X msg 373 508 L4 \$1 0 0; +#X msg 503 509 L6 \$1 0 0; +#X msg 176 475 L1 \$1 0 0; +#X msg 243 507 L2 \$1 0 0; +#X msg 437 478 L5 \$1 0 0; +#X obj 154 376 *~ 1; +#X obj 218 375 *~ 1; +#X obj 282 377 *~ 1; +#X obj 348 376 *~ 1; +#X obj 412 376 *~ 1; +#X obj 478 375 *~ 1; +#X msg 186 565 S1 \$1 0 0; +#X msg 253 597 S2 \$1 0 0; +#X msg 317 566 S3 \$1 0 0; +#X msg 383 599 S4 \$1 0 0; +#X msg 447 568 S5 \$1 0 0; +#X msg 513 598 S6 \$1 0 0; +#X obj 179 104 r fromVCV; +#X obj 179 143 route K1 K2 K3 K4 K5 K6, f 56; +#X obj 188 198 route S1 S2 S3 S4 S5 S6, f 56; +#X obj 187 341 == 0; +#X obj 253 342 == 0; +#X obj 317 341 == 0; +#X obj 383 340 == 0; +#X obj 447 342 == 0; +#X obj 513 343 == 0; +#X msg 89 622 display \$1 \$2; +#X obj 80 582 pack f f; +#X obj 107 526 t b f; #X connect 0 0 2 0; -#X connect 0 1 4 0; -#X connect 0 2 5 0; -#X connect 0 3 6 0; -#X connect 0 4 7 0; -#X connect 0 5 8 0; -#X connect 2 0 21 0; -#X connect 3 0 2 1; -#X connect 3 0 18 0; -#X connect 4 0 22 0; -#X connect 5 0 23 0; -#X connect 6 0 24 0; -#X connect 7 0 25 0; -#X connect 8 0 26 0; -#X connect 9 0 4 1; -#X connect 9 0 19 0; -#X connect 10 0 5 1; -#X connect 10 0 15 0; -#X connect 11 0 6 1; -#X connect 11 0 16 0; -#X connect 12 0 7 1; -#X connect 12 0 20 0; -#X connect 13 0 8 1; -#X connect 13 0 17 0; -#X connect 15 0 14 0; -#X connect 16 0 14 0; -#X connect 17 0 14 0; -#X connect 18 0 14 0; -#X connect 19 0 14 0; -#X connect 20 0 14 0; -#X connect 21 0 1 0; -#X connect 22 0 1 1; -#X connect 23 0 1 2; -#X connect 24 0 1 3; -#X connect 25 0 1 4; -#X connect 26 0 1 5; -#X connect 27 0 38 0; -#X connect 27 0 39 0; +#X connect 0 1 3 0; +#X connect 0 2 4 0; +#X connect 0 3 5 0; +#X connect 0 4 6 0; +#X connect 0 5 7 0; +#X connect 2 0 15 0; +#X connect 3 0 16 0; +#X connect 4 0 17 0; +#X connect 5 0 18 0; +#X connect 6 0 19 0; +#X connect 7 0 20 0; +#X connect 9 0 8 0; +#X connect 10 0 8 0; +#X connect 11 0 8 0; +#X connect 12 0 8 0; +#X connect 13 0 8 0; +#X connect 14 0 8 0; +#X connect 15 0 1 0; +#X connect 16 0 1 1; +#X connect 17 0 1 2; +#X connect 18 0 1 3; +#X connect 19 0 1 4; +#X connect 20 0 1 5; +#X connect 21 0 8 0; +#X connect 22 0 8 0; +#X connect 23 0 8 0; +#X connect 24 0 8 0; +#X connect 25 0 8 0; +#X connect 26 0 8 0; +#X connect 27 0 28 0; +#X connect 28 0 2 1; +#X connect 28 0 12 0; #X connect 28 0 37 0; -#X connect 28 0 40 0; -#X connect 29 0 36 0; -#X connect 29 0 41 0; -#X connect 30 0 35 0; -#X connect 30 0 42 0; -#X connect 31 0 34 0; -#X connect 31 0 43 0; -#X connect 32 0 33 0; -#X connect 32 0 44 0; -#X connect 33 0 26 1; -#X connect 34 0 25 1; -#X connect 35 0 24 1; -#X connect 36 0 23 1; -#X connect 37 0 22 1; -#X connect 38 0 21 1; -#X connect 39 0 14 0; -#X connect 40 0 14 0; -#X connect 41 0 14 0; -#X connect 42 0 14 0; -#X connect 43 0 14 0; -#X connect 44 0 14 0; +#X connect 28 1 3 1; +#X connect 28 1 13 0; +#X connect 28 1 38 0; +#X connect 28 2 4 1; +#X connect 28 2 9 0; +#X connect 28 3 5 1; +#X connect 28 3 10 0; +#X connect 28 4 6 1; +#X connect 28 4 14 0; +#X connect 28 5 7 1; +#X connect 28 5 11 0; +#X connect 28 6 29 0; +#X connect 29 0 30 0; +#X connect 29 0 21 0; +#X connect 29 1 31 0; +#X connect 29 1 22 0; +#X connect 29 2 32 0; +#X connect 29 2 23 0; +#X connect 29 3 33 0; +#X connect 29 3 24 0; +#X connect 29 4 34 0; +#X connect 29 4 25 0; +#X connect 29 5 35 0; +#X connect 29 5 26 0; +#X connect 30 0 15 1; +#X connect 31 0 16 1; +#X connect 32 0 17 1; +#X connect 33 0 18 1; +#X connect 34 0 19 1; +#X connect 35 0 20 1; +#X connect 36 0 8 0; +#X connect 37 0 36 0; +#X connect 38 0 37 0; +#X connect 38 1 37 1; diff --git a/src/LibPDEngine.cpp b/src/LibPDEngine.cpp index ec06e9b..4f98972 100644 --- a/src/LibPDEngine.cpp +++ b/src/LibPDEngine.cpp @@ -11,6 +11,8 @@ using namespace rack; float g_lights[NUM_ROWS][3] = {}; float g_switchLights[NUM_ROWS][3] = {}; +std::string g_utility[2] = {}; +bool g_display_is_valid = false; std::vector split (const std::string &s, char delim) { std::vector result; @@ -52,6 +54,7 @@ struct LibPDEngine : ScriptEngine { float _input[BUFFERSIZE] = {};// = (float*)malloc(1024*2*sizeof(float)); const static std::map _light_map; const static std::map _switchLight_map; + const static std::map _utility_map; std::string getEngineName() override { return "Pure Data"; @@ -131,6 +134,11 @@ struct LibPDEngine : ScriptEngine { sendSwitch(i, block->switches[i]); } } + + // display + if(g_display_is_valid){ + display(g_utility[1]); + } // process samples in libpd _ticks = 1; libpd_process_float(_ticks, _input, _output); @@ -158,7 +166,7 @@ void LibPDEngine::receiveLights(const char *s) { std::vector atoms = split (str, ' '); if(atoms[0]=="toVCV:"){ - // light list + // parse lights list bool light_is_valid = true; int light_idx = -1; try { @@ -177,7 +185,7 @@ void LibPDEngine::receiveLights(const char *s) { else { // error } - + // parse switch lights list bool switchLight_is_valid = true; int switchLight_idx = -1; try { @@ -196,9 +204,34 @@ void LibPDEngine::receiveLights(const char *s) { else { // error } + + // parse switch lights list + bool utility_is_valid = true; + int utility_idx = -1; + try { + utility_idx = _utility_map.at(atoms[1]); // map::at throws an out-of-range + } + catch (const std::out_of_range& oor) { + utility_is_valid = false; + //g_display_is_valid = true; + //display("Warning:"+atoms[1]+" not found!"); + } + //std::cout << v[1] << ", " << g_led_map[v[1]] << std::endl; + if(utility_is_valid && atoms.size()>=3){ + g_utility[0] = atoms[1]; // display + g_utility[1] = {""}; + for(int i=0; i LibPDEngine::_switchLight_map{ { "S6", 5 } }; +const std::map LibPDEngine::_utility_map{ + { "display", 0 } +}; + + void LibPDEngine::sendKnob(const int idx, const float value){ std::string knob = "K"+std::to_string(idx+1); - libpd_float(knob.c_str(), value); + libpd_start_message(1); + libpd_add_float(value); + libpd_finish_message("fromVCV", knob.c_str()); } void LibPDEngine::sendSwitch(const int idx, const bool value){ std::string sw = "S"+std::to_string(idx+1); - libpd_float(sw.c_str(), value); + libpd_start_message(1); + libpd_add_float(value); + libpd_finish_message("fromVCV", sw.c_str()); } void LibPDEngine::sendInitialStates(const ProcessBlock* block){ From 67cd901396be3c17d8cb248681878e5ae11e860d Mon Sep 17 00:00:00 2001 From: max Date: Wed, 1 Jul 2020 15:33:21 +0200 Subject: [PATCH 17/27] Pd: added vco.pd example --- examples/vco.pd | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 examples/vco.pd diff --git a/examples/vco.pd b/examples/vco.pd new file mode 100644 index 0000000..313e3d5 --- /dev/null +++ b/examples/vco.pd @@ -0,0 +1,20 @@ +#N canvas 3038 579 617 344 12; +#X obj 61 19 r fromVCV; +#X obj 61 44 route K1; +#X obj 61 126 mtof; +#X obj 61 234 osc~; +#X obj 61 259 dac~ 1; +#X obj 61 73 * 120; +#X obj 61 98 + 15; +#X obj 147 264 print toVCV; +#X msg 147 232 desplay Freq: \$1 Hz; +#X obj 61 164 t f f; +#X connect 0 0 1 0; +#X connect 1 0 5 0; +#X connect 2 0 9 0; +#X connect 3 0 4 0; +#X connect 5 0 6 0; +#X connect 6 0 2 0; +#X connect 8 0 7 0; +#X connect 9 0 3 0; +#X connect 9 1 8 0; From 5bbc3dd1348ee58d95b6ac09bf4cec5493a8faa0 Mon Sep 17 00:00:00 2001 From: clwe Date: Wed, 1 Jul 2020 15:56:07 +0200 Subject: [PATCH 18/27] PD: fixes initial display, display pd version --- examples/gain.pd | 9 --------- src/LibPDEngine.cpp | 6 ++++++ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/examples/gain.pd b/examples/gain.pd index 8d3b097..a98f6f1 100644 --- a/examples/gain.pd +++ b/examples/gain.pd @@ -35,9 +35,6 @@ #X obj 383 340 == 0; #X obj 447 342 == 0; #X obj 513 343 == 0; -#X msg 89 622 display \$1 \$2; -#X obj 80 582 pack f f; -#X obj 107 526 t b f; #X connect 0 0 2 0; #X connect 0 1 3 0; #X connect 0 2 4 0; @@ -71,10 +68,8 @@ #X connect 27 0 28 0; #X connect 28 0 2 1; #X connect 28 0 12 0; -#X connect 28 0 37 0; #X connect 28 1 3 1; #X connect 28 1 13 0; -#X connect 28 1 38 0; #X connect 28 2 4 1; #X connect 28 2 9 0; #X connect 28 3 5 1; @@ -102,7 +97,3 @@ #X connect 33 0 18 1; #X connect 34 0 19 1; #X connect 35 0 20 1; -#X connect 36 0 8 0; -#X connect 37 0 36 0; -#X connect 38 0 37 0; -#X connect 38 1 37 1; diff --git a/src/LibPDEngine.cpp b/src/LibPDEngine.cpp index 4f98972..7d15fc9 100644 --- a/src/LibPDEngine.cpp +++ b/src/LibPDEngine.cpp @@ -138,6 +138,7 @@ struct LibPDEngine : ScriptEngine { // display if(g_display_is_valid){ display(g_utility[1]); + g_display_is_valid = false; } // process samples in libpd _ticks = 1; @@ -296,4 +297,9 @@ void LibPDEngine::sendInitialStates(const ProcessBlock* block){ sendKnob(i, block->knobs[i]); sendSwitch(i, block->knobs[i]); } + std::string version = "pd "+std::to_string(PD_MAJOR_VERSION)+"."+ + std::to_string(PD_MINOR_VERSION)+"." + +std::to_string(PD_BUGFIX_VERSION); + + display(version); } \ No newline at end of file From 910dea5b5cdb3cca5768c9ae791ce59a5e8d7d8b Mon Sep 17 00:00:00 2001 From: max Date: Wed, 1 Jul 2020 15:40:17 +0200 Subject: [PATCH 19/27] Pd: added vco.pd example --- examples/vco.pd | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/examples/vco.pd b/examples/vco.pd index 313e3d5..6ee92f7 100644 --- a/examples/vco.pd +++ b/examples/vco.pd @@ -1,20 +1,24 @@ -#N canvas 3038 579 617 344 12; -#X obj 61 19 r fromVCV; -#X obj 61 44 route K1; -#X obj 61 126 mtof; -#X obj 61 234 osc~; -#X obj 61 259 dac~ 1; -#X obj 61 73 * 120; -#X obj 61 98 + 15; -#X obj 147 264 print toVCV; -#X msg 147 232 desplay Freq: \$1 Hz; -#X obj 61 164 t f f; +#N canvas 832 571 566 366 12; +#X obj 27 18 r fromVCV; +#X obj 27 43 route K1; +#X obj 27 180 mtof; +#X obj 27 236 osc~; +#X obj 27 261 dac~ 1; +#X obj 27 125 * 120; +#X obj 27 154 + 15; +#X obj 108 260 print toVCV; +#X obj 27 207 t f f, f 12; +#X msg 108 236 display Freq: \$1 Hz; +#X obj 39 71 loadbang; +#X msg 39 96 0.5; #X connect 0 0 1 0; #X connect 1 0 5 0; -#X connect 2 0 9 0; +#X connect 2 0 8 0; #X connect 3 0 4 0; #X connect 5 0 6 0; #X connect 6 0 2 0; -#X connect 8 0 7 0; -#X connect 9 0 3 0; -#X connect 9 1 8 0; +#X connect 8 0 3 0; +#X connect 8 1 9 0; +#X connect 9 0 7 0; +#X connect 10 0 11 0; +#X connect 11 0 5 0; From 6b82cc60d7767e17fbeb44f73ef8595526d1878c Mon Sep 17 00:00:00 2001 From: clwe Date: Wed, 1 Jul 2020 16:09:34 +0200 Subject: [PATCH 20/27] PD: reset global arrays on script reload to fix wrong lights display --- src/LibPDEngine.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/LibPDEngine.cpp b/src/LibPDEngine.cpp index 7d15fc9..fe4199d 100644 --- a/src/LibPDEngine.cpp +++ b/src/LibPDEngine.cpp @@ -208,9 +208,8 @@ void LibPDEngine::receiveLights(const char *s) { // parse switch lights list bool utility_is_valid = true; - int utility_idx = -1; try { - utility_idx = _utility_map.at(atoms[1]); // map::at throws an out-of-range + _utility_map.at(atoms[1]); // map::at throws an out-of-range } catch (const std::out_of_range& oor) { utility_is_valid = false; @@ -221,7 +220,7 @@ void LibPDEngine::receiveLights(const char *s) { if(utility_is_valid && atoms.size()>=3){ g_utility[0] = atoms[1]; // display g_utility[1] = {""}; - for(int i=0; i Date: Wed, 1 Jul 2020 18:42:36 +0200 Subject: [PATCH 21/27] Pd: added and updated examples --- examples/gain.pd | 126 ++++++++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 56 deletions(-) diff --git a/examples/gain.pd b/examples/gain.pd index a98f6f1..ebc925e 100644 --- a/examples/gain.pd +++ b/examples/gain.pd @@ -1,40 +1,52 @@ -#N canvas 1187 297 729 742 12; -#X obj 153 257 adc~ 1 2 3 4 5 6, f 47; -#X obj 153 427 dac~ 1 2 3 4 5 6, f 47; -#X obj 154 297 *~ 1; -#X obj 218 296 *~ 1; -#X obj 282 298 *~ 1; -#X obj 348 297 *~ 1; -#X obj 412 297 *~ 1; -#X obj 478 296 *~ 1; -#X obj 330 663 print toVCV; -#X msg 307 476 L3 \$1 0 0; -#X msg 373 508 L4 \$1 0 0; -#X msg 503 509 L6 \$1 0 0; -#X msg 176 475 L1 \$1 0 0; -#X msg 243 507 L2 \$1 0 0; -#X msg 437 478 L5 \$1 0 0; -#X obj 154 376 *~ 1; -#X obj 218 375 *~ 1; -#X obj 282 377 *~ 1; -#X obj 348 376 *~ 1; -#X obj 412 376 *~ 1; -#X obj 478 375 *~ 1; -#X msg 186 565 S1 \$1 0 0; -#X msg 253 597 S2 \$1 0 0; -#X msg 317 566 S3 \$1 0 0; -#X msg 383 599 S4 \$1 0 0; -#X msg 447 568 S5 \$1 0 0; -#X msg 513 598 S6 \$1 0 0; -#X obj 179 104 r fromVCV; -#X obj 179 143 route K1 K2 K3 K4 K5 K6, f 56; -#X obj 188 198 route S1 S2 S3 S4 S5 S6, f 56; -#X obj 187 341 == 0; -#X obj 253 342 == 0; -#X obj 317 341 == 0; -#X obj 383 340 == 0; -#X obj 447 342 == 0; -#X obj 513 343 == 0; +#N canvas 860 318 890 742 12; +#X obj 117 30 adc~ 1 2 3 4 5 6, f 47; +#X obj 118 261 dac~ 1 2 3 4 5 6, f 47; +#X obj 117 98 *~ 1; +#X obj 182 98 *~ 1; +#X obj 246 98 *~ 1; +#X obj 312 98 *~ 1; +#X obj 376 98 *~ 1; +#X obj 442 98 *~ 1; +#X obj 21 422 print toVCV; +#X msg 171 365 L3 \$1 0 0; +#X msg 247 365 L4 \$1 0 0; +#X msg 397 365 L6 \$1 0 0; +#X msg 21 365 L1 \$1 0 0; +#X msg 96 365 L2 \$1 0 0; +#X msg 322 365 L5 \$1 0 0; +#X obj 118 229 *~ 1; +#X obj 183 228 *~ 1; +#X obj 247 228 *~ 1; +#X obj 313 228 *~ 1; +#X obj 377 228 *~ 1; +#X obj 443 228 *~ 1; +#X msg 21 521 S1 \$1 0 0; +#X msg 96 522 S2 \$1 0 0; +#X msg 171 522 S3 \$1 0 0; +#X msg 247 523 S4 \$1 0 0; +#X msg 322 523 S5 \$1 0 0; +#X msg 397 523 S6 \$1 0 0; +#X obj 20 30 r fromVCV; +#X obj 142 70 route K1 K2 K3 K4 K5 K6, f 56; +#X obj 143 169 route S1 S2 S3 S4 S5 S6, f 56; +#X obj 143 198 == 0; +#X obj 208 198 == 0; +#X obj 272 198 == 0; +#X obj 338 198 == 0; +#X obj 402 198 == 0; +#X obj 468 198 == 0; +#X obj 21 307 r fromVCV; +#X obj 21 336 route K1 K2 K3 K4 K5 K6, f 65; +#X obj 21 492 route S1 S2 S3 S4 S5 S6, f 65; +#X obj 21 463 r fromVCV; +#X obj 19 134 r fromVCV; +#X obj 21 569 print toVCV; +#X text 558 52 Usually we'd interpolate here with line~ but VCVRack +is already sending one message persample so there seems hardly a point +to complicate this example., f 38; +#X text 560 368 Just using the red channels in the RGB triplet for +the LED., f 35; +#X text 561 492 Same for the switch., f 35; #X connect 0 0 2 0; #X connect 0 1 3 0; #X connect 0 2 4 0; @@ -59,41 +71,43 @@ #X connect 18 0 1 3; #X connect 19 0 1 4; #X connect 20 0 1 5; -#X connect 21 0 8 0; -#X connect 22 0 8 0; -#X connect 23 0 8 0; -#X connect 24 0 8 0; -#X connect 25 0 8 0; -#X connect 26 0 8 0; +#X connect 21 0 41 0; +#X connect 22 0 41 0; +#X connect 23 0 41 0; +#X connect 24 0 41 0; +#X connect 25 0 41 0; +#X connect 26 0 41 0; #X connect 27 0 28 0; #X connect 28 0 2 1; -#X connect 28 0 12 0; #X connect 28 1 3 1; -#X connect 28 1 13 0; #X connect 28 2 4 1; -#X connect 28 2 9 0; #X connect 28 3 5 1; -#X connect 28 3 10 0; #X connect 28 4 6 1; -#X connect 28 4 14 0; #X connect 28 5 7 1; -#X connect 28 5 11 0; -#X connect 28 6 29 0; #X connect 29 0 30 0; -#X connect 29 0 21 0; #X connect 29 1 31 0; -#X connect 29 1 22 0; #X connect 29 2 32 0; -#X connect 29 2 23 0; #X connect 29 3 33 0; -#X connect 29 3 24 0; #X connect 29 4 34 0; -#X connect 29 4 25 0; #X connect 29 5 35 0; -#X connect 29 5 26 0; #X connect 30 0 15 1; #X connect 31 0 16 1; #X connect 32 0 17 1; #X connect 33 0 18 1; #X connect 34 0 19 1; #X connect 35 0 20 1; +#X connect 36 0 37 0; +#X connect 37 0 12 0; +#X connect 37 1 13 0; +#X connect 37 2 9 0; +#X connect 37 3 10 0; +#X connect 37 4 14 0; +#X connect 37 5 11 0; +#X connect 38 0 21 0; +#X connect 38 1 22 0; +#X connect 38 2 23 0; +#X connect 38 3 24 0; +#X connect 38 4 25 0; +#X connect 38 5 26 0; +#X connect 39 0 38 0; +#X connect 40 0 29 0; From b26fbd9f8cab7764d34dacf9e6004d829ed324f9 Mon Sep 17 00:00:00 2001 From: max Date: Wed, 1 Jul 2020 18:44:31 +0200 Subject: [PATCH 22/27] Pd: added and updated examples --- examples/rainbow.pd | 1020 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1020 insertions(+) create mode 100644 examples/rainbow.pd diff --git a/examples/rainbow.pd b/examples/rainbow.pd new file mode 100644 index 0000000..1165921 --- /dev/null +++ b/examples/rainbow.pd @@ -0,0 +1,1020 @@ +#N canvas 547 398 649 666 12; +#N canvas 250 355 563 749 hsv2rgb 0; +#X obj 20 64 route 0; +#X msg 20 36 \$2 \$3 \$1; +#X obj 20 552 f; +#X obj 66 92 unpack 0 0 0, f 27; +#X text 87 37 svh; +#X obj 20 8 inlet hsv; +#X obj 20 663 outlet rgb; +#X obj 303 166 * 6; +#X obj 284 213 % 6; +#X obj 252 190 t f f; +#X msg 252 166 0; +#X text 308 213 i; +#X obj 252 264 -; +#X obj 66 501 *; +#X obj 66 169 - 1; +#X obj 66 196 * -1; +#X obj 103 502 *; +#X obj 103 399 - 1; +#X obj 103 424 * -1; +#X obj 103 377 *; +#X obj 252 288 t f f; +#X obj 282 311 - 1; +#X obj 282 334 * -1; +#X obj 140 503 *; +#X obj 140 400 - 1; +#X obj 140 425 * -1; +#X obj 140 378 *; +#X obj 66 142 t f f f, f 11; +#X obj 66 535 pack 0 0 0 0, f 16; +#N canvas 1219 718 529 336 select 0; +#X obj 290 37 inlet; +#X obj 16 281 outlet; +#X obj 16 58 t b l, f 20; +#X obj 152 176 unpack 0 0 0 0; +#X obj 16 29 inlet p q t v; +#X obj 16 123 i; +#X obj 16 175 select 0 1 2 3 4 5; +#X obj 16 239 pack 0 0 0; +#X obj 16 209 f; +#X obj 96 239 pack 0 0 0; +#X obj 96 209 f; +#X obj 176 239 pack 0 0 0; +#X obj 176 209 f; +#X obj 256 239 pack 0 0 0; +#X obj 256 209 f; +#X obj 336 239 pack 0 0 0; +#X obj 336 209 f; +#X obj 416 239 pack 0 0 0; +#X obj 416 209 f; +#X connect 0 0 5 1; +#X connect 2 0 5 0; +#X connect 2 1 3 0; +#X connect 3 0 7 2; +#X connect 3 0 9 2; +#X connect 3 0 12 1; +#X connect 3 0 14 1; +#X connect 3 0 15 1; +#X connect 3 0 17 1; +#X connect 3 1 10 1; +#X connect 3 1 13 1; +#X connect 3 1 17 2; +#X connect 3 2 7 1; +#X connect 3 2 11 2; +#X connect 3 2 16 1; +#X connect 3 3 8 1; +#X connect 3 3 9 1; +#X connect 3 3 11 1; +#X connect 3 3 13 2; +#X connect 3 3 15 2; +#X connect 3 3 18 1; +#X connect 4 0 2 0; +#X connect 5 0 6 0; +#X connect 6 0 8 0; +#X connect 6 1 10 0; +#X connect 6 2 12 0; +#X connect 6 3 14 0; +#X connect 6 4 16 0; +#X connect 6 5 18 0; +#X connect 7 0 1 0; +#X connect 8 0 7 0; +#X connect 9 0 1 0; +#X connect 10 0 9 0; +#X connect 11 0 1 0; +#X connect 12 0 11 0; +#X connect 13 0 1 0; +#X connect 14 0 13 0; +#X connect 15 0 1 0; +#X connect 16 0 15 0; +#X connect 17 0 1 0; +#X connect 18 0 17 0; +#X restore 66 560 pd select; +#X f 28; +#X msg 20 621 \$1 \$1 \$1; +#X obj 20 593 clip 0 1; +#X obj 66 117 clip 0 1; +#X obj 175 119 clip 0 1; +#X obj 252 118 clip 0 1; +#X obj 252 142 select 1; +#X obj 175 462 t f f f f; +#X obj 260 237 t f f; +#X text 26 699 taken from the GEM helpfile hsv2rgb-help; +#X connect 0 0 2 0; +#X connect 0 1 3 0; +#X connect 1 0 0 0; +#X connect 2 0 31 0; +#X connect 3 0 32 0; +#X connect 3 1 33 0; +#X connect 3 2 34 0; +#X connect 5 0 1 0; +#X connect 7 0 9 0; +#X connect 8 0 37 0; +#X connect 9 0 12 0; +#X connect 9 1 8 0; +#X connect 10 0 9 0; +#X connect 12 0 20 0; +#X connect 13 0 28 0; +#X connect 14 0 15 0; +#X connect 15 0 13 0; +#X connect 16 0 28 1; +#X connect 17 0 18 0; +#X connect 18 0 16 0; +#X connect 19 0 17 0; +#X connect 20 0 19 1; +#X connect 20 1 21 0; +#X connect 21 0 22 0; +#X connect 22 0 26 1; +#X connect 23 0 28 2; +#X connect 24 0 25 0; +#X connect 25 0 23 0; +#X connect 26 0 24 0; +#X connect 27 0 14 0; +#X connect 27 1 19 0; +#X connect 27 2 26 0; +#X connect 28 0 29 0; +#X connect 29 0 6 0; +#X connect 30 0 6 0; +#X connect 31 0 30 0; +#X connect 32 0 27 0; +#X connect 33 0 36 0; +#X connect 34 0 35 0; +#X connect 35 0 10 0; +#X connect 35 1 7 0; +#X connect 36 0 13 1; +#X connect 36 1 16 1; +#X connect 36 2 23 1; +#X connect 36 3 28 3; +#X connect 37 0 29 1; +#X connect 37 1 12 1; +#X restore 29 303 pd hsv2rgb; +#X obj 29 438 print toVCV; +#X msg 29 360 S1 \$1 \$2 \$3; +#X obj 30 16 loadbang; +#X msg 30 41 1; +#X msg 29 275 \$1 1 1; +#X obj 30 67 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1 1 +; +#X obj 30 143 line; +#N canvas 250 355 563 749 hsv2rgb 0; +#X obj 20 64 route 0; +#X msg 20 36 \$2 \$3 \$1; +#X obj 20 552 f; +#X obj 66 92 unpack 0 0 0, f 27; +#X text 87 37 svh; +#X obj 20 8 inlet hsv; +#X obj 20 663 outlet rgb; +#X obj 303 166 * 6; +#X obj 284 213 % 6; +#X obj 252 190 t f f; +#X msg 252 166 0; +#X text 308 213 i; +#X obj 252 264 -; +#X obj 66 501 *; +#X obj 66 169 - 1; +#X obj 66 196 * -1; +#X obj 103 502 *; +#X obj 103 399 - 1; +#X obj 103 424 * -1; +#X obj 103 377 *; +#X obj 252 288 t f f; +#X obj 282 311 - 1; +#X obj 282 334 * -1; +#X obj 140 503 *; +#X obj 140 400 - 1; +#X obj 140 425 * -1; +#X obj 140 378 *; +#X obj 66 142 t f f f, f 11; +#X obj 66 535 pack 0 0 0 0, f 16; +#N canvas 1219 718 529 336 select 0; +#X obj 290 37 inlet; +#X obj 16 281 outlet; +#X obj 16 58 t b l, f 20; +#X obj 152 176 unpack 0 0 0 0; +#X obj 16 29 inlet p q t v; +#X obj 16 123 i; +#X obj 16 175 select 0 1 2 3 4 5; +#X obj 16 239 pack 0 0 0; +#X obj 16 209 f; +#X obj 96 239 pack 0 0 0; +#X obj 96 209 f; +#X obj 176 239 pack 0 0 0; +#X obj 176 209 f; +#X obj 256 239 pack 0 0 0; +#X obj 256 209 f; +#X obj 336 239 pack 0 0 0; +#X obj 336 209 f; +#X obj 416 239 pack 0 0 0; +#X obj 416 209 f; +#X connect 0 0 5 1; +#X connect 2 0 5 0; +#X connect 2 1 3 0; +#X connect 3 0 7 2; +#X connect 3 0 9 2; +#X connect 3 0 12 1; +#X connect 3 0 14 1; +#X connect 3 0 15 1; +#X connect 3 0 17 1; +#X connect 3 1 10 1; +#X connect 3 1 13 1; +#X connect 3 1 17 2; +#X connect 3 2 7 1; +#X connect 3 2 11 2; +#X connect 3 2 16 1; +#X connect 3 3 8 1; +#X connect 3 3 9 1; +#X connect 3 3 11 1; +#X connect 3 3 13 2; +#X connect 3 3 15 2; +#X connect 3 3 18 1; +#X connect 4 0 2 0; +#X connect 5 0 6 0; +#X connect 6 0 8 0; +#X connect 6 1 10 0; +#X connect 6 2 12 0; +#X connect 6 3 14 0; +#X connect 6 4 16 0; +#X connect 6 5 18 0; +#X connect 7 0 1 0; +#X connect 8 0 7 0; +#X connect 9 0 1 0; +#X connect 10 0 9 0; +#X connect 11 0 1 0; +#X connect 12 0 11 0; +#X connect 13 0 1 0; +#X connect 14 0 13 0; +#X connect 15 0 1 0; +#X connect 16 0 15 0; +#X connect 17 0 1 0; +#X connect 18 0 17 0; +#X restore 66 560 pd select; +#X f 28; +#X msg 20 621 \$1 \$1 \$1; +#X obj 20 593 clip 0 1; +#X obj 66 117 clip 0 1; +#X obj 175 119 clip 0 1; +#X obj 252 118 clip 0 1; +#X obj 252 142 select 1; +#X obj 175 462 t f f f f; +#X obj 260 237 t f f; +#X text 26 699 taken from the GEM helpfile hsv2rgb-help; +#X connect 0 0 2 0; +#X connect 0 1 3 0; +#X connect 1 0 0 0; +#X connect 2 0 31 0; +#X connect 3 0 32 0; +#X connect 3 1 33 0; +#X connect 3 2 34 0; +#X connect 5 0 1 0; +#X connect 7 0 9 0; +#X connect 8 0 37 0; +#X connect 9 0 12 0; +#X connect 9 1 8 0; +#X connect 10 0 9 0; +#X connect 12 0 20 0; +#X connect 13 0 28 0; +#X connect 14 0 15 0; +#X connect 15 0 13 0; +#X connect 16 0 28 1; +#X connect 17 0 18 0; +#X connect 18 0 16 0; +#X connect 19 0 17 0; +#X connect 20 0 19 1; +#X connect 20 1 21 0; +#X connect 21 0 22 0; +#X connect 22 0 26 1; +#X connect 23 0 28 2; +#X connect 24 0 25 0; +#X connect 25 0 23 0; +#X connect 26 0 24 0; +#X connect 27 0 14 0; +#X connect 27 1 19 0; +#X connect 27 2 26 0; +#X connect 28 0 29 0; +#X connect 29 0 6 0; +#X connect 30 0 6 0; +#X connect 31 0 30 0; +#X connect 32 0 27 0; +#X connect 33 0 36 0; +#X connect 34 0 35 0; +#X connect 35 0 10 0; +#X connect 35 1 7 0; +#X connect 36 0 13 1; +#X connect 36 1 16 1; +#X connect 36 2 23 1; +#X connect 36 3 28 3; +#X connect 37 0 29 1; +#X connect 37 1 12 1; +#X restore 125 303 pd hsv2rgb; +#N canvas 250 355 563 749 hsv2rgb 0; +#X obj 20 64 route 0; +#X msg 20 36 \$2 \$3 \$1; +#X obj 20 552 f; +#X obj 66 92 unpack 0 0 0, f 27; +#X text 87 37 svh; +#X obj 20 8 inlet hsv; +#X obj 20 663 outlet rgb; +#X obj 303 166 * 6; +#X obj 284 213 % 6; +#X obj 252 190 t f f; +#X msg 252 166 0; +#X text 308 213 i; +#X obj 252 264 -; +#X obj 66 501 *; +#X obj 66 169 - 1; +#X obj 66 196 * -1; +#X obj 103 502 *; +#X obj 103 399 - 1; +#X obj 103 424 * -1; +#X obj 103 377 *; +#X obj 252 288 t f f; +#X obj 282 311 - 1; +#X obj 282 334 * -1; +#X obj 140 503 *; +#X obj 140 400 - 1; +#X obj 140 425 * -1; +#X obj 140 378 *; +#X obj 66 142 t f f f, f 11; +#X obj 66 535 pack 0 0 0 0, f 16; +#N canvas 1219 718 529 336 select 0; +#X obj 290 37 inlet; +#X obj 16 281 outlet; +#X obj 16 58 t b l, f 20; +#X obj 152 176 unpack 0 0 0 0; +#X obj 16 29 inlet p q t v; +#X obj 16 123 i; +#X obj 16 175 select 0 1 2 3 4 5; +#X obj 16 239 pack 0 0 0; +#X obj 16 209 f; +#X obj 96 239 pack 0 0 0; +#X obj 96 209 f; +#X obj 176 239 pack 0 0 0; +#X obj 176 209 f; +#X obj 256 239 pack 0 0 0; +#X obj 256 209 f; +#X obj 336 239 pack 0 0 0; +#X obj 336 209 f; +#X obj 416 239 pack 0 0 0; +#X obj 416 209 f; +#X connect 0 0 5 1; +#X connect 2 0 5 0; +#X connect 2 1 3 0; +#X connect 3 0 7 2; +#X connect 3 0 9 2; +#X connect 3 0 12 1; +#X connect 3 0 14 1; +#X connect 3 0 15 1; +#X connect 3 0 17 1; +#X connect 3 1 10 1; +#X connect 3 1 13 1; +#X connect 3 1 17 2; +#X connect 3 2 7 1; +#X connect 3 2 11 2; +#X connect 3 2 16 1; +#X connect 3 3 8 1; +#X connect 3 3 9 1; +#X connect 3 3 11 1; +#X connect 3 3 13 2; +#X connect 3 3 15 2; +#X connect 3 3 18 1; +#X connect 4 0 2 0; +#X connect 5 0 6 0; +#X connect 6 0 8 0; +#X connect 6 1 10 0; +#X connect 6 2 12 0; +#X connect 6 3 14 0; +#X connect 6 4 16 0; +#X connect 6 5 18 0; +#X connect 7 0 1 0; +#X connect 8 0 7 0; +#X connect 9 0 1 0; +#X connect 10 0 9 0; +#X connect 11 0 1 0; +#X connect 12 0 11 0; +#X connect 13 0 1 0; +#X connect 14 0 13 0; +#X connect 15 0 1 0; +#X connect 16 0 15 0; +#X connect 17 0 1 0; +#X connect 18 0 17 0; +#X restore 66 560 pd select; +#X f 28; +#X msg 20 621 \$1 \$1 \$1; +#X obj 20 593 clip 0 1; +#X obj 66 117 clip 0 1; +#X obj 175 119 clip 0 1; +#X obj 252 118 clip 0 1; +#X obj 252 142 select 1; +#X obj 175 462 t f f f f; +#X obj 260 237 t f f; +#X text 26 699 taken from the GEM helpfile hsv2rgb-help; +#X connect 0 0 2 0; +#X connect 0 1 3 0; +#X connect 1 0 0 0; +#X connect 2 0 31 0; +#X connect 3 0 32 0; +#X connect 3 1 33 0; +#X connect 3 2 34 0; +#X connect 5 0 1 0; +#X connect 7 0 9 0; +#X connect 8 0 37 0; +#X connect 9 0 12 0; +#X connect 9 1 8 0; +#X connect 10 0 9 0; +#X connect 12 0 20 0; +#X connect 13 0 28 0; +#X connect 14 0 15 0; +#X connect 15 0 13 0; +#X connect 16 0 28 1; +#X connect 17 0 18 0; +#X connect 18 0 16 0; +#X connect 19 0 17 0; +#X connect 20 0 19 1; +#X connect 20 1 21 0; +#X connect 21 0 22 0; +#X connect 22 0 26 1; +#X connect 23 0 28 2; +#X connect 24 0 25 0; +#X connect 25 0 23 0; +#X connect 26 0 24 0; +#X connect 27 0 14 0; +#X connect 27 1 19 0; +#X connect 27 2 26 0; +#X connect 28 0 29 0; +#X connect 29 0 6 0; +#X connect 30 0 6 0; +#X connect 31 0 30 0; +#X connect 32 0 27 0; +#X connect 33 0 36 0; +#X connect 34 0 35 0; +#X connect 35 0 10 0; +#X connect 35 1 7 0; +#X connect 36 0 13 1; +#X connect 36 1 16 1; +#X connect 36 2 23 1; +#X connect 36 3 28 3; +#X connect 37 0 29 1; +#X connect 37 1 12 1; +#X restore 221 303 pd hsv2rgb; +#N canvas 250 355 563 749 hsv2rgb 0; +#X obj 20 64 route 0; +#X msg 20 36 \$2 \$3 \$1; +#X obj 20 552 f; +#X obj 66 92 unpack 0 0 0, f 27; +#X text 87 37 svh; +#X obj 20 8 inlet hsv; +#X obj 20 663 outlet rgb; +#X obj 303 166 * 6; +#X obj 284 213 % 6; +#X obj 252 190 t f f; +#X msg 252 166 0; +#X text 308 213 i; +#X obj 252 264 -; +#X obj 66 501 *; +#X obj 66 169 - 1; +#X obj 66 196 * -1; +#X obj 103 502 *; +#X obj 103 399 - 1; +#X obj 103 424 * -1; +#X obj 103 377 *; +#X obj 252 288 t f f; +#X obj 282 311 - 1; +#X obj 282 334 * -1; +#X obj 140 503 *; +#X obj 140 400 - 1; +#X obj 140 425 * -1; +#X obj 140 378 *; +#X obj 66 142 t f f f, f 11; +#X obj 66 535 pack 0 0 0 0, f 16; +#N canvas 1219 718 529 336 select 0; +#X obj 290 37 inlet; +#X obj 16 281 outlet; +#X obj 16 58 t b l, f 20; +#X obj 152 176 unpack 0 0 0 0; +#X obj 16 29 inlet p q t v; +#X obj 16 123 i; +#X obj 16 175 select 0 1 2 3 4 5; +#X obj 16 239 pack 0 0 0; +#X obj 16 209 f; +#X obj 96 239 pack 0 0 0; +#X obj 96 209 f; +#X obj 176 239 pack 0 0 0; +#X obj 176 209 f; +#X obj 256 239 pack 0 0 0; +#X obj 256 209 f; +#X obj 336 239 pack 0 0 0; +#X obj 336 209 f; +#X obj 416 239 pack 0 0 0; +#X obj 416 209 f; +#X connect 0 0 5 1; +#X connect 2 0 5 0; +#X connect 2 1 3 0; +#X connect 3 0 7 2; +#X connect 3 0 9 2; +#X connect 3 0 12 1; +#X connect 3 0 14 1; +#X connect 3 0 15 1; +#X connect 3 0 17 1; +#X connect 3 1 10 1; +#X connect 3 1 13 1; +#X connect 3 1 17 2; +#X connect 3 2 7 1; +#X connect 3 2 11 2; +#X connect 3 2 16 1; +#X connect 3 3 8 1; +#X connect 3 3 9 1; +#X connect 3 3 11 1; +#X connect 3 3 13 2; +#X connect 3 3 15 2; +#X connect 3 3 18 1; +#X connect 4 0 2 0; +#X connect 5 0 6 0; +#X connect 6 0 8 0; +#X connect 6 1 10 0; +#X connect 6 2 12 0; +#X connect 6 3 14 0; +#X connect 6 4 16 0; +#X connect 6 5 18 0; +#X connect 7 0 1 0; +#X connect 8 0 7 0; +#X connect 9 0 1 0; +#X connect 10 0 9 0; +#X connect 11 0 1 0; +#X connect 12 0 11 0; +#X connect 13 0 1 0; +#X connect 14 0 13 0; +#X connect 15 0 1 0; +#X connect 16 0 15 0; +#X connect 17 0 1 0; +#X connect 18 0 17 0; +#X restore 66 560 pd select; +#X f 28; +#X msg 20 621 \$1 \$1 \$1; +#X obj 20 593 clip 0 1; +#X obj 66 117 clip 0 1; +#X obj 175 119 clip 0 1; +#X obj 252 118 clip 0 1; +#X obj 252 142 select 1; +#X obj 175 462 t f f f f; +#X obj 260 237 t f f; +#X text 26 699 taken from the GEM helpfile hsv2rgb-help; +#X connect 0 0 2 0; +#X connect 0 1 3 0; +#X connect 1 0 0 0; +#X connect 2 0 31 0; +#X connect 3 0 32 0; +#X connect 3 1 33 0; +#X connect 3 2 34 0; +#X connect 5 0 1 0; +#X connect 7 0 9 0; +#X connect 8 0 37 0; +#X connect 9 0 12 0; +#X connect 9 1 8 0; +#X connect 10 0 9 0; +#X connect 12 0 20 0; +#X connect 13 0 28 0; +#X connect 14 0 15 0; +#X connect 15 0 13 0; +#X connect 16 0 28 1; +#X connect 17 0 18 0; +#X connect 18 0 16 0; +#X connect 19 0 17 0; +#X connect 20 0 19 1; +#X connect 20 1 21 0; +#X connect 21 0 22 0; +#X connect 22 0 26 1; +#X connect 23 0 28 2; +#X connect 24 0 25 0; +#X connect 25 0 23 0; +#X connect 26 0 24 0; +#X connect 27 0 14 0; +#X connect 27 1 19 0; +#X connect 27 2 26 0; +#X connect 28 0 29 0; +#X connect 29 0 6 0; +#X connect 30 0 6 0; +#X connect 31 0 30 0; +#X connect 32 0 27 0; +#X connect 33 0 36 0; +#X connect 34 0 35 0; +#X connect 35 0 10 0; +#X connect 35 1 7 0; +#X connect 36 0 13 1; +#X connect 36 1 16 1; +#X connect 36 2 23 1; +#X connect 36 3 28 3; +#X connect 37 0 29 1; +#X connect 37 1 12 1; +#X restore 317 303 pd hsv2rgb; +#N canvas 250 355 563 749 hsv2rgb 0; +#X obj 20 64 route 0; +#X msg 20 36 \$2 \$3 \$1; +#X obj 20 552 f; +#X obj 66 92 unpack 0 0 0, f 27; +#X text 87 37 svh; +#X obj 20 8 inlet hsv; +#X obj 20 663 outlet rgb; +#X obj 303 166 * 6; +#X obj 284 213 % 6; +#X obj 252 190 t f f; +#X msg 252 166 0; +#X text 308 213 i; +#X obj 252 264 -; +#X obj 66 501 *; +#X obj 66 169 - 1; +#X obj 66 196 * -1; +#X obj 103 502 *; +#X obj 103 399 - 1; +#X obj 103 424 * -1; +#X obj 103 377 *; +#X obj 252 288 t f f; +#X obj 282 311 - 1; +#X obj 282 334 * -1; +#X obj 140 503 *; +#X obj 140 400 - 1; +#X obj 140 425 * -1; +#X obj 140 378 *; +#X obj 66 142 t f f f, f 11; +#X obj 66 535 pack 0 0 0 0, f 16; +#N canvas 1219 718 529 336 select 0; +#X obj 290 37 inlet; +#X obj 16 281 outlet; +#X obj 16 58 t b l, f 20; +#X obj 152 176 unpack 0 0 0 0; +#X obj 16 29 inlet p q t v; +#X obj 16 123 i; +#X obj 16 175 select 0 1 2 3 4 5; +#X obj 16 239 pack 0 0 0; +#X obj 16 209 f; +#X obj 96 239 pack 0 0 0; +#X obj 96 209 f; +#X obj 176 239 pack 0 0 0; +#X obj 176 209 f; +#X obj 256 239 pack 0 0 0; +#X obj 256 209 f; +#X obj 336 239 pack 0 0 0; +#X obj 336 209 f; +#X obj 416 239 pack 0 0 0; +#X obj 416 209 f; +#X connect 0 0 5 1; +#X connect 2 0 5 0; +#X connect 2 1 3 0; +#X connect 3 0 7 2; +#X connect 3 0 9 2; +#X connect 3 0 12 1; +#X connect 3 0 14 1; +#X connect 3 0 15 1; +#X connect 3 0 17 1; +#X connect 3 1 10 1; +#X connect 3 1 13 1; +#X connect 3 1 17 2; +#X connect 3 2 7 1; +#X connect 3 2 11 2; +#X connect 3 2 16 1; +#X connect 3 3 8 1; +#X connect 3 3 9 1; +#X connect 3 3 11 1; +#X connect 3 3 13 2; +#X connect 3 3 15 2; +#X connect 3 3 18 1; +#X connect 4 0 2 0; +#X connect 5 0 6 0; +#X connect 6 0 8 0; +#X connect 6 1 10 0; +#X connect 6 2 12 0; +#X connect 6 3 14 0; +#X connect 6 4 16 0; +#X connect 6 5 18 0; +#X connect 7 0 1 0; +#X connect 8 0 7 0; +#X connect 9 0 1 0; +#X connect 10 0 9 0; +#X connect 11 0 1 0; +#X connect 12 0 11 0; +#X connect 13 0 1 0; +#X connect 14 0 13 0; +#X connect 15 0 1 0; +#X connect 16 0 15 0; +#X connect 17 0 1 0; +#X connect 18 0 17 0; +#X restore 66 560 pd select; +#X f 28; +#X msg 20 621 \$1 \$1 \$1; +#X obj 20 593 clip 0 1; +#X obj 66 117 clip 0 1; +#X obj 175 119 clip 0 1; +#X obj 252 118 clip 0 1; +#X obj 252 142 select 1; +#X obj 175 462 t f f f f; +#X obj 260 237 t f f; +#X text 26 699 taken from the GEM helpfile hsv2rgb-help; +#X connect 0 0 2 0; +#X connect 0 1 3 0; +#X connect 1 0 0 0; +#X connect 2 0 31 0; +#X connect 3 0 32 0; +#X connect 3 1 33 0; +#X connect 3 2 34 0; +#X connect 5 0 1 0; +#X connect 7 0 9 0; +#X connect 8 0 37 0; +#X connect 9 0 12 0; +#X connect 9 1 8 0; +#X connect 10 0 9 0; +#X connect 12 0 20 0; +#X connect 13 0 28 0; +#X connect 14 0 15 0; +#X connect 15 0 13 0; +#X connect 16 0 28 1; +#X connect 17 0 18 0; +#X connect 18 0 16 0; +#X connect 19 0 17 0; +#X connect 20 0 19 1; +#X connect 20 1 21 0; +#X connect 21 0 22 0; +#X connect 22 0 26 1; +#X connect 23 0 28 2; +#X connect 24 0 25 0; +#X connect 25 0 23 0; +#X connect 26 0 24 0; +#X connect 27 0 14 0; +#X connect 27 1 19 0; +#X connect 27 2 26 0; +#X connect 28 0 29 0; +#X connect 29 0 6 0; +#X connect 30 0 6 0; +#X connect 31 0 30 0; +#X connect 32 0 27 0; +#X connect 33 0 36 0; +#X connect 34 0 35 0; +#X connect 35 0 10 0; +#X connect 35 1 7 0; +#X connect 36 0 13 1; +#X connect 36 1 16 1; +#X connect 36 2 23 1; +#X connect 36 3 28 3; +#X connect 37 0 29 1; +#X connect 37 1 12 1; +#X restore 413 303 pd hsv2rgb; +#N canvas 250 355 563 749 hsv2rgb 0; +#X obj 20 64 route 0; +#X msg 20 36 \$2 \$3 \$1; +#X obj 20 552 f; +#X obj 66 92 unpack 0 0 0, f 27; +#X text 87 37 svh; +#X obj 20 8 inlet hsv; +#X obj 20 663 outlet rgb; +#X obj 303 166 * 6; +#X obj 284 213 % 6; +#X obj 252 190 t f f; +#X msg 252 166 0; +#X text 308 213 i; +#X obj 252 264 -; +#X obj 66 501 *; +#X obj 66 169 - 1; +#X obj 66 196 * -1; +#X obj 103 502 *; +#X obj 103 399 - 1; +#X obj 103 424 * -1; +#X obj 103 377 *; +#X obj 252 288 t f f; +#X obj 282 311 - 1; +#X obj 282 334 * -1; +#X obj 140 503 *; +#X obj 140 400 - 1; +#X obj 140 425 * -1; +#X obj 140 378 *; +#X obj 66 142 t f f f, f 11; +#X obj 66 535 pack 0 0 0 0, f 16; +#N canvas 1219 718 529 336 select 0; +#X obj 290 37 inlet; +#X obj 16 281 outlet; +#X obj 16 58 t b l, f 20; +#X obj 152 176 unpack 0 0 0 0; +#X obj 16 29 inlet p q t v; +#X obj 16 123 i; +#X obj 16 175 select 0 1 2 3 4 5; +#X obj 16 239 pack 0 0 0; +#X obj 16 209 f; +#X obj 96 239 pack 0 0 0; +#X obj 96 209 f; +#X obj 176 239 pack 0 0 0; +#X obj 176 209 f; +#X obj 256 239 pack 0 0 0; +#X obj 256 209 f; +#X obj 336 239 pack 0 0 0; +#X obj 336 209 f; +#X obj 416 239 pack 0 0 0; +#X obj 416 209 f; +#X connect 0 0 5 1; +#X connect 2 0 5 0; +#X connect 2 1 3 0; +#X connect 3 0 7 2; +#X connect 3 0 9 2; +#X connect 3 0 12 1; +#X connect 3 0 14 1; +#X connect 3 0 15 1; +#X connect 3 0 17 1; +#X connect 3 1 10 1; +#X connect 3 1 13 1; +#X connect 3 1 17 2; +#X connect 3 2 7 1; +#X connect 3 2 11 2; +#X connect 3 2 16 1; +#X connect 3 3 8 1; +#X connect 3 3 9 1; +#X connect 3 3 11 1; +#X connect 3 3 13 2; +#X connect 3 3 15 2; +#X connect 3 3 18 1; +#X connect 4 0 2 0; +#X connect 5 0 6 0; +#X connect 6 0 8 0; +#X connect 6 1 10 0; +#X connect 6 2 12 0; +#X connect 6 3 14 0; +#X connect 6 4 16 0; +#X connect 6 5 18 0; +#X connect 7 0 1 0; +#X connect 8 0 7 0; +#X connect 9 0 1 0; +#X connect 10 0 9 0; +#X connect 11 0 1 0; +#X connect 12 0 11 0; +#X connect 13 0 1 0; +#X connect 14 0 13 0; +#X connect 15 0 1 0; +#X connect 16 0 15 0; +#X connect 17 0 1 0; +#X connect 18 0 17 0; +#X restore 66 560 pd select; +#X f 28; +#X msg 20 621 \$1 \$1 \$1; +#X obj 20 593 clip 0 1; +#X obj 66 117 clip 0 1; +#X obj 175 119 clip 0 1; +#X obj 252 118 clip 0 1; +#X obj 252 142 select 1; +#X obj 175 462 t f f f f; +#X obj 260 237 t f f; +#X text 26 699 taken from the GEM helpfile hsv2rgb-help; +#X connect 0 0 2 0; +#X connect 0 1 3 0; +#X connect 1 0 0 0; +#X connect 2 0 31 0; +#X connect 3 0 32 0; +#X connect 3 1 33 0; +#X connect 3 2 34 0; +#X connect 5 0 1 0; +#X connect 7 0 9 0; +#X connect 8 0 37 0; +#X connect 9 0 12 0; +#X connect 9 1 8 0; +#X connect 10 0 9 0; +#X connect 12 0 20 0; +#X connect 13 0 28 0; +#X connect 14 0 15 0; +#X connect 15 0 13 0; +#X connect 16 0 28 1; +#X connect 17 0 18 0; +#X connect 18 0 16 0; +#X connect 19 0 17 0; +#X connect 20 0 19 1; +#X connect 20 1 21 0; +#X connect 21 0 22 0; +#X connect 22 0 26 1; +#X connect 23 0 28 2; +#X connect 24 0 25 0; +#X connect 25 0 23 0; +#X connect 26 0 24 0; +#X connect 27 0 14 0; +#X connect 27 1 19 0; +#X connect 27 2 26 0; +#X connect 28 0 29 0; +#X connect 29 0 6 0; +#X connect 30 0 6 0; +#X connect 31 0 30 0; +#X connect 32 0 27 0; +#X connect 33 0 36 0; +#X connect 34 0 35 0; +#X connect 35 0 10 0; +#X connect 35 1 7 0; +#X connect 36 0 13 1; +#X connect 36 1 16 1; +#X connect 36 2 23 1; +#X connect 36 3 28 3; +#X connect 37 0 29 1; +#X connect 37 1 12 1; +#X restore 509 303 pd hsv2rgb; +#X msg 125 360 S2 \$1 \$2 \$3; +#X msg 221 360 S3 \$1 \$2 \$3; +#X msg 317 360 S4 \$1 \$2 \$3; +#X msg 413 360 S5 \$1 \$2 \$3; +#X msg 509 360 S6 \$1 \$2 \$3; +#X obj 29 480 loadbang; +#X obj 29 534 print toVCV; +#X obj 30 92 metro 2000; +#X msg 62 386 L1 \$1 \$2 \$3; +#X msg 158 386 L2 \$1 \$2 \$3; +#X msg 254 386 L3 \$1 \$2 \$3; +#X msg 350 386 L4 \$1 \$2 \$3; +#X msg 447 386 L5 \$1 \$2 \$3; +#X msg 542 386 L6 \$1 \$2 \$3; +#X obj 266 534 dac~ 1 2 3 4 5 6; +#X msg 29 506 display Hello world!; +#X obj 29 329 t l l; +#X obj 125 329 t l l; +#X obj 221 329 t l l; +#X obj 317 329 t l l; +#X obj 413 329 t l l; +#X obj 509 329 t l l; +#X msg 125 276 \$1 1 1; +#X msg 30 118 0 \, 100 2000; +#X obj 125 201 + 16.6667; +#X obj 125 227 % 100; +#X obj 29 249 / 100; +#X obj 125 252 / 100; +#X obj 221 224 % 100; +#X obj 221 249 / 100; +#X msg 221 275 \$1 1 1; +#X obj 317 225 % 100; +#X obj 317 250 / 100; +#X msg 317 276 \$1 1 1; +#X obj 413 226 % 100; +#X obj 413 251 / 100; +#X msg 413 277 \$1 1 1; +#X obj 509 226 % 100; +#X obj 509 251 / 100; +#X msg 509 277 \$1 1 1; +#X obj 221 198 + 33.3334; +#X obj 413 200 + 66.6667; +#X obj 509 200 + 83.3334; +#X obj 29 167 t f f f f f f, f 69; +#X obj 317 199 + 50; +#X connect 0 0 29 0; +#X connect 2 0 1 0; +#X connect 3 0 4 0; +#X connect 4 0 6 0; +#X connect 5 0 0 0; +#X connect 6 0 20 0; +#X connect 7 0 56 0; +#X connect 8 0 30 0; +#X connect 9 0 31 0; +#X connect 10 0 32 0; +#X connect 11 0 33 0; +#X connect 12 0 34 0; +#X connect 13 0 1 0; +#X connect 14 0 1 0; +#X connect 15 0 1 0; +#X connect 16 0 1 0; +#X connect 17 0 1 0; +#X connect 18 0 28 0; +#X connect 20 0 36 0; +#X connect 21 0 1 0; +#X connect 22 0 1 0; +#X connect 23 0 1 0; +#X connect 24 0 1 0; +#X connect 25 0 1 0; +#X connect 26 0 1 0; +#X connect 28 0 19 0; +#X connect 29 0 2 0; +#X connect 29 1 21 0; +#X connect 30 0 13 0; +#X connect 30 1 22 0; +#X connect 31 0 14 0; +#X connect 31 1 23 0; +#X connect 32 0 15 0; +#X connect 32 1 24 0; +#X connect 33 0 16 0; +#X connect 33 1 25 0; +#X connect 34 0 17 0; +#X connect 34 1 26 0; +#X connect 35 0 8 0; +#X connect 36 0 7 0; +#X connect 37 0 38 0; +#X connect 38 0 40 0; +#X connect 39 0 5 0; +#X connect 40 0 35 0; +#X connect 41 0 42 0; +#X connect 42 0 43 0; +#X connect 43 0 9 0; +#X connect 44 0 45 0; +#X connect 45 0 46 0; +#X connect 46 0 10 0; +#X connect 47 0 48 0; +#X connect 48 0 49 0; +#X connect 49 0 11 0; +#X connect 50 0 51 0; +#X connect 51 0 52 0; +#X connect 52 0 12 0; +#X connect 53 0 41 0; +#X connect 54 0 47 0; +#X connect 55 0 50 0; +#X connect 56 0 39 0; +#X connect 56 1 37 0; +#X connect 56 2 53 0; +#X connect 56 3 57 0; +#X connect 56 4 54 0; +#X connect 56 5 55 0; +#X connect 57 0 44 0; From 65c7ba13da77a2eded0df4a8ba41c4ddbf0a9fe6 Mon Sep 17 00:00:00 2001 From: clwe Date: Wed, 1 Jul 2020 19:17:31 +0200 Subject: [PATCH 23/27] PD: audio output correction factor x4, shows version before loading patch --- src/LibPDEngine.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/LibPDEngine.cpp b/src/LibPDEngine.cpp index fe4199d..381714d 100644 --- a/src/LibPDEngine.cpp +++ b/src/LibPDEngine.cpp @@ -86,6 +86,12 @@ struct LibPDEngine : ScriptEngine { libpd_start_message(1); // one enstry in list libpd_add_float(1.0f); libpd_finish_message("pd", "dsp"); + + std::string version = "pd "+std::to_string(PD_MAJOR_VERSION)+"."+ + std::to_string(PD_MINOR_VERSION)+"."+ + std::to_string(PD_BUGFIX_VERSION); + + display(version); std::string name = string::filename(path); std::string dir = string::directory(path); @@ -147,7 +153,8 @@ struct LibPDEngine : ScriptEngine { //return samples to prototype for (int s = 0; s < _pd_block_size; s++) { for (int r = 0; r < rows; r++) { - block->outputs[r][s] = _output[s*rows+r]; + block->outputs[r][s] = _output[s*rows+r] * 4; + // there is a correction multilpier, because libpd's output is too quiet(?) } } @@ -231,7 +238,7 @@ void LibPDEngine::receiveLights(const char *s) { } else { // print out on command line - std::cout << std::string(s) << std::endl; + std::cout << "libpd prototype unrecognizes message: " << std::string(s) << std::endl; } } @@ -296,10 +303,6 @@ void LibPDEngine::sendInitialStates(const ProcessBlock* block){ sendKnob(i, block->knobs[i]); sendSwitch(i, block->knobs[i]); } - std::string version = "pd "+std::to_string(PD_MAJOR_VERSION)+"."+ - std::to_string(PD_MINOR_VERSION)+"." - +std::to_string(PD_BUGFIX_VERSION); - for(int i=0; i Date: Wed, 1 Jul 2020 19:13:17 +0200 Subject: [PATCH 24/27] Pd: updated rainbow example --- examples/rainbow.pd | 120 +++++++++++++++++++++++++++++++------------- 1 file changed, 84 insertions(+), 36 deletions(-) diff --git a/examples/rainbow.pd b/examples/rainbow.pd index 1165921..11d6266 100644 --- a/examples/rainbow.pd +++ b/examples/rainbow.pd @@ -1,4 +1,4 @@ -#N canvas 547 398 649 666 12; +#N canvas 547 398 828 731 12; #N canvas 250 355 563 749 hsv2rgb 0; #X obj 20 64 route 0; #X msg 20 36 \$2 \$3 \$1; @@ -148,12 +148,12 @@ #X connect 36 3 28 3; #X connect 37 0 29 1; #X connect 37 1 12 1; -#X restore 29 303 pd hsv2rgb; -#X obj 29 438 print toVCV; -#X msg 29 360 S1 \$1 \$2 \$3; +#X restore 29 343 pd hsv2rgb; +#X obj 29 478 print toVCV; +#X msg 29 400 S1 \$1 \$2 \$3; #X obj 30 16 loadbang; #X msg 30 41 1; -#X msg 29 275 \$1 1 1; +#X msg 29 315 \$1 1 1; #X obj 30 67 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 1 1 ; #X obj 30 143 line; @@ -306,7 +306,7 @@ #X connect 36 3 28 3; #X connect 37 0 29 1; #X connect 37 1 12 1; -#X restore 125 303 pd hsv2rgb; +#X restore 125 343 pd hsv2rgb; #N canvas 250 355 563 749 hsv2rgb 0; #X obj 20 64 route 0; #X msg 20 36 \$2 \$3 \$1; @@ -456,7 +456,7 @@ #X connect 36 3 28 3; #X connect 37 0 29 1; #X connect 37 1 12 1; -#X restore 221 303 pd hsv2rgb; +#X restore 221 343 pd hsv2rgb; #N canvas 250 355 563 749 hsv2rgb 0; #X obj 20 64 route 0; #X msg 20 36 \$2 \$3 \$1; @@ -606,7 +606,7 @@ #X connect 36 3 28 3; #X connect 37 0 29 1; #X connect 37 1 12 1; -#X restore 317 303 pd hsv2rgb; +#X restore 317 343 pd hsv2rgb; #N canvas 250 355 563 749 hsv2rgb 0; #X obj 20 64 route 0; #X msg 20 36 \$2 \$3 \$1; @@ -756,7 +756,7 @@ #X connect 36 3 28 3; #X connect 37 0 29 1; #X connect 37 1 12 1; -#X restore 413 303 pd hsv2rgb; +#X restore 413 343 pd hsv2rgb; #N canvas 250 355 563 749 hsv2rgb 0; #X obj 20 64 route 0; #X msg 20 36 \$2 \$3 \$1; @@ -906,30 +906,30 @@ #X connect 36 3 28 3; #X connect 37 0 29 1; #X connect 37 1 12 1; -#X restore 509 303 pd hsv2rgb; -#X msg 125 360 S2 \$1 \$2 \$3; -#X msg 221 360 S3 \$1 \$2 \$3; -#X msg 317 360 S4 \$1 \$2 \$3; -#X msg 413 360 S5 \$1 \$2 \$3; -#X msg 509 360 S6 \$1 \$2 \$3; -#X obj 29 480 loadbang; -#X obj 29 534 print toVCV; +#X restore 509 343 pd hsv2rgb; +#X msg 125 400 S2 \$1 \$2 \$3; +#X msg 221 400 S3 \$1 \$2 \$3; +#X msg 317 400 S4 \$1 \$2 \$3; +#X msg 413 400 S5 \$1 \$2 \$3; +#X msg 509 400 S6 \$1 \$2 \$3; +#X obj 294 17 loadbang; +#X obj 294 71 print toVCV; #X obj 30 92 metro 2000; -#X msg 62 386 L1 \$1 \$2 \$3; -#X msg 158 386 L2 \$1 \$2 \$3; -#X msg 254 386 L3 \$1 \$2 \$3; -#X msg 350 386 L4 \$1 \$2 \$3; -#X msg 447 386 L5 \$1 \$2 \$3; -#X msg 542 386 L6 \$1 \$2 \$3; -#X obj 266 534 dac~ 1 2 3 4 5 6; -#X msg 29 506 display Hello world!; -#X obj 29 329 t l l; -#X obj 125 329 t l l; -#X obj 221 329 t l l; -#X obj 317 329 t l l; -#X obj 413 329 t l l; -#X obj 509 329 t l l; -#X msg 125 276 \$1 1 1; +#X msg 62 426 L1 \$1 \$2 \$3; +#X msg 158 426 L2 \$1 \$2 \$3; +#X msg 254 426 L3 \$1 \$2 \$3; +#X msg 350 426 L4 \$1 \$2 \$3; +#X msg 447 426 L5 \$1 \$2 \$3; +#X msg 542 426 L6 \$1 \$2 \$3; +#X obj 29 592 dac~ 1 2 3 4 5 6, f 69; +#X msg 294 43 display Hello world!; +#X obj 29 369 t l l; +#X obj 125 369 t l l; +#X obj 221 369 t l l; +#X obj 317 369 t l l; +#X obj 413 369 t l l; +#X obj 509 369 t l l; +#X msg 125 316 \$1 1 1; #X msg 30 118 0 \, 100 2000; #X obj 125 201 + 16.6667; #X obj 125 227 % 100; @@ -937,21 +937,45 @@ #X obj 125 252 / 100; #X obj 221 224 % 100; #X obj 221 249 / 100; -#X msg 221 275 \$1 1 1; +#X msg 221 315 \$1 1 1; #X obj 317 225 % 100; #X obj 317 250 / 100; -#X msg 317 276 \$1 1 1; +#X msg 317 316 \$1 1 1; #X obj 413 226 % 100; #X obj 413 251 / 100; -#X msg 413 277 \$1 1 1; +#X msg 413 317 \$1 1 1; #X obj 509 226 % 100; #X obj 509 251 / 100; -#X msg 509 277 \$1 1 1; +#X msg 509 317 \$1 1 1; #X obj 221 198 + 33.3334; #X obj 413 200 + 66.6667; #X obj 509 200 + 83.3334; #X obj 29 167 t f f f f f f, f 69; #X obj 317 199 + 50; +#X obj 40 281 s out1; +#X obj 30 511 r out1; +#X obj 127 511 r out2; +#X obj 316 509 r out4; +#X obj 223 509 r out3; +#X obj 413 509 r out5; +#X obj 508 507 r out6; +#X obj 136 282 s out2; +#X obj 229 283 s out3; +#X obj 328 283 s out4; +#X obj 427 286 s out5; +#X obj 529 284 s out6; +#X obj 127 536 cos~; +#X obj 222 534 cos~; +#X obj 316 534 cos~; +#X obj 413 534 cos~; +#X obj 508 532 cos~; +#X obj 30 564 +~ 1; +#X obj 30 536 cos~; +#X obj 126 562 +~ 1; +#X obj 222 561 +~ 1; +#X obj 316 559 +~ 1; +#X obj 413 560 +~ 1; +#X obj 508 560 +~ 1; #X connect 0 0 29 0; #X connect 2 0 1 0; #X connect 3 0 4 0; @@ -995,18 +1019,24 @@ #X connect 37 0 38 0; #X connect 38 0 40 0; #X connect 39 0 5 0; +#X connect 39 0 58 0; #X connect 40 0 35 0; +#X connect 40 0 65 0; #X connect 41 0 42 0; #X connect 42 0 43 0; +#X connect 42 0 66 0; #X connect 43 0 9 0; #X connect 44 0 45 0; #X connect 45 0 46 0; +#X connect 45 0 67 0; #X connect 46 0 10 0; #X connect 47 0 48 0; #X connect 48 0 49 0; +#X connect 48 0 68 0; #X connect 49 0 11 0; #X connect 50 0 51 0; #X connect 51 0 52 0; +#X connect 51 0 69 0; #X connect 52 0 12 0; #X connect 53 0 41 0; #X connect 54 0 47 0; @@ -1018,3 +1048,21 @@ #X connect 56 4 54 0; #X connect 56 5 55 0; #X connect 57 0 44 0; +#X connect 59 0 76 0; +#X connect 60 0 70 0; +#X connect 61 0 72 0; +#X connect 62 0 71 0; +#X connect 63 0 73 0; +#X connect 64 0 74 0; +#X connect 70 0 77 0; +#X connect 71 0 78 0; +#X connect 72 0 79 0; +#X connect 73 0 80 0; +#X connect 74 0 81 0; +#X connect 75 0 27 0; +#X connect 76 0 75 0; +#X connect 77 0 27 1; +#X connect 78 0 27 2; +#X connect 79 0 27 3; +#X connect 80 0 27 4; +#X connect 81 0 27 5; From 572ae136f80b722723e9ac7ae226013582437b7d Mon Sep 17 00:00:00 2001 From: clwe Date: Wed, 1 Jul 2020 19:22:35 +0200 Subject: [PATCH 25/27] PD: audio output correction factor is x5 --- src/LibPDEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/LibPDEngine.cpp b/src/LibPDEngine.cpp index 381714d..606bf9f 100644 --- a/src/LibPDEngine.cpp +++ b/src/LibPDEngine.cpp @@ -153,7 +153,7 @@ struct LibPDEngine : ScriptEngine { //return samples to prototype for (int s = 0; s < _pd_block_size; s++) { for (int r = 0; r < rows; r++) { - block->outputs[r][s] = _output[s*rows+r] * 4; + block->outputs[r][s] = _output[s*rows+r] * 5; // there is a correction multilpier, because libpd's output is too quiet(?) } } From 59e8f388bb3915c5f0273fc96e9ba267b8a3110a Mon Sep 17 00:00:00 2001 From: max Date: Thu, 2 Jul 2020 01:15:16 +0200 Subject: [PATCH 26/27] Added info to README.md --- Makefile | 9 +++------ README.md | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 56e4eab..8a08076 100644 --- a/Makefile +++ b/Makefile @@ -14,21 +14,18 @@ DISTRIBUTABLES += $(wildcard LICENSE*) include $(RACK_DIR)/arch.mk DUKTAPE ?= 0 -QUICKJS ?= 0 +QUICKJS ?= 1 LUAJIT ?= 1 PYTHON ?= 0 SUPERCOLLIDER ?= 0 -<<<<<<< HEAD VULT ?= 1 +LIBPD ?= 1 # Vult depends on both LuaJIT and QuickJS ifeq ($(VULT), 1) QUICKJS := 1 LUAJIT := 1 endif -======= -LIBPD ?= 1 ->>>>>>> implements Makefile build flow # Entropia File System Watcher efsw := dep/lib/libefsw-static-release.a @@ -41,7 +38,7 @@ $(efsw): cd efsw && cp lib/libefsw-static-release.a $(DEP_PATH)/lib/ cd efsw && cp -R include/efsw $(DEP_PATH)/include/ -# LibPD +# libpd ifeq ($(LIBPD), 1) libpd := dep/lib/libpd.a SOURCES += src/LibPDEngine.cpp diff --git a/README.md b/README.md index 268cc6c..8d6bc4b 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Supported scripting languages: - JavaScript (ES2020) (.js) - [Lua](https://www.lua.org/) (.lua) - [Vult](https://github.com/modlfo/vult) (.vult) +- [Pure Data](https://puredata.info) (.pd) - [Add your own below](#adding-a-script-engine) [Discussion thread](https://community.vcvrack.com/t/vcv-prototype/3271) @@ -116,6 +117,23 @@ sudo apt install premake4 sudo pacman -S premake ``` +## Build +### Add path to Rack-SDK +```bash +export RACK_DIR=/set/path/to/Rack-SDK/ +``` + +### load submodules +```bash +git submodule update --init --recursive +``` + +### Make +```bash +make dep +make +``` + ## Adding a script engine - Add your scripting language library to the build system so it builds with `make dep`, following the Duktape example in `Makefile`. @@ -131,4 +149,5 @@ sudo pacman -S premake - [Andrew Belt](https://github.com/AndrewBelt): host code, Duktape (JavaScript, not used), LuaJIT (Lua), Python (in development) - [Jerry Sievert](https://github.com/JerrySievert): QuickJS (JavaScript) - [Leonardo Laguna Ruiz](https://github.com/modlfo): Vult +- [CHAIR](https://chair.audio) [Clemens Wegener (libpd), Max Neupert (patches)] : libpd - add your name here From 2d8748675208b3c97908663eb33499dbf4213d11 Mon Sep 17 00:00:00 2001 From: max Date: Thu, 2 Jul 2020 02:03:33 +0200 Subject: [PATCH 27/27] Pd: updated rainbow example --- examples/rainbow.pd | 164 ++++++++++++++++++++++++-------------------- 1 file changed, 88 insertions(+), 76 deletions(-) diff --git a/examples/rainbow.pd b/examples/rainbow.pd index 11d6266..c67a266 100644 --- a/examples/rainbow.pd +++ b/examples/rainbow.pd @@ -1,4 +1,4 @@ -#N canvas 547 398 828 731 12; +#N canvas 698 144 821 731 12; #N canvas 250 355 563 749 hsv2rgb 0; #X obj 20 64 route 0; #X msg 20 36 \$2 \$3 \$1; @@ -912,8 +912,6 @@ #X msg 317 400 S4 \$1 \$2 \$3; #X msg 413 400 S5 \$1 \$2 \$3; #X msg 509 400 S6 \$1 \$2 \$3; -#X obj 294 17 loadbang; -#X obj 294 71 print toVCV; #X obj 30 92 metro 2000; #X msg 62 426 L1 \$1 \$2 \$3; #X msg 158 426 L2 \$1 \$2 \$3; @@ -922,7 +920,6 @@ #X msg 447 426 L5 \$1 \$2 \$3; #X msg 542 426 L6 \$1 \$2 \$3; #X obj 29 592 dac~ 1 2 3 4 5 6, f 69; -#X msg 294 43 display Hello world!; #X obj 29 369 t l l; #X obj 125 369 t l l; #X obj 221 369 t l l; @@ -930,7 +927,6 @@ #X obj 413 369 t l l; #X obj 509 369 t l l; #X msg 125 316 \$1 1 1; -#X msg 30 118 0 \, 100 2000; #X obj 125 201 + 16.6667; #X obj 125 227 % 100; #X obj 29 249 / 100; @@ -976,93 +972,109 @@ #X obj 316 559 +~ 1; #X obj 413 560 +~ 1; #X obj 508 560 +~ 1; -#X connect 0 0 29 0; +#N canvas 0 68 624 300 display 0; +#X obj 29 10 loadbang; +#X msg 29 34 44; +#X obj 29 140 print toVCV; +#X obj 29 90 list prepend display; +#X obj 29 115 list trim; +#X obj 29 62 makefilename Hello%c\ world!; +#X text 264 22 A somewhat ugly workaround just to print a comma. In +Pd \, commas separate messages., f 32; +#X connect 0 0 1 0; +#X connect 1 0 5 0; +#X connect 3 0 4 0; +#X connect 4 0 2 0; +#X connect 5 0 3 0; +#X restore 229 19 pd display; +#X text 608 326 This should be an abstraction \, but to keep the example +directory tidy it here is duplicated code., f 28; +#X msg 30 118 100 \, 0 2000; +#X connect 0 0 26 0; #X connect 2 0 1 0; #X connect 3 0 4 0; #X connect 4 0 6 0; #X connect 5 0 0 0; -#X connect 6 0 20 0; -#X connect 7 0 56 0; -#X connect 8 0 30 0; -#X connect 9 0 31 0; -#X connect 10 0 32 0; -#X connect 11 0 33 0; -#X connect 12 0 34 0; +#X connect 6 0 18 0; +#X connect 7 0 52 0; +#X connect 8 0 27 0; +#X connect 9 0 28 0; +#X connect 10 0 29 0; +#X connect 11 0 30 0; +#X connect 12 0 31 0; #X connect 13 0 1 0; #X connect 14 0 1 0; #X connect 15 0 1 0; #X connect 16 0 1 0; #X connect 17 0 1 0; -#X connect 18 0 28 0; -#X connect 20 0 36 0; +#X connect 18 0 80 0; +#X connect 19 0 1 0; +#X connect 20 0 1 0; #X connect 21 0 1 0; #X connect 22 0 1 0; #X connect 23 0 1 0; #X connect 24 0 1 0; -#X connect 25 0 1 0; -#X connect 26 0 1 0; -#X connect 28 0 19 0; -#X connect 29 0 2 0; -#X connect 29 1 21 0; -#X connect 30 0 13 0; -#X connect 30 1 22 0; -#X connect 31 0 14 0; -#X connect 31 1 23 0; -#X connect 32 0 15 0; -#X connect 32 1 24 0; -#X connect 33 0 16 0; -#X connect 33 1 25 0; -#X connect 34 0 17 0; -#X connect 34 1 26 0; -#X connect 35 0 8 0; -#X connect 36 0 7 0; +#X connect 26 0 2 0; +#X connect 26 1 19 0; +#X connect 27 0 13 0; +#X connect 27 1 20 0; +#X connect 28 0 14 0; +#X connect 28 1 21 0; +#X connect 29 0 15 0; +#X connect 29 1 22 0; +#X connect 30 0 16 0; +#X connect 30 1 23 0; +#X connect 31 0 17 0; +#X connect 31 1 24 0; +#X connect 32 0 8 0; +#X connect 33 0 34 0; +#X connect 34 0 36 0; +#X connect 35 0 5 0; +#X connect 35 0 54 0; +#X connect 36 0 32 0; +#X connect 36 0 61 0; #X connect 37 0 38 0; -#X connect 38 0 40 0; -#X connect 39 0 5 0; -#X connect 39 0 58 0; -#X connect 40 0 35 0; -#X connect 40 0 65 0; +#X connect 38 0 39 0; +#X connect 38 0 62 0; +#X connect 39 0 9 0; +#X connect 40 0 41 0; #X connect 41 0 42 0; -#X connect 42 0 43 0; -#X connect 42 0 66 0; -#X connect 43 0 9 0; +#X connect 41 0 63 0; +#X connect 42 0 10 0; +#X connect 43 0 44 0; #X connect 44 0 45 0; -#X connect 45 0 46 0; -#X connect 45 0 67 0; -#X connect 46 0 10 0; +#X connect 44 0 64 0; +#X connect 45 0 11 0; +#X connect 46 0 47 0; #X connect 47 0 48 0; -#X connect 48 0 49 0; -#X connect 48 0 68 0; -#X connect 49 0 11 0; -#X connect 50 0 51 0; -#X connect 51 0 52 0; -#X connect 51 0 69 0; -#X connect 52 0 12 0; -#X connect 53 0 41 0; -#X connect 54 0 47 0; -#X connect 55 0 50 0; -#X connect 56 0 39 0; -#X connect 56 1 37 0; -#X connect 56 2 53 0; -#X connect 56 3 57 0; -#X connect 56 4 54 0; -#X connect 56 5 55 0; -#X connect 57 0 44 0; -#X connect 59 0 76 0; +#X connect 47 0 65 0; +#X connect 48 0 12 0; +#X connect 49 0 37 0; +#X connect 50 0 43 0; +#X connect 51 0 46 0; +#X connect 52 0 35 0; +#X connect 52 1 33 0; +#X connect 52 2 49 0; +#X connect 52 3 53 0; +#X connect 52 4 50 0; +#X connect 52 5 51 0; +#X connect 53 0 40 0; +#X connect 55 0 72 0; +#X connect 56 0 66 0; +#X connect 57 0 68 0; +#X connect 58 0 67 0; +#X connect 59 0 69 0; #X connect 60 0 70 0; -#X connect 61 0 72 0; -#X connect 62 0 71 0; -#X connect 63 0 73 0; -#X connect 64 0 74 0; +#X connect 66 0 73 0; +#X connect 67 0 74 0; +#X connect 68 0 75 0; +#X connect 69 0 76 0; #X connect 70 0 77 0; -#X connect 71 0 78 0; -#X connect 72 0 79 0; -#X connect 73 0 80 0; -#X connect 74 0 81 0; -#X connect 75 0 27 0; -#X connect 76 0 75 0; -#X connect 77 0 27 1; -#X connect 78 0 27 2; -#X connect 79 0 27 3; -#X connect 80 0 27 4; -#X connect 81 0 27 5; +#X connect 71 0 25 0; +#X connect 72 0 71 0; +#X connect 73 0 25 1; +#X connect 74 0 25 2; +#X connect 75 0 25 3; +#X connect 76 0 25 4; +#X connect 77 0 25 5; +#X connect 80 0 7 0;