| @@ -1282,6 +1282,100 @@ struct Chuck_Get_External_String_Request · 1281 unmodified lines |
| 1282 | | 1282 | |
| 1283 | | 1283 | |
| 1284 | | 1284 | |
| | 1285 | //----------------------------------------------------------------------------- |
| | 1286 | // name: struct Chuck_Set_External_Int_Array_Request |
| | 1287 | // desc: container for messages to set external int arrays (REFACTOR-2017) |
| | 1288 | //----------------------------------------------------------------------------- |
| | 1289 | struct Chuck_Set_External_Int_Array_Request |
| | 1290 | { |
| | 1291 | std::string name; |
| | 1292 | std::vector< t_CKINT > arrayValues; |
| | 1293 | // constructor |
| | 1294 | Chuck_Set_External_Int_Array_Request() { } |
| | 1295 | }; |
| | 1296 | |
| | 1297 | |
| | 1298 | |
| | 1299 | |
| | 1300 | //----------------------------------------------------------------------------- |
| | 1301 | // name: struct Chuck_Get_External_Int_Array_Request |
| | 1302 | // desc: container for messages to get external arrays (REFACTOR-2017) |
| | 1303 | //----------------------------------------------------------------------------- |
| | 1304 | struct Chuck_Get_External_Int_Array_Request |
| | 1305 | { |
| | 1306 | std::string name; |
| | 1307 | void (* callback)(t_CKINT[], t_CKUINT); |
| | 1308 | // constructor |
| | 1309 | Chuck_Get_External_Int_Array_Request() : callback(NULL) { } |
| | 1310 | }; |
| | 1311 | |
| | 1312 | |
| | 1313 | |
| | 1314 | |
| | 1315 | //----------------------------------------------------------------------------- |
| | 1316 | // name: struct Chuck_Set_External_Int_Array_Value_Request |
| | 1317 | // desc: container for messages to set individual elements of int arrays (REFACTOR-2017) |
| | 1318 | //----------------------------------------------------------------------------- |
| | 1319 | struct Chuck_Set_External_Int_Array_Value_Request |
| | 1320 | { |
| | 1321 | std::string name; |
| | 1322 | t_CKUINT index; |
| | 1323 | t_CKINT value; |
| | 1324 | // constructor |
| | 1325 | Chuck_Set_External_Int_Array_Value_Request() : index(-1), value(0) { } |
| | 1326 | }; |
| | 1327 | |
| | 1328 | |
| | 1329 | |
| | 1330 | |
| | 1331 | //----------------------------------------------------------------------------- |
| | 1332 | // name: struct Chuck_Get_External_Int_Array_Value_Request |
| | 1333 | // desc: container for messages to get individual elements of int arrays (REFACTOR-2017) |
| | 1334 | //----------------------------------------------------------------------------- |
| | 1335 | struct Chuck_Get_External_Int_Array_Value_Request |
| | 1336 | { |
| | 1337 | std::string name; |
| | 1338 | t_CKUINT index; |
| | 1339 | void (* callback)(t_CKINT); |
| | 1340 | // constructor |
| | 1341 | Chuck_Get_External_Int_Array_Value_Request() : index(-1), callback(NULL) { } |
| | 1342 | }; |
| | 1343 | |
| | 1344 | |
| | 1345 | |
| | 1346 | |
| | 1347 | //----------------------------------------------------------------------------- |
| | 1348 | // name: struct Chuck_Set_External_Associative_Int_Array_Value_Request |
| | 1349 | // desc: container for messages to set elements of associative int arrays (REFACTOR-2017) |
| | 1350 | //----------------------------------------------------------------------------- |
| | 1351 | struct Chuck_Set_External_Associative_Int_Array_Value_Request |
| | 1352 | { |
| | 1353 | std::string name; |
| | 1354 | std::string key; |
| | 1355 | t_CKINT value; |
| | 1356 | // constructor |
| | 1357 | Chuck_Set_External_Associative_Int_Array_Value_Request() : value(0) { } |
| | 1358 | }; |
| | 1359 | |
| | 1360 | |
| | 1361 | |
| | 1362 | |
| | 1363 | //----------------------------------------------------------------------------- |
| | 1364 | // name: struct Chuck_Get_External_Associative_Int_Array_Value_Request |
| | 1365 | // desc: container for messages to get elements of associative int arrays (REFACTOR-2017) |
| | 1366 | //----------------------------------------------------------------------------- |
| | 1367 | struct Chuck_Get_External_Associative_Int_Array_Value_Request |
| | 1368 | { |
| | 1369 | std::string name; |
| | 1370 | std::string key; |
| | 1371 | void (* callback)(t_CKINT); |
| | 1372 | // constructor |
| | 1373 | Chuck_Get_External_Associative_Int_Array_Value_Request() : callback(NULL) { } |
| | 1374 | }; |
| | 1375 | |
| | 1376 | |
| | 1377 | |
| | 1378 | |
| 1285 | //----------------------------------------------------------------------------- | 1379 | //----------------------------------------------------------------------------- |
| 1286 | // name: struct Chuck_External_Int_Container | 1380 | // name: struct Chuck_External_Int_Container |
| 1287 | // desc: container for external ints | 1381 | // desc: container for external ints |
| @@ -1918,6 +2012,152 @@ Chuck_UGen * * Chuck_VM::get_ptr_to_external_ugen( std::string name ) · 630 unmodified lines |
| 1918 | | 2012 | |
| 1919 | | 2013 | |
| 1920 | | 2014 | |
| | 2015 | //----------------------------------------------------------------------------- |
| | 2016 | // name: set_external_int_array() |
| | 2017 | // desc: tell the vm to set an entire int array |
| | 2018 | //----------------------------------------------------------------------------- |
| | 2019 | t_CKBOOL Chuck_VM::set_external_int_array( std::string name, t_CKINT arrayValues[], t_CKUINT numValues ) |
| | 2020 | { |
| | 2021 | Chuck_Set_External_Int_Array_Request * message = |
| | 2022 | new Chuck_Set_External_Int_Array_Request; |
| | 2023 | message->name = name; |
| | 2024 | message->arrayValues.resize( numValues ); |
| | 2025 | for( int i = 0; i < numValues; i++ ) |
| | 2026 | { |
| | 2027 | message->arrayValues[i] = arrayValues[i]; |
| | 2028 | } |
| | 2029 | |
| | 2030 | Chuck_External_Request r; |
| | 2031 | r.type = set_external_int_array_request; |
| | 2032 | r.setIntArrayRequest = message; |
| | 2033 | |
| | 2034 | m_external_request_queue.put( r ); |
| | 2035 | |
| | 2036 | return TRUE; |
| | 2037 | } |
| | 2038 | |
| | 2039 | |
| | 2040 | |
| | 2041 | |
| | 2042 | //----------------------------------------------------------------------------- |
| | 2043 | // name: get_external_int_array() |
| | 2044 | // desc: tell the vm to get an entire int array |
| | 2045 | //----------------------------------------------------------------------------- |
| | 2046 | t_CKBOOL Chuck_VM::get_external_int_array( std::string name, void (* callback)(t_CKINT[], t_CKUINT)) |
| | 2047 | { |
| | 2048 | Chuck_Get_External_Int_Array_Request * message = |
| | 2049 | new Chuck_Get_External_Int_Array_Request; |
| | 2050 | message->name = name; |
| | 2051 | message->callback = callback; |
| | 2052 | |
| | 2053 | Chuck_External_Request r; |
| | 2054 | r.type = get_external_int_array_request; |
| | 2055 | r.getIntArrayRequest = message; |
| | 2056 | |
| | 2057 | m_external_request_queue.put( r ); |
| | 2058 | |
| | 2059 | return TRUE; |
| | 2060 | } |
| | 2061 | |
| | 2062 | |
| | 2063 | |
| | 2064 | |
| | 2065 | //----------------------------------------------------------------------------- |
| | 2066 | // name: set_external_int_array_value() |
| | 2067 | // desc: tell the vm to set one value of an int array by index |
| | 2068 | //----------------------------------------------------------------------------- |
| | 2069 | t_CKBOOL Chuck_VM::set_external_int_array_value( std::string name, t_CKUINT index, t_CKINT value ) |
| | 2070 | { |
| | 2071 | Chuck_Set_External_Int_Array_Value_Request * message = |
| | 2072 | new Chuck_Set_External_Int_Array_Value_Request; |
| | 2073 | message->name = name; |
| | 2074 | message->index = index; |
| | 2075 | message->value = value; |
| | 2076 | |
| | 2077 | Chuck_External_Request r; |
| | 2078 | r.type = set_external_int_array_value_request; |
| | 2079 | r.setIntArrayValueRequest = message; |
| | 2080 | |
| | 2081 | m_external_request_queue.put( r ); |
| | 2082 | |
| | 2083 | return TRUE; |
| | 2084 | } |
| | 2085 | |
| | 2086 | |
| | 2087 | |
| | 2088 | |
| | 2089 | //----------------------------------------------------------------------------- |
| | 2090 | // name: get_external_int_array_value() |
| | 2091 | // desc: tell the vm to get one value of an int array by index |
| | 2092 | //----------------------------------------------------------------------------- |
| | 2093 | t_CKBOOL Chuck_VM::get_external_int_array_value( std::string name, t_CKUINT index, void (* callback)(t_CKINT) ) |
| | 2094 | { |
| | 2095 | Chuck_Get_External_Int_Array_Value_Request * message = |
| | 2096 | new Chuck_Get_External_Int_Array_Value_Request; |
| | 2097 | message->name = name; |
| | 2098 | message->index = index; |
| | 2099 | message->callback = callback; |
| | 2100 | |
| | 2101 | Chuck_External_Request r; |
| | 2102 | r.type = get_external_int_array_value_request; |
| | 2103 | r.getIntArrayValueRequest = message; |
| | 2104 | |
| | 2105 | m_external_request_queue.put( r ); |
| | 2106 | |
| | 2107 | return TRUE; |
| | 2108 | } |
| | 2109 | |
| | 2110 | |
| | 2111 | |
| | 2112 | |
| | 2113 | //----------------------------------------------------------------------------- |
| | 2114 | // name: set_external_associative_int_array_value() |
| | 2115 | // desc: tell the vm to set one value of an associative array by string key |
| | 2116 | //----------------------------------------------------------------------------- |
| | 2117 | t_CKBOOL Chuck_VM::set_external_associative_int_array_value( std::string name, std::string key, t_CKINT value ) |
| | 2118 | { |
| | 2119 | Chuck_Set_External_Associative_Int_Array_Value_Request * message = |
| | 2120 | new Chuck_Set_External_Associative_Int_Array_Value_Request; |
| | 2121 | message->name = name; |
| | 2122 | message->key = key; |
| | 2123 | message->value = value; |
| | 2124 | |
| | 2125 | Chuck_External_Request r; |
| | 2126 | r.type = set_external_associative_int_array_value_request; |
| | 2127 | r.setAssociativeIntArrayValueRequest = message; |
| | 2128 | |
| | 2129 | m_external_request_queue.put( r ); |
| | 2130 | |
| | 2131 | return TRUE; |
| | 2132 | } |
| | 2133 | |
| | 2134 | |
| | 2135 | |
| | 2136 | |
| | 2137 | //----------------------------------------------------------------------------- |
| | 2138 | // name: get_external_associative_int_array_value() |
| | 2139 | // desc: tell the vm to get one value of an associative array by string key |
| | 2140 | //----------------------------------------------------------------------------- |
| | 2141 | t_CKBOOL Chuck_VM::get_external_associative_int_array_value( std::string name, std::string key, void (* callback)(t_CKINT) ) |
| | 2142 | { |
| | 2143 | Chuck_Get_External_Associative_Int_Array_Value_Request * message = |
| | 2144 | new Chuck_Get_External_Associative_Int_Array_Value_Request; |
| | 2145 | message->name = name; |
| | 2146 | message->key = key; |
| | 2147 | message->callback = callback; |
| | 2148 | |
| | 2149 | Chuck_External_Request r; |
| | 2150 | r.type = get_external_associative_int_array_value_request; |
| | 2151 | r.getAssociativeIntArrayValueRequest = message; |
| | 2152 | |
| | 2153 | m_external_request_queue.put( r ); |
| | 2154 | |
| | 2155 | return TRUE; |
| | 2156 | } |
| | 2157 | |
| | 2158 | |
| | 2159 | |
| | 2160 | |
| 1921 | //----------------------------------------------------------------------------- | 2161 | //----------------------------------------------------------------------------- |
| 1922 | // name: init_external_array() | 2162 | // name: init_external_array() |
| 1923 | // desc: tell the vm that an external string is now available | 2163 | // desc: tell the vm that an external string is now available |
| @@ -2236,6 +2476,162 @@ void Chuck_VM::handle_external_queue_messages() · 312 unmodified lines |
| 2236 | // clean up request storage | 2476 | // clean up request storage |
| 2237 | delete message.listenForEventRequest; | 2477 | delete message.listenForEventRequest; |
| 2238 | break; | 2478 | break; |
| | 2479 | case set_external_int_array_request: |
| | 2480 | { |
| | 2481 | // replace an entire array, if it exists |
| | 2482 | Chuck_Set_External_Int_Array_Request * request = |
| | 2483 | message.setIntArrayRequest; |
| | 2484 | if( m_external_arrays.count( request->name ) > 0 ) |
| | 2485 | { |
| | 2486 | // we know that array's name. does it exist yet? is it an int array? |
| | 2487 | Chuck_Object * array = m_external_arrays[request->name]->array; |
| | 2488 | if( array != NULL && |
| | 2489 | m_external_arrays[request->name]->array_type == te_externalInt ) |
| | 2490 | { |
| | 2491 | // it exists! get existing array, new size |
| | 2492 | Chuck_Array4 * intArray = (Chuck_Array4 *) array; |
| | 2493 | t_CKUINT newSize = request->arrayValues.size(); |
| | 2494 | |
| | 2495 | // resize and copy in |
| | 2496 | intArray->set_size( newSize ); |
| | 2497 | for( int i = 0; i < newSize; i++ ) |
| | 2498 | { |
| | 2499 | intArray->set( i, request->arrayValues[i] ); |
| | 2500 | } |
| | 2501 | } |
| | 2502 | } |
| | 2503 | } |
| | 2504 | |
| | 2505 | // clean up request storage |
| | 2506 | delete message.setIntArrayRequest; |
| | 2507 | break; |
| | 2508 | case get_external_int_array_request: |
| | 2509 | { |
| | 2510 | // fetch an entire array, if it exists |
| | 2511 | Chuck_Get_External_Int_Array_Request * request = |
| | 2512 | message.getIntArrayRequest; |
| | 2513 | if( m_external_arrays.count( request->name ) > 0 ) |
| | 2514 | { |
| | 2515 | // we know that array's name. does it exist yet; do we have a callback? |
| | 2516 | Chuck_Object * array = m_external_arrays[request->name]->array; |
| | 2517 | if( array != NULL && |
| | 2518 | m_external_arrays[request->name]->array_type == te_externalInt && |
| | 2519 | request->callback != NULL ) |
| | 2520 | { |
| | 2521 | Chuck_Array4 * intArray = (Chuck_Array4 *) array; |
| | 2522 | // TODO: why is m_vector a vector of unsigned ints...?? |
| | 2523 | request->callback( |
| | 2524 | (t_CKINT *) &(intArray->m_vector[0]), |
| | 2525 | intArray->size() |
| | 2526 | ); |
| | 2527 | } |
| | 2528 | } |
| | 2529 | } |
| | 2530 | |
| | 2531 | // clean up request storage |
| | 2532 | delete message.getIntArrayRequest; |
| | 2533 | break; |
| | 2534 | case set_external_int_array_value_request: |
| | 2535 | { |
| | 2536 | // set a single value, if array exists and index in range |
| | 2537 | Chuck_Set_External_Int_Array_Value_Request * request = |
| | 2538 | message.setIntArrayValueRequest; |
| | 2539 | if( m_external_arrays.count( request->name ) > 0 ) |
| | 2540 | { |
| | 2541 | // we know that array's name. does it exist yet? is it an int array? |
| | 2542 | Chuck_Object * array = m_external_arrays[request->name]->array; |
| | 2543 | if( array != NULL && |
| | 2544 | m_external_arrays[request->name]->array_type == te_externalInt ) |
| | 2545 | { |
| | 2546 | // it exists! get existing array |
| | 2547 | Chuck_Array4 * intArray = (Chuck_Array4 *) array; |
| | 2548 | // set! (if index within range) |
| | 2549 | if( intArray->size() > request->index ) |
| | 2550 | { |
| | 2551 | intArray->set( request->index, request->value ); |
| | 2552 | } |
| | 2553 | } |
| | 2554 | } |
| | 2555 | } |
| | 2556 | |
| | 2557 | // clean up request storage |
| | 2558 | delete message.setIntArrayValueRequest; |
| | 2559 | break; |
| | 2560 | case get_external_int_array_value_request: |
| | 2561 | { |
| | 2562 | // get a single value, if array exists and index in range |
| | 2563 | Chuck_Get_External_Int_Array_Value_Request * request = |
| | 2564 | message.getIntArrayValueRequest; |
| | 2565 | // fetch an entire array, if it exists |
| | 2566 | if( m_external_arrays.count( request->name ) > 0 ) |
| | 2567 | { |
| | 2568 | // we know that array's name. does it exist yet; do we have a callback? |
| | 2569 | Chuck_Object * array = m_external_arrays[request->name]->array; |
| | 2570 | if( array != NULL && |
| | 2571 | m_external_arrays[request->name]->array_type == te_externalInt && |
| | 2572 | request->callback != NULL ) |
| | 2573 | { |
| | 2574 | Chuck_Array4 * intArray = (Chuck_Array4 *) array; |
| | 2575 | // TODO why is it unsigned int storage? |
| | 2576 | t_CKUINT result = 0; |
| | 2577 | intArray->get( request->index, &result ); |
| | 2578 | request->callback( result ); |
| | 2579 | } |
| | 2580 | } |
| | 2581 | } |
| | 2582 | |
| | 2583 | // clean up request storage |
| | 2584 | delete message.getIntArrayValueRequest; |
| | 2585 | break; |
| | 2586 | case set_external_associative_int_array_value_request: |
| | 2587 | { |
| | 2588 | // set a single value by key, if array exists |
| | 2589 | Chuck_Set_External_Associative_Int_Array_Value_Request * request = |
| | 2590 | message.setAssociativeIntArrayValueRequest; |
| | 2591 | if( m_external_arrays.count( request->name ) > 0 ) |
| | 2592 | { |
| | 2593 | // we know that array's name. does it exist yet? is it an int array? |
| | 2594 | Chuck_Object * array = m_external_arrays[request->name]->array; |
| | 2595 | if( array != NULL && |
| | 2596 | m_external_arrays[request->name]->array_type == te_externalInt ) |
| | 2597 | { |
| | 2598 | // it exists! get existing array |
| | 2599 | Chuck_Array4 * intArray = (Chuck_Array4 *) array; |
| | 2600 | // set! |
| | 2601 | intArray->set( request->key, request->value ); |
| | 2602 | } |
| | 2603 | } |
| | 2604 | } |
| | 2605 | |
| | 2606 | // clean up request storage |
| | 2607 | delete message.setAssociativeIntArrayValueRequest; |
| | 2608 | break; |
| | 2609 | case get_external_associative_int_array_value_request: |
| | 2610 | { |
| | 2611 | // get a single value by key, if array exists and key in map |
| | 2612 | Chuck_Get_External_Associative_Int_Array_Value_Request * request = |
| | 2613 | message.getAssociativeIntArrayValueRequest; |
| | 2614 | // fetch an entire array, if it exists |
| | 2615 | if( m_external_arrays.count( request->name ) > 0 ) |
| | 2616 | { |
| | 2617 | // we know that array's name. does it exist yet; do we have a callback? |
| | 2618 | Chuck_Object * array = m_external_arrays[request->name]->array; |
| | 2619 | if( array != NULL && |
| | 2620 | m_external_arrays[request->name]->array_type == te_externalInt && |
| | 2621 | request->callback != NULL ) |
| | 2622 | { |
| | 2623 | Chuck_Array4 * intArray = (Chuck_Array4 *) array; |
| | 2624 | // TODO why is it unsigned int storage? |
| | 2625 | t_CKUINT result = 0; |
| | 2626 | intArray->get( request->key, &result ); |
| | 2627 | request->callback( result ); |
| | 2628 | } |
| | 2629 | } |
| | 2630 | } |
| | 2631 | |
| | 2632 | // clean up request storage |
| | 2633 | delete message.getAssociativeIntArrayValueRequest; |
| | 2634 | break; |
| 2239 | } | 2635 | } |
| 2240 | } | 2636 | } |
| 2241 | else | 2637 | else |