Hi,
Being new with Bela ( just finished building my Pepper Rev2) , I struggle with Arrays in Pd and HVCC. My question might be simple to answer ( but I don't find a working solution) : How to load a text file into a table or array by clicking on a button on Pepper and compile this with Heavy?
What I am trying to achieve is the following (provided that the array already exists and all files are the same size (1024 points) and that the button responds correctly):

[r bela_digitalIn24 @hv_param ]
|
[ change ]
|
[counter]
|
[ select 1 2 ]
| |
[ MyArray read Foo.txt ( |
[ MyArray read bar.txt (

Any help to achieve this is welcome ( I am no good in programming in C)
Thank you a lot for help.

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.

Thank you a lot Guilomoro ! I will study your howto ASAP.
In the meanwhile, I loaded all data into several arrays (32 in total) and saved the status of the arrays in Pd.
Heavy does not complain about reading arrays instead of tables. I suppose these are the same in Pd.
Now my patch works and I am be glad to share it if anyone would like to try it. The file is attached.
One thing could be doe would be to adapt it for midi input if someone wishes to use a keyboard with it.
There is a short manual in the patch ( But 2 is not implemented in this version).
https://patchstorage.com/waveshaper-for-bela-pepper-hvcc-compatible/

yes, that's what heavy recommends for populating arrays. I thought you needed to fill them in from the file at runtime.