arduino-mozzi-5/01 mono drum

/*
   mono  drum 
   

 1.36→1.37:
 音量を固定


*/


#include <MozziGuts.h> // Mozziの基本ヘッダファイル
#include <Oscil.h> // オシレータのテンプレート

#include <tables/SAW2048_int8.h>
#include <tables/SAW1024_int8.h>
#include <tables/SAW512_int8.h>
#include <tables/SQUARE_NO_ALIAS_2048_int8.h>
#include <tables/triangle_warm8192_int8.h>
#include <tables/TRIANGLE_VALVE_2_2048_int8.h>
#include <tables/SMOOTHSQUARE8192_int8.h>
#include <tables/SAW_ANALOGUE512_int8.h>
#include <tables/SIN512_int8.h>
#include <tables/BROWNNOISE8192_int8.h>
#include <tables/WHITENOISE8192_int8.h>
#include <tables/snaretable.h>

#include <Sample.h> // Sample template
Sample <SNARETABLE_NUM_CELLS, AUDIO_RATE> snare(SNARETABLE_DATA);

#include <mozzi_rand.h>

#include <Line.h> 
Line <long> kick; // Line <型> 変数名
Line <long> kick1; 
Line <long> kick2; 
Line <unsigned int> filt;

/*
#include <LowPassFilter.h>
LowPassFilter lpf;
*/

#include <StateVariable.h>

StateVariable <LOWPASS> svf;


#include <ADSR.h>                      //エンベロープ
ADSR <AUDIO_RATE, AUDIO_RATE> envB1;
ADSR <AUDIO_RATE, AUDIO_RATE> envB2;
ADSR <AUDIO_RATE, AUDIO_RATE> envB3;


#include <mozzi_midi.h>

// SIN2048_DATA2048のデータをaSinに格納  その他も同様

/*
Oscil <SQUARE_NO_ALIAS_2048_NUM_CELLS, AUDIO_RATE> triWarm1(SQUARE_NO_ALIAS_2048_DATA);
Oscil <SQUARE_NO_ALIAS_2048_NUM_CELLS, AUDIO_RATE> triWarm2(SQUARE_NO_ALIAS_2048_DATA);
Oscil <SQUARE_NO_ALIAS_2048_NUM_CELLS, AUDIO_RATE> triWarm3(SQUARE_NO_ALIAS_2048_DATA);
Oscil <SQUARE_NO_ALIAS_2048_NUM_CELLS, AUDIO_RATE> triWarm4(SQUARE_NO_ALIAS_2048_DATA); 
*/


//Oscil <SQUARE_NO_ALIAS_2048_NUM_CELLS, AUDIO_RATE> triWarm1(SQUARE_NO_ALIAS_2048_DATA);

Oscil <SAW2048_NUM_CELLS, AUDIO_RATE> triWarm1(SAW2048_DATA); 

/*
Oscil <SAW512_NUM_CELLS, AUDIO_RATE> triWarm1(SAW512_DATA); 
Oscil <SAW512_NUM_CELLS, AUDIO_RATE> triWarm2(SAW512_DATA); 
Oscil <SAW512_NUM_CELLS, AUDIO_RATE> triWarm3(SAW512_DATA); 
Oscil <SAW512_NUM_CELLS, AUDIO_RATE> triWarm4(SAW512_DATA); 
*/


//Oscil <TRIANGLE_VALVE_2_2048_NUM_CELLS, AUDIO_RATE> aSin(TRIANGLE_VALVE_2_2048_DATA);
Oscil <SIN512_NUM_CELLS, AUDIO_RATE> aSin(SIN512_DATA);

Oscil <BROWNNOISE8192_NUM_CELLS, AUDIO_RATE> Bnoise(BROWNNOISE8192_DATA);
//Oscil <WHITENOISE8192_NUM_CELLS, AUDIO_RATE> Bnoise(WHITENOISE8192_DATA);

//Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin(SIN2048_DATA);


/*
Oscil <TRIANGLE_WARM8192_NUM_CELLS, AUDIO_RATE> triWarm1(TRIANGLE_WARM8192_DATA);
Oscil <TRIANGLE_WARM8192_NUM_CELLS, AUDIO_RATE> triWarm2(TRIANGLE_WARM8192_DATA);
Oscil <TRIANGLE_WARM8192_NUM_CELLS, AUDIO_RATE> triWarm3(TRIANGLE_WARM8192_DATA);
Oscil <TRIANGLE_WARM8192_NUM_CELLS, AUDIO_RATE> triWarm4(TRIANGLE_WARM8192_DATA); 
*/

