Freeware on Music

This page contains the source code for the Record Menu

Return to freeware page

Carnatic Music Hme Page

--------------------------

void new()
{
	int area,i;
	char *p,ptr[10];
	strcpy(filename,"NONAME.SNG");
	size(32,0);
	if(mouseinit!=0)
		hidemsptr();
	if(notedisp==0)
	{
		area=(17-6+1)*(60-19+1)*2;
		disparea=malloc(area);
		if(disparea==NULL)
		{
			errormesg(0,10);
		}
		savevideo(6,19,17,60,disparea);
	}
	menubox(6,19,17,60,112,7);
	drawbox(6,19,16,58,112);
	write_fname(filename);
	writestring("Notes:",9,32,112);
	writestring("Note:",10,33,112);
	writestring("Persistence:",12,26,112);
	writestring("Volume:",11,31,112);
	writestring("Pause:",13,32,112);
	if(mouseinit!=0)
		showms_ptr();
	filpoint=fopen(filespec,"wb+");
	if(filpoint==NULL)
	{
		errormesg(0,7);
	}
	notedisp=1;
	status_line();
}

openfun()
{
	FILE *op;
	int area,esc_flag=0;
	char not[10];
	if(notedisp==0)
	{
		notedisp=1;
		size(32,0);
		area=(17-6+1)*(60-19+1)*2;
		disparea=malloc(area);
		if(disparea==NULL)
		{
			errormesg(0,10);
		}
		if(mouseinit!=0)
			hidemsptr();
		savevideo(6,19,17,60,disparea);
		if(mouseinit!=0)
			showms_ptr();
		esc_flag=ask_name("Enter Record name",filename," Open Record ");
//		if(mouseinit!=0)
//			hidemsptr();
		size(32,0);
		if(esc_flag==ESC)
		{
			notedisp=0;
			return(0);
		}
		op=fopen(filename,"rb+");
		if(filpoint==NULL)
		{
			errormesg(0,8);
			notedisp=0;
			return(0);
		}
		filpoint=fopen(filespec,"wb+");
		if(filpoint==NULL)
		{
			errormesg(0,7);
			notedisp=0;
			return(0);
		}
		menubox(6,19,17,60,112,7);
		drawbox(6,19,16,58,112);
		write_fname(filename);
		writestring("Notes:",9,32,112);
		writestring("Note:",10,33,112);
		writestring("Persistence:",11,26,112);
		writestring("Volume:",13,31,112);
		writestring("Pause:",12,32,112);
		while(fread(¬e,sizeof(note),1,op)==1)
		{
			++notes;
			fwrite(¬e,sizeof(note),1,filpoint);
		}
		sprintf(not,"%10.0f",notes);
		writestring(not,9,38,112);
	}
	fclose(op);
	fclose(filpoint);
	filpoint=fopen(filespec,"ab+");
	if(filpoint==NULL)
	{
		errormesg(0,9);
	}
	if(mouseinit!=0)
		showms_ptr();
	return(0);
}

save()
{
	FILE *rp;
	char *savename;
	int esc_flag=0;
	float count=0;
	if(mouseinit!=0)
		hidemsptr();
	size(32,0);
	if( (strcmp(filename,"NONAME.SNG")==0))
	{
		while(1)
		{
			esc_flag=ask_name("Enter record name",savename," Save Record ");
			if(esc_flag==ESC)
			{
				if(mouseinit!=0)
					showms_ptr();
				return(ESC);
			}
			rp=fopen(savename,"rb");
			if(rp!=NULL)
			{
				if(mouseinit!=0)
					showms_ptr();
				esc_flag=message("Record Exists","Overwrite?");
				if(esc_flag=='Y' || esc_flag=='y')
				{
					fclose(rp);
					strcpy(filename,savename);
					break;
				}
				else if(esc_flag=='n' || esc_flag=='N')
				{
					if(mouseinit!=0)
						showms_ptr();
					return(0);
				}
			}
			else
			{
				strcpy(filename,savename);
				saved=NO;
				fclose(rp);
				break;
			}
		}
		write_fname(filename);
	}
	size(32,0);
	fclose(filpoint);
	filpoint=fopen(filespec,"rb");
	if(filpoint==NULL)
	{
		errormesg(0,8);
	}
	rewind(filpoint);
	rp=fopen(filename,"wb");
	if(rp==NULL)
	{
		errormesg(0,7);
	}
	while(fread(¬e,sizeof(note),1,filpoint)==1)
	{
		count++;
		fwrite(¬e, sizeof(note),1,rp);
	}
	fclose(rp);
	fclose(filpoint);
	filpoint=fopen(filespec,"ab+");
	if(filpoint==NULL)
	{
		errormesg(0,9);
	}
	if(mouseinit!=0)
		hidemsptr();
	menubox(24,0,24,79,112,NO_SHADOW);
	writestring("Saving Record...                           ",24,1,112);
	delay(700);
	status_line();
	saved=YES;
	if(mouseinit!=0)
		showms_ptr();
	return(1);
}

