CSV
have a look in script folder read/write textfile
-
sm_jamieson
- Member
- Posts: 555
- Contact:
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;
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;
Thanks 23fx23 ! Do you by any chance know where to find more info on how text file should/can be formatted ? Thx in advance.
Not sure what you need, but here an patch example with basic manipulation of a csv
place the csv file in your C:
Download
place the csv file in your C:
Download
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:
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:
Edit : cross post hadn't see nay's one, might work out of the box 
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;
//////////////////////////////////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;And for fun a more ergonomic and musical one
of course works with simple csv , one colonne..( same csv file as before)
Download
of course works with simple csv , one colonne..( same csv file as before)
Download
Who is online
Users browsing this forum: No registered users and 13 guests
