Esempio n. 1
0
//start of main
void main(void)
{

    init_all();
    EA=TRUE;

	delay(5);	//Give Delay of 5 Seconds
    clear_screen_lcd();		//Clears LCD screen
    draw_piano();			//Draws a Piano
    delay(5);				//Give some time for it to draw.
    clear_screen_lcd();		//Clear LCD screen
    draw_drums();			//Draw Drums now

    while(1)
    {
    	delay(1);
    }
}
int title_screen(const char *commands[100], int *f, double noteinfo[2][1000], char output[1000]){

int xsize=1250;
int ysize=1000;
int xpos;
int ypos;
int height=400;
int width=(xsize-50)/16;
int i,j;
char input[20];
char initial[1000];
char c;
gfx_open(xsize, ysize, "Digital Piano");
quit_button();
draw_title(100);
draw_name(50);
draw_name2(50);
draw_button(295,600,70,310);
draw_button(645,600,70,310);
button_label(60);
button_label2(60);

while (1){

	c=gfx_wait();
	xpos=gfx_xpos();
	ypos=gfx_ypos();
	//user clicks the quit button
	if (xpos>=1110 && xpos<=1210 && ypos>=850 && ypos<=890){
		return 0;
	}

	//user clicks free play button
	if (xpos>=295 && xpos<=605 && ypos>=600 && ypos<=670){
		gfx_clear();
		piano_graphic(commands, f);

	}
	//user clicks load file button
	if (xpos>=645 && xpos<=955 && ypos>=600 && ypos<=670){
		terminal_message();
		printf("Please enter the name of the file, including the extension.\nThe file content should follow the same format as the examples in lab 8:\n");
		scanf("%s", input);
		//scans file name into input
		FILE *music=fopen(input, "r");
		if ((music=fopen(input, "r")) == NULL){
			//returns error if file not found
			puts("File could not be opened");
			return 0;
		}

		else{
			//scans the file into output
			for (j=0; j<1000; j++){
			fscanf(music, "%c", &output[j]);
			if (output[j]=='X'){
				break;
			}
			}
			
		}

		piano2(noteinfo, output);
		//fork to play sound while lighting up keys
		if (fork()){
			system("play sound.wav");
		}
		else{
		gfx_clear();
		draw_piano(width, height);
		draw_arrow(50, f);
		gfx_color(255,255,255);
		draw_box();
		octave_label(30);
		quit_button();
		gfx_flush();
		key_animation(noteinfo, f);
		return 0;
		}
	
	}

}

}