/*
Oscil <TRIANGLE_VALVE_2_2048_NUM_CELLS, AUDIO_RATE> triWarm1(TRIANGLE_VALVE_2_2048_DATA);
Oscil <TRIANGLE_VALVE_2_2048_NUM_CELLS, AUDIO_RATE> triWarm2(TRIANGLE_VALVE_2_2048_DATA);
Oscil <TRIANGLE_VALVE_2_2048_NUM_CELLS, AUDIO_RATE> triWarm3(TRIANGLE_VALVE_2_2048_DATA);
Oscil <TRIANGLE_VALVE_2_2048_NUM_CELLS, AUDIO_RATE> triWarm4(TRIANGLE_VALVE_2_2048_DATA);
*/

/*
Oscil <SMOOTHSQUARE8192_NUM_CELLS, AUDIO_RATE> triWarm1(SMOOTHSQUARE8192_DATA);
Oscil <SMOOTHSQUARE8192_NUM_CELLS, AUDIO_RATE> triWarm2(SMOOTHSQUARE8192_DATA);
Oscil <SMOOTHSQUARE8192_NUM_CELLS, AUDIO_RATE> triWarm3(SMOOTHSQUARE8192_DATA);
Oscil <SMOOTHSQUARE8192_NUM_CELLS, AUDIO_RATE> triWarm4(SMOOTHSQUARE8192_DATA);
*/

/*
Oscil <SAW_ANALOGUE512_NUM_CELLS, AUDIO_RATE> triWarm1(SAW_ANALOGUE512_DATA);
Oscil <SAW_ANALOGUE512_NUM_CELLS, AUDIO_RATE> triWarm2(SAW_ANALOGUE512_DATA);
Oscil <SAW_ANALOGUE512_NUM_CELLS, AUDIO_RATE> triWarm3(SAW_ANALOGUE512_DATA);
Oscil <SAW_ANALOGUE512_NUM_CELLS, AUDIO_RATE> triWarm4(SAW_ANALOGUE512_DATA);
*/


// トリガー(発音タイミング)のためのヘッダ
#include <EventDelay.h>
EventDelay kTriggerDelay;
EventDelay LEDdelay;

// スムースに値を変化させるためのヘッダ

byte  count=0;
byte  count1=0;
byte dcount=0;
byte melcount=0;
byte meltcount=0;
byte chcount=0;
byte chtime=0;
byte randmel;
uint8_t freq;

byte gainF;

byte dpat=0;

//byte dstep[32]={1,0,0,0,0,0,0,1, 0,0,1,0,0,0,0,0, 0,0,0,1,0,0,0,0, 0,0,0,1, 0,0,1,0}; 
//byte hstep[32]={0,0,1,1,0,0,1,0, 1,1,0,0,1,0,0,0, 0,0,1,1,0,0,1,0, 1,0,1,0, 0,1,1,0}; 

//byte melody1[30]={0,2,4,7,11,12 , 12, 14, 16, 19, 23,24, 24,26,28,31,35,36, 36,38,40,43,47,48, 48,43,52,55,40,35};   //メロディーのパターン
//byte melody1[20][4]={ {67,64,60,48},{67,62,59,47},{69,65,60,41},{71,65,62,43},  {69,64,61,45},{65,62,58,43},{67,64,58,36},{69,64,60,41},  {68,62,57,47},{66,62,57,47},{68,62,59,40},{64,60,55,36},   {68,62,59,40},{69,64,60,45},{70,65,62,43},{70,67,64,36},  {69,65,60,41},{67,64,61,45},{65,62,57,38},{65,60,56,46}  };                             

//byte melody1[8][3]={ {69,60,45}, {69,60,45}, {65,58,43},{67,58,36}, {69,60,41},{69,60,41}, {68,59,40},{68,59,40}};  
//byte melody[15]={48,50,52,55,57, 60,62,64,67,69, 72,74,76,79,81};                           


//byte melody1[4][3]={ {61,57,42},  {66,62,47},{61,56,42},{64,61,42}     };  
//byte melody[15]={44,47,59,61,64,66,69,71,73,76,78,81,83,85,88};  


