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-Output.c < prev    next >
C/C++ Source or Header  |  1992-07-16  |  29KB  |  944 lines

  1. /*                           ===  NM-Output.c  ===
  2.  *
  3.  * void See_Tempo_Set(Id)
  4.  * void Use_Keys(ch)
  5.  * void Output(Melody_Id)
  6.  * void Print_Melody(Melody_Id)
  7.  * void Switch_Set(button,W,H)
  8.  * void Adjust_Set(button,W,H)
  9.  * void Combine_Tempo(Id)
  10.  * void Up_Date_Value(W,H)
  11.  * void Fix_Value(button,W,H)
  12.  * void Adjust_Value(Melody_Id)
  13.  * 
  14.  */
  15.  
  16. #include "NM.h"
  17.  
  18.   XEvent report;
  19.   KeySym ks;
  20.   int i,p,q,button,MS_x,MS_y,old_MS_x,old_MS_y,dx,dy,first,last;
  21.  
  22. void See_Tempo_Set(Id)
  23.   int Id;
  24. {
  25.   XEvent report;
  26.   KeySym ks;
  27.   int button,i,k,Num,Tmp_Id,Timbre_Id,Mx,My,Info;
  28.   more *WITH;
  29.  
  30.   if ((timfile=fopen("Dir_Song/IM.tim","r"))==NULL) 
  31.     for (i=0;i<100;i++) 
  32.       {
  33.     tim[i]=(more *)malloc(sizeof(more));WITH=tim[i];*WITH->tool='\0';
  34.     for (j=0;j<20;j++) WITH->freq[j]=0;
  35.       }
  36.   if (Motion!=Tempo_Set_On)
  37.     {
  38.       Num=0;
  39.       for (i=1;i<7;i++) 
  40.     {
  41.           if (i<4)
  42.         { 
  43.           if (St[Id][2][1].nt[i]!=200)
  44.         {
  45.           for (k=0;k<4;k++) tmp_buf[Num][k].note=tmp_buf[Num][k].act=0;
  46.           for (k=4;k<30;k++) 
  47.             tmp_buf[Num][k].note=tmp_buf[Num][k].act=200;
  48.           tmp_buf[Num][1].note=St[Id][1][1].nt[0]; /*  Timer  */
  49.                   tmp_buf[Num][1].act=St[Id][2][1].nt[0];  /*  Measure  */
  50.           tmp_buf[Num][2].note=0;tmp_buf[Num][2].act=0;
  51.           for (k=3;k<30;k++)
  52.             {
  53.               Info=St[Id][k-1][1].nt[i];if (Info==200) break;
  54.               if (Info<0) tmp_buf[Num][k].note=0;
  55.               else tmp_buf[Num][k].note=71;
  56.               tmp_buf[Num][k].act=abs(Info);
  57.             }
  58.           tmp_buf[Num][0].note=k-2;tmp_buf[Num][0].act=0;
  59.           Timbre_Id=St[Id][1][1].nt[i]-1;
  60.           Sample_names[Num]=(char *)malloc(50);*Sample_names[Num]='\0';
  61.           if (tim[Timbre_Id]->tool!='\0') 
  62.             strcpy(Sample_names[Num],tim[Timbre_Id]->tool);
  63.           Num++;
  64.         }
  65.         }
  66.       else          
  67.         { 
  68.           if (St[Id][2][2].nt[i-3]!=200)
  69.         {
  70.           for (k=0;k<4;k++) tmp_buf[Num][k].note=tmp_buf[Num][k].act=0;
  71.           for (k=4;k<30;k++) 
  72.             tmp_buf[Num][k].note=tmp_buf[Num][k].act=200;
  73.           tmp_buf[Num][1].note=St[Id][1][1].nt[0]; /*  Timer  */
  74.                   tmp_buf[Num][1].act=St[Id][2][1].nt[0];  /*  Measure  */
  75.           tmp_buf[Num][2].note=0;tmp_buf[Num][2].act=0;
  76.           for (k=3;k<30;k++)
  77.             {
  78.               Info=St[Id][k-1][2].nt[i-3];if (Info==200) break;
  79.               if (Info<0) tmp_buf[Num][k].note=0;
  80.               else tmp_buf[Num][k].note=71;
  81.               tmp_buf[Num][k].act=abs(Info);
  82.             }
  83.           tmp_buf[Num][0].note=k-2;tmp_buf[Num][0].act=0;
  84.           Timbre_Id=St[Id][1][2].nt[i-3]-1;
  85.           Sample_names[Num]=(char *)malloc(50);*Sample_names[Num]='\0';
  86.           if (tim[Timbre_Id]->tool!='\0') 
  87.             strcpy(Sample_names[Num],tim[Timbre_Id]->tool);
  88.           Num++;
  89.         }
  90.         }
  91.     }
  92.       if (Num>0)
  93.     {
  94.       Tour_On=1;Back_Id=Id;Now_Bank=now;now=0;XClearWindow(display,win);
  95.       Staff(now,five,0);for (k=0;k<Num;k++) Showpage(k,0,1,0,2,-1);
  96.     }
  97.     }
  98.   else 
  99.     {
  100.       Set_Id=Id;now=0;five=1;XClearWindow(display,win);Staff(now,five,0);
  101.       _LA:Num=0;
  102.       for (i=0;i<6;i++) 
  103.     {
  104.       Tmp_Id=cont[Set_Id].tempo[i]-1;Timbre_Id=cont[Set_Id].instru[i];
  105.       if (Tmp_Id>-1 && Tmp_Id<content[0]) 
  106.         { 
  107.           for (k=0;k<30;k++) tmp_buf[Num][k]=tmp[Tmp_Id][k];
  108.           Sample_names[Num]=(char *)malloc(50);*Sample_names[Num]='\0';
  109.  
  110.           if (-1<Timbre_Id && Timbre_Id<100 &&
  111.           strlen(tim[Timbre_Id]->tool)>0) 
  112.         strcpy(Sample_names[Num],tim[Timbre_Id]->tool);
  113.           Num++;
  114.         }
  115.     }
  116.       Rub(0,33,1137,700,"NavyBlue");
  117.       if (Num>0) for (k=0;k<Num;k++) Showpage(k,0,1,0,2,-1);
  118.       
  119.       if (Action==Print_On) system("xwd | xpr -device lw -rv | lpr -h -Pps10");
  120.  
  121.       do {
  122.            XNextEvent(display,&report);ch='\0';
  123.        switch(report.type) 
  124.          {
  125.            case ButtonPress:button=report.xbutton.button;
  126.                         Mx=report.xmotion.x;My=report.xmotion.y;
  127.                                 switch (button)
  128.                   {
  129.                     case Button1:if (Set_Id>0) Set_Id--;
  130.                                                  else 
  131.                            Set_Id=content[Max_kind-1];
  132.                                  goto _LA;
  133.                       break;
  134.                     case Button2:if (Set_Id<content[Max_kind-1])
  135.                                    Set_Id++;
  136.                                                  else Set_Id=0;
  137.                                  goto _LA;
  138.                       break;
  139.                     case Button3:if (548<Mx && Mx<585 && 2<My
  140.                              && My<28)
  141.                                    ch='&';
  142.                                  else 
  143.                                {
  144.                              if (Set_Id<content[Max_kind
  145.                                     -1])
  146.                                Set_Id++;
  147.                              else Set_Id=0;
  148.                              goto _LA;
  149.                            }
  150.                       break;
  151.                   }
  152.          break;
  153.            case KeyPress:ks=XLookupKeysym(report,0);
  154.                      switch(ks)
  155.                    {
  156.                      case 65498:if (Set_Id>0) Set_Id--;
  157.                                             else Set_Id=content[Max_kind-1];
  158.                             goto _LA;
  159.                    break;      /*  PgUp  */
  160.                  case 65504:if (Set_Id<content[Max_kind-1]) 
  161.                               Set_Id++;
  162.                                             else Set_Id=0;
  163.                             goto _LA;
  164.                    break;      /*  PgDn  */
  165.                  case XK_Return:ch='!';break;
  166.                  case XK_Escape:ch='&';break;
  167.                    }
  168.          break;
  169.          }
  170.      } while (!(ch == '!' || ch == '&'));
  171.     }
  172. }
  173.  
  174. void Use_Keys(ch)
  175.   char ch;
  176. {
  177.   char STR1[256],*filename;
  178.  
  179.   old_MS_x=200;old_MS_y=200;MS_x=old_MS_x;MS_y=old_MS_y;dx=dy=0;;
  180.   switch (ch) 
  181.     {
  182.       case '$':if (now>0)
  183.              {
  184.            if (M_Id>p) 
  185.              {
  186.                switch (page) 
  187.              {
  188.                case 0:M_Id--;Print_pt=0;
  189.                       if (St[M_Id][8][0].nt[0]>St[M_Id][8][1].nt[0])
  190.                     page=St[M_Id][8][0].nt[0];
  191.                   else page=St[M_Id][8][1].nt[0];
  192.                       if (St[M_Id][8][0].nt[2]>page)
  193.                     page=St[M_Id][8][2].nt[0];
  194.                   Rub(67,3,477,25,"MediumBlue");
  195.                       SetColor("gold");Use_Font("12x24");
  196.                       OutTextXY(67,26,names[now*1000+M_Id-1000]);
  197.                       Showpage(M_Id,page,1,0,2,-1);
  198.                  break;
  199.                case 1:
  200.                case 2:
  201.                case 3:
  202.                case 4:
  203.                case 5:
  204.                case 6:
  205.                case 7:
  206.                case 8:
  207.                case 9:page--;Showpage(M_Id,page,1,0,2,-1);
  208.                  break;
  209.              }
  210.              } 
  211.            else if (page!=0) 
  212.                   { page--;Showpage(M_Id,page,1,0,2,-1); }
  213.          }
  214.     break;
  215.       case '^':if (now>0)
  216.              {
  217.            if (M_Id<q) 
  218.              {
  219.                if (page<St[M_Id][8][0].nt[0]||page<St[M_Id][8][1].nt[0]
  220.                || page<St[M_Id][8][2].nt[0]) 
  221.              page++;
  222.                else { M_Id++;page=0;Print_pt=0; }
  223.                Showpage(M_Id,page,1,0,2,-1);
  224.              } 
  225.            else if (page<St[M_Id][8][0].nt[0] ||
  226.                 page<St[M_Id][8][1].nt[0] || 
  227.                 page<St[M_Id][8][2].nt[0]) 
  228.                   { page++;Showpage(M_Id,page,1,0,2,-1); }
  229.          }
  230.     break;
  231.       case '*':                     /* F1 */   
  232.       case '/':_LA:page=0;          /* F2 */
  233.            if (now>0)
  234.          {
  235.            Rub(67,3,477,25,"MediumBlue");
  236.            SetColor("gold");Use_Font("12x24");
  237.            if (ch=='*') { if (M_Id>0) M_Id--;else M_Id=content[now]-1; }
  238.            else { if (M_Id<content[now]-1) M_Id++;else M_Id=0; }
  239.            OutTextXY(67,26,names[now*1000+M_Id]);ch='\0';
  240.            do {
  241.                 XNextEvent(display,&report);
  242.                 switch(report.type) 
  243.               {
  244.                 case ButtonPress:button=report.xbutton.button;
  245.                                          MS_x=report.xbutton.x;
  246.                                  MS_y=report.xbutton.y;
  247.                                  switch(button)
  248.                            {
  249.                                      case Button1:ch='*';break;
  250.                                      case Button2:ch='!';Print_pt=0;
  251.                            break;
  252.                              case Button3:if (548<MS_x && 
  253.                                   MS_x<585 && 
  254.                                   2<MS_y && 
  255.                                   MS_y<28)
  256.                                         ch='&';
  257.                                       else ch='/';
  258.                          break;
  259.                            }
  260.                   break;
  261.                 case KeyPress:ks=XLookupKeysym(report,0);
  262.                               switch(ks)
  263.                         {
  264.                           case XK_F1:ch='*';break;
  265.                           case XK_F2:ch='/';break;
  266.                           case XK_Return:ch='!';break;
  267.                           case XK_Escape:ch='&';break;
  268.                         }
  269.                   break;
  270.               }
  271.             if (ch=='*' || ch=='/') goto _LA;
  272.               } while (ch != '!' && ch != '&');
  273.            if (ch=='&') return;else Showpage(M_Id,0,1,0,2,-1);
  274.            if (unite) highlight(x*36+5,z+100,26,37);
  275.          }
  276.            else
  277.          {
  278.            Rub(200,3,50,25,"MediumBlue");SetColor("gold");
  279.            if (ch=='*') { if (M_Id>0) M_Id--;else M_Id=content[now]-1; }
  280.            else { if (M_Id<content[now]-1) M_Id++;else M_Id=0; }
  281.            Use_Font("12x24");Out_I_XY(200,26,M_Id+1);
  282.            Showpage(M_Id,0,1,0,2,-1);
  283.          }
  284.     break;
  285.       case '+':if (unite) { Pickup(x,way,-1);first=Count(M_Id,way*30+x,&n,1); }
  286.     break;   /* F3 */ 
  287.       case '=':if (unite) { Pickup(x,way,1);last=Count(M_Id,way*30+x,&n,1); }
  288.     break;  /* F4 */   
  289.       case '[':if (unite && first<=last && i+last-first<=M_Len-1)  /* F5 */   
  290.              {
  291.            if (St[head][0][0].nt[0]==0) 
  292.              for (j=0;j<St_Start;j++)
  293.                {
  294.              St[head][j][0]=St[M_Id][j][0];
  295.              St[head][j][1]=St[M_Id][j][1];
  296.              St[head][j][2]=St[M_Id][j][2];
  297.                }
  298.            for (j=first;j<last+1;j++)
  299.              { 
  300.                St[head][i+j-first][0]=St[M_Id][j][0];
  301.                St[head][i+j-first][1]=St[M_Id][j][1];
  302.                St[head][i+j-first][2]=St[M_Id][j][2];
  303.              }
  304.            i+=last-first+1;
  305.            St[head][0][0].nt[0]=St[head][0][1].nt[0]=i;
  306.            St[head][0][2].nt[0]=i;Save(M_Id+1,tail);
  307.          } 
  308.                else { /*sound(180);delay(600);nosound();*/ }
  309.     break;
  310.       case '#':if (now>0) 
  311.              {
  312.            dis(&lock);Rub(921,835,30,17,"MediumBlue");
  313.            SetColor("gold");Use_Font("7x14");
  314.            if (lock) OutTextXY(921,852,"On ");
  315.            else OutTextXY(921,852,"Off");
  316.          }
  317.     break;
  318.       case '<':if (unite) 
  319.              {
  320.            highlight(x*36+5,z+100,26,37);
  321.            if (x>1) x--;
  322.            else 
  323.              {
  324.                switch (way) 
  325.              {
  326.                case 3:
  327.                case 6:way--;page=way/3;Showpage(M_Id,page,1,0,2,-1);
  328.                       x=30;
  329.                  break;
  330.                case 1:
  331.                case 2:
  332.                case 4:
  333.                case 5:
  334.                case 7:
  335.                case 8:way--;x=30;break;
  336.              }
  337.                z=(way-page*3)*Dist;
  338.              }
  339.            highlight(x*36+5,z+100,26,37);
  340.          }
  341.     break;
  342.       case '>':if (unite) 
  343.              {
  344.            highlight(x*36+5,z+100,26,37);
  345.            if (x<30) x++;
  346.            else 
  347.              {
  348.                switch (way) 
  349.              {
  350.                case 2:
  351.                case 5:way++;page=way/3;Showpage(M_Id,page,1,0,2,-1);
  352.                       x=1;
  353.                  break;
  354.                default:way++;x=1;break;
  355.              }
  356.                z=(way-page*3)*Dist;
  357.              }
  358.            highlight(x*36+5,z+100,26,37);
  359.          }
  360.     break;
  361.       case '?':if (unite && way>0) 
  362.              {
  363.            switch (way) 
  364.              {
  365.                case 3:
  366.                case 6:way--;page=way/3;Showpage(M_Id,page,1,0,2,-1);
  367.              break;
  368.                case 1:
  369.                case 2:
  370.                case 4:
  371.                case 5:
  372.                case 7:
  373.                case 8:way--;break;
  374.              }
  375.            highlight(x*36+5,z+100,26,37);z=(way-page*3)*Dist;
  376.            highlight(x*36+5,z+100,26,37);
  377.          }
  378.     break;
  379.       case '@':if (unite & St[M_Id][0][0].nt[0]-p>=30) 
  380.              {
  381.            switch (way) 
  382.              {
  383.                case 2:
  384.                case 5:way++;page=way/3;Showpage(M_Id,page,1,0,2,-1);
  385.              break;
  386.                default:way++;break;
  387.              }
  388.            highlight(x*36+5,z+100,26,37);z=(way-page*3)*Dist;
  389.            highlight(x*36+5,z+100,26,37);
  390.          }
  391.     break;
  392.       case 'L':Signal=1;q=M_Id+1;Sing();q=content[now];break;
  393.       case 'G':Rub(176,840,770,16,"MediumBlue");SetColor("cyan");
  394.                Use_Font("7x14");OutTextXY(176,852,"Back file name: ");
  395.            SetColor("white");filename=(char *)malloc(100);*filename='\0';
  396.            sprintf(filename+strlen(filename),"%s","Dir_Text/");j=0;
  397.            do {
  398.             ch='\0';ch=getkey();
  399.             if (('0'<=ch && ch<='9') || ('a'<=ch && ch<='z') || ('A'<=ch
  400.             && ch<='Z') || ch=='.' || ch=='-' || ch=='_' || ch=='*')
  401.               {
  402.             sprintf(filename+strlen(filename),"%c",ch);
  403.             sprintf(STR1,"%c",ch);OutTextXY(j*8+300,852,STR1);j++;
  404.               }
  405.           } while (ch != '!' && j != 33);
  406.                 if (j>1)
  407.           { 
  408.             Load_On=1;M_Id=Load_From_Back_Up(filename,M_Id,1);
  409.             Showpage(M_Id,0,1,0,2,-1);Load_On=0;
  410.           }
  411.             Rub(176,840,770,16,"MediumBlue");
  412.             SetColor("gold");Use_Font("7x14");
  413.             OutTextXY(179,852,"F1-Ahead  F2-Behind  F3-First  F4-Last  F5-Copy   B-Backup  G-Get_Backup   D-Midi_Load  S-Midi_Save  Lock-Off");
  414.     break;
  415.       case 'B':if (now>0) Save_To_Back_Up(names[now*1000+M_Id],M_Id);
  416.            else Save_To_Back_Up("tempo-",M_Id);
  417.     break;
  418.  
  419.       case 'D':Rub(176,840,770,16,"MediumBlue");SetColor("cyan");
  420.                Use_Font("7x14");OutTextXY(176,852,"Midi file name: ");
  421.            SetColor("white");filename=(char *)malloc(100);*filename='\0';
  422.            sprintf(filename+strlen(filename),"%s","Dir_Midi/");j=0;
  423.            do {
  424.             ch='\0';ch=getkey();
  425.             if (('0'<=ch && ch<='9') || ('a'<=ch && ch<='z') || ('A'<=ch
  426.             && ch<='Z') || ch=='.' || ch=='-' || ch=='_' || ch=='*')
  427.               {
  428.             sprintf(filename+strlen(filename),"%c",ch);
  429.             sprintf(STR1,"%c",ch);OutTextXY(j*8+300,852,STR1);j++;
  430.               }
  431.           } while (ch != '!' && j != 33);
  432.             if (j>1)
  433.           { 
  434.             M_Id=Load_From_Midi(filename,M_Id);
  435.             Showpage(M_Id,0,1,0,2,-1);
  436.             Rub(176,840,770,16,"MediumBlue");
  437.           }
  438.             SetColor("gold");Use_Font("7x14");
  439.             OutTextXY(179,852,"F1-Ahead  F2-Behind  F3-First  F4-Last  F5-Copy   B-Backup  G-Get_Backup   D-Midi_Load  S-Midi_Save  Lock-Off");
  440.     break;
  441.       case 'S':if (now>0) Save_To_Midi(names[now*1000+M_Id],M_Id);
  442.            else Save_To_Midi("tempo-",M_Id);
  443.     break;
  444.     }
  445. }
  446.  
  447. void Output(Melody_Id)
  448.   int Melody_Id;
  449. {
  450.   int j,k,At_high,Tmp_Lim,Val;
  451.   char STR1[256];
  452.  
  453.   old_MS_x=200;old_MS_y=200;MS_x=old_MS_x;MS_y=old_MS_y;ch='\0';
  454.   if (next==0) unite=0;first=St_Start+1;last=St_Start;
  455.   if (content[next]==0 || unite)
  456.     {
  457.       Rub(0,480,1139,400,"MediumBlue");Rub(0,480,1139,2,"yellow");
  458.       SetColor("green");Use_Font("12x24");
  459.     }
  460.   if (content[next]==0) 
  461.     { 
  462.       OutTextXY(470,600,"No such melody !");do { } while ((ch=GetKey())!='!');
  463.       return; 
  464.     }
  465.   p=0;q=content[next]-1;
  466.   if (unite) 
  467.     {
  468.       if (content[next]==1000) 
  469.     { 
  470.       Rub(0,480,1139,400,"MediumBlue");Rub(0,480,1139,2,"yellow");
  471.       SetColor("green");Use_Font("12x24");
  472.       OutTextXY(300,600,"No more then 1000 melodys");
  473.       do { } while ((ch=GetKey())!='!');return;
  474.     }
  475.       head=content[next];tail=head+1;
  476.     }
  477.   if (now!=next) { now=next;Load(); }
  478. /*
  479.   OutTextXY(420,600,"Five-line ?");ch=GetKey();if (ch!= 'N') five=1;else five=0;
  480. */
  481.   Rub(0,480,1137,378,"MediumBlue");XSetLineAttributes(display,gc,2,0,0,0);
  482.   SetColor("yellow");Line(0,480,1137,480);SetColor("green");
  483.   nx=-1;ny=-1;five=1;
  484.   if (unite) 
  485.     {
  486.       OutTextXY(310,560,"Melody name: ");i=now*1000+head;
  487.       S_bf=(char *)malloc(10);*S_bf='\0';sprintf(S_bf,"%5ld",i+1);
  488.       Out_I_XY(460,560,i+1);strcpy(names[i],S_bf);ch='.';j=0;
  489.       do {
  490.        sprintf(names[i]+strlen(names[i]),"%c",ch);
  491.        sprintf(STR1,"%c",ch);OutTextXY(j*12+530,560,STR1);j++;ch=getkey();
  492.          } while (ch != '!' && j != 34);
  493.       if (j==1) sprintf(names[i]+strlen(names[i]),"%s","New");
  494.       sprintf(names[i]+strlen(names[i]),"%c",'\n');i=St_Start;      
  495.       for (j=0;j<M_Len;j++) 
  496.     for (At_high=0;At_high<3;At_high++)
  497.       {
  498.         St[head][j][At_high].nt[0]=200;
  499.             St[head][j][At_high].nt[1]=St[head][j][At_high].nt[2]=0;
  500.         St[head][j][At_high].nt[3]=0;
  501.         St[head][j][At_high].act=0;St[head][j][At_high].vol=Volumn;
  502.       }
  503.       St[head][0][0].nt[0]=0;
  504.     }
  505.   XClearWindow(display,win);Staff(now,five,0);On_High=2;
  506.   next=0;M_Id=Melody_Id;way=0;page=0;lock=0;Use_Font("7x14");SetColor("gold");
  507.   OutTextXY(179,852,"F1-Ahead  F2-Behind  F3-First  F4-Last  F5-Copy   B-Backup  G-Get_Backup   D-Midi_Load  S-Midi_Save  Lock-Off");
  508.   if (now>0) Showpage(M_Id,0,1,0,2,-1);        
  509.   else 
  510.     {
  511.       for (j=0;j<q+1;j++)
  512.     {
  513.       for (k=0;k<30;k++) tmp_buf[j][k]=tmp[j][k];
  514.       Sample_names[j]=(char *)malloc(50);*Sample_names[j]='\0';
  515.           strcpy(Sample_names[j],names[j]);
  516.     }
  517.       if (q-M_Id>9) Tmp_Lim=10;else Tmp_Lim=q+1-M_Id;
  518.       for (j=M_Id;j<M_Id+Tmp_Lim;j++) Showpage(j,0,1,0,2,-1);M_Id+=Tmp_Lim-1;
  519.     }
  520.  
  521.   if (unite) { z=0;if (five) x=1;else x=4;highlight(x*36+5,z+100,26,37); }
  522.   do {
  523.        XNextEvent(display,&report);
  524.        switch(report.type) 
  525.      {
  526.        case ButtonPress:button=report.xbutton.button;ch='\0';
  527.                         MS_x=report.xbutton.x;MS_y=report.xbutton.y;
  528.                         Val=DoButtonEvent(report,button,MS_x,MS_y,M_Id,1,1);
  529.                         if (Val!=1) Use_Keys(ch);
  530.          break;
  531.        case KeyPress:ks=XLookupKeysym(report,0);
  532.                  switch(ks)
  533.                {
  534.                  case XK_F1:ch='*';break;
  535.                  case XK_F2:ch='/';break;
  536.                  case XK_F3:ch='+';break;
  537.                  case XK_F4:ch='=';break;
  538.                  case XK_F5:ch='[';break;
  539.                  case XK_F6:ch=']';break;
  540.                  case XK_Return:ch='!';break;
  541.                  case XK_Escape:ch='&';break;
  542.                  case XK_Left:ch='<';break;
  543.                  case XK_Right:ch='>';break;
  544.                  case XK_Up:ch='?';break;
  545.                  case XK_Down:ch='@';break;
  546.                  case 65496:ch='#';break;          /*  Home  */
  547.                  case 65502:ch='%';break;          /*  End   */
  548.                  case 65498:ch='$';break;          /*  PgUp  */
  549.                  case 65504:ch='^';break;          /*  PgDn  */
  550.                  case XK_Num_Lock:ch='|';break;
  551.                  case XK_Insert:ch='{';break;
  552.                  case XK_Delete:ch='}';break;
  553.                  default:XLookupString(report,tmpstr,128,&ks,0);
  554.                      if (isalpha(tmpstr[0])) 
  555.                        ch=toupper(tmpstr[0]);
  556.                      else ch=tmpstr[0];
  557.                    break;
  558.                }
  559.                      Use_Keys(ch);    
  560.          break;
  561.      }
  562.      } while (ch != '&');
  563.  
  564.   if (unite) 
  565.     { if (first<=last) { Del=-1;content[now]+=1;Save(M_Id+1,tail);} unite=0; }
  566. }
  567.  
  568. void Print_Melody(Melody_Id)
  569.   int Melody_Id;
  570. {
  571.   int i,j,k,q,Tmp_Lim,page,Num;
  572.  
  573.   if (Melody_Id==-1) 
  574.     {
  575.       Rub(0,480,1139,400,"MediumBlue");Rub(0,480,1139,2,"yellow");
  576.       SetColor("green");Use_Font("12x24");OutTextXY(370,630,"Print all ?");
  577.       ch=GetKey();if (ch != 'N') ch='Y';S_bf=(char *)malloc(10);*S_bf='\0';
  578.       sprintf(S_bf,"%c",ch);OutTextXY(590,630,S_bf);
  579.       if (ch!='N') { M_Id=0;Num=content[next]; } else return;
  580.       if (M_Id>=content[next])
  581.     { 
  582.       OutTextXY(500,700,"No such melody !");
  583.       do { } while ((ch=GetKey())!='!');
  584.       return;
  585.     }
  586.     }
  587.   else { M_Id=Melody_Id;Num=1; }
  588.  
  589.   if (now != next) now=next;
  590.   if (now!=Max_kind-1 && content[now]>0) Load();
  591.  
  592.   five=1;
  593.   if (now==0)
  594.     {
  595.       q=content[next]-1;Num=0;XClearWindow(display,win);Staff(now,1,0);
  596.       for (j=0;j<q;j++)
  597.     {
  598.       for (k=0;k<30;k++) tmp_buf[j][k]=tmp[j][k];
  599.       Sample_names[j]=(char *)malloc(50);*Sample_names[j]='\0';
  600.           strcpy(Sample_names[j],names[j]);
  601.     }
  602.       do {
  603.        if (content[next]-Num>10) Tmp_Lim=10;else Tmp_Lim=content[next]-Num;
  604.        for (M_Id=Num;M_Id<Num+Tmp_Lim;M_Id++) Showpage(M_Id,0,1,0,2,-1);
  605.        Num+=Tmp_Lim;system("xwd | xpr -device lw -rv | lpr -h -Pps10");
  606.      } while (Num<content[next]);
  607.     }
  608.   else 
  609.     {
  610.       XClearWindow(display,win);Staff(now,1,0);i=M_Id;
  611.       for (M_Id=i;M_Id<i+Num;M_Id++)
  612.     {
  613.       if (St[M_Id][8][0].nt[0]>St[M_Id][8][1].nt[0]) k=St[M_Id][8][0].nt[0];
  614.       else k=St[M_Id][8][1].nt[0];
  615.       if (k<St[M_Id][8][2].nt[0]) k=St[M_Id][8][2].nt[0];
  616.  
  617.       for (page=0;page<k+1;page++)
  618.         {
  619.           Showpage(M_Id,page,1,1,2,-1);
  620.           system("xwd | xpr -device lw -rv | lpr -h -Pps10");
  621.         }
  622.     }
  623.     }
  624. }
  625.  
  626. void Switch_Set(button,W,H)
  627.   int button,W,H;
  628. {
  629.   int i,dx,dy;
  630.  
  631.   Rub(Set_X+40,Set_Y+1,2*W-40,H-2,"MediumBlue");
  632.   for (i=0;i<6;i++)
  633.     {
  634.       dx=Set_X+2*W+i*W+2;dy=Set_Y+H+2;Rub(dx,dy,W-3,H-4,"MediumBlue");
  635.       Rub(dx,dy+H,W-3,H-4,"MediumBlue");
  636.     }
  637.  
  638.   if (button==Button1)
  639.     { if (Set_Id==0) Set_Id=content[Max_kind-1];else Set_Id--; }
  640.   else if (button==Button3)
  641.          { if (Set_Id==content[Max_kind-1]) Set_Id=0;else Set_Id++; }
  642.   SetColor("SpringGreen");
  643.   OutTextXY(Set_X+32,Set_Y+26,Sub_Str(cont[Set_Id].Set_name,0,12));
  644.  
  645.   for (i=0;i<6;i++)
  646.     {
  647.       if (cont[Set_Id].tempo[i]>0)
  648.     Out_I_XY(Set_X+22+2*W+i*W,Set_Y+H+26,cont[Set_Id].tempo[i]);
  649.       if (cont[Set_Id].instru[i]>0)
  650.     Out_I_XY(Set_X+22+2*W+i*W,Set_Y+2*H+26,cont[Set_Id].instru[i]);
  651.     }
  652. }
  653.  
  654. void Adjust_Set(button,W,H)
  655.   int button,W,H;
  656. {
  657.   int dx,dy;
  658.  
  659.   dx=Set_X+2*W+Set_Column*W+2;dy=Set_Y+H+Set_Row*H+2;
  660.   Rub(dx,dy,W-3,H-4,"MediumBlue");SetColor("white");
  661.  
  662.   if (Set_Row==0)
  663.     {
  664.       switch (button)
  665.     {
  666.       case Button1:if (cont[Set_Id].tempo[Set_Column]==0) 
  667.                      cont[Set_Id].tempo[Set_Column]=1000;
  668.                    else cont[Set_Id].tempo[Set_Column]--;
  669.         break;
  670.       case Button2:if (cont[Set_Id].tempo[Set_Column]+10>999) 
  671.                      cont[Set_Id].tempo[Set_Column]=0;
  672.                    else cont[Set_Id].tempo[Set_Column]+=10;
  673.         break;
  674.       case Button3:if (cont[Set_Id].tempo[Set_Column]>999) 
  675.                  cont[Set_Id].tempo[Set_Column]=0;
  676.                    else cont[Set_Id].tempo[Set_Column]++;
  677.         break;
  678.     }
  679.       Out_I_XY(Set_X+22+2*W+Set_Column*W,Set_Y+H+26,
  680.            cont[Set_Id].tempo[Set_Column]);
  681.     }
  682.   else if (Set_Row==1)
  683.          {
  684.        switch (button)
  685.          {
  686.            case Button1:if (cont[Set_Id].instru[Set_Column]==0) 
  687.                           cont[Set_Id].instru[Set_Column]=1000;
  688.                         else cont[Set_Id].instru[Set_Column]--;
  689.          break;
  690.            case Button2:if (cont[Set_Id].instru[Set_Column]+10>999) 
  691.                           cont[Set_Id].instru[Set_Column]=0;
  692.                         else cont[Set_Id].instru[Set_Column]+=10;
  693.          break;
  694.            case Button3:if (cont[Set_Id].instru[Set_Column]>999) 
  695.                       cont[Set_Id].instru[Set_Column]=0;
  696.                         else cont[Set_Id].instru[Set_Column]++;
  697.          break;
  698.          }
  699.        Out_I_XY(Set_X+22+2*W+Set_Column*W,Set_Y+26+2*H,
  700.             cont[Set_Id].instru[Set_Column]);
  701.      }
  702.   highlight(dx+1,dy+1,W-5,H-6);
  703. }
  704.  
  705. void Combine_Tempo(Id)
  706.   int Id;
  707. {
  708.   int i,W,H,button,Ms_x,Ms_y;
  709.  
  710.   Rub(0,480,1132,384,"MediumBlue");XSetLineAttributes(display,gc,2,0,0,0);
  711.   SetColor("yellow");Line(0,480,1132,480);Use_Font("7x14");SetColor("white");
  712.   Set_X=325;Set_Y=620;Set_W=480;Set_H=120;W=60;H=40;Set_Id=Id;ch='\0';
  713.   DrawRectangle(Set_X,Set_Y,Set_W,Set_H);XSetLineAttributes(display,gc,1,0,0,0);
  714.  
  715.   for (i=0;i<6;i++) Line(Set_X+2*W+W*i,Set_Y,Set_X+2*W+W*i,Set_Y+Set_H);
  716.   for (i=1;i<3;i++) Line(Set_X,Set_Y+H*i,Set_X+Set_W,Set_Y+H*i);
  717.   SetColor("magenta");OutTextXY(Set_X+10,Set_Y+26,"Num");SetColor("yellow");
  718.   OutTextXY(Set_X+10,Set_Y+26+H,"Tempo #");Set_Column=-10;Set_Row=-10;
  719.   OutTextXY(Set_X+10,Set_Y+26+2*H,"Instrument #");SetColor("cyan");
  720.   for (i=0;i<6;i++) Out_I_XY(Set_X+26+2*W+i*W,Set_Y+26,i+1);
  721.   Switch_Set(Button2,W,H);
  722.  
  723.   do {
  724.        XNextEvent(display,&report);
  725.        switch(report.type) 
  726.      {
  727.            case MotionNotify:Ms_x=report.xmotion.x;Ms_y=report.xmotion.y;
  728.                          Hi_light_Set(Ms_x,Ms_y);
  729.          break;
  730.        case ButtonPress:button=report.xbutton.button;
  731.                         if (button==Button2 && In_Set(Ms_x,Ms_y,W,H)==0)
  732.                   {
  733.                 for (i=0;i<6;i++)
  734.                   if (cont[content[Max_kind-1]].instru[i]>0 ||
  735.                       cont[content[Max_kind-1]].tempo[i]>0)
  736.                     { 
  737.                       if (content[Max_kind-1]<999)
  738.                     { 
  739.                       content[Max_kind-1]++;Save_Set();
  740.                       Get_List();
  741.                     }
  742.                       break;
  743.                     }
  744.                   }
  745.                         else
  746.                   {
  747.                 Ms_x=report.xbutton.x;Ms_y=report.xbutton.y;
  748.                 if (In_Set(Ms_x,Ms_y,W,H)==0)
  749.                   Switch_Set(button,W,H);
  750.                 else if (In_Set(Ms_x,Ms_y,W,H)==1)
  751.                   Adjust_Set(button,W,H);
  752.                   }
  753.          break;
  754.        case KeyPress:ks=XLookupKeysym(report,0);
  755.                  switch(ks)
  756.                {
  757.                  case XK_Return:ch='!';break;
  758.                  case XK_Escape:ch='&';break;
  759.                  case XK_Delete:Delete_Set(Set_Id);
  760.                                 if (content[Max_kind-1]<Set_Id) 
  761.                           Set_Id=content[Max_kind-1];
  762.                                 Switch_Set(-1,W,H);Get_List();
  763.                    break;
  764.                }
  765.          break;
  766.        }
  767.      } while (!(ch=='!' || ch=='&'));
  768.   Save_Set();
  769. }
  770.  
  771. void Up_Date_Value(W,H)
  772.   int W,H;
  773. {
  774.   int i,j,X,Y;
  775.  
  776.   for (i=0;i<4;i++)
  777.     for (j=0;j<5;j++)
  778.       { 
  779.         X=Value_X+Value_H_X+j*W+2;Y=Value_Y+Value_H_Y+i*H+2;
  780.         Rub(X,Y,Value_H_W,Value_H_H,"MediumBlue");SetColor("cyan");
  781.         Out_I_XY(X+22,Y+15,St[M_Id][10+i*5+j][On_High].nt[0]);
  782.       }
  783. }
  784.  
  785. void Fix_Value(button,W,H)
  786.   int button,W,H;
  787. {
  788.   int X,Y,Id;
  789.  
  790.   X=Value_X+Value_H_X+Value_Column*W+2;Y=Value_Y+Value_H_Y+Value_Row*H+2;
  791.   Rub(X,Y,Value_H_W,Value_H_H,"MediumBlue");SetColor("white");
  792.   Id=10+Value_Row*5+Value_Column;
  793.  
  794.   switch (button)
  795.     {
  796.       case Button1:if (St[M_Id][Id][On_High].nt[0]<-9) 
  797.                  St[M_Id][Id][On_High].nt[0]=10;
  798.                    else St[M_Id][Id][On_High].nt[0]-=1;
  799.            Out_I_XY(Value_X+96+Value_Column*W,Value_Y+47+Value_Row*H,
  800.                 St[M_Id][Id][On_High].nt[0]);
  801.         break;
  802.       case Button2:Rub(Value_X,Value_Y-32,33,16,"MediumBlue");
  803.                switch (On_High)
  804.              {
  805.                case 0:On_High=2;break;
  806.                case 1:On_High=0;break;
  807.                case 2:On_High=1;break;
  808.              }
  809.                Up_Date_Value(W,H);SetColor("white");
  810.                if (On_High==2) OutTextXY(Value_X,Value_Y-20,"Vois");
  811.                else if (On_High==1) OutTextXY(Value_X,Value_Y-20,"High");
  812.                     else if (On_High==0) 
  813.               OutTextXY(Value_X,Value_Y-20,"Low");
  814.         break;
  815.       case Button3:if (St[M_Id][Id][On_High].nt[0]>9) 
  816.                  St[M_Id][Id][On_High].nt[0]=-10;
  817.            else St[M_Id][Id][On_High].nt[0]+=1;
  818.            Out_I_XY(Value_X+96+Value_Column*W,Value_Y+47+Value_Row*H,
  819.                 St[M_Id][Id][On_High].nt[0]);
  820.         break;
  821.     }
  822.   highlight(X,Y,Value_H_W,Value_H_H);
  823. }
  824.  
  825. void Adjust_Value(Melody_Id)
  826.   int Melody_Id;
  827. {
  828.   int i,j,W,H,button,Ms_x,Ms_y;
  829.  
  830.   Rub(0,480,1132,384,"MediumBlue");XSetLineAttributes(display,gc,2,0,0,0);
  831.   SetColor("yellow");Line(0,480,1132,480);Value_X=225;Value_Y=590;Value_W=680;
  832.   Value_H=240;W=136;H=60;SetColor("white");M_Id=Melody_Id;Use_Font("12x24");
  833.   DrawRectangle(Value_X,Value_Y,Value_W,Value_H);Value_Column=-10;Value_Row=-10;
  834.   XSetLineAttributes(display,gc,1,0,0,0);ch='\0';On_High=1;
  835.  
  836.   for (i=1;i<5;i++) Line(Value_X+W*i,Value_Y,Value_X+W*i,Value_Y+Value_H);
  837.   for (i=1;i<4;i++) Line(Value_X,Value_Y+H*i,Value_X+Value_W,Value_Y+H*i);
  838.   SetColor("green");OutTextXY(Value_X+2*W,Value_Y-20,names[now*1000+M_Id]);
  839.   Use_Font("7x14");SetColor("white");OutTextXY(Value_X,Value_Y-20,"High");
  840.   SetColor("yellow");
  841.   for (i=0;i<4;i++)
  842.     switch (i)
  843.       {
  844.         case 0:for (j=0;j<5;j++)
  845.              switch (j)
  846.            {
  847.              case 0:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Quality");
  848.                break;
  849.              case 1:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Creative");
  850.                break;
  851.              case 2:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Famous");
  852.                break;
  853.              case 3:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Pleasing");
  854.                break;
  855.              case 4:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,
  856.                       "Genaration");
  857.                break;
  858.            }
  859.       break;
  860.         case 1:for (j=0;j<5;j++)
  861.              switch (j)
  862.            {
  863.              case 0:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Year");
  864.                break;
  865.              case 1:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Complex");
  866.                break;
  867.              case 2:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Fast");
  868.                break;
  869.              case 3:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Best_A");
  870.                break;
  871.              case 4:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Best_Z");
  872.                break;
  873.            }
  874.       break;
  875.         case 2:for (j=0;j<5;j++)
  876.              switch (j)
  877.            {
  878.              case 0:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Lasting");
  879.                break;
  880.              case 1:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Light");
  881.                break;
  882.              case 2:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Bright");
  883.                break;
  884.              case 3:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Better_A");
  885.                break;
  886.              case 4:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Better_Z");
  887.                break;
  888.            }
  889.       break;
  890.         case 3:for (j=0;j<5;j++)
  891.              switch (j)
  892.            {
  893.              case 0:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Happy");
  894.                break;
  895.              case 1:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Smooth");
  896.                break;
  897.              case 2:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Humor");
  898.                break;
  899.              case 3:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Good_A");
  900.                break;
  901.              case 4:OutTextXY(Value_X+20+j*W,Value_Y+26+i*H,"Good_Z");
  902.                break;
  903.            }
  904.       break;
  905.     }
  906.  
  907.   Up_Date_Value(W,H);
  908.   do {
  909.        XNextEvent(display,&report);
  910.        switch(report.type) 
  911.      {
  912.            case MotionNotify:Ms_x=report.xmotion.x;Ms_y=report.xmotion.y;
  913.                          Hi_light_Value(Ms_x,Ms_y);
  914.          break;
  915.        case ButtonPress:button=report.xbutton.button;
  916.                         if (In_Value(Ms_x,Ms_y)==1 || button==Button2)
  917.                   Fix_Value(button,W,H);
  918.          break;
  919.        case KeyPress:ks=XLookupKeysym(report,0);
  920.                  switch(ks)
  921.                {
  922.                  case XK_Return:ch='!';break;
  923.                  case XK_Escape:ch='&';break;
  924.                }
  925.          break;
  926.        }
  927.      } while (!(ch=='!' || ch=='&'));
  928.   Del=-1;tail=content[now];Save(1,tail);Host=0;Column_Id=-10;Row_Id=-10;List();
  929. }
  930.  
  931.  
  932.  
  933.  
  934.  
  935.  
  936.  
  937.  
  938.  
  939.  
  940.  
  941.  
  942.  
  943.  
  944.