Old 09-19-2016, 04:39 PM   #1
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default Q: Parse CSV file with JSFX

Hi,

I am a bit confused that string format and function in JSFX.

imagine a file like
Code:
45-50
40-51
68-98
The seperator - can be replace with any other separator.


Here is the code for sampling a file (from MIDI Pattern/Scale Variation Generator [IXix])
Code:
@slider
seqFile != slider8 ?
(
  seqFile = slider8;
  seqSize = 0;
  fileHandle = file_open(slider8);
  fileHandle > 0 && file_text(fileHandle) ?
  (
    while
    (
      file_var(fileHandle,seq[seqSize]);
      file_avail(fileHandle) ? seqSize += 1;
    );
    file_close(fileHandle);
  );
);
You can then access a line with seq[x] where x is the number of the line.

But how will you return two variables from that line ? How would you parse the "45-50" into two int variable ?
I only succeed to get int when there is only one number per line, but not two with a sperator.

Thanks for your help !

Last edited by X-Raym; 09-19-2016 at 07:30 PM.
X-Raym is offline   Reply With Quote
Old 09-19-2016, 07:01 PM   #2
James HE
Human being with feelings
 
James HE's Avatar
 
Join Date: Mar 2007
Location: I'm in a barn
Posts: 4,467
Default

The internal parsing that IXIX's code is doing is tied specifically to sliders and ignores non numbers, and con only read a single variable.

however, you could do

Code:
45.50
40.51
68.98
and manipulate it mathematically to parse the variables.

so you'd have to use a text editor to convert " - " into "."


You can use file_string(handle,str) to get the text, however, this only reads the first line - it should be able to do newlines, might be some encoding issue, might be a bug. will AskJF.

*asked justin and the great oracle answered see post #11

Last edited by James HE; 09-20-2016 at 05:22 PM.
James HE is offline   Reply With Quote
Old 09-19-2016, 07:44 PM   #3
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default

@JamesHE
thank you james for the precision, it helps,
I missed the file_string function, is the second parameter supposed to be the line number in "read" mod ?

But yes indeed, a solution without match/string function can work for my particular case.

The number tricks is a good idea, not very difficult to implement (just math floor for the first value)

I will change the - to . inside the script which generates this CSV.

Stay tuned for the script, should came out tomorrow :P

Last edited by X-Raym; 09-20-2016 at 04:03 AM.
X-Raym is offline   Reply With Quote
Old 09-19-2016, 10:40 PM   #4
planetnine
Human being with feelings
 
planetnine's Avatar
 
Join Date: Oct 2007
Location: Lincoln, UK
Posts: 7,942
Default

What about a comma?

Isn't that what the "C" is in CSV? (comma separated values)




>
__________________
Nathan, Lincoln, UK. | Item Marker Tool. (happily retired) | Source Time Position Tool. | CD Track Marker Tool. | Timer Recording Tool. | dB marks on MCP faders FR.
planetnine is offline   Reply With Quote
Old 09-20-2016, 01:30 AM   #5
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 19,681
Default

Wouldn't the match() function be the one to use?

I would post the answer but have never really understood how to define the matching pattern
__________________
DarkStar ... interesting, if true. . . . Inspired by ...
DarkStar is offline   Reply With Quote
Old 09-20-2016, 03:01 AM   #6
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,900
Default

@planetnine
Actuallly, it is for "Character", it is very often a space or a a tab :P

But the problem is more about variable value than line formatting, I can change it without problem.

@DarkStar
spk77 and gofer already made a example of match function used in eel,
ReaScripts-Templates/gofer-spk77-Functions - User inputs fields.eel at master · ReaTeam/ReaScripts-Templates
but for some reason it didn't work with the way the file is parsed using the code I show in post 1.
JamesHE explained why: this parsing method doesn't support strings

@all
If anyone find a workable solution involving more columns (without math tricks), I'm sure it could be very useful.
Thanks for your suggestions !
X-Raym is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:53 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.