re-add mainthreadhook
Unified · Split
| @@ -1126,3 +1126,24 @@ void ChucK::poop() · 1125 unmodified lines | |||
| 1126 | { | 1126 | { |
| 1127 | ::uh(); | 1127 | ::uh(); |
| 1128 | } | 1128 | } |
| 1129 | |||
| 1130 | |||
| 1131 | |||
| 1132 | //----------------------------------------------------------------------------- | ||
| 1133 | // name: setMainThreadHook() | ||
| 1134 | // desc: | ||
| 1135 | //----------------------------------------------------------------------------- | ||
| 1136 | bool ChucK::setMainThreadHook(Chuck_DL_MainThreadHook * hook) | ||
| 1137 | { | ||
| 1138 | m_hook = hook; | ||
| 1139 | return true; | ||
| 1140 | } | ||
| 1141 | |||
| 1142 | //----------------------------------------------------------------------------- | ||
| 1143 | // name: getMainThreadHook() | ||
| 1144 | // desc: | ||
| 1145 | //----------------------------------------------------------------------------- | ||
| 1146 | Chuck_DL_MainThreadHook * ChucK::getMainThreadHook() | ||
| 1147 | { | ||
| 1148 | return m_hook; | ||
| 1149 | } | ||
| @@ -122,6 +122,10 @@ public: · 121 unmodified lines | |||
| 122 | public: | 122 | public: |
| 123 | // additional native chuck bindings/types (use with extra caution) | 123 | // additional native chuck bindings/types (use with extra caution) |
| 124 | bool bind( f_ck_query queryFunc, const std::string & name ); | 124 | bool bind( f_ck_query queryFunc, const std::string & name ); |
| 125 | |||
| 126 | bool setMainThreadHook(Chuck_DL_MainThreadHook * hook); | ||
| 127 | |||
| 128 | Chuck_DL_MainThreadHook * getMainThreadHook(); | ||
| 125 | 129 | ||
| 126 | public: | 130 | public: |
| 127 | // get VM (dangerous) | 131 | // get VM (dangerous) |
| @@ -200,6 +204,8 @@ protected: · 72 unmodified lines | |||
| 200 | std::map< std::string, std::list<std::string> > m_listParams; | 204 | std::map< std::string, std::list<std::string> > m_listParams; |
| 201 | // did user init? | 205 | // did user init? |
| 202 | t_CKBOOL m_init; | 206 | t_CKBOOL m_init; |
| 207 | // main thread "hook" (if there is a main thread) | ||
| 208 | Chuck_DL_MainThreadHook * m_hook = nullptr; | ||
| 203 | }; | 209 | }; |
| 204 | 210 | ||
| 205 | 211 | ||
| @@ -40,6 +40,7 @@ · 39 unmodified lines | |||
| 40 | #include "chuck_instr.h" | 40 | #include "chuck_instr.h" |
| 41 | #include "chuck_compile.h" | 41 | #include "chuck_compile.h" |
| 42 | #include "chuck_vm.h" | 42 | #include "chuck_vm.h" |
| 43 | #include "chuck.h" | ||
| 43 | #include <sstream> | 44 | #include <sstream> |
| 44 | using namespace std; | 45 | using namespace std; |
| 45 | 46 | ||
| @@ -556,6 +557,17 @@ t_CKBOOL CK_DLL_CALL ck_end_class( Chuck_DL_Query * query ) · 510 unmodified lines | |||
| 556 | } | 557 | } |
| 557 | 558 | ||
| 558 | 559 | ||
| 560 | //----------------------------------------------------------------------------- | ||
| 561 | // name: ck_create_main_thread_hook() | ||
| 562 | // desc: ... | ||
| 563 | //----------------------------------------------------------------------------- | ||
| 564 | Chuck_DL_MainThreadHook * CK_DLL_CALL ck_create_main_thread_hook( Chuck_DL_Query * query, | ||
| 565 | f_mainthreadhook hook, | ||
| 566 | f_mainthreadquit quit, | ||
| 567 | void * bindle ) | ||
| 568 | { | ||
| 569 | return new Chuck_DL_MainThreadHook( hook, quit, bindle, query->carrier() ); | ||
| 570 | } | ||
| 559 | 571 | ||
| 560 | 572 | ||
| 561 | //----------------------------------------------------------------------------- | 573 | //----------------------------------------------------------------------------- |
| @@ -935,6 +947,7 @@ Chuck_DL_Query::Chuck_DL_Query( Chuck_Carrier * carrier ) · 373 unmodified lines | |||
| 935 | doc_class = ck_doc_class; | 947 | doc_class = ck_doc_class; |
| 936 | doc_func = ck_doc_func; | 948 | doc_func = ck_doc_func; |
| 937 | doc_var = ck_doc_var; | 949 | doc_var = ck_doc_var; |
| 950 | create_main_thread_hook = ck_create_main_thread_hook; | ||
| 938 | m_carrier = carrier; | 951 | m_carrier = carrier; |
| 939 | 952 | ||
| 940 | // memset(reserved2, NULL, sizeof(void*)*RESERVED_SIZE); | 953 | // memset(reserved2, NULL, sizeof(void*)*RESERVED_SIZE); |
| @@ -1005,6 +1018,41 @@ Chuck_DL_Func::~Chuck_DL_Func() · 64 unmodified lines | |||
| 1005 | } | 1018 | } |
| 1006 | 1019 | ||
| 1007 | 1020 | ||
| 1021 | /******************************************************************************* | ||
| 1022 | |||
| 1023 | Main Thread Hook stuff | ||
| 1024 | |||
| 1025 | *******************************************************************************/ | ||
| 1026 | |||
| 1027 | t_CKBOOL ck_mthook_activate(Chuck_DL_MainThreadHook *hook) | ||
| 1028 | { | ||
| 1029 | hook->m_carrier->chuck->setMainThreadHook(hook); | ||
| 1030 | hook->m_active = true; | ||
| 1031 | return hook->m_active; | ||
| 1032 | } | ||
| 1033 | |||
| 1034 | t_CKBOOL ck_mthook_deactivate(Chuck_DL_MainThreadHook *hook) | ||
| 1035 | { | ||
| 1036 | hook->m_carrier->chuck->setMainThreadHook(nullptr); | ||
| 1037 | hook->m_active = false; | ||
| 1038 | return hook->m_active; | ||
| 1039 | } | ||
| 1040 | |||
| 1041 | //----------------------------------------------------------------------------- | ||
| 1042 | // name: Chuck_DL_MainThreadHook() | ||
| 1043 | // desc: ... | ||
| 1044 | //----------------------------------------------------------------------------- | ||
| 1045 | Chuck_DL_MainThreadHook::Chuck_DL_MainThreadHook(f_mainthreadhook hook, f_mainthreadquit quit, | ||
| 1046 | void * bindle, Chuck_Carrier * carrier) : | ||
| 1047 | m_hook(hook), | ||
| 1048 | m_quit(quit), | ||
| 1049 | m_carrier(carrier), | ||
| 1050 | m_bindle(bindle), | ||
| 1051 | activate(ck_mthook_activate), | ||
| 1052 | deactivate(ck_mthook_deactivate), | ||
| 1053 | m_active(FALSE) | ||
| 1054 | { } | ||
| 1055 | |||
| 1008 | 1056 | ||
| 1009 | 1057 | ||
| 1010 | /******************************************************************************* | 1058 | /******************************************************************************* |
| @@ -48,7 +48,7 @@ · 47 unmodified lines | |||
| 48 | // major version must be the same between chuck:chugin | 48 | // major version must be the same between chuck:chugin |
| 49 | #define CK_DLL_VERSION_MAJOR (0x0007) | 49 | #define CK_DLL_VERSION_MAJOR (0x0007) |
| 50 | // minor version of chugin must be less than or equal to chuck's | 50 | // minor version of chugin must be less than or equal to chuck's |
| 51 | #define CK_DLL_VERSION_MINOR (0x0000) | 51 | #define CK_DLL_VERSION_MINOR (0x0001) |
| 52 | #define CK_DLL_VERSION_MAKE(maj,min) ((t_CKUINT)(((maj) << 16) | (min))) | 52 | #define CK_DLL_VERSION_MAKE(maj,min) ((t_CKUINT)(((maj) << 16) | (min))) |
| 53 | #define CK_DLL_VERSION_GETMAJOR(v) (((v) >> 16) & 0xFFFF) | 53 | #define CK_DLL_VERSION_GETMAJOR(v) (((v) >> 16) & 0xFFFF) |
| 54 | #define CK_DLL_VERSION_GETMINOR(v) ((v) & 0xFFFF) | 54 | #define CK_DLL_VERSION_GETMINOR(v) ((v) & 0xFFFF) |
| @@ -73,6 +73,7 @@ struct Chuck_DLL; · 18 unmodified lines | |||
| 73 | struct Chuck_UGen; | 73 | struct Chuck_UGen; |
| 74 | struct Chuck_UAna; | 74 | struct Chuck_UAna; |
| 75 | struct Chuck_UAnaBlobProxy; | 75 | struct Chuck_UAnaBlobProxy; |
| 76 | struct Chuck_DL_MainThreadHook; | ||
| 76 | namespace Chuck_DL_Api { struct Api; } | 77 | namespace Chuck_DL_Api { struct Api; } |
| 77 | 78 | ||
| 78 | 79 | ||
| @@ -306,7 +307,9 @@ typedef void (CK_DLL_CALL * f_add_ugen_ctrl)( Chuck_DL_Query * query, f_ctrl ctr · 227 unmodified lines | |||
| 306 | const char * type, const char * name ); | 307 | const char * type, const char * name ); |
| 307 | // end class/namespace - must correspondent with begin_class. returns false on error | 308 | // end class/namespace - must correspondent with begin_class. returns false on error |
| 308 | typedef t_CKBOOL (CK_DLL_CALL * f_end_class)( Chuck_DL_Query * query ); | 309 | typedef t_CKBOOL (CK_DLL_CALL * f_end_class)( Chuck_DL_Query * query ); |
| 309 | 310 | // create main thread hook- used for executing a "hook" function in the main thread of a primary chuck instance | |
| 311 | typedef Chuck_DL_MainThreadHook * (CK_DLL_CALL * f_create_main_thread_hook)( Chuck_DL_Query * query, f_mainthreadhook hook, f_mainthreadquit quit, void * bindle ); | ||
| 312 | |||
| 310 | // documentation | 313 | // documentation |
| 311 | // set current class documentation | 314 | // set current class documentation |
| 312 | typedef t_CKBOOL (CK_DLL_CALL * f_doc_class)( Chuck_DL_Query * query, const char * doc ); | 315 | typedef t_CKBOOL (CK_DLL_CALL * f_doc_class)( Chuck_DL_Query * query, const char * doc ); |
| @@ -334,6 +337,7 @@ public: · 21 unmodified lines | |||
| 334 | Chuck_Compiler * compiler() const { return m_carrier->compiler; } | 337 | Chuck_Compiler * compiler() const { return m_carrier->compiler; } |
| 335 | Chuck_VM * vm() const { return m_carrier->vm; } | 338 | Chuck_VM * vm() const { return m_carrier->vm; } |
| 336 | Chuck_Env * env() const { return m_carrier->env; } | 339 | Chuck_Env * env() const { return m_carrier->env; } |
| 340 | Chuck_Carrier * carrier() const { return m_carrier; } | ||
| 337 | 341 | ||
| 338 | public: | 342 | public: |
| 339 | // function pointers - to be called from client module | 343 | // function pointers - to be called from client module |
| @@ -375,6 +379,9 @@ public: · 35 unmodified lines | |||
| 375 | f_doc_var doc_var; | 379 | f_doc_var doc_var; |
| 376 | f_add_example add_ex; | 380 | f_add_example add_ex; |
| 377 | 381 | ||
| 382 | // re-added 1.4.0.1 | ||
| 383 | f_create_main_thread_hook create_main_thread_hook; | ||
| 384 | |||
| 378 | // NOTE: everything below std::anything cannot be reliably accessed | 385 | // NOTE: everything below std::anything cannot be reliably accessed |
| 379 | // by offset between dynamic modules, since std::anything could be variable | 386 | // by offset between dynamic modules, since std::anything could be variable |
| 380 | // size -- put everything need to be accessed across modules above here! | 387 | // size -- put everything need to be accessed across modules above here! |
| @@ -629,6 +636,20 @@ protected: · 248 unmodified lines | |||
| 629 | }; | 636 | }; |
| 630 | 637 | ||
| 631 | 638 | ||
| 639 | struct Chuck_DL_MainThreadHook | ||
| 640 | { | ||
| 641 | public: | ||
| 642 | Chuck_DL_MainThreadHook(f_mainthreadhook hook, f_mainthreadquit quit, | ||
| 643 | void * bindle, Chuck_Carrier * carrier); | ||
| 644 | t_CKBOOL (* const activate)(Chuck_DL_MainThreadHook *); | ||
| 645 | t_CKBOOL (* const deactivate)(Chuck_DL_MainThreadHook *); | ||
| 646 | |||
| 647 | Chuck_Carrier * const m_carrier; | ||
| 648 | f_mainthreadhook const m_hook; | ||
| 649 | f_mainthreadquit const m_quit; | ||
| 650 | void * const m_bindle; | ||
| 651 | t_CKBOOL m_active; | ||
| 652 | }; | ||
| 632 | 653 | ||
| 633 | 654 | ||
| 634 | /* API to ChucK's innards */ | 655 | /* API to ChucK's innards */ |
| @@ -1037,7 +1037,11 @@ bool go( int argc, const char ** argv ) · 1036 unmodified lines | |||
| 1037 | // real-time audio | 1037 | // real-time audio |
| 1038 | if( g_enable_realtime_audio ) | 1038 | if( g_enable_realtime_audio ) |
| 1039 | { | 1039 | { |
| 1040 | usleep( 10000 ); | 1040 | Chuck_DL_MainThreadHook * hook = the_chuck->getMainThreadHook(); |
| 1041 | if (hook) | ||
| 1042 | hook->m_hook(hook->m_bindle); | ||
| 1043 | else | ||
| 1044 | usleep( 10000 ); | ||
| 1041 | } | 1045 | } |
| 1042 | else // silent mode | 1046 | else // silent mode |
| 1043 | { | 1047 | { |
| @@ -1046,6 +1050,10 @@ bool go( int argc, const char ** argv ) · 2 unmodified lines | |||
| 1046 | } | 1050 | } |
| 1047 | } | 1051 | } |
| 1048 | 1052 | ||
| 1053 | Chuck_DL_MainThreadHook * hook = the_chuck->getMainThreadHook(); | ||
| 1054 | if (hook) | ||
| 1055 | hook->m_quit(hook->m_bindle); | ||
| 1056 | |||
| 1049 | return TRUE; | 1057 | return TRUE; |
| 1050 | } | 1058 | } |
| 1051 | 1059 | ||