Forum Rule: Always post complete source code & details to reproduce any issue!

1. ## Envelope Array Problems

Hi everyone. I am having some issues with an array of envelopes, I'd like to slim down my code with a for loop or two, but I am getting errors.

Code:
```//first I made the array

char envelopes[16] = {'envelope1', 'envelope2', 'envelope3', 'envelope4', 'envelope5', 'envelope6', 'envelope7', 'envelope8', 'envelope9', 'envelope10', 'envelope11', 'envelope12', 'envelope13', 'envelope14', 'envelope15', 'envelope16'};

//Then the for loop that throws the error: request for member 'attack' in 'envelopes[i]', which is of non-class type 'char'

for(int i=16; i<17; i++){
envelopes[i].attack(attack);
envelopes[i].decay(decay);
envelopes[i].sustain(sustain);
envelopes[i].release(release);
}```
In my research it seems I may need to be using pointers, but I'm a tad confused on how to implement that. Any help would be hugely appreciated. I'll post my synth full source below. Sorry its a mess I am a super newbie. If you need to see the Audio tool code in syntharch.h let me know.

Code:
```#include <Arduino.h>
#include <Bounce.h>
#include "SYNTHARCH.H"

// Formulas to remember
// largest output you want * (value you get in / max input value)
// EXAMPLE - potentiometer from 0 to 30000: finalVariable = 30000 * (inputVariable / 1023)

Bounce button0 = Bounce(25, 15);
Bounce button1 = Bounce(26, 15);
Bounce button2 = Bounce(27, 15);
Bounce button3 = Bounce(28, 15);
Bounce button4 = Bounce(29, 15);
Bounce button5 = Bounce(30, 15);
Bounce button6 = Bounce(31, 15);
Bounce button7 = Bounce(32, 15);

float noteFrequencies[8][8] = {
//Amin
{220.00, 246.94, 261.63, 293.66, 329.63, 349.23, 392.00, 440.00},
//Bmin
{246.94, 277.18, 293.66, 329.63, 369.99, 392.00, 440.00, 493.88},
//Cmin
{261.63, 293.66, 311.13, 349.23, 392.00, 415.30, 466.16, 523.25},
//Dmin
{293.66, 329.63, 349.23, 392.00, 440.00, 466.16, 523.25, 587.33},
//Emin
{329.63, 369.99, 392.00, 440.00, 493.88, 523.25, 587.33, 659.25},
//Fmin
{349.23, 392.00, 415.30, 466.16, 523.25, 554.37, 622.25, 698.46},
//Gmin
{392.00, 440.00, 466.16, 523.25, 587.33, 622.25, 698.46, 783.99},
//Chrom
{220.00, 233.08, 246.94, 261.63, 277.18, 293.66, 311.13, 329.63},
};

char envelopes[16] = {'envelope1', 'envelope2', 'envelope3', 'envelope4', 'envelope5', 'envelope6', 'envelope7', 'envelope8', 'envelope9', 'envelope10', 'envelope11', 'envelope12', 'envelope13', 'envelope14', 'envelope15', 'envelope16'};

#define NPROGS 8
#define NPROGS2 8
const byte BUFFER = 8;
float attack = 50;
float decay = 150;
float sustain = 0.8;
float release = 550;
float mixgain = 0.4;
int numNotes = 8;

void setup() {
Serial.begin(9600);

//Full Synth requires some serious memory
AudioMemory(64);
sgtl5000_1.enable();

// Full volume is 1.0 which will damage speakers or ears in most cases
sgtl5000_1.volume(0.4);

pinMode(25, INPUT_PULLUP);
pinMode(26, INPUT_PULLUP);
pinMode(27, INPUT_PULLUP);
pinMode(28, INPUT_PULLUP);
pinMode(29, INPUT_PULLUP);
pinMode(30, INPUT_PULLUP);
pinMode(31, INPUT_PULLUP);
pinMode(32, INPUT_PULLUP);

mixer1.gain(0, mixgain);
mixer1.gain(1, mixgain);
mixer1.gain(2, mixgain);
mixer1.gain(3, mixgain);

mixer2.gain(0, mixgain);
mixer2.gain(1, mixgain);
mixer2.gain(2, mixgain);
mixer2.gain(3, mixgain);

mixer3.gain(0, mixgain);
mixer3.gain(1, mixgain);
mixer3.gain(2, mixgain);
mixer3.gain(3, mixgain);

mixer4.gain(0, mixgain);
mixer4.gain(1, mixgain);
mixer4.gain(2, mixgain);
mixer4.gain(3, mixgain);

mixerFinal.gain(0, mixgain);
mixerFinal.gain(1, mixgain);

for(int i=16; i<17; i++){
envelopes[i].attack(attack);
envelopes[i] + .decay(decay);
envelopes[i] + .sustain(sustain);
envelopes[i] + .release(release);
}

envelope1.attack(attack);
envelope1.decay(decay);
envelope1.sustain(sustain);
envelope1.release(release);

envelope2.attack(attack);
envelope2.decay(decay);
envelope2.sustain(sustain);
envelope2.release(release);

envelope9.attack(attack);
envelope3.decay(decay);
envelope3.sustain(sustain);
envelope3.release(release);

envelope4.attack(attack);
envelope4.decay(decay);
envelope4.sustain(sustain);
envelope4.release(release);

envelope5.attack(attack);
envelope5.decay(decay);
envelope5.sustain(sustain);
envelope5.release(release);

envelope6.attack(attack);
envelope6.decay(decay);
envelope6.sustain(sustain);
envelope6.release(release);

envelope7.attack(attack);
envelope7.decay(decay);
envelope7.sustain(sustain);
envelope7.release(release);

envelope8.attack(attack);
envelope8.decay(decay);
envelope8.sustain(sustain);
envelope8.release(release);

envelope9.attack(attack);
envelope9.decay(decay);
envelope9.sustain(sustain);
envelope9.release(release);

envelope10.attack(attack);
envelope10.decay(decay);
envelope10.sustain(sustain);
envelope10.release(release);

envelope11.attack(attack);
envelope11.decay(decay);
envelope11.sustain(sustain);
envelope11.release(release);

envelope12.attack(attack);
envelope12.decay(decay);
envelope12.sustain(sustain);
envelope12.release(release);

envelope13.attack(attack);
envelope13.decay(decay);
envelope13.sustain(sustain);
envelope13.release(release);

envelope14.attack(attack);
envelope14.decay(decay);
envelope14.sustain(sustain);
envelope14.release(release);

envelope15.attack(attack);
envelope15.decay(decay);
envelope15.sustain(sustain);
envelope15.release(release);

envelope16.attack(attack);
envelope16.decay(decay);
envelope16.sustain(sustain);
envelope16.release(release);
}

void loop() {

AudioNoInterrupts();

int knob1 = 11880 * analogRead(A0) / 1023;
int knob2 = 11880 * analogRead(A1) / 1023;
int scale = map(val1, 0, 1024, 0, 7);
int knob6 = 11880 * analogRead(A3) / 1023;

/*
Below is the code to activate wave modulation at a fixed rate. TODO: Make rate Variable
modWave1.begin(0.6, 2, WAVEFORM_SINE);
modWave2.begin(0.6, 2, WAVEFORM_SINE);
*/

/* Wave Choice Knob

//filter on knob1 by uncommenting below and filter lines
//int knob1 = 11880 * analogRead(A2) / 1023;
//int knob2 = 7 * analogRead(A3) / 1023;

//Below will be how you scroll through wavforms. Need two knobs, then make int prognum = myProg; and
uint8_t progs[NPROGS] = {
WAVEFORM_SINE,
WAVEFORM_SQUARE,
WAVEFORM_TRIANGLE,
WAVEFORM_SAWTOOTH,
WAVEFORM_SAWTOOTH_REVERSE,
WAVEFORM_PULSE,
WAVEFORM_SAMPLE_HOLD,
WAVEFORM_ARBITRARY,
};

int index = map(val, 0, 1024, 0, 7);
int myProg = progs[index];

int prognum = myProg;

*/
float progamp = 0.6;
const char prognum = WAVEFORM_SQUARE;
waveform1.begin(progamp, noteFrequencies[scale][0], prognum);
waveform2.begin(progamp, noteFrequencies[scale][1], prognum);
waveform3.begin(progamp, noteFrequencies[scale][2], prognum);
waveform4.begin(progamp, noteFrequencies[scale][3], prognum);
waveform5.begin(progamp, noteFrequencies[scale][4], prognum);
waveform6.begin(progamp, noteFrequencies[scale][5], prognum);
waveform7.begin(progamp, noteFrequencies[scale][6], prognum);
waveform8.begin(progamp, noteFrequencies[scale][7], prognum);

envelope1.attack(knob1);
envelope1.release(knob2);
filter1.frequency(knob6);
//filter1.octaveControl(7);

envelope2.attack(knob1);
envelope2.release(knob2);
filter2.frequency(knob6);
//filter2.octaveControl(7);

envelope3.attack(knob1);
envelope3.release(knob2);
filter3.frequency(knob6);
//filter3.octaveControl(7);

envelope4.attack(knob1);
envelope4.release(knob2);
filter4.frequency(knob6);
//filter4.octaveControl(7);

envelope5.attack(knob1);
envelope5.release(knob2);
filter5.frequency(knob6);
//filter5.octaveControl(7);

envelope6.attack(knob1);
envelope6.release(knob2);
filter6.frequency(knob6);
//filter6.octaveControl(7);

envelope7.attack(knob1);
envelope7.release(knob2);
filter7.frequency(knob6);
//filter7.octaveControl(7);

envelope8.attack(knob1);
envelope8.release(knob2);
filter8.frequency(knob6);
//filter8.octaveControl(7);

/*

//filter on knob1 by uncommenting below and filter lines
//int knob5 = 11880 * analogRead(A2) / 1023;
//int knob2 = 7 * analogRead(A3) / 1023;

//Below will be how you scroll through wavforms. Need two knobs, then make int prognum = myProg; and
uint8_t progs2[NPROGS] = {
WAVEFORM_SINE,
WAVEFORM_SQUARE,
WAVEFORM_TRIANGLE,
WAVEFORM_SAWTOOTH,
WAVEFORM_SAWTOOTH_REVERSE,
WAVEFORM_PULSE,
WAVEFORM_SAMPLE_HOLD,
WAVEFORM_ARBITRARY,
};

int index2 = map(val2, 0, 1024, 0, 7);
int myProg2 = progs2[index2];

int prognum2 = myProg2;
*/
const char prognum2 = WAVEFORM_SINE;
//Detune will be controlled not fixed
int detune = 3;

waveform9.begin(progamp, noteFrequencies[scale][0] - detune, prognum2);
waveform10.begin(progamp, noteFrequencies[scale][1] - detune, prognum2);
waveform11.begin(progamp, noteFrequencies[scale][2] - detune, prognum2);
waveform12.begin(progamp, noteFrequencies[scale][3] - detune, prognum2);
waveform13.begin(progamp, noteFrequencies[scale][4] - detune, prognum2);
waveform14.begin(progamp, noteFrequencies[scale][5] - detune, prognum2);
waveform15.begin(progamp, noteFrequencies[scale][6] - detune, prognum2);
waveform16.begin(progamp, noteFrequencies[scale][7] - detune, prognum2);

envelope9.attack(knob1);
envelope9.release(knob2);
filter9.frequency(knob6);
//filter9.octaveControl(7);

envelope10.attack(knob1);
envelope10.release(knob2);
filter10.frequency(knob6);
//filter10.octaveControl(7);

envelope11.attack(knob1);
envelope11.release(knob2);
filter11.frequency(knob6);
//filter11.octaveControl(7);

envelope12.attack(knob1);
envelope12.release(knob2);
filter12.frequency(knob6);
//filter12.octaveControl(7);

envelope13.attack(knob1);
envelope13.release(knob2);
filter13.frequency(knob6);
//filter13.octaveControl(7);

envelope14.attack(knob1);
envelope14.release(knob2);
filter14.frequency(knob6);
//filter14.octaveControl(7);

envelope15.attack(knob1);
envelope15.release(knob2);
filter15.frequency(knob6);
//filter15.octaveControl(7);

envelope16.attack(knob1);
envelope16.release(knob2);
filter16.frequency(knob6);
//filter16.octaveControl(7);

button0.update();
button1.update();
button2.update();
button3.update();
button4.update();
button5.update();
button6.update();
button7.update();

AudioInterrupts();
//Trigger notes
if (button0.fallingEdge()) {
envelope1.noteOn();
envelope9.noteOn();
}
if (button0.risingEdge()) {
envelope1.noteOff();
envelope9.noteOff();
}

if (button1.fallingEdge()) {
envelope2.noteOn();
envelope10.noteOn();
}
if (button1.risingEdge()) {
envelope2.noteOff();
envelope10.noteOff();
}

if (button2.fallingEdge()) {
envelope3.noteOn();
envelope11.noteOn();
}
if (button2.risingEdge()) {
envelope3.noteOff();
envelope11.noteOff();
}

if (button3.fallingEdge()) {
envelope4.noteOn();
envelope12.noteOn();
}
if (button3.risingEdge()) {
envelope4.noteOff();
envelope12.noteOff();
}

if (button4.fallingEdge()) {

envelope5.noteOn();
envelope13.noteOn();
}
if (button4.risingEdge()) {
envelope5.noteOff();
envelope13.noteOff();
}

if (button5.fallingEdge()) {
envelope6.noteOn();
envelope14.noteOn();
}
if (button5.risingEdge()) {
envelope6.noteOff();
envelope14.noteOff();
}

if (button6.fallingEdge()) {
envelope7.noteOn();
envelope15.noteOn();
}
if (button6.risingEdge()) {
envelope7.noteOff();
envelope15.noteOff();
}

if (button7.fallingEdge()) {
envelope8.noteOn();
envelope16.noteOn();
}
if (button7 .risingEdge()) {
envelope8.noteOff();
envelope16.noteOff();
}
}```

