Jit_matrix method in max object ?

Apr 10, 2013 at 7:00am

Jit_matrix method in max object ?

Hi,

Is is safe to access a jit.matrix from a classic object (like in the code bellow) ?

Or is there under the hood mechanisms that force me to implement jit methods (jit_object_new, max_jit_classex_standard_wrap…) to create the object ?

int main(void)
{
    t_class *c = NULL;

    c = class_new("flopMatrix", flop_new, NULL, sizeof(t_flop), NULL, A_GIMME, 0);
    class_addmethod(c, (method)flop_jit_matrix, "jit_matrix", A_GIMME, 0);
    class_register(CLASS_BOX, c);
    flop_class = c;

    return 0;
}

void flop_jit_matrix(t_flop *x, t_symbol *s, long argc, t_atom *argv)
{
    void *matrix = NULL;

    if (argc && argv && (matrix = jit_object_findregistered(jit_atom_getsym(argv)))) {
    //
    if (jit_object_method(matrix, _jit_sym_class_jit_matrix)) {
    //
    long dimcount, savelock;
    t_jit_matrix_info info;

    savelock = (long)jit_object_method(matrix, _jit_sym_lock, 1);
    jit_object_method(matrix, _jit_sym_getinfo, &info);
    dimcount = info.dimcount;
    jit_object_method(matrix, _jit_sym_lock, savelock);

    post("Dimcount %s: %ld", jit_atom_getsym(argv)->s_name, dimcount);
    //
    }
    //
    }
}
#67636
Apr 10, 2013 at 9:45am

It should be perfectly safe.
All you need is the following:

addmess((method)flop_jit_matrix, "jit_matrix", A_GIMME, 0);

and implement the method, just as you have already done…

However, I would do some extra error checking, for example:

(non-tested code so use with caution)

if (argc && argv) {

        // find matrix
	matrix = jit_object_findregistered(jit_atom_getsym(argv));

	if (matrix && jit_object_method(matrix, _jit_sym_class_jit_matrix)) {

                long dimcount, savelock;
                t_jit_matrix_info info;
                char *bp;

		savelock = (long) jit_object_method(matrix, _jit_sym_lock, 1);

		jit_object_method(matrix, _jit_sym_getinfo, &info);
		jit_object_method(matrix, _jit_sym_getdata, &bp);

		if (!bp) {
			jit_error_sym(x, _jit_sym_err_calculate);
			jit_object_method(matrix, _jit_sym_lock, savelock);
			return;
		}
		dimcount = info.dimcount;

		if (info.type == _jit_sym_char) {
			// handle char
		} else if (info.type == _jit_sym_long) {
			// handle long
		} else if (info.type == _jit_sym_float32) {
			// handle float32
		} else if (info.type == _jit_sym_float64) {
			// handle float64
		}
		jit_object_method(matrix, _jit_sym_lock, savelock);
	}
}

Hope this helps.

- Luigi

#243386
Apr 10, 2013 at 10:46am

Hi,

Yep, i will implement the “jit_object_method(matrix, _jit_sym_getdata, &bp);” function.

But that’s just to make an example for my github repository for newbies ;-)

Thanks.

Ciao.

#243387

You must be logged in to reply to this topic.