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 / NM-Sound.c < prev    next >
C/C++ Source or Header  |  1992-07-16  |  9KB  |  296 lines

  1. /*                           ===  NM-Sound.c  ===
  2.  *
  3.  * void Ball(p,q,Draw)
  4.  * void Sound(ch)
  5.  * 
  6.  */
  7.  
  8. #include "NM.h"
  9.  
  10. void Ball(p,q,Draw)
  11.   int p,q,Draw;
  12. {
  13.   if (Draw==1) { SetColor("white");DrawEllipse(p,q,8,8,0,360); }
  14.   else if (Draw==0) Rub(p-2,q-2,12,13,"MediumBlue");
  15. }
  16.  
  17. void Sound(ch)
  18.   char ch;
  19. {
  20.   int i,j,k,p,q,FORLIM;
  21.  
  22.   XClearWindow(display,win);Use_Font("12x24");
  23.   switch (ch) 
  24.     {
  25.       case 'I':if ((unifile=fopen("Dir_Song/IM.uit","r"))==NULL)
  26.              {
  27.            uniset[0][0]=1000;for (i=1;i<=10;i++) uniset[0][i]=0;
  28.            for (j=0;j<100;j++) 
  29.              {
  30.                uniset[j][0]=1000;uniset[j][10]=32767;
  31.                for (i=1;i<=9;i++) uniset[j][i]=37;
  32.              }
  33.            contain=99;
  34.          }
  35.            lf=37;hf=32767;t=1000;
  36.            _LA:SetColor("green");
  37.                    OutTextXY(420,50,"--- Sound-Imitation ---");
  38.                    SetColor("white");DrawRectangle(20,138,1103,567);
  39.                    Rub(22,140,1100,564,"MediumBlue");
  40.                    Rub(100,818,900,27,"black");
  41.                SetColor("white");OutTextXY(26,116,"Fn=");
  42.                OutTextXY(457,116,"No.(1--100)=");
  43.                    for (i=0;i<=9;i++) Line(i*100+122,696,i*100+122,704);
  44.                OutTextXY(26,744,"T(ms)");readat(610,116,3,&k);
  45.                    if (k<1 || k>100) 
  46.              { 
  47.                k=1;Rub(610,92,60,27,"black");SetColor("green");
  48.                OutTextXY(610,116,"1");           
  49.              }
  50.                SetColor("white");
  51.            _LE:lf=uniset[k-1][1];hf=lf;t=uniset[k-1][0];
  52.                    for (i=1;i<11;i++) 
  53.              {
  54.                if (uniset[k-1][i]<lf) lf=uniset[k-1][i];
  55.                if (uniset[k-1][i]>hf) hf=uniset[k-1][i];
  56.              }
  57.            _LB:Rub(22,140,1100,556,"MediumBlue");SetColor("white");
  58.                d=log((double)hf/lf)/100;
  59.                for (i=10;i>0;i--) 
  60.              {
  61.                p=i*100+18;fn=uniset[k-1][i];
  62.                q=(int)floor(660-5*log((double)fn/lf)/d+0.5);
  63.                Ball(p,q,1);
  64.              }
  65.                    SetColor("cyan");Out_I_XY(30,170,hf);Out_I_XY(30,670,lf);
  66.                Notice(p-2,677,13,13,1,"magenta","MediumBlue");
  67.                Rub(107,722,1000,26,"black");SetColor("gold");
  68.                    for (i=1;i<11;i++) 
  69.              Out_I_XY(i*100+10,744,(int)(0.1*t*i-0.1*t));
  70.                SetColor("green");
  71.                    OutTextXY(300,841,"Esc -- Exit   Return -- Go on   A...Z -- sound");
  72.                Rub(610,92,60,27,"black");SetColor("green");
  73.                Out_I_XY(610,116,k);fn=uniset[k-1][1];uniset[k-1][0]=t;
  74.                    Rub(70,92,80,27,"black");SetColor("green");
  75.                Out_I_XY(70,116,fn);
  76.                    do {
  77.                         ch=GetKey();
  78.                 if (ch=='?' || ch=='@' || ch=='$' || ch=='^' || ch=='<' 
  79.                 || ch=='>')
  80.                   switch (ch) 
  81.                 {
  82.                   case '?':                           /*  Up  */
  83.                           case '@':Ball(p,q,0);               /* Down */
  84.                                    switch (ch) 
  85.                          {
  86.                            case '?':if (q>160) q-=2;else q=660;
  87.                          break;
  88.                        case '@':if (q<660) q+=2;else q=160;
  89.                          break;
  90.                          }
  91.                            Ball(p,q,1);
  92.                            fn=(int)floor(lf*exp(d*(660-q)/5)+0.5);
  93.                            Rub(70,92,80,27,"black");
  94.                            SetColor("green");Out_I_XY(70,116,fn);
  95.                                    uniset[k-1][(p-18)/100]=fn;
  96.                     break;
  97.                   case '$':if (k>1) k--;else k=100;      /* PgUp */
  98.                        goto _LE;
  99.                     break;
  100.                   case '^':if (k<100) k++;else k=1;      /* PgDn */
  101.                        goto _LE;
  102.                     break;
  103.                   case '<':                              /* Left */
  104.                   case '>':Notice(p-2,677,13,13,0,"magenta",
  105.                           "MediumBlue");         /* Right */
  106.                            switch (ch) 
  107.                          {
  108.                            case '<':if (p>118) p-=100;
  109.                                 else p=1018;
  110.                          break;
  111.                        case '>':if (p<1018) p+=100;
  112.                                 else p=118;
  113.                          break;
  114.                          }
  115.                            fn=uniset[k-1][(p-18)/100];
  116.                        Notice(p-2,677,13,13,1,"magenta",
  117.                           "MediumBlue");
  118.                            q=(int)floor(660-5*log((double)fn/lf)/d+
  119.                             0.5);
  120.                            Ball(p,q,1);Rub(70,92,80,27,"black");
  121.                            SetColor("green");Out_I_XY(70,116,fn);
  122.                     break;
  123.                 }
  124.             else if (ch==' ' || isalpha(ch)) 
  125.                        {
  126.                                  if (uniset[k-1][0] < 0) 
  127.                    {
  128.                      x=0;
  129.                      do {
  130.                           for (j=1;j<=10;j++) 
  131.                         { /* sound(uniset[k-1][j]);
  132.                              delay(1); */
  133.                         }
  134.                       x+=10;
  135.                     } while (x+uniset[k-1][0]<=-10);
  136.                    } 
  137.                  else 
  138.                    {
  139.                      for (j=1;j<=10;j++) 
  140.                        {
  141.                      /* sound(uniset[k-1][j]);
  142.                         delay((int)floor(0.1*
  143.                         uniset[k-1][0]+0.5));
  144.                         */
  145.                        }
  146.                    }
  147.                  /* nosound(); */
  148.                    }
  149.               } while (ch != '!' && ch != '&');
  150.                if (ch != '&')
  151.              {
  152.                Rub(100,820,960,27,"black");SetColor("white");
  153.                OutTextXY(450,800,"C--correct,G--go on");ch=GetKey();
  154.                if (ch=='!') ch='G';Rub(20,770,1070,90,"black");
  155.                if (ch=='C') 
  156.              {
  157.                SetColor("white");
  158.                OutTextXY(450,830,"Change scale (Y/N) ?");
  159.                ch=GetKey();Rub(20,805,1070,27,"black");
  160.                if (ch=='Y') 
  161.                  {
  162.                    SetColor("cyan");OutTextXY(204,830,"Lf=");
  163.                    readat(260,830,5,&lf);
  164.                    if (lf<19)
  165.                  { 
  166.                    lf=19;Rub(260,805,80,27,"black");
  167.                    SetColor("green");Out_I_XY(260,830,lf);
  168.                  } 
  169.                    else 
  170.                  {
  171.                    for (i=1;i<=10;i++) 
  172.                      {
  173.                        if (lf>uniset[k-1][i]) 
  174.                      {
  175.                        lf=uniset[k-1][i];
  176.                        Rub(260,805,80,27,"black");
  177.                        SetColor("green");
  178.                        Out_I_XY(260,830,lf);
  179.                      }
  180.                      }
  181.                  }
  182.                    SetColor("cyan");OutTextXY(456,830,"Hf=");
  183.                    readat(510,830,5,&hf);
  184.                    if (hf>32767) 
  185.                  { 
  186.                    hf=32767;Rub(510,805,100,27,"black");
  187.                    SetColor("green");Out_I_XY(510,830,hf); 
  188.                  } 
  189.                    else 
  190.                  {
  191.                    for (i=1;i<=10;i++) 
  192.                      {
  193.                        if (hf<uniset[k-1][i]) 
  194.                      {
  195.                        hf=uniset[k-1][i];
  196.                        Rub(510,805,100,27,"black");
  197.                        SetColor("green");
  198.                        Out_I_XY(510,830,hf);
  199.                      }
  200.                      }
  201.                  }
  202.                    fn=lf;SetColor("cyan");
  203.                    OutTextXY(696,830,"T( <0 repeat )=");
  204.                    readat(890,830,5,&t);Rub(10,805,1000,27,"black");
  205.                    if (abs(t)<10) t=10;
  206.                  }
  207.                goto _LB;
  208.              }
  209.                else if (ch=='G')
  210.                   {
  211.                 SetColor("white");
  212.                 OutTextXY(410,840,"Input new unit (Y/N) ?");
  213.                 ch=GetKey();
  214.                 if (ch=='Y')
  215.                   { 
  216.                     Rub(70,92,80,27,"black");
  217.                     Rub(610,92,60,27,"black");goto _LA;
  218.                   }
  219.                   }
  220.              }
  221.            unifile=fopen("Dir_Song/IM.uit","w");
  222.            if (unifile!=NULL) rewind(unifile);else timfile=tmpfile();
  223.            for (j=0;j<100;j++) 
  224.          for (i=0;i<11;i++) fwrite(&uniset[j][i],sizeof(int),1,unifile);
  225.            if (unifile != NULL) fclose(unifile);unifile=NULL;
  226.     break;
  227.             /* I */
  228.       case 'O':printf("Print out (Y/N) ?");ch=GetKey();putchar('\n');
  229.            switch (ch) 
  230.          {
  231.            case 'Y':FORLIM=contain;
  232.                     for (i=1;i<FORLIM;i++) 
  233.                   {
  234.                     fprintf(stdout,"%2ld.Tm=%5ld(ms) F=",i,
  235.                     uniset[i][0]);
  236.                 for (j=1;j<=10;j++) 
  237.                   fprintf(stdout,"%6ld",uniset[i][j]);
  238.                 putc('\n',stdout);
  239.                   }
  240.              break;
  241.            default:FORLIM=contain;
  242.                    for (i=1;i<FORLIM;i++) 
  243.                  {
  244.                    if (i==25 || i==49 || i==73 || i==97) 
  245.                  {
  246.                    printf("      Return key to go on ...");
  247.                    scanf("%*[^\n]");
  248.                  }
  249.                    printf("%2ld.Time=%4ld(ms) F=",i,uniset[i][0]);
  250.                    for (j=2;j<=11;j++)
  251.                  { printf("%12ld",uniset[i][j-1]); }
  252.                    putchar('\n');
  253.                  }
  254.              break;
  255.          }/*case*/
  256.            putchar('\n');printf("Press any key to Menu\n");
  257.            do { } while (!(ch=GetKey()));
  258.     break;
  259.             /* L */
  260.       case 'S':XClearWindow(display,win);p=0;q=contain;
  261.                printf("Esc--exit     Return--repeat\n\n");
  262.                printf("Unit number:    From---");scanf("%ld", &p);
  263.                printf("To---");scanf("%ld",&q);k=p;printf("Number=");
  264.            do {
  265.                 printf("%12ld", k);
  266.                     if (uniset[k][0] < 0) 
  267.               {
  268.             x=0;
  269.             do {
  270.                  for (j=1;j<=10;j++) 
  271.                    { /* sound(uniset[k][j]);delay(1); */ }
  272.                  x+=10;
  273.                } while (x+uniset[k][0]<=-10);
  274.               } 
  275.             else 
  276.               {
  277.             for (j=1;j<=10;j++) 
  278.               {
  279.                 if (k!=0) { /* sound(uniset[k][j]); */ }
  280.                 /*   delay((int)floor(0.1*uniset[k][0]+0.5)); */
  281.               }
  282.               }
  283.             if (k != 0) { /* nosound(); */ }
  284.             /*    delay(1000); */
  285.             if ((ch=GetKey())!=NULL) 
  286.               switch (ch) 
  287.             {
  288.               case '&':return;break;
  289.               case '!':k--;break;
  290.             }
  291.             k++;
  292.           } while (k<=q);
  293.     break;
  294.       }/* case */
  295. }  /* S_I */
  296.