int arduino_do_analog_in_whitecat()
{
int vfader=0;
int temp_ardniveauX1=0; 
int temp_ardniveauX2=0;

for(int p=0;p<arduino_max_analog;p++)
{
if(analog_data_from_arduino[p]!=previous_analog_data_from_arduino[p])
{
switch(arduino_analog_function_input[p])
{
case 1://affectation à un fader

vfader=arduino_analog_attribution_input[p];
Fader[vfader]=analog_data_from_arduino[p];  
midi_levels[vfader]=(Fader[vfader]/2);
index_fader_is_manipulated[vfader]=1; 
if(midi_send_out[vfader]==1){ index_send_midi_out[vfader]=1;}
if(lfo_mode_is[vfader]==1 || lfo_mode_is[vfader]==2 || lfo_cycle_is_on[vfader]==1)
{
lfo_mode_is[vfader]=0; lfo_mode_is[vfader]=0; lfo_cycle_is_on[vfader]=0;                           
}
break;
case 2://affectation au speed d un fader
vfader=arduino_analog_attribution_input[p];
lfo_speed[vfader]=analog_data_from_arduino[p]/2;
if(lfo_speed[vfader]<0){lfo_speed[vfader]=0;}
if(lfo_speed[vfader]>127){lfo_speed[vfader]=127;}
midi_levels[196+vfader]=lfo_speed[vfader];
index_send_midi_out[196+vfader]=1;
break;
case 3://grand master
//NIVEAU
if(index_allow_grand_master==1)
{
niveauGMaster=analog_data_from_arduino[p];  
midi_levels[615]=(niveauGMaster/2);
if(midi_send_out[615]==1){ index_send_midi_out[615]=1;}     
}
break;

case 4://sequenciel : Val 1 stage  Val 2 preset Val 3 speed 

if(arduino_analog_attribution_input[p]==0 || arduino_analog_attribution_input[p]==1 )//traitement du crossfade manuel 
{
// stage
if(arduino_analog_attribution_input[p]==0 )
{
temp_ardniveauX1=analog_data_from_arduino[p];     
if(index_get_back_faders_need_to_be_done==0)
{
index_go=0; index_go_back=0; index_pause=0;
niveauX1=analog_data_from_arduino[p];    
midi_levels[491]=niveauX1/2;
if(midi_send_out[491]==1){index_send_midi_out[491]=1;}      
}
}
// preset
if(arduino_analog_attribution_input[p]==1 ) 
{
temp_ardniveauX2=255-analog_data_from_arduino[p];
if(index_get_back_faders_need_to_be_done==0)
{
index_go=0; index_go_back=0; index_pause=0;
niveauX2=255-analog_data_from_arduino[p];   
midi_levels[492]=analog_data_from_arduino[p]/2;//inversion faite dans le midi
if(midi_send_out[492]==1){index_send_midi_out[492]=1;}        
}
}

//remise à jour du crossfade
if(temp_ardniveauX1==0 && temp_ardniveauX2==255)
{
index_go=0; index_go_back=0; index_pause=0;
next_mem_crossfade_finished(position_preset);
index_x1_x2_together=1;
index_get_back_faders_need_to_be_done=1;
refresh_integrated_gridplayer1();
}
if(temp_ardniveauX1==255 && temp_ardniveauX2==0)
{
index_get_back_faders_need_to_be_done=0;            
}
}
// speed
if(arduino_analog_attribution_input[p]==2)
{
crossfade_speed=analog_data_from_arduino[p]/2;
//if(midi_send_out[493]==1){index_send_midi_out[493]=1;}  
prepare_crossfade();
//ventilation_temps_vers_char();//icat
someone_changed_in_time_sequences=1;//icat
}
break;
case 5://MIDI CH0
simulate_midi(4,0,arduino_digital_function_input[p][1],analog_data_from_arduino[p]/2);
sprintf (my_midi_string, "Arduino Chan:%-2d Pitch:%-2d Vel:%-2d Typ: %s",	ischan,ispitch,isvel, "Ctrl-Chge");      
break;
case 6://MIDI CH1
simulate_midi(4,1,arduino_digital_function_input[p][1],analog_data_from_arduino[p]/2);
sprintf (my_midi_string, "Arduino Chan:%-2d Pitch:%-2d Vel:%-2d Typ: %s",	ischan,ispitch,isvel, "Ctrl-Chge");      
break;
case 7://MIDI CH2
simulate_midi(4,2,arduino_digital_function_input[p][1],analog_data_from_arduino[p]/2);
sprintf (my_midi_string, "Arduino Chan:%-2d Pitch:%-2d Vel:%-2d Typ: %s",	ischan,ispitch,isvel, "Ctrl-Chge");      
break;
case 8://MIDI CH3
simulate_midi(4,3,arduino_digital_function_input[p][1],analog_data_from_arduino[p]/2);
sprintf (my_midi_string, "Arduino Chan:%-2d Pitch:%-2d Vel:%-2d Typ: %s",	ischan,ispitch,isvel, "Ctrl-Chge");      
break;
case 9://MIDI CH4
simulate_midi(4,4,arduino_digital_function_input[p][1],analog_data_from_arduino[p]/2);
sprintf (my_midi_string, "Arduino Chan:%-2d Pitch:%-2d Vel:%-2d Typ: %s",	ischan,ispitch,isvel, "Ctrl-Chge");      
break;
case 10://MIDI CH5
simulate_midi(4,5,arduino_digital_function_input[p][1],analog_data_from_arduino[p]/2);
sprintf (my_midi_string, "Arduino Chan:%-2d Pitch:%-2d Vel:%-2d Typ: %s",	ischan,ispitch,isvel, "Ctrl-Chge");      
break;
case 11://MIDI CH6
simulate_midi(4,6,arduino_digital_function_input[p][1],analog_data_from_arduino[p]/2);
sprintf (my_midi_string, "Arduino Chan:%-2d Pitch:%-2d Vel:%-2d Typ: %s",	ischan,ispitch,isvel, "Ctrl-Chge");      
break;
case 12://MIDI CH7
simulate_midi(4,7,arduino_digital_function_input[p][1],analog_data_from_arduino[p]/2);
sprintf (my_midi_string, "Arduino Chan:%-2d Pitch:%-2d Vel:%-2d Typ: %s",	ischan,ispitch,isvel, "Ctrl-Chge");      
break;
case 13://MIDI CH8
simulate_midi(4,8,arduino_digital_function_input[p][1],analog_data_from_arduino[p]/2);
sprintf (my_midi_string, "Arduino Chan:%-2d Pitch:%-2d Vel:%-2d Typ: %s",	ischan,ispitch,isvel, "Ctrl-Chge");      
break;
case 14://MIDI CH9
simulate_midi(4,9,arduino_digital_function_input[p][1],analog_data_from_arduino[p]/2);
sprintf (my_midi_string, "Arduino Chan:%-2d Pitch:%-2d Vel:%-2d Typ: %s",	ischan,ispitch,isvel, "Ctrl-Chge");      
break;
case 15://MIDI CH10
simulate_midi(4,10,arduino_digital_function_input[p][1],analog_data_from_arduino[p]/2);
sprintf (my_midi_string, "Arduino Chan:%-2d Pitch:%-2d Vel:%-2d Typ: %s",	ischan,ispitch,isvel, "Ctrl-Chge");      
break;
case 16://MIDI CH11
simulate_midi(4,11,arduino_digital_function_input[p][1],analog_data_from_arduino[p]/2);
sprintf (my_midi_string, "Arduino Chan:%-2d Pitch:%-2d Vel:%-2d Typ: %s",	ischan,ispitch,isvel, "Ctrl-Chge");      
break;
case 17://MIDI CH12
simulate_midi(4,12,arduino_digital_function_input[p][1],analog_data_from_arduino[p]/2);
sprintf (my_midi_string, "Arduino Chan:%-2d Pitch:%-2d Vel:%-2d Typ: %s",	ischan,ispitch,isvel, "Ctrl-Chge");      
break;
case 18://MIDI CH13
simulate_midi(4,13,arduino_digital_function_input[p][1],analog_data_from_arduino[p]/2);
sprintf (my_midi_string, "Arduino Chan:%-2d Pitch:%-2d Vel:%-2d Typ: %s",	ischan,ispitch,isvel, "Ctrl-Chge");      
break;
case 19://MIDI CH14
simulate_midi(4,14,arduino_digital_function_input[p][1],analog_data_from_arduino[p]/2);
sprintf (my_midi_string, "Arduino Chan:%-2d Pitch:%-2d Vel:%-2d Typ: %s",	ischan,ispitch,isvel, "Ctrl-Chge");      
break;
case 20://MIDI CH15
simulate_midi(4,15,arduino_digital_function_input[p][1],analog_data_from_arduino[p]/2);
sprintf (my_midi_string, "Arduino Chan:%-2d Pitch:%-2d Vel:%-2d Typ: %s",	ischan,ispitch,isvel, "Ctrl-Chge");      
break;
default:
break;

}

}
previous_analog_data_from_arduino[p]=analog_data_from_arduino[p];
//mise en boite des datas

} 

return(0);
}
int do_logical_x1_x2(int x_seq,int y_seq)
{

/////////////////////////////////////CROSSFADE MANUEL/////////////////////////////

if(mouse_y>=y_seq+60 && mouse_y<=y_seq+100+255)//-20 +20
{
///////////////////X///////////////////////////////////////////////////////////
if(mouse_x> x_seq+480 && mouse_x< x_seq+480+45)
{


switch(miditable[0][491])
{
//midi report
case 0:
sprintf(thetypinfo,"Note");
break;
case 1:
sprintf(thetypinfo,"Key On");
break;
case 2:
sprintf(thetypinfo,"Key Off");
break;
case 4:
sprintf(thetypinfo,"Ctrl Change");
break;
}
sprintf(string_last_midi_id,"STAGE Fader is Ch: %d Pitch: %d Typ: %s" , miditable[1][491],miditable[2][491],thetypinfo);
if( Midi_Faders_Affectation_Type!=0)//config midi
{
attribute_midi_solo_affectation(491,Midi_Faders_Affectation_Mode);
mouse_released=1;
}
else
{
set_mouse_range(x_seq+480, y_seq+60, x_seq+480+45, y_seq+100+255);//pour pas deborder
index_go=0; index_go_back=0; index_pause=0;
niveauX1=(y_seq+80+255)-mouse_y;
if(niveauX1<0){niveauX1=0;}
if(niveauX1>255){niveauX1=255;}
if(midi_send_out[491]==1){index_send_midi_out[491]=1;}
if(index_x1_x2_together==1)
{
if(((255.0-ratio_X1X2_together)/255)==1.0){niveauX2=(255-niveauX1);}
else {niveauX2=remapX2[(255-niveauX1)];}
if(niveauX2<0){niveauX2=0;}
if(niveauX2>255){niveauX2=255;}
if(midi_send_out[492]==1){index_send_midi_out[492]=1;}
}
}
}

////////////////////X2////////////////////////////////////////////////////////////////
if(mouse_x> x_seq+580 && mouse_x< x_seq+580+45)
{


//midi report
switch(miditable[0][492])
{
//midi report
case 0:
sprintf(thetypinfo,"Note");
break;
case 1:
sprintf(thetypinfo,"Key On");
break;
case 2:
sprintf(thetypinfo,"Key Off");
break;
case 4:
sprintf(thetypinfo,"Ctrl Change");
break;
}
sprintf(string_last_midi_id,"Preset Fader is Ch: %d Pitch: %d Typ: %s" , miditable[1][492],miditable[2][492],thetypinfo);
if( Midi_Faders_Affectation_Type!=0)//config midi
{
attribute_midi_solo_affectation(492,Midi_Faders_Affectation_Mode);
mouse_released=1;
}
else
{
set_mouse_range(x_seq+580, y_seq+60, x_seq+580+45, y_seq+100+255);//pour pas deborder
index_go=0; index_go_back=0; index_pause=0;
niveauX2=(-1)*(mouse_y-(y_seq+80+255));
if(niveauX2<0){niveauX2=0;}
if(niveauX2>255){niveauX2=255;}
if(midi_send_out[492]==1){index_send_midi_out[492]=1;}
if(index_x1_x2_together==1)
{
if(((255.0-ratio_X1X2_together)/255)==1.0){niveauX1=(255-niveauX2);}
else { niveauX1=255-remapX1[niveauX2];     }
if(niveauX1<0){niveauX1=0;}
if(niveauX1>255){niveauX1=255;}
if (niveauX2==255){niveauX1=0;}//report à zero
if(midi_send_out[491]==1){index_send_midi_out[491]=1;}
}
}
}
if(niveauX1==0 && niveauX2==255)
{
index_go=0; index_go_back=0; index_pause=0;
next_mem_crossfade_finished(position_preset);
index_x1_x2_together=1;
mouse_released=1;
}
}


raccrochage_midi_logical_vertical_dmx ( x_seq+480, (y_seq+80), 491, 45, 255);//X1
raccrochage_midi_logical_vertical_dmx ( x_seq+580, (y_seq+80), 492, 45, 255);//X2 séparés car inversés pour l'affichage etc

//TOGETHER


if(mouse_x>  x_seq+535 && mouse_x<  x_seq+535+40 && mouse_y>=y_seq+80 && mouse_y<=y_seq+80+255)
{

ratio_X1X2_together=(int)((mouse_y)-(y_seq+80+255));

float fract_remplaX1=(255.0-ratio_X1X2_together)/255;
float remapis=255.0;
float fract_remplaX2=(255.0-ratio_X1X2_together)/255;
for(int mop=255;mop>=0;mop--)
{
remapis-=fract_remplaX1;
if (remapis>255){remapX1[mop]=255;}
else if(remapis<0){remapX1[mop]=0;}
else
{
remapX1[mop]=(int)(remapis);
}
}

for(int mop=0;mop<256;mop++)
{
remapis+=fract_remplaX2;
if (remapis>255){remapX2[mop]=255;}
else if(remapis<0){remapX2[mop]=0;}
else {remapX2[mop]=(int)(remapis);  }
}
}


if(mouse_x>  x_seq+540 && mouse_x<  x_seq+540+50 && mouse_y>y_seq+50 && mouse_y<y_seq+50+20)
{
if(index_x1_x2_together==0){index_x1_x2_together=1;}
else {index_x1_x2_together=0;}
mouse_released=1;
}




if(mouse_x>x_seq+540+14-20 && mouse_x<x_seq+540+14+20 && mouse_y>y_seq+80+255+40-20 && mouse_y<y_seq+80+255+40+20)
{


//midi report
 switch(miditable[0][495])
{
//midi report
case 0:
sprintf(thetypinfo,"Note");
break;
case 1:
sprintf(thetypinfo,"Key On");
break;
case 2:
sprintf(thetypinfo,"Key Off");
break;
case 4:
sprintf(thetypinfo,"Ctrl Change");
break;
}
sprintf(string_last_midi_id,"GO is Ch: %d Pitch: %d Typ: %s" , miditable[1][495],miditable[2][495],thetypinfo);
if(Midi_Faders_Affectation_Type!=0)//config midi
{
attribute_midi_solo_affectation(495,Midi_Faders_Affectation_Mode);
mouse_released=1;
}
else
{
do_go_function();
if(index_go==1 && index_pause==0)
{
do_send_bang();
}
mouse_released=1;
}
}


//////////////go back

if(mouse_x>x_seq+490+14-20 && mouse_x<x_seq+490+14+20 && mouse_y>y_seq+80+255+40-20 && mouse_y<y_seq+80+255+40+20)
{

//midi report
switch(miditable[0][494])
{
//midi report
case 0:
sprintf(thetypinfo,"Note");
break;
case 1:
sprintf(thetypinfo,"Key On");
break;
case 2:
sprintf(thetypinfo,"Key Off");
break;
case 4:
sprintf(thetypinfo,"Ctrl Change");
break;
}
  sprintf(string_last_midi_id,"GO BACK is Ch: %d Pitch: %d Typ: %s" , miditable[1][494],miditable[2][494],thetypinfo);
if( Midi_Faders_Affectation_Type!=0)//config midi
{
attribute_midi_solo_affectation(494,Midi_Faders_Affectation_Mode);
mouse_released=1;
}

else
{
do_go_back_function();
int banger_back_is=Banger_Memoire[position_preset]-1;
do_go_back_bang(banger_back_is);
mouse_released=1;
}
}


//////////////double go

if(mouse_x>x_seq+590+14-20 && mouse_x<x_seq+590+14+20 && mouse_y>y_seq+80+255+40-20 && mouse_y<y_seq+80+255+40+20)
{


//midi report
switch(miditable[0][496])
{
//midi report
case 0:
sprintf(thetypinfo,"Note");
break;
case 1:
sprintf(thetypinfo,"Key On");
break;
case 2:
sprintf(thetypinfo,"Key Off");
break;
case 4:
sprintf(thetypinfo,"Ctrl Change");
break;
}
  sprintf(string_last_midi_id,"GO BACK is Ch: %d Pitch: %d Typ: %s" , miditable[1][496],miditable[2][496],thetypinfo);
if( Midi_Faders_Affectation_Type!=0)//config midi
{
attribute_midi_solo_affectation(496,Midi_Faders_Affectation_Mode);
mouse_released=1;
}

else
{
do_double_go_function();
if(index_go==1 && index_pause==0)
{
do_send_bang();
}
mouse_released=1;
}
}

/////////////////////ACCELEROMETRE

if(mouse_x>=x_seq+490 && mouse_x<=x_seq+490+127 && mouse_y>y_seq+405 && mouse_y<y_seq+405+(45/2))
{



switch(miditable[0][493])
{
//midi report
case 0:
sprintf(thetypinfo,"Note");
break;
case 1:
sprintf(thetypinfo,"Key On");
break;
case 2:
sprintf(thetypinfo,"Key Off");
break;
case 4:
sprintf(thetypinfo,"Ctrl Change");
break;
}
sprintf(string_last_midi_id,"SpeedFader is Ch: %d Pitch: %d Typ: %s" , miditable[1][493],miditable[2][493],thetypinfo);

if(Midi_Faders_Affectation_Type!=0)//config midi
{
attribute_midi_solo_affectation(493,Midi_Faders_Affectation_Mode);
mouse_released=1;
}
else
{
set_mouse_range(x_seq+490, y_seq+405, x_seq+490+127, y_seq+405+(45/2));//pour pas deborder
crossfade_speed=mouse_x-(x_seq+490);
if(crossfade_speed<0){crossfade_speed=0;}
if(crossfade_speed>127){crossfade_speed=127;}
//integration gridplayer 1
if(index_link_speed_crossfade_to_gpl1==1)
{
grid_crossfade_speed[0]=crossfade_speed;
midi_levels[1508]=crossfade_speed;
gridder_prepare_cross(0,index_grider_selected[0],index_grider_step_is[0]);
}

if(midi_send_out[493]==1){index_send_midi_out[493]=1;}
prepare_crossfade();
//ventilation_temps_vers_char();//icat
someone_changed_in_time_sequences=1;//icat
}
}

//midi out des x1 et x2

if(mouse_x> x_seq+655-10 && mouse_x<  x_seq+655+10 && mouse_y>y_seq+340-10 && mouse_y<y_seq+340+10)
{

  if(midi_send_out[491]==0){midi_send_out[491]=1; }
  else if(midi_send_out[491]==1){midi_send_out[491]=0; }
  //report pour x2 et speed crossfade
  midi_send_out[492]=midi_send_out[491];
  mouse_released=1;
}


//MIDI OUT DU SPEED

if(mouse_x> x_seq+655-10 && mouse_x<  x_seq+655+10 && mouse_y>y_seq+340-10+85 && mouse_y<y_seq+340+10+85)
{
  if(midi_send_out[493]==0){midi_send_out[493]=1; }
  else if(midi_send_out[493]==1){midi_send_out[493]=0; }
  mouse_released=1;
}

raccrochage_midi_logical_horizontal ( x_seq+490, y_seq+405, 493,127,13);

//auto reset on link
if(mouse_x> x_seq+548 && mouse_x<  x_seq+548+15 && mouse_y>y_seq+435 && mouse_y<y_seq+435+15)
{
if( Midi_Faders_Affectation_Type!=0)
{
attribute_midi_solo_affectation(1591,Midi_Faders_Affectation_Mode);
}
else
{
auto_reset_crossfade_speed_on_link=toggle(auto_reset_crossfade_speed_on_link);
}
mouse_released=1;
}
return(0);
}