2. ## Envelope Array Problems

envelope1-16 is instantiated objects not a char type as you defined. I cannot see the name of the object in you code, i guess in this example it's Envelope, maybe you have to look in header files for that.

You have to create an array of pointers to that object like this. the & is a address-of operator, it returns the memory address of a variable/object.

Code:
```Envelope *myEnvelope = { &envelope1, &envelope2, &envelope3, &envelope4 };

for (int i=0; i<4; i++){
myEnvelope[i]->attack(attack);
myEnvelope[i]->decay(decay);
myEnvelope[i]->sustain(sustain);
myEnvelope[i]->release(release);
}```

3. Hello Jacob.Schultz, thanks so much for your reply. I'm still a little confused. I think the object name is AudioEffectEnvelope from the header file. But do I replace Envelope in your code with that? It seems to throw a couple errors: "conflicting declaration 'AudioEffectEnvelope* myEnvelope'". Do I have to declare Envelope or myEnvelope? And how do I declare a pointer array? Thanks for all the help so far, I'm really trying to learn.

4. Here's the header file by the way:

Code:
```#ifndef _SYNTHARCH_H
#define _SYNTHARCH_H
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioSynthWaveform       modWave2; //xy=65,1082
AudioSynthWaveform       modWave1;      //xy=79,344
AudioMixer4              mixer6; //xy=212,1100
AudioMixer4              mixer5;         //xy=221,364
AudioSynthWaveformModulated waveform14; //xy=363,1336
AudioSynthWaveformModulated waveform16; //xy=366,1519
AudioSynthWaveformModulated waveform15; //xy=368,1437
AudioSynthWaveformModulated waveform12; //xy=375,1119
AudioSynthWaveformModulated waveform13; //xy=378,1206
AudioSynthWaveformModulated waveform9; //xy=380,836
AudioSynthWaveformModulated waveform10; //xy=381,928
AudioSynthWaveformModulated waveform11; //xy=381,1015
AudioSynthWaveformModulated waveform6; //xy=412,505
AudioSynthWaveformModulated waveform5; //xy=420,398
AudioSynthWaveformModulated waveform4; //xy=424,302
AudioSynthWaveformModulated waveform8; //xy=427,703
AudioSynthWaveformModulated waveform7; //xy=432,611
AudioSynthWaveformModulated waveform3; //xy=437,208
AudioSynthWaveformModulated waveform1;   //xy=444,27
AudioSynthWaveformModulated waveform2; //xy=449,110
AudioFilterStateVariable filter12;       //xy=525,1113
AudioFilterStateVariable filter13;       //xy=533,1209
AudioFilterStateVariable filter10;       //xy=535,923
AudioFilterStateVariable filter9;        //xy=536,841
AudioFilterStateVariable filter16;       //xy=538,1514
AudioFilterStateVariable filter14;       //xy=541,1332
AudioFilterStateVariable filter11;       //xy=546,1016
AudioFilterStateVariable filter15;       //xy=545,1438
AudioFilterStateVariable filter4;        //xy=571,307
AudioFilterStateVariable filter5;        //xy=579,403
AudioFilterStateVariable filter1;        //xy=581,35
AudioFilterStateVariable filter2;        //xy=581,117
AudioFilterStateVariable filter8;        //xy=584,708
AudioFilterStateVariable filter6;        //xy=587,526
AudioFilterStateVariable filter3;        //xy=592,210
AudioFilterStateVariable filter7;        //xy=591,632
AudioEffectEnvelope      envelope12;     //xy=705,1100
AudioEffectEnvelope      envelope13;     //xy=713,1196
AudioEffectEnvelope      envelope10;     //xy=715,910
AudioEffectEnvelope      envelope16;     //xy=718,1501
AudioEffectEnvelope      envelope9;      //xy=722,844
AudioEffectEnvelope      envelope14;     //xy=721,1316
AudioEffectEnvelope      envelope11;     //xy=726,1003
AudioEffectEnvelope      envelope15;     //xy=725,1425
AudioEffectEnvelope      envelope1;      //xy=737,20
AudioEffectEnvelope      envelope4;      //xy=751,294
AudioEffectEnvelope      envelope5;      //xy=759,390
AudioEffectEnvelope      envelope2;      //xy=761,104
AudioEffectEnvelope      envelope8;      //xy=764,695
AudioEffectEnvelope      envelope6;      //xy=767,513
AudioEffectEnvelope      envelope3;      //xy=772,197
AudioEffectEnvelope      envelope7;      //xy=771,619
AudioMixer4              mixer1;         //xy=977,679
AudioMixer4              mixer2;         //xy=984,788
AudioMixer4              mixer3;         //xy=986,929
AudioMixer4              mixer4;         //xy=989,1071
AudioMixer4              mixerFinal;     //xy=1138,812
AudioOutputI2S           i2s1;           //xy=1359,750
AudioConnection          patchCord1(modWave2, 0, mixer6, 0);
AudioConnection          patchCord2(modWave1, 0, mixer5, 0);
AudioConnection          patchCord3(mixer6, 0, waveform10, 0);
AudioConnection          patchCord4(mixer6, 0, waveform11, 0);
AudioConnection          patchCord5(mixer6, 0, waveform12, 0);
AudioConnection          patchCord6(mixer6, 0, waveform13, 0);
AudioConnection          patchCord7(mixer6, 0, waveform14, 0);
AudioConnection          patchCord8(mixer6, 0, waveform15, 0);
AudioConnection          patchCord9(mixer6, 0, waveform16, 0);
AudioConnection          patchCord10(mixer6, 0, waveform9, 0);
AudioConnection          patchCord11(mixer5, 0, waveform2, 0);
AudioConnection          patchCord12(mixer5, 0, waveform3, 0);
AudioConnection          patchCord13(mixer5, 0, waveform4, 0);
AudioConnection          patchCord14(mixer5, 0, waveform5, 0);
AudioConnection          patchCord15(mixer5, 0, waveform6, 0);
AudioConnection          patchCord16(mixer5, 0, waveform7, 0);
AudioConnection          patchCord17(mixer5, 0, waveform8, 0);
AudioConnection          patchCord18(mixer5, 0, waveform1, 0);
AudioConnection          patchCord19(waveform14, 0, filter14, 0);
AudioConnection          patchCord20(waveform16, 0, filter16, 0);
AudioConnection          patchCord21(waveform15, 0, filter15, 0);
AudioConnection          patchCord22(waveform12, 0, filter12, 0);
AudioConnection          patchCord23(waveform13, 0, filter13, 0);
AudioConnection          patchCord24(waveform9, 0, filter9, 0);
AudioConnection          patchCord25(waveform10, 0, filter10, 0);
AudioConnection          patchCord26(waveform11, 0, filter11, 0);
AudioConnection          patchCord27(waveform6, 0, filter6, 0);
AudioConnection          patchCord28(waveform5, 0, filter5, 0);
AudioConnection          patchCord29(waveform4, 0, filter4, 0);
AudioConnection          patchCord30(waveform8, 0, filter8, 0);
AudioConnection          patchCord31(waveform7, 0, filter7, 0);
AudioConnection          patchCord32(waveform3, 0, filter3, 0);
AudioConnection          patchCord33(waveform1, 0, filter1, 0);
AudioConnection          patchCord34(waveform2, 0, filter2, 0);
AudioConnection          patchCord35(filter12, 0, envelope12, 0);
AudioConnection          patchCord36(filter13, 0, envelope13, 0);
AudioConnection          patchCord37(filter10, 0, envelope10, 0);
AudioConnection          patchCord38(filter9, 0, envelope9, 0);
AudioConnection          patchCord39(filter16, 0, envelope16, 0);
AudioConnection          patchCord40(filter14, 0, envelope14, 0);
AudioConnection          patchCord41(filter11, 0, envelope11, 0);
AudioConnection          patchCord42(filter15, 0, envelope15, 0);
AudioConnection          patchCord43(filter4, 0, envelope4, 0);
AudioConnection          patchCord44(filter5, 0, envelope5, 0);
AudioConnection          patchCord45(filter1, 0, envelope1, 0);
AudioConnection          patchCord46(filter2, 0, envelope2, 0);
AudioConnection          patchCord47(filter8, 0, envelope8, 0);
AudioConnection          patchCord48(filter6, 0, envelope6, 0);
AudioConnection          patchCord49(filter3, 0, envelope3, 0);
AudioConnection          patchCord50(filter7, 0, envelope7, 0);
AudioConnection          patchCord51(envelope12, 0, mixer3, 3);
AudioConnection          patchCord52(envelope13, 0, mixer4, 0);
AudioConnection          patchCord53(envelope10, 0, mixer3, 1);
AudioConnection          patchCord54(envelope16, 0, mixer4, 3);
AudioConnection          patchCord55(envelope9, 0, mixer3, 0);
AudioConnection          patchCord56(envelope14, 0, mixer4, 1);
AudioConnection          patchCord57(envelope11, 0, mixer3, 2);
AudioConnection          patchCord58(envelope15, 0, mixer4, 2);
AudioConnection          patchCord59(envelope1, 0, mixer1, 0);
AudioConnection          patchCord60(envelope4, 0, mixer1, 3);
AudioConnection          patchCord61(envelope5, 0, mixer2, 0);
AudioConnection          patchCord62(envelope2, 0, mixer1, 1);
AudioConnection          patchCord63(envelope8, 0, mixer2, 3);
AudioConnection          patchCord64(envelope6, 0, mixer2, 1);
AudioConnection          patchCord65(envelope3, 0, mixer1, 2);
AudioConnection          patchCord66(envelope7, 0, mixer2, 2);
AudioConnection          patchCord67(mixer1, 0, mixerFinal, 0);
AudioConnection          patchCord68(mixer2, 0, mixerFinal, 1);
AudioConnection          patchCord69(mixer3, 0, mixerFinal, 2);
AudioConnection          patchCord70(mixer4, 0, mixerFinal, 3);
AudioConnection          patchCord71(mixerFinal, 0, i2s1, 0);
AudioConnection          patchCord72(mixerFinal, 0, i2s1, 1);
AudioControlSGTL5000     sgtl5000_1;     //xy=1046,562
// GUItool: end automatically generated code

#endif // _SYNTHARCH_H```

5. It should be like this
And please note the square brackets i have added, sorry i forgot that.

AudioEffectEnvelope *myEnvelope[] = { &envelope1, &envelope2, &envelope3, &envelope4 };

6. Originally Posted by Jacob.Schultz
It should be like this
And please note the square brackets i have added, sorry i forgot that.

AudioEffectEnvelope *myEnvelope[] = { &envelope1, &envelope2, &envelope3, &envelope4 };
Thank you so much! This is going to cut my code down by at least 35%! Jacob.Schultz, I tip my hat to you, sir!

7. Did you ever get this working? I'd like to do 16 voices and would love to not have to use a huge case statement for doing stuff to voices and envelopes.

If it works for you, can you please show the relevant variable declarations?

8. @quarterturn
A while back I posted an example on how to use arrays of audiolib objects,