Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*****************************************************************/
- /* */
- /* CASIO fx-9860G SDK Library */
- /* */
- /* File name : [ProjectName].c */
- /* */
- /* Copyright (c) 2006 CASIO COMPUTER CO., LTD. */
- /* */
- /*****************************************************************/
- #include "fxlib.h"
- #include "serial.h"
- #include "MonochromeLib.h" // FICHIER DEFINISSANT LES FONCTIONS GRAPHIQUES
- #include "stdio.h"
- #include "stdlib.h"
- #include "string.h"
- #include "SH4comp.c"
- #include "test.h"
- #include "memory.h"
- #include "img.h"
- #include "EasyInput.h"
- //****************************************************************************
- // AddIn_main (Sample program main function)
- //
- // param : isAppli : 1 = This application is launched by MAIN MENU.
- // : 0 = This application is launched by a strip in eACT application.
- //
- // OptionNum : Strip number (0~3)
- // (This parameter is only used when isAppli parameter is 0.)
- //
- // retval : 1 = No error / 0 = Error
- //
- //****************************************************************************
- // une fonction qui affiche la fequence=>son (faite) et autre qui fait note =>frequence (faite)
- // *(array+octave*12+demi_ton)
- //#define NB_DEMI_TON 12
- #define r 1.059463094
- #define octave(x) ((int)x/12)
- #define place_note(note) ((note%12)== 0 || (note%12)== 2 || (note%12)== 4 || (note%12)== 5 || (note%12)== 7 || (note%12)== 9 || (note%12)== 11 ? note : note-1)
- /*static int SysCallCode[] = {0xD201422B,0x60F20000,0x80010070};
- static int (*SysCall)(int R4, int R5, int R6, int R7, int FNo ) = (void*)&SysCallCode;
- int RTC_getTicks()
- {
- return (*SysCall)(0, 0, 0, 0, 0x3B);
- }*/
- char *notes[12]=
- {
- "do",
- "do#",
- "re",
- "re#",
- "mi",
- "fa",
- "fa#",
- "sol",
- "sol#",
- "la",
- "la#",
- "si"
- };
- //short note=9; //correspond au la 3
- //short octave=3;
- double tempo=160.0;
- double length_rythme[]={
- 0.25, //double
- 0.5, // croche
- 0.75, //croche pointee
- 1, //noire
- 1.5, // noire pointee
- 2, //blanche
- 3, //blanche pointee
- 4 // ronde
- };
- void draw_part(unsigned char* notes, int decalx)
- {
- int i=0,j;
- unsigned int key;
- char buffer[50];
- Bdisp_AllClr_DDVRAM();
- //for(j=0;j<5;j++)
- //ML_horizontal_line(17+6*j, 0, 128, ML_BLACK); // on trace les lignes de la partition
- while(*(notes+i))
- {
- if (*(notes+i)>1)
- ML_bmp_or_cl(*(rythme+(int)*(notes+i+1)-1), 4.5*i-decalx, 32-2*(place_note(*(notes+i))-49)-21, 8, 16);
- else
- ML_bmp_or_cl(*(silence+(int)*(notes+i+1)-1), 4.5*i-decalx, 21, 8, 16);
- i+=2;
- }
- for(j=0;j<5;j++)
- ML_horizontal_line(17+6*j, 0, 128, ML_BLACK); // on trace les lignes de la partition
- ML_display_vram();
- return;
- }
- void edit_part(unsigned char *notes_lect)
- {
- int i=0,j; // decalage des notes
- unsigned int key;
- unsigned char note=45;
- unsigned char ryth=3;
- char buffer[50];
- unsigned char place_note;
- while(*(notes_lect+i+2)) i+=2; // si on réedite on va à la fin de la partoche
- while(1)
- {
- draw_part(notes_lect, 4.5*i-45);
- if (note>1)
- ML_bmp_or_cl(*(rythme+ryth), 50, 32-2*(place_note(note)-49)-21, 8, 16);
- else
- ML_bmp_or_cl(*(silence+ryth), 50, 21, 8, 16);
- //ML_bmp_or_cl(select, 49, 32-2*(note-49)-22, 11, 19);
- Mini("swit", 0);
- Mini("see", 5);
- sprintf(buffer,"note : %s",*(notes+note%12));
- PrintMini(80,15,buffer,0);
- //sprintf(buffer,"ryth : %d",ryth);
- // PrintMini(80,25,buffer,0);
- sprintf(buffer,"tempo : %.0f",tempo);
- PrintMini(80,25,buffer,0);
- GetKey(&key);
- switch(key)
- {
- case KEY_CTRL_UP : note++; break;
- case KEY_CTRL_DOWN : note--; break;
- case KEY_CTRL_LEFT : ryth=(ryth <=0 ? 7 : ryth-1); break;
- case KEY_CTRL_RIGHT : ryth=(ryth >=7 ? 0 : ryth+1); break;
- case KEY_CHAR_PLUS : tempo++; break;
- case KEY_CHAR_MINUS : tempo--; break;
- case KEY_CTRL_EXE : *(notes_lect+i)=note; *(notes_lect+1+i)=ryth+1; i+=2; break;
- case KEY_CTRL_F1 : note=(note >1 ? note = 1 : 45); break;
- case KEY_CTRL_F2 : case KEY_CTRL_DEL : *(notes_lect+i)=0; i-=2; break;
- case KEY_CTRL_F6 : return; // play
- }
- }
- }
- unsigned char* user_select(unsigned char* ch)
- {
- unsigned int key;
- int i,j,k,t;
- int p=0, offset=0;
- char x;
- char **files = memory_alloc(20);
- char *name_file=NULL;
- while(1)
- {
- x = memory_find("\\\\fls0\\*.cf",files,20);
- Bdisp_AllClr_VRAM();
- for(t=0;t<(x>5?5:x);t++)
- {
- PrintMini(1,1,(const unsigned char *)"your files : ",0);
- PrintMini(2,10*t+9,(const unsigned char *)*(files+offset+t),0);
- }
- if(x>0) Bdisp_AreaReverseVRAM(1,10*p+7,100,10*p+15);
- else PrintMini(36,29,(const unsigned char *)"no files found",0);
- Mini("new", 0);
- Mini("del", 1);
- Mini("exit", 5);
- GetKey(&key);
- switch(key)
- {
- if(x>0)
- {
- case KEY_CTRL_EXE :
- sprintf(ch,"\\\\fls0\\%s",*(files+(offset+p)));
- return ch;
- case KEY_CTRL_UP :
- if(offset || p)
- {
- if(p==4) p--;
- else if(offset)
- offset--;
- else p--;
- }
- break;
- case KEY_CTRL_DOWN :
- if(offset+p+1<x)
- {
- if(p==0) p++;
- else if(offset+5<x) offset++;
- else p++;
- }
- break;
- }
- case KEY_CTRL_F1 :
- Bdisp_AllClr_DDVRAM();
- PrintXY(2,1,"File name :",0);
- EI_init();
- EI_manage_config(EI_SET_COLUMN, 1);
- EI_manage_config(EI_SET_ROW, 3);
- EI_manage_config(EI_SET_START_MODE, EI_ALPHA_LOCKED);
- name_file=EI_input_string(8,(const char*)"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
- sprintf(ch,"\\\\fls0\\%s.cf",name_file);
- memory_createfile(ch,20);
- break;
- case KEY_CTRL_F2 :
- sprintf(ch,"\\\\fls0\\%s",*(files+(offset+p)));
- memory_deletefile(ch);
- break;
- // case KEY_CTRL_F
- case KEY_CTRL_F6 :
- memory_free(files,20);
- return NULL;
- }
- }
- }
- int AddIn_main(int isAppli, unsigned short OptionNum)
- {
- // double length=1.0; // a 60 batt/minute
- //double freq=440;
- int i=0;
- unsigned short taille_file;
- unsigned int key;
- char x;
- char buffer[50];
- unsigned char* ID_note; // On crée un pointeur sur int
- unsigned char* ch;
- //sprintf(ch,"\\\\crd0\\%s",files[memory_user_select(files,memory_find("\\\\crd0\\*sav*",files,20),1,0)]);
- ch= user_select(ch);
- /* while(*(data+taille_file)) taille_file++;
- for(i=0;i<taille_file;i++)
- *(ID_note+i)=*(data+i); */
- ID_note=memory_load(ch);
- if(ID_note==NULL) ID_note=calloc(100,sizeof(unsigned char));
- edit_part(ID_note);
- while(1)
- {
- draw_part(ID_note, 0);
- for(i=0;ID_note[i];i+=2);
- memory_save(ch,ID_note,i);
- Mini("edit", 0);
- Mini("save", 1);
- Mini("clear", 2);
- Mini("play", 5);
- GetKey(&key);
- switch(key)
- {
- case KEY_CTRL_EXIT : free(ID_note); return 1;
- case KEY_CTRL_F1 : edit_part(ID_note); break;
- case KEY_CTRL_F2 :
- {
- break;
- }
- case KEY_CTRL_F3 :
- {
- for(i=0;*(ID_note+i);i++)
- {
- *(ID_note+i)=0;
- }
- edit_part(ID_note);
- break;
- }
- case KEY_CTRL_F6 :jouer_partition(ID_note); break;
- }
- }
- return 1;
- }
- void jouer_partition(unsigned char* ID_note)
- {
- int i=0;
- //for(i=0;*(ID_note+i)<21;i+=2);
- while(*(ID_note+i))
- {
- //freq=440*power(r,*(ID_note+i)-45);
- draw_part(ID_note, 4.5*i-40);
- if(*(ID_note+i)>1) // on verifie que ce n'est pas un silence
- play_freq(440*power(r,*(ID_note+i)-45), (60/tempo**(length_rythme+*(ID_note+1+i))));
- else play_silence(60/tempo**(length_rythme+*(ID_note+1+i)));
- i+=2;
- }
- }
- float power(float x, int y)
- {
- float temp;
- if( y == 0)
- return 1;
- temp = power(x, y/2);
- if (y%2 == 0)
- return temp*temp;
- else
- {
- if(y > 0)
- return x*temp*temp;
- else
- return (temp*temp)/x;
- }
- }
- void Mini(char* chaine, int n ) // fonc defini le numero de la fonction
- {
- int i;
- short j;
- for(i=56 ; i<64 ; i++)
- Bdisp_DrawLineVRAM(n*21+2, i, n*21+20, i);
- while(chaine[j]) j++; // on calcul la longeur de la chaine
- if(j<4) i=4;
- else i=3;
- PrintMini(n*21+i, 58, chaine, 18);
- //ML_display_vram();
- }
- void play_silence(double length)
- {
- int i;
- double j;
- for(i=0;i<(int)(length*496);i++)
- {
- Sleep(2);
- }
- return;
- }
- void play_freq(double frequence , double length)
- {
- int i;
- double j;
- unsigned char config[] = {0, 5, 0, 0, 0, 0};
- Serial_Open(config);
- for(i=0;i<(int)(frequence*length*0.653);i++)
- {
- Serial_WriteByte(255);
- for (j=0;j<17.5;j+=0.211892619*frequence/440); // 0.211892619 => 2*((12)/square(2))
- }
- Serial_Close(1);
- return;
- }
- void lecteur_son(int *ID, int *length)
- {
- short i=0;
- //double freq;
- while(*(ID+i))
- {
- if(*(ID+i)>1)
- play_freq(440*power(r,*(ID+i)-45), (60/tempo**(length_rythme+*(length+i))));
- else play_silence(60/tempo**(length_rythme+*(length+i)));
- i++;
- }
- return;
- }
- /*double calcul_frequence()
- {
- double frequence;
- //short nb_de_demi_ton=0;
- char buffer[50];
- unsigned int key;
- while(1)
- {
- Bdisp_AllClr_DDVRAM();
- sprintf(buffer,"note : %s",notes[note]);
- PrintMini(10,30,buffer,0);
- sprintf(buffer,"%d",octave);
- PrintMini(37+5*strlen(notes[note]),32,buffer,0);
- sprintf(buffer,"freq : %.2f",440*power(r,12*octave+note-45));
- PrintMini(10,20,buffer,0);
- sprintf(buffer,"tempo : %.0f",tempo);
- PrintMini(10,40,buffer,0);
- GetKey(&key);
- switch(key)
- {
- case KEY_CTRL_UP :
- {
- if (note<11)
- {
- note++;
- }
- else
- {
- note=0;
- octave=(octave<7 ? octave+1 : 0);
- }
- break;
- }
- case KEY_CTRL_DOWN :
- {
- if(note>0)
- {
- note--;
- }
- else
- {
- note=11;
- octave=(octave>0 ? octave-1 : 7);
- }
- break;
- }
- case KEY_CHAR_PLUS : tempo+=10; break;
- case KEY_CHAR_MINUS : tempo-=10; break;
- case KEY_CTRL_EXE : return 440*power(r,12*octave+note-45);
- }
- }
- }*/
- //****************************************************************************
- //************** ****************
- //************** Notice! ****************
- //************** ****************
- //************** Please do not change the following source. ****************
- //************** ****************
- //****************************************************************************
- #pragma section _BR_Size
- unsigned long BR_Size;
- #pragma section
- #pragma section _TOP
- //****************************************************************************
- // InitializeSystem
- //
- // param : isAppli : 1 = Application / 0 = eActivity
- // OptionNum : Option Number (only eActivity)
- //
- // retval : 1 = No error / 0 = Error
- //
- //****************************************************************************
- int InitializeSystem(int isAppli, unsigned short OptionNum)
- {
- return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
- }
- #pragma section
Advertisement
Add Comment
Please, Sign In to add comment