Forums > MaxMSP

list letter shifting

September 11, 2007 | 8:11 pm

Hello, I would like to make a patch that shifts every letter in the words in a text field over one letter and spits them out into another text field shifted. For example, Cat in the Hat would become DBU jo uif Ibu. Does anybody have any suggestions as to how I would go about constructing this in max?

thanks a lot

sincerely

jared madere


September 11, 2007 | 8:23 pm

On 11 sept. 07, at 22:11, Jared Madere wrote:

>
> Hello, I would like to make a patch that shifts every letter in the
> words in a text field over one letter and spits them out into
> another text field shifted. For example, Cat in the Hat would
> become DBU jo uif Ibu. Does anybody have any suggestions as to how
> I would go about constructing this in max?

It’s pretty easy to achieve with atoi/itoa which gives you a numeric
representation of the ASCII letters. You probably gonna have to make
something wrapping though.

ej

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 279 270 114 196617 loadmess scalarmode 1;
#P message 401 386 50 196617 upup;
#P newex 401 357 62 196617 prepend set;
#P newex 465 213 27 196617 t b i;
#P newex 401 241 36 196617 zl reg;
#P number 465 193 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 401 299 91 196617 vexpr $i1+$i2;
#P newex 401 328 40 196617 itoa;
#P newex 401 270 40 196617 atoi;
#P newex 401 212 56 196617 route text;
#P user textedit 401 129 501 179 32896 3 9 toto;
#P connect 10 0 4 0;
#P connect 8 0 9 0;
#P connect 3 0 8 0;
#P connect 7 1 4 1;
#P connect 7 0 6 0;
#P connect 5 0 7 0;
#P connect 6 0 2 0;
#P connect 1 0 6 0;
#P connect 4 0 3 0;
#P connect 2 0 4 0;
#P connect 0 0 1 0;
#P window clipboard copycount 11;


September 11, 2007 | 8:29 pm

Here is one possibility.

-Adam

#P window setfont "Sans Serif" 9.;
#P number 267 118 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 236 258 64 196617 fromsymbol;
#P newex 164 189 27 196617 32;
#P newex 164 165 52 196617 select 32;
#P window linecount 2;
#P message 236 312 50 196617 Dbu jo uif Ibu;
#P window linecount 1;
#P newex 190 92 56 196617 t b s clear;
#P newex 236 233 40 196617 itoa;
#P newex 206 191 27 196617 + 1;
#P newex 236 284 62 196617 prepend set;
#P message 190 66 71 196617 Cat in the Hat;
#P newex 164 139 31 196617 spell;
#P window linecount 2;
#P comment 75 165 100 196617 don’t shift space (32);
#P window linecount 1;
#P comment 310 120 100 196617 shift amount;
#P connect 12 0 5 1;
#P connect 4 0 8 0;
#P connect 11 0 4 0;
#P connect 6 0 11 0;
#P fasten 10 0 6 1 169 219 256 219;
#P connect 9 0 10 0;
#P connect 9 1 5 0;
#P connect 2 0 9 0;
#P fasten 5 0 6 1 211 219 256 219;
#P connect 7 1 2 0;
#P fasten 7 0 6 0 195 123 241 123;
#P connect 7 2 6 0;
#P connect 3 0 7 0;
#P window clipboard copycount 13;


September 11, 2007 | 11:55 pm

that works great, thank you so much. the only problem is that certain characters such as quotation marks and commas do not even get registered. I would like to be able to put an entire essay into the patch and have it shift every letter and number in it one character up. does anybody know how to go about making max recognize " and , as symbols and not simply ignoring them?

max v2;
#N vpatcher 165 44 1401 718;
#P window setfont "Sans Serif" 9.;
#P newex 244 360 27 196617 58;
#P newex 203 361 27 196617 39;
#P newex 165 361 27 196617 46;
#P newex 136 361 27 196617 33;
#P newex 105 360 27 196617 63;
#P newex 638 176 32 196617 print;
#P message 639 145 14 196617 ,;
#P newex 297 203 56 196617 route text;
#P newex 864 389 56 196617 route text;
#P user textedit 811 224 968 315 32896 3 9 ;;
#P newex 758 494 32 196617 print;
#P newex 785 423 31 196617 spell;
#P button 114 28 15 0;
#P user textedit 244 51 517 176 32896 3 9 if you think you’re pootie tangin;
#P number 381 270 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 350 410 64 196617 fromsymbol;
#P newex 63 362 27 196617 32;
#P newex 89 328 127 196617 select 32 63 33 46 39 58;
#P message 350 464 163 196617 jg zpv uijol zpv’sf qppujf ubohjo;
#P newex 304 244 56 196617 t b s clear;
#P newex 350 385 40 196617 itoa;
#P newex 395 334 27 196617 + 1;
#P newex 350 436 62 196617 prepend set;
#P newex 276 296 31 196617 spell;
#P window linecount 2;
#P comment 6 326 61 196617 don’t shift space (32);
#P window linecount 1;
#P comment 424 272 100 196617 shift amount;
#P connect 8 0 9 0;
#P connect 2 0 8 0;
#P connect 8 1 21 0;
#P connect 8 2 22 0;
#P connect 8 3 23 0;
#P connect 8 4 24 0;
#P connect 13 0 12 0;
#P connect 8 5 25 0;
#P connect 6 1 2 0;
#P connect 12 0 18 0;
#P connect 18 0 6 0;
#P fasten 6 0 5 0 309 275 355 275;
#P connect 6 2 5 0;
#P connect 5 0 10 0;
#P connect 10 0 3 0;
#P connect 3 0 7 0;
#P fasten 9 0 5 1 68 378 370 378;
#P fasten 4 0 5 1 400 371 370 371;
#P connect 21 0 5 1;
#P connect 22 0 5 1;
#P connect 23 0 5 1;
#P connect 24 0 5 1;
#P connect 25 0 5 1;
#P connect 8 6 4 0;
#P connect 11 0 4 1;
#P connect 19 0 20 0;
#P connect 14 0 15 0;
#P connect 17 0 14 0;
#P connect 16 0 17 0;
#P pop;


