diff --git a/CMakeLists.txt b/CMakeLists.txt index 3283814..af3133d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.13.0 FATAL_ERROR) -SET(VERSION 0.3.4) +SET(VERSION 0.3.5) project(ChucKDesigner VERSION ${VERSION}) set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ChucKDesignerCHOP) diff --git a/README.md b/README.md index de99c67..8a27efa 100644 --- a/README.md +++ b/README.md @@ -44,12 +44,11 @@ Install Python 3 Install CMake and confirm that it's installed by running cmake --version in a command prompt.
Then in this repository, -
cmake . -DCMAKE_BUILD_TYPE=Release -Bbuild -DPYTHONVER="3.11"
-Finally, open build/ChucKDesignerCHOP.sln and compile. +Then, cmake --build build --config Release to compile. ### MacOS diff --git a/src/Plugin_ChucK.cpp b/src/Plugin_ChucK.cpp index 1987bf2..b7c31dd 100644 --- a/src/Plugin_ChucK.cpp +++ b/src/Plugin_ChucK.cpp @@ -11,8 +11,12 @@ #include "Plugin_ChucK.h" #include "chuck_globals.h" +#include "chuck_vm.h" +#include "util_platforms.h" // for ck_usleep + #include #include + #ifndef WIN32 #include #endif @@ -545,7 +549,9 @@ namespace ChucK_For_TouchDesigner } - CHUCKDESIGNERSHARED_API bool getGlobalAssociativeIntArrayValueWithID(unsigned int chuckID, t_CKINT callbackID, const char* name, char* key, void(*callback)(t_CKINT, t_CKINT)) + CHUCKDESIGNERSHARED_API bool getGlobalAssociativeIntArrayValueWithID( + unsigned int chuckID, t_CKINT callbackID, const char* name, + char* key, void(*callback)(t_CKINT, t_CKINT)) { if (chuck_instances.count(chuckID) == 0) { return false; } Chuck_Globals_Manager* gm = chuck_instances[chuckID]->globals(); @@ -555,6 +561,27 @@ namespace ChucK_For_TouchDesigner name, callbackID, key, callback); } + // internal/audio-thread-friendly global array setter + CHUCKDESIGNERSHARED_API bool setGlobalIntArray_AT( + unsigned int chuckID,const char* name, t_CKINT arrayValues[], unsigned int numValues) + { + if (chuck_instances.count(chuckID) == 0) { return false; } + Chuck_Globals_Manager* gm = chuck_instances[chuckID]->globals(); + if (gm == NULL) { return false; } + + return gm->set_global_int_array(name, arrayValues, numValues); + } + + // internal/audio-thread-friendly + CHUCKDESIGNERSHARED_API bool setGlobalIntArrayValue_AT( + unsigned int chuckID, const char* name, unsigned int index, t_CKINT value) + { + if (chuck_instances.count(chuckID) == 0) { return false; } + Chuck_Globals_Manager* gm = chuck_instances[chuckID]->globals(); + if (gm == NULL) { return false; } + + return gm->set_global_float_array_value(name, index, value); + } // float array methods CHUCKDESIGNERSHARED_API bool setGlobalFloatArray(unsigned int chuckID, @@ -700,6 +727,27 @@ namespace ChucK_For_TouchDesigner } + + // internal/audio-thread-friendly global array setter + CHUCKDESIGNERSHARED_API bool setGlobalFloatArray_AT( + unsigned int chuckID, const char* name, t_CKFLOAT arrayValues[], unsigned int numValues) + { + if (chuck_instances.count(chuckID) == 0) { return false; } + Chuck_Globals_Manager* gm = chuck_instances[chuckID]->globals(); + if (gm == NULL) { return false; } + + return gm->set_global_float_array(name, arrayValues, numValues); + } + + CHUCKDESIGNERSHARED_API bool setGlobalFloatArrayValue_AT( + unsigned int chuckID, const char* name, unsigned int index, t_CKFLOAT value) { + if (chuck_instances.count(chuckID) == 0) { return false; } + Chuck_Globals_Manager* gm = chuck_instances[chuckID]->globals(); + if (gm == NULL) { return false; } + + return gm->set_global_float_array_value(name, index, value); + } + CHUCKDESIGNERSHARED_API bool setChoutCallback(unsigned int chuckID, void (*callback)(const char*)) { return chuck_instances[chuckID]->setChoutCallback(callback); @@ -1028,6 +1076,9 @@ namespace ChucK_For_TouchDesigner data_instances.erase( chuckID ); } + // wait a bit + ck_usleep(30000); + op_ids_to_chuck_ids.erase(opId); // todo: is this dangerous? @@ -1077,13 +1128,15 @@ namespace ChucK_For_TouchDesigner CHUCKDESIGNERSHARED_API void cleanRegisteredChucks() { // first, invalidate all callbacks' references to chucks - for( std::map< unsigned int, EffectData::Data * >::iterator it = - data_instances.begin(); it != data_instances.end(); it++ ) + for (std::map::iterator it = data_instances.begin(); it != data_instances.end(); it++) { - EffectData::Data * data = it->second; + EffectData::Data* data = it->second; data->myId = -1; } + // wait for callbacks to finish their current run + ck_usleep(30000); + // next, delete chucks for( std::map< unsigned int, ChucK * >::iterator it = chuck_instances.begin(); it != chuck_instances.end(); it++ ) diff --git a/src/Plugin_ChucK.h b/src/Plugin_ChucK.h index 81950fa..d0b91c0 100644 --- a/src/Plugin_ChucK.h +++ b/src/Plugin_ChucK.h @@ -79,6 +79,8 @@ extern "C" { CHUCKDESIGNERSHARED_API bool getGlobalAssociativeIntArrayValue(unsigned int chuckID, const char* name, char* key, void (*callback)(t_CKINT)); CHUCKDESIGNERSHARED_API bool getNamedGlobalAssociativeIntArrayValue(unsigned int chuckID, const char* name, char* key, void (*callback)(const char*, t_CKINT)); CHUCKDESIGNERSHARED_API bool getGlobalAssociativeIntArrayValueWithID(unsigned int chuckID, t_CKINT callbackID, const char* name, char* key, void (*callback)(t_CKINT, t_CKINT)); + CHUCKDESIGNERSHARED_API bool setGlobalIntArray_AT(unsigned int chuckID, const char* name, t_CKINT arrayValues[], unsigned int numValues); // internal/audio-thread-friendly global array setter + CHUCKDESIGNERSHARED_API bool setGlobalIntArrayValue_AT(unsigned int chuckID, const char* name, unsigned int index, t_CKINT value); // internal/audio-thread-friendly // TODO: set entire dict, add to dict in batch; get entire dict // float array methods @@ -94,7 +96,8 @@ extern "C" { CHUCKDESIGNERSHARED_API bool getGlobalAssociativeFloatArrayValue(unsigned int chuckID, const char* name, char* key, void (*callback)(t_CKFLOAT)); CHUCKDESIGNERSHARED_API bool getNamedGlobalAssociativeFloatArrayValue(unsigned int chuckID, const char* name, char* key, void (*callback)(const char*, t_CKFLOAT)); CHUCKDESIGNERSHARED_API bool getGlobalAssociativeFloatArrayValueWithID(unsigned int chuckID, t_CKINT callbackID, const char* name, char* key, void (*callback)(t_CKINT, t_CKFLOAT)); - + CHUCKDESIGNERSHARED_API bool setGlobalFloatArray_AT(unsigned int chuckID, const char* name, t_CKFLOAT arrayValues[], unsigned int numValues); // internal/audio-thread-friendly global array setter + CHUCKDESIGNERSHARED_API bool setGlobalFloatArrayValue_AT(unsigned int chuckID, const char* name, unsigned int index, t_CKFLOAT value); // internal/audio-thread-friendly CHUCKDESIGNERSHARED_API bool initChuckInstance(unsigned int chuckID, unsigned int sampleRate, unsigned int numInChannels, unsigned int numOutChannels, string globalDir); CHUCKDESIGNERSHARED_API bool clearChuckInstance(unsigned int chuckID); diff --git a/thirdparty/chuck b/thirdparty/chuck index 2b886d7..c63d71c 160000 --- a/thirdparty/chuck +++ b/thirdparty/chuck @@ -1 +1 @@ -Subproject commit 2b886d7f190d3e9a82be0b0588656105e4666274 +Subproject commit c63d71c1c7082f8c865bd29540368518d5a71960