[javascript-dev] JSUI : question about Array index/value
lists at simonadcock.co.uk
lists at simonadcock.co.uk
Wed Oct 3 08:38:20 MDT 2007
- Previous message: [javascript-dev] JSUI : question about Array index/value
- Next message: [javascript-dev] Re: RE: JSUI : question about Array index/value
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
I'm no expert either, but I'd have thought something along the lines of this
would be work:
var Ratio = ["1:1", "2:1", "3:1","4:1", "6:1", "10:1"];
function ratio(a)
{
for(i=0; i<Ratio.length; i++)
{
if(Ratio[i] == a)
{
outlet(0, i);
}
}
}
If you send "ratio 3:1" you'll get back "2" out the outlet.
max v2;
#N vpatcher 15 55 615 455;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 214 132 21 9109513 4:1;
#P message 190 132 21 9109513 3:1;
#P newex 190 157 62 9109513 prepend ratio; #P number 190 203 35 9 0 0 0 139
0 0 0 221 221 221 222 222 222 0 0 0; #P newex 190 180 41 9109513 js ratios;
#P connect 3 0 2 0; #P connect 4 0 2 0; #P connect 2 0 0 0; #P connect 0 0 1
0; #P pop;
Hope that's of use,
Simon
-----Original Message-----
From: javascript-dev-bounces at cycling74.com
[mailto:javascript-dev-bounces at cycling74.com] On Behalf Of Salvator
Sent: 03 October 2007 15:10
To: javascript-dev at cycling74.com
Subject: [javascript-dev] JSUI : question about Array index/value
Hi,
I'm working on a JSUI knob meant for a compressor knee.
SO I've setted an Array with my knee settings :
var Ratio = ["1:1", "2:1", "3:1","4:1", "6:1", "10:1", "];
My goal is to be able to control this jsui knob by sending message of the
knee settings (ex:10:1), rather than float or int (i.e. NOT by sending the
array index).
Thus my question :
Is it possible to send a "value" to an Array, so it check if it match the
content, and if positive retrieve the array index for that "value" ?
ie. for
var Ratio = ["1:1", "2:1", "3:1","4:1", "6:1", "10:1"];
// index's are 0 1 2 3 4 5
I send the message "3:1" and I get back the index of this value wich is
"2".
I've tried with vregexp.exec(Ratio) etc... but I lack skill in java and I
have no good results.
So far, I'm doing like this :
function ratio(input)
{
switch (input)
{ case "1:1": msg_float(0) ;break;
case "2:1": msg_float(1) ;break;
case "3:1": msg_float(2) ;break;
case "4:1": msg_float(3) ;break;
case "6:1": msg_float(4) ;break;
case "10:1": msg_float(5) ;break;
case "20:1": msg_float(6) ;break;
case "NUKE": msg_float(7) ;break;
}
}
This works, but I want to use this code on much bigger arrays(like for a
fixed frequency knob with dozen of frequency), and it'll be hard to manage
all those cases lines. Especially if I make change in the array order and
number etc...
Second question :
Actually I have to pass a message with a prefix "ratio 3:1" , to enter the
function ratio(input).
Is there anyway to make it work just by sending a single symbol "3:1" ? Is
is possible at all to send single symbol message to jsui ?
Thanks for any help or advice !
Salvator
_______________________________________________
javascript-dev mailing list
javascript-dev at cycling74.com
http://www.cycling74.com/mailman/listinfo/javascript-dev
- Previous message: [javascript-dev] JSUI : question about Array index/value
- Next message: [javascript-dev] Re: RE: JSUI : question about Array index/value
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