//byte melody1[4][3]={ {60,55,44},  {62,53,43}, {60,51,46},{61,51,46}  }; 
//byte melody1[4][3]={ {60,55,44},  {62,53,43}, {62,51,44},{62,51,46}  }; 
//byte melody1[4][3]={ {60,55,44},  {62,53,43}, {58,62,46},{67,51,46}  }; 
//byte melody1[16][3]={  {60,55,44},  {62,53,43}, {62,51,44},{62,51,46},  {60,55,44},{62,53,43}, {65,55,46},{62,51,46}  , {60,55,44},  {62,53,43}, {58,62,46},{67,51,46}  , {65,51,44},  {70,58,46}, {65,62,46},{63,55,46}}; 

//byte melody[64]={63,65,67,70,72,67,70,67, 63,65,63,62,63,65,67,67, 70,65,70,75,74,75,68,67, 70,68,70,75,70,75,77,79, 82,77,79,75,79,74,79,74, 75,72,75,70,79,74,82,75 ,
//                 79,84,82,77,67,65,63,70, 75,72,77,79,82,86,84,87}; 
//byte melody[64]={60,65,67,70,67,62,63,60, 67,65,70,62,65,58,67,62, 70,67,65,62,74,75,75,72, 70,67,70,77,74,75,72,67, 82,77,79,74,63,67,77,70, 75,72,65,74,79,80,82,75,
//                 79,86,82,77,72,70,63,67, 75,72,79,74,82,72,80,75}; 
// byte melody[128]={63,65,67,70,72,65,70,67, 70,65,70,65,63,65,67,63, 70,72,70,72,74,75,72,70, 77,70,72,75,70,75,72,77,   82,77,79,75,79,75,79,74, 75,72,75,77,79,74,82,75 ,79,84,82,77,67,65,67,70, 75,72,77,79,82,86,84,87, 77,79,75,79,82,74,70,72, 74,75,79,72,67,72,77,79, 70,86,91,77,82,84,87,79, 82,82,74,77,72,75,72,74,          82,77,79,74,87,84,77,91, 75,72,86,74,79,84,82,89, 91,86,94,82,87,77,75,91, 75,86,82,79,82,87,84,79}; 

//byte meltrig1[16]=  {1,1,0,1, 1,0,1,0, 1,0,0,1, 1,0,1,1};
// byte meltrig2[32]={0,0,1,1, 1,1,0,1, 0,1,1,0, 0,1,1,0, 1,1,0,1, 1,1,0,0, 1,0,1,1 ,1,1,0,0}; 
                 
              
// byte melody[24]={50,51,53,55,58,60, 62,63,65,67,70,72, 74,75,77,79,82,84, 86,87,89,91,94,96}; 

/*
byte melody1[64][3]={ {59,50,43},{59,50,43},{62,54,45},{62,54,45}, {60,52,43},{60,52,43},{59,50,43},{62,54,45},  //G G D D C C G D
                     {59,55,40},{54,50,47},{57,48,40},{62,54,45}, {59,55,40},{54,50,47},{57,48,40},{62,54,45},  //Em Bm Am7 D Em Bm Am7 D
                     {60,52,43},{60,52,43},{54,50,47},{59,55,40}, {57,49,43},{57,49,43},{57,50,43},{62,54,45},  //C C Bm Em A7 A7 Dsus4 D
                     {59,50,43},{60,52,43},{62,54,45},{57,51,42}, {59,55,40},{62,59,52},{60,53,45},{59,53,43},  //G C D D#dim Em Em7 Dm7 G7
                     
                     {60,52,43},{60,52,43},{54,50,47},{59,55,40}, {57,49,43},{57,49,43},{57,50,43},{62,54,45},  //C C Bm Em A7 A7 Dsus4 D
                     {59,50,43},{60,52,43},{62,54,45},{57,51,42}, {59,55,40},{62,59,52},{60,53,45},{59,53,43},  //G C D D#dim Em Em7 Dm7 G7
                     {59,55,40},{54,50,47},{57,48,40},{62,54,45}, {59,55,40},{54,50,47},{57,48,40},{62,54,45},  //Em Bm Am7 D Em Bm Am7 D
                     {60,52,43},{60,52,43},{54,50,47},{59,55,40}, {57,49,43},{57,49,43},{57,50,43},{62,54,45},  //C C Bm Em A7 A7 Dsus4 D
                     };
byte melody[64] ={66,62,67,64,67,62,64,66, 64,67,69,66,64,67,62,60, 59,62,64,67,66,69,71,74, 71,69,67,74,66,69,74,71,
                 69,76,74,71,74,69,71,74, 67,71,76,74,71,69,64,71, 74,69,64,67,71,74,76,78, 79,81,76,71,74,67,76,83 
                } ;                    
*/


