I tried creating a second struct with a member from a first struct,
seems it need a constructor?
r2_sound works, but r2_word doesn't.
I want to return a r2_word struct from r2_wordGen function. How to initialize r2_word?
r2d2.h
struct r2sound {
int f0;
int f1;
float freqInc;
int d0;
int d1;
float durInc;
int soundlength;
};
struct r2word {
r2sound soundA;
int soundRepet;
int repdelay;
int order[6] = {0};
//r2word(r2sound soundA, int repdelay, int order[6]) : soundA(soundA), repdelay(repdelay), order(order) {};
};
r2sound r2_soundGen(int flow, int fmaxi, int srIN0, int srIn1, int dmin, int dmax, int drIN0, int drIn1);
r2word r2_wordGen(r2sound sound0, int replow, int rephi, int rdellow, int rdelhi);
r2d2.ino
r2sound r2_soundGen(int flow, int fmaxi, int srIN0, int srIn1, int dmin, int dmax, int drIN0, int drIn1) {
// word gen
int f0 = TrueRandom.random(flow, fmaxi);
int f1 = TrueRandom.random(flow, fmaxi);
float freqInc = 1.0 + (abs(f0 -f1) / srIN0) + ((float)TrueRandom.random(srIn1, 100) / 100);
int d0 = TrueRandom.random(dmin, dmax);
int d1 = TrueRandom.random(dmin, dmax);
float durInc = 1.0 + (abs(d0 -d1) / drIN0) + ((float)TrueRandom.random(drIn1, 100) / 100);
int soundlength = r2_sound(f0, f1, freqInc, d0, d1, durInc, 1);
r2sound R2S = {f0, f1, freqInc, d0, d1, durInc, soundlength}; // THIS WORKS !!!
return R2S;
}
r2word r2_wordGen(r2sound sound0, int replow, int rephi, int rdellow, int rdelhi) {
int soundRepet = TrueRandom.random(replow, rephi);
int repdelay = TrueRandom.random(rdellow, rdelhi);
int order[6] = {0, 0, 0, 0, 0, 0};
for(int i=0; i<6; i++){
if (i < soundRepet) order[i] = random(1, 5);
else order[i] = 0;
}
r2word R2W = {sound0, soundRepet, repdelay, order}; // HERE IS THE ERROR !!!
return R2W;
}
Error:
r2d2.ino: In function 'r2word r2_wordGen(r2sound, int, int, int, int)':
r2d2.ino:53:52: error: in C++98 'R2W' must be initialized by constructor, not by '{...}'
r2d2.ino:53:52: error: could not convert '{sound0, soundRepet, repdelay, order}' from '<brace-enclosed initializer list>' to 'r2word'
Error compiling.