
/////////////////////////////////////////////////////////////////////////////
// PLAY PATTERNS AND PHRASES !!!
/////////////////////////////////////////////////////////////////////////////


//PLAYING PATTERN
unsigned char pattern[4][64];//pattern de 4 pistes !! ATTENTION, ON PEUT PAS STOCKER PLUS DE 256B EN ARRAY

unsigned char _tik=0;
unsigned char step=0;
unsigned char lastep=0;


const unsigned char chans[4]={
	{0},//voie 01 (drum10)
	{8},//voie 02 (bass09)
	{7},//voie 03 (matrix8)
	{0},//voie 04 (yam/c64)
};


const unsigned char patchans[4]={//pattern for corresponding channel
	{0x00},//voie 01 (drum10)
	{0x00},//voie 02 (bass09)
	{0x00},//voie 03 (matrix8)
	{0x00},//voie 04 (yam/c64)
};



// HOLD BUFFER
unsigned char hold1[16];// hold notes
unsigned char hold2[16];// hold notes

//PATTERN LENGTH default and max value is 16)
//char PAT_LENGTH=16;

void PUSH(){
	
	unsigned char i;

	if( _tik == 24 )_tik=0;  

	// PATTERN PLAY //
	if(_tik==0 || _tik==6 || _tik==12 || _tik==18){ // ON MORE STEP :)

		if(step==16)step=0;//16 step reset

		if(step==0){//Load Tracks From Bankstick !!!
			//for(i=0;i<4;i++)GETPAT(i,patchans[i]);// Each voices
		}

		/*
		MIOS_LCD_CursorSet(lastep);
		if(_tik==6){
			MIOS_LCD_PrintChar(0x00);//clr
		}else{
			MIOS_LCD_PrintChar(0x01);//clr
		}
		MIOS_LCD_CursorSet(step);
		MIOS_LCD_PrintChar(0x02);//pointer
		*/

		//Song position
		//MIOS_LCD_CursorSet(0xd0);// patch
		//MIOS_LCD_PrintCString("P:");//
		//MIOS_LCD_PrintBCD2(song_pos);

		//note=pattern[step][0];
		/*
		for(i=0;i<1;i++){// Each voices

			// CANAL MIDI POUR CHAQUE VOIE : chans[i]
			unsigned char midichan=chans[i];
	
			//La note : pattern[i][step]
			unsigned char note1=pattern[i][step];
			unsigned char note2=pattern[i][step+16];

			//unsigned char lastnote1=hold1[i];
			//unsigned char lastnote2=hold2[i];

			//kill les dernières notes

			if(hold1[i]!=0){
				MIOS_MIDI_TxBufferPut(144 + midichan);//Note
				MIOS_MIDI_TxBufferPut(hold1[i]);
				MIOS_MIDI_TxBufferPut(0x00);//velocity
			}
			if(hold2[i]!=0){
				MIOS_MIDI_TxBufferPut(144 + midichan);//Note
				MIOS_MIDI_TxBufferPut(hold2[i]);
				MIOS_MIDI_TxBufferPut(0x00);//velocity
			}

			//joue les nouvelles notes
			if(note1!=0x00){
				MIOS_MIDI_TxBufferPut(144 + midichan);//Note
				MIOS_MIDI_TxBufferPut(note1);
				MIOS_MIDI_TxBufferPut(0x7F);//velocity
			}
			if(note2!=0x00){
				MIOS_MIDI_TxBufferPut(144 + midichan);//Note
				MIOS_MIDI_TxBufferPut(note2);
				MIOS_MIDI_TxBufferPut(0x7F);//velocity
			}

			//mémorise les dernières notes
			hold1[i]=note1;
			hold2[i]=note2;


		}

		*/

		//LedDisp();//Display pos with leds
		MIOS_DOUT_SRSet(1,led_pos[step][0]);
		MIOS_DOUT_SRSet(2,led_pos[step][1]);
		///////////////
		lastep=step;//mem last step
		step++;//16 step counter

	}

	_tik++;
	return;
}



