Split main sketch into multiple files?

Status
Not open for further replies.

Revalogics

Well-known member
Hi guys, is it possible to split a single sketch into multiple files? I have a sketch for Teensy 3.6 that is 1,562 lines long. I tried the library approach, but most functions must change or read a global variable, and there I failed. Also, I noticed that running a code with other functions in separate libraries is slower than having all the functions in the main sketch.

Example: main sketch file
Code:
void setup() {
  function1begin();
  function2begin();
  function3begin();
}
void loop() {
  function1update();
  function2update();
  function3update();
}
void function1begin() {
  pinMode(1, OUTPUT);
}
void function2begin() {
  pinMode(2, OUTPUT);
}
void function3begin() {
  pinMode(3, OUTPUT);
}
void function1update() {
  digitalWriteFast(1, HIGH);
  digitalWriteFast(2, LOW);
  digitalWriteFast(3, LOW);
}
void function2update() {
  digitalWriteFast(1, LOW);
  digitalWriteFast(2, HIGH);
  digitalWriteFast(3, LOW);
}
void function3update() {
  digitalWriteFast(1, LOW);
  digitalWriteFast(2, LOW);
  digitalWriteFast(3, HIGH);
}
changed into something like this:
Code:
// Main sketch
#include "function1.c"
#include "function2.c"
#include "function3.c"
void setup() {
  function1begin();
  function2begin();
  function3begin();
}
void loop() {
  function1update();
  function2update();
  function3update();
}
Code:
// function1.c
void function1begin() {
  pinMode(1, OUTPUT);
}
void function1update() {
  digitalWriteFast(1, HIGH);
  digitalWriteFast(2, LOW);
  digitalWriteFast(3, LOW);
}
Code:
// function2.c
void function2begin() {
  pinMode(2, OUTPUT);
}
void function2update() {
  digitalWriteFast(1, LOW);
  digitalWriteFast(2, HIGH);
  digitalWriteFast(3, LOW);
}
Code:
// function3.c
void function3begin() {
  pinMode(3, OUTPUT);
}
void function3update() {
  digitalWriteFast(1, LOW);
  digitalWriteFast(2, LOW);
  digitalWriteFast(3, HIGH);
}
 
why files? why not tabs? they can be organized cleanly, just remember, includes and globals should be at the main tab, or before any tabs that use them, else you'll get compile errors that they are undefined.

Basically, the compiler has to see their creation before they are being used, if the variable will only be used in one tab for example you can put it above the function or the top of the tab that uses it.
 
Actually the multi-tabs are each files in the sketch folder.

Some details are up at places like: https://www.arduino.cc/en/Hacking/BuildProcess

It says that there are four valid extensions; none, .c, .cpp, .h

I could have sworn that you can have multiple files up there with the .ino extension. (Probably their case for no extension).

I believe the build process, simply combines all of the .ino (or no extension?) files into one .cpp file during the build, where the main sketch file (the one with the directory name) goes first. So that is where they suggest putting all of your globals.

As for having all of your functions in your sketch is faster than libraries... Not sure why? Other than maybe the optimizer can do something different?
 
heres an idea, setup your tabs in the IDE then save
then use notepad++ on your tabbed files
re-loading the IDE to compile will have the new changes
 
