Hi, I'm working on a new object that is kinda like [value], but much simplified and you can set multiple variable names and output them all as a list (only floats now). It's been fun and it was working, compiling with some weird bugs. I then started revising it and when I thought I could be fixing the last bug, code does not compile now.
What I'm doing is storing multiple variable values and variable names, just like I'm doing with some float values for my new multichannel aware audio objects (one value per channel).
So I have.
*typedef* *struct* _var{
t_object x_obj;
t_int x_n; // number of given vars as arguments
t_symbol **x_sym; // variable name
*float* *x_fval; // var value
}t_var;
Now, when initializing the variable, in "new", I am trying to get the value of an existing variable name (which is created if it doesn't exist yet). This is done in the same as in [value] by the way
In [value] you have x->x_floatstar = value_get(s);
I got x->x_fval[i] = var_get(x->x_sym[i] = atom_getsymbol(av+i));
But this gives me the error
*
*var.c:80:22: **error: **assigning to 'float' from incompatible type 't_float *'*
* (aka 'float *'); dereference with **
x->x_fval[i] = var_get(x->x_sym[i] = atom_getsymbol(av+i));
* ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
Funny enough, I had an older version that would compile and work very well despite some crashes, that initialized x_fval as
*float* **x_fval; // var value
Instead of just "*x_fval", which doesn't seem right.
Please help, and also, at this time, I could take suggestions of some nice and free online C course that would make me intelligent to the point I would have a minimum idea of what I am doing.
thanks
here's the full code by the way https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/v...
And here's an older version that was compiling and running https://github.com/porres/pd-else/blob/cd1406cff28baf1eb056d1500fb0d62694171...
cheers
Em seg., 9 de out. de 2023 às 13:22, Alexandre Torres Porres < porres@gmail.com> escreveu:
Hi, I'm working on a new object that is kinda like [value], but much simplified and you can set multiple variable names and output them all as a list (only floats now). It's been fun and it was working, compiling with some weird bugs. I then started revising it and when I thought I could be fixing the last bug, code does not compile now.
What I'm doing is storing multiple variable values and variable names, just like I'm doing with some float values for my new multichannel aware audio objects (one value per channel).
So I have.
*typedef* *struct* _var{
t_object x_obj; t_int x_n; // number of given vars as arguments t_symbol **x_sym; // variable name *float* *x_fval; // var value
}t_var;
Now, when initializing the variable, in "new", I am trying to get the value of an existing variable name (which is created if it doesn't exist yet). This is done in the same as in [value] by the way
In [value] you have x->x_floatstar = value_get(s);
I got x->x_fval[i] = var_get(x->x_sym[i] = atom_getsymbol(av+i));
But this gives me the error
*
*var.c:80:22: **error: **assigning to 'float' from incompatible type 't_float *'*
(aka 'float *'); dereference with ** x->x_fval[i] = var_get(x->x_sym[i] = atom_getsymbol(av+i));
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
Funny enough, I had an older version that would compile and work very well despite some crashes, that initialized x_fval as
*float* **x_fval; // var value
Instead of just "*x_fval", which doesn't seem right.
Please help, and also, at this time, I could take suggestions of some nice and free online C course that would make me intelligent to the point I would have a minimum idea of what I am doing.
thanks
Am 9. Oktober 2023 18:22:11 MESZ schrieb Alexandre Torres Porres porres@gmail.com:
*var.c:80:22: **error: **assigning to 'float' from incompatible type 't_float *'*
Well it's just what it says: you are trying to assign a `t_float*` value to a `t_float`. A `t_float` is some floating type, and it is not allowed to use it to store a pointer.
What's the question?
mfg.sfg.jfd IOhannes
Em seg., 9 de out. de 2023 às 16:37, IOhannes m zmölnig zmoelnig@iem.at escreveu:
Am 9. Oktober 2023 18:22:11 MESZ schrieb Alexandre Torres Porres < porres@gmail.com>:
*var.c:80:22: **error: **assigning to 'float' from incompatible type 't_float *'*
Well it's just what it says: you are trying to assign a `t_float*` value to a `t_float`. A `t_float` is some floating type, and it is not allowed to use it to store a pointer.
Ok, your comment already did shed some light. And looking closely, the [value] code actually uses *x_floatstar ... so let me get this straight, that makes it a pointer then, so it works. Now, I'm also using the same thing to create an array of values, that can be set with something like x->x_fval[i]. This is where things get confusing to me. Now, in an earlier version, this was working and initialized as **x_fval which then it seems it is a pointer to the array of values?
In the end, the question would be how to initialize a variable that can take the pointer correctly. Was the last compilable code from https://github.com/porres/pd-else/blob/cd1406cff28baf1eb056d1500fb0d62694171... completely correct? I guess I got lucky then and when tried to fix what wasn't broken I just ruined it. And the bugs I was trying to fix were unrelated.
Another good question would be simple online courses that could help me understand things a little better :)
thanks
What's the question?
mfg.sfg.jfd IOhannes
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
Ok, updated the code as before, so it compiles https://github.com/porres/pd-else/commit/4f052fbe4af3889f06eb69c236f04eeae35...
now I initialize as **x_fval in https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/v...
At bangs, I get and set the value of the output atom list as *SETFLOAT(at+i, ***x->x_fval[i]);* https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/v...
In the list method, I get atoms' values with **x->x_fval[i] = atom_getfloat(av+i); * https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/v...
What's weird to me is now that in the 'new' method, I initialize the variable as
*x->x_fval[i] = var_get(x->x_sym[i] = atom_getsymbol(av+i)); * https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/v...
and it works, and no need of '*' in here.. I would expect it though... not sure why, just feels right :)
But i am just making sure now that all is ok and that my bugs are elsewhere. Also note I am initializing the data as x->x_fval = getbytes(sizeof(float) * x->x_n); in https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/v... and I free it as freebytes(x->x_fval, x->x_n * sizeof(*x->x_fval)); in https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/v...
thanks
Em seg., 9 de out. de 2023 às 18:28, Alexandre Torres Porres < porres@gmail.com> escreveu:
Em seg., 9 de out. de 2023 às 16:37, IOhannes m zmölnig zmoelnig@iem.at escreveu:
Am 9. Oktober 2023 18:22:11 MESZ schrieb Alexandre Torres Porres < porres@gmail.com>:
*var.c:80:22: **error: **assigning to 'float' from incompatible type 't_float *'*
Well it's just what it says: you are trying to assign a `t_float*` value to a `t_float`. A `t_float` is some floating type, and it is not allowed to use it to store a pointer.
Ok, your comment already did shed some light. And looking closely, the [value] code actually uses *x_floatstar ... so let me get this straight, that makes it a pointer then, so it works. Now, I'm also using the same thing to create an array of values, that can be set with something like x->x_fval[i]. This is where things get confusing to me. Now, in an earlier version, this was working and initialized as **x_fval which then it seems it is a pointer to the array of values?
In the end, the question would be how to initialize a variable that can take the pointer correctly. Was the last compilable code from https://github.com/porres/pd-else/blob/cd1406cff28baf1eb056d1500fb0d62694171... completely correct? I guess I got lucky then and when tried to fix what wasn't broken I just ruined it. And the bugs I was trying to fix were unrelated.
Another good question would be simple online courses that could help me understand things a little better :)
thanks
What's the question?
mfg.sfg.jfd IOhannes
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
Now, if I tried fixed what wasn't broken, then I still don't know what's broken and let me tell what was originally not working.
The object was behaving perfectly well with two named variables, but when I tried 3, I am getting an error when trying to free the first variable name.
This is all the same as in [value], I just have a loop to create many variables according to the arguments, which are created in "var_get". When it is freed, the problem I have is that it doesn't find the first created variable with "pd_findbyclass", as if it wasn't created, but printing and debugging, it does say and show it was in fact created...
So maybe forget about all from before as I thought I saw something weird that could fix and looks like it's unrelated.
Em seg., 9 de out. de 2023 às 18:42, Alexandre Torres Porres < porres@gmail.com> escreveu:
Ok, updated the code as before, so it compiles https://github.com/porres/pd-else/commit/4f052fbe4af3889f06eb69c236f04eeae35...
now I initialize as **x_fval in https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/v...
At bangs, I get and set the value of the output atom list as *SETFLOAT(at+i, ***x->x_fval[i]);* https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/v...
In the list method, I get atoms' values with **x->x_fval[i] = atom_getfloat(av+i); * https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/v...
What's weird to me is now that in the 'new' method, I initialize the variable as
*x->x_fval[i] = var_get(x->x_sym[i] = atom_getsymbol(av+i)); * https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/v...
and it works, and no need of '*' in here.. I would expect it though... not sure why, just feels right :)
But i am just making sure now that all is ok and that my bugs are elsewhere. Also note I am initializing the data as x->x_fval = getbytes(sizeof(float) * x->x_n); in https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/v... and I free it as freebytes(x->x_fval, x->x_n * sizeof(*x->x_fval)); in https://github.com/porres/pd-else/blob/master/Code_source/Compiled/control/v...
thanks
Em seg., 9 de out. de 2023 às 18:28, Alexandre Torres Porres < porres@gmail.com> escreveu:
Em seg., 9 de out. de 2023 às 16:37, IOhannes m zmölnig zmoelnig@iem.at escreveu:
Am 9. Oktober 2023 18:22:11 MESZ schrieb Alexandre Torres Porres < porres@gmail.com>:
*var.c:80:22: **error: **assigning to 'float' from incompatible type 't_float *'*
Well it's just what it says: you are trying to assign a `t_float*` value to a `t_float`. A `t_float` is some floating type, and it is not allowed to use it to store a pointer.
Ok, your comment already did shed some light. And looking closely, the [value] code actually uses *x_floatstar ... so let me get this straight, that makes it a pointer then, so it works. Now, I'm also using the same thing to create an array of values, that can be set with something like x->x_fval[i]. This is where things get confusing to me. Now, in an earlier version, this was working and initialized as **x_fval which then it seems it is a pointer to the array of values?
In the end, the question would be how to initialize a variable that can take the pointer correctly. Was the last compilable code from https://github.com/porres/pd-else/blob/cd1406cff28baf1eb056d1500fb0d62694171... completely correct? I guess I got lucky then and when tried to fix what wasn't broken I just ruined it. And the bugs I was trying to fix were unrelated.
Another good question would be simple online courses that could help me understand things a little better :)
thanks
What's the question?
mfg.sfg.jfd IOhannes
Pd-dev mailing list Pd-dev@lists.iem.at https://lists.puredata.info/listinfo/pd-dev
Em seg., 9 de out. de 2023 às 20:27, Alexandre Torres Porres < porres@gmail.com> escreveu:
but printing and debugging, it does say and show it was in fact created...
here's to illustrate, I load the patch with a single [var a b c] object, and I'm printing at creation time that it's creating 'a', 'b' and 'c' which didn't exist before. If I duplicate the object, it says it's creating 'a' again as if it didn't already exist.. copy again and you get yet the same thing. Now if I delete the first object it shows that error where it couldn't find the variable to free it, as it really never existed. If I do "control z" and recreated the object, it recreates yet once again variable 'a'...
[image: Screen Shot 2023-10-09 at 21.07.39.png]
I don't know how to test any further and it really seems there's NOTHING wrong with it with the code :)
thanks
Ok, I solved it by just using the value functions that, as it turns out, are available in m_pd.h :)
it all works, but I wanted to expand the object and also make it take symbols, which won't be possible now, but it will be if [value] is expanded to take symbols as well, and there's a PR for it, so I can then annoyingly insist on it instead.
This works better as the external now is perfectly integrated with [value] and can also take values that are set in [expr] for instance.
here's the code, pretty much simpler now as well. Thanks!
// porres 2023
#include "m_pd.h"
*static* t_class *var_class;
*typedef* *struct* _var{
t_object x_obj;
t_int x_n; // number of given vars as arguments
t_symbol **x_sym; // variable names
}t_var;
*static* *void* var_bang(t_var *x){
t_atom at[x->x_n];
*for*(*int* i = 0; i < x->x_n; i++){
t_float f;
*int* flag = value_getfloat(x->x_sym[i], &f);
SETFLOAT(at+i, !flag ? f : 0);
}
outlet_list(x->x_obj.ob_outlet, &s_list, x->x_n, at);
}
*static* *void* var_list(t_var *x, t_symbol *s, *int* ac, t_atom *av){
s = *NULL*;
*if*(!ac)
var_bang(x);
*else* *for*(*int* i = 0; i < (ac > x->x_n ? x->x_n : ac); i++)
value_setfloat(x->x_sym[i], atom_getfloat(av+i));
}
*static* *void* var_free(t_var *x){
*for*(*int* i = 0; i < x->x_n; i++)
value_release(x->x_sym[i]);
freebytes(x->x_sym, x->x_n * *sizeof*(*x->x_sym));
}
*static* *void* *var_new(t_symbol *s, *int* ac, t_atom *av){
s = *NULL*;
t_var *x = (t_var *)pd_new(var_class);
x->x_sym = getbytes(*sizeof*(t_symbol) * (x->x_n = (!ac ? 1 : ac)));
*if*(!ac)
value_get(x->x_sym[0] = &s_);
*else* *for*(*int* i = 0; i < x->x_n; i++)
value_get(x->x_sym[i] = atom_getsymbol(av+i));
outlet_new(&x->x_obj, &s_list);
*return*(x);
}
*void* var_setup(*void*){
var_class = class_new(gensym("var"), (t_newmethod)var_new,
(t_method)var_free, *sizeof*(t_var), 0, A_GIMME, 0);
class_addbang(var_class, var_bang);
class_addlist(var_class, var_list);
}
Em seg., 9 de out. de 2023 às 21:11, Alexandre Torres Porres < porres@gmail.com> escreveu:
Em seg., 9 de out. de 2023 às 20:27, Alexandre Torres Porres < porres@gmail.com> escreveu:
but printing and debugging, it does say and show it was in fact created...
here's to illustrate, I load the patch with a single [var a b c] object, and I'm printing at creation time that it's creating 'a', 'b' and 'c' which didn't exist before. If I duplicate the object, it says it's creating 'a' again as if it didn't already exist.. copy again and you get yet the same thing. Now if I delete the first object it shows that error where it couldn't find the variable to free it, as it really never existed. If I do "control z" and recreated the object, it recreates yet once again variable 'a'...
[image: Screen Shot 2023-10-09 at 21.07.39.png]
I don't know how to test any further and it really seems there's NOTHING wrong with it with the code :)
thanks