// コントロールレートをあらかじめ定義
#define CONTROL_RATE 256

void setup(){
  TIMSK0= 0;      //タイマー0割り込み停止
 
 startMozzi(CONTROL_RATE);
 kTriggerDelay.start(100);// トリガーのタイミング指定(100ms)
 LEDdelay.start(10);
 randSeed();
// pinMode(3,INPUT_PULLUP);
 pinMode(5,INPUT_PULLUP);               //トグルスイッチ
 pinMode(6,INPUT);                      //パルス用
 pinMode(2,OUTPUT);                    //内部led用                   
 pinMode(11,OUTPUT);                   //パネルled用

 snare.setFreq( 16*(float)SNARETABLE_SAMPLERATE/(float)SNARETABLE_NUM_CELLS );
 

}


void updateControl(){
/*     
byte dstep[32]={1,0,0,0, 0,0,0,1, 0,0,1,0, 0,0,0,0, 0,0,0,1, 0,0,0,0, 0,0,0,1, 0,0,1,0}; 
byte hstep[32]={0,0,1,1,0,0,1,0, 1,1,0,0,1,0,0,0, 0,0,1,1,0,0,1,0, 1,0,1,0, 0,1,1,0}; 
*/
/*
byte dstep[32]={1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0}; 
byte hstep[32]={0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,1,0}; 
*/

bool dstep[7][16]={ {1,0,0,1, 0,0,0,0, 1,0,0,1, 0,0,1,0}, 
                   {1,0,0,1, 0,0,1,0, 1,0,0,1, 0,1,0,0}, 
                   {1,0,0,0, 1,0,0,0, 1,0,0,0, 1,0,0,0}, 
                   {1,0,0,1, 0,0,1,0, 0,0,0,0, 0,0,0,0},
                   
                   {1,0,0,0, 0,0,0,0, 0,0,1,0, 0,0,0,0},
                   {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0},
                   {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0} }; 
                   
bool sstep[7][16]={ {0,0,0,0, 1,0,1,0, 0,0,0,0, 1,0,1,0}, 
                   {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0},
                   {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0}, 
                   {0,0,0,0, 0,0,0,0, 1,0,0,0, 0,0,0,1},
                   
                   {0,0,0,0, 1,0,1,0, 0,0,0,0, 1,0,1,0},
                   {0,0,0,0, 1,0,0,0, 0,0,0,0, 1,0,1,0},
                   {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0}};
                   
bool hstep[7][16]={ {0,0,1,0, 0,0,1,0, 0,0,1,0, 1,0,0,1}, 
                   {0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,1,0},
                   {0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,1,0}, 
                   {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0},
                   
                   {0,0,1,0, 0,0,1,0, 0,0,1,0, 1,0,0,1},
                   {0,0,1,0, 0,0,1,0, 0,0,1,0, 1,0,0,1},
                   {0,0,1,0, 0,0,1,0, 0,0,1,0, 0,0,1,0}};
                   
byte dpatt[7]={50,50,50,50,50,40,30};             

byte meltrig1[16]=  {1,1,1,1, 1,1,1,0, 1,1,1,1, 1,0,1,1};
byte meltrig2[32]={1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1, 1,1,1,1 ,1,1,1,1}; 

byte melody1[4][3]={ {60,55,44},  {62,53,43}, {60,51,46},{61,51,46}  }; 
byte melody[128]={63,65,67,70,72,65,70,67, 70,65,70,65,63,65,67,63, 70,72,70,72,74,75,72,70, 77,70,72,75,70,75,72,77,   82,77,79,75,79,75,79,74, 75,72,75,77,79,74,82,75 ,79,84,82,77,67,65,67,70, 75,72,77,79,82,86,84,87, 77,79,75,79,82,74,70,72, 74,75,79,72,67,72,77,79, 70,86,91,77,82,84,87,79, 82,82,74,77,72,75,72,74,          82,77,79,74,87,84,77,91, 75,72,86,74,79,84,82,89, 91,86,94,82,87,77,75,91, 75,86,82,79,82,87,84,79}; 


/*
byte melody1[64][3]={ {59,50,43},{59,50,43},{62,54,45},{62,54,45}, {60,52,43},{60,52,43},{59,50,43},{62,54,45},  //G G D D C C G D
                     {59,55,40},{54,50,47},{57,48,40},{62,54,45}, {59,55,40},{54,50,47},{57,48,40},{62,54,45},  //Em Bm Am7 D Em Bm Am7 D
                     {60,52,43},{60,52,43},{54,50,47},{59,55,40}, {57,49,43},{57,49,43},{57,50,43},{62,54,45},  //C C Bm Em A7 A7 Dsus4 D
                     {59,50,43},{60,52,43},{62,54,45},{57,51,42}, {59,55,40},{62,59,52},{60,53,45},{59,53,43},  //G C D D#dim Em Em7 Dm7 G7
                     
                     {60,52,43},{60,52,43},{54,50,47},{59,55,40}, {57,49,43},{57,49,43},{57,50,43},{62,54,45},  //C C Bm Em A7 A7 Dsus4 D
                     {59,50,43},{60,52,43},{62,54,45},{57,51,42}, {59,55,40},{62,59,52},{60,53,45},{59,53,43},  //G C D D#dim Em Em7 Dm7 G7
                     {59,55,40},{54,50,47},{57,48,40},{62,54,45}, {59,55,40},{54,50,47},{57,48,40},{62,54,45},  //Em Bm Am7 D Em Bm Am7 D
                     {60,52,43},{60,52,43},{54,50,47},{59,55,40}, {57,49,43},{57,49,43},{57,50,43},{62,54,45},  //C C Bm Em A7 A7 Dsus4 D
                     };
byte melody[64] ={66,62,67,64,67,62,64,66, 64,67,69,66,64,67,62,60, 59,62,64,67,66,69,71,74, 71,69,67,74,66,69,74,71,
                 69,76,74,71,74,69,71,74, 67,71,76,74,71,69,64,71, 74,69,64,67,71,74,76,78, 79,81,76,71,74,67,76,83 
                } ;                    
*/


unsigned int attackBa1, decayBa1, sustainBa1, releaseBa1;
unsigned int attackBa2, decayBa2, sustainBa2, releaseBa2;
unsigned int attackBa3, decayBa3, sustainBa3, releaseBa3;
//unsigned int attackBa4, decayBa4, sustainBa4, releaseBa4;
 
 bool pin5=digitalRead(5);               //トグルスイッチ
 bool pulse=digitalRead(6);               //   パルス入力
 bool check;
 bool trigger;  
 int dfreq; 
     
     if(pin5==1){                       //トグルスイッチの切り替えの判断
       trigger=kTriggerDelay.ready();        //シンセに内蔵のテンポで
       }else{                                     
         if(pulse==0&&check==0){                 //パルスが来て、かつチェックが0なら
           trigger=true;                          //トリガーする
           check=1;                                  //チェックを1にして次はトリガーしないようにする
           }else{
           trigger=false;                         
             }
          if(pulse==1){                               //パルスが0ならチェックを0にして次にパルスが1になった時にトリガー出来るようにする.
           check=0;
           }   
         }
      
 
     dpat=map(mozziAnalogRead(5),0,1024,0,7);
      int tempo=map(mozziAnalogRead(4),0,1024,0,500); 


      
      
      byte lf1=map(mozziAnalogRead(0),0,1024,40,200);
      byte lf2=20;

    //  byte freqrange=map(mozziAnalogRead(3),0,1024,0,7);;
     

     int ads=map(mozziAnalogRead(1),0,1024,0,100);
     int ads2=map(mozziAnalogRead(2),0,1024,10,500);
     
  //   int ads=((int)map(mozziAnalogRead(1),0,1024,0,100)); 
  //   int ads2=((int)map(mozziAnalogRead(2),0,1024,0,700)); 
             
  //   int ads=mozziAnalogRead(1);
  //   int ads2=mozziAnalogRead(2);
     

   //  int att1=map(ads,0,1024,5,200); 
   //  int de1=map(ads2,0,1024,10,450);
   //  int sus1=map(ads2,0,1024,10,450);
     //int re1=map(ads2,0,1024,10,450);
     

     //int att2=map(ads,0,1024,5,150); 
    // int de2=map(ads2,0,1024,5,400);
     //int sus2=map(ads2,0,1024,5,400);
    // int re2=map(ads2,0,1024,5,400);
     

  //   char ac=12;
    

      //  int tt=map(mozziAnalogRead(1),0,1024,2,20);

  
  
   attackBa1=ads;                                                 //ADSRの値を設定する
   decayBa1=ads2+30;
   sustainBa1=ads2+30;
   releaseBa1=ads+30;

   attackBa2=ads;                                                 //フィルターのADSRの値を設定する
   decayBa2=ads2;
   sustainBa2=10;
   releaseBa2=ads2;


   
   
   
   if(kTriggerDelay.ready()){
         
          digitalWrite(2,HIGH);   
          digitalWrite(11,HIGH);  

     if(pin5==1){
     switch (sstep[dpat][dcount]){
       case 0:

       break;
       case 1:
       snare.start();
       break;
       }
     switch (hstep[dpat][dcount]){
       case 0:
       Bnoise.setFreq(0);
       break;
       case 1:
       Bnoise.setFreq(100);
       break;
       }
   
          
     switch (dstep[dpat][dcount]){    // キック 配列dstepが0か1かで音が鳴るか鳴らないか判断する。  

     case 0:
       
   
       kick.set(0, 0, 0);  // 配列が0の時は音が鳴らないようにパラメータを0にする
       kick1.set(0, 0, 0); 
       kick2.set(0, 0, 0);
       break;

     case 1:
       
     
       kick.set(400, 140, 20); // Lineによる値の変化設定(初期値, 目標値, ステップ数)
       kick1.set(140, 80, 35); 
       kick2.set(80, 60, 100);
       break;
      }                     //キック switch 終わり

     }else{
       Bnoise.setFreq(0);
      
   
       kick.set(0, 0, 0);  // 配列が0の時は音が鳴らないようにパラメータを0にする
       kick1.set(0, 0, 0); 
       kick2.set(0, 0, 0);
       }
              
     
    // triWarm.setFreq(((int)rand((int)map(mozziAnalogRead(2),0,1024,0,12))+1)*80);                 //bassの周波数
     //  triWarm1.setFreq( mtof( (int)melody1[(int)rand(6)]+(int)((rand((int)map(mozziAnalogRead(2),0,1024,1,5))+2)*12)  )  ); 
     //  triWarm2.setFreq( mtof( (int)melody1[(int)rand(6)]+(int)((rand((int)map(mozziAnalogRead(2),0,1024,2,6))+2)*12)  )  ); 
     //  triWarm3.setFreq( mtof( (int)melody1[(int)rand(6)]+(int)((rand((int)map(mozziAnalogRead(2),0,1024,2,4))+2)*12)  )  ); 
     //  triWarm4.setFreq( mtof( (int)melody1[(int)rand(6)]+(int)((rand((int)map(mozziAnalogRead(2),0,1024,3,5))+2)*12)  )  ); 

     //  triWarm1.setFreq( mtof( (byte)melody1[(byte)map(mozziAnalogRead(3),0,1024,0,19)][0] +12 ))  ;    //0 1 4 6
     //  triWarm2.setFreq( mtof( (byte)melody1[(byte)map(mozziAnalogRead(3),0,1024,0,19)][1] +12))  ; 
     //  triWarm3.setFreq( mtof( (byte)melody1[(byte)map(mozziAnalogRead(3),0,1024,0,19)][2] +12))  ; 
     //  triWarm4.setFreq( mtof( (byte)melody1[(byte)map(mozziAnalogRead(3),0,1024,0,19)][3] +12))  ; 

    
      
      // triWarm1.setFreq( mtof( (byte)melody[(byte)map(mozziAnalogRead(3),0,1024,0,47)] +12 ))  ;  
     if(meltrig2[meltcount+rand(15)]==1){ 
      // triWarm1.setFreq(mtof( (byte)melody[melcount+((byte)map(mozziAnalogRead(3),0,1024,0,55))*2 ]  -(rand(4)-3)*12)  ) ; 
     // triWarm1.setFreq(mtof( (byte)melody[melcount+random(120) ]  -(rand(2)-1)*12)  ) ; 
      triWarm1.setFreq(mtof( (byte)melody[melcount+((byte)map(mozziAnalogRead(3),0,1024,0,55))*2 ] +rand(-4, 0)*12) )   ; 
       
      
     }else{
       triWarm1.setFreq( 0 );
       }
      //  triWarm1.setFreq( mtof( (byte)melody[rand((byte)map(mozziAnalogRead(3),0,1024,0,23)) ]  )    ) ;     
     if(meltrig1[chtime]==1){  

     
       
     }else{

      


     
          
     } 
     
     
     
     envB1.setADLevels((byte)250, (byte)140);                    // bassのエンベロープレベル   0~255
     envB1.setTimes(attackBa1, decayBa1,sustainBa1, releaseBa1);     // bassのエンベロープタイム
     envB1.noteOn();

     envB2.setADLevels(lf1, lf2);                    // bassのエンベロープレベル   0~255
     envB2.setTimes(attackBa2, decayBa2,sustainBa2, releaseBa2);     // bassのエンベロープタイム
     envB2.noteOn();

     envB3.setADLevels(220, 100);                    // bassのエンベロープレベル   0~255
     envB3.setTimes(0,dpatt[dpat],0, dpatt[dpat]);     // bassのエンベロープタイム
     envB3.noteOn();
     


   // filt.set(lf1,lf2, tc);
    

   
      count +=1; //  カウントを増やす 16になったらゼロにする 
      dcount +=1;
      melcount +=1;
      meltcount +=1;
      chcount =random(8);
      chtime +=1;
      if(count==8){                              // countおきに コードを変更
        count=0;
        count1 +=1;
        } 
      if(count1==4){                           // コードのカウント数
        count1=0;       
        }  
      if(dcount==16){                       //ドラムカウント
         dcount=0;
      //   dpat=random(6);
       }

      if(melcount==4){                         // メロディーのカウント数
        melcount=0;
        
        }   
      if(meltcount==16){                         // メロディーのトリガーカウント数
        meltcount=0;
        }       
      if(chcount==8){                         // chcountのカウント数
        chcount=0;
        }  
      if(chtime==16){                         //chtimeのカウント数
        chtime=0;
       
       }
      


       kTriggerDelay.start(tempo);
       
  }    //  kTrigger if文終わり

//   freq=filt.next();
     


//   lpf.setCutoffFreqAndResonance(freq, 200); 
    svf.setResonance(150);
 svf.setCentreFreq(freq*15);

      
    
   dfreq = kick.next(); // 変数freqにスムースな値の変化の結果を代入

   if(dfreq>140&& dfreq<=400){             // f1→f2の時はkick
     dfreq=kick.next();
     }else  if(dfreq>80&& dfreq<=140){     // f2→f3の時はkick1
     dfreq=kick1.next();
     }else  if(dfreq>60&& dfreq<=80){      // f3→f4の時はkick2 になるように
     dfreq=kick2.next();
     }

   if(dfreq > 60 && dfreq <= 400){
     aSin.setFreq(dfreq); // f4より大きい限り音を出力
    
     
     } else{
     kick.set(0, 0, 0); // スムースな値の変化設定の初期化
     aSin.setFreq(0); // 周波数を0に設定
    
     }

     digitalWrite(2,LOW); 
    digitalWrite(11,LOW);
  
}        //void updateControl()終わり 

int updateAudio(){
 envB1.update();
 envB2.update();
 envB3.update();
 freq=envB2.next();
 

 int env2=envB1.next();
  
  int add2=(env2*triWarm1.next()>>2  )>>3;
  
  int add3=   (svf.next(add2 >>3)  )  ;        // サイン波とノイズを足す ノイズはgainで256倍されているので8ビットシフト(=1/2^8倍)で音量を小さくする

//  return (add3*2+aSin.next()+((envB3.next()*Bnoise.next())>>10) );
   return (add3+2*aSin.next()+(snare.next())+((envB3.next()*Bnoise.next())>>9) )>>2;
}


void loop(){
 audioHook();
} 


いいなと思ったら応援しよう!

fendoap
よろしければサポートお願いします!