how can i import an array instead of lists?

Apr 9, 2013 at 1:09pm

how can i import an array instead of lists?

Hello everyone :)

After a lot of searching, i achieved to pass an amount of lists and put them to an array in programm.
Now i would like to know how to pass an array directly,without passing the lists of atoms..
Any idea?

#include “ext.h”
#include “ext_obex.h”

typedef struct _fingertips {
t_object p_ob;
Atom f_value;
void *f_outlet;
} t_fingertips;

short image[1000][1000];
short perimeter[1000];
long points[5][2];
long imageWidth;
long imageHeight;

void fingertips_bang(t_fingertips *x);
void fingertips_list(t_fingertips *x, t_symbol *s, short argc, t_atom*argv);
void fingertips_perimeter(t_fingertips *x);
void fingertips_points(t_fingertips *x);
void fingertips_clear(t_fingertips *x);
void *fingertips_new();

t_class *fingertips_class;

int main(void) {
t_class *c;

c = class_new(“fingertips”, (method) fingertips_new, (method) NULL,
sizeof(t_fingertips), 0L, A_GIMME, 0);

class_addmethod(c, (method) fingertips_bang, “bang”, 0);
class_addmethod(c, (method) fingertips_list, “list”, A_GIMME, 0);
class_addmethod(c, (method) fingertips_clear, “clear”, 0);

class_register(CLASS_BOX, c);
fingertips_class = c;

post(“fingertips object loaded…”, 0);
return 0;
}

void *fingertips_new() {

long i, j;
t_fingertips *x;

x = (t_fingertips *) object_alloc(fingertips_class);
x->f_outlet = intout(x);

for (i = 0; i < 1000; i++) {
perimeter[i] = 0;
for (j = 0; j < 1000; j++) {
if (i == 0)
image[i][j] = 1;
else
image[i][j] = 0;

}
}
for (i = 0; i < 5; i++) {
points[i][0] = 0;
points[i][1] = 0;
}
imageHeight = 0;
imageWidth = 0;

post(” new fingertips object instance added to patch…”, 0);
return (x);
}

void fingertips_bang(t_fingertips *x) {

Atom argv[15];

atom_setlong(argv, points[0][0]);
atom_setsym(argv + 1, gensym(“,”));
atom_setlong(argv + 2, points[0][1]);
atom_setlong(argv + 3, points[1][0]);
atom_setsym(argv + 4, gensym(“,”));
atom_setlong(argv + 5, points[1][1]);
atom_setlong(argv + 6, points[2][0]);
atom_setsym(argv + 7, gensym(“,”));
atom_setlong(argv + 8, points[2][1]);
atom_setlong(argv + 9, points[3][0]);
atom_setsym(argv + 10, gensym(“,”));
atom_setlong(argv + 11, points[3][1]);
atom_setlong(argv + 12, points[4][0]);
atom_setsym(argv + 13, gensym(“,”));
atom_setlong(argv + 14, points[4][1]);

outlet_anything(x->f_outlet, gensym(“list”), 15, argv);
}

void fingertips_list(t_fingertips *x, t_symbol *s, short ac, t_atom*av) {

if (s->s_name == “clear”) {
fingertips_bang(x);
} else {
if (ac == 3) {
image[av[1].a_w.w_long][av[0].a_w.w_long] = av[2].a_w.w_long;
if (imageWidth < av[0].a_w.w_long + 1)
imageWidth = av[0].a_w.w_long + 1;
if (imageHeight < av[1].a_w.w_long + 1)
imageHeight = av[1].a_w.w_long + 1;
}
fingertips_perimeter(x);
}
}

void fingertips_clear(t_fingertips *x) {

fingertips_bang(fingertips_new());
}

void fingertips_perimeter(t_fingertips *x) {

long i, j;

for (i = 0; i < imageWidth; i++) {
for (j = 0; j < imageHeight; j++) {
if (image[j][i] != 0)
perimeter[i] = j;
}
}
fingertips_points(x);
}

void fingertips_points(t_fingertips *x) {

long i, j = -1, stop = 0, sum = 1, tempSum = 0;

for (i = 1; i < imageWidth; i++) {
if (perimeter[i] < perimeter[i - 1] && stop == 0) {
j++;
points[j][0] = i – 1;
points[j][1] = perimeter[i - 1];
stop = -1;
if (sum % 2 != 0)
tempSum = (sum + 1) / 2;
else
tempSum = sum / 2;
points[j][0] = (i – 1) – tempSum;
points[j][1] = perimeter[i - 1];
sum = 0;
tempSum = 0;
} else if (perimeter[i] > perimeter[i - 1] && stop == -1) {
stop = 0;
}
if (perimeter[i] == perimeter[i - 1]) {
sum++;
} else {
sum = 0;
}
fingertips_bang(x);
}
}

#67611

You must be logged in to reply to this topic.