textedit adds quotes around text that contains space. How to avoid this?
Each time the Live set is saved the text in the textedit has a set of double quotes placed around the original string. After a couple of saves there are nested quotes involving \" the resulting mess is ugly and unreadable by what comes next in the processing sequence. I'm trying to replace the contents by stripping the added characters ( with a js) but this is turning out to be difficult for reasons I'm having difficulty grasping.
This must be a common issue, is there a standard way to handle this situation?
thanks
Made it work. Was able to remove the quotes (with a js object) and (re)set the text each time the textedit is banged. If anyone wants the details I'll post it here.
Hi, could you please share what you came up with? I have no experience in js but I'm trying to keep the textedit cleanstrings after restart too, so any help would be appreciated!
Thanks!
Here's the *.js:
//post("Remove quotes from text...\n");
inlets = 1; //action list string to be processed by ClyphX Pro
outlets = 2; //left: to ClyphX, right: (re)set contents of textedit (quotes removed)
function textin(t,r) //t contains "text", r contains the textedit text
{
var i;
for(i=0;i<r.length;i++){ //delete doublequote chars
if (r.charCodeAt(i)==34) {
r=r.slice(0,i)+r.slice(i+1);
}
}
outlet(0, "text", r.toString()); //send it to clyphX Pro
outlet(1, "set", r.toString()); //reset contents of textedit
}
The js object's input takes the output of the textedit object, and the right output of the js object is patched to the input of the textedit object. The left output is for the application to use.
Hope this helps!
Hhmm...all I get is an error message saying "no function text". No output from the js object whatsoever. What could I have done wrong here?
The left output sends a message which is prepended by the symbol "text" because in my patcher there is a js object with a function called "text" into which the string (de quoted text) the is being passed.
You can modify the line
outlet(0, "text", r.toString());
to suit your application. What are you doing with the output?
Is the right output connected?
To be clear, the right output of the js object needs to be patched back into the input of the text edit.
The output of the text edit is (naturally) patched to the input of the js object.
The left output of the js object can be customised to the application (as I suggest above).
Thanks for your help!
But right now, I can't even get the js file to output anything. If the message being sent into its inlet starts with "text" I get the error message in Max console "js: no function text". I tried changing "text" to "textin (+ whatever string...)" to match the name of the function but then I get the error "JavaScript TypeError : r is undefined, line 10". Again, I have no experience with js so I might be missing something obvious...
Ok I didn't explain it properly:
My use case is to have a Textedit in a max4live device that contains ClyphX Pro script commands that execute whenever the live set is loaded. The script commands in the Textedit object can be added to, or modified and they get executed and saved with the set and then executed again the next time the live set is loaded into Ableton.
The problem I hit when I started working with this device is that because my textedit text contained spaces (as clyphx command strings may) the textedit object would automagically put quotes around the text. Then when I reload it puts quotes around the quotes etc, resulting in a broken mess.
So the purpose of the js object is to "clean up" the text by removing quotes and then re-load the contents of the textedit with the text (minus quotes). Of course the Textedit adds quotes back and they appear in the textedit but they don't damage the functionality anymore.
I have made a small code change to simplify it's use (see below).
The input to js object is patched to the left output of the Textedit. The left output of a textedit is a message with the symbol "text" then the text contents as a single string. With a js object the first symbol received in a message is the function name (in this case text()), followed by the argument to the function "r".
The left output (of the js object) is the message "text" followed by the text for your application to use as it would the output of the textedit. The right output must be patched to the input of the textedit, this replaces the text with de-quoted string (note you will still see a single pair of quotes around the text containing spaces, as I mentioned).
//post("Remove quotes from text...\n");
inlets = 1; //action list string to be processed by ClyphX Pro
outlets = 2; //left: to ClyphX, right: (re)set contents of
//textedit (quotes removed)
function text(r) //r contains the textedit text
{
var i;
for(i=0;i<r.length;i++){ //delete doublequote chars
if (r.charCodeAt(i)==34) {
r=r.slice(0,i)+r.slice(i+1);
}
}
outlet(0, "text", r.toString()); //send it to clyphX Pro
outlet(1, "set", r.toString()); //reset contents of textedit
}
Ah, I see, so all I needed to do with the first js you sent me was to prepend "textin" before "text textedit_string". Now it works fine except I need to use quotes for track and device names unfortunately.
Ah, I see, so all I needed to do with the first js you sent me was to prepend "textin" before "text textedit_string".
Yes I neglected to mention the prepend "textin" in my device. I realised I could make it simpler and clearer without the need to prepend which is what I did in the updated (second) version .
Now it works fine except I need to use quotes for track and device names unfortunately.
If your talking about the text displayed in textedit's: if it has spaces it will show quotes and there is nothing that will change this behaviour. Of course text strings can be displayed by Comment objects without the unwanted quotes.
Yes, thank you for simplifying it, and now I understand better how the input needs to be formatted.
Concerning textedit object's text, I meant that I need to use quotes for specifying track name or device name for ClyphX actions such as "Track Name"/MUTE. But now the js code removes them which makes these actions unusable. I guess you weren't using track/device names in your project?
If you're using clyphX then you may find this intersting. It's the device (based on one that comes with clyphX pro) modifyed to remember it's state in between ableton sessions. It's actually what lead me down this particular rabbit hole of textedit quotes behaviour and the work around I came up with.
The textedit can be entered with ClyphX Pro command list as per the ClyphX documentation. List elements are separated by semicolon. A basic test would be "METRO" or "METRO;METRO;METRO" which would toggle the state of the metronome each time a liveset is saved/reloaded. The point of the device is to execute clyphx commands every time a set is loaded to put things into the desired state.
But this is the exact same js file you sent me earlier isn't it? I already have my own device for triggering ClyphX actions. The only problem with the js file you created is that it will erase the double-quotes needed for some CLyphX actions with specified track, clip or device names such as:
"Track Name"/MUTE
1/PLAY "Clip Name"
SEL/DEV("Device Name")
The js code is named for the max device I posted.
Sounds like the js code you need will parse the strings more carefully and only remove the outside quotes.
The code I posted is a good starting template for what you need. There are lots of resources for javascript online. I learned js purely for working with max because it complements max so well (it's why they embedded it!). Well worth the learning curve, I promise!