home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
d
/
dir_nm20.zip
/
Dir_NM_2.0
/
Dir_TTS
/
tts.m
< prev
next >
Wrap
Text File
|
1992-07-16
|
9KB
|
280 lines
/*
tts.m --- NM to Score translater
*/
#import <musickit/musickit.h>
#import <musickit/synthpatches/synthpatches.h>
#import <musickit/pitches.h>
#import "tts.h"
int Speed,Percent,V_Fit[3],Fit[3][7];
double T[3],T_H_tmp[3],T_L_tmp[3];
id Nt_on,Nt_off,IM_score,Pt[3][4],Pt_tmp[6],ampEnvelope,freqEnvelope;
id Pt_rec[8],IM_info;
int Nt_Y(Nt,At_high)
int Nt,At_high;
{
int Y;
Y=26;
if (At_high==1 || At_high==2)
switch(Nt)
{
case 48:Y=29;break; case 50:Y=28;break; case 52:Y=27;break;
case 53:Y=26;break; case 55:Y=25;break; case 57:Y=24;break;
case 59:Y=23;break; case 60:Y=22;break; case 62:Y=21;break;
case 64:Y=20;break; case 65:Y=19;break; case 67:Y=18;break;
case 69:Y=17;break; case 71:Y=16;break; case 72:Y=15;break;
case 74:Y=14;break; case 76:Y=13;break; case 77:Y=12;break;
case 79:Y=11;break; case 81:Y=10;break; case 83:Y=9;break;
case 84:Y=8;break; case 86:Y=7;break; case 88:Y=6;break;
case 89:Y=5;break; case 91:Y=4;break; case 93:Y=3;break;
case 95:Y=2;break; case 96:Y=1;break; case 98:Y=0;break;
}
else switch(Nt)
{
case 21:Y=53;break; case 23:Y=52;break; case 24:Y=51;break;
case 26:Y=50;break; case 28:Y=49;break; case 29:Y=48;break;
case 31:Y=47;break; case 33:Y=46;break; case 35:Y=45;break;
case 36:Y=44;break; case 38:Y=43;break; case 40:Y=42;break;
case 41:Y=41;break; case 43:Y=40;break; case 45:Y=39;break;
case 47:Y=38;break; case 48:Y=37;break; case 50:Y=36;break;
case 52:Y=35;break; case 53:Y=34;break; case 55:Y=33;break;
case 57:Y=32;break; case 59:Y=31;break; case 60:Y=30;break;
case 62:Y=29;break; case 64:Y=28;break; case 65:Y=27;break;
case 67:Y=26;break; case 69:Y=25;break; case 71:Y=24;break;
case 72:Y=23;break;
}
if (At_high<2) Y+=V_Ht/4;
return Y;
}
int Fix_Note(nt,At_High)
int nt,At_High;
{
int i;
for (i=0;i<7;i++)
if (Nt_Y(nt,At_High)==Fit[At_High][i] || Nt_Y(nt,At_High)==Fit[At_High][i]-8
|| Nt_Y(nt,At_High)==Fit[At_High][i]-16
|| Nt_Y(nt,At_High)==Fit[At_High][i]-24
|| Nt_Y(nt,At_High)==Fit[At_High][i]+8
|| Nt_Y(nt,At_High)==Fit[At_High][i]+16
|| Nt_Y(nt,At_High)==Fit[At_High][i]+24)
return (nt+V_Fit[At_High]);
return nt;
}
char *Sub_Str(string,head,length)
char *string;
int head,length;
{
char *sub;
int i;
sub=(char *)malloc(5000);*sub='\0';i=-1;
if (strlen(string)>head && string[head]!='\n')
{
do
{
i++;sprintf(sub+strlen(sub),"%c",string[head+i]);
} while (i<length-1 && string[head+i]!='\n');
}
return sub;
}
int Load_From_Text(filename)
char *filename;
{
int i,j;
char Line[100],Word_buf[3000];
if ((Textfile=fopen(filename,"r"))==NULL) exit(0);;
S_bf=(char *)malloc(10);*S_bf='\0';
for (j=0;j<3;j++)
{
for (i=0;i<St_Start;i++)
{
St[i][j].nt[0]=0;St[i][j].nt[1]=0;
St[i][j].nt[2]=0;St[i][j].nt[3]=0;
St[i][j].act=0;St[i][j].vol=100;
}
for (i=St_Start;i<M_Len;i++)
{
St[i][j].nt[0]=200;St[i][j].nt[1]=0;
St[i][j].nt[2]=0;St[i][j].nt[3]=0;
St[i][j].act=0;St[i][j].vol=100;
}
}
setvbuf(Textfile,buf,_IOFBF,2048);rewind(Textfile);S_bf=(char *)malloc(10);
*S_bf='\0';i=0;fgets(Line,100,Textfile);fgets(Word_buf,3000,Textfile);
do {
fgets(Line,100,Textfile);S_bf=(char *)malloc(10);*S_bf='\0';
for (j=0;j<4;j++) St[i][0].nt[j]=atoi(strncpy(S_bf,Line+4*j,4));
St[i][0].act=atoi(strncpy(S_bf,Line+4*4,4));
St[i][0].vol=atoi(strncpy(S_bf,Line+4*5,4));
for (j=6;j<10;j++) St[i][1].nt[j-6]=atoi(strncpy(S_bf,Line+4*j,4));
St[i][1].act=atoi(strncpy(S_bf,Line+4*10,4));
St[i][1].vol=atoi(strncpy(S_bf,Line+4*11,4));
for (j=12;j<16;j++) St[i][2].nt[j-12]=atoi(strncpy(S_bf,Line+4*j,4));
St[i][2].act=atoi(strncpy(S_bf,Line+4*16,4));
St[i++][2].vol=atoi(strncpy(S_bf,Line+4*17,4));
} while ((St[i-1][0].nt[0]!=200 || St[i-1][1].nt[0]!=200 ||
St[i-1][2].nt[0]!=200) && i<M_Len-1);
if (Textfile != NULL) fclose(Textfile);Textfile= NULL;
Speed=St[3][1].nt[0];Percent=St[4][1].nt[0];
for (j=0;j<3;j++)
{
if ((V_Fit[j]=St[6][i].nt[0])!=0)
for (i=0;i<7;i++)
switch (i)
{
case 0:Fit[j][i]=St[St_Start-3][j].nt[1];break;
case 1:Fit[j][i]=St[St_Start-2][j].nt[1];break;
case 2:Fit[j][i]=St[St_Start-2][j].nt[2];break;
case 3:Fit[j][i]=St[St_Start-2][j].nt[3];break;
case 4:Fit[j][i]=St[St_Start-1][j].nt[1];break;
case 5:Fit[j][i]=St[St_Start-1][j].nt[2];break;
case 6:Fit[j][i]=St[St_Start-1][j].nt[3];break;
}
}
return 1;
}
void Add_One_Note(At_high,Num,Freq,Vol,Time_A,Time_Z)
int At_high,Num;
double Freq,Vol,Time_A,Time_Z;
{
if (At_high!=-1)
{
Nt_on=[[Note alloc] initWithTimeTag:Time_A];
Nt_off=[[Note alloc] initWithTimeTag:Time_Z];
[Nt_on setNoteType:MK_noteOn];[Nt_off setNoteType:MK_noteOff];
[Nt_on setNoteTag:MKNoteTag()];[Nt_off setNoteTag:[Nt_on noteTag]];
[Nt_on setPar:MK_keyNum toDouble:Freq];[Nt_on setPar:MK_amp toDouble:Vol];
[Pt[At_high][Num] addNote:Nt_on];[Pt[At_high][Num] addNote:Nt_off];
}
else
{
Nt_on=[[Note alloc] initWithTimeTag:Time_A];
Nt_off=[[Note alloc] initWithTimeTag:Time_Z];
[Nt_on setNoteType:MK_noteOn];[Nt_off setNoteType:MK_noteOff];
[Nt_on setNoteTag:MKNoteTag()];[Nt_off setNoteTag:[Nt_on noteTag]];
[Nt_on setPar:MK_keyNum toDouble:Freq];[Nt_on setPar:MK_amp toDouble:Vol];
[Pt_tmp[Num] addNote:Nt_on];[Pt_tmp[Num] addNote:Nt_off];
}
}
void Add_Note_To_Part()
{
int i,j,k,nt[3],Nt,Tmp_H_pt[3],Tmp_L_pt[3];
double act[3],vol[3],act_H_tmp[3],act_L_tmp[3],P_act,P_vol;
i=St_Start-1;T[0]=T[1]=T[2]=0.0;P_act=0.0003*(double)Percent;P_vol=0.009;
for (j=0;j<3;j++)
{ Tmp_H_pt[j]=2;Tmp_L_pt[j]=2;T_H_tmp[j]=0.0;T_L_tmp[j]=0.0; }
do {
for (k=0;k<3;k++)
{
nt[k]=St[i+1][k].nt[0];act[k]=P_act*(double)St[i][k].act;
vol[k]=P_vol*(double)St[i][k].vol;
for (j=0;j<4;j++)
{
Nt=St[i][k].nt[j];
if (Nt!=600)
{
if (Nt>0)
{
if (200<Nt && Nt<328) Nt-=200;
else if (St[6][k].nt[0]!=0) Nt=Fix_Note(Nt,1);
Add_One_Note(k,j,(double)Nt,vol[k],T[k],T[k]+act[k]);
}
}
}
T[k]+=act[k];
}
for (j=0;j<3;j++)
{
if (St[2][1].nt[j+1]!=200 && St[Tmp_H_pt[j]][1].nt[j+1]!=0)
{
act_H_tmp[j]=(double)St[Tmp_H_pt[j]][1].nt[j+1];
if (act_H_tmp[j]==200.0)
{
Tmp_H_pt[j]=2;
act_H_tmp[j]=(double)St[Tmp_H_pt[j]][1].nt[j+1];
}
if (act_H_tmp[j]>0)
{
act_H_tmp[j]=P_act*act_H_tmp[j];
Add_One_Note(-1,j,60.0,0.8,T_H_tmp[j],
T_H_tmp[j]+act_H_tmp[j]/3.0);
}
}
if (St[2][2].nt[j+1]!=200 && St[Tmp_L_pt[j]][2].nt[j+1]!=0)
{
act_L_tmp[j]=(double)St[Tmp_L_pt[j]][2].nt[j+1];
if (act_L_tmp[j]==200.0)
{
Tmp_L_pt[j]=2;
act_L_tmp[j]=(double)St[Tmp_L_pt[j]][2].nt[j+1];
}
if (act_L_tmp[j]>0)
{
act_L_tmp[j]=P_act*act_L_tmp[j];
Add_One_Note(-1,j+3,-60.0,0.8,T_L_tmp[j],
T_L_tmp[j]+act_L_tmp[j]/3.0);
}
}
T_H_tmp[j]+=fabs(act_H_tmp[j]);T_L_tmp[j]+=fabs(act_L_tmp[j]);
}
} while (!(nt[0]==200 && nt[1]==200 && nt[2]==200) && ++i<M_Len);
}
Translate_Text_To_Score(Input_name,Output_name)
char Input_name[100],Output_name[100];
{
int i,j;
/* Make envelopes */
double xAmpArray[] = {0,.1,.2,.3};
double yAmpArray[] = {0,1,.1,0};
double xFreqArray[] = {0,.05,.1,.2};
double yFreqArray[] = {.99,1.1,1.0,.99};
ampEnvelope = [[Envelope alloc] init];
[ampEnvelope setPointCount:4 xArray:xAmpArray yArray:yAmpArray];
[ampEnvelope setStickPoint:2];
freqEnvelope = [[Envelope alloc] init];
[freqEnvelope setPointCount:4 xArray:xFreqArray yArray:yFreqArray];
[freqEnvelope setStickPoint:1];
Load_From_Text(Input_name);IM_score=[[Score alloc] init];
for (j=0;j<3;j++)
for (i=0;i<4;i++)
{
Pt[j][i]=[[Part alloc] init];Nt_on=[[Note alloc] init];
[Nt_on setPar:MK_synthPatch toString:"Pluck"];
[Nt_on setPar:MK_tempo toDouble:(double)Speed];
[Pt[j][i] setInfo:Nt_on];[IM_score addPart:Pt[j][i]];
}
for (i=0;i<6;i++)
{
Pt_tmp[i]=[[Part alloc] init];Nt_on=[[Note alloc] init];
[Nt_on setPar:MK_synthPatch toString:"Pluck"];
[Nt_on setPar:MK_tempo toDouble:(double)Speed];
[Pt_tmp[i] setInfo:Nt_on];[IM_score addPart:Pt_tmp[i]];
}
Add_Note_To_Part();[[Conductor defaultConductor] setTempo:(double)Speed];
[IM_score writeScorefile:Output_name];
}
main(ac, av)
int ac;
char * av[];
{
Translate_Text_To_Score(av[1],av[1]);
}