I tried that tonton81, but I received compilation error about variables and function calls. I'm reverting to single sketch.
Here's my sketch I'm trying to split: (note, it's long)
Code:
//#define USE_VOCODER
#ifndef ENCLOSETHIS
/** BOTTOM SIDE **/
//MIDI Rx         0
//MIDI Tx         1
#define LRS       2
//I2S Tx          3
#define LRW       4
#define LEN       5
#define LD4       6
#define LD5       7
#define LD6       8
#define LD7       9
#define ENC1      10
#define ENC2      11
#define ENCB      12
//I2S Rx          27
//I2S BCLK        29
//I2S LRCLK       30
/** TOP SIDE **/
#define VPOT01    23
#define VPOT02    22
#define VPOT03    21
#define VPOT04    20
#define VPOT05    19
#define VPOT06    18
#define VPOT07    17
#define VPOT08    16
#define BPMBTN    15
#define BPMLED    14
//I2S MCLK        35
#define LEDLAT    36  // 74HC595 pin 12
#define LEDCLK    37  // 74HC595 pin 11
#define LEDDAT    38  // 74HC595 pin 14

//#include <LiquidCrystalFast.h>
//LiquidCrystalFast MC2004(LRS, LRW, LEN, LD4, LD5, LD6, LD7);
#include <Audio.h>
#include <Bounce.h>
#include <ResponsiveAnalogRead.h>
#include <MIDI.h>
//Bounce encoderButton = Bounce(ENCB, 10);
Bounce bpmButton = Bounce(BPMBTN, 10);
ResponsiveAnalogRead vPot1(VPOT01, true, 0.01);
ResponsiveAnalogRead vPot2(VPOT02, true, 0.01);
ResponsiveAnalogRead vPot3(VPOT03, true, 0.01);
ResponsiveAnalogRead vPot4(VPOT04, true, 0.01);
ResponsiveAnalogRead vPot5(VPOT05, true, 0.01);
ResponsiveAnalogRead vPot6(VPOT06, true, 0.01);
ResponsiveAnalogRead vPot7(VPOT07, true, 0.01);
ResponsiveAnalogRead vPot8(VPOT08, true, 0.01);
elapsedMillis MIDITXt;
elapsedMillis MIDIRX1t;
elapsedMillis MIDIRX2t;
elapsedMillis POTSt;
elapsedMicros BPM1t;
elapsedMicros BPM2t;
elapsedMillis BPMLEDt;
elapsedMicros OFFt;
byte chsw[8], r[8], g[8], b[8], potc[8], potp[8], channels[8] = {1, 3, 5, 7, 9, 11, 13, 15},
pwmCounter, BPM, bpmValue = 128, thisnum;
bool PEDAL, MIDIRX1, MIDIRX2, MIDITX, br, bg, bb, bpmButtonCheck, OFF[8];
const float attack = 0.9;
float rawPeaks[19], valPeaks[19];
#endif
#ifdef USE_VOCODER
AudioInputI2S                 AudioIn;
AudioMixer4                   M001;
AudioMixer4                   M002;
AudioConnection                 C001(AudioIn, 0, M001, 0);
AudioConnection                 C002(AudioIn, 1, M002, 0);

AudioFilterStateVariable      F101_1;
AudioConnection                 C003(M001, 0, F101_1, 0);
AudioFilterStateVariable      F101_2;
AudioConnection                 C004(F101_1, 0, F101_2, 0);
AudioAnalyzePeak              P101;
AudioConnection                 C005(F101_2, 0, P101, 0);
AudioFilterStateVariable      F201_1;
AudioConnection                 C006(M002, 0, F201_1, 0);
AudioFilterStateVariable      F201_2;
AudioConnection                 C007(F201_1, 0, F201_2, 0);
AudioMixer4                   M201;
AudioConnection                 C008(F201_2, 0, M201, 0);

AudioFilterStateVariable      F102_1;
AudioConnection                 C009(M001, 0, F102_1, 0);
AudioFilterStateVariable      F102_2;
AudioConnection                 C010(F102_1, 1, F102_2, 0);
AudioAnalyzePeak              P102;
AudioConnection                 C011(F102_2, 1, P102, 0);
AudioFilterStateVariable      F202_1;
AudioConnection                 C012(M002, 0, F202_1, 0);
AudioFilterStateVariable      F202_2;
AudioConnection                 C013(F202_1, 1, F202_2, 0);
AudioMixer4                   M202;
AudioConnection                 C014(F202_2, 1, M202, 0);

AudioFilterStateVariable      F103_1;
AudioConnection                 C015(M001, 0, F103_1, 0);
AudioFilterStateVariable      F103_2;
AudioConnection                 C016(F103_1, 1, F103_2, 0);
AudioAnalyzePeak              P103;
AudioConnection                 C017(F103_2, 1, P103, 0);
AudioFilterStateVariable      F203_1;
AudioConnection                 C018(M002, 0, F203_1, 0);
AudioFilterStateVariable      F203_2;
AudioConnection                 C019(F203_1, 1, F203_2, 0);
AudioMixer4                   M203;
AudioConnection                 C020(F203_2, 1, M203, 0);

AudioFilterStateVariable      F104_1;
AudioConnection                 C021(M001, 0, F104_1, 0);
AudioFilterStateVariable      F104_2;
AudioConnection                 C022(F104_1, 1, F104_2, 0);
AudioAnalyzePeak              P104;
AudioConnection                 C023(F104_2, 1, P104, 0);
AudioFilterStateVariable      F204_1;
AudioConnection                 C024(M002, 0, F204_1, 0);
AudioFilterStateVariable      F204_2;
AudioConnection                 C025(F204_1, 1, F204_2, 0);
AudioMixer4                   M204;
AudioConnection                 C026(F204_2, 1, M204, 0);

AudioFilterStateVariable      F105_1;
AudioConnection                 C027(M001, 0, F105_1, 0);
AudioFilterStateVariable      F105_2;
AudioConnection                 C028(F105_1, 1, F105_2, 0);
AudioAnalyzePeak              P105;
AudioConnection                 C029(F105_2, 1, P105, 0);
AudioFilterStateVariable      F205_1;
AudioConnection                 C030(M002, 0, F205_1, 0);
AudioFilterStateVariable      F205_2;
AudioConnection                 C031(F205_1, 1, F205_2, 0);
AudioMixer4                   M205;
AudioConnection                 C032(F205_2, 1, M205, 0);

AudioFilterStateVariable      F106_1;
AudioConnection                 C033(M001, 0, F106_1, 0);
AudioFilterStateVariable      F106_2;
AudioConnection                 C034(F106_1, 1, F106_2, 0);
AudioAnalyzePeak              P106;
AudioConnection                 C035(F106_2, 1, P106, 0);
AudioFilterStateVariable      F206_1;
AudioConnection                 C036(M002, 0, F206_1, 0);
AudioFilterStateVariable      F206_2;
AudioConnection                 C037(F206_1, 1, F206_2, 0);
AudioMixer4                   M206;
AudioConnection                 C038(F206_2, 1, M206, 0);

AudioFilterStateVariable      F107_1;
AudioConnection                 C039(M001, 0, F107_1, 0);
AudioFilterStateVariable      F107_2;
AudioConnection                 C040(F107_1, 1, F107_2, 0);
AudioAnalyzePeak              P107;
AudioConnection                 C041(F107_2, 1, P107, 0);
AudioFilterStateVariable      F207_1;
AudioConnection                 C042(M002, 0, F207_1, 0);
AudioFilterStateVariable      F207_2;
AudioConnection                 C043(F207_1, 1, F207_2, 0);
AudioMixer4                   M207;
AudioConnection                 C044(F207_2, 1, M207, 0);

AudioFilterStateVariable      F108_1;
AudioConnection                 C045(M001, 0, F108_1, 0);
AudioFilterStateVariable      F108_2;
AudioConnection                 C046(F108_1, 1, F108_2, 0);
AudioAnalyzePeak              P108;
AudioConnection                 C047(F108_2, 1, P108, 0);
AudioFilterStateVariable      F208_1;
AudioConnection                 C048(M002, 0, F208_1, 0);
AudioFilterStateVariable      F208_2;
AudioConnection                 C049(F208_1, 1, F208_2, 0);
AudioMixer4                   M208;
AudioConnection                 C050(F208_2, 1, M208, 0);

AudioFilterStateVariable      F109_1;
AudioConnection                 C051(M001, 0, F109_1, 0);
AudioFilterStateVariable      F109_2;
AudioConnection                 C052(F109_1, 1, F109_2, 0);
AudioAnalyzePeak              P109;
AudioConnection                 C053(F109_2, 1, P109, 0);
AudioFilterStateVariable      F209_1;
AudioConnection                 C054(M002, 0, F209_1, 0);
AudioFilterStateVariable      F209_2;
AudioConnection                 C055(F209_1, 1, F209_2, 0);
AudioMixer4                   M209;
AudioConnection                 C056(F209_2, 1, M209, 0);

AudioFilterStateVariable      F110_1;
AudioConnection                 C057(M001, 0, F110_1, 0);
AudioFilterStateVariable      F110_2;
AudioConnection                 C058(F110_1, 1, F110_2, 0);
AudioAnalyzePeak              P110;
AudioConnection                 C059(F110_2, 1, P110, 0);
AudioFilterStateVariable      F210_1;
AudioConnection                 C060(M002, 0, F210_1, 0);
AudioFilterStateVariable      F210_2;
AudioConnection                 C061(F210_1, 1, F210_2, 0);
AudioMixer4                   M210;
AudioConnection                 C062(F210_2, 1, M210, 0);

AudioFilterStateVariable      F111_1;
AudioConnection                 C063(M001, 0, F111_1, 0);
AudioFilterStateVariable      F111_2;
AudioConnection                 C064(F111_1, 1, F111_2, 0);
AudioAnalyzePeak              P111;
AudioConnection                 C065(F111_2, 1, P111, 0);
AudioFilterStateVariable      F211_1;
AudioConnection                 C066(M002, 0, F211_1, 0);
AudioFilterStateVariable      F211_2;
AudioConnection                 C067(F211_1, 1, F211_2, 0);
AudioMixer4                   M211;
AudioConnection                 C068(F211_2, 1, M211, 0);

AudioFilterStateVariable      F112_1;
AudioConnection                 C069(M001, 0, F112_1, 0);
AudioFilterStateVariable      F112_2;
AudioConnection                 C070(F112_1, 1, F112_2, 0);
AudioAnalyzePeak              P112;
AudioConnection                 C071(F112_2, 1, P112, 0);
AudioFilterStateVariable      F212_1;
AudioConnection                 C072(M002, 0, F212_1, 0);
AudioFilterStateVariable      F212_2;
AudioConnection                 C073(F212_1, 1, F212_2, 0);
AudioMixer4                   M212;
AudioConnection                 C074(F212_2, 1, M212, 0);

AudioFilterStateVariable      F113_1;
AudioConnection                 C075(M001, 0, F113_1, 0);
AudioFilterStateVariable      F113_2;
AudioConnection                 C076(F113_1, 1, F113_2, 0);
AudioAnalyzePeak              P113;
AudioConnection                 C077(F113_2, 1, P113, 0);
AudioFilterStateVariable      F213_1;
AudioConnection                 C078(M002, 0, F213_1, 0);
AudioFilterStateVariable      F213_2;
AudioConnection                 C079(F213_1, 1, F213_2, 0);
AudioMixer4                   M213;
AudioConnection                 C080(F213_2, 1, M213, 0);

AudioFilterStateVariable      F114_1;
AudioConnection                 C081(M001, 0, F114_1, 0);
AudioFilterStateVariable      F114_2;
AudioConnection                 C082(F114_1, 1, F114_2, 0);
AudioAnalyzePeak              P114;
AudioConnection                 C083(F114_2, 1, P114, 0);
AudioFilterStateVariable      F214_1;
AudioConnection                 C084(M002, 0, F214_1, 0);
AudioFilterStateVariable      F214_2;
AudioConnection                 C085(F214_1, 1, F214_2, 0);
AudioMixer4                   M214;
AudioConnection                 C086(F214_2, 1, M214, 0);

AudioFilterStateVariable      F115_1;
AudioConnection                 C087(M001, 0, F115_1, 0);
AudioFilterStateVariable      F115_2;
AudioConnection                 C088(F115_1, 1, F115_2, 0);
AudioAnalyzePeak              P115;
AudioConnection                 C089(F115_2, 1, P115, 0);
AudioFilterStateVariable      F215_1;
AudioConnection                 C090(M002, 0, F215_1, 0);
AudioFilterStateVariable      F215_2;
AudioConnection                 C091(F215_1, 1, F215_2, 0);
AudioMixer4                   M215;
AudioConnection                 C092(F215_2, 1, M215, 0);

AudioFilterStateVariable      F116_1;
AudioConnection                 C093(M001, 0, F116_1, 0);
AudioFilterStateVariable      F116_2;
AudioConnection                 C094(F116_1, 1, F116_2, 0);
AudioAnalyzePeak              P116;
AudioConnection                 C095(F116_2, 1, P116, 0);
AudioFilterStateVariable      F216_1;
AudioConnection                 C096(M002, 0, F216_1, 0);
AudioFilterStateVariable      F216_2;
AudioConnection                 C097(F216_1, 1, F216_2, 0);
AudioMixer4                   M216;
AudioConnection                 C098(F216_2, 1, M216, 0);

AudioFilterStateVariable      F117_1;
AudioConnection                 C099(M001, 0, F117_1, 0);
AudioFilterStateVariable      F117_2;
AudioConnection                 C100(F117_1, 1, F117_2, 0);
AudioAnalyzePeak              P117;
AudioConnection                 C101(F117_2, 1, P117, 0);
AudioFilterStateVariable      F217_1;
AudioConnection                 C102(M002, 0, F217_1, 0);
AudioFilterStateVariable      F217_2;
AudioConnection                 C103(F217_1, 1, F217_2, 0);
AudioMixer4                   M217;
AudioConnection                 C104(F217_2, 1, M217, 0);

AudioFilterStateVariable      F118_1;
AudioConnection                 C105(M001, 0, F118_1, 0);
AudioFilterStateVariable      F118_2;
AudioConnection                 C106(F118_1, 1, F118_2, 0);
AudioAnalyzePeak              P118;
AudioConnection                 C107(F118_2, 1, P118, 0);
AudioFilterStateVariable      F218_1;
AudioConnection                 C108(M002, 0, F218_1, 0);
AudioFilterStateVariable      F218_2;
AudioConnection                 C109(F218_1, 1, F218_2, 0);
AudioMixer4                   M218;
AudioConnection                 C110(F218_2, 1, M218, 0);

AudioFilterStateVariable      F119_1;
AudioConnection                 C111(M001, 0, F119_1, 0);
AudioFilterStateVariable      F119_2;
AudioConnection                 C112(F119_1, 2, F119_2, 0);
AudioAnalyzePeak              P119;
AudioConnection                 C113(F119_2, 2, P119, 0);
AudioFilterStateVariable      F219_1;
AudioConnection                 C114(M002, 0, F219_1, 0);
AudioFilterStateVariable      F219_2;
AudioConnection                 C115(F219_1, 2, F219_2, 0);
AudioMixer4                   M219;
AudioConnection                 C116(F219_2, 2, M219, 0);

AudioSynthNoiseWhite          noiseGen;
AudioFilterStateVariable      F220_1;
AudioConnection                 C117(noiseGen, 0, F220_1, 0);
AudioFilterStateVariable      F220_2;
AudioConnection                 C118(F220_1, 2, F220_2, 0);
AudioMixer4                   M220;
AudioConnection                 C119(F220_2, 2, M220, 0);

AudioMixer4                   M003;
AudioConnection                 C120(M201, 0, M003, 0);
AudioConnection                 C121(M202, 0, M003, 1);
AudioConnection                 C122(M203, 0, M003, 2);
AudioConnection                 C123(M204, 0, M003, 3);

AudioMixer4                   M004;
AudioConnection                 C124(M205, 0, M004, 0);
AudioConnection                 C125(M206, 0, M004, 1);
AudioConnection                 C126(M207, 0, M004, 2);
AudioConnection                 C127(M208, 0, M004, 3);

AudioMixer4                   M005;
AudioConnection                 C128(M209, 0, M005, 0);
AudioConnection                 C129(M210, 0, M005, 1);
AudioConnection                 C130(M211, 0, M005, 2);
AudioConnection                 C131(M212, 0, M005, 3);

AudioMixer4                   M006;
AudioConnection                 C132(M213, 0, M006, 0);
AudioConnection                 C133(M214, 0, M006, 1);
AudioConnection                 C134(M215, 0, M006, 2);
AudioConnection                 C135(M216, 0, M006, 3);

AudioMixer4                   M007;
AudioConnection                 C136(M217, 0, M007, 0);
AudioConnection                 C137(M218, 0, M007, 1);
AudioConnection                 C138(M219, 0, M007, 2);
AudioConnection                 C139(M220, 0, M007, 3);

AudioMixer4                   M008;
AudioConnection                 C140(M003, 0, M008, 0);
AudioConnection                 C141(M004, 0, M008, 1);
AudioConnection                 C142(M005, 0, M008, 2);
AudioConnection                 C143(M006, 0, M008, 3);

AudioMixer4                   M009;
AudioConnection                 C144(M007, 0, M009, 0);

AudioMixer4                   M010;
AudioConnection                 C145(M008, 0, M010, 0);
AudioConnection                 C146(M009, 0, M010, 1);
AudioConnection                 C147(M001, 0, M010, 2);

AudioMixer4                   M011;
AudioConnection                 C148(M008, 0, M011, 0);
AudioConnection                 C149(M009, 0, M011, 1);
AudioConnection                 C150(M002, 0, M011, 2);

AudioOutputI2S                AudioOut;
AudioConnection                 C151(M010, 0, AudioOut, 0);
AudioConnection                 C152(M011, 0, AudioOut, 1);
#endif
void setup() {
  //vocoderBegin();
  usbMIDI.setHandleNoteOff(OnNoteOff);
  usbMIDI.setHandleNoteOn(OnNoteOn);
  usbMIDI.setHandleControlChange(OnControlChange);
  usbMIDI.setHandleProgramChange(OnProgramChange);
  usbMIDI.setHandlePitchChange(OnPitchChange);
  MIDI.begin(MIDI_CHANNEL_OMNI);
  pinMode(BPMBTN, INPUT_PULLUP);
  pinMode(13, OUTPUT);
  pinMode(LEDDAT, OUTPUT);
  pinMode(LEDCLK, OUTPUT);
  pinMode(LEDLAT, OUTPUT);
  pinMode(BPMLED, OUTPUT);
  digitalWriteFast(LEDDAT, LOW);
  digitalWriteFast(LEDCLK, LOW);
  digitalWriteFast(LEDLAT, HIGH);
  digitalWriteFast(13, HIGH);
}
void loop() {
  //vocoderUpdate();
  HWMIDIupdate();
  usbMIDIupdate();
  bpmRoutine();
  LEDupdate();
  checkLedOff();
  readPots();
}
void bpmRoutine() {
  bpmButton.update();
  if(BPM1t > 937500) {
    BPM1t = 0;
    bpmButtonCheck = 0;
  }
  if(bpmButton.fallingEdge()) {
    if(!bpmButtonCheck) {
      BPM1t = 0;
      BPM2t = 0;
      bpmButtonCheck = 1;
      usbMIDI.sendControlChange(14, BPM, 16);
      MIDI.sendControlChange(14, BPM, 16);
      MIDITX = 1;
      MIDITXt = 0;
    }
    else {
      bpmValue = 60000000/BPM1t;
      BPM1t = 0;
      BPM2t = 60000000/bpmValue;
      if(bpmValue > 191) bpmValue = 191;
      if(bpmValue < 64) bpmValue = 64;
      BPM = bpmValue - 64;
      usbMIDI.sendControlChange(14, BPM, 16);
      MIDI.sendControlChange(14, BPM, 16);
      MIDITX = 1;
      MIDITXt = 0;
    }
  }
  if(BPM2t >= 60000000/bpmValue) {
    BPM2t = 0;
    digitalWriteFast(BPMLED, HIGH);
    BPMLEDt = 0;
    OFFt = 0;
    thisnum = 7;
  }
}
void HWMIDIupdate() {
  if(MIDI.read()) {
    MIDIRX1 = 1;
    MIDIRX1t = 0;
    byte type = MIDI.getType();
    byte note, velocity, channel, control, value, program, d1, d2;
    int d3, pitch;
    switch(type) {
      case NoteOff:
        note = MIDI.getData1();
        velocity = MIDI.getData2();
        channel = MIDI.getChannel();
        if(chsw[0]) {
          usbMIDI.sendNoteOff(note, velocity, channels[0]);
          MIDITX = 1;
          MIDITXt = 0;
        }
        if(chsw[1]) {
          usbMIDI.sendNoteOff(note, velocity, channels[1]);
          MIDITX = 1;
          MIDITXt = 0;
        }
        if(chsw[2]) {
          usbMIDI.sendNoteOff(note, velocity, channels[2]);
          MIDITX = 1;
          MIDITXt = 0;
        }
        if(chsw[3]) {
          usbMIDI.sendNoteOff(note, velocity, channels[3]);
          MIDITX = 1;
          MIDITXt = 0;
        }
        if(chsw[4]) {
          usbMIDI.sendNoteOff(note, velocity, channels[4]);
          MIDITX = 1;
          MIDITXt = 0;
        }
        if(chsw[5]) {
          usbMIDI.sendNoteOff(note, velocity, channels[5]);
          MIDITX = 1;
          MIDITXt = 0;
        }
        if(chsw[6]) {
          usbMIDI.sendNoteOff(note, velocity, channels[6]);
          MIDITX = 1;
          MIDITXt = 0;
        }
        if(chsw[7]) {
          usbMIDI.sendNoteOff(note, velocity, channels[7]);
          MIDITX = 1;
          MIDITXt = 0;
        }
      break;
      case NoteOn:
        note = MIDI.getData1();
        velocity = MIDI.getData2();
        channel = MIDI.getChannel();
        if(velocity == 0) {
          if(chsw[0]) {
            usbMIDI.sendNoteOff(note, 127, channels[0]);
            MIDITX = 1;
            MIDITXt = 0;
          }
          if(chsw[1]) {
            usbMIDI.sendNoteOff(note, 127, channels[1]);
            MIDITX = 1;
            MIDITXt = 0;
          }
          if(chsw[2]) {
            usbMIDI.sendNoteOff(note, 127, channels[2]);
            MIDITX = 1;
            MIDITXt = 0;
          }
          if(chsw[3]) {
            usbMIDI.sendNoteOff(note, 127, channels[3]);
            MIDITX = 1;
            MIDITXt = 0;
          }
          if(chsw[4]) {
            usbMIDI.sendNoteOff(note, 127, channels[4]);
            MIDITX = 1;
            MIDITXt = 0;
          }
          if(chsw[5]) {
            usbMIDI.sendNoteOff(note, 127, channels[5]);
            MIDITX = 1;
            MIDITXt = 0;
          }
          if(chsw[6]) {
            usbMIDI.sendNoteOff(note, 127, channels[6]);
            MIDITX = 1;
            MIDITXt = 0;
          }
          if(chsw[7]) {
            usbMIDI.sendNoteOff(note, 127, channels[7]);
            MIDITX = 1;
            MIDITXt = 0;
          }
        }
        else {
          if(chsw[0]) {
            usbMIDI.sendNoteOn(note, velocity, channels[0]);
            MIDITX = 1;
            MIDITXt = 0;
          }
          if(chsw[1]) {
            usbMIDI.sendNoteOn(note, velocity, channels[1]);
            MIDITX = 1;
            MIDITXt = 0;
          }
          if(chsw[2]) {
            usbMIDI.sendNoteOn(note, velocity, channels[2]);
            MIDITX = 1;
            MIDITXt = 0;
          }
          if(chsw[3]) {
            usbMIDI.sendNoteOn(note, velocity, channels[3]);
            MIDITX = 1;
            MIDITXt = 0;
          }
          if(chsw[4]) {
            usbMIDI.sendNoteOn(note, velocity, channels[4]);
            MIDITX = 1;
            MIDITXt = 0;
          }
          if(chsw[5]) {
            usbMIDI.sendNoteOn(note, velocity, channels[5]);
            MIDITX = 1;
            MIDITXt = 0;
          }
          if(chsw[6]) {
            usbMIDI.sendNoteOn(note, velocity, channels[6]);
            MIDITX = 1;
            MIDITXt = 0;
          }
          if(chsw[7]) {
            usbMIDI.sendNoteOn(note, velocity, channels[7]);
            MIDITX = 1;
            MIDITXt = 0;
          }
        }
      break;
      case ControlChange:
        control = MIDI.getData1();
        value = MIDI.getData2();
        channel = MIDI.getChannel();
        if(control == 1 || control == 64) {
          usbMIDI.sendControlChange(control, value, channels[0]);
          usbMIDI.sendControlChange(control, value, channels[1]);
          usbMIDI.sendControlChange(control, value, channels[2]);
          usbMIDI.sendControlChange(control, value, channels[3]);
          usbMIDI.sendControlChange(control, value, channels[4]);
          usbMIDI.sendControlChange(control, value, channels[5]);
          usbMIDI.sendControlChange(control, value, channels[6]);
          usbMIDI.sendControlChange(control, value, channels[7]);
          MIDITX = 1;
          MIDITXt = 0;
          if(control == 64) {
            if(value == 127) PEDAL = 1;
            if(value == 0) PEDAL = 0;
          }
        }
      break;
      case ProgramChange:
        program = MIDI.getData1();
        channel = MIDI.getChannel();
        //usbMIDI.sendProgramChange(program, channel);
      break;
      case PitchBend:
        d1 = MIDI.getData1();
        d2 = MIDI.getData2();
        d3 = d2 << 9;
        pitch = (d3 >> 2) + d1;
        channel = MIDI.getChannel();
        usbMIDI.sendPitchBend(pitch, channels[0]);
        usbMIDI.sendPitchBend(pitch, channels[1]);
        usbMIDI.sendPitchBend(pitch, channels[2]);
        usbMIDI.sendPitchBend(pitch, channels[3]);
        usbMIDI.sendPitchBend(pitch, channels[4]);
        usbMIDI.sendPitchBend(pitch, channels[5]);
        usbMIDI.sendPitchBend(pitch, channels[6]);
        usbMIDI.sendPitchBend(pitch, channels[7]);
        MIDITX = 1;
        MIDITXt = 0;
      break;
      default:
      break;
    }
  }
}
void usbMIDIupdate() {
  if(usbMIDI.read()) {
    MIDIRX2 = 1;
    MIDIRX2t = 0;
  }
}
void LEDupdate() {
  static byte number;
  number++;
  pwmCounter++;
  long bpmToLed = 7400000 / bpmValue;
  if(OFFt >= bpmToLed) {
    OFFt = 0;
    thisnum++;
    if(thisnum > 7) thisnum = 0;
    switch(thisnum) {
      case 0:
        OFF[0] = 1;
        OFF[1] = 0;
        OFF[2] = 0;
        OFF[3] = 0;
        OFF[4] = 0;
        OFF[5] = 0;
        OFF[6] = 0;
        OFF[7] = 0;
      break;
      case 1:
        OFF[0] = 0;
        OFF[1] = 1;
        OFF[2] = 0;
        OFF[3] = 0;
        OFF[4] = 0;
        OFF[5] = 0;
        OFF[6] = 0;
        OFF[7] = 0;
      break;
      case 2:
        OFF[0] = 0;
        OFF[1] = 0;
        OFF[2] = 1;
        OFF[3] = 0;
        OFF[4] = 0;
        OFF[5] = 0;
        OFF[6] = 0;
        OFF[7] = 0;
      break;
      case 3:
        OFF[0] = 0;
        OFF[1] = 0;
        OFF[2] = 0;
        OFF[3] = 1;
        OFF[4] = 0;
        OFF[5] = 0;
        OFF[6] = 0;
        OFF[7] = 0;
      break;
      case 4:
        OFF[0] = 0;
        OFF[1] = 0;
        OFF[2] = 0;
        OFF[3] = 0;
        OFF[4] = 1;
        OFF[5] = 0;
        OFF[6] = 0;
        OFF[7] = 0;
      break;
      case 5:
        OFF[0] = 0;
        OFF[1] = 0;
        OFF[2] = 0;
        OFF[3] = 0;
        OFF[4] = 0;
        OFF[5] = 1;
        OFF[6] = 0;
        OFF[7] = 0;
      break;
      case 6:
        OFF[0] = 0;
        OFF[1] = 0;
        OFF[2] = 0;
        OFF[3] = 0;
        OFF[4] = 0;
        OFF[5] = 0;
        OFF[6] = 1;
        OFF[7] = 0;
      break;
      case 7:
        OFF[0] = 0;
        OFF[1] = 0;
        OFF[2] = 0;
        OFF[3] = 0;
        OFF[4] = 0;
        OFF[5] = 0;
        OFF[6] = 0;
        OFF[7] = 1;
      break;
    }
  }
  if(number > 8) number = 1;
  switch(number) {
    case 1:
      pwmCheck(0);
      if(chsw[0]) command(PEDAL, br, bg, bb, 1);
      else command(PEDAL, OFF[0], 0, 0, 1);
    break;
    case 2:
      pwmCheck(1);
      if(chsw[1]) command(MIDIRX1, br, bg, bb, 2);
      else command(MIDIRX1, OFF[1], 0, 0, 2);
    break;
    case 3:
      pwmCheck(2);
      if(chsw[2]) command(MIDIRX2, br, bg, bb, 3);
      else command(MIDIRX2, OFF[2], 0, 0, 3);
    break;
    case 4:
      pwmCheck(3);
      if(chsw[3]) command(MIDITX, br, bg, bb, 4);
      else command(MIDITX, OFF[3], 0, 0, 4);
    break;
    case 5:
      pwmCheck(4);
      if(chsw[4]) command(0, br, bg, bb, 5);
      else command(0, OFF[4], 0, 0, 5);
    break;
    case 6:
      pwmCheck(5);
      if(chsw[5]) command(0, br, bg, bb, 6);
      else command(0, OFF[5], 0, 0, 6);
    break;
    case 7:
      pwmCheck(6);
      if(chsw[6]) command(0, br, bg, bb, 7);
      else command(0, OFF[6], 0, 0, 7);
    break;
    case 8:
      pwmCheck(7);
      if(chsw[7]) command(0, br, bg, bb, 8);
      else command(0, OFF[7], 0, 0, 8);
    break;
  }
}
void checkLedOff() {
  if(MIDIRX1 && MIDIRX1t >= 50) {
    MIDIRX1 = 0;
  }
  if(MIDIRX2 && MIDIRX2t >= 50) {
    MIDIRX2 = 0;
  }
  if(MIDITX && MIDITXt >= 50) {
    MIDITX = 0;
  }
  if(digitalRead(BPMLED) && BPMLEDt >= 25) {
    digitalWriteFast(BPMLED, LOW);
  }
}
void readPots() {
  if(POTSt >= 20) {
    POTSt = 0;
    vPot1.update();
    vPot2.update();
    vPot3.update();
    vPot4.update();
    vPot5.update();
    vPot6.update();
    vPot7.update();
    vPot8.update();
    potc[0] = vPot1.getValue() >> 3;
    potc[1] = vPot2.getValue() >> 3;
    potc[2] = vPot3.getValue() >> 3;
    potc[3] = vPot4.getValue() >> 3;
    potc[4] = vPot5.getValue() >> 3;
    potc[5] = vPot6.getValue() >> 3;
    potc[6] = vPot7.getValue() >> 3;
    potc[7] = vPot8.getValue() >> 3;
    for(int i = 0; i < 8; i++) {
      sendVol(i);
      storePWM(i, potc[i]);
    }
  }
}
void sendVol(byte channel) {
  if(potc[channel] != potp[channel]) {
    usbMIDI.sendControlChange(7, potc[channel], channels[channel]);
    MIDITX = 1;
    MIDITXt = 0;
    potp[channel] = potc[channel];
    if(potc[channel] == 0) {
      chsw[channel] = 0;
    }
    else {
      chsw[channel] = 1;
    }
  }
}
void pwmCheck(byte num) {
  if(r[num] > pwmCounter) {
    br = 1;
  }
  else {
    br = 0;
  }
  if(g[num] > pwmCounter) {
    bg = 1;
  }
  else {
    bg = 0;
  }
  if(b[num] > pwmCounter) {
    bb = 1;
  }
  else {
    bb = 0;
  }
}
void command(byte c1, byte c2, byte c3, byte c4, byte number) {
  switch(number) {
    case 1:
      parse(c1, c2, c3, c4);
      sendHigh();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
    break;
    case 2:
      parse(c1, c2, c3, c4);
      sendLow();
      sendHigh();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
    break;
    case 3:
      parse(c1, c2, c3, c4);
      sendLow();
      sendLow();
      sendHigh();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
    break;
    case 4:
      parse(c1, c2, c3, c4);
      sendLow();
      sendLow();
      sendLow();
      sendHigh();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
    break;
    case 5:
      parse(c1, c2, c3, c4);
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendHigh();
      sendLow();
      sendLow();
      sendLow();
    break;
    case 6:
      parse(c1, c2, c3, c4);
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendHigh();
      sendLow();
      sendLow();
    break;
    case 7:
      parse(c1, c2, c3, c4);
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendHigh();
      sendLow();
    break;
    case 8:
      parse(c1, c2, c3, c4);
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendHigh();
    break;
    default:
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
      sendLow();
    break;
  }
  sendLatch();
}
void parse(byte c1, byte c2, byte c3, byte c4) {
  if(c4) {
    sendLow();
  }
  else {
    sendHigh();
  }
  if(c3) {
    sendLow();
  }
  else {
    sendHigh();
  }
  if(c2) {
    sendLow();
  }
  else {
    sendHigh();
  }
  if(c1) {
    sendLow();
  }
  else {
    sendHigh();
  }
}
void sendHigh() {
  digitalWriteFast(LEDDAT, HIGH);
  epicDelay();
  digitalWriteFast(LEDCLK, HIGH);
  epicDelay();
  digitalWriteFast(LEDCLK, LOW);
  epicDelay();
}
void sendLow() {
  digitalWriteFast(LEDDAT, LOW);
  epicDelay();
  digitalWriteFast(LEDCLK, HIGH);
  epicDelay();
  digitalWriteFast(LEDCLK, LOW);
  epicDelay();
}
void sendLatch() {
  digitalWriteFast(LEDLAT, LOW);
  epicDelay();
  digitalWriteFast(LEDLAT, HIGH);
  epicDelay();
}
void epicDelay() {
  digitalWrite(13, HIGH);
}
void storePWM(byte num, byte value) {
  if(value == 0) {
    r[num] = 255;
    g[num] = 0;
    b[num] = 0;
  }
  if(value <= 42 && value > 0) {
    int val1 = map(value, 1, 42, 0, 255);
    int val2 = 255 - val1;
    r[num] = val2;
    g[num] = val1;
    b[num] = 0;
  }
  if(value <= 84 && value > 42) {
    int val3 = map(value, 43, 84, 0, 255);
    int val4 = 255 - val3;
    r[num] = 0;
    g[num] = val4;
    b[num] = val3;
  }
  if(value <= 127 && value > 84) {
    int val5 = map(value, 85, 127, 0, 255);
    r[num] = val5;
    g[num] = val5;
    b[num] = 255;
  }
}
void OnNoteOff(byte channel, byte note, byte velocity) {
  usbMIDI.sendNoteOff(note, velocity, channels[0]);
  usbMIDI.sendNoteOff(note, velocity, channels[1]);
  usbMIDI.sendNoteOff(note, velocity, channels[2]);
  usbMIDI.sendNoteOff(note, velocity, channels[3]);
  usbMIDI.sendNoteOff(note, velocity, channels[4]);
  usbMIDI.sendNoteOff(note, velocity, channels[5]);
  usbMIDI.sendNoteOff(note, velocity, channels[6]);
  usbMIDI.sendNoteOff(note, velocity, channels[7]);
  MIDITX = 1;
  MIDITXt = 0;
}
void OnNoteOn(byte channel, byte note, byte velocity) {
  usbMIDI.sendNoteOn(note, velocity, channels[0]);
  usbMIDI.sendNoteOn(note, velocity, channels[1]);
  usbMIDI.sendNoteOn(note, velocity, channels[2]);
  usbMIDI.sendNoteOn(note, velocity, channels[3]);
  usbMIDI.sendNoteOn(note, velocity, channels[4]);
  usbMIDI.sendNoteOn(note, velocity, channels[5]);
  usbMIDI.sendNoteOn(note, velocity, channels[6]);
  usbMIDI.sendNoteOn(note, velocity, channels[7]);
  MIDITX = 1;
  MIDITXt = 0;
}
void OnControlChange(byte channel, byte control, byte value) {
  usbMIDI.sendControlChange(control, value, channels[0]);
  usbMIDI.sendControlChange(control, value, channels[1]);
  usbMIDI.sendControlChange(control, value, channels[2]);
  usbMIDI.sendControlChange(control, value, channels[3]);
  usbMIDI.sendControlChange(control, value, channels[4]);
  usbMIDI.sendControlChange(control, value, channels[5]);
  usbMIDI.sendControlChange(control, value, channels[6]);
  usbMIDI.sendControlChange(control, value, channels[7]);
  MIDITX = 1;
  MIDITXt = 0;
  if(control == 64) {
    if(value == 127) PEDAL = 1;
    if(value == 0) PEDAL = 0;
  }
}
void OnProgramChange(byte channel, byte program) {
  
}
void OnPitchChange(byte channel, int pitch) {
  usbMIDI.sendPitchBend(pitch, channels[0]);
  usbMIDI.sendPitchBend(pitch, channels[1]);
  usbMIDI.sendPitchBend(pitch, channels[2]);
  usbMIDI.sendPitchBend(pitch, channels[3]);
  usbMIDI.sendPitchBend(pitch, channels[4]);
  usbMIDI.sendPitchBend(pitch, channels[5]);
  usbMIDI.sendPitchBend(pitch, channels[6]);
  usbMIDI.sendPitchBend(pitch, channels[7]);
  MIDITX = 1;
  MIDITXt = 0;
}
#ifdef USE_VOCODER
void vocoderBegin() {
  float res = 5; // filter resonance
  M001.gain(0, 0); // voice input gain
  M002.gain(0, 0); // instrument input gain
  M010.gain(0, 0); // vocoder out 1 level (16 bands) to voice out
  M010.gain(1, 0); // vocoder out 2 level (4 bands) to voice out
  M010.gain(2, 0); // voice dry level
  M011.gain(0, 0); // vocoder out 1 level (16 bands) to instrument out
  M011.gain(1, 0); // vocoder out 2 level (4 bands) to instrument out
  M011.gain(2, 0); // instrument dry level
  noiseGen.amplitude(0); // sibilance level
  M003.gain(0, 0.25); // level 2 vocoder bands mixer
  M003.gain(1, 0.25); // level 2 vocoder bands mixer
  M003.gain(2, 0.25); // level 2 vocoder bands mixer
  M003.gain(3, 0.25); // level 2 vocoder bands mixer
  M004.gain(0, 0.25); // level 2 vocoder bands mixer
  M004.gain(1, 0.25); // level 2 vocoder bands mixer
  M004.gain(2, 0.25); // level 2 vocoder bands mixer
  M004.gain(3, 0.25); // level 2 vocoder bands mixer
  M005.gain(0, 0.25); // level 2 vocoder bands mixer
  M005.gain(1, 0.25); // level 2 vocoder bands mixer
  M005.gain(2, 0.25); // level 2 vocoder bands mixer
  M005.gain(3, 0.25); // level 2 vocoder bands mixer
  M006.gain(0, 0.25); // level 2 vocoder bands mixer
  M006.gain(1, 0.25); // level 2 vocoder bands mixer
  M006.gain(2, 0.25); // level 2 vocoder bands mixer
  M006.gain(3, 0.25); // level 2 vocoder bands mixer
  M007.gain(0, 0.25); // level 2 vocoder bands mixer
  M007.gain(1, 0.25); // level 2 vocoder bands mixer
  M007.gain(2, 0.25); // level 2 vocoder bands mixer
  M007.gain(3, 0.25); // level 2 vocoder bands mixer
  M008.gain(0, 0.25); // level 3 vocoder bands mixer
  M008.gain(1, 0.25); // level 3 vocoder bands mixer
  M008.gain(2, 0.25); // level 3 vocoder bands mixer
  M008.gain(3, 0.25); // level 3 vocoder bands mixer
  M009.gain(0, 0.25); // level 3 vocoder bands mixer
  float freq;
  freq = 110.0000000; // A2
  F101_1.frequency(freq);
  F101_2.frequency(freq);
  F201_1.frequency(freq);
  F201_2.frequency(freq);
  freq = 138.5913155; // C#3
  F102_1.frequency(freq);
  F102_2.frequency(freq);
  F202_1.frequency(freq);
  F202_2.frequency(freq);
  freq = 174.6141157; // F3
  F103_1.frequency(freq);
  F103_2.frequency(freq);
  F203_1.frequency(freq);
  F203_2.frequency(freq);
  freq = 220.0000000; // A3
  F104_1.frequency(freq);
  F104_2.frequency(freq);
  F204_1.frequency(freq);
  F204_2.frequency(freq);
  freq = 277.1826310; // C#4
  F105_1.frequency(freq);
  F105_2.frequency(freq);
  F205_1.frequency(freq);
  F205_2.frequency(freq);
  freq = 349.2282314; // F4
  F106_1.frequency(freq);
  F106_2.frequency(freq);
  F206_1.frequency(freq);
  F206_2.frequency(freq);
  freq = 440.0000000; // A4
  F107_1.frequency(freq);
  F107_2.frequency(freq);
  F207_1.frequency(freq);
  F207_2.frequency(freq);
  freq = 554.3652620; // C#5
  F108_1.frequency(freq);
  F108_2.frequency(freq);
  F208_1.frequency(freq);
  F208_2.frequency(freq);
  freq = 698.4564629; // F5
  F109_1.frequency(freq);
  F109_2.frequency(freq);
  F209_1.frequency(freq);
  F209_2.frequency(freq);
  freq = 880.0000000; // A5
  F110_1.frequency(freq);
  F110_2.frequency(freq);
  F210_1.frequency(freq);
  F210_2.frequency(freq);
  freq = 1108.730524; // C#6
  F111_1.frequency(freq);
  F111_2.frequency(freq);
  F211_1.frequency(freq);
  F211_2.frequency(freq);
  freq = 1396.912926; // F6
  F112_1.frequency(freq);
  F112_2.frequency(freq);
  F212_1.frequency(freq);
  F212_2.frequency(freq);
  freq = 1760.000000; // A6
  F113_1.frequency(freq);
  F113_2.frequency(freq);
  F213_1.frequency(freq);
  F213_2.frequency(freq);
  freq = 2217.461048; // C#7
  F114_1.frequency(freq);
  F114_2.frequency(freq);
  F214_1.frequency(freq);
  F214_2.frequency(freq);
  freq = 2793.825851; // F7
  F115_1.frequency(freq);
  F115_2.frequency(freq);
  F215_1.frequency(freq);
  F215_2.frequency(freq);
  freq = 3520.000000; // A7
  F116_1.frequency(freq);
  F116_2.frequency(freq);
  F216_1.frequency(freq);
  F216_2.frequency(freq);
  freq = 4434.922096; // C#8
  F117_1.frequency(freq);
  F117_2.frequency(freq);
  F217_1.frequency(freq);
  F217_2.frequency(freq);
  freq = 5587.651703; // F8
  F118_1.frequency(freq);
  F118_2.frequency(freq);
  F218_1.frequency(freq);
  F218_2.frequency(freq);
  freq = 7040.000000; // A8
  F119_1.frequency(freq);
  F119_2.frequency(freq);
  F219_1.frequency(freq);
  F219_2.frequency(freq);
  F220_1.frequency(freq);
  F220_2.frequency(freq);
  F101_1.resonance(res);
  F101_2.resonance(res);
  F201_1.resonance(res);
  F201_2.resonance(res);
  F102_1.resonance(res);
  F102_2.resonance(res);
  F202_1.resonance(res);
  F202_2.resonance(res);
  F103_1.resonance(res);
  F103_2.resonance(res);
  F203_1.resonance(res);
  F203_2.resonance(res);
  F104_1.resonance(res);
  F104_2.resonance(res);
  F204_1.resonance(res);
  F204_2.resonance(res);
  F105_1.resonance(res);
  F105_2.resonance(res);
  F205_1.resonance(res);
  F205_2.resonance(res);
  F106_1.resonance(res);
  F106_2.resonance(res);
  F206_1.resonance(res);
  F206_2.resonance(res);
  F107_1.resonance(res);
  F107_2.resonance(res);
  F207_1.resonance(res);
  F207_2.resonance(res);
  F108_1.resonance(res);
  F108_2.resonance(res);
  F208_1.resonance(res);
  F208_2.resonance(res);
  F109_1.resonance(res);
  F109_2.resonance(res);
  F209_1.resonance(res);
  F209_2.resonance(res);
  F110_1.resonance(res);
  F110_2.resonance(res);
  F210_1.resonance(res);
  F210_2.resonance(res);
  F111_1.resonance(res);
  F111_2.resonance(res);
  F211_1.resonance(res);
  F211_2.resonance(res);
  F101_1.resonance(res);
  F112_2.resonance(res);
  F212_1.resonance(res);
  F212_2.resonance(res);
  F113_1.resonance(res);
  F113_2.resonance(res);
  F213_1.resonance(res);
  F213_2.resonance(res);
  F114_1.resonance(res);
  F114_2.resonance(res);
  F214_1.resonance(res);
  F214_2.resonance(res);
  F115_1.resonance(res);
  F115_2.resonance(res);
  F215_1.resonance(res);
  F215_2.resonance(res);
  F116_1.resonance(res);
  F116_2.resonance(res);
  F216_1.resonance(res);
  F216_2.resonance(res);
  F117_1.resonance(res);
  F117_2.resonance(res);
  F217_1.resonance(res);
  F217_2.resonance(res);
  F118_1.resonance(res);
  F118_2.resonance(res);
  F218_1.resonance(res);
  F218_2.resonance(res);
  F119_1.resonance(res);
  F119_2.resonance(res);
  F219_1.resonance(res);
  F219_2.resonance(res);
  F220_1.resonance(res);
  F220_2.resonance(res);
  valPeaks[0] = 1;
  valPeaks[1] = 1;
  valPeaks[2] = 1;
  valPeaks[3] = 1;
  valPeaks[4] = 1;
  valPeaks[5] = 1;
  valPeaks[6] = 1;
  valPeaks[7] = 1;
  valPeaks[8] = 1;
  valPeaks[9] = 1;
  valPeaks[10] = 1;
  valPeaks[11] = 1;
  valPeaks[12] = 1;
  valPeaks[13] = 1;
  valPeaks[14] = 1;
  valPeaks[15] = 1;
  valPeaks[16] = 1;
  valPeaks[17] = 1;
  valPeaks[18] = 1;
  AudioMemory(64);
}
void vocoderUpdate() {
  if(P101.available()) {
    rawPeaks[0] = P101.read();
  }
  if(rawPeaks[0] > valPeaks[0]) {
    valPeaks[0] /= attack;
    M201.gain(0, valPeaks[0]);
  }
  if(rawPeaks[0] < valPeaks[0]) {
    valPeaks[0] *= attack;
    M201.gain(0, valPeaks[0]);
  }
  if(P102.available()) {
    rawPeaks[1] = P102.read();
  }
  if(rawPeaks[1] > valPeaks[1]) {
    valPeaks[1] /= attack;
    M202.gain(0, valPeaks[1]);
  }
  if(rawPeaks[1] < valPeaks[1]) {
    valPeaks[1] *= attack;
    M202.gain(0, valPeaks[1]);
  }
  if(P103.available()) {
    rawPeaks[2] = P103.read();
  }
  if(rawPeaks[2] > valPeaks[2]) {
    valPeaks[2] /= attack;
    M203.gain(0, valPeaks[2]);
  }
  if(rawPeaks[2] < valPeaks[2]) {
    valPeaks[2] *= attack;
    M203.gain(0, valPeaks[2]);
  }
  if(P104.available()) {
    rawPeaks[3] = P104.read();
  }
  if(rawPeaks[3] > valPeaks[3]) {
    valPeaks[3] /= attack;
    M204.gain(0, valPeaks[3]);
  }
  if(rawPeaks[3] < valPeaks[3]) {
    valPeaks[3] *= attack;
    M204.gain(0, valPeaks[3]);
  }
  if(P105.available()) {
    rawPeaks[4] = P105.read();
  }
  if(rawPeaks[4] > valPeaks[4]) {
    valPeaks[4] /= attack;
    M205.gain(0, valPeaks[4]);
  }
  if(rawPeaks[4] < valPeaks[4]) {
    valPeaks[4] *= attack;
    M205.gain(0, valPeaks[4]);
  }
  if(P106.available()) {
    rawPeaks[5] = P106.read();
  }
  if(rawPeaks[5] > valPeaks[5]) {
    valPeaks[5] /= attack;
    M206.gain(0, valPeaks[5]);
  }
  if(rawPeaks[5] < valPeaks[5]) {
    valPeaks[5] *= attack;
    M206.gain(0, valPeaks[5]);
  }
  if(P107.available()) {
    rawPeaks[6] = P107.read();
  }
  if(rawPeaks[6] > valPeaks[6]) {
    valPeaks[6] /= attack;
    M207.gain(0, valPeaks[6]);
  }
  if(rawPeaks[6] < valPeaks[6]) {
    valPeaks[6] *= attack;
    M207.gain(0, valPeaks[6]);
  }
  if(P108.available()) {
    rawPeaks[7] = P108.read();
  }
  if(rawPeaks[7] > valPeaks[7]) {
    valPeaks[7] /= attack;
    M208.gain(0, valPeaks[7]);
  }
  if(rawPeaks[7] < valPeaks[7]) {
    valPeaks[7] *= attack;
    M208.gain(0, valPeaks[7]);
  }
  if(P109.available()) {
    rawPeaks[8] = P109.read();
  }
  if(rawPeaks[8] > valPeaks[8]) {
    valPeaks[8] /= attack;
    M209.gain(0, valPeaks[8]);
  }
  if(rawPeaks[8] < valPeaks[8]) {
    valPeaks[8] *= attack;
    M209.gain(0, valPeaks[8]);
  }
  if(P110.available()) {
    rawPeaks[9] = P110.read();
  }
  if(rawPeaks[9] > valPeaks[9]) {
    valPeaks[9] /= attack;
    M210.gain(0, valPeaks[9]);
  }
  if(rawPeaks[9] < valPeaks[9]) {
    valPeaks[9] *= attack;
    M210.gain(0, valPeaks[9]);
  }
  if(P111.available()) {
    rawPeaks[10] = P111.read();
  }
  if(rawPeaks[10] > valPeaks[10]) {
    valPeaks[10] /= attack;
    M211.gain(0, valPeaks[10]);
  }
  if(rawPeaks[10] < valPeaks[10]) {
    valPeaks[10] *= attack;
    M211.gain(0, valPeaks[10]);
  }
  if(P112.available()) {
    rawPeaks[11] = P112.read();
  }
  if(rawPeaks[11] > valPeaks[11]) {
    valPeaks[11] /= attack;
    M212.gain(0, valPeaks[11]);
  }
  if(rawPeaks[11] < valPeaks[11]) {
    valPeaks[11] *= attack;
    M212.gain(0, valPeaks[11]);
  }
  if(P113.available()) {
    rawPeaks[12] = P113.read();
  }
  if(rawPeaks[12] > valPeaks[12]) {
    valPeaks[12] /= attack;
    M213.gain(0, valPeaks[12]);
  }
  if(rawPeaks[12] < valPeaks[12]) {
    valPeaks[12] *= attack;
    M213.gain(0, valPeaks[12]);
  }
  if(P114.available()) {
    rawPeaks[13] = P114.read();
  }
  if(rawPeaks[13] > valPeaks[13]) {
    valPeaks[13] /= attack;
    M214.gain(0, valPeaks[13]);
  }
  if(rawPeaks[13] < valPeaks[13]) {
    valPeaks[13] *= attack;
    M214.gain(0, valPeaks[13]);
  }
  if(P115.available()) {
    rawPeaks[14] = P115.read();
  }
  if(rawPeaks[14] > valPeaks[14]) {
    valPeaks[14] /= attack;
    M215.gain(0, valPeaks[14]);
  }
  if(rawPeaks[14] < valPeaks[14]) {
    valPeaks[14] *= attack;
    M215.gain(0, valPeaks[14]);
  }
  if(P116.available()) {
    rawPeaks[15] = P116.read();
  }
  if(rawPeaks[15] > valPeaks[15]) {
    valPeaks[15] /= attack;
    M216.gain(0, valPeaks[15]);
  }
  if(rawPeaks[15] < valPeaks[15]) {
    valPeaks[15] *= attack;
    M216.gain(0, valPeaks[15]);
  }
  if(P117.available()) {
    rawPeaks[16] = P117.read();
  }
  if(rawPeaks[16] > valPeaks[16]) {
    valPeaks[16] /= attack;
    M217.gain(0, valPeaks[16]);
  }
  if(rawPeaks[16] < valPeaks[16]) {
    valPeaks[16] *= attack;
    M217.gain(0, valPeaks[16]);
  }
  if(P118.available()) {
    rawPeaks[17] = P118.read();
  }
  if(rawPeaks[17] > valPeaks[17]) {
    valPeaks[17] /= attack;
    M218.gain(0, valPeaks[17]);
  }
  if(rawPeaks[17] < valPeaks[17]) {
    valPeaks[17] *= attack;
    M218.gain(0, valPeaks[17]);
  }
  if(P119.available()) {
    rawPeaks[18] = P119.read();
  }
  if(rawPeaks[18] > valPeaks[18]) {
    valPeaks[18] /= attack;
    M219.gain(0, valPeaks[18]);
    M220.gain(0, valPeaks[18]);
  }
  if(rawPeaks[18] < valPeaks[18]) {
    valPeaks[18] *= attack;
    M219.gain(0, valPeaks[18]);
    M220.gain(0, valPeaks[18]);
  }
}
void vocoderSibilance(float value) {
  noiseGen.amplitude(value);
}
void vocoderVoiceInputGain(float value) {
  M001.gain(0, value);
}
void vocoderInstrInputGain(float value) {
  M002.gain(0, value);
}
void vocoderVcdr2VoiceOutGain(float value) {
  M010.gain(0, value);
  M010.gain(1, value);
}
void vocoderVoiceBypssOutGain(float value) {
  M010.gain(2, value);
}
void vocoderVcdr2InstrOutGain(float value) {
  M011.gain(0, value);
  M011.gain(1, value);
}
void vocoderInstrBypssOutGain(float value) {
  M011.gain(2, value);
}
#endif
 
View attachment MAIN.zip

Compiles fine, i dropped loop() and setup() functions in a SETUP_LOOP tab as an example

you can make your tabs naming convection as you wish and move the functions you want to there, to organize things

the MAIN tab (or whatever you want to rename it to) can contain your includes and global vars, the rest can be put in other tabs, then once its saved, you can use notepad++ on them after

tabs are created, renamed, deleted right under the serial monitor button. be aware that deleting the tab doesnt only remove it from the sketch, but also deletes the file itself.
 
Last edited:
I dislike the Arduino IDE and use sublimetext, and a typical setup for me is:
Code:
#include "DmtrPixelnode.h"

void setup() {
	setupPixelnode();
}

void loop() {
	loopPixelnode();
}

and all the libraries, functions and definitions goes into another .h file (syntax coloring for editor) or a bunch of .h files
this .h file goes in the same sketch folder, so it opens as a new tab, and I use "external editor" in preferences so I can keep identation as I like (tabs instead of spaces)
 
Status
Not open for further replies.
Back
Top