Freeware on Music

This page contains the source code for the Edit menu

Return to freeware page

Carnatic Music Hme Page

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

selectfun()
{
	int area,tab=0,col=38,row=8,c=0,r,n=0,v=0;
	char *p,tonot[6],fromnot[6];
	char str[6], str1[6];
	long int ctest;
	size(32,0);
	area=(15-5+1)*(55-23+1)*2;
	p=malloc(area);
	if(p==NULL)
	{
		errormesg(0,10);
		return(0);
	}
	if(mouseinit!=0)
		hidemsptr();
	savevideo(5,23,15,55,p);
	tonote=0;
	fromnote=0;
	menubox(5,23,15,55,112,7);
	drawbox(5,23,14,53,127);
	writestring(" Select ",5,35,127);
	writestring("Notes",7,36,112);
	writestring("From:",8,31,127);
	menubox(8,37,8,48,47,NO_SHADOW);
	sprintf(fromnot,"%.0f",fromnote);
	writestring(fromnot,8,38,47);
	writestring("To:",10,33,112);
	menubox(10,37,10,48,47,NO_SHADOW);
	sprintf(tonot,"%.0f",tonote);
	writestring(tonot,10,38,47);
	/*display OK button */
	menubox(12,34,13,43,32,HALF_SHADOW);
	writestring("O",12,37,46);
	writestring("K",12,38,47);
	messgline(4);
	if(mouseinit!=0)
		showms_ptr();
	while(v==0)
	{
		while(1)
		{
			if(mouseinit!=0)
				showms_ptr();
			size(6,7);
			gotoxy(col+c+1,row+1);
			getkey();
			if(ascii==27 || ((ascii==13) && c==0) || ((button==1) && (xgrid>=280 && xgrid<=320) && ygrid==112 ))
			{
				select=0;
				v=1;
				size(32,0);
				break;
			}
			else if(ascii==13 && c!=0 && button==0)
				break;
			 //backspace
			else if(ascii=='\b' &&  button==0)
			{
				if(c!=0)
				{
					c--;
					writechar(row,col+c,' ',47);
					if(tab==1)
					{
						tonote=tonote/10;
						if(tonote<1)
							tonote=0;
					}
					else if(tab==0)
					{
						fromnote=fromnote/10;
						if(fromnote<=1)
						fromnote=0;
					}
				}
			}
			// to check whether not a control character
			else if(isascii(ascii) && !iscntrl(ascii) && button==0 && isdigit(ascii) && c<=8)
			{
				writechar(row,col+c,ascii,47);
				if(tab==1)
				{
					tonote=ascii-48+tonote*10;
				}
				if(tab==0)
				{
					fromnote=ascii-48+fromnote*10;
				}
				c++;
			}
			else if(ascii==9) // TAB key
			{
				if(tab==0)
				{
					writestring("From:",8,31,112);
					writestring("To:",10,33,127);
					menubox(10,37,10,48,47,NO_SHADOW);
					col=38;
					row=10;
					tonote=0;
					c=0;
					size(32,0);
					size(6,7);
					gotoxy(col+c+1,row+1);
					tab=1;
				}
				else if(tab==1)
				{
					writestring("From:",8,31,127);
					writestring("To:",10,33,112);
					menubox(8,37,8,48,47,NO_SHADOW);
					col=38;
					row=8;
					fromnote=0;
					c=0;
					size(32,0);
					size(6,7);
					gotoxy(col+c+1,row+1);
					tab=0;
				}
			}
			else if((ascii==ESC || ascii=='O' || ascii=='o' || ascii==ENTER) && (button==0))
			{
				if(ascii==ESC)
					v=1;
				break;
			}
			else if((button==1) && ((xgrid>=272) && (xgrid<=328)) && (ygrid==96))
			{
				menubox(12,33,13,42,112,NO_SHADOW);
				menubox(12,35,12,42,32,NO_SHADOW);
				writestring("OK",12,38,46);
				delay(300);
				menubox(12,34,13,43,32,HALF_SHADOW);
				writestring("O",12,37,46);
				writestring("K",12,38,47);
				break;
			}
		}
		fclose(filpoint);
		filpoint=fopen(filespec,"rb");
		if(filpoint==NULL)
		{
			errormesg(0,8);
		}
		fseek(filpoint,0,SEEK_END);
		ctest=ftell(filpoint);
		n=ctest/6;
		fclose(filpoint);
		filpoint=fopen(filespec,"ab+");
		if(filpoint==NULL)
		{
			errormesg(0,9);
		}
		if(v==1)
			break;
		if(ntonote )
			v=0;
		else
			v=1;
		if(v==0)
		{
			errormesg(0,24);
			messgline(4);
		}
	}
	if(v==1 && ascii!=ESC && tonote!=0)
		select=1;
	size(32,0);
	if(mouseinit!=0)
		hidemsptr();
	restorevideo(5,23,15,55,p);
	free(p);
	status_line();
	if(mouseinit!=0)
		showms_ptr();
	return(0);
}

