Page 1 of 1
Posted: 24 Oct 2017, 09:21
by Ant1
Hi everyone,
Does anyone in the community know whether it is possible to read .csv files in Usine. Or perhaps other text file formats, for the purpose of reading data collection and produce sonifications... thank you !
Ant1
Posted: 24 Oct 2017, 14:27
by 23fx23
have a look in script folder read/write textfile
Posted: 24 Oct 2017, 15:52
by sm_jamieson
For a single line of CSV, the Usine "commatext" is just that. In a script you can read in a text file and convert to commatext using built-in pascal/Delphi functions. An example from one of my scripts is below. I'm not sure if you can do it just by wiring modules.
Of course you can do it in C++ in an SDK user module - I use a little CSV function I found, and PUGIXML for XML.
procedure ReadPresetFile(filename : ansiString; inst : integer);
var presetcomma : ansiString;
var presetsList, presetInfList : tstringlist;
var i:integer;
begin
// Read in a preset file and store it in an Instrument record.
// The preset file is a stringlist of commatext
Instruments[inst].filename := filename;
presetsList.create; // whole file - list of presets
presetInfList.create; // preset info being processed
presetsList.LoadFromFile(USINEBASEDIR + '' + PRESETMAPDIR + '' + filename);
setarraylength(Instruments[inst].Presets, presetsList.count);
Instruments[inst].Presetcount := presetsList.count;
for i := 0 to presetsList.count-1 do begin
presetcomma := presetsList.getStrings(i);
presetInfList.setCommaText(presetcomma);
Instruments[inst].Presets.number := StrToInt(presetInfList.getStrings(0));
Instruments[inst].Presets.bank := StrToInt(presetInfList.getStrings(1));
Instruments[inst].Presets.prog := StrToInt(presetInfList.getStrings(2));
Instruments[inst].Presets.name := presetInfList.getStrings(3);
Instruments[inst].Presets.category := presetInfList.getStrings(4);
StoreCategory(Instruments[inst].Categories, Instruments[inst].Presets.category);
presetInfList.clear();
end;
presetsList.free;
presetInfList.free;
end;
Posted: 24 Oct 2017, 16:28
by Ant1
Thanks 23fx23 ! Do you by any chance know where to find more info on how text file should/can be formatted ? Thx in advance.
Posted: 24 Oct 2017, 17:38
by nay-seven
Not sure what you need, but here an patch example with basic manipulation of a csv
place the csv file in your C:
Download
Posted: 24 Oct 2017, 17:39
by 23fx23
it depends a bit of what you want, the simplest way is having a simple text file where each line got a value, ie
1
2
3
...
then i suppose you want convert number values so this script for exemple will read each line, convert text to float and put in an array:
Code: Select all
//////////////////////////
// Read text File lines and outputs float array
/////////////////////////
// declaration
const filename = 'c:list.txt';
var pArray : Tparameter;
var st : TStringList;
//////////////////////////////
procedure destroy;
begin
st.free;
end
// initialisation : create parameters
procedure init;
var i : integer;
begin
pArray := CreateParam('Array_out',ptArray);
setIsInput(pArray,false);
//////////////////////////////////////////////////////
st.create;
st.clear;
st.loadfromFile(filename);
setLength(pArray,st.count);
for i := 0 to st.count-1
do begin
setDataArrayValue(pArray,i,strToFloat(st.getstrings(i)));
end;
st.free;
end;
//////////////////////////////////
if you can't get a line by line text easily, but got values separated by commas ie 1,2,3,4,5,6, ect on a single line can use this one:
Code: Select all
//////////////////////////
// Read text File lines and outputs float array
/////////////////////////
// declaration
const filename = 'c:list.txt';
var pArray : Tparameter;
var stA : TStringList;
var st : TStringList;
//////////////////////////////
procedure destroy;
begin
st.free;
stA.free;
end
// initialisation : create parameters
procedure init;
var i : integer;
begin
pArray := CreateParam('Array_out',ptArray);
setIsInput(pArray,false);
//////////////////////////////////////////////////////
st.create;
st.clear;
stA.create;
stA.clear;
///////////////////////////////////
stA.loadfromFile(filename);
St.SetCommaText(stA.getstrings(0));
setLength(pArray,st.count);
for i := 0 to st.count-1
do begin
setDataArrayValue(pArray,i,strToFloat(st.getstrings(i)));
end;
st.free;
end;
Edit : cross post hadn't see nay's one, might work out of the box

Posted: 24 Oct 2017, 20:22
by nay-seven
And for fun a more ergonomic and musical one
of course works with simple csv , one colonne..( same csv file as before)
Download
Posted: 25 Oct 2017, 17:06
by Ant1
Merci à tous ! J'explore tout çà.
A