Code:
// WAV files converted to code by wav2sketch
#include "AudioSampleSnare.h" // http://www.freesound.org/people/KEVOY/sounds/82583/
#include "AudioSampleTomtom.h" // http://www.freesound.org/people/zgump/sounds/86334/
#include "AudioSampleHihat.h" // http://www.freesound.org/people/mhc/sounds/102790/
#include "AudioSampleKick.h" // http://www.freesound.org/people/DWSD/sounds/171104/
#include "AudioSampleGong.h" // http://www.freesound.org/people/juskiddink/sounds/86773/
#include "AudioSampleC4.h" // http://www.freesound.org/people/kiddpark/sounds/201159/
#include "AudioSampleD4.h"
#include "AudioSampleE4.h"
#include "AudioSampleF4.h"
#include "AudioSampleG4.h"
#include "AudioSampleA4.h"
#include "AudioSampleB4.h"
#include "AudioSampleC5.h"
/////LED//////
#include <FastLED.h>
#define LED_PIN 12
#define NUM_LEDS 4
CRGB leds[NUM_LEDS];
///////////////////
#include <Bounce.h>
#include "pitches.h"
const unsigned int* notes[] = {
AudioSampleC4, AudioSampleD4, AudioSampleE4, AudioSampleF4, AudioSampleG4, AudioSampleA4, AudioSampleB4, AudioSampleC5
};
const unsigned int* melody1[64] = {};
const unsigned int* melody2[64] = {};
const unsigned int* melody3[64] = {};
const unsigned int* melody4[64] = {};
const unsigned int* melody1Play[64] = {};
const unsigned int* melody2Play[64] = {};
const unsigned int* melody3Play[64] = {};
const unsigned int* melody4Play[64] = {};
bool arrToggle12 = false;
bool arrToggle34 = false;
bool channelToggle = false;
int play1MemMode = 0;
int play2MemMode = 0;
///////CAP TOUCH///////////////////
#include <Wire.h>
#include "Adafruit_MPR121.h"
#ifndef _BV
#define _BV(bit) (1 << (bit))
#endif
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioPlayMemory playMem7; //xy=81,253
AudioPlayMemory playMem3; //xy=82,88
AudioPlayMemory playMem4; //xy=82,121
AudioPlayMemory playMem8; //xy=82,293
AudioPlayMemory playMem5; //xy=83,166
AudioPlayMemory playMem6; //xy=83,213
AudioPlayMemory playMem2; //xy=84,53
AudioPlayMemory playMem1; //xy=85,20
AudioPlayMemory playMem9; //xy=85,349
AudioPlayMemory playMem12; //xy=85,464
AudioPlayMemory playMem11; //xy=86,424
AudioPlayMemory playMem10; //xy=89,381
AudioPlayMemory playMem16; //xy=106,644
AudioPlayMemory playMem13; //xy=108,535
AudioPlayMemory playMem14; //xy=109,568
AudioPlayMemory playMem15; //xy=109,611
AudioMixer4 mixer5; //xy=347,589
AudioMixer4 mixer4; //xy=348,474
AudioMixer4 mixer2; //xy=355,322
AudioMixer4 mixer1; //xy=356,207
AudioMixer4 mixer3; //xy=568,260
AudioOutputI2S i2s1; //xy=834,218
AudioConnection patchCord1(playMem7, 0, mixer2, 2);
AudioConnection patchCord2(playMem3, 0, mixer1, 2);
AudioConnection patchCord3(playMem4, 0, mixer1, 3);
AudioConnection patchCord4(playMem8, 0, mixer2, 3);
AudioConnection patchCord5(playMem5, 0, mixer2, 0);
AudioConnection patchCord6(playMem6, 0, mixer2, 1);
AudioConnection patchCord7(playMem2, 0, mixer1, 1);
AudioConnection patchCord8(playMem1, 0, mixer1, 0);
AudioConnection patchCord9(playMem9, 0, mixer4, 0);
AudioConnection patchCord10(playMem12, 0, mixer4, 3);
AudioConnection patchCord11(playMem11, 0, mixer4, 2);
AudioConnection patchCord12(playMem10, 0, mixer4, 1);
AudioConnection patchCord13(playMem16, 0, mixer5, 3);
AudioConnection patchCord14(playMem13, 0, mixer5, 0);
AudioConnection patchCord15(playMem14, 0, mixer5, 1);
AudioConnection patchCord16(playMem15, 0, mixer5, 2);
AudioConnection patchCord17(mixer5, 0, mixer3, 3);
AudioConnection patchCord18(mixer4, 0, mixer3, 2);
AudioConnection patchCord19(mixer2, 0, mixer3, 1);
AudioConnection patchCord20(mixer1, 0, mixer3, 0);
AudioConnection patchCord21(mixer3, 0, i2s1, 0);
AudioConnection patchCord22(mixer3, 0, i2s1, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=643,692
// GUItool: end automatically generated code
//CAP TOUCH Vars//
Adafruit_MPR121 cap = Adafruit_MPR121();
uint16_t lasttouched = 0;
uint16_t currtouched = 0;
// Bounce objects to read pushbuttons
Bounce rec1Button = Bounce(0, 15);
Bounce play1Button = Bounce(1, 15);
Bounce rec2Button = Bounce(2, 15);
Bounce play2Button = Bounce(3, 15);
//Bounce button5 = Bounce(4, 15);
//Bounce button6 = Bounce(5, 15);
//Bounce button7 = Bounce(6, 15);
//Bounce button8 = Bounce(8, 15);
//TEMPO Vars//
elapsedMillis blinkTime;
elapsedMillis loopTime;
int tempoPin = A0;
int millisBPM = 0;
int bars;
int bpm;
int tempoCounter = 0;
int barsCounter = 0;
bool didPlay = false;
bool didBarPlay = false;
///////////////////
void setup() {
Serial.begin(9600);
//int timing[];
////////LED Vars//////
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
//////////////////
while (!Serial) { // needed to keep leonardo/micro from starting too fast!
delay(10);
}
// Serial.println("Adafruit MPR121 Capacitive Touch sensor test");
// Default address is 0x5A, if tied to 3.3V its 0x5B
// If tied to SDA its 0x5C and if SCL then 0x5D
if (!cap.begin(0x5A)) {
// Serial.println("MPR121 not found, check wiring?");
while (1);
}
// Serial.println("MPR121 found!");
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
// pinMode(4, INPUT_PULLUP);
// pinMode(5, INPUT_PULLUP);
// pinMode(6, INPUT_PULLUP);
// pinMode(8, INPUT_PULLUP);
AudioMemory(10);
sgtl5000_1.enable();
sgtl5000_1.volume(0.5);
///////////MIXERS IN///////////////////
mixer1.gain(0, 0.4);
mixer1.gain(1, 0.4);
mixer1.gain(2, 0.4);
mixer1.gain(3, 0.4);
mixer2.gain(0, 0.4);
mixer2.gain(1, 0.4);
mixer2.gain(2, 0.4);
mixer2.gain(3, 0.4);
mixer4.gain(0, 0.4);
mixer4.gain(1, 0.4);
mixer4.gain(2, 0.4);
mixer4.gain(3, 0.4);
mixer5.gain(0, 0.4);
mixer5.gain(1, 0.4);
mixer5.gain(2, 0.4);
mixer5.gain(3, 0.4);
////////////////MIXER OUT////////////
mixer3.gain(0, 0.4);
mixer3.gain(1, 0.4);
mixer3.gain(2, 0.4);
mixer3.gain(3, 0.4);
// //Envelope///
// envelope1.attack(0.3);
// envelope1.hold(0);
// envelope1.decay(0.1);
// envelope1.sustain(0.3);
// envelope1.release(1000);
//
// envelope2.attack(0.3);
// envelope2.hold(0);
// envelope2.decay(0.1);
// envelope2.sustain(0.3);
// envelope2.release(1000);
}
bool preCount = false;
bool isRec1 = false;
bool isPlay1 = false;
bool isRec2 = false;
bool isPlay2 = false;
bool rec1Mode = false;//////TOGGLE REC1 AND STOP
bool rec2Mode = false;//////TOGGLE REC2 AND STOP
bool play1Mode = false;//////TOGGLE PLAY1 AND STOP
bool play2Mode = false;//////TOGGLE PLAY2 AND STOP
void loop() {
////////////MAKE LEDS BLACK////////////
if (!isPlay1 && !isRec1 && !isPlay2 && !isRec2){
for (int i = 0; i < NUM_LEDS; i++){
leds[i] = CRGB::Black;
FastLED.show();
}
}
/////////////////BPM///////////////////////
bpm = map(analogRead(tempoPin),0,1023,60,140);
millisBPM = 60000/bpm;
bars = millisBPM/4;
///////////BUTTON CHECK////////////
rec1Button.update();
if (rec1Button.fallingEdge()){
if (rec1Mode == false){
preCount = true;
barsCounter = 0;
///////////////CLEAR THE RECORD AND PLAY ARRAYS//////////////////
memset(melody1, 0, sizeof(melody1));
memset(melody2, 0, sizeof(melody2));
memset(melody1Play, 0, sizeof(melody1Play));
memset(melody2Play, 0, sizeof(melody2Play));
Serial.println("record12");
////////////////////////////////////////////
arrToggle12 = false;
isRec1 = true;
//////STOP IF PLAY 1 IS PLAYING//////////////
isPlay1 = false;
///////////////
isRec2 = false;
} else {
barsCounter = 0;
// envelope1.noteOff();
for (int i = 0; i < 64; i++){
melody1Play[i] = melody1[i];
melody2Play[i] = melody2[i];
}
isRec1 = false;
channelToggle = false;
Serial.println("stopRecording1");
}
rec1Mode = !rec1Mode;
}
play1Button.update();
if (play1Button.fallingEdge()){
if (!play1Mode){
////////DONT REC WHILE PLAY/////////////
isRec1 = false;
///////////////////////
barsCounter = 0;
isPlay1 = true;
Serial.println("play1");
} else {
barsCounter = 0;
Serial.println("stopPlaying1");
isPlay1 = false;
for (int i = 0; i < NUM_LEDS; i++){
leds[i] = CRGB::Black;
FastLED.show();
}
}
play1Mode = !play1Mode;
}
rec2Button.update();
if (rec2Button.fallingEdge()){
if (rec2Mode == false){
preCount = true;
barsCounter = 0;
///////////////CLEAR THE RECORD AND PLAY ARRAYS//////////////////
memset(melody3, 0, sizeof(melody3));
memset(melody4, 0, sizeof(melody4));
memset(melody3Play, 0, sizeof(melody3Play));
memset(melody4Play, 0, sizeof(melody4Play));
Serial.println("record34");
///////////////////////////////////////
arrToggle34 = false;
//////STOP IF PLAY 1 IS PLAYING//////////////
isPlay2 = false;
///////////////
isRec2 = true;
isRec1 = false;
} else {
barsCounter = 0;
// envelope2.noteOff();
for (int i = 0; i < 64; i++){
melody3Play[i] = melody3[i];
melody4Play[i] = melody4[i];
}
isRec2 = false;
channelToggle = true;
Serial.println("stopRecording2");
}
rec2Mode = !rec2Mode;
}
play2Button.update();
if (play2Button.fallingEdge()){
if (!play2Mode){
////////DONT REC WHILE PLAY/////////////
isRec2 = false;
///////////////////////
barsCounter = 0;
isPlay2 = true;
Serial.println("play2");
} else {
barsCounter = 0;
Serial.println("stopPlaying2");
isPlay2 = false;
for (int i = 0; i < NUM_LEDS; i++){
leds[i] = CRGB::Black;
FastLED.show();
}
}
play2Mode = !play2Mode;
}
//recButton.update();
//if (recButton.fallingEdge()){
// preCount = true;
// barsCounter = 0;
// memset(melody1, 0, sizeof(melody1));
// memset(melody2, 0, sizeof(melody2));
// Serial.println("record");
// arrToggle = false;
//}
//playButton.update();
//if (playButton.fallingEdge()){
// barsCounter = 0;
// isPlay = true;
// Serial.println("play");
//}
//stopButton.update();
//if (stopButton.fallingEdge()){
// isPlay = false;
// isRec = false;
// tempoCounter = 0;
// barsCounter = 0;
// envelope1.noteOff();
// for (int i = 0; i < 64; i++){
// melody1Play[i] = melody1[i];
// melody2Play[i] = melody2[i];
// }
// Serial.println("stop");
//}
//channelButton.update();
//if(channelButton.fallingEdge()){
// channelToggle = !channelToggle;
// }
////////////PRECOUNT/////////////////////
if (preCount){
playMem1.play(AudioSampleTomtom);
leds[0] = CRGB::Red;
FastLED.show();
delay(millisBPM);
playMem1.play(AudioSampleSnare);
leds[0] = CRGB::Green;
FastLED.show();
delay(millisBPM);
playMem1.play(AudioSampleSnare);
leds[0] = CRGB::Green;
FastLED.show();
delay(millisBPM);
playMem1.play(AudioSampleSnare);
leds[0] = CRGB::Green;
FastLED.show();
delay(millisBPM);
playMem1.play(AudioSampleTomtom);
leds[0] = CRGB::Red;
FastLED.show();
delay(millisBPM);
playMem1.play(AudioSampleSnare);
leds[0] = CRGB::Green;
FastLED.show();
delay(millisBPM);
playMem1.play(AudioSampleSnare);
leds[0] = CRGB::Green;
FastLED.show();
delay(millisBPM);
playMem1.play(AudioSampleSnare);
leds[0] = CRGB::Green;
FastLED.show();
delay(millisBPM);
}
preCount = false;
///////////////////SEQUENCE////////////////////
if(isRec1 || isPlay1 || isRec2 || isPlay2){
//////////////////Couner of bars///////////
if(blinkTime > millisBPM/4 ){
barsCounter ++;
didPlay = false;
didBarPlay = false;
blinkTime = 0;
// envelope1.noteOff();
Serial.println(barsCounter);
}
///////////////////CLICK////////////////////
if (barsCounter == 4 && !didPlay){
leds[3] = CRGB::Black;
// Serial.println('!');
// Serial.println(bpm);
// playMem1.play(AudioSampleTomtom);
didPlay = true;
leds[0] = CRGB::Red;
FastLED.show();
} else if (barsCounter == 8 && !didPlay){
leds[0] = CRGB::Black;
// Serial.println('/');
// playMem1.play(AudioSampleSnare);
didPlay = true;
leds[1] = CRGB::Green;
FastLED.show();
} else if (barsCounter == 12 && !didPlay){
leds[1] = CRGB::Black;
// Serial.println('/');
// playMem1.play(AudioSampleSnare);
didPlay = true;
leds[2] = CRGB::Green;
FastLED.show();
} else if (barsCounter == 16 && !didPlay){
leds[2] = CRGB::Black;
// Serial.println('/');
// playMem1.play(AudioSampleSnare);
didPlay = true;
leds[3] = CRGB::Green;
FastLED.show();
} else if(barsCounter == 20 && !didPlay){
leds[3] = CRGB::Black;
// Serial.println('!');
// Serial.println(bpm);
// playMem1.play(AudioSampleTomtom);
didPlay = true;
leds[0] = CRGB::Red;
FastLED.show();
} else if (barsCounter == 24 && !didPlay){
leds[0] = CRGB::Black;
// Serial.println('/');
// playMem1.play(AudioSampleSnare);
didPlay = true;
leds[1] = CRGB::Green;
FastLED.show();
} else if (barsCounter == 28 && !didPlay){
leds[1] = CRGB::Black;
// Serial.println('/');
// playMem1.play(AudioSampleSnare);
didPlay = true;
leds[2] = CRGB::Green;
FastLED.show();
} else if (barsCounter == 32 && !didPlay){
leds[2] = CRGB::Black;
// Serial.println('/');
// playMem1.play(AudioSampleSnare);
didPlay = true;
leds[3] = CRGB::Green;
FastLED.show();
}else if(barsCounter == 36 && !didPlay){
leds[3] = CRGB::Black;
// Serial.println('!');
// Serial.println(bpm);
// playMem1.play(AudioSampleTomtom);
didPlay = true;
leds[0] = CRGB::Red;
FastLED.show();
} else if (barsCounter == 40 && !didPlay){
leds[0] = CRGB::Black;
// Serial.println('/');
// playMem1.play(AudioSampleSnare);
didPlay = true;
leds[1] = CRGB::Green;
FastLED.show();
} else if (barsCounter == 44 && !didPlay){
leds[1] = CRGB::Black;
// Serial.println('/');
// playMem1.play(AudioSampleSnare);
didPlay = true;
leds[2] = CRGB::Green;
FastLED.show();
} else if (barsCounter == 48 && !didPlay){
leds[2] = CRGB::Black;
// Serial.println('/');
// playMem1.play(AudioSampleSnare);
didPlay = true;
leds[3] = CRGB::Green;
FastLED.show();
}else if(barsCounter == 52 && !didPlay){
leds[3] = CRGB::Black;
// Serial.println('!');
// Serial.println(bpm);
// playMem1.play(AudioSampleTomtom);
didPlay = true;
leds[0] = CRGB::Red;
FastLED.show();
} else if (barsCounter == 56 && !didPlay){
leds[0] = CRGB::Black;
// Serial.println('/');
// playMem1.play(AudioSampleSnare);
didPlay = true;
leds[1] = CRGB::Green;
FastLED.show();
} else if (barsCounter == 60 && !didPlay){
leds[1] = CRGB::Black;
// Serial.println('/');
// playMem1.play(AudioSampleSnare);
didPlay = true;
leds[2] = CRGB::Green;
FastLED.show();
} else if (barsCounter == 64 && !didPlay){
leds[2] = CRGB::Black;
// Serial.println('/');
// playMem1.play(AudioSampleSnare);
didPlay = true;
leds[3] = CRGB::Green;
FastLED.show();
}
}
///////////////////PLAY THE LOOP//////////////////
if (isPlay1){
if(didBarPlay == false){
if(arrToggle12 == true){
if(melody1Play[barsCounter]!= NULL){
if (play1MemMode == 0 && !playMem1.isPlaying()){
playMem1.play(melody1Play[barsCounter]);
} else if (play1MemMode == 1 && !playMem2.isPlaying()){
playMem2.play(melody1Play[barsCounter]);
} else if (play1MemMode == 2 && !playMem3.isPlaying()){
playMem3.play(melody1Play[barsCounter]);
} else if (play1MemMode == 3 && !playMem4.isPlaying()){
playMem4.play(melody1Play[barsCounter]);
} else if (play1MemMode == 4 && !playMem5.isPlaying()){
playMem5.play(melody1Play[barsCounter]);
} else if (play1MemMode == 5 && !playMem6.isPlaying()){
playMem6.play(melody1Play[barsCounter]);
} else if (play1MemMode == 6 && !playMem7.isPlaying()){
playMem7.play(melody1Play[barsCounter]);
}else if (play1MemMode == 7 && !playMem8.isPlaying()){
playMem8.play(melody1Play[barsCounter]);
}
play1MemMode ++;
}
}else if(arrToggle12 == false){
if(melody2Play[barsCounter]!= NULL){
if (play1MemMode == 0 && !playMem1.isPlaying()){
playMem1.play(melody2Play[barsCounter]);
} else if (play1MemMode == 1 && !playMem2.isPlaying()){
playMem2.play(melody2Play[barsCounter]);
} else if (play1MemMode == 2 && !playMem3.isPlaying()){
playMem3.play(melody2Play[barsCounter]);
} else if (play1MemMode == 3 && !playMem4.isPlaying()){
playMem4.play(melody2Play[barsCounter]);
} else if (play1MemMode == 4 && !playMem5.isPlaying()){
playMem5.play(melody2Play[barsCounter]);
} else if (play1MemMode == 5 && !playMem6.isPlaying()){
playMem6.play(melody2Play[barsCounter]);
} else if (play1MemMode == 6 && !playMem7.isPlaying()){
playMem7.play(melody2Play[barsCounter]);
}else if (play1MemMode == 7 && !playMem8.isPlaying()){
playMem8.play(melody2Play[barsCounter]);
}
play1MemMode ++;
}
}
}
}
if (isPlay2){
if(didBarPlay == false){
if(arrToggle34 == true){
if(melody3Play[barsCounter]!= NULL){
if (play2MemMode == 0 && !playMem9.isPlaying()){
playMem9.play(melody3Play[barsCounter]);
} else if (play2MemMode == 1 && !playMem10.isPlaying()){
playMem10.play(melody3Play[barsCounter]);
} else if (play2MemMode == 2 && !playMem11.isPlaying()){
playMem11.play(melody3Play[barsCounter]);
} else if (play2MemMode == 3 && !playMem12.isPlaying()){
playMem12.play(melody3Play[barsCounter]);
} else if (play2MemMode == 4 && !playMem13.isPlaying()){
playMem13.play(melody3Play[barsCounter]);
} else if (play2MemMode == 5 && !playMem14.isPlaying()){
playMem14.play(melody3Play[barsCounter]);
} else if (play2MemMode == 6 && !playMem15.isPlaying()){
playMem15.play(melody3Play[barsCounter]);
}else if (play2MemMode == 7 && !playMem16.isPlaying()){
playMem16.play(melody3Play[barsCounter]);
}
play2MemMode ++;
}
}else if(arrToggle34 == false){
if(melody4Play[barsCounter]!= NULL){
if (play2MemMode == 0 && !playMem9.isPlaying()){
playMem9.play(melody4Play[barsCounter]);
} else if (play2MemMode == 1 && !playMem10.isPlaying()){
playMem10.play(melody4Play[barsCounter]);
} else if (play2MemMode == 2 && !playMem11.isPlaying()){
playMem11.play(melody4Play[barsCounter]);
} else if (play2MemMode == 3 && !playMem12.isPlaying()){
playMem12.play(melody4Play[barsCounter]);
} else if (play2MemMode == 4 && !playMem13.isPlaying()){
playMem13.play(melody4Play[barsCounter]);
} else if (play2MemMode == 5 && !playMem14.isPlaying()){
playMem14.play(melody4Play[barsCounter]);
} else if (play2MemMode == 6 && !playMem15.isPlaying()){
playMem15.play(melody4Play[barsCounter]);
}else if (play2MemMode == 7 && !playMem16.isPlaying()){
playMem16.play(melody4Play[barsCounter]);
}
play2MemMode ++;
}
}
}
}
didBarPlay = true;
////////////////Counter reset/////////////////
if (barsCounter >= 64){
barsCounter = 0;
if (isPlay1){
if (arrToggle12){
Serial.println("playing array 1");
// for(int i = 0; i < sizeof(melody1); i++){
// Serial.println(melody1[i]);
//
// }
} else {
Serial.println("playing array 2");
}
}
if (isPlay2){
if (arrToggle34){
Serial.println("playing array 3");
// for(int i = 0; i < sizeof(melody1); i++){
// Serial.println(melody1[i]);
//
// }
} else {
Serial.println("playing array 4");
}
}
if (isRec1){
arrToggle12 = !arrToggle12;
if (arrToggle12){
memset(melody2, 0, sizeof(melody2));
}else {
memset(melody1, 0, sizeof(melody1));
}
}
if (isRec2){
arrToggle34 = !arrToggle34;
if (arrToggle34){
memset(melody4, 0, sizeof(melody4));
}else {
memset(melody3, 0, sizeof(melody3));
}
}
}
//////////////KEYBOARD////////////////////
currtouched = cap.touched();
for (uint8_t i=0; i<12; i++) {
//////////////////KEYBOARD PLAY////////////////////////
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
if(isPlay1){
if (play2MemMode == 0 && !playMem9.isPlaying()){
playMem9.play(notes[i]);
} else if (play2MemMode == 1 && !playMem10.isPlaying()){
playMem10.play(notes[i]);
} else if (play2MemMode == 2 && !playMem11.isPlaying()){
playMem11.play(notes[i]);
} else if (play2MemMode == 3 && !playMem12.isPlaying()){
playMem12.play(notes[i]);
} else if (play2MemMode == 4 && !playMem13.isPlaying()){
playMem13.play(notes[i]);
} else if (play2MemMode == 5 && !playMem14.isPlaying()){
playMem14.play(notes[i]);
} else if (play2MemMode == 6 && !playMem15.isPlaying()){
playMem15.play(notes[i]);
}else if (play2MemMode == 7 && !playMem16.isPlaying()){
playMem16.play(notes[i]);
}
play2MemMode ++;
}else if (isPlay2){
if (play1MemMode == 0 && !playMem1.isPlaying()){
playMem1.play(notes[i]);
} else if (play1MemMode == 1 && !playMem2.isPlaying()){
playMem2.play(notes[i]);
} else if (play1MemMode == 2 && !playMem3.isPlaying()){
playMem3.play(notes[i]);
} else if (play1MemMode == 3 && !playMem4.isPlaying()){
playMem4.play(notes[i]);
} else if (play1MemMode == 4 && !playMem5.isPlaying()){
playMem5.play(notes[i]);
} else if (play1MemMode == 5 && !playMem6.isPlaying()){
playMem6.play(notes[i]);
} else if (play1MemMode == 6 && !playMem7.isPlaying()){
playMem7.play(notes[i]);
}else if (play1MemMode == 7 && !playMem8.isPlaying()){
playMem8.play(notes[i]);
}
play1MemMode ++;
}
// if (play1MemMode > 7){
// play1MemMode = 0;
// }
else {
if (play1MemMode == 0 && !playMem1.isPlaying()){
playMem1.play(notes[i]);
} else if (play1MemMode == 1 && !playMem2.isPlaying()){
playMem2.play(notes[i]);
} else if (play1MemMode == 2 && !playMem3.isPlaying()){
playMem3.play(notes[i]);
} else if (play1MemMode == 3 && !playMem4.isPlaying()){
playMem4.play(notes[i]);
} else if (play1MemMode == 4 && !playMem5.isPlaying()){
playMem5.play(notes[i]);
} else if (play1MemMode == 5 && !playMem6.isPlaying()){
playMem6.play(notes[i]);
} else if (play1MemMode == 6 && !playMem7.isPlaying()){
playMem7.play(notes[i]);
}else if (play1MemMode == 7 && !playMem8.isPlaying()){
playMem8.play(notes[i]);
}
play1MemMode ++;
}
////////////////////////KEYBOARD RECORD////////////////////////
if (isRec2){
if (!arrToggle34){
melody3[barsCounter] = notes[i];
}else{
melody4[barsCounter] = notes[i];
}
} else if (isRec1){
if (!arrToggle12){
melody1[barsCounter] = notes[i];
}else{
melody2[barsCounter] = notes[i];
}
}
// if (play1MemMode > 7){
// play1MemMode = 0;
// }
}
////////////////BURNING THE SAMPLES TO THE ARRAYS/////////////////
// if(isRec1){
//
// if((currtouched & _BV(i))){
// if (!arrToggle12){
// melody1[barsCounter] = notes[i];
// }else{
// melody2[barsCounter] = notes[i];
// }
// }
// }
// if (isRec2){
// if((currtouched & _BV(i))){
// if (!arrToggle34){
// melody3[barsCounter] = notes[i];
// }else{
// melody4[barsCounter] = notes[i];
// }
// }
// }
}
if (play1MemMode > 7){
play1MemMode = 0;
}
if (play2MemMode > 7){
play2MemMode = 0;
}
// reset our state
lasttouched = currtouched;
}