Prevent "hot" messages from textedit
I am working on a thing that lets the user input words, which are then used as "seed" for a bunch of synth parameter values. (In a way that the immediate relation between letters and parameters a near impossible to decipher, but if you like the outcome, the same string of words will always produce the same set of parameter values.)
My problem is that certain words, like "set", "clear", "textcolor" are interpeted as "productive messages" instead of plain text, and it screws with the patch.
I have attached the textedit-handling part of the thing here. My apologies, it is probably a bit clumsy.
When the user press enter in textedit its content are first filtered through regexpr to allow only letters, but both caps and smallcaps and also most diacritics.
Thereafter the number of words are checked. If below 7, a prompt tells the user that x more words are needed. If above 7, the first 7 are passed as a result. And if exactly 7, they are passed as a result.
After a list of 7 words is achieved, the next stage displays them one by one. This acts as a confirmation so it is clear what words are actually passed along. I wanted to keep this function here even though it makes the patch clumsier, because I think it makes it more clear when "hot words" are messing things up.
If the user writes for example "in tennis there is game set match", the first 5 words are passed correctly and then it stops working, and console reports "missing arguments for message "set" ".
I think one solution would be to have a comprehensive list of words that should be filtered out, but even if I would succeed in making that list cover every possible "hot" word, I would much rather like to make all words "cold" so that the user doesn't have to have words removed.
You will have hard time avoiding issues with words like float
, int
, list
, bang
, and common box attributes like textcolor
.
This said, I played a bit with the recent string and array objects and I managed to get something working.
The key is:
to keep the word "text" from the [textedit] output to make sure any sentence will work even if they start with a "functional word"
convert everything to a string using the string object family
split that string into an array of strings (fortunately string.regexp does that for us)
prepare your messages while they are still strings by prepending "set " to them (mind the space)
and convert the string to a symbol and then to a regular list before it reaches your comment
Thank you so much! Works like a charm.