I want to change patches with a rotary encoder. For that, I use a patchbank and the load/i object. Changing patches works so far, but i need to access the number of patches stored in the patch bank to implement some further instrument change logic. I don't want to store the number in a controller object but rather read it at runtime. I found the function "LoadPatchIndexed" which is called by the load/i, and the c code in patch.c which parses the index.axb file. Although I know basic c/c++ coding I couldn't manage to adapt the code to use it in a patcher object. Any hints how to read the index file from within a patcher object would be really useful.
Get number of patches stored in patch bank on sdcard
DrJustice
#2
Below is an example of reading the number of patches in the patch bank. In the code.declaration section the function count_lines() is defined. It's a simple function that counts the number of new lines in a file. In the code.init section the function is called. The depends section is needed to use the filing system API.
<depends>
<depend>fatfs</depend>
</depends>
<code.declaration><![CDATA[
int count_lines( const char *filename )
{
int n_lines = 0;
FRESULT err;
FIL FileObject;
err = f_open( &FileObject, filename, FA_READ | FA_OPEN_EXISTING );
if( err != FR_OK )
{
f_close( &FileObject );
}
else
{
char byte;
unsigned int bytes_read;
while( !f_eof(&FileObject) )
{
err = f_read( &FileObject, (uint8_t *) &byte, sizeof( char ), &bytes_read );
if( err != FR_OK )
{
break;
}
if( byte == 0x0A )
{
n_lines++;
}
}
f_close( &FileObject );
}
return n_lines;
}
]]></code.declaration>
<code.init><![CDATA[
int n_patches = count_lines( "/index.axb" );
LogTextMessage("number of patches = %d", n_patches );
]]></code.init>