[javascript-dev] Tasks and String manipulations
Garth Paine
ga.paine at uws.edu.au
Fri Mar 14 04:24:37 MDT 2008
- Previous message: [javascript-dev] setInterval
- Next message: [javascript-dev] Tasks and String manipulations
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Thanks to everyone for assistance with Tasks - got them going
I am reading out of a text file recorded using the Max Text object so it
looks like
0, 110 9 220 218;
1, 110 9 218 218;
2, 110 9 218 218;
3, 110 9 218 218;
4, 110 9 218 218;
5, 110 14 218 218;
6, 110 9 218 216;
7, 110 9 218 220;
8, 110 4 220 220;
9, 110 4 220 220;
10, 110 4 220 220;
I want to isolate each incoming integer and send it out a different output
I looked at using regular expressions
re = /\(?\d{4}\)?([,])\d{2}\1\d{2}\1\d{2}\1\d{2}/;
But I do not really understand them and the size of the integers could be
from 0-20000, and I did not know how to provide for that in RE's
The code for the entire script looks like the following - I am sure some of
you experienced coders will be able to suggest a much better way of dealing
with breaking up the line and directing the data to the outputs than the one
I have cooked up
/*
*Reading through BioData Text File
*
* by garth paine March 2008
* http://www.activatedspace.com and http://www.syncsonics.com
*/
// global code
inlets = 1;
outlets = 5;
autowatch = 1;
var f = new File();
t = new Task();
fileName = "" ;
newstr = "";
re = /\(?\d{4}\)?([,])\d{2}\1\d{2}\1\d{2}\1\d{2}/;
function bang()
{
if (jsarguments.length > 0){
post("------------------------------------------------------- \n");
fileName = jsarguments[3];
post("Reding from file: "+ fileName + "\n");
f = new File(fileName);
f.open ();
if (f.isopen){
newstr = "start";
f.position = 0;
t = new Task(readFIle, this);
t.interval = jsarguments[4]; // time interval set as argument in
object
t.repeat(); // repeat
}
}}
function stopTask(){
t.cancel();
}
function readFIle(){
post("---------------- -------------\n" );
newstr = f.readline();
if (newstr !=null){
newstr = newstr.split(" ", 5);
//post("newstr " + newstr + "\n");
//newstr = newstr.split(" ", 5);
if (newstr != null){
for(i=0; i<5;i++)
{
outlet(i, parseInt(newstr[i]));
}
//newstr = re.exec(aString); possible approach using
expressions
}
}
else("the file " + fileName +" is not open.");
}
function list() //just incase a list is sent in
{
var aList = arrayfromargs(arguments);
post("------ you sent me a list ---------" + "\n" +aList +"\n");
}
//The End :-)
---
Kind Regards
Dr Garth Paine
I implement the 5 sentences policy http://five.sentenc.es/
http://www.activatedspace.com
http://www.syncsonics.com
http://www.meterosonics.com
http://marcs.uws.edu.au/people/paine/
Senior Lecturer in Music Technology
School of Communication Arts
University of Western Sydney,
BD 1.14 Werrington South, Locked Bag 1797
Penrith South DC, NSW, 1797, Australia
http://marcs.uws.edu.au/people/paine/index.htm
Member of MARCS Auditory Laboratories
Coordinator VIPRE Research Lab
University of Western Sydney
Bankstown Campus
Webpage: <http://marcs.uws.edu.au/people/paine/>
MARCS Ph. +61 (0)2 9772 6902 FAX +61 (0)2 9772 6040
***************************************************************
Please do not forward this message to any other person or entity not named
in the recipient fields above without the express consent of the sender. If
you are not the intended recipient of this message as set out in the address
field above, please contact the School of Communication Arts on +61 2 9852
5476 to advise. Please remove the message from your system and do not
forward the message to any other person or entity. The views expressed
herein are not necessarily those of the University of Western Sydney.
***************************************************************
- Previous message: [javascript-dev] setInterval
- Next message: [javascript-dev] Tasks and String manipulations
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
