| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
#ifndef __CHUCK_GLOBALS_H__ |
| 41 |
#define __CHUCK_GLOBALS_H__ |
| 42 |
|
| 43 |
#include "chuck_def.h" |
| 44 |
#include "chuck_type.h" |
| 45 |
#include "chuck_ugen.h" |
| 46 |
#include <string> |
| 47 |
#include <map> |
| 48 |
#include <vector> |
| 49 |
|
| 50 |
|
| 51 |
struct Chuck_VM; |
| 52 |
struct Chuck_VM_Shred; |
| 53 |
struct Chuck_Msg; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
struct Chuck_Set_Global_Int_Request; |
| 60 |
struct Chuck_Get_Global_Int_Request; |
| 61 |
struct Chuck_Set_Global_Float_Request; |
| 62 |
struct Chuck_Get_Global_Float_Request; |
| 63 |
struct Chuck_Signal_Global_Event_Request; |
| 64 |
struct Chuck_Listen_For_Global_Event_Request; |
| 65 |
struct Chuck_Set_Global_String_Request; |
| 66 |
struct Chuck_Get_Global_String_Request; |
| 67 |
struct Chuck_Set_Global_Int_Array_Request; |
| 68 |
struct Chuck_Get_Global_Int_Array_Request; |
| 69 |
struct Chuck_Set_Global_Int_Array_Value_Request; |
| 70 |
struct Chuck_Get_Global_Int_Array_Value_Request; |
| 71 |
struct Chuck_Set_Global_Associative_Int_Array_Value_Request; |
| 72 |
struct Chuck_Get_Global_Associative_Int_Array_Value_Request; |
| 73 |
struct Chuck_Set_Global_Float_Array_Request; |
| 74 |
struct Chuck_Get_Global_Float_Array_Request; |
| 75 |
struct Chuck_Set_Global_Float_Array_Value_Request; |
| 76 |
struct Chuck_Get_Global_Float_Array_Value_Request; |
| 77 |
struct Chuck_Set_Global_Associative_Float_Array_Value_Request; |
| 78 |
struct Chuck_Get_Global_Associative_Float_Array_Value_Request; |
| 79 |
struct Chuck_Get_Global_All_Request; |
| 80 |
struct Chuck_Execute_Chuck_Msg_Request; |
| 81 |
|
| 82 |
|
| 83 |
struct Chuck_Global_Int_Container; |
| 84 |
struct Chuck_Global_Float_Container; |
| 85 |
struct Chuck_Global_String_Container; |
| 86 |
struct Chuck_Global_Event_Container; |
| 87 |
struct Chuck_Global_UGen_Container; |
| 88 |
struct Chuck_Global_Array_Container; |
| 89 |
struct Chuck_Global_Object_Container; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
enum Chuck_Global_Request_Type |
| 98 |
{ |
| 99 |
|
| 100 |
global_request_none, |
| 101 |
|
| 102 |
set_global_int_request, |
| 103 |
get_global_int_request, |
| 104 |
set_global_float_request, |
| 105 |
get_global_float_request, |
| 106 |
set_global_string_request, |
| 107 |
get_global_string_request, |
| 108 |
|
| 109 |
signal_global_event_request, |
| 110 |
listen_for_global_event_request, |
| 111 |
|
| 112 |
set_global_int_array_request, |
| 113 |
get_global_int_array_request, |
| 114 |
set_global_int_array_value_request, |
| 115 |
get_global_int_array_value_request, |
| 116 |
set_global_associative_int_array_value_request, |
| 117 |
get_global_associative_int_array_value_request, |
| 118 |
|
| 119 |
set_global_float_array_request, |
| 120 |
get_global_float_array_request, |
| 121 |
set_global_float_array_value_request, |
| 122 |
get_global_float_array_value_request, |
| 123 |
set_global_associative_float_array_value_request, |
| 124 |
get_global_associative_float_array_value_request, |
| 125 |
|
| 126 |
get_global_all_request, |
| 127 |
|
| 128 |
spork_shred_request, |
| 129 |
|
| 130 |
execute_chuck_msg_request |
| 131 |
}; |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
struct Chuck_Global_Request |
| 141 |
{ |
| 142 |
Chuck_Global_Request_Type type; |
| 143 |
t_CKUINT retries; |
| 144 |
union { |
| 145 |
|
| 146 |
Chuck_Set_Global_Int_Request* setIntRequest; |
| 147 |
Chuck_Get_Global_Int_Request* getIntRequest; |
| 148 |
Chuck_Set_Global_Float_Request* setFloatRequest; |
| 149 |
Chuck_Get_Global_Float_Request* getFloatRequest; |
| 150 |
Chuck_Set_Global_String_Request* setStringRequest; |
| 151 |
Chuck_Get_Global_String_Request* getStringRequest; |
| 152 |
|
| 153 |
Chuck_Signal_Global_Event_Request* signalEventRequest; |
| 154 |
Chuck_Listen_For_Global_Event_Request* listenForEventRequest; |
| 155 |
|
| 156 |
Chuck_Set_Global_Int_Array_Request* setIntArrayRequest; |
| 157 |
Chuck_Get_Global_Int_Array_Request* getIntArrayRequest; |
| 158 |
Chuck_Set_Global_Int_Array_Value_Request* setIntArrayValueRequest; |
| 159 |
Chuck_Get_Global_Int_Array_Value_Request* getIntArrayValueRequest; |
| 160 |
Chuck_Set_Global_Associative_Int_Array_Value_Request* setAssociativeIntArrayValueRequest; |
| 161 |
Chuck_Get_Global_Associative_Int_Array_Value_Request* getAssociativeIntArrayValueRequest; |
| 162 |
|
| 163 |
Chuck_Set_Global_Float_Array_Request* setFloatArrayRequest; |
| 164 |
Chuck_Get_Global_Float_Array_Request* getFloatArrayRequest; |
| 165 |
Chuck_Set_Global_Float_Array_Value_Request* setFloatArrayValueRequest; |
| 166 |
Chuck_Get_Global_Float_Array_Value_Request* getFloatArrayValueRequest; |
| 167 |
Chuck_Set_Global_Associative_Float_Array_Value_Request* setAssociativeFloatArrayValueRequest; |
| 168 |
Chuck_Get_Global_Associative_Float_Array_Value_Request* getAssociativeFloatArrayValueRequest; |
| 169 |
|
| 170 |
Chuck_Get_Global_All_Request* getAllRequest; |
| 171 |
|
| 172 |
Chuck_VM_Shred* shred; |
| 173 |
|
| 174 |
Chuck_Execute_Chuck_Msg_Request* executeChuckMsgRequest; |
| 175 |
}; |
| 176 |
|
| 177 |
Chuck_Global_Request() |
| 178 |
{ |
| 179 |
type = global_request_none; |
| 180 |
retries = 0; |
| 181 |
executeChuckMsgRequest = NULL; |
| 182 |
} |
| 183 |
}; |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
struct Chuck_Globals_TypeValue |
| 194 |
{ |
| 195 |
|
| 196 |
std::string type; |
| 197 |
|
| 198 |
std::string name; |
| 199 |
|
| 200 |
|
| 201 |
Chuck_Globals_TypeValue() |
| 202 |
{ } |
| 203 |
Chuck_Globals_TypeValue( const std::string & t, const std::string & n ) |
| 204 |
: type(t), name(n) { } |
| 205 |
}; |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
struct Chuck_Globals_Manager |
| 215 |
{ |
| 216 |
public: |
| 217 |
Chuck_Globals_Manager( Chuck_VM * vm ); |
| 218 |
~Chuck_Globals_Manager(); |
| 219 |
|
| 220 |
public: |
| 221 |
|
| 222 |
|
| 223 |
t_CKBOOL getGlobalInt( const char * name, void (*callback)(t_CKINT) ); |
| 224 |
t_CKBOOL getGlobalInt( const char * name, void (*callback)(const char*, t_CKINT) ); |
| 225 |
t_CKBOOL getGlobalInt( const char * name, t_CKINT callbackID, void (*callback)(t_CKINT, t_CKINT) ); |
| 226 |
t_CKBOOL setGlobalInt( const char * name, t_CKINT val ); |
| 227 |
|
| 228 |
t_CKBOOL getGlobalFloat( const char * name, void (*callback)(t_CKFLOAT) ); |
| 229 |
t_CKBOOL getGlobalFloat( const char * name, void (*callback)(const char*, t_CKFLOAT) ); |
| 230 |
t_CKBOOL getGlobalFloat( const char * name, t_CKINT callbackID, void (*callback)(t_CKINT, t_CKFLOAT) ); |
| 231 |
t_CKBOOL setGlobalFloat( const char * name, t_CKFLOAT val ); |
| 232 |
|
| 233 |
t_CKBOOL getGlobalString( const char * name, void (*callback)(const char*) ); |
| 234 |
t_CKBOOL getGlobalString( const char * name, void (*callback)(const char*, const char*) ); |
| 235 |
t_CKBOOL getGlobalString( const char * name, t_CKINT callbackID, void (*callback)(t_CKINT, const char*) ); |
| 236 |
t_CKBOOL setGlobalString( const char * name, const char * val ); |
| 237 |
|
| 238 |
t_CKBOOL signalGlobalEvent( const char * name ); |
| 239 |
t_CKBOOL broadcastGlobalEvent( const char * name ); |
| 240 |
t_CKBOOL listenForGlobalEvent( const char * name, void (*callback)(void), t_CKBOOL listen_forever ); |
| 241 |
t_CKBOOL listenForGlobalEvent( const char * name, void (*callback)(const char*), t_CKBOOL listen_forever ); |
| 242 |
t_CKBOOL listenForGlobalEvent( const char * name, t_CKINT callbackID, void (*callback)(t_CKINT), t_CKBOOL listen_forever ); |
| 243 |
t_CKBOOL stopListeningForGlobalEvent( const char * name, void (*callback)(void) ); |
| 244 |
t_CKBOOL stopListeningForGlobalEvent( const char * name, void (*callback)(const char*) ); |
| 245 |
t_CKBOOL stopListeningForGlobalEvent( const char * name, t_CKINT callbackID, void (*callback)(t_CKINT) ); |
| 246 |
|
| 247 |
t_CKBOOL getGlobalUGenSamples( const char * name, SAMPLE * buffer, int numFrames ); |
| 248 |
t_CKBOOL getGlobalUGenSamplesMulti( const char * name, SAMPLE * buffer, int numFrames, int numChannels ); |
| 249 |
|
| 250 |
t_CKBOOL setGlobalIntArray( const char * name, t_CKINT arrayValues[], t_CKUINT numValues ); |
| 251 |
t_CKBOOL getGlobalIntArray( const char * name, void (*callback)(t_CKINT[], t_CKUINT) ); |
| 252 |
t_CKBOOL getGlobalIntArray( const char * name, void (*callback)(const char*, t_CKINT[], t_CKUINT) ); |
| 253 |
t_CKBOOL getGlobalIntArray( const char * name, t_CKINT callbackID, void (*callback)(t_CKINT, t_CKINT[], t_CKUINT) ); |
| 254 |
t_CKBOOL setGlobalIntArrayValue( const char * name, t_CKUINT index, t_CKINT value ); |
| 255 |
t_CKBOOL getGlobalIntArrayValue( const char * name, t_CKUINT index, void (*callback)(t_CKINT) ); |
| 256 |
t_CKBOOL getGlobalIntArrayValue( const char * name, t_CKUINT index, void (*callback)(const char*, t_CKINT) ); |
| 257 |
t_CKBOOL getGlobalIntArrayValue( const char * name, t_CKINT callbackID, t_CKUINT index, void (*callback)(t_CKINT, t_CKINT) ); |
| 258 |
t_CKBOOL setGlobalAssociativeIntArrayValue( const char * name, const char * key, t_CKINT value ); |
| 259 |
t_CKBOOL getGlobalAssociativeIntArrayValue( const char * name, const char * key, void (*callback)(t_CKINT) ); |
| 260 |
t_CKBOOL getGlobalAssociativeIntArrayValue( const char * name, const char * key, void (*callback)(const char*, t_CKINT) ); |
| 261 |
t_CKBOOL getGlobalAssociativeIntArrayValue( const char * name, t_CKINT callbackID, const char * key, void (*callback)(t_CKINT, t_CKINT) ); |
| 262 |
|
| 263 |
t_CKBOOL setGlobalFloatArray( const char * name, t_CKFLOAT arrayValues[], t_CKUINT numValues ); |
| 264 |
t_CKBOOL getGlobalFloatArray( const char * name, void (*callback)(t_CKFLOAT[], t_CKUINT) ); |
| 265 |
t_CKBOOL getGlobalFloatArray( const char * name, void (*callback)(const char*, t_CKFLOAT[], t_CKUINT) ); |
| 266 |
t_CKBOOL getGlobalFloatArray( const char * name, t_CKINT callbackID, void (*callback)(t_CKINT, t_CKFLOAT[], t_CKUINT) ); |
| 267 |
t_CKBOOL setGlobalFloatArrayValue( const char * name, t_CKUINT index, t_CKFLOAT value ); |
| 268 |
t_CKBOOL getGlobalFloatArrayValue( const char * name, t_CKUINT index, void (*callback)(t_CKFLOAT) ); |
| 269 |
t_CKBOOL getGlobalFloatArrayValue( const char * name, t_CKUINT index, void (*callback)(const char*, t_CKFLOAT) ); |
| 270 |
t_CKBOOL getGlobalFloatArrayValue( const char * name, t_CKINT callbackID, t_CKUINT index, void (*callback)(t_CKINT, t_CKFLOAT) ); |
| 271 |
t_CKBOOL setGlobalAssociativeFloatArrayValue( const char * name, const char * key, t_CKFLOAT value ); |
| 272 |
t_CKBOOL getGlobalAssociativeFloatArrayValue( const char * name, const char * key, void (*callback)(t_CKFLOAT) ); |
| 273 |
t_CKBOOL getGlobalAssociativeFloatArrayValue( const char * name, const char * key, void (*callback)(const char*, t_CKFLOAT) ); |
| 274 |
t_CKBOOL getGlobalAssociativeFloatArrayValue( const char * name, t_CKINT callbackID, const char * key, void (*callback)(t_CKINT, t_CKFLOAT) ); |
| 275 |
|
| 276 |
|
| 277 |
t_CKBOOL getAllGlobalVariables( void (*callback)( const std::vector<Chuck_Globals_TypeValue> & list, void * data ), |
| 278 |
void * data = NULL ); |
| 279 |
|
| 280 |
public: |
| 281 |
|
| 282 |
t_CKBOOL execute_chuck_msg_with_globals( Chuck_Msg* msg ); |
| 283 |
|
| 284 |
public: |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
t_CKBOOL init_global_int( const std::string & name ); |
| 289 |
t_CKINT get_global_int_value( const std::string & name ); |
| 290 |
t_CKINT* get_ptr_to_global_int( const std::string & name ); |
| 291 |
|
| 292 |
t_CKBOOL init_global_float( const std::string & name ); |
| 293 |
t_CKFLOAT get_global_float_value( const std::string & name ); |
| 294 |
t_CKFLOAT* get_ptr_to_global_float( const std::string & name ); |
| 295 |
|
| 296 |
t_CKBOOL init_global_string( const std::string & name ); |
| 297 |
Chuck_String* get_global_string( const std::string & name ); |
| 298 |
Chuck_String** get_ptr_to_global_string( const std::string & name ); |
| 299 |
|
| 300 |
t_CKBOOL init_global_event( const std::string & name, Chuck_Type* type ); |
| 301 |
Chuck_Event* get_global_event( const std::string & name ); |
| 302 |
Chuck_Event** get_ptr_to_global_event( const std::string & name ); |
| 303 |
|
| 304 |
t_CKBOOL init_global_ugen( const std::string & name, Chuck_Type* type ); |
| 305 |
t_CKBOOL is_global_ugen_init( const std::string & name ); |
| 306 |
t_CKBOOL is_global_ugen_valid( const std::string & name ); |
| 307 |
Chuck_UGen* get_global_ugen( const std::string & name ); |
| 308 |
Chuck_UGen** get_ptr_to_global_ugen( const std::string & name ); |
| 309 |
|
| 310 |
|
| 311 |
t_CKBOOL init_global_array( const std::string & name, Chuck_Type* type, te_GlobalType arr_type ); |
| 312 |
|
| 313 |
Chuck_Object* get_global_array( const std::string & name ); |
| 314 |
Chuck_Object** get_ptr_to_global_array( const std::string & name ); |
| 315 |
t_CKINT get_global_int_array_value( const std::string & name, t_CKUINT index ); |
| 316 |
t_CKINT get_global_associative_int_array_value( const std::string & name, const std::string & key ); |
| 317 |
t_CKFLOAT get_global_float_array_value( const std::string & name, t_CKUINT index ); |
| 318 |
t_CKFLOAT get_global_associative_float_array_value( const std::string & name, const std::string & key ); |
| 319 |
|
| 320 |
t_CKBOOL set_global_int_array( const std::string & name, t_CKINT arrayValues[], t_CKUINT numValues ); |
| 321 |
t_CKBOOL set_global_int_array_value( const std::string & name, t_CKUINT index, t_CKINT value ); |
| 322 |
t_CKBOOL set_global_float_array( const std::string & name, t_CKFLOAT arrayValues[], t_CKUINT numValues ); |
| 323 |
t_CKBOOL set_global_float_array_value( const std::string & name, t_CKUINT index, t_CKFLOAT value ); |
| 324 |
|
| 325 |
t_CKBOOL init_global_object( const std::string & name, Chuck_Type* type ); |
| 326 |
t_CKBOOL is_global_object_init( const std::string & name ); |
| 327 |
t_CKBOOL is_global_object_valid( const std::string & name ); |
| 328 |
Chuck_Object* get_global_object( const std::string & name ); |
| 329 |
Chuck_Object** get_ptr_to_global_object( const std::string & name ); |
| 330 |
|
| 331 |
|
| 332 |
void get_all_global_variables( std::vector<Chuck_Globals_TypeValue> & list ); |
| 333 |
|
| 334 |
t_CKBOOL should_call_global_ctor( const std::string & name, te_GlobalType type ); |
| 335 |
void global_ctor_was_called( const std::string & name, te_GlobalType type ); |
| 336 |
|
| 337 |
|
| 338 |
void cleanup_global_variables(); |
| 339 |
|
| 340 |
public: |
| 341 |
|
| 342 |
t_CKBOOL add_request( Chuck_Global_Request request ); |
| 343 |
t_CKBOOL more_requests(); |
| 344 |
|
| 345 |
void handle_global_queue_messages(); |
| 346 |
|
| 347 |
private: |
| 348 |
|
| 349 |
Chuck_VM * m_vm; |
| 350 |
|
| 351 |
|
| 352 |
std::map< std::string, Chuck_Global_Int_Container* > m_global_ints; |
| 353 |
std::map< std::string, Chuck_Global_Float_Container* > m_global_floats; |
| 354 |
std::map< std::string, Chuck_Global_String_Container* > m_global_strings; |
| 355 |
std::map< std::string, Chuck_Global_Event_Container* > m_global_events; |
| 356 |
std::map< std::string, Chuck_Global_UGen_Container* > m_global_ugens; |
| 357 |
std::map< std::string, Chuck_Global_Array_Container* > m_global_arrays; |
| 358 |
std::map< std::string, Chuck_Global_Object_Container* > m_global_objects; |
| 359 |
|
| 360 |
|
| 361 |
FinalRingBuffer< Chuck_Global_Request > m_global_request_queue; |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
FinalRingBuffer< Chuck_Global_Request > m_global_request_retry_queue; |
| 370 |
}; |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
#endif |