i can't ad more variable despite using 60% of the RAM, it compile but the prg is stuck at the beginning of the loop()
i use 1.8.19 arduino IDE
So i set show verbose et compile "fastest pure code" then it didn't compile and had theses error messages :
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\Quantizer.cpp:79:1: error: insn does not satisfy its constraints:
}
^
(insn 23 22 152 2 (set (reg:SF 31 s15 [121])
(const_double:SF 4.41e+4 [0x0.ac44p+16])) C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\Quantizer.cpp:38 621 {*thumb2_movsf_vfp}
(expr_list:REG_EQUIV (const_double:SF 4.41e+4 [0x0.ac44p+16])
(nil)))
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\Quantizer.cpp:79:1: internal compiler error: in extract_constrain_insn, at recog.c:2246
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O3 -mpure-code -D__PURE_CODE__ -g -Wall -ffunction-sections -fdata-sections -nostdlib -mno-unaligned-access -MMD -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK66FX1M0__ -DTEENSYDUINO=157 -DARDUINO=10819 -DARDUINO_TEENSY36 -DF_CPU=180000000 -DUSB_MIDI_AUDIO_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Users\\DELLLA~1\\AppData\\Local\\Temp\\arduino_build_674652/pch" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\cores\\teensy3" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\Audio" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SPI" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SD\\src" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SdFat\\src" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SerialFlash" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\Wire" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\Audio\\utility" "C:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\Audio\\analyze_print.cpp" -o "C:\\Users\\DELLLA~1\\AppData\\Local\\Temp\\arduino_build_674652\\libraries\\Audio\\analyze_print.cpp.o"
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\Resampler.cpp: In member function 'void Resampler::configure(float, float)':
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\Resampler.cpp:228:1: error: insn does not satisfy its constraints:
}
^
(insn 1077 618 615 34 (set (reg:SI 31 s15 [orig:211 D.16613 ] [211])
(mem/c:SI (plus:SI (reg/f:SI 13 sp)
(const_int 56 [0x38])) [11 %sfp+-8 S4 A32])) C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\Resampler.cpp:123 615 {*thumb2_movsi_vfp}
(nil))
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\Resampler.cpp:228:1: internal compiler error: in extract_constrain_insn, at recog.c:2246
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Multiple libraries were found for "SD.h"
Used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD
Not used: C:\Program Files (x86)\Arduino\libraries\SD
Using library Audio at version 1.3 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio
Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI
Using library SD at version 2.0.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD
Using library SdFat at version 2.1.2 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat
Using library SerialFlash at version 0.5 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SerialFlash
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Wire
Error compiling for board Teensy 3.6.
my "code"
i use 1.8.19 arduino IDE
So i set show verbose et compile "fastest pure code" then it didn't compile and had theses error messages :
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\Quantizer.cpp:79:1: error: insn does not satisfy its constraints:
}
^
(insn 23 22 152 2 (set (reg:SF 31 s15 [121])
(const_double:SF 4.41e+4 [0x0.ac44p+16])) C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\Quantizer.cpp:38 621 {*thumb2_movsf_vfp}
(expr_list:REG_EQUIV (const_double:SF 4.41e+4 [0x0.ac44p+16])
(nil)))
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\Quantizer.cpp:79:1: internal compiler error: in extract_constrain_insn, at recog.c:2246
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
"C:\\Program Files (x86)\\Arduino\\hardware\\teensy/../tools/arm/bin/arm-none-eabi-g++" -c -O3 -mpure-code -D__PURE_CODE__ -g -Wall -ffunction-sections -fdata-sections -nostdlib -mno-unaligned-access -MMD -fno-exceptions -fpermissive -felide-constructors -std=gnu++14 -Wno-error=narrowing -fno-rtti -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant -D__MK66FX1M0__ -DTEENSYDUINO=157 -DARDUINO=10819 -DARDUINO_TEENSY36 -DF_CPU=180000000 -DUSB_MIDI_AUDIO_SERIAL -DLAYOUT_US_ENGLISH "-IC:\\Users\\DELLLA~1\\AppData\\Local\\Temp\\arduino_build_674652/pch" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\cores\\teensy3" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\Audio" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SPI" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SD\\src" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SdFat\\src" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\SerialFlash" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\Wire" "-IC:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\Audio\\utility" "C:\\Program Files (x86)\\Arduino\\hardware\\teensy\\avr\\libraries\\Audio\\analyze_print.cpp" -o "C:\\Users\\DELLLA~1\\AppData\\Local\\Temp\\arduino_build_674652\\libraries\\Audio\\analyze_print.cpp.o"
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\Resampler.cpp: In member function 'void Resampler::configure(float, float)':
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\Resampler.cpp:228:1: error: insn does not satisfy its constraints:
}
^
(insn 1077 618 615 34 (set (reg:SI 31 s15 [orig:211 D.16613 ] [211])
(mem/c:SI (plus:SI (reg/f:SI 13 sp)
(const_int 56 [0x38])) [11 %sfp+-8 S4 A32])) C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\Resampler.cpp:123 615 {*thumb2_movsi_vfp}
(nil))
C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio\Resampler.cpp:228:1: internal compiler error: in extract_constrain_insn, at recog.c:2246
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
Multiple libraries were found for "SD.h"
Used: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD
Not used: C:\Program Files (x86)\Arduino\libraries\SD
Using library Audio at version 1.3 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Audio
Using library SPI at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SPI
Using library SD at version 2.0.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SD
Using library SdFat at version 2.1.2 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SdFat
Using library SerialFlash at version 0.5 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\SerialFlash
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\teensy\avr\libraries\Wire
Error compiling for board Teensy 3.6.
my "code"
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include <Arduino.h>
int seti = 2;
int setj = 1;
int the8 = 0;
int cntArpBass = 0;
int countBass = 0;
int trigBass =0;
int tuneB = 0;
int filtB = 0;
int msb = 0;
int lsb = 0;
bool isPlay = true;
int tap = 0;
int setk = 0;
int exfader8 = 0;
int flagRec = 3;
long freqLive;
int timeSeq =777;
int freqClock1 = 777;
int time1T;
float frqBpm4;
String songName = "song-one.mdx";
int songNum = 0;
const int chipSelect = BUILTIN_SDCARD;
long timeKick;
short armRec = 0;
int flagKick = 0;
int exBeatfader =0;
int faderBeat =0;
int armDrum[12];
int chr[]={4,7,9,14 };
int chrb[]={2,4,7,9,14,17 };
//
int chord[2][6] ={ {0,5,9,17,22, 27} , {0,7,12,16,21,26} };
//float arrDist[9] ={-1 ,-0.89,-0.78,-0.54,0,0.49,0.77,0.89,1};
float arrDist[9] ={-1 ,-0.99,-0.98,-0.94,0,0.94,0.98,0.99,1};
int theSet []={127,49,81,127,127,119,18,9,49,21,127,48,7,62,36,30,127,90,0,2,107,104,121,10,58,0,47,27,94,87,60,97,67,59,7,90,64,1,49,16,29,28,27,26,25,24,23,22,30,29,28,27,26,25,24,23,31,30,29,28,27,26,25,24,110,84,14,60,74,78,127,72,9,17,11,80,21,5,72,16,47,126,29,61,51,10,20,19,122,127,0,2,82,127,9,81,28,16,26,25,24,23,22,89,29,28,27,26,25,24,23,22,30,29,28,27,26,25,24,23,31,30,29,28,27,26,25,24,18,78,75,50,122,123,18,17,25,30,21,30,21,20,19,18,26,25,24,23,22,21,20,19,111,26,18,24,23,22,21,20,28,27,26,25,24,23,22,21,29,28,27,26,25,24,23,22,30,29,28,27,26,25,24,23,31,30,29,28,27,26,25,24,21,23,22,26,5,19,18,17,30,24,23,41,21,20,19,18,26,25,24,23,22,21,20,19,27,26,100,111,23,22,21,20,28,27,26,25,24,23,22,21,29,28,27,26,25,24,23,22,30,29,28,27,26,25,24,23,31,30,29,28,27,26,25,24,24,23,22,21,127,19,18,17,25,24,23,22,21,20,19,18,26,25,24,23,22,21,20,19,27,26,25,24,23,22,21,20,28,27,26,25,24,23,22,21,29,28,27,26,25,24,23,22,30,29,28,27,26,25,24,23,31,30,29,28,27,26,25,24,24,23,118,21,20,95,18,17,25,24,23,22,21,20,19,18,26,25,24,23,22,21,20,19,27,26,25,24,23,22,21,20,28,27,26,25,24,23,22,21,29,28,27,26,25,24,23,22,30,29,28,27,26,25,24,23,31,30,29,28,27,26,25,24,24,23,22,21,20,19,18,17,25,24,23,22,21,20,127,18,26,25,24,23,22,21,20,19,27,26,25,24,23,22,32,20,5,18,26,25,24,23,22,21,29,28,27,26,25,24,23,22,30,29,28,27,26,25,24,23,31,30,29,28,27,26,25,24,24,23,22,21,20,19,18,17,25,24,23,22,21,20,19,19,26,25,24,23,22,21,20,19,27,26,25,24,23,22,21,127,94,27,26,25,24,111,22,80,29,28,27,26,25,24,23,22,30,29,28,27,26,25,24,23,31,30,29,28,27,26,25,24};
int delta8 = 0;
int dirU = 1;
long cntSnare = 0;
long cntClap = 0;
bool onSnare = false;
bool onClap = false;
int startCC;
int startDir;
float startVelo = 127;
int exDeltaG = 0;
float veloGuit = 0.30;
int deltaTG = 0;
int uOn = 0;
int startUltra = 0;
byte lastCC = 0;
int okChord[12];
int r[6] = {2,1 , 0, 0, 44 , 90};
int g[6] = {0, 0, 30, 60, 80 , 80 };
int b[6] = {8, 127,30, 0, 0 , 80};
const float tune[128] =
{
8.1758, 8.6620, 9.1770, 9.7227, 10.3009, 10.9134, 11.5623, 12.2499,
12.9783, 13.7500, 14.5676, 15.4339, 16.3516, 17.3239, 18.3540, 19.4454,
20.6017, 21.8268, 23.1247, 24.4997, 25.9565, 27.5000, 29.1352, 30.8677,
32.7032, 34.6478, 36.7081, 38.8909, 41.2034, 43.6535, 46.2493, 48.9994,
51.9131, 55.0000, 58.2705, 61.7354, 65.4064, 69.2957, 73.4162, 77.7817,
82.4069, 87.3071, 92.4986, 97.9989, 103.8262, 110.0000, 116.5409, 123.4708,
130.8128, 138.5913, 146.8324, 155.5635, 164.8138, 174.6141, 184.9972, 195.9977,
207.6523, 220.0000, 233.0819, 246.9417, 261.6256, 277.1826, 293.6648, 311.1270,
329.6276, 349.2282, 369.9944, 391.9954, 415.3047, 440.0000, 466.1638, 493.8833,
523.2511, 554.3653, 587.3295, 622.2540, 659.2551, 698.4565, 739.9888, 783.9909,
830.6094, 880.0000, 932.3275, 987.7666, 1046.5023, 1108.7305, 1174.6591, 1244.5079,
1318.5102, 1396.9129, 1479.9777, 1567.9817, 1661.2188, 1760.0000, 1864.6550, 1975.5332,
2093.0045, 2217.4610, 2349.3181, 2489.0159, 2637.0205, 2793.8259, 2959.9554, 3135.9635,
3322.4376, 3520.0000, 3729.3101, 3951.0664, 4186.0090, 4434.9221, 4698.6363, 4978.0317,
5274.0409, 5587.6517, 5919.9108, 6271.9270, 6644.8752, 7040.0000, 7458.6202, 7902.1328,
8372.0181, 8869.8442, 9397.2726, 9956.0635, 10548.0818, 11175.3034, 11839.8215, 12543.8540
};
AudioOutputAnalog dac1;
AudioSynthNoiseWhite noise1; //xy=55,125.54546356201172
AudioSynthSimpleDrum drum3; //xy=55.72727966308594,165.99997329711914
AudioSynthNoisePink pink1; //xy=55.88888931274414,214.8888988494873
AudioSynthWaveformSine lfo3; //xy=55,737.5511474609375
AudioSynthWaveformSine lfo4; //xy=55,777.5511474609375
AudioSynthWaveformSine sine1; //xy=58,271.99999809265137
AudioSynthWaveformSine lfo1; //xy=57,662
AudioSynthWaveformSine lfo2; //xy=59.00569152832031,699.5511474609375
AudioSynthWaveformSineModulated sine_fm3; //xy=62,461.0000476837158
AudioSynthWaveform waveform2; //xy=64,315.66666412353516
AudioSynthWaveform waveform1; //xy=64,1037.181884765625
AudioEffectEnvelope ev2; //xy=65.00567626953125,886.4601821899414
AudioSynthWaveformSineModulated sine_fm2; //xy=67,561
AudioEffectEnvelope ev1; //xy=66,847
AudioEffectEnvelope ev4; //xy=67.00569152832031,963.4601440429688
AudioSynthSimpleDrum drum2; //xy=74.54545593261719,77.27274513244629
AudioSynthSimpleDrum drum1; //xy=75.45454406738281,27.272724151611328
AudioEffectEnvelope ev3; //xy=75.00566864013672,920.4601707458496
AudioSynthNoiseWhite noise2; //xy=94,420.9999952316284
AudioSynthWaveformModulated waveformMod1; //xy=195.54547119140625,227.6364231109619
AudioEffectEnvelope envelope2; //xy=207.0000343322754,98.99999141693115
AudioAnalyzePeak peak4; //xy=209,736.5511474609375
AudioAnalyzePeak peak5; //xy=209,776.5511474609375
AudioAnalyzePeak peak2; //xy=211,661
AudioAnalyzePeak peak3; //xy=213.0056915283203,698.5511474609375
AudioSynthWaveformModulated waveformMod2; //xy=214,510
AudioAnalyzePeak peak7; //xy=213.00568389892578,885.4601821899414
AudioAnalyzePeak peak6; //xy=214,847
AudioSynthWaveformSineModulated sine_fm1; //xy=228,563
AudioAnalyzePeak peak9; //xy=231.0057144165039,964.4601573944092
AudioAnalyzePeak peak8; //xy=233.00567626953125,923.4601821899414
AudioSynthKarplusStrong string2; //xy=269.00000381469727,323.9999942779541
AudioSynthKarplusStrong string1; //xy=271.0000114440918,293.00001430511475
AudioSynthKarplusStrong string6; //xy=270.88888931274414,463.88890838623047
AudioSynthKarplusStrong string3; //xy=272.00000762939453,354.99999046325684
AudioSynthKarplusStrong string4; //xy=272.00000381469727,390.0000114440918
AudioSynthKarplusStrong string5; //xy=271.8888816833496,425.8888931274414
AudioEffectEnvelope envelope6; //xy=352.88890838623047,213.88889122009277
AudioMixer4 mixer1; //xy=370.4545593261719,35
AudioEffectEnvelope envelope1; //xy=371.54542541503906,112.54545783996582
AudioEffectEnvelope envelope4; //xy=393,507
AudioEffectGranular granular1; //xy=395.73292541503906,560.9146976470947
AudioMixer4 mixer4; //xy=419.00012969970703,305
AudioMixer4 mixer7; //xy=427.8889274597168,405.88887786865234
AudioEffectEnvelope envelope3; //xy=482.09095764160156,168.54548835754395
AudioMixer4 mixer5; //xy=522,47
AudioAnalyzePeak peak1; //xy=525.4545593261719,1029.727294921875
AudioEffectReverb reverb1; //xy=535.9999542236328,675.0001268386841
AudioMixer4 mixer8; //xy=539.8888397216797,334.88891220092773
AudioEffectEnvelope envelope5; //xy=559.9999313354492,572.0000057220459
AudioAmplifier amp2; //xy=579.6417121887207,408.9148235321045
AudioEffectBitcrusher bitcrusher1; //xy=584.7329406738281,501.00567054748535
AudioFilterStateVariable filterBass; //xy=597.2727165222168,234.99999046325684
AudioAmplifier amp1; //xy=616.9090309143066,125.90907859802246
AudioFilterLadder ladder1; //xy=670.8889007568359,38.88888931274414
AudioEffectWaveshaper waveshape1; //xy=720.0055770874023,345.9147701263428
AudioMixer4 mixerdist; //xy=822.6420288085938,259.9147834777832
AudioMixer4 mixer3; //xy=857.9999923706055,35
AudioFilterStateVariable filter3; //xy=886.8237762451172,511.7329330444336
AudioFilterStateVariable filter2; //xy=983.7330074310303,221.9147491455078
AudioMixer4 mixer2; //xy=988.0909729003906,124.81816482543945
AudioMixer4 mixer6; //xy=1163.0000495910645,107
AudioFilterStateVariable filter40; //xy=1300.4447059631348,106.88888168334961
AudioOutputUSB usb1; //xy=1561.2729187011719,98.45458030700684
AudioConnection patchCord1(noise1, envelope2);
AudioConnection patchCord2(drum3, 0, mixer1, 3);
AudioConnection patchCord3(pink1, envelope1);
AudioConnection patchCord4(lfo3, peak4);
AudioConnection patchCord5(lfo4, peak5);
AudioConnection patchCord6(sine1, 0, waveformMod1, 0);
AudioConnection patchCord7(lfo1, peak2);
AudioConnection patchCord8(lfo2, peak3);
AudioConnection patchCord9(sine_fm3, 0, waveformMod2, 0);
AudioConnection patchCord10(waveform1, peak1);
AudioConnection patchCord11(ev2, peak7);
AudioConnection patchCord12(sine_fm2, sine_fm1);
AudioConnection patchCord13(ev1, peak6);
AudioConnection patchCord14(ev4, peak9);
AudioConnection patchCord15(drum2, 0, mixer1, 1);
AudioConnection patchCord16(drum1, 0, mixer1, 0);
AudioConnection patchCord17(ev3, peak8);
AudioConnection patchCord18(waveformMod1, envelope6);
AudioConnection patchCord19(envelope2, 0, mixer1, 2);
AudioConnection patchCord20(waveformMod2, envelope4);
AudioConnection patchCord21(sine_fm1, granular1);
AudioConnection patchCord22(string2, 0, mixer4, 1);
AudioConnection patchCord23(string1, 0, mixer4, 0);
AudioConnection patchCord24(string6, 0, mixer7, 1);
AudioConnection patchCord25(string3, 0, mixer4, 2);
AudioConnection patchCord26(string4, 0, mixer4, 3);
AudioConnection patchCord27(string5, 0, mixer7, 0);
AudioConnection patchCord28(envelope6, envelope3);
AudioConnection patchCord29(mixer1, 0, mixer5, 0);
AudioConnection patchCord30(envelope1, 0, mixer5, 1);
AudioConnection patchCord31(envelope4, bitcrusher1);
AudioConnection patchCord32(granular1, envelope5);
AudioConnection patchCord33(mixer4, 0, mixer8, 0);
AudioConnection patchCord34(mixer7, 0, mixer8, 1);
AudioConnection patchCord35(envelope3, amp1);
AudioConnection patchCord36(mixer5, 0, ladder1, 0);
AudioConnection patchCord37(mixer8, 0, mixerdist, 0);
AudioConnection patchCord38(mixer8, amp2);
AudioConnection patchCord39(envelope5, 0, mixer2, 0);
AudioConnection patchCord40(amp2, waveshape1);
AudioConnection patchCord41(bitcrusher1, 0, filter3, 0);
AudioConnection patchCord42(filterBass, 0, mixer3, 1);
AudioConnection patchCord43(amp1, 0, filterBass, 0);
AudioConnection patchCord44(ladder1, 0, mixer3, 0);
AudioConnection patchCord45(waveshape1, 0, mixerdist, 1);
AudioConnection patchCord46(mixerdist, 0, filter2, 0);
AudioConnection patchCord47(mixer3, 0, mixer6, 0);
AudioConnection patchCord48(filter3, 0, mixer3, 3);
AudioConnection patchCord49(filter2, 0, mixer3, 2);
AudioConnection patchCord50(mixer2, 0, mixer6, 1);
AudioConnection patchCord51(mixer6, 0, filter40, 0);
AudioConnection patchCord52(filter40, 2, usb1, 0);
AudioConnection patchCord53(filter40, 2, usb1, 1);
short wave_type[16] = {
WAVEFORM_SINE,
WAVEFORM_SQUARE,
WAVEFORM_SAWTOOTH,
WAVEFORM_SAWTOOTH_REVERSE,
WAVEFORM_TRIANGLE,
WAVEFORM_TRIANGLE_VARIABLE,
WAVEFORM_PULSE, //WAVEFORM_ARBITRARY,
WAVEFORM_PULSE,
WAVEFORM_SAWTOOTH,
WAVEFORM_TRIANGLE,
WAVEFORM_SINE,
WAVEFORM_SQUARE,
WAVEFORM_SAWTOOTH,
WAVEFORM_TRIANGLE,
WAVEFORM_SINE,
WAVEFORM_SQUARE,
};
#define GRANULAR_MEMORY_SIZE 51200 // enough for 290 ms at 44.1 kHz
int16_t granularMemory[GRANULAR_MEMORY_SIZE];
int lfo[8] = {0,0,0,0,0,0,0,0};
int beat[4][32]={ {1,0,0,0,1,0,0,0,1,1,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,1,1,0,1,0,0,0 },
{0,0,1,0,0,0,1,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,1,0,0 } ,
{1,1,0,1,1,1,0,1,1,1,1,0,1,1,1,0,1,1,0,1,1,1,0,1,1,1,1,0,1,1,1,0 },
{0,0,1,0,0,0,1,0,0,0,1,1,0,0,0,1,0,0,1,0,0,0,1,0,0,0,1,1,0,0,0,1 } };
int fatBeat[32];
int ara [8][8][8];
int countBeat = 0;
float bpm = 80 ;
int world = 440;
int exsetj = setj;
int fader5 = 0;
int fader8 = 0;
int fader = 0;
int BT1 = 0;
int BT2 = 0;
int currentVoice = 0;
void myNoteOn(byte b1,byte b2, byte b3)
{
if(b1 == 148 && b2 == 121)
{
BT1 = 1;
if(BT1 == 1 && BT2 == 1 && uOn == 1 )savePresets();
else if(BT1 == 1 && BT2 == 1 && uOn == 0 )loadPresets();
if(seti == 7 && flagRec == 0){flagRec = 2; cleanMatrix();}
else if(seti == 7 && flagRec == 3){flagRec = 4; cleanMatrix();}
point( seti, 4 , 1);
}
else if(b1 == 148 && b2 == 122){
BT2 = 1;
if(BT1 == 1 && BT2 == 1 && uOn == 1 )savePresets();
else if(BT1 == 1 && BT2 == 1 && uOn == 0 )loadPresets();
if(seti == 7 )tapTempo();
point( 0 , setj , 2);
}
else
{
onNoteUlt(b2,b3);
uOn = 1;
}
}
void myNoteOff(byte b1,byte b2, byte b3)
{
if(b1 == 132 && b2 == 121){
BT1 = 0;
if(seti == 7 && flagRec == 1){flagRec = 0; cleanMatrix();}
else if(seti == 7 && flagRec == 2){flagRec = 3; cleanMatrix();}
else if(seti == 7 && flagRec == 4){
countBeat = 0; freqLive = millis();
flagRec = 0;
}
else if(seti == 7 && flagRec == 5){
countBeat = 0; freqLive = millis();
flagRec = 0;
}
point(setk , 4 , 0);
}
else if(b1 == 132 && b2 == 122){
BT2 = 0;
if(seti == 7 && tap > 3 ){
freqClock1 = timeSeq;
int msb = freqClock1 / 128;
int lsb = freqClock1 - ( msb * 128);
ara[7][7][6] = msb;
ara[7][7][7] = lsb;
bpm = 60 / ( freqClock1 / 1000 * 8 );
Serial.print("BPM : ");
Serial.println(bpm);
}
point(setk , 4 , 0);
}
else
{
if(seti > 5) drawFaderTrack();
offNoteUlt(b1);
uOn = 0;
}
}
void myControlChange(byte b1,byte b2, byte b3)
{
if( b2>127 || b3>127 )return;
if(b1 == 180)
{
if(b2 == 3){ ///////////////////////// FADER
if(b3<12)b3 = 12;
b3 = map(b3,12,127,0,127);
fader = b3;
fader8 = b3/16;
fader5 = b3/27;
int fadermod = b3 % 8;
int okfad = 0;
if( fadermod > 0 && fadermod < 7)okfad = 1;
if( flagRec >= 3)flagRec = 3;
else flagRec = 0;
if(BT1 == 0 && BT2 == 0 && okfad == 1)
{
setk = fader8;
point(setk , 4 , 0);
}
songNum = fader8;
if(BT1 == 1 && BT2 == 0){
if(uOn == 0 && okfad == 1 )//&& setk != fader8
{
seti = fader8;
point(seti , 4 , 1);
}
if(seti != exfader8 && uOn == 0 ){
exfader8 = seti;
if(seti < 6)drawSet();
else cleanMatrix();
}
}
if( BT1 == 0 && BT2 == 1)
{
}
}
else if(b2 == 1)////////////ULTRASONYK
{
if(b3 != 0 && b3 != 127) lastCC = b3;
if (BT1 == 1 && BT2 == 0)
{
if(seti > 5 && uOn == 1)beatFader( b3 );
}
else if(BT1 == 0 && BT2 == 1)
{
if( uOn == 1 ) setj = 4 - ( b3/15 );
if(setj < 0)setj = 0;
point( 0 , setj , 2);
if(exsetj != setj)
{
envelope3.noteOff();
envelope2.noteOff();
envelope1.noteOff();
envelope4.noteOff();
envelope5.noteOff();
exsetj = setj;
}
}
else if(BT1 == 0 && BT2 == 0)
{
if(setj == 2 && seti ==0 && uOn == 1)playGuit( b3);
else if(setj == 0 && seti ==0 && uOn == 1)beatFader( b3 );
// else if(setj == 0 && seti ==0 && uOn == 1)beatFader( b3 );
else if(seti > 5 && uOn == 1)beatFader( b3 );
}
}
else if(b2 == 2)////////////VELO
{
if(b3<63)dirU =-1;
else dirU = 1;
}
else if(b2 == 6)//////////// CC MSB
{
msb = b3;
}
else if(b2 == 7)//////////// CC MSB
{
lsb = b3;
int big = (msb * 128) + lsb;
big = big * 2;
if( big > 16482) big = 16482;
int small = map(big , 0 , 16482 , 0 , 127 );
if(seti < 5 && uOn == 1 && BT1 == 1 && BT2 == 0){
ara[seti][setj][setk] = small;
changeSet( seti, setj, setk, small);
vBar(setk , small);
point( setk , 4 , 0);
}
}
}
}
void myBend(byte b1,byte b2, byte b3)
{
int big = b2 + (b3 * 128);
if( seti > 2)
{
if(setj == 1)
{
int hlf = big;
int frq = map(hlf,0,16383,filtB/10,filtB + ((filtB/10)*9));
if(frq < 40)frq = 40;
filterBass.frequency(frq);
}
}
}
void setup()
{
Serial1.begin(31250);
/////// BPM osc
frqBpm4 = bpm * 8 / 60;
freqClock1 = 1 / (bpm / 60) * 1000 / 8 / 16;
/////float frqBpm6 = bpm * 6 / 60;
filter40.frequency(40);
filter40.resonance(0);
if (!SD.begin(chipSelect)) {
Serial.println("SD card failed !");
return;
}
Serial.println("SD card ready");
waveform1.frequency(frqBpm4);
waveform1.amplitude(1);
/// KICK
drum1.frequency(68);
drum1.length(1120);
drum1.secondMix(0.28);
drum1.pitchMod(0.55);
///// SNARE
drum2.frequency(167);
drum2.length(130);
drum2.secondMix(0.4);
drum2.pitchMod(0.49);
envelope2.attack(1.85);
envelope2.hold(0.41);
envelope2.decay(8.4);
envelope2.sustain(0.2);
envelope2.release(9.4);
noise1.amplitude(0.3);
///// HH
drum3.frequency(2540);
drum3.length(9);
drum3.secondMix(2.4);
drum3.pitchMod(0.35);
///// clap
pink1.amplitude(0.5);
envelope1.attack(0.13);
envelope1.hold(0.3);
envelope1.decay(4.1);
envelope1.sustain(0.00);
envelope1.release(0.03);
////////////////7 BASSSSSSSSSSSSSSSSSSSSSS
envelope3.attack(23.15);
envelope3.hold(9.4);
envelope3.decay(28.4);
envelope3.sustain(0.33);
envelope3.release(726.4);
amp1.gain(0.7);
filterBass.frequency(360);
filterBass.resonance(4.2);
sine1.frequency( 33 );
waveformMod1.frequency(68);
waveformMod1.amplitude(0.3);
waveformMod2.begin(WAVEFORM_TRIANGLE);
///////// synth 1
envelope4.attack(13.15);
envelope4.hold(3.4);
envelope4.decay(8.4);
envelope4.sustain(0.33);
envelope4.release(6.4);
///////////// syn1
sine_fm3.frequency(954);
sine_fm3.amplitude(0.2);
///////////// syn2 long
sine_fm1.frequency(320);
sine_fm1.amplitude(0.6);
reverb1.reverbTime(0.3);
envelope5.attack(43.15);
envelope5.hold(9.4);
envelope5.decay(28.4);
envelope5.sustain(0.33);
envelope5.release(1726.4);
AudioMemory(20);
granular1.begin(granularMemory, GRANULAR_MEMORY_SIZE);
usbMIDI.begin();
usbMIDI.setHandleNoteOff(myNoteOff);
usbMIDI.setHandleNoteOn(myNoteOn);
usbMIDI.setHandleControlChange(myControlChange) ;
delay(200);
initt();
}
void loop() ///LOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOP
{
getMidiSerial();
runIt();
checkSnare();
}
void checkSnare()
{
int delta = millis()- cntSnare;
if( delta > 50 && onSnare ){envelope2.noteOff(); onSnare = false; }
delta = millis()- cntClap;
if( delta > 50 && onClap ){envelope1.noteOff(); onClap = false; }
}
void runIt()
{
int dlt = millis() - freqLive;
if( dlt >= freqClock1 )
{
freqLive = millis();
int modu = the8%16;
if(modu == 0)
{
runBeat();
}
runBass();
the8++;
if( the8 > 511)the8 = 0;
}
}
void runBeat()
{
// int kk =0;
// if (peak1.available())
// {
//
// kk = peak1.read() * 1000;
// }
if( trigBass ==1 || trigBass == 2 )
{
envelope3.noteOn();
envelope6.noteOn();
if(trigBass == 2)trigBass = 3;
else trigBass = 0;
//cntArpBass = 0;
}
else if(trigBass == 3)
{
envelope3.noteOff();
trigBass = 0;
}
if( flagRec == 1 && faderBeat == 0){
fatBeat[countBeat] = 0;
}
if( seti < 5 && flagRec == 0)faderBeat = fatBeat[countBeat];
else if( seti < 5 && flagRec == 3)faderBeat = faderBeat;
else if( faderBeat !=0 )faderBeat = faderBeat;
else if( flagRec == 0 )faderBeat = fatBeat[countBeat];
if( seti > 5 && flagRec == 1)drawPoint(countBeat%8, countBeat / 8 , faderBeat);
if(faderBeat == 1)
{
drum1.noteOn();
}
else if(faderBeat == 4)
{
drum2.noteOn();
envelope2.noteOn();
onSnare = true;
cntSnare = millis();
}
else if(faderBeat == 3)
{
drum3.noteOn();
}
if(faderBeat == 2)
{
envelope1.noteOn();
onClap = true;
cntClap = millis();
}
countBeat++;
if(countBeat >= 32){
if(flagRec == 1)flagRec = 5;
countBeat = 0;
}
if(seti>5)
{
int x = ( countBeat % 8 );
int y = ( countBeat / 8 );
if(flagRec != 1)
{
if(flagRec == 0)drawPoint(x,y,5);
int cnt = countBeat-1;
if (cnt<0)cnt = 31;
x = ( cnt % 8 );
y = ( cnt / 8 );
drawPoint(x,y,fatBeat[cnt]);
}
}
faderBeat = 0;
}
void runBass()
{
if(seti <= 6 && setj == 1 ) // && uOn == 1
{
int dt2 = ara[2][1][2] / 10;
int ar[]= { 0,128,64,48,32,24,16,12,8,6,4,3,2}; // max 12.9
int arpSpeed = ar[dt2];
//
// Serial.println( arpSpeed );
// if( countBass >= arpSpeed && arpSpeed > 0)
// {
// countBass = 0;
//
// switch(cntArpBass) { // arpeggio bass
// case 0:
// if(ara[2][1][5]/11>0)
// {
// waveformMod1.frequency( tune[ tuneB + (ara[2][1][5]/5)] );
// }
// break;
// case 1:
// if(ara[2][1][6]/11>0)
// {
// waveformMod1.frequency( tune[ tuneB + (ara[2][1][6]/5)] );
// }
// break;
// case 2:
// if(ara[2][1][7]/11>0)
// {
// waveformMod1.frequency( tune[ tuneB + (ara[2][1][7]/5)] );
//
// }
// break;
//
// default:
//
// break;
// }
//
// cntArpBass++;
// if( cntArpBass > 2)cntArpBass = 0;
//
// envelope6.noteOn();
// if(dt2 == 4)envelope6.noteOff();
// }
}
}
void getCpu()
{
// return;
Serial.print("Proc = ");
Serial.print(AudioProcessorUsage());
Serial.print(" (");
Serial.print(AudioProcessorUsageMax());
Serial.print("), Mem = ");
Serial.print(AudioMemoryUsage());
Serial.print(" (");
Serial.print(AudioMemoryUsageMax());
Serial.println(")");
}
void changeSet( int i, int j, int k, int val)
{
float flt = 0.0;
int mpx = 0;
if(val < 0 || val > 127)return;
if(i == 0)
{
if(j == 0){
switch(k) {
case 0: // VOL all drumz
flt = map( val,0,127,0,1000 );
flt = flt / 1000;
mixer3.gain(0, flt);
break;
case 1:
ladder1.frequency( map( val,0,127,100,12000 ) );
break;
case 2:
flt = map( val,0,127,0,1000 );
flt = flt / 1000;
ladder1.resonance( flt );
break;
case 3:
flt = map( val,0,127,0,7000 );
flt = flt / 1000;
ladder1.octaveControl( flt );
break;
case 4:
flt = map( val,0,127,0,4000 );
flt = flt / 1000;
ladder1.inputDrive( flt );
break;
case 5:
flt = map( val,0,127,0,500 );
flt = flt / 1000;
ladder1.passbandGain( flt );
break;
default:
break;
}
}
else if(j == 1){ /////BASS
switch (k) {
case 0:
flt = map( val,0,127,0,700 );
flt = flt/1000;
mixer3.gain(1, flt);
break;
case 1:
if(val < 64)envelope3.attack( map(val,0,63,0, 50 ));
else envelope3.attack( map(val,64,127,50, 1400 ));
break;
case 2:
if(val < 64)
{
envelope3.hold(0);
envelope3.decay(map(val,0,127,0, 100) );
}
else
{
envelope3.hold( map(val,0,127,100, 1200 ) );
envelope3.decay(map(val,0,127,100, 1200 ));
}
break;
case 3:
flt = map(val,0,127,0, 100 );
flt = flt / 100;
envelope3.sustain( flt );
break;
case 4:
envelope3.release( map(val,0,127,0, 2600 ));
break;
case 5:
mpx = val / 16;
waveformMod1.begin(wave_type[mpx] );
Serial.println(wave_type[mpx]);
break;
case 6:
filterBass.frequency( map(val,0,127,0, 800 ));
filtB = map(val,0,127,0, 800 );
break;
case 7:
flt = map(val,0,127,70, 300 );
flt = flt/100;
filterBass.resonance( flt );
break;
default:
break;
}
}
else if(j == 2){///GUITAR
switch (k) {
case 0:
flt = map( val,0,127,0,1000 );
flt = flt/1000;
mixer3.gain(2, flt);
break;
case 1:
flt = map( val,0,127,0,1000 );
flt = flt/1000;
veloGuit = flt;
break;
case 2:
flt = map( val,0,127,0,100 );
flt = flt/100;
if(val < 40){
mixerdist.gain(0, 0.66 + (flt / 1) );
mixerdist.gain(1, 0);}
else if(val <= 40 && val > 80){
mixerdist.gain(0, 1 - flt);
mixerdist.gain(1, flt);}
else{
mixerdist.gain(0, 0);
mixerdist.gain(1, flt/2);}
break;
case 3:
for( int i=1; i < 4; i++)
{
flt = map( val,0,127,950,1000 );
arrDist[i] = flt/1000;
arrDist[8 - i] = -flt/1000;
flt = map( val,0,127,900,1000 );
arrDist[i] = flt/1000;
arrDist[8 - i] = -flt/1000;
flt = map( val,0,127,850,1000 );
arrDist[i] = flt/1000;
arrDist[8 - i] = -flt/1000;
}
break;
case 4:
flt = map( val,0,127,0,6000 );
flt = flt/1000;
amp2.gain(flt);
break;
case 5:
flt = map(val,0,127,0, 700 );
flt = flt / 100;
filter2.octaveControl( flt);
break;
case 6:
filter2.frequency( map(val,0,127,50, 2000 ));
break;
case 7:
flt = map(val,0,127,70, 500 );
flt = flt / 100;
filter2.resonance( flt);
break;
default:
break;
}
}
else if(j == 3){/// SYNTH arpg
switch (k) {
case 0: // vol syn 1
flt = map( val,0,127,0,1000 ) / 100;
flt = flt / 1000;
mixer3.gain(3, flt);
break;
case 1:
if(val < 64)envelope4.attack( map(val,0,63,0, 200 ));
else envelope4.attack( map(val,64,127,200, 2400 ));
envelope4.hold(0);
envelope4.decay(0);
envelope4.sustain(1);
break;
case 2:
envelope4.release( map(val,0,127,0, 4600 ));
break;
case 3:
mpx = val / 16;
waveformMod2.begin(wave_type[mpx] );
break;
case 4:
bitcrusher1.bits(map(val,0,127,16, 2 ));
break;
case 5:
flt = map(val,0,127,100, 360000 );
flt = flt / 400;
sine_fm3.frequency( flt);
break;
case 6:
filter3.frequency( map(val,0,127,40, 2000 ));
break;
case 7:
flt = map(val,0,127,70, 500 );
flt = flt/100;
filter3.resonance( flt);
break;
default:
break;
}
}
else if(j == 4){///// synth nappe
switch (k) {
case 0: // vol syn 3
flt = map( val,0,127,0,1000 );
flt = flt/1000;
mixer2.gain(0, flt);
break;
case 1:
if(val < 64)envelope5.attack( map(val,0,63,0, 200 ));
else envelope5.attack( map(val,64,127,200, 2400 ));
envelope5.hold(0);
envelope5.decay(0);
envelope5.sustain(1);
break;
case 2:
envelope5.release( map(val,0,127,0, 4600 ));
break;
case 3:
flt = map( val,0,127,100,300000 );
flt = flt / 1000;
sine_fm2.frequency( flt );
break;
case 4:
flt = map( val,0,127,0,1000 );
flt = flt/1000;
sine_fm2.amplitude( flt );
break;
case 5:
granular1.beginPitchShift( map(val,0,127,1, 95 ));
break;
case 6:
flt = map(val,2,127,125, 8000 );
flt = flt/1000;
granular1.setSpeed(flt);
break;
case 7:
flt = map(val,2,127,0, 1156 );
granular1.beginFreeze(flt);
break;
default:
break;
}
}
}
else if(i == 1)// ALL DRUMZ
{
if(j == 0){// K I C K
switch (k) {
case 0: //
flt = map( val,0,127,0,1000 );
flt = flt / 1000;
mixer1.gain(0, flt);
break;
case 1:
drum1.frequency( map(val,0,127,20, 120));
break;
case 2:
drum1.length( map( val,0,127,20,700 ));
break;
case 3:
flt = map( val,0,127,0,1000 );
flt = flt / 1000;
drum1.secondMix( flt);
break;
case 4:
flt = map( val,0,127,1000,10 );
flt = flt / 1000;
drum1.pitchMod( flt );
break;
default:
break;
}
}
else if(j == 1){// snare
switch (k) {
case 0:
flt = map( val,0,127,0,1000 );
flt = flt / 1000;
mixer1.gain(1, flt);
break;
case 1:
drum2.frequency( map(val,0,127,120, 250 ));
break;
case 2:
drum2.length(map(val,0,127,15, 400 ));
envelope2.release( map(val,0,127,15, 400 ) );
break;
case 3:
flt = map( val,0,127,0,1000 );
flt = flt / 1000;
drum2.secondMix( flt );
break;
case 4:
flt = map( val,0,127,1000,10 );
flt = flt / 1000;
drum2.pitchMod( flt );
break;
case 5:
flt = map( val,0,127,0,500 );
flt = flt / 1000;
mixer1.gain(2, flt);
break;
case 6:
envelope2.hold(0);
envelope2.delay(0);
envelope2.attack((val)*2);
envelope2.decay(val/2);
envelope2.hold(0);
break;
case 7:
flt = map( val,0,127,0,1000 );
flt = flt / 1000;
envelope2.sustain( 0.32);
envelope2.release(val * 4 );
break;
default:
break;
}
}
else if(j == 2){// HH
switch (k) {
case 0:
flt = map( val,0,127,0,1000 );
flt = flt / 1000;
mixer1.gain(3, flt);
break;
case 1:
drum3.frequency( map(val,0,127,800, 2800 ));
break;
case 2:
drum3.length( map(val,0,127,1, 80 ));
break;
case 3:
flt = map( val,0,127,0,1000 );
flt = flt / 1000;
drum3.secondMix( flt);
break;
case 4:
flt = map( val,0,127,800,20 );
flt = flt / 1000;
drum3.pitchMod( flt );
break;
default:
break;
}
}
else if(j == 3){// clap
switch (k) {
case 0:
flt = map( val,0,127,0,1000 );
flt = flt / 1000;
mixer5.gain(1, flt);
break;
case 1:
flt = map( val,0,127,0,1000 );
flt = flt / 1000;
pink1.amplitude( flt );
break;
case 2:
envelope1.hold(0);
envelope1.attack(val);
break;
case 3:
envelope1.decay(val * 6 );
envelope1.sustain( 0.0 );
envelope1.release(0.0 );
break;
default:
break;
}
}
}
else if(i == 2)// FX
{
if(j == 1){ ///////// ////////// BASS 2 ////////////////////
switch (k) {
case 0:
flt = map(val,0,127,1, 25000 );
flt = flt / 100;
sine1.frequency(flt);
break;
case 1:
flt = map( val,0,127,0,1000 );
flt = flt / 1000;
sine1.amplitude(flt);
break;
case 2:
////// X 1 - 8 arpegio
break;
case 3:
envelope6.hold(val/2);
envelope6.attack(val );
break;
case 4:
envelope6.decay( 0 );
envelope6.sustain( 1.0 );
envelope6.release( val );
break;
case 5:
break;
case 6:
break;
case 7:
break;
default:
break;
}
}
}
else if(i == 3)// LFO
{
if(j == 0){
switch (k) {
case 0:
lfo1.frequency(map( val,0,127,0.044,world));
break;
default:
break;
}
}
else if(j == 1){
switch (k) {
case 0:
lfo2.frequency(map( val,0,127,0.044,world));
break;
default:
break;
}
}
else if(j == 2){
switch (k) {
case 0:
lfo3.frequency(map( val,0,127,0.044,world));
break;
default:
break;
}
}
else if(j == 3){
switch (k) {
case 0:
lfo4.frequency(map( val,0,127,0.044,world));
break;
default:
break;
}
}
}
else if(i== 7)
{
if(j ==7)
{
if(k == 7)
{
freqClock1 = (( ara[7][7][6] * 128 ) + val ) / 16 ;
bpm = 60 / ( freqClock1 * 8 / 1000) / 8 ;
Serial.print("BPM : ");
Serial.println(freqClock1);
}
}
}
}
void initt()
{
filterBass.octaveControl(6);
filter2.octaveControl(2.5);
waveformMod1.amplitude(0.99);
waveformMod1.begin(WAVEFORM_SINE);
amp1.gain(0.5);
mixer8.gain(0,1);
mixer8.gain(1,0.5);
waveshape1.shape(arrDist , 9 );
waveformMod2.frequency(598);
waveformMod2.amplitude(1);
waveformMod2.begin(WAVEFORM_TRIANGLE);
delay(80);
loadPresets();
freqLive = millis();
}
void loadPresets()
{
int cni = 0;
int cnj = 0;
int cnk = 0;
int cnt =0;
File myFile;
String track = "track-"+ String(songNum) + ".mdx";
myFile = SD.open( track.c_str() );
if (myFile) {
while (myFile.available()) {
switch ((char)myFile.peek()) {
case ',':
myFile.read();
break;
case '\r':
myFile.read();
break;
default:
int newV = myFile.parseInt();
if(cni <= 7){
ara[cni][cnj][cnk] = newV;
changeSet( cni, cnj, cnk, newV);
}
else {
fatBeat[cnt] = newV;
cnt++;
}
cnk++;
if(cnk == 8){cnk=0; cnj++;}//Serial.println(" " );
if(cnj == 8){cnj=0; cni++; }//Serial.println(" " ); Serial.println(" " );
break;
}
}
Serial.print(track);
Serial.println(" loaded");
myFile.close();
}
else {
Serial.println("error loading song on SD");
songNum = 0;
loadPresets();
}
}
void savePresets()
{
String allSet = "";
for( int i=0; i< 8; i++)
{
for( int j=0; j<8;j++)
{
for( int k=0; k<8;k++)
{
int val = ara[i][j][k];
allSet = allSet + val + ",";
}
}
}
for( int i=0; i< 32; i++)
{
int val = fatBeat[i];
if( i == 31 )allSet = allSet + val;
else allSet = allSet + val + ",";
}
delay(50);
String track = "track-"+ String(songNum)+".mdx";
SD.remove( track.c_str());
File myFile = SD.open( track.c_str() , FILE_WRITE);
if (myFile) {
myFile.println(allSet);
myFile.close();
Serial.println( track+ " saved on SD");
}
else
{
Serial.println("ERROR saving on SD");
}
allSet ="";
}
void getMidiSerial()
{
byte b1;
byte b2;
byte b3;
do{
if (Serial1.available()){
b1=Serial1.read();
while (b1 == 255) b1=Serial1.read();
b2=Serial1.read();
while (b2 == 255) b2=Serial1.read();
b3=Serial1.read();
while (b3 == 255) b3=Serial1.read();
if(b1>= 144 && b1 < 160)myNoteOn(b1,b2,b3);
else if(b1>= 128 && b1 < 144)myNoteOff(b1,b2,b3);
else if(b1>= 176 && b1 < 192)myControlChange(b1,b2,b3);
else if(b1>= 224 && b1 < 240)myBend(b1,b2,b3);
}
}
while (Serial1.available() > 2);
}
void playGuit( byte b3)
{
int delta = (startCC - b3)/8;
if(delta == exDeltaG)return;
else exDeltaG = delta;
if(delta == 7) okChord[0] =1;
else if(delta == 6) okChord[1] =1;
else if(delta == 5 && okChord[0] ==1 )
{
okChord[2] =1;
okChord[0] =0;
if(startUltra <= 49 ) string6.noteOn( tune[startUltra + chord[1][5] ], veloGuit );
}
else if(delta == 4 && okChord[1] ==1 )
{
okChord[3] =1;
okChord[1] =0;
if(startUltra <= 44 ) string5.noteOn( tune[startUltra + chord[1][4] ], veloGuit);
}
else if(delta == 3 && okChord[2] ==1 )
{
okChord[0] =1;
okChord[4] =1;
okChord[2] =0;
string4.noteOn( tune[startUltra + chord[1][3] ], veloGuit);
}
else if(delta == 2 && okChord[3] ==1 )
{
okChord[1] =1;
okChord[5] =1;
okChord[3] =0;
string3.noteOn( tune[startUltra + chord[1][2] ], veloGuit);
}
else if(delta == 1 && okChord[4] ==1 )
{
okChord[2]=1;
okChord[6]=1;
okChord[4] =0;
string2.noteOn( tune[startUltra +chord[1][1]] ,veloGuit);
}
else if(delta == 0 && okChord[5] ==1 )
{
okChord[3]=1;
okChord[7] =1;
okChord[5] =0;
string1.noteOn( tune[startUltra +chord[1][0]] , veloGuit);
}
else if(delta == -1 && okChord[6] ==1 )
{
okChord[4]=1;
okChord[8] =1;
okChord[6] =0;
string2.noteOn( tune[startUltra + chord[1][1] ], veloGuit);
}
else if(delta == -2 && okChord[7] ==1 )
{
okChord[5]=1;
okChord[9] =1;
okChord[7] =0;
string3.noteOn( tune[startUltra + chord[1][2]] , veloGuit);
}
else if(delta == -3 && okChord[8] ==1 )
{
okChord[6]=1;
okChord[10] =1;
okChord[8] =0;
string4.noteOn( tune[startUltra + chord[1][3]] , veloGuit);
}
else if(delta == -4 && okChord[9] ==1 )
{
okChord[7]=1;
okChord[9] =0;
if(startUltra <= 44 )string5.noteOn( tune[startUltra + chord[1][4]] , veloGuit);
}
else if(delta == -5 && okChord[10] ==1 )
{
okChord[8]=1;
okChord[10] =0;
if(startUltra <= 49 )string6.noteOn( tune[startUltra + chord[1][5]] , veloGuit);
}
else if(delta == -6) okChord[9] =1;
else if(delta == -7) okChord[10] =1;
}
void onNoteUlt(byte nt , byte vl )
{
if(BT1 == 1 || BT2 == 1)return;
if(seti == 0)//////////////77 SET 0
{
if(setj == 0)
{
armDrum[0]=0;
armDrum[1]=0;
armDrum[2]=0;
armDrum[3]=0;
armDrum[4]=0;
}
else if(setj == 1)
{
if(nt>11)nt = 11;
nt =nt/3;
nt = chr[nt] + 24;
waveformMod1.frequency( tune[nt] );
tuneB = nt;
trigBass = 1;
}
else if(setj == 2)
{
if(nt>11)nt = 11;
nt =nt/3;
startCC = lastCC;
startDir = dirU;
nt = chr[nt] + 36;
startUltra = nt;
float flt = vl;
flt = flt / 400;
string1.noteOn( tune[nt + 0 ], veloGuit );
okChord[0] = 1;
okChord[1] = 1;
okChord[2] = 1;
okChord[3] = 1;
okChord[4] = 1;
okChord[5] = 0;
okChord[6] = 1;
okChord[7] = 1;
okChord[8] = 1;
okChord[9] = 1;
okChord[10] = 1;
okChord[11] = 1;
deltaTG = millis();
}
else if(setj == 3)
{
if(nt>11)nt = 11;
nt =nt/3;
nt = chr[nt] + 48;
waveformMod2.frequency(tune[nt]);
envelope4.noteOn();
}
else if(setj == 4)
{
if(nt>11)nt = 11;
nt =nt/3;
nt = chr[nt] + 48;
sine_fm1.frequency(tune[nt]);
envelope5.noteOn();
}
}
else if(seti == 1) //////////SET 1
{
if(nt>11)nt = 11;
nt = nt/3;
nt = setj;
if(nt >3)nt=3;
if( nt == 0)drum1.noteOn();
else if( nt == 1)
{
drum2.noteOn();
envelope2.noteOn();
onSnare = true;
cntSnare = millis();
}
else if( nt == 2)drum3.noteOn();
else if( nt == 3)
{
envelope1.noteOn();
onClap = true;
cntClap = millis();
}
}
else if(seti >= 2 && seti <= 5 )
{
if(setj == 1)
{
if(nt>17)nt = 17;
nt =nt/3;
nt = chrb[nt] + 24;
waveformMod1.frequency( tune[nt] );
tuneB = nt;
trigBass = 1;
}
}
else if(seti > 5 || (seti == 0 && setj == 0 ))
{
exBeatfader = 99;
armDrum[0]=0;
armDrum[1]=0;
armDrum[2]=0;
armDrum[3]=0;
armDrum[3]=0;
}
}
void offNoteUlt(byte b1)
{
if(setj == 0 || seti==1)
{
}
if(setj == 1 )
{
if( trigBass == 0 )
{
envelope3.noteOff();
}
else if ( trigBass == 1 )
{
trigBass = 2;
}
}
else if(setj == 2)
{
envelope3.noteOff();
// envelope1.noteOff();
}
else if(setj == 3)
{
envelope4.noteOff();
}
else if(setj == 4)
{
envelope5.noteOff();
}
if(( seti > 5 && flagRec == 0) || (seti == 0 && setj == 0 ) )
{
exBeatfader = 99;
armDrum[0]=0;
armDrum[1]=0;
armDrum[2]=0;
armDrum[3]=0;
armDrum[3]=0;
}
if( seti > 5 )cleanMatrix();
}
void beatFader( int nt)
{
nt = nt/2;
if(nt>16)nt=16;
int delta = -1;
if(nt != exBeatfader)
{
delta = nt - exBeatfader;
int vl = nt * 7.8;
if(( seti > 5 && flagRec == 3 ) ||( seti > 5 && flagRec == 0 ) )
{
vBar( 3 ,vl );
vBar( 4 ,vl );
}
}
exBeatfader = nt;
if( nt == 0 && armDrum[0]==0)
{
armDrum[0]=1;
faderBeat = 1;
if(flagRec == 2 || flagRec == 4 ){ countBeat = 0; freqLive = millis(); flagRec = 1;}
if( flagRec == 1 ){
fatBeat[countBeat] = faderBeat;
}
}
else if( nt == 3 || nt == 2 )
{
armDrum[0]=0;
armDrum[1]=0;
}
else if( nt == 5 && armDrum[1]==0 && delta > 0 )
{
armDrum[1]=1;
if(faderBeat == 0){
faderBeat = 2;
if(BT1 == 1 && flagRec == 1 ){
fatBeat[countBeat] = faderBeat;
}
}
armDrum[4]=0;
}
else if( nt == 7 && armDrum[4]==0)
{
armDrum[4]=1;
armDrum[1]=0;
armDrum[2]=0;
// drum3.noteOn();
faderBeat = 3;
if(BT1 == 1 && flagRec == 1 ){
fatBeat[countBeat] = faderBeat;
}
}
else if( nt >= 9 && nt < 11 && armDrum[2]==0)
{
if(faderBeat == 0) {
faderBeat = 2;
if(BT1 == 1 && flagRec == 1 ){
fatBeat[countBeat] = faderBeat;
}
}
armDrum[2]=1;
armDrum[3]=0;
}
else if( nt == 11 || nt == 12)
{
armDrum[2]=0;
armDrum[4]=0;
}
else if( nt >= 13 && armDrum[3]==0)
{
armDrum[3]=1;
faderBeat = 4;
if(BT1 == 1 && flagRec == 1 ){
fatBeat[countBeat] = faderBeat;
}
if(BT2 == 1 && seti > 5)
{
flagKick = 0;
}
}
else if( nt == 14 || nt == 15 )
{
}
else if( nt >= 16 )
{
}
}
void prepRec()
{
for( int i=0; i< 4; i++)
{
for( int j=0; j< 16 ;j++)
{
beat[i][j] = 0;
}
}
}
void drawPoint(int x, int y, int z )
{
Serial1.write(191);
Serial1.write(0);
Serial1.write(x);
Serial1.write(191);
Serial1.write(1);
Serial1.write(y);
Serial1.write(191);
Serial1.write(2);
Serial1.write(r[z] );
Serial1.write(191);
Serial1.write(3);
Serial1.write( g[z] );
Serial1.write(191);
Serial1.write(4);
Serial1.write( b[z] );
Serial1.write(191);
Serial1.write(6);
Serial1.write(0);
}
void blinkPoint()
{
return;
int cnt =countBeat - 1;
if(cnt < 0 )cnt=31;
Serial1.write(191);
Serial1.write(0);
Serial1.write(0+(countBeat%8));
Serial1.write(191);
Serial1.write(1);
Serial1.write(0+(countBeat/8));
Serial1.write(191);
Serial1.write(2);
Serial1.write(120);
Serial1.write(191);
Serial1.write(3);
Serial1.write( 100);
Serial1.write(191);
Serial1.write(4);
Serial1.write( 100);
Serial1.write(191);
Serial1.write(6);
Serial1.write(1);
drawPoint( cnt%8 , cnt/8 , fatBeat[cnt] );
}
void cleanMatrix()
{
Serial1.write(143);
Serial1.write(1);
Serial1.write(1);
}
void drawFaderTrack()
{
//
// for( int i=0; i < 7; i++)
// {
//
// drawPoint( i%8 , i/8 , fatBeat[i] );
//
// }
}
void point(int x, int y, int z )
{
x = x+1;
y = y + 1;
Serial1.write(191);
Serial1.write(0);
Serial1.write(x);
Serial1.write(191);
Serial1.write(1);
Serial1.write(y);
Serial1.write(191);
Serial1.write(5);
Serial1.write(z);
}
void vBar( int x, int vl )
{
Serial1.write(191);
Serial1.write(0);
Serial1.write(x+ 1);
Serial1.write(191);
Serial1.write(7);
Serial1.write(vl);
}
void tapTempo()
{
int dlt = millis() - timeKick;
if(dlt > 4400 || dlt < 44 )
{
timeKick = millis();
tap = 1;
}
else if(tap == 1 ){
time1T = millis() - timeKick;
timeKick = millis();
tap++;
}
else if( tap > 1 )
{
time1T = ((millis() - timeKick)+ time1T ) / 2;
timeKick = millis();
frqBpm4 = 8000 / time1T ;
bpm = 60000 / time1T ;
Serial.print("BPM ");
Serial.println(bpm);
timeSeq = time1T /8;
tap++;
}
}
void drawSet()
{
for( int i=0; i < 7; i++)
{
vBar( i , ara[seti][setj][i] );
}
}
Last edited by a moderator: