function to string processing

Discuss Lemur and share techniques.
Post Reply
Leo Souza
Newbie
Posts: 5
Joined: 20 Jan 2012 13:54

function to string processing

Post by Leo Souza »

Hi all,

I have developed this funcion at topmost level to help with string processing

Code: Select all

name: converteHex
parameter: car

decl val=car;

if(car == '0') val = 0x30;
if(car == 0) val = 0x30;
else if(car == '\') val = 0x5C;
else if(car == '/') val = 0x2F;

else if(car == '1') val = 0x31;
else if(car == '2') val = 0x32;
else if(car == '3') val = 0x33;
else if(car == '4') val = 0x34;
else if(car == '5') val = 0x35;
else if(car == '6') val = 0x36;
else if(car == '7') val = 0x37;
else if(car == '8') val = 0x38;
else if(car == '9') val = 0x39;

else if(car == 1) val = 0x31;
else if(car == 2) val = 0x32;
else if(car == 3) val = 0x33;
else if(car == 4) val = 0x34;
else if(car == 5) val = 0x35;
else if(car == 6) val = 0x36;
else if(car == 7) val = 0x37;
else if(car == 8) val = 0x38;
else if(car == 9) val = 0x39;

else if(car == 'a') val = 0x61;
else if(car == 'b') val = 0x62;
else if(car == 'c') val = 0x63;
else if(car == 'd') val = 0x64;
else if(car == 'e') val = 0x65;
else if(car == 'f') val = 0x66;
else if(car == 'g') val = 0x67;
else if(car == 'h') val = 0x68;
else if(car == 'i') val = 0x69;
else if(car == 'j') val = 0x6A;
else if(car == 'k') val = 0x6B;
else if(car == 'l') val = 0x6C;
else if(car == 'm') val = 0x6D;
else if(car == 'n') val = 0x6E;
else if(car == 'o') val = 0x6F;
else if(car == 'p') val = 0x70;
else if(car == 'q') val = 0x71;
else if(car == 'r') val = 0x72;
else if(car == 's') val = 0x73;
else if(car == 't') val = 0x74;
else if(car == 'u') val = 0x75;
else if(car == 'v') val = 0x76;
else if(car == 'w') val = 0x77;
else if(car == 'x') val = 0x78;
else if(car == 'y') val = 0x79;
else if(car == 'z') val = 0x7A;

else if(car == 'A') val = 0x41;
else if(car == 'B') val = 0x42;
else if(car == 'C') val = 0x43;
else if(car == 'D') val = 0x44;
else if(car == 'E') val = 0x45;
else if(car == 'F') val = 0x46;
else if(car == 'G') val = 0x47;
else if(car == 'H') val = 0x48;
else if(car == 'I') val = 0x49;
else if(car == 'J') val = 0x4A;

else if(car == 'K') val = 0x4B;
else if(car == 'L') val = 0x4C;
else if(car == 'M') val = 0x4D;
else if(car == 'N') val = 0x4E;
else if(car == 'O') val = 0x4F;
else if(car == 'P') val = 0x50;
else if(car == 'Q') val = 0x51;
else if(car == 'R') val = 0x52;
else if(car == 'S') val = 0x53;
else if(car == 'T') val = 0x54;
else if(car == 'U') val = 0x55;
else if(car == 'V') val = 0x56;
else if(car == 'W') val = 0x57;
else if(car == 'X') val = 0x58;
else if(car == 'Y') val = 0x59;
else if(car == 'Z') val = 0x5A;

return val;
and this is how is to be used:

Code: Select all

name: joinChars
parameters: array

// array is come vector like {'/','l','a','y','e','r',1,'/','c','l','i','p',1,'/','c','o','n','n','e','c','t'};

decl saida,i,size,arraySaida;
size = sizeof(array);
arraySaida=stretch(0,size);

for (i=0;i<size;i++)
{
 arraySaida[i] = converteHex(array[i]);
}

saida = arraytostring(arraySaida);

return saida;
this allow us to make something like this in a button:

Code: Select all

decl clicado = firstof(x)+1;

decl endOSC = {'/','l','a','y','e','r',1,'/','c','l','i','p',1,'/','c','o','n','n','e','c','t'};
decl layer = 1;

decl definicaoDeClip = 12;
decl definicaoDeLayer = 6;

endOSC[definicaoDeClip] = clicado;
endOSC[definicaoDeLayer] = layer;

endereco = joinChars(endOSC);

oscout(0,endereco,1);
Last edited by Leo Souza on 22 Feb 2012 15:13, edited 3 times in total.
SuperChester
Newbie
Posts: 6
Joined: 01 Feb 2012 04:14

Re: function to string processing

Post by SuperChester »

Is the 2nd block of code supposed to be named "joinChars"?
Do these functions help with concatenating strings?
I'm not at home to test at the moment, but would I be able to monitor/trace additional hex codes to add to the first function (such as a colon:) or is there a limit to characters that are available to the Lemur?

If this works as I think it's intending, then this is something I have wanted for a few weeks, so thank you!
Leo Souza
Newbie
Posts: 5
Joined: 20 Jan 2012 13:54

Re: function to string processing

Post by Leo Souza »

Hi,

Yes I fixed that. Sorry.

This is a way to concatenate strings yeah! And the converteHex function could be improved with all ascii hex codes. Linke those in: http://www.asciitable.com/

Good use!
joebataz
Regular
Posts: 154
Joined: 28 Feb 2012 16:50
Location: Anthem, AZ USA
Contact:

Re: function to string processing

Post by joebataz »

once again, newbie question.
how do I define a function with parameters?

TIA,

Joe B
www.stoneagelighting.com
"old as dirt and made from rock..."
SuperChester
Newbie
Posts: 6
Joined: 01 Feb 2012 04:14

Re: function to string processing

Post by SuperChester »

joebataz wrote:once again, newbie question.
how do I define a function with parameters?

TIA,

Joe B
You need to select the folder, on the right, where you want the function to reside. Global functions will be top most, so that it's available to every folder beneath it. After selecting the folder, press the "SCRIPT" button below that window. It will ask you to name the script/function. In the example Leo created for us above, you would name the function convertHex(car). This creates the function "convertHex" with the parameter "car" in parenthesis. Then you can code the function in the multi-line box that appears. The variable "car" will be available immediately as it's "declared" in the function creation. Additional variables will need to be defined with "decl".
joebataz
Regular
Posts: 154
Joined: 28 Feb 2012 16:50
Location: Anthem, AZ USA
Contact:

Re: function to string processing

Post by joebataz »

thanks mate!
www.stoneagelighting.com
"old as dirt and made from rock..."
bxsj
Regular
Posts: 116
Joined: 24 Dec 2011 06:47
Location: Vienna

Re: function to string processing

Post by bxsj »

Just a little addition. It is possible to define multiple parameters to a script:

test_script(par1, par2, par3)

B.
Win7 64, Ipad Lemur, Cubase6 and a bunch of Roland Synths and Samplers
Post Reply