|
|
|
12-18-2013, 07:43 AM
|
#1
|
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 15,721
|
JSFX string support discussion thread
Discuss the new JS string support here!
-----
This will end up in the JSFX documentation eventually:
Some other string related functions available:
- sprintf(str,"string %{varname}d blah");
- strlen("test") == 4
- match("*test*", "this is a test") != 0
- matchi("*tESt*", "this is a test") != 0
For these you can use simplified regex-style wildcards:- * = match 0 or more characters
- *? = match 0 or more characters, lazy
- + = match 1 or more characters
- +? = match 1 or more characters, lazy
- ? = match one character
and format specifiers:- %s means 1 or more chars
- %0s means 0 or more chars
- %5s means exactly 5 chars
- %5-s means 5 or more chars
- %-10s means 1-10 chars
- %3-5s means 3-5 chars.
- %0-5s means 0-5 chars.
- (also, x, d, u, f are available, and c too but it can't take length parameters)
Example:
Code:
match("*%4{blah}d*","some four digit value is 8000, I say")==1 && blah == 8000
- strcpy(str, srcstr);
- strcat(str, srcstr);
- strcmp(str, str2);
- stricmp(str, str2);
- strncmp(str, str2, maxlen);
- strnicmp(str, str2, maxlen);
- strncpy(str, srcstr, maxlen); // maxlen=-1 for unlimited
- strncat(str, srcstr, maxlen); // maxlen=-1 for unlimited, refers to maximum bytes of srcstr
- strcpy_from(str,srcstr, offset); // copies srcstr to str, but starts reading srcstr at offset offset
- str_getchar(str, offset); //returns value at offset offset
- str_setchar(str, offset, value); //sets value at offset offset (must be within strlen())
- str_setlen(str, len); // sets length of string (if increasing, will be space-padded)
- str_delsub(str, pos, len); // deletes len chars at pos
- str_insert(str, srcstr, pos); //inserts srcstr at pos
- pre2+:
- strcpy_fromslider(str, [slider1 or 1-based slider index) // gets the filename if a file-slider, or the string if the slider specifies string translations, otherwise gets an empty string
- gfx_printf("this is a %{somestring}s"); etc, identical to gfx_drawstr(sprintf(#,"this is a ..."));
- file_open() can now take a string filename directly, i.e. file_open("whatever.txt") opens Appdata\REAPER\Data\whatever.txt
- file_string(handle, str) can now be used.
- If in @serialize and handle is 0, it will read or write a string blob, up to about 16kb of data, which can include NULL characters if need be (it is encoded as size and string).
- If used with a handle return by file_open(), and not a .wav or .ogg file, it will return a line of text (including any newlines etc), i.e. it mimics fgets().
Variables that reference strings must be set to constant values between 0 and 1023, or to a literal string such as "xyz", or an unnamed mutable string (#), or a named mutable string like #xyz.
Code:
x = strcpy(#, "boo");
y=x;
strcat(y,"hoo"); // y and x point to the same string, value of which is "boohoo"
or
Code:
x = 500; // use user string slot 500
strcpy(x,"boo"); // set value of user string...
y=x;
strcat(x,"hoo"); // y and x point to the same string, value of which is "boohoo"
It's important to note the difference between #str and str. #str has its own storage for the string, and str is a number that can only point to a string.
Code:
str = "blah blah";
#str = "blah blah";
str2 = #str;
strcat(#str, "test"); // valid, #str becomes "blah blahtest", since #str is mutable
strcat(str,"test"); // invalid, will not modify str since str refers to the literal "blah blah"
// str2 also points to "blah blahtest" since it refers to #str
Also, most string functions return the string they modify, so you can do things like:
Code:
gfx_drawstr(sprintf(#, "the value of boo is %{boo}f, and zzz is %{#zzz}s"));
As of 4.59pre2, you can use the string functions in any section.
Last edited by Justin; 12-28-2013 at 09:48 PM.
Reason: pre4
|
|
|
12-18-2013, 07:30 PM
|
#2
|
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 15,721
|
Pulled this from the 4.59pre1 thread, and updated for pre2 -- changes: fixes to string support, threadsafety fixes (this will make strings slightly more slow, but it shouldn't really be a problem if you're not using them in @sample or @block...), added strcpy_fromslider(), file_open(string), gfx_printf(), and file_string().
|
|
|
12-19-2013, 02:15 AM
|
#3
|
Human being with feelings
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
|
Nothing to report yet, except: Cool!
|
|
|
12-19-2013, 07:30 AM
|
#4
|
Human being with feelings
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,889
|
Aaargh! I've no time to play (bad time of year!) but this looks very exciting. Can't wait to dive in and see what's what. I can't believe you just implemented all of this out of the blue!
|
|
|
12-19-2013, 09:08 PM
|
#5
|
Administrator
Join Date: Jan 2005
Location: NYC
Posts: 15,721
|
Quote:
Originally Posted by IXix
I can't believe you just implemented all of this out of the blue!
|
It came from making midi2osc AKA OSCII-bot...
|
|
|
12-23-2013, 05:45 AM
|
#6
|
Human being with feelings
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,889
|
So far so good, although I haven't had time to dig deep.
They say that if you don't ask, you don't get, so is there any chance we could get adjustable text size? How about different typefaces and antialiased text?
|
|
|
12-23-2013, 06:08 AM
|
#7
|
Human being with feelings
Join Date: Jun 2009
Location: Croatia
Posts: 24,790
|
Quote:
Originally Posted by IXix
so is there any chance we could get adjustable text size? How about different typefaces and antialiased text?
|
This would be so awesome.
|
|
|
12-23-2013, 09:41 AM
|
#8
|
Human being with feelings
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,889
|
Thinking about it a little, I don't think it would be that hard to make a user function that could take a string as input and blit appropriate characters from a typeface image. Hmmm...
|
|
|
12-19-2013, 09:21 AM
|
#9
|
Human being with feelings
Join Date: Dec 2008
Posts: 117
|
Kudos for avoiding syntactic sugar (e.g. C-shell) here, too.
|
|
|
Thread Tools |
|
Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 10:10 AM.
|