[PD-dev] parsing pd patch files (in php)
Andre Schmidt
andre at osku.de
Wed Dec 7 20:58:38 CET 2005
hi,
im now trying two days to find a way how to parse pd patch files, today
i found about "recursive functions" and think that would be the
solution...
but as im not a good coder i cant really modify the "recursive directory
listing" code examples that i found through google....
http://www.zend.com/zend/art/recursion.php
$delim = strstr(PHP_OS, "WIN") ? "\\" : "/";
function retrieveTree($path) {
global $delim;
if ($dir=@opendir($path)) {
while (($element=readdir($dir))!== false) {
if(is_dir($path.$delim.$element) && $element!= "." && $element!=
"..") {
$array[$element] = retrieveTree($path.$delim.$element);
}elseif ($element!= "." && $element!= "..") {
$array[] = $element;
}
}
closedir($dir);
}
return (isset($array) ? $array : false);
}
but i think i found out how the array should look like:
this is the pd patch file: (line numbers are used for better
visualisation)
01#N canvas 667 88 332 225 10;
02#X text 21 13 cid0;
03#N canvas 408 254 450 300 cid1 0;
04#N canvas 0 0 450 300 cid1 0;
05#X text 9 6 cid0;
06#X restore 18 30 pd cid1;
07#X text 17 8 cid0;
08#X restore 22 31 pd cid1;
09#N canvas 473 157 450 300 cid2 0;
10#X text 16 16 cid0;
11#X restore 116 31 pd cid2;
12#N canvas 0 0 450 300 cid3 0;
13#X text 14 11 cid0;
14#X restore 203 30 pd cid3;
and this would be the array:
Array(
[canvas0] => Array(
[0] => 01#N canvas 667 88 332 225 10;
[1] => 02#X text 21 13 cid0;
[canvas1] => Array(
[0] => 03#N canvas 408 254 450 300 cid1 0;
[canvas2] => Array(
[0] => 04#N canvas 0 0 450 300 cid1 0;
[1] => 05#X text 9 6 cid0;
)
[1] => 06#X restore 18 30 pd cid1;
[2] => 07#X text 17 8 cid0;
)
[2] => 08#X restore 22 31 pd cid1;
[canvas3] => Array(
[0] => 09#N canvas 473 157 450 300 cid2 0;
[1] => 10#X text 16 16 cid0;
)
[3] => 11#X restore 116 31 pd cid2;
[canvas4] => Array(
[0] => 12#N canvas 0 0 450 300 cid3 0;
[1] => 13#X text 14 11 cid0;
)
[4] => 14#X restore 203 30 pd cid3;
)
)
well, im not sure if that array is correct. i did it manually :)
and i havent even tested if i can then use that array the way i like,
but as im stuck on this parsing problem i desided not to test further
until i get this to work....
and maybe my array "design" is not so good anyway...
so, i wanted to ask you what would be the best way to parse pd files ?
im pretty sure i can do all other things (object drawing, connections)
alone, just this parsing thing gives me headache...
cheers
andre
ps. why i do this ? i wanted to display pd patches using "canvas" in
firefox 1.5...
More information about the Pd-dev
mailing list