Question about calling same functions from several threads in an object


#1

Hey

First I am going to apologize for not uising the right language. Still learning here, and the technial terms is for me one of the harder areas to get right... I know what I am aiming for, but cant always get the lingo right. Anyway, to the subjects:

I am curious about it I want to use for example 2 tables inside one object.

For example the table/read interp. If I want to use 2 of them in an object, would I have to delare the functions used a second time?

The init code of the table/play is:
// Table/Play //
pos = 0;
pstart = 0;
pstop = 1;

And the k-rate code is:
// Table/Play //
if ((inlet_start+Loopval_a>0) && !pstart) {
pstart = 1;
pstop = 0;
uint32_t asat = _USAT(inletpos+param_position,27);
pos = ((uint64_t)(asat>>(27-attr_t.LENGTHPOW)))<<32;
} else if (!(inlet_start+Loopval_a>0)) {
pstart = 0;
}
if ((inlet_stop>0) && !pstop) {
pstop = 1;
pstart = 0;
}
uint32_t f0;
MTOFEXTENDED(inlet_pitch + 0xFEC747D4 - param_pitch,f0);

Would I have to declare those functions, the ...
pos = 0;
pstart = 0;
pstop = 1;

a second time for the second table? And rename the new ones so I have both....
pos = 0;
pstart = 0;
pstop = 1;

pos2 = 0;
pstart2 = 0;
pstop2 = 1;

Thanks, Jaffa


#2

There are probably several ways of doing it, you will only need to declare the variables once, but you may need to reset the values as you show above

pos = 0;
pstart = 0;
pstop = 1;

pos2 = 0;
pstart2 = 0;
pstop2 = 1;

more than once depending on your desired outcome.

If these are the default values, for example if needing to apply one or more conditional statements based on these values, then probably yes you will need to reset them.

The 2 sets of variables is also a good idea helps you track which table you are referring too.

A personal recommendation (your choice), if you are using 2 on the end of your second set of variables, I would use a 1 on the end of your first set of variables too. Its good to develop a pattern that you can always follow and rely on when coding for naming variables etc.. For me it hasn't always work out that way, but have to start somewhere.. ! :grin:


#3

Thanks @Gavin

I got it working just before I went to bed :slight_smile:

Ah yes I should put a 1 in the end of the first ones too :slight_smile: But in general I write wha everything does down inside the object. After all still learning, so to make it easier to understand I need the notes.


#4

I am not sure if you know, but you can make any comments in the code by starting the line with the double forward slash "//" the comments will be saved in the code, but do not get compiled, its an easy way to keep track of the steps in your code. You can also add the two slashes at the beginning of your code line if you want them ignored while testing or something. :grin:


#5

Yes I use the // all the time. Very good when learning and when making more complicated stuff :slight_smile: