Heavy has no support for disk I/O, so anything like that would have to be implemented in the C++ wrapping code. However, it is rarely a good idea to read arrays at run time: you probably want to read the data into two different arrays when the program starts and then use your [select]
to choose which one is the active array. You can manipulate Heavy arrays ("tables") from the C++ wrapping code. This is what is already happening for multiplexerArray
(although that gets updated while the program runs), but you can reuse most of the code there as a starting point.
The relevant code that is already there is, in setup()
:
multiplexerTableHash = hv_stringToHash(multiplexerArray);
if(context->multiplexerChannels > 0){
pdMultiplexerActive = true;
multiplexerArraySize = context->multiplexerChannels * context->analogInChannels;
hv_table_setLength(gHeavyContext, multiplexerTableHash, multiplexerArraySize);
hv_sendFloatToReceiver(gHeavyContext, hv_stringToHash("bela_multiplexerChannels"), context->multiplexerChannels);
}
this:
- computes and stores the table's hash, to be able to reference the array later more efficiently
multiplexerTableHash = hv_stringToHash(multiplexerArray);
- changes the size of the table to the desired one
hv_table_setLength(gHeavyContext, multiplexerTableHash, multiplexerArraySize);
- sends a message to another receiver containing the length of the array, so that the program knows it
hv_sendFloatToReceiver(gHeavyContext, hv_stringToHash("bela_multiplexerChannels"), context->multiplexerChannels);
then in render()
:
- it simply copies memory into the array:
memcpy(hv_table_getBuffer(gHeavyContext, multiplexerTableHash), (float *const)context->multiplexerAnalogIn, multiplexerArraySize * sizeof(float));
again, you'll want to only fill up your arrays once in setup()
with the content of the files, so you should move this line to setup()
.
Hope this helps.