Welcome to %s forums

BrainModular Users Forum

Login Register

store data to file

Create your own modules in C++
Post Reply
User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 06 Jul 2017, 23:54

Hi !
what are the options to save datas to a file with SDK ? seems to me it is only possible to save a wavefile

maybe it is possible to use sdkSaveToDiskAudioFile (AudioFilePtr audiofile, AnsiCharPtr name, int nbChannels)

with a different extention (for exemple .dhh)

and make a special reader

TPrecision only tho, so not good for timestamps...

any idea ?

cheers
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

23fx23
Member
Posts: 2545
Contact:

Unread post by 23fx23 » 07 Jul 2017, 10:55

not that an expert in file hanling, but i now you can use C++ standard files functions, already did read write some stuff.
read/write binary or classic text files mainly, there are several methods. i don't recall all but can check c++ reference, filestream for ex

found back in kinda preset manager that stored datas as text lines i used something like this for ex:

void Preset::SaveToFile(string Path)
{
ofstream outfile;
outfile.open(Path);

// do your lines stuff here ie float to string
outfile << "blablastring" << endl; //line0
outfile << "second line txt" << endl; //line 1 ect, or use a loop

outfile.close();
}
///////////////////////////////
void Preset::ReadFromFile(string Path)
{
fstream infile;
infile.open(Path);

string line;
float F_value = 0;

while (getline(infile, line))
{
getline(infile, line);
F_value = atof(line.c_str()); //string to F value line after line
}
infile.close();
}
//////////////////////////////////////////

or used a different binary one on in other project, among those lines to read wav floats that where saved in a raw binary file, so easier as had no header to mess with
but maybe could start the 'effective' reading after the number of bytes of header if plan using wave files

myfile = fopen(input_file_name, "rb"); //read binary mode
fseek(myfile, 0L, SEEK_END); //scrub all the file
nb_elements = ftell(myfile); // retrieve nb of elements
nb_elements /= 4; // as floats are 4 bytes
rewind(myfile); //returns back at start

values = new float[nb_elements]; // array of float that will get values

fread(values, sizeof(float), nb_elements, myfile); // read file bytes and store to values array
fclose(myfile);

// do stuff with the retrieved array then
//////////

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 19 Jul 2017, 12:46

Thanks 23fx23 , I'll try that.
So far I managed to save in the patch with the chunk system. But definitly will complete the module with a save /load to file option.
Also made a 128x128 for crazy midi stuff
Cheers
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

sm_jamieson
Member
Posts: 551
Contact:

Unread post by sm_jamieson » 20 Jul 2017, 02:33

I used the "pugixml" C++ library for reading and writing XML files (used to save my module's own data settings).

User avatar
oli_lab
Member
Posts: 1261
Location: Brittany, France
Contact:

Unread post by oli_lab » 25 Jul 2017, 11:32

thanks all, that will help !
XML is brilliant as it can organize data and we can make query and mad stuff.

filestream is more straight forwards and is a good candidate for plain array data.

time vs ideas...

cheers

Olivar
http://oli-lab.org

Win11 Ryzen9/32GB RAM - RME MADIFACE - SSL alpha link 4-16 - OSC capable interfaces

follow OLI_LAB adventures on Mastodon
@olivar_premier@mastodon.social

Post Reply

Who is online

Users browsing this forum: No registered users and 60 guests