September 12, 2007 | 12:17 am

Quote: jaredmadere@mac.com wrote on Tue, 11 September 2007 16:55
—————————————————-
> tthe only problem is that certain characters such as quotation marks and commas do not even get registered. … does anybody know how to go about making max recognize " and , as symbols and not simply ignoring them?
>

Try putting a backslash before special characters, so type " and , instead of " and ,

If the letter shifting turns a character into a quote or comma, you may still have problems. I don’t know if that will be the case, but if it is you should be able to special case it to do the right thing before the itoa object.

-Adam


September 12, 2007 | 4:08 am

why is it that text entered into this version of the patch, only seems to have part of it translated? try pasting any text document longer than a few paragraphs in and see what i mean.

max v2;
#N vpatcher 245 44 925 717;
#P origin 0 14;
#P window setfont "Sans Serif" 9.;
#N standalone;
#S creator ????;
#S statusvisible 0;
#S noloadbangdefeating 0;
#S useownplist 0;
#S preffilename "Max 4 Preferences";
#S overdrive 0;
#S allwindowsactive 0;
#S searchformissingfiles 1;
#S usesearchpath 0;
#S cantclosetoplevelpatchers 1;
#S audiosupport 1;
#S midisupport 1;
#P hidden newobj 112 21 57 196617 standalone;
#P user textedit 342 41 646 624 32896 3 9 b;
#N vpatcher 20 74 741 526;
#P origin -9 0;
#P outlet 355 361 15 0;
#P inlet 286 42 15 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 282 241 27 196617 97;
#P newex 238 245 27 196617 58;
#P newex 197 246 27 196617 39;
#P newex 159 246 27 196617 46;
#P newex 130 246 27 196617 33;
#P newex 99 245 27 196617 63;
#P newex 291 88 56 196617 route text;
#P newex 344 295 64 196617 fromsymbol;
#P newex 57 247 27 196617 32;
#P newex 84 216 148 196617 select 32 63 33 46 39 58 122;
#P newex 298 129 56 196617 t b s clear;
#P newex 344 270 40 196617 itoa;
#P newex 389 219 27 196617 + 1;
#P newex 344 321 62 196617 prepend set;
#P newex 270 181 31 196617 spell;
#P window linecount 2;
#P comment 0 211 61 196617 don’t shift space (32);
#P connect 6 0 7 0;
#P connect 1 0 6 0;
#P connect 6 1 10 0;
#P connect 6 2 11 0;
#P connect 6 3 12 0;
#P connect 6 4 13 0;
#P connect 6 5 14 0;
#P connect 5 1 1 0;
#P connect 6 6 15 0;
#P connect 16 0 9 0;
#P connect 9 0 5 0;
#P fasten 5 0 4 0 303 160 349 160;
#P connect 5 2 4 0;
#P connect 4 0 8 0;
#P connect 8 0 2 0;
#P connect 2 0 17 0;
#P connect 15 0 4 1;
#P fasten 7 0 4 1 62 263 364 263;
#P fasten 3 0 4 1 394 256 364 256;
#P connect 10 0 4 1;
#P connect 11 0 4 1;
#P connect 12 0 4 1;
#P connect 13 0 4 1;
#P connect 14 0 4 1;
#P connect 6 7 3 0;
#P pop;
#P hidden newobj 201 663 49 196617 p shifter;
#P user textedit 22 41 326 624 32896 3 9 a;
#P hidden connect 0 0 1 0;
#P hidden connect 1 0 2 0;
#P pop;


September 12, 2007 | 7:42 am

On 12 Sep 2007, at 01:55, Jared Madere wrote:

>
> that works great, thank you so much. the only problem is that
> certain characters such as quotation marks and commas do not even
> get registered. I would like to be able to put an entire essay into
> the patch and have it shift every letter and number in it one
> character up. does anybody know how to go about making max
> recognize " and , as symbols and not simply ignoring them?

first of all, if you want to filter " and , you should put in the
corresponding ascii numbers, i.e. 34 and 44.
but it’s true, since these characters have special meanings in max,
it’s a little cumbersome to deal with them.
therefore i would suggest using javascript for this task – at least
for the text file reading.
here is a little script that reads a text file (use raw text and not
some word docs etc.) and feeds single lines back to max.
send it the message [readfile my_file] to read in a text, and
[get_line x] to access it.
you can bypass the [textedit] object. but [itoa] e.g. can only handle
256 elements. that won’t give you very long sentences…
in the end i think it’s easier to do the whole thing in js.
vb

// (watch out, email coding…)

outlets = 2;
var lines = new Array();

function readfile(s) {
lines = new Array();
var f = new File(s);
var c, line;

if (f.isopen) {
c = f.eof;
line=0;
while(f.position
lines[line] = f.readline();
line++; // increment line count
}
outlet(1, line);
f.close();
}
else {
post(">>> could not open file: " + s + "n");
}
}

function get_line( i ) {
outlet(0, lines[i]);
}


September 12, 2007 | 5:49 pm


Viewing 8 posts - 1 through 8 (of 8 total)