void check_saved()
{
	char ans;
	/* if file is not saved*/
	if(saved==NO && notedisp==1 && load==0)
	{
		ans=message("Record is not saved...","Save?");
		if(ans=='Y')
			save();
	}
}

void closefun()
{
	if(notedisp==1 && load==0)
	{
		check_saved();
		if(mouseinit!=0)
			hidemsptr();
		restorevideo(6,19,17,60,disparea);
		notedisp=0;
		notes=0;
	}
	if(load==1)
	{
		if(mouseinit!=0)
			hidemsptr();
		restorevideo(6,19,17,60,disparea);
		notedisp=0;
		load=0;
		notes=0;
	}
	saved=YES;
	strcpy(filename,"NONAME.SNG");
	fclose(filpoint);
	remove(filespec);
	select=0;
	free(disparea);
	if(mouseinit!=0)
		showms_ptr();
}

saveasfun()
{
	FILE *fs;
	char *sa;
	int esc_flag;
	fclose(filpoint);
	if(mouseinit!=0)
		hidemsptr();

	while(1)
	{
		esc_flag=ask_name("Enter Record Name",sa," Save As ");
		if(esc_flag==ESC)
		{
			return(0);
		}
		fs=fopen(sa,"rb");
		if(fs!=NULL)
		{
			if(mouseinit!=0)
				hidemsptr();

			esc_flag=message("Record Exists","Overwrite?");
			if(esc_flag=='Y' || esc_flag=='y')
				break;
			else if(esc_flag=='n' || esc_flag=='N')
			{
				return(0);
			}
		}
		else
			break;
	}
	if(saved==YES)
	{
		filpoint=fopen(filename,"rb");
		if(filpoint==NULL)
		{
			errormesg(0,8);
		}
		fs=fopen(sa,"wb");
		if(fs==NULL)
		{
			errormesg(0,7);
		}
		while(fread(¬e,sizeof(note),1,filpoint)==1)
		{
			fwrite(¬e,sizeof(note),1,fs);
		}
		fclose(filpoint);
		fclose(fs);
		write_fname(sa);
		strcpy(filename,sa);
		filpoint=fopen(sa,"ab+");
		if(filpoint==NULL)
		{
			errormesg(0,9);
		}
		saved=YES;
	}
	else if(saved==NO)
	{
		filpoint=fopen(filespec,"rb");
		if(filpoint==NULL)
		{
			errormesg(0,8);
		}
		fs=fopen(sa,"wb");
		if(fs==NULL)
		{
			errormesg(0,7);
		}
		while(fread(¬e,sizeof(note),1,filpoint)==1)
		{
			fwrite(¬e,sizeof(note),1,fs);
		}
		fclose(filpoint);
		fclose(fs);
		write_fname(sa);
		strcpy(filename,sa);
		filpoint=fopen(sa,"ab+");
		if(filpoint==NULL)
		{
			errormesg(0,9);
		}
		saved=YES;
	}
	if(mouseinit!=0)
		hidemsptr();
	return(0);
}

saveas()
{
	int success=0,esc_flag=0;
	FILE *fp;
	char lname[20];
	size(32,0);
	if(mouseinit!=0)
		hidemsptr();
	esc_flag=ask_name("Enter new file name",lname," Save Record As ");
	if(mouseinit!=0)
		hidemsptr();
	if(esc_flag==ESC)
	{
		return(0);
	}
	fclose(filpoint);
	fp=fopen(lname,"wb+");
	if(fp==NULL)
	{
		errormesg(0,7);
	}
	filpoint=fopen(filename,"rb");
	if(filpoint==NULL)
	{
		errormesg(0,8);
	}
	if(success==0)
		return(0);
	return(0);
}