ELEC2645 (2019/20) / Mbed 2 deprecated el18loc_final

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Front.cpp Source File

Front.cpp

00001 #include "mbed.h"
00002 #include "Front.h"
00003 
00004 //Objects-----------------------------------------------------------------------
00005 Sound sound;
00006 Envelope envelope;
00007 Filter filter;
00008 
00009 //Sprites-----------------------------------------------------------------------
00010 const int fader[35][5] =   { //Fader Sprite
00011     { 1,1,1,1,1 },
00012     { 0,0,1,0,0 },
00013     { 0,0,1,0,0 },
00014     { 0,0,1,0,0 },
00015     { 0,0,1,0,0 },
00016     { 1,1,1,0,0 },
00017     { 0,0,1,0,0 },
00018     { 0,0,1,0,0 },
00019     { 0,0,1,0,0 },
00020     { 0,0,1,0,0 },
00021     { 1,1,1,0,0 },
00022     { 0,0,1,0,0 },
00023     { 0,0,1,0,0 },
00024     { 0,0,1,0,0 },
00025     { 0,0,1,0,0 },
00026     { 1,1,1,0,0 },
00027     { 0,0,1,0,0 },
00028     { 0,0,1,0,0 },
00029     { 0,0,1,0,0 },
00030     { 0,0,1,0,0 },
00031     { 1,1,1,0,0 },
00032     { 0,0,1,0,0 },
00033     { 0,0,1,0,0 },
00034     { 0,0,1,0,0 },
00035     { 0,0,1,0,0 },
00036     { 1,1,1,0,0 },
00037     { 0,0,1,0,0 },
00038     { 0,0,1,0,0 },
00039     { 0,0,1,0,0 },
00040     { 0,0,1,0,0 },
00041     { 1,1,1,0,0 },
00042     { 0,0,1,0,0 },
00043     { 0,0,1,0,0 },
00044     { 0,0,1,0,0 },
00045     { 1,1,1,1,1 },
00046 };
00047 
00048 const int sin_wav[6][28] =   {//sub 1 sin sprite
00049     { 0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0 },
00050     { 0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0 },
00051     { 1,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,1,0 },
00052     { 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1 },
00053     { 0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0 },
00054     { 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0 },
00055 };
00056 const int tri_wav[6][28] =   {//sub 2 tri sprite
00057     { 0,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 },
00058     { 0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0 },
00059     { 0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0 },
00060     { 1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0 },
00061     { 0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1 },
00062     { 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 },
00063 };
00064 const int square_wav[6][28] =   {//sub 3 sqr sprite
00065     { 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 },
00066     { 1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1 },
00067     { 0,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 },
00068     { 0,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 },
00069     { 0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0 },
00070     { 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 },
00071 };
00072 
00073 const int Low_pass[19][29]= {//LPF plot
00074     { 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 },
00075     { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
00076     { 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0 },
00077     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0 },
00078     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0 },
00079     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0 },
00080     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0 },
00081     { 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,0 },
00082     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0 },
00083     { 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 },
00084     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0 },
00085     { 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 },
00086     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0 },
00087     { 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 },
00088     { 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 },
00089     { 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,1,0,0,0 },
00090     { 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 },
00091     { 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 },
00092     { 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,1,0,0 },
00093 };
00094 
00095 const int High_pass[19][29]= {//HPF plot
00096     { 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 },
00097     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
00098     { 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
00099     { 0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
00100     { 0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
00101     { 0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
00102     { 0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
00103     { 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 },
00104     { 0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
00105     { 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 },
00106     { 0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
00107     { 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 },
00108     { 0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
00109     { 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 },
00110     { 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 },
00111     { 0,0,0,1,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 },
00112     { 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 },
00113     { 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 },
00114     { 0,0,1,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 },
00115 };
00116 
00117 const int Band_pass[19][29]= {//BPF plot
00118     { 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 },
00119     { 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0 },
00120     { 0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0 },
00121     { 0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0 },
00122     { 0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0 },
00123     { 0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0 },
00124     { 0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0 },
00125     { 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0 },
00126     { 0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0 },
00127     { 0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0 },
00128     { 0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0 },
00129     { 0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0 },
00130     { 0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0 },
00131     { 0,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,0 },
00132     { 0,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,0 },
00133     { 0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0 },
00134     { 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,1,0,0,0 },
00135     { 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,1,0,0,0 },
00136     { 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,1,0,0 },
00137 };
00138 
00139 //Gloabal Variables
00140 volatile int g_isr_flag; //used for sound generation
00141 volatile extern int silent_flag; //used for note release
00142 
00143 
00144 //constructor/destructor
00145 Front::Front()
00146 {
00147 }
00148 Front::~Front()
00149 {
00150 }
00151 //PUBLIC------------------------------------------------------------------------
00152 
00153 void Front::frontrun(N5110 &lcd, Gamepad &pad, int submenu)
00154 {
00155     frontsetup(lcd, pad, submenu,0, true);  //Initialises front pannel display
00156     frequency=frequency_convert(pad,oct); //collects initial frequency
00157     release_flag=silent_flag=0; //Flags setup
00158     used=menuflag=1;  //initialises vairables
00159     filter_type=envelope_in=0;
00160     a=d=s=r=17; //starting adsr values (1->35)
00161     noteon=false;
00162     oct=3; //starting octave
00163 #ifdef CSV
00164     itterator=0; //sets itterator for CSV OUTPUT
00165 #endif
00166 
00167     while (menuflag==1) {
00168 #ifdef SLOW_TIME
00169         print_SLOWTIME_out(out,noteon,a,d,s,r,release_flag,silent_flag); //debug terminal print function
00170 #endif
00171         if (noteon==true && g_isr_flag == 1) { //isr triggered and note on
00172             pad.write_u16(out); //writes Output in uns short format 
00173             envelope_in=(sound.sound_main(false,submenu,frequency)-32767); //int around 0
00174             envelope_in=filter.filter_run(envelope_in,filter_type,false);
00175             if (release_flag==0) { //Note still on
00176                 out=(envelope.env_in(a,d,s,r,envelope_in,false));//Uint around 32767
00177             }  else { //Note off
00178                 out=envelope.release(s,r,envelope_in,false); //release rubnthrough
00179                 if (silent_flag==1) { //release transient finished
00180                     release_flag=0; //resets variables
00181                     silent_flag=0;
00182                     noteon=false;
00183                     out=envelope.env_in(a,d,s,r,out,true); //initialises
00184                     out=0;
00185                 }
00186             }
00187             g_isr_flag=0; //resets ISR flag
00188 #ifdef CSV //generates CSV out
00189             printf("%d,%d\n",itterator,out);
00190             itterator++;
00191 #endif
00192         }
00193         dir=pad.get_direction(); //checks joystick
00194         if (dir!=dir_1) {
00195             //printf("dir =%d\n",dir); //debug
00196             switch (dir) {
00197                 case 3:
00198                     used=fader_select(used,1); break; //itterates Fader (R)
00199                 case 7:
00200                     used=fader_select(used,-1); break; //itterates fader(L)
00201                 case 1:
00202                     if (used==1) {
00203                         a=incrament_adsr(used,a,1); //Attack up
00204                     }
00205                     if (used==2) {
00206                         d=incrament_adsr(used,d,1); //Decay up
00207                     }
00208                     if (used==3) {
00209                         s=incrament_adsr(used,s,1); //Sustain Up
00210                     }
00211                     if (used==4) {
00212                         r=incrament_adsr(used,r,1); //Release Up
00213                     }
00214                     if (used==5) { //Filter UP
00215                         filter_type=incrament_adsr(used,filter_type,-1);
00216                         //printf("FILTER_TYPE=%d\n",filter_type);
00217                     }
00218                     break;
00219                 case 5:
00220                     if (used==1) {
00221                         a=incrament_adsr(used,a,-1); //Attack Down
00222                     }
00223                     if (used==2) {
00224                         d=incrament_adsr(used,d,-1); //Decay Down
00225                     }
00226                     if (used==3) {
00227                         s=incrament_adsr(used,s,-1); //Sustain Down
00228                     }
00229                     if (used==4) {
00230                         r=incrament_adsr(used,r,-1); //Release Down
00231                     }
00232                     if (used==5) { //Filter Down
00233                         filter_type=incrament_adsr(used,filter_type,1);
00234                         //printf("FILTER_TYPE=%d\n",filter_type);
00235                     }
00236                     break;
00237             }
00238             frontsetup(lcd,pad,submenu,filter_type,false); //reprints Front Panel
00239             printsliders(lcd,a,d,s,r,used); //Prints Sliders
00240             wait_ms(100); //Debounce
00241         } //END if DIR
00242         if ( pad.A_pressed())  { //NOTE ON
00243             //printf("NOTE_ON\n");
00244             noteon=true;
00245             out=envelope.env_in(a,d,s,r,out,true); //Initiialises
00246             frequency=frequency_convert(pad,oct); //Checks Frequnecy
00247         }
00248         if ( pad.B_pressed())  { //NOTE OFF
00249             release_flag=1; //Begins release
00250             envelope_in=envelope.release(s,r,envelope_in,true); //initialises
00251             pad.reset_buttons();
00252         }
00253         if ( pad.X_pressed())  { //Down Octave
00254             oct--;
00255             if (oct<0) { //Min Value
00256                 oct++;
00257             }
00258             //printf("OCTAVE %d\n",oct);
00259             pad.reset_buttons();
00260         }
00261         if ( pad.Y_pressed())  { //Octave Up
00262             oct++;
00263             if (oct>5) { //Max Value
00264                 oct--;
00265             }
00266             //printf("OCTAVE %d\n",oct);
00267             pad.reset_buttons();
00268         }
00269 
00270         if (pad.start_pressed())  { //Main Menu Select
00271             //printf("Main selected\n"); //debug
00272             noteon=false;
00273             menuflag=0; //sets flag to exit
00274             break;
00275         }
00276         dir=dir_1;
00277         sleep(); //puts sleep until ISR wakes up
00278     }
00279 }
00280 
00281 
00282 //PRIVATE-----------------------------------------------------------------------
00283 
00284 void Front::frontsetup(N5110 &lcd, Gamepad &pad, int submenu, int filter_type, bool initial)
00285 {
00286     if (initial==true) { //intial Setup
00287         printsliders(lcd,17,17,17,17,1); 
00288         initialise(pad,lcd,submenu); //Initialises functions
00289 
00290     }
00291     lcd.clear(); //Draws Front Pannel
00292     lcd.printString("A D S R",3,5);
00293     printfader(lcd,3,3);
00294     printfader(lcd,15,3);
00295     printfader(lcd,27,3);
00296     printfader(lcd,39,3);
00297     lcd.drawRect(50,3,30,8,FILL_TRANSPARENT);
00298     printwav(lcd,submenu); //Prints Waveform
00299     printfilter(lcd, filter_type); //Prints Filter Type
00300     lcd.refresh();
00301 }
00302 
00303 void Front::initialise(Gamepad &pad, N5110 &lcd, int submenu)
00304 {
00305     out=sound.sound_main(true,submenu,440); //initialises external variables
00306     out = filter.filter_run(out,1,true); //initialises LPF Filter
00307     out = filter.filter_run(out,2,true); //initialises HPF Filter
00308     out = filter.filter_run(out,3,true); //initialises BPF Filter
00309     out=envelope.env_in(17,17,17,17,out,true);
00310     out=envelope.release(17,17,out,true);
00311     printsliders(lcd,17,17,17,17,1);  //prints initialsliders
00312     pad.reset_buttons();
00313 }
00314 
00315 void Front::printsliders(N5110 &lcd, int a, int d, int s, int r, int used)
00316 {
00317     //printf("USED(SLIDERS)=%d\n",used);
00318     if(used==0) { //NONE
00319         printslider(lcd,3,a,false);
00320         printslider(lcd,15,d,false);
00321         printslider(lcd,27,s,false);
00322         printslider(lcd,39,r,false);
00323     }
00324     if(used==1) { //ATTACK
00325         printslider(lcd,3,a,true);
00326         printslider(lcd,15,d,false);
00327         printslider(lcd,27,s,false);
00328         printslider(lcd,39,r,false);
00329     }
00330     if(used==2) { //DECAY
00331         printslider(lcd,3,a,false);
00332         printslider(lcd,15,d,true);
00333         printslider(lcd,27,s,false);
00334         printslider(lcd,39,r,false);
00335     }
00336     if(used==3) { //SUSTAIN
00337         printslider(lcd,3,a,false);
00338         printslider(lcd,15,d,false);
00339         printslider(lcd,27,s,true);
00340         printslider(lcd,39,r,false);
00341     }
00342     if(used==4) { //Relase
00343         printslider(lcd,3,a,false);
00344         printslider(lcd,15,d,false);
00345         printslider(lcd,27,s,false);
00346         printslider(lcd,39,r,true);
00347     }
00348     if(used>=5) {
00349         printslider(lcd,3,a,false);
00350         printslider(lcd,15,d,false);
00351         printslider(lcd,27,s,false);
00352         printslider(lcd,39,r,false);
00353     }
00354     lcd.refresh();
00355 }
00356 
00357 void Front::printslider(N5110 &lcd, int x_val, int y_val, bool use)
00358 {
00359     if (use==true) {
00360         lcd.drawRect(x_val,37-y_val,5,2,FILL_BLACK);
00361     }
00362     if (use==false) {
00363         lcd.drawRect(x_val,37-y_val,5,1,FILL_BLACK);
00364     }
00365 }
00366 
00367 
00368 void Front::printfader(N5110 &lcd, int x, int y)
00369 {
00370     // x origin, y origin, rows, cols, sprite
00371     lcd.drawSprite(x,y,35,5,(int *)fader);
00372 }
00373 
00374 void Front::printwav(N5110 &lcd, int submenu)
00375 {
00376     if (submenu==1) {
00377         // x origin, y origin, rows, cols, sprite
00378         lcd.drawSprite(51,4,6,28,(int *)sin_wav); //sin
00379     }
00380     if (submenu==2) {
00381         // x origin, y origin, rows, cols, sprite
00382         lcd.drawSprite(51,4,6,28,(int *)tri_wav); //tri
00383     }
00384     if (submenu==3) {
00385         // x origin, y origin, rows, cols, sprite
00386         lcd.drawSprite(51,4,6,28,(int *)square_wav); //sqr
00387     }
00388 }
00389 
00390 void Front::printfilter(N5110 &lcd, int filter_type)
00391 {
00392     if (filter_type>=1) {
00393         lcd.drawLine(51,32,51,12,1); //y axis
00394         lcd.drawLine(51,32,81,32,1); //x axis
00395         if (filter_type==1) {
00396             lcd.drawSprite(52,13,19,29,(int *)Low_pass); //LPF
00397             lcd.printString("L",45,2);
00398         }
00399         if (filter_type==2) {
00400             lcd.drawSprite(52,13,19,29,(int *)High_pass); //HPF
00401             lcd.printString("H",45,2);
00402         }
00403         if (filter_type==3) {
00404             lcd.drawSprite(52,13,19,29,(int *)Band_pass); //BPF
00405             lcd.printString("B",45,2);
00406         }
00407     }
00408 }
00409 
00410 int Front::incrament_adsr(int used, int adsr, int ud)
00411 {
00412     if (used<=4) { //Num of Faders
00413         if (ud==1) { //Up
00414             adsr++;
00415             if (adsr>35) {
00416                 adsr--;
00417             }
00418         }
00419         if (ud==-1) {//Down
00420             adsr--;
00421             if (adsr<1) {
00422                 adsr++;
00423             }
00424         }
00425     }
00426     if (used==5) {
00427         adsr=incrament_filter(adsr,ud); //Filter Type Change
00428     }
00429     return(adsr);
00430 }
00431 
00432 int Front::incrament_filter(int adsr, int ud)
00433 {
00434     if (ud==1) { //UP
00435         adsr++;
00436         if (adsr>3) { //Max Filters
00437             adsr--;
00438         }
00439     }
00440     if (ud==-1) { //down
00441         adsr--;
00442         if (adsr<0) {
00443             adsr++;
00444         }
00445     }
00446     return(adsr);
00447 }
00448 
00449 int Front::frequency_convert(Gamepad &pad,int oct)
00450 {
00451     frequency=55*(pow(2.0,oct)); //Converts to correct Octave Start
00452     frequency=(frequency+(pad.read_pot1()*frequency)); //Generates Exact Frequency
00453     return(frequency);
00454 }
00455 
00456 int Front::fader_select(int used,int lr)
00457 {
00458     if (lr==1) { //Right
00459         used++;
00460         if (used>5) { //Max
00461             used=5;
00462         }
00463     }
00464     if(lr==-1) { ///Left
00465         used--;
00466         if(used<1) { //Min
00467             used=1;
00468         }
00469     }
00470     //printf("INCRAMENT USED= %d\n",used); //debug
00471     return(used);
00472 }
00473 
00474 #ifdef SLOW_TIME
00475 void Front::print_SLOWTIME_out (uint16_t out, bool noteon, int a, int d, int s, int r, int release_flag, int silent_flag)
00476 {
00477     //Prints all data required in SLOW_TIME
00478     printf("OUTPUT:%d\n",out);
00479     printf("NOTEON: %d\n",noteon);
00480     printf("A:%d,D:%d,S:%d,R:%d\n",a,d,s,r);
00481     printf("RelFlag=%d, SilFlag=%d\n\n",release_flag,silent_flag);
00482 }
00483 #endif