void clearfun()
{
	FILE *fp;
	int n=0;
	const char *delname="DEL.SNG";
	char not[10];
	notes=0;
	fclose(filpoint);
	fp=fopen(delname,"wb+");
	if(fp==NULL)
	{
		errormesg(0,7);
	}
	filpoint=fopen(filespec,"rb+");
	if(filpoint==NULL)
	{
		errormesg(0,8);
	}
	messgline(8);
	while(fread(¬e,sizeof(note),1,filpoint)==1)
	{
		++n;
		if(n==fromnote && fromnote<=tonote)
		{
			fromnote++;
		}
		else
		{
			++notes;
			fwrite(¬e,sizeof(note),1,fp);
		}
	}
	fclose(fp);
	fclose(filpoint);
	remove(filespec);
	rename(delname,filespec);
	filpoint=fopen(filespec,"ab+");
	if(filpoint==NULL)
	{
		errormesg(0,9);
	}
	sprintf(not,"%10.0f",notes);
	writestring(not,9,38,112);
	fromnote=0;
	tonote=0;
	select=0;
	saved=NO;
	status_line();
	if(mouseinit!=0)
		showms_ptr();
}

void copyfun()
{
	FILE *fp;
	const char *copyname="COPY.SNG";
	float n=0;
	fclose(filpoint);
	fp=fopen(copyname,"wb+");
	if(fp==NULL)
	{
		errormesg(0,7);
	}
	filpoint=fopen(filespec,"rb+");
	if(filpoint==NULL)
	{
		errormesg(0,8);
	}
	while(fread(¬e,sizeof(note),1,filpoint)==1)
	{
		++n;
		if((fromnote==(int)n) && fromnote<=tonote)
		{
			fwrite(¬e,sizeof(note),1,fp);
			fromnote++;
		}
	}
	fclose(fp);
	fclose(filpoint);
	copy=1;
	filpoint=fopen(filespec,"ab+");
	if(filpoint==NULL)
	{
		errormesg(0,9);
	}
}

void cutfun()
{
	FILE *fp,*fc;
	char *cutr="CUT.SNG", *cutp="CUTR.SNG",not[20];
	float n=0,count=0;
	fclose(filpoint);
	filpoint=fopen(filespec,"rb");
	if(filpoint==NULL)
	{
		errormesg(0,8);
	}
	fp=fopen(cutr,"wb+");
	if(fp==NULL)
	{
		errormesg(0,7);
	}
	fc=fopen(cutp,"wb+");
	if(fc==NULL)
	{
		errormesg(0,7);
	}
	while(fread(¬e,sizeof(note),1,filpoint)==1)
	{
		n++;
		if(fromnote<=(int)n && tonote>=(int)n)
		{
			fwrite(¬e,sizeof(note),1,fp);
		}
		else
		{
			fwrite(¬e,sizeof(note),1,fc);
			count++;
		}
	}
	fclose(filpoint);
	fclose(fc);
	fclose(fp);
	sprintf(not,"%10.0f",count);
	writestring(not,9,38,112);
	remove(filespec);
	{
		int h;
		h=rename(cutp,filespec);
		if(h!=0)
			errormesg(0,12);
	}
	cut=1;
	saved=NO;
	filpoint=fopen(filespec,"ab+");
	if(filpoint==NULL)
	{
		errormesg(0,9);
	}
}

void pastefun()
{
	FILE *fp,*pp;
	const char *copyname="COPY.SNG", *cutname="CUT.SNG", *pastename="PASTE.SNG";
	char not[20];
	float n=1, atnote=0,count=0;
	int area,r,col=34,row=10,c=0;
	char *p,tonot[6],atnot[6];
	char str[6], str1[6];
	size(32,0);
	if(mouseinit!=0)
		hidemsptr();
	area=(17-6+1)*(60-19+1)*2;
	p=malloc(area);
	if(p==NULL)
	{
		errormesg(0,10);
		return;
	}
	savevideo(6,19,16,60,p);
	menubox(6,25,15,50,112,7);
	drawbox(6,25,14,48,127);
	writestring(" Paste ",6,33,127);
	writestring("Note Number",8,30,112);
	writestring("After:",10,27,112);
	menubox(10,33,10,46,47,NO_SHADOW);
	sprintf(atnot,"%.0f",atnote);
	writestring(atnot,10,34,47);
	/*display OK button */
	menubox(12,32,13,41,32,HALF_SHADOW);
	writestring("O",12,35,46);
	writestring("k",12,36,47);
	if(mouseinit!=0)
		showms_ptr();

	while(1)
	{
		while(1)
		{
			if(mouseinit!=0)
				showms_ptr();
			size(6,7);
			gotoxy(col+c+1,row+1);
			getkey();
			if(ascii==27 || ((ascii==13) && c==0))
			{
				size(32,0);
				restorevideo(6,19,16,60,p);
				free(p);
				return;
			}
			else if(ascii==13 && c!=0 && button==0)
				break;
			 //backspace
			else if(ascii=='\b' &&  button==0)
			{
				if(c!=0)
				{
					c--;
					atnote=atnote/10;
					if(atnote<1)
					atnote=0;
					writechar(row,col+c,' ',47);
				}
			}
			// to check whether not a control character
			else if(isascii(ascii) && !iscntrl(ascii) && button==0 && isdigit(ascii) && c<=9)
			{
				writechar(row,col+c,ascii,47);
				atnote=ascii-48+atnote*10;
				c++;
			}
			else if((ascii==ESC || ascii=='O' || ascii=='o' || ascii==ENTER) && (button==0) || (button==1 && (xgrid>=256 && xgrid<=312) && ygrid==96))
			{
				size(32,0);
				if(button==1)
				{
					if(mouseinit!=0)
						hidemsptr();

					menubox(12,32,13,42,112,NO_SHADOW);
					menubox(12,33,12,40,32,NO_SHADOW);
					writestring("Ok",12,36,46);
					delay(150);
					menubox(12,32,13,41,32,HALF_SHADOW);
					writestring("Ok",12,35,32);
					delay(75);
				}
				break;
			}
		}
		fclose(filpoint);
		filpoint=fopen(filespec,"rb");
		if(filpoint==NULL)
		{
			errormesg(0,8);
		}
		else
		{
			rewind(filpoint);
			while(fread(¬e,sizeof(note),1,filpoint)==1)
			{
				count++;
			}
			if(atnote<=count && atnote>0)
				break;
			else
			{
				errormesg(0,24);
				menubox(10,33,10,46,47,NO_SHADOW);
				c=0;
				atnote=0;
			}
		}
	}
	fclose(filpoint);
	size(32,0);
	if(copy==1)
	{
		fp=fopen(copyname,"rb+");
		if(fp==NULL)
		{
			errormesg(0,8);
		}
	}
	if(cut==1)
	{
		fp=fopen(cutname,"rb+");
		if(fp==NULL)
		{
			errormesg(0,8);
		}
	}
	filpoint=fopen(filespec,"rb");
	if(filpoint==NULL)
	{
		errormesg(0,8);
	}
	pp=fopen(pastename,"wb+");
	if(pp==NULL)
	{
		errormesg(0,7);
	}
	rewind(filpoint);
	rewind(fp);
	if(copy==1)
	{
		while(1)
		{
			if(atnote==n)
				while(fread(¬e,sizeof(note),1,fp)==1)
				{
					fwrite(¬e,sizeof(note),1,pp);
					n++;
				}
			else if(fread(¬e,sizeof(note),1,filpoint)==1)
			{
				fwrite(¬e,sizeof(note),1,pp);
				n++;
			}
			else
				break;
		}
	}
	if(cut==1)
	{
		while(fread(¬e,sizeof(note),1,filpoint)==1)
		{
			n++;
			if(atnote==n)
				while(fread(¬e,sizeof(note),1,fp)==1)
				{
					fwrite(¬e,sizeof(note),1,pp);
					n++;
				}
			else
				fwrite(¬e,sizeof(note),1,pp);
		}
	}
	fclose(filpoint);
	fclose(pp);
	fclose(fp);
	if(mouseinit!=0)
		hidemsptr();

	restorevideo(6,19,16,60,p);
	free(p);
	n--;
	notes=n;
	sprintf(not,"%10.0f",notes);
	writestring(not,9,38,112);
	remove(filespec);
	remove(copyname);
	remove(cutname);
	{
		int h;
		h=rename(pastename,filespec);
		if(h!=0)
			errormesg(0,6);
	}
	filpoint=fopen(filespec,"ab+");
	if(filpoint==NULL)
	{
		errormesg(0,9);
	}
	saved=NO;
	select=0;
	cut=0;
	copy=0;
	size(32,0);
	if(mouseinit!=0)
		showms_ptr();
}

mergefun()
{
	char dname[30],*sname;
	FILE *fpd,*fps;
	int esc_flag;
	while(1)
	{
		messgline(5);
		esc_flag=ask_name("Enter Source Record",sname," Merge Records ");
		if(esc_flag==ESC)
		{
			status_line();
			return(0);
		}
		else
		{
			fps=fopen(sname,"rb");
			if(fps==NULL)
			{
				errormesg(0,8);
			}
			else
				break;
		}
	}
	while(1)
	{
		messgline(6);
		esc_flag=ask_name("Enter Destination Record",dname," Merge Records ");
		if(esc_flag==ESC)
		{
			status_line();
			return(0);
		}
		else
		{
			fpd=fopen(dname,"ab+");
			if(fpd==NULL)
			{
				errormesg(0,9);
			}
			else
				break;
		}
	}
	messgline(7);
	while(fread(¬e,sizeof(note),1,fps)==1)
	{
		fwrite(¬e,sizeof(note),1,fpd);
	}
	fclose(fps);
	fclose(fpd);
	status_line();
